查询物料点订单销量

This commit is contained in:
苏尹岚
2020-03-11 14:15:11 +08:00
parent 65f41defef
commit 6e019ca10e
4 changed files with 69 additions and 0 deletions

View File

@@ -54,6 +54,10 @@ type OrderSkusAccept struct {
Img string `json:"img"`
}
type OrderCount struct {
Count int `json:"count"`
}
func (c *OrderManager) GetStoreOrderCountInfo(ctx *jxcontext.Context, storeID, lastHours int, isIncludeFake bool) (countInfo []*model.GoodsOrderCountInfo, err error) {
globals.SugarLogger.Debugf("GetStoreOrderCountInfo storeID:%d", storeID)
if lastHours > maxLastHours {
@@ -1168,3 +1172,42 @@ func GetOrdersAccept(ctx *jxcontext.Context, storeID int) (result []*OrderSkusAc
err = dao.GetRows(db, &result, sql, sqlParams)
return result, err
}
func GetMatterStoreOrderCount(ctx *jxcontext.Context, storeID int) (count int, err error) {
var (
db = dao.GetDB()
goodsOrder *model.GoodsOrder
orderCount *OrderCount
orderTime time.Time
)
sql := `
SELECT *
FROM goods_order
WHERE IF(store_id = 0,jx_store_id,store_id) = 666666
AND from_store_id = ?
ORDER BY order_created_at DESC
LIMIT 1
`
sqlParams := []interface{}{storeID}
err = dao.GetRow(db, &goodsOrder, sql, sqlParams)
if goodsOrder != nil {
orderTime = goodsOrder.OrderFinishedAt
} else {
orderTime = time.Now().AddDate(0, -1, 0)
}
sql2 := `
SELECT COUNT(*) count
FROM goods_order
WHERE IF(store_id = 0,jx_store_id,store_id) = ?
AND order_created_at <= NOW() AND order_created_at >= ?
`
sqlParams2 := []interface{}{
storeID,
orderTime,
}
err = dao.GetRow(db, &orderCount, sql2, sqlParams2)
if err != nil {
return 0, err
}
return orderCount.Count, err
}