From 70ecbf5114a2dc7c541a38d33c38fe98e5b45903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 24 Dec 2019 11:39:15 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E7=95=85=E9=94=80=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 71 +++++++++++++++++++++++++++ business/model/dao/store_sku.go | 42 +++++++++++++++- controllers/cms_store_sku.go | 15 ++++++ routers/commentsRouter_controllers.go | 9 ++++ 4 files changed, 135 insertions(+), 2 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index dd3ac73b5..e12740783 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -2169,6 +2169,77 @@ func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (storeSkuNameE return storeSkuNameExt, err } +func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNameAndPlaceList []*dao.SkuNameAndPlace, err error) { + db := dao.GetDB() + orderCreate := time.Now().AddDate(0, -1, 0) + skuNameAndPlace, err := dao.GetTopSkusByCityCode(db, cityCode, orderCreate) + if storeID > 0 { + var skuNameList []*model.SkuName + //未关注,不可售的商品nameID列表 + sql := ` + SELECT DISTINCT b.name_id + FROM store_sku_bind a + JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ? + WHERE a.deleted_at = ? + AND a.store_id = ? + AND a.status <> ? + AND b.name_id NOT IN(SELECT DISTINCT b.name_id + FROM store_sku_bind a + JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ? + WHERE a.deleted_at = ? + AND a.store_id = ? + AND a.status = ?) + UNION + SELECT DISTINCT a.name_id + FROM sku a + LEFT JOIN (SELECT DISTINCT b.name_id + FROM store_sku_bind a + JOIN sku b ON a.sku_id = b.id + WHERE a.deleted_at = ? + AND store_id = ?)b ON a.name_id = b.name_id + WHERE a.status = ? + AND a.deleted_at = ? + AND b.name_id IS NULL + ` + sqlParams := []interface{}{ + utils.DefaultTimeValue, + utils.DefaultTimeValue, + storeID, + model.StoreSkuBindStatusNormal, + utils.DefaultTimeValue, + utils.DefaultTimeValue, + storeID, + model.StoreSkuBindStatusNormal, + utils.DefaultTimeValue, + storeID, + model.StoreSkuBindStatusNormal, + utils.DefaultTimeValue, + } + err = dao.GetRows(db, &skuNameList, sql, sqlParams...) + var skuNameMap = make(map[int]*model.SkuName) + for _, v := range skuNameList { + skuNameMap[v.ID] = v + } + for _, v := range skuNameAndPlace { + if skuNameMap[v.ID] != nil { + skuNameAndPlaceList = append(skuNameAndPlaceList, v) + } + } + } else { + skuNameAndPlace = skuNameAndPlaceList + } + i := 1 + for _, v := range skuNameAndPlaceList { + v.Sequence = i + i++ + } + if len(skuNameAndPlaceList) <= 100 { + return skuNameAndPlaceList, err + } else { + return skuNameAndPlaceList[0:100], err + } +} + func GetTopCategoriesByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCategory []*model.SkuCategory, err error) { var ( skuCategory2 []*model.SkuCategory diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 712136722..506c1f76c 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -18,6 +18,7 @@ var ( model.VendorIDMTWM: "mtwm_url", model.VendorIDEBAI: "ebai_url", } + salePriceLimit = 100 ) type SkuStoreCatInfo struct { @@ -195,6 +196,14 @@ type StoreSkuExt struct { Times int `json:"times"` } +type SkuNameAndPlace struct { + model.SkuName + CityCode int `json:"cityCode"` + CityName string `json:"cityName"` + Sequence int `json:"sequence"` + Count int `json:"count"` +} + // todo 应该通过需要同步的skuid来驱动同步分类,而不是当前这种分开的逻辑 // 单门店模式厂商适用 // 从store_sku_bind中,得到所有依赖的商家分类信息 @@ -1027,7 +1036,7 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (storeSkuNameExt []*StoreSk ORDER BY t1.count DESC LIMIT ? ` - sqlParams = append(sqlParams, 100, 30) + sqlParams = append(sqlParams, salePriceLimit, 30) err = GetRows(db, &storeSkuNameExt, sql, sqlParams...) var skuNamesInfo = &StoreSkuNamesInfo{ SkuNames: storeSkuNameExt, @@ -1063,6 +1072,35 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (storeSkuNameExt []*StoreSk return storeSkuNameExt, err } +func GetTopSkusByCityCode(db *DaoDB, cityCode int, orderCreate time.Time) (skuNameAndPlace []*SkuNameAndPlace, err error) { + sql := ` + SELECT t1.*, t2.* + FROM + (SELECT SUM(b.count) count, c.name_id, e.name city_name, d.city_code, + FROM goods_order a + JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id AND a.vendor_id = b.vendor_id + JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ? + JOIN store d ON d.id = a.store_id AND d.deleted_at = ? AND d.city_code = ? + JOIN place e ON e.code = d.city_code + WHERE 1=1 + AND b.sale_price > ? + AND a.created_at BETWEEN ? and NOW() + GROUP BY 2,3,4 + ORDER BY count DESC + )t1 + JOIN sku_name t2 ON t2.id = t1.name_id + ` + sqlParams := []interface{}{ + utils.DefaultTimeValue, + utils.DefaultTimeValue, + cityCode, + salePriceLimit, + orderCreate, + } + err = GetRows(db, &skuNameAndPlace, sql, sqlParams...) + return skuNameAndPlace, err +} + func GetTopCategoriesByStoreIDs(db *DaoDB, storeIDs []int, limit int) (skuCategory []*model.SkuCategory, err error) { sql := ` SELECT DISTINCT t5.* FROM( @@ -1102,7 +1140,7 @@ func GetTopCategoriesByStoreIDs(db *DaoDB, storeIDs []int, limit int) (skuCatego Order by t4.count DESC)t5 LIMIT ? ` - sqlParams = append(sqlParams, time.Now().AddDate(0, -1, 0), 100, 2, utils.DefaultTimeValue, 1, limit) + sqlParams = append(sqlParams, time.Now().AddDate(0, -1, 0), salePriceLimit, 2, utils.DefaultTimeValue, 1, limit) err = GetRows(db, &skuCategory, sql, sqlParams...) return skuCategory, err } diff --git a/controllers/cms_store_sku.go b/controllers/cms_store_sku.go index f99bdacd7..b9cfc6432 100644 --- a/controllers/cms_store_sku.go +++ b/controllers/cms_store_sku.go @@ -465,6 +465,21 @@ func (c *StoreSkuController) GetTopSkusByStoreIDs() { }) } +// @Title 根据城市信息查找推荐商品(按销量) +// @Description 根据城市信息查找推荐商品(按销量) +// @Param token header string false "认证token" +// @Param cityCode query int true "城市id" +// @Param storeID query int false "门店id" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetTopSkusByCityCode [get] +func (c *StoreSkuController) GetTopSkusByCityCode() { + c.callGetTopSkusByCityCode(func(params *tStoreSkuGetTopSkusByCityCodeParams) (retVal interface{}, errCode string, err error) { + retVal, err = cms.GetTopSkusByCityCode(params.Ctx, params.CityCode, params.StoreID) + return retVal, "", err + }) +} + // @Title 根据门店信息查找推荐分类(按商品销量) // @Description 根据门店信息查找推荐分类(按商品销量) // @Param token header string false "认证token" diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 2b51ceb30..aa31c9cb3 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1674,6 +1674,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"], + beego.ControllerComments{ + Method: "GetTopSkusByCityCode", + Router: `/GetTopSkusByCityCode`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"], beego.ControllerComments{ Method: "GetTopSkusByStoreIDs", From 322a298223754ac7c109e7542acbfb69913e1fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 24 Dec 2019 11:41:47 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E7=95=85=E9=94=80=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/store_sku.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index b52bd0768..2a76b8296 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -1076,7 +1076,7 @@ func GetTopSkusByCityCode(db *DaoDB, cityCode int, orderCreate time.Time) (skuNa sql := ` SELECT t1.*, t2.* FROM - (SELECT SUM(b.count) count, c.name_id, e.name city_name, d.city_code, + (SELECT SUM(b.count) count, c.name_id, e.name city_name, d.city_code FROM goods_order a JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id AND a.vendor_id = b.vendor_id JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ? From f98ea4eefafeae2c14ac8b637a953b9b9b663d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 24 Dec 2019 11:49:08 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E7=95=85=E9=94=80=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 2 +- business/model/dao/store_sku.go | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index dde8d2252..440256172 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -2239,7 +2239,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam } } } else { - skuNameAndPlace = skuNameAndPlaceList + skuNameAndPlaceList = append(skuNameAndPlaceList,skuNameAndPlace...) } i := 1 for _, v := range skuNameAndPlaceList { diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 2a76b8296..48e315325 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -1074,12 +1074,11 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (storeSkuNameExt []*StoreSk func GetTopSkusByCityCode(db *DaoDB, cityCode int, orderCreate time.Time) (skuNameAndPlace []*SkuNameAndPlace, err error) { sql := ` - SELECT t1.*, t2.* - FROM - (SELECT SUM(b.count) count, c.name_id, e.name city_name, d.city_code + SELECT SUM(b.count) count, c.name_id, e.name city_name, d.city_code FROM goods_order a JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id AND a.vendor_id = b.vendor_id JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ? + JOIN sku_name f ON f.id = c.name_id JOIN store d ON d.id = a.store_id AND d.deleted_at = ? AND d.city_code = ? JOIN place e ON e.code = d.city_code WHERE 1=1 @@ -1087,8 +1086,6 @@ func GetTopSkusByCityCode(db *DaoDB, cityCode int, orderCreate time.Time) (skuNa AND a.created_at BETWEEN ? and NOW() GROUP BY 2,3,4 ORDER BY count DESC - )t1 - JOIN sku_name t2 ON t2.id = t1.name_id ` sqlParams := []interface{}{ utils.DefaultTimeValue, From eff05244dca101f16c67aac3d33782cb93f90c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 24 Dec 2019 11:52:23 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E7=95=85=E9=94=80=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/store_sku.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 48e315325..3a4623055 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -1074,7 +1074,7 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (storeSkuNameExt []*StoreSk func GetTopSkusByCityCode(db *DaoDB, cityCode int, orderCreate time.Time) (skuNameAndPlace []*SkuNameAndPlace, err error) { sql := ` - SELECT SUM(b.count) count, c.name_id, e.name city_name, d.city_code + SELECT SUM(b.count) count, e.name city_name, d.city_code, f.* FROM goods_order a JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id AND a.vendor_id = b.vendor_id JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ? From 52ea751e4577911ef05b3c866ef5214d492acdc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 24 Dec 2019 11:52:34 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E7=95=85=E9=94=80=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/cms_store_sku.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/cms_store_sku.go b/controllers/cms_store_sku.go index b9cfc6432..13f46eaa1 100644 --- a/controllers/cms_store_sku.go +++ b/controllers/cms_store_sku.go @@ -450,7 +450,7 @@ func (c *StoreSkuController) GetMissingStoreSkuFromOrder() { // @Title 根据门店信息查找推荐商品(按销量) // @Description 根据门店信息查找推荐商品(按销量) -// @Param token header string false "认证token" +// @Param token header string true "认证token" // @Param storeIDs query string true "门店列表" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult @@ -467,7 +467,7 @@ func (c *StoreSkuController) GetTopSkusByStoreIDs() { // @Title 根据城市信息查找推荐商品(按销量) // @Description 根据城市信息查找推荐商品(按销量) -// @Param token header string false "认证token" +// @Param token header string true "认证token" // @Param cityCode query int true "城市id" // @Param storeID query int false "门店id" // @Success 200 {object} controllers.CallResult @@ -482,7 +482,7 @@ func (c *StoreSkuController) GetTopSkusByCityCode() { // @Title 根据门店信息查找推荐分类(按商品销量) // @Description 根据门店信息查找推荐分类(按商品销量) -// @Param token header string false "认证token" +// @Param token header string true "认证token" // @Param storeIDs query string true "门店列表" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult From 86def54ea6766cfc50545fc89f6f6df3d971e85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 24 Dec 2019 11:55:52 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E7=95=85=E9=94=80=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 440256172..4cef4929f 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -2190,7 +2190,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam var skuNameList []*model.SkuName //未关注,不可售的商品nameID列表 sql := ` - SELECT DISTINCT b.name_id + SELECT DISTINCT b.name_id id FROM store_sku_bind a JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ? WHERE a.deleted_at = ? @@ -2203,7 +2203,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam AND a.store_id = ? AND a.status = ?) UNION - SELECT DISTINCT a.name_id + SELECT DISTINCT a.name_id id FROM sku a LEFT JOIN (SELECT DISTINCT b.name_id FROM store_sku_bind a @@ -2239,7 +2239,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam } } } else { - skuNameAndPlaceList = append(skuNameAndPlaceList,skuNameAndPlace...) + skuNameAndPlaceList = append(skuNameAndPlaceList, skuNameAndPlace...) } i := 1 for _, v := range skuNameAndPlaceList { From 471b2c63fc9a61bd837c2d9165dde80a127405de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 24 Dec 2019 13:33:27 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E7=95=85=E9=94=80=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 5 +++-- business/model/dao/store_sku.go | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 4cef4929f..b773238f0 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -2190,7 +2190,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam var skuNameList []*model.SkuName //未关注,不可售的商品nameID列表 sql := ` - SELECT DISTINCT b.name_id id + SELECT DISTINCT b.name_id id,1 brand_id FROM store_sku_bind a JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ? WHERE a.deleted_at = ? @@ -2203,7 +2203,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam AND a.store_id = ? AND a.status = ?) UNION - SELECT DISTINCT a.name_id id + SELECT DISTINCT a.name_id id,0 brand_id FROM sku a LEFT JOIN (SELECT DISTINCT b.name_id FROM store_sku_bind a @@ -2235,6 +2235,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam } for _, v := range skuNameAndPlace { if skuNameMap[v.ID] != nil { + v.Type = v.BrandID skuNameAndPlaceList = append(skuNameAndPlaceList, v) } } diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 3a4623055..82d24bd31 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -202,6 +202,7 @@ type SkuNameAndPlace struct { CityName string `json:"cityName"` Sequence int `json:"sequence"` Count int `json:"count"` + Type int `json:"type"` } // todo 应该通过需要同步的skuid来驱动同步分类,而不是当前这种分开的逻辑 From 7408b877429b07234dde25ae14f3a4042fa58581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 24 Dec 2019 13:39:52 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E7=95=85=E9=94=80=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index b773238f0..af727e547 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -2235,7 +2235,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam } for _, v := range skuNameAndPlace { if skuNameMap[v.ID] != nil { - v.Type = v.BrandID + v.Type = skuNameMap[v.ID].BrandID skuNameAndPlaceList = append(skuNameAndPlaceList, v) } } From ac10d134ea39e0cbe5aefc1a2c72e99bbd886fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 24 Dec 2019 14:07:28 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E7=95=85=E9=94=80=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/dao/store_sku.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 82d24bd31..730f8f7d1 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -1080,7 +1080,7 @@ func GetTopSkusByCityCode(db *DaoDB, cityCode int, orderCreate time.Time) (skuNa JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id AND a.vendor_id = b.vendor_id JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ? JOIN sku_name f ON f.id = c.name_id - JOIN store d ON d.id = a.store_id AND d.deleted_at = ? AND d.city_code = ? + JOIN store d ON d.id = IF(a.jx_store_id = 0,a.store_id,a.jx_store_id) AND d.deleted_at = ? AND d.city_code = ? JOIN place e ON e.code = d.city_code WHERE 1=1 AND b.sale_price > ? From a2fe344e18bf85e1f5c15b7bdf5f06f48addb64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 24 Dec 2019 16:39:58 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E6=A0=B9=E6=8D=AEskuid=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=85=B3=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 85 +++++++++++++++++++++++++++ controllers/cms_store_sku.go | 17 ++++++ routers/commentsRouter_controllers.go | 9 +++ 3 files changed, 111 insertions(+) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index af727e547..06a6a6f6a 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -2734,3 +2734,88 @@ func WriteToExcelNormal(task *tasksch.SeqTask, fileName string, excelParam []Exc } return err } + +func FocusStoreSkusByExcel(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync, isContinueWhenError bool) (hint string, err error) { + if len(files) == 0 { + return "", errors.New("没有文件上传!") + } + fileHeader := files[0] + file, err := fileHeader.Open() + hint, err = FocusStoreSkusByExcelBin(ctx, file, isAsync, isContinueWhenError) + file.Close() + return hint, err +} + +func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) { + var ( + skuMap = make(map[int]int) + skuNameMap = make(map[int]int) + skuBindInfos []*StoreSkuBindInfo + db = dao.GetDB() + storeIDs []int + skuIDs []int + price int + ) + sheetParam := &SheetParam{ + OutSkuIDCol: 1, + SkuPriceCol: 3, + SkuRow: 1, + } + xlsx, err := excelize.OpenReader(reader) + if err != nil { + return "", err + } + rows, _ := xlsx.GetRows(xlsx.GetSheetName(1)) + for rowNum, row := range rows { + if rowNum < sheetParam.SkuRow { + continue + } + GetCellForFocusStoreSkus(db, rowNum, row, sheetParam, skuMap) + } + for k, _ := range skuMap { + skuIDs = append(skuIDs, k) + } + skuList, err := dao.GetSkus(db, skuIDs, nil, nil, nil) + if err != nil && len(skuList) == 0 { + return + } + for _, v := range skuList { + if v.Unit == model.SpecialUnit { + price = model.SpecialSpecQuality / int(utils.Float64TwoInt64(float64(v.SpecQuality))) * skuMap[v.ID] + } + if skuNameMap[v.NameID] < price { + skuNameMap[v.NameID] = price + } + } + for k, v := range skuNameMap { + skuBindInfo := &StoreSkuBindInfo{ + NameID: k, + UnitPrice: v, + IsFocus: 1, + IsSale: 1, + } + skuBindInfos = append(skuBindInfos, skuBindInfo) + } + storeList, err := dao.GetStoreList(db, nil, nil, "") + for _, v := range storeList { + storeIDs = append(storeIDs, v.ID) + } + hint, err = UpdateStoresSkus(ctx, storeIDs, skuBindInfos, false, isAsync, isContinueWhenError) + return hint, err +} + +func GetCellForFocusStoreSkus(db *dao.DaoDB, rowNum int, row []string, sheetParam *SheetParam, skuMap map[int]int) { + var ( + skuID int + price int + ) + for k, cell := range row { + if k == sheetParam.OutSkuIDCol { + skuID = int(utils.Str2Int64(cell)) + } + if k == sheetParam.SkuPriceCol { + price = int(utils.Float64TwoInt64(utils.Str2Float64(cell) * 100)) + } + } + skuMap[skuID] = price +} diff --git a/controllers/cms_store_sku.go b/controllers/cms_store_sku.go index 13f46eaa1..a99af647f 100644 --- a/controllers/cms_store_sku.go +++ b/controllers/cms_store_sku.go @@ -535,6 +535,23 @@ func (c *StoreSkuController) RefreshJxPriceByExcel() { }) } +// @Title 根据Excel中SkuID批量关注商品 +// @Description 根据Excel中SkuID批量关注商品 +// @Param token header string true "认证token" +// @Param isAsync formData bool true "是否异步,缺省是同步" +// @Param isContinueWhenError formData bool true "单个同步失败是否继续,缺省false" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /FocusStoreSkusByExcel [post] +func (c *StoreSkuController) FocusStoreSkusByExcel() { + c.callFocusStoreSkusByExcel(func(params *tStoreSkuFocusStoreSkusByExcelParams) (retVal interface{}, errCode string, err error) { + r := c.Ctx.Request + files := r.MultipartForm.File["userfiles"] + retVal, err = cms.FocusStoreSkusByExcel(params.Ctx, files, params.IsAsync, params.IsContinueWhenError) + return retVal, "", err + }) +} + // @Title 得到门店的分类列表 // @Description 得到门店的分类列表(按商品销量) // @Param token header string false "认证token" diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index aa31c9cb3..c6d91884e 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1611,6 +1611,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"], + beego.ControllerComments{ + Method: "FocusStoreSkusByExcel", + Router: `/FocusStoreSkusByExcel`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"], beego.ControllerComments{ Method: "GetMissingStoreSkuFromOrder",