Files
jx-callback/business/model/dao/promotion.go
gazebo ae9833361a - dao.GetPromotionSkuPriceMap
- 京西活动要求不能冲突
2019-06-20 11:23:04 +08:00

49 lines
1.4 KiB
Go

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
}