60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package dao
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
)
|
|
|
|
type PromotionStoreSku struct {
|
|
model.PromotionSku
|
|
StoreID int `orm:"column(store_id)" json:"storeID"`
|
|
}
|
|
|
|
func GenSkuPriceMapKey(storeID, skuID int) (key int64) {
|
|
return int64(storeID)*1000000 + int64(skuID)
|
|
}
|
|
|
|
func GetPromotionSkuPriceMap(db *DaoDB, vendorID int, storeIDs, skuIDs []int, fromTime, toTime time.Time) (skuPriceMap map[int64]*PromotionStoreSku, err error) {
|
|
sql := `
|
|
SELECT t2.store_id, 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 NOT (t1.begin_at > ? OR t1.end_at < ?) AND (t1.status = ? OR t1.status = ?)`
|
|
sqlParams := []interface{}{
|
|
utils.DefaultTimeValue,
|
|
vendorID,
|
|
toTime,
|
|
fromTime,
|
|
model.PromotionStatusRemoteCreated,
|
|
}
|
|
if vendorID == model.VendorIDJX {
|
|
sqlParams = append(sqlParams, model.PromotionStatusLocalCreated)
|
|
} else {
|
|
sqlParams = append(sqlParams, model.PromotionStatusRemoteCreated)
|
|
}
|
|
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)
|
|
}
|
|
sql += " ORDER BY t2.store_id, t3.sku_id, t3.price"
|
|
var skuPriceList []*PromotionStoreSku
|
|
if err = GetRows(db, &skuPriceList, sql, sqlParams...); err != nil {
|
|
return nil, err
|
|
}
|
|
skuPriceMap = make(map[int64]*PromotionStoreSku)
|
|
for _, v := range skuPriceList {
|
|
index := GenSkuPriceMapKey(v.StoreID, v.SkuID)
|
|
if true /*skuPriceMap[index] == nil || v.EarningPrice < skuPriceMap[index].EarningPrice*/ {
|
|
skuPriceMap[index] = v
|
|
}
|
|
}
|
|
return skuPriceMap, err
|
|
}
|