- GetStoresSkus返回商品活动价格信息
This commit is contained in:
@@ -7,20 +7,33 @@ import (
|
||||
"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) {
|
||||
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 t3.*
|
||||
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 (t1.status = ? OR t1.status = ?) AND (t1.begin_at <= ? AND t1.end_at >= ?)`
|
||||
WHERE t1.deleted_at = ? AND t1.vendor_id = ? AND (t1.begin_at <= ? AND t1.end_at >= ?) AND (t1.status = ? OR t1.status = ?)`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
model.VendorIDJX,
|
||||
model.PromotionStatusLocalCreated,
|
||||
model.PromotionStatusRemoteCreated,
|
||||
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)) + ")"
|
||||
@@ -30,15 +43,15 @@ func GetPromotionSkuPriceMap(db *DaoDB, storeIDs, skuIDs []int, fromTime, toTime
|
||||
sql += " AND t3.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
|
||||
var skuPriceList []*model.PromotionSku
|
||||
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[int]*model.PromotionSku)
|
||||
skuPriceMap = make(map[int64]*PromotionStoreSku)
|
||||
for _, v := range skuPriceList {
|
||||
if v.EarningPrice > 0 {
|
||||
index := v.SkuID
|
||||
index := GenSkuPriceMapKey(v.StoreID, v.SkuID)
|
||||
if skuPriceMap[index] == nil || v.EarningPrice < skuPriceMap[index].EarningPrice {
|
||||
skuPriceMap[index] = v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user