- GetStoreSkus handle zero

This commit is contained in:
gazebo
2018-11-29 17:51:09 +08:00
parent 698e3267a8
commit 891766b55b
2 changed files with 11 additions and 11 deletions

View File

@@ -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 {

View File

@@ -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
})