尝试解决商城topskus重复问题

This commit is contained in:
苏尹岚
2020-03-03 11:09:06 +08:00
parent 670c1d81bf
commit e6e8bcfde6
2 changed files with 21 additions and 7 deletions

View File

@@ -2314,16 +2314,30 @@ func ReCalculateJxPriceLight(db *dao.DaoDB, ctx *jxcontext.Context, storeID int)
return err
}
func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (storeSkuNameExt []*dao.StoreSkuNameExt, err error) {
func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (storeSkuNameExt2 []*dao.StoreSkuNameExt, err error) {
var (
db = dao.GetDB()
skuMap = make(map[int]*dao.StoreSkuNameExt)
)
if len(storeIDs) == 0 {
return storeSkuNameExt, err
return storeSkuNameExt2, err
}
db := dao.GetDB()
storeSkuNameExt, err = dao.GetTopSkusByStoreIDs(db, storeIDs)
storeSkuNameExt, err := dao.GetTopSkusByStoreIDs(db, storeIDs)
if err != nil {
return nil, err
}
return storeSkuNameExt, err
for _, v := range storeSkuNameExt {
if skuMap[v.SkuID] == nil {
skuMap[v.SkuID] = v
}
if skuMap[v.SkuID] != nil && v.Count != 0 {
skuMap[v.SkuID] = v
}
}
for _, v := range skuMap {
storeSkuNameExt2 = append(storeSkuNameExt2, v)
}
return storeSkuNameExt2, err
}
func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNameAndPlaceList []*dao.SkuNameAndPlace, err error) {

View File

@@ -148,6 +148,7 @@ type StoreSkuNameExt struct {
PendingOpType int8 `json:"pendingOpType"` // 取值同 StoreOpRequest.Type
PendingUnitPrice int `json:"pendingUnitPrice"` // 这个是待审核的价格申请
RealMidUnitPrice int `json:"realMidUnitPrice"`
Count int `json:"count"`
}
// GetStoreSkus用
@@ -967,7 +968,6 @@ func GetStoreSkusByNameIDs(db *DaoDB, storeIDs []int, nameID int) (skuList []*St
func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (storeSkuNameExt []*StoreSkuNameExt, err error) {
sql := `
SELECT DISTINCT t1.* FROM(
SELECT t1.count, t2.id sku_id, t3.*, t1.store_id, t1.store_name
FROM(
SELECT SUM(b.count) count,c.id,a.store_id,d.name store_name
@@ -1018,7 +1018,7 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (storeSkuNameExt []*StoreSk
AND a.status = ?
AND a.deleted_at = ?
AND (d.type = ? OR d.type = ?)
ORDER BY 1 DESC) t1
ORDER BY 1 DESC
LIMIT ?
`
sqlParams = append(sqlParams, model.StoreSkuBindStatusNormal, utils.DefaultTimeValue, model.ActSkuDirectDown, model.ActSkuSecKill, 30)