- GetStoreSkus handle zero
This commit is contained in:
@@ -3,6 +3,7 @@ package cms
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -268,10 +269,12 @@ func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword str
|
||||
if params["stFromCount"] != nil {
|
||||
fromCount = params["stFromCount"].(int)
|
||||
}
|
||||
toCount = math.MaxInt32
|
||||
if params["stToCount"] != nil {
|
||||
toCount = params["stToCount"].(int)
|
||||
}
|
||||
if saleInfoList, err = GetStoresSkusSaleInfo(ctx, []int{storeID}, skuIDs, timeList[0], timeList[1], fromCount, toCount); err != nil {
|
||||
// 不能用SQL筛除,否则不能区分是没有销量,还是不在条件中
|
||||
if saleInfoList, err = GetStoresSkusSaleInfo(ctx, []int{storeID}, skuIDs, timeList[0], timeList[1], 0, math.MaxInt32); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
@@ -287,7 +290,7 @@ func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword str
|
||||
if saleInfo == nil && fromCount == 0 {
|
||||
saleInfo = &SkuSaleInfo{}
|
||||
}
|
||||
if saleInfo != nil {
|
||||
if saleInfo != nil && saleInfo.Count >= fromCount && saleInfo.Count <= toCount {
|
||||
sku["times"] = saleInfo.Times
|
||||
sku["count"] = saleInfo.Count
|
||||
newSkus = append(newSkus, sku)
|
||||
@@ -340,16 +343,9 @@ func GetStoresSkusSaleInfo(ctx *jxcontext.Context, storeIDs []int, skuIDs []int,
|
||||
}
|
||||
sql += `
|
||||
GROUP BY 1,2
|
||||
HAVING 1 = 1
|
||||
HAVING count >= ? AND count <= ?
|
||||
`
|
||||
if fromCount > 0 {
|
||||
sql += " AND times >= ?"
|
||||
sqlParams = append(sqlParams, fromCount)
|
||||
}
|
||||
if toCount > 0 {
|
||||
sql += " AND times <= ?"
|
||||
sqlParams = append(sqlParams, toCount)
|
||||
}
|
||||
sqlParams = append(sqlParams, fromCount, toCount)
|
||||
// fmt.Println(sql)
|
||||
// fmt.Println(utils.Format4Output(sqlParams, false))
|
||||
if err = dao.GetRows(db, &saleInfoList, sql, sqlParams...); err == nil {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -205,6 +206,9 @@ func (c *StoreSkuController) GetStoresSkusSaleInfo() {
|
||||
if timeList, err = jxutils.BatchStr2Time(params.StFromTime, params.StToTime); err != nil {
|
||||
return retVal, "", err
|
||||
}
|
||||
if params.MapData["stToToCount"] == nil {
|
||||
params.StToToCount = math.MaxInt32
|
||||
}
|
||||
retVal, err = cms.GetStoresSkusSaleInfo(params.Ctx, storeIDs, skuIDs, timeList[0], timeList[1], params.StFromCount, params.StToToCount)
|
||||
return retVal, "", err
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user