From b0cd64a358db80f24e0d0d585549bc3a9b57c24a Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 16 Dec 2019 18:05:26 +0800 Subject: [PATCH 1/3] +store/sku/GetStoreCategories --- business/jxstore/cms/store_sku.go | 4 +++ business/model/dao/sku.go | 2 +- business/model/dao/store_sku.go | 40 +++++++++++++++++++++++++++ controllers/cms_store_sku.go | 18 ++++++++++++ routers/commentsRouter_controllers.go | 9 ++++++ 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 126662b55..ce52ec267 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -2473,3 +2473,7 @@ func IsChineseChar(str string) bool { } return false } + +func GetStoreCategories(ctx *jxcontext.Context, storeID, parentID int) (catList []*model.SkuCategory, err error) { + return dao.GetStoreSkuCategories(dao.GetDB(), storeID, parentID) +} diff --git a/business/model/dao/sku.go b/business/model/dao/sku.go index 699e4b185..2884efab4 100644 --- a/business/model/dao/sku.go +++ b/business/model/dao/sku.go @@ -63,7 +63,7 @@ func GetCategories(db *DaoDB, parentID, level int, catIDs []int) (cats []*model. params = append(params, parentID) } if len(catIDs) > 0 { - sql += " AND t1.id (" + GenQuestionMarks(len(catIDs)) + ")" + sql += " AND t1.id IN (" + GenQuestionMarks(len(catIDs)) + ")" params = append(params, catIDs) } if level > 0 { diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index d35415100..4422edfa9 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -1028,6 +1028,46 @@ func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int, limit int) (skuCategor return skuCategory, err } +func GetStoreSkuCategories(db *DaoDB, storeID, parentID int) (catList []*model.SkuCategory, err error) { + sql := ` + SELECT + t1.* + FROM sku_category t1 + JOIN + ( + SELECT DISTINCT t3.category_id + FROM store_sku_bind t1 + JOIN sku t2 ON t2.id = t1.sku_id AND t2.deleted_at = ? AND t2.status = ? + JOIN sku_name t3 ON t3.id = t2.name_id AND t3.deleted_at = ? AND t3.status = ? + WHERE t1.deleted_at = ? AND t1.status = ? AND t1.store_id = ? + ) t2 ON t2.category_id = t1.id + WHERE t1.deleted_at = ?` + sqlParams := []interface{}{ + utils.DefaultTimeValue, model.SkuStatusNormal, + utils.DefaultTimeValue, model.SkuStatusNormal, + utils.DefaultTimeValue, model.SkuStatusNormal, storeID, + utils.DefaultTimeValue, + } + if parentID >= 0 { + sql += " AND t1.parent_id = ?" + sqlParams = append(sqlParams, parentID) + } + sql += " ORDER BY t1.level, t1.seq" + if err = GetRows(db, &catList, sql, sqlParams...); err == nil && len(catList) > 0 { + parentIDMap := make(map[int]int) + for _, v := range catList { + parentIDMap[v.ParentID] = 1 + } + paretnCats, err2 := GetCategories(db, -1, 0, jxutils.IntMap2List(parentIDMap)) + if err = err2; err == nil { + catList = append(catList, paretnCats...) + } else { + catList = nil + } + } + return catList, err +} + func RefershStoreSkusMidPrice(db *DaoDB, storeIDs []int) (count int64, err error) { sql := ` UPDATE store_sku_bind a diff --git a/controllers/cms_store_sku.go b/controllers/cms_store_sku.go index 59fd3b635..cc8c48273 100644 --- a/controllers/cms_store_sku.go +++ b/controllers/cms_store_sku.go @@ -517,3 +517,21 @@ func (c *StoreSkuController) RefreshJxPriceByExcel() { return retVal, "", err }) } + +// @Title 得到门店的分类列表 +// @Description 得到门店的分类列表(按商品销量) +// @Param token header string false "认证token" +// @Param storeID query int true "门店ID" +// @Param parentID query int false "父分类id" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetStoreCategories [get] +func (c *StoreSkuController) GetStoreCategories() { + c.callGetStoreCategories(func(params *tStoreSkuGetStoreCategoriesParams) (retVal interface{}, errCode string, err error) { + if params.MapData["parentID"] == nil { + params.ParentID = -1 + } + retVal, err = cms.GetStoreCategories(params.Ctx, params.StoreID, params.ParentID) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 273fb032d..bda9106aa 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1602,6 +1602,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: "GetStoreCategories", + Router: `/GetStoreCategories`, + 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: "GetStoreSkus", From a0fee1f7566c2acebd34c63c9f4c578df0bc3a9f Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 16 Dec 2019 18:21:16 +0800 Subject: [PATCH 2/3] fk --- business/model/dao/act.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/business/model/dao/act.go b/business/model/dao/act.go index 0137b566d..ec8fd2a47 100644 --- a/business/model/dao/act.go +++ b/business/model/dao/act.go @@ -406,11 +406,11 @@ func GetEffectiveActStoreSkuInfo(db *DaoDB, actID int, vendorIDs []int, actType sqlParams = append(sqlParams, model.GetVendorMask(vendorIDs...), vendorIDs) } if actID > 0 { - sql = " AND t1.act_type = ?" + sql = " AND t1.id = ?" sqlParams = append(sqlParams, actID) } if actType != model.ActTypeAll { - sql = " AND t1.type = ?" + sql = " AND t1.`type` = ?" sqlParams = append(sqlParams, actType) } if len(storeIDs) > 0 { From b985b1a907a8dbf6e8ef5680dc7967bb44b7b04c Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 16 Dec 2019 18:26:29 +0800 Subject: [PATCH 3/3] fk --- business/model/dao/act.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/business/model/dao/act.go b/business/model/dao/act.go index ec8fd2a47..8e3db3c8c 100644 --- a/business/model/dao/act.go +++ b/business/model/dao/act.go @@ -406,11 +406,11 @@ func GetEffectiveActStoreSkuInfo(db *DaoDB, actID int, vendorIDs []int, actType sqlParams = append(sqlParams, model.GetVendorMask(vendorIDs...), vendorIDs) } if actID > 0 { - sql = " AND t1.id = ?" + sql += " AND t1.id = ?" sqlParams = append(sqlParams, actID) } if actType != model.ActTypeAll { - sql = " AND t1.`type` = ?" + sql += " AND t1.type = ?" sqlParams = append(sqlParams, actType) } if len(storeIDs) > 0 {