diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index b381ea969..ac000d4a2 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -105,23 +105,24 @@ const ( maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数 ) -func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) { - return GetStoresSkus(ctx, []int{storeID}, isFocus, keyword, isBySku, params, offset, pageSize) +func GetStoreSkus(ctx *jxcontext.Context, storeID int, skuIDs []int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) { + return GetStoresSkus(ctx, []int{storeID}, skuIDs, isFocus, keyword, isBySku, params, offset, pageSize) } -// 商品不可售,直接排除 -// 如果门店商品是可售状态,那么会忽略区域限制。否则有区域限制 -func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) { - db := dao.GetDB() - sql := ` +func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}) (sql string, sqlParams []interface{}, err error) { + sql = ` FROM sku_name t1 JOIN sku t2 ON t1.id = t2.name_id AND t2.deleted_at = ?/* AND t2.status = ?*/ - JOIN store t3 ON t3.id IN (` + dao.GenQuestionMarks(len(storeIDs)) + `) - LEFT JOIN store_sku_bind t4 ON t4.sku_id = t2.id AND t4.deleted_at = ? AND t4.store_id = t3.id + JOIN store t3 ON t3.id IN (` + dao.GenQuestionMarks(len(storeIDs)) + `)` + if !isFocus { + sql += " LEFT" + } + sql += ` + JOIN store_sku_bind t4 ON t4.sku_id = t2.id AND t4.deleted_at = ? AND t4.store_id = t3.id LEFT JOIN sku_name_place_bind t5 ON t1.id = t5.name_id AND t3.city_code = t5.place_code WHERE t1.deleted_at = ? AND (t1.is_global = 1 OR t5.id IS NOT NULL OR 1 = ?)/* AND t1.status = ?*/ ` - sqlParams := []interface{}{ + sqlParams = []interface{}{ utils.DefaultTimeValue, // model.SkuStatusNormal, storeIDs, @@ -131,10 +132,10 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword // model.SkuStatusNormal, } if isFocus { - sql += " AND t4.sku_id IS NOT NULL AND ((t2.status = ? AND t1.status = ?) OR t4.status = ?)" + sql += " AND ((t2.status = ? AND t1.status = ?) OR t4.status = ?)" sqlParams = append(sqlParams, model.SkuStatusNormal, model.SkuStatusNormal, model.SkuStatusNormal) } else { - sql += " AND t4.sku_id IS NULL AND t2.status = ? AND t1.status = ?" + sql += " AND t4.sku_id IS NULL AND (t2.status = ? AND t1.status = ?)" sqlParams = append(sqlParams, model.SkuStatusNormal, model.SkuStatusNormal) } if keyword != "" { @@ -143,8 +144,12 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike) if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil { - sql += " OR t1.id = ? OR t2.id = ? OR t2.jd_id = ? OR t4.ebai_id = ? OR t4.mtwm_id = ?" - sqlParams = append(sqlParams, keywordInt64, keywordInt64, keywordInt64, keywordInt64, keywordInt64) + sql += " OR t1.id = ? OR t2.id = ? OR t2.jd_id = ?" + sqlParams = append(sqlParams, keywordInt64, keywordInt64, keywordInt64) + if isFocus { + sql += " OR t4.ebai_id = ? OR t4.mtwm_id = ?" + sqlParams = append(sqlParams, keywordInt64, keywordInt64) + } } sql += ")" } @@ -156,7 +161,7 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword if params["nameIDs"] != nil { var nameIDs []int if err = utils.UnmarshalUseNumber([]byte(params["nameIDs"].(string)), &nameIDs); err != nil { - return nil, err + return "", nil, err } if len(nameIDs) > 0 { sql += " AND t1.id IN (" + dao.GenQuestionMarks(len(nameIDs)) + ")" @@ -167,7 +172,7 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword cat := &model.SkuCategory{} cat.ID = params["categoryID"].(int) if err = dao.GetEntity(db, cat); err != nil { - return nil, err + return "", nil, err } sql += " AND (t1.category_id = ?" sqlParams = append(sqlParams, cat.ID) @@ -193,15 +198,9 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword sql += " AND t1.unit = ?" sqlParams = append(sqlParams, params["unit"].(string)) } - var skuIDs []int - if params["skuIDs"] != nil { - if err = utils.UnmarshalUseNumber([]byte(params["skuIDs"].(string)), &skuIDs); err != nil { - return nil, err - } - if len(skuIDs) > 0 { - sql += " AND t2.id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")" - sqlParams = append(sqlParams, skuIDs) - } + if len(skuIDs) > 0 { + sql += " AND t2.id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")" + sqlParams = append(sqlParams, skuIDs) } else if params["skuID"] != nil { skuID, ok := params["skuID"].(int) if ok { @@ -223,7 +222,7 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword if params["jdSyncStatus"] != nil || params["ebaiSyncStatus"] != nil || params["mtwmSyncStatus"] != nil { realVendorMap, err2 := getValidStoreVendorMap(db, storeIDs) if err = err2; err != nil { - return nil, err + return "", nil, err } sql += " AND ( 1 = 0" if params["jdSyncStatus"] != nil && realVendorMap[model.VendorIDJD] == 1 { @@ -241,6 +240,17 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword sql += ")" } } + return sql, sqlParams, err +} + +// 商品不可售,直接排除 +// 如果门店商品是可售状态,那么会忽略区域限制。否则有区域限制 +func GetStoresSkus(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) { + db := dao.GetDB() + sql, sqlParams, err := getGetStoresSkusBaseSQL(db, storeIDs, skuIDs, isFocus, keyword, isBySku, params) + if err != nil { + return nil, err + } sql += ` GROUP BY t1.id, diff --git a/controllers/cms_store_sku.go b/controllers/cms_store_sku.go index 5b080ecd1..3299d8896 100644 --- a/controllers/cms_store_sku.go +++ b/controllers/cms_store_sku.go @@ -48,7 +48,10 @@ type StoreSkuController struct { // @router /GetStoreSkus [get] func (c *StoreSkuController) GetStoreSkus() { c.callGetStoreSkus(func(params *tStoreSkuGetStoreSkusParams) (retVal interface{}, errCode string, err error) { - retVal, err = cms.GetStoreSkus(params.Ctx, params.StoreID, params.IsFocus, params.Keyword, params.IsBySku, params.MapData, params.Offset, params.PageSize) + var skuIDs []int + if err = jxutils.Strings2Objs(params.SkuIDs, &skuIDs); err == nil { + retVal, err = cms.GetStoreSkus(params.Ctx, params.StoreID, skuIDs, params.IsFocus, params.Keyword, params.IsBySku, params.MapData, params.Offset, params.PageSize) + } return retVal, "", err }) } @@ -84,9 +87,9 @@ func (c *StoreSkuController) GetStoreSkus() { // @router /GetStoresSkus [get] func (c *StoreSkuController) GetStoresSkus() { c.callGetStoresSkus(func(params *tStoreSkuGetStoresSkusParams) (retVal interface{}, errCode string, err error) { - var storeIDs []int - if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err == nil { - retVal, err = cms.GetStoresSkus(params.Ctx, storeIDs, params.IsFocus, params.Keyword, params.IsBySku, params.MapData, params.Offset, params.PageSize) + var storeIDs, skuIDs []int + if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.SkuIDs, &skuIDs); err == nil { + retVal, err = cms.GetStoresSkus(params.Ctx, storeIDs, skuIDs, params.IsFocus, params.Keyword, params.IsBySku, params.MapData, params.Offset, params.PageSize) } return retVal, "", err })