- 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

@@ -236,29 +236,6 @@ func (c *OrderManager) SaveOrder(order *model.GoodsOrder, isAdjust bool, db *dao
return isDuplicated, err
}
func getPromotionSkuPriceMap(db *dao.DaoDB, storeID int, skuIDs []int) (skuPriceMap map[int64]*model.PromotionSku, err error) {
sql := `
SELECT t3.*
FROM promotion t1
JOIN promotion_store t2 ON t2.promotion_id = t1.id AND t2.store_id = ?
JOIN promotion_sku t3 ON t3.promotion_id = t1.id AND t3.sku_id IN (` + dao.GenQuestionMarks(len(skuIDs)) + `) AND t3.earning_price > 0
WHERE t1.deleted_at = ? AND (t1.status = ? OR t1.status = ?) AND (t1.begin_at <= NOW() AND t1.end_at >= NOW()) AND t1.vendor_id = ?`
var skuPriceList []*model.PromotionSku
if err = dao.GetRows(db, &skuPriceList, sql, storeID, skuIDs, utils.DefaultTimeValue, model.PromotionStatusLocalCreated, model.PromotionStatusRemoteCreated, model.VendorIDJX); err != nil {
return nil, err
}
skuPriceMap = make(map[int64]*model.PromotionSku)
for _, v := range skuPriceList {
if v.EarningPrice > 0 {
index := jxutils.Combine2Int(v.SkuID, v.Price)
if skuPriceMap[index] == nil || v.EarningPrice < skuPriceMap[index].EarningPrice {
skuPriceMap[index] = v
}
}
}
return skuPriceMap, err
}
func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.DaoDB) (err error) {
globals.SugarLogger.Debugf("updateOrderSkuOtherInfo orderID:%s, VendorStoreID:%s", order.VendorOrderID, order.VendorStoreID)
jxStoreID := jxutils.GetShowStoreIDFromOrder(order)
@@ -309,12 +286,14 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
skumapper[v.VendorSkuID] = v
}
skuPriceMap, err2 := getPromotionSkuPriceMap(db, jxStoreID, jxutils.IntMap2List(skuIDMap))
if err = err2; err != nil {
globals.SugarLogger.Errorf("updateOrderSkuOtherInfo can not get sku promotion info for orderID:%s, error:%v", order.VendorOrderID, err)
return err
var skuPriceMap map[int]*model.PromotionSku
if len(skuIDMap) > 0 {
skuPriceMap, err = dao.GetPromotionSkuPriceMap(db, []int{jxStoreID}, jxutils.IntMap2List(skuIDMap), time.Now(), time.Now())
if err != nil {
globals.SugarLogger.Errorf("updateOrderSkuOtherInfo can not get sku promotion info for orderID:%s, error:%v", order.VendorOrderID, err)
return err
}
}
for _, v := range orderSkus {
v.VendorOrderID = order.VendorOrderID
v.VendorID = order.VendorID
@@ -335,10 +314,12 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
}
}
if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 && v.StoreSubName != "" {
index := jxutils.Combine2Int(jxStoreID, int(v.SalePrice))
if skuPriceMap[index] != nil {
v.EarningPrice = int64(skuPriceMap[index].EarningPrice)
if skuPriceMap != nil {
if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 /*&& v.StoreSubName != ""*/ {
index := skuID
if skuPriceMap[index] != nil {
v.EarningPrice = int64(skuPriceMap[index].EarningPrice)
}
}
}
}