- cms.GetStoresSkus
This commit is contained in:
@@ -27,6 +27,9 @@ const (
|
||||
|
||||
// GetStoreSkus用
|
||||
type StoreSkuNameExt struct {
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
StoreName string
|
||||
|
||||
model.SkuName
|
||||
UnitPrice int `json:"unitPrice"`
|
||||
Skus []map[string]interface{} `orm:"-" json:"skus"`
|
||||
@@ -85,24 +88,27 @@ type StoreOpRequestInfo struct {
|
||||
UnitPrice int `json:"unitPrice"`
|
||||
}
|
||||
|
||||
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, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) {
|
||||
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 := `
|
||||
FROM sku_name t1
|
||||
JOIN sku t2 ON t1.id = t2.name_id AND t2.deleted_at = ?/* AND t2.status = ?*/
|
||||
LEFT JOIN store_sku_bind t4 ON t4.sku_id = t2.id AND t4.deleted_at = ? AND t4.store_id = ?
|
||||
JOIN store t3 ON t3.id = ?
|
||||
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
|
||||
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 t4.status = ?)/* AND t1.status = ?*/
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
// model.SkuStatusNormal,
|
||||
storeIDs,
|
||||
utils.DefaultTimeValue,
|
||||
storeID,
|
||||
storeID,
|
||||
utils.DefaultTimeValue,
|
||||
model.SkuStatusNormal,
|
||||
// model.SkuStatusNormal,
|
||||
@@ -215,7 +221,9 @@ func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword str
|
||||
t1.unit,
|
||||
t1.price,
|
||||
t1.img,
|
||||
t1.elm_img_hash_code`
|
||||
t1.elm_img_hash_code,
|
||||
t3.id,
|
||||
t3.name`
|
||||
if isBySku {
|
||||
sql += `,
|
||||
t2.id`
|
||||
@@ -237,6 +245,8 @@ func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword str
|
||||
t1.price,
|
||||
t1.img,
|
||||
t1.elm_img_hash_code,
|
||||
t3.id store_id,
|
||||
t3.name store_name,
|
||||
CONCAT("[", GROUP_CONCAT(DISTINCT CONCAT('{"id":', t2.id, ',"comment":"', t2.comment, '","status":', t2.status, ',"createdAt":"',
|
||||
CONCAT(REPLACE(IF(t4.created_at IS NULL, '1970-01-01 00:00:00', t4.created_at)," ","T"),"+08:00"), '","updatedAt":"', CONCAT(REPLACE(IF(t4.updated_at IS NULL, '1970-01-01 00:00:00', t4.updated_at)," ","T"),"+08:00"),
|
||||
'","lastOperator":"', IF(t4.last_operator IS NULL, '', t4.last_operator), '","specQuality":', t2.spec_quality, ',"specUnit":"', t2.spec_unit, '","weight":', t2.weight,
|
||||
@@ -317,17 +327,17 @@ func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword str
|
||||
toCount = params["stToCount"].(int)
|
||||
}
|
||||
// 不能用SQL筛除,否则不能区分是没有销量,还是不在条件中
|
||||
if saleInfoList, err = GetStoresSkusSaleInfo(ctx, []int{storeID}, skuIDs, timeList[0], timeList[1], 0, math.MaxInt32); err != nil {
|
||||
if saleInfoList, err = GetStoresSkusSaleInfo(ctx, storeIDs, skuIDs, timeList[0], timeList[1], 0, math.MaxInt32); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
for _, saleInfo := range saleInfoList {
|
||||
saleInfoMap[int64(saleInfo.StoreID)*100000+int64(saleInfo.SkuID)] = saleInfo
|
||||
}
|
||||
storeID2 := int64(storeID) * 100000
|
||||
var newSkuNames []*StoreSkuNameExt
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
var newSkus []map[string]interface{}
|
||||
storeID2 := int64(skuName.StoreID) * 100000
|
||||
for _, sku := range skuName.Skus {
|
||||
saleInfo := saleInfoMap[storeID2+utils.MustInterface2Int64(sku["id"])]
|
||||
if saleInfo == nil && fromCount == 0 {
|
||||
@@ -360,7 +370,7 @@ func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword str
|
||||
for k, skuName := range skuNamesInfo.SkuNames {
|
||||
nameIDs[k] = skuName.ID
|
||||
}
|
||||
pagedInfo, err2 := GetStoreOpRequests(ctx, utils.DefaultTimeValue, utils.DefaultTimeValue, "", []int{storeID}, nameIDs, nil, []int{model.RequestStatusNew}, 0, -1)
|
||||
pagedInfo, err2 := GetStoreOpRequests(ctx, utils.DefaultTimeValue, utils.DefaultTimeValue, "", storeIDs, nameIDs, nil, []int{model.RequestStatusNew}, 0, -1)
|
||||
if err = err2; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user