- dao.GetPromotionSkuPriceMap

- 京西活动要求不能冲突
This commit is contained in:
gazebo
2019-06-20 11:20:28 +08:00
parent bb7834c268
commit ae9833361a
4 changed files with 85 additions and 43 deletions

View File

@@ -0,0 +1,48 @@
package dao
import (
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
)
func GetPromotionSkuPriceMap(db *DaoDB, storeIDs, skuIDs []int, fromTime, toTime time.Time) (skuPriceMap map[int]*model.PromotionSku, err error) {
sql := `
SELECT t3.*
FROM promotion t1
JOIN promotion_store t2 ON t2.promotion_id = t1.id
JOIN promotion_sku t3 ON t3.promotion_id = t1.id
WHERE t1.deleted_at = ? AND t1.vendor_id = ? AND (t1.status = ? OR t1.status = ?) AND (t1.begin_at <= ? AND t1.end_at >= ?)`
sqlParams := []interface{}{
utils.DefaultTimeValue,
model.VendorIDJX,
model.PromotionStatusLocalCreated,
model.PromotionStatusRemoteCreated,
toTime,
fromTime,
}
if len(storeIDs) > 0 {
sql += " AND t2.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
sqlParams = append(sqlParams, storeIDs)
}
if len(skuIDs) > 0 {
sql += " AND t3.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
sqlParams = append(sqlParams, skuIDs)
}
var skuPriceList []*model.PromotionSku
if err = GetRows(db, &skuPriceList, sql, sqlParams...); err != nil {
return nil, err
}
skuPriceMap = make(map[int]*model.PromotionSku)
for _, v := range skuPriceList {
if v.EarningPrice > 0 {
index := v.SkuID
if skuPriceMap[index] == nil || v.EarningPrice < skuPriceMap[index].EarningPrice {
skuPriceMap[index] = v
}
}
}
return skuPriceMap, err
}