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