From d35fe2c40d7e8c7fab685766345c82fe69d73501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 6 Dec 2019 13:50:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E8=8D=90=E5=95=86=E5=93=81=EF=BC=8C?= =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/store_sku.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 5426955a4..01a9b2b94 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -672,10 +672,12 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuName []*model.SkuName, JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ? JOIN sku_name d ON d.id = c.name_id AND d.deleted_at = ? WHERE 1=1 + AND a.order_created_at BETWEEN ? and NOW() ` sqlParams := []interface{}{ utils.DefaultTimeValue, utils.DefaultTimeValue, + time.Now().AddDate(0, -1, 0), } if len(storeIDs) > 0 { sql += " AND a.store_id in(" + GenQuestionMarks(len(storeIDs)) + ")" @@ -695,7 +697,10 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuName []*model.SkuName, func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model.SkuCategory, err error) { sql := ` - SELECT t3.* + SELECT DISTINCT t5.* FROM( + SELECT d.* + FROM ( + SELECT t3.*,t1.count FROM( SELECT SUM(b.count) count,d.category_id FROM goods_order a @@ -703,10 +708,12 @@ func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model. JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ? JOIN sku_name d ON d.id = c.name_id AND d.deleted_at = ? WHERE 1=1 + AND a.order_created_at BETWEEN ? and NOW() ` sqlParams := []interface{}{ utils.DefaultTimeValue, utils.DefaultTimeValue, + time.Now().AddDate(0, -1, 0), } if len(storeIDs) > 0 { sql += " AND a.store_id in(" + GenQuestionMarks(len(storeIDs)) + ")" @@ -718,10 +725,13 @@ func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model. JOIN sku_category t3 ON t1.category_id = t3.id AND t3.level = ? AND t3.deleted_at = ? - ORDER BY t1.count DESC + ORDER BY t1.count DESC)t4 + JOIN sku_category d ON d.id = t4.parent_id + AND d.level = ? + Order by t4.count DESC)t5 LIMIT ? ` - sqlParams = append(sqlParams, 100, 2, utils.DefaultTimeValue, 10) + sqlParams = append(sqlParams, 100, 2, utils.DefaultTimeValue, 1, 10) err = GetRows(db, &skuCategory, sql, sqlParams...) return skuCategory, err }