- 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 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) { func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.DaoDB) (err error) {
globals.SugarLogger.Debugf("updateOrderSkuOtherInfo orderID:%s, VendorStoreID:%s", order.VendorOrderID, order.VendorStoreID) globals.SugarLogger.Debugf("updateOrderSkuOtherInfo orderID:%s, VendorStoreID:%s", order.VendorOrderID, order.VendorStoreID)
jxStoreID := jxutils.GetShowStoreIDFromOrder(order) jxStoreID := jxutils.GetShowStoreIDFromOrder(order)
@@ -309,12 +286,14 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
skumapper[v.VendorSkuID] = v skumapper[v.VendorSkuID] = v
} }
skuPriceMap, err2 := getPromotionSkuPriceMap(db, jxStoreID, jxutils.IntMap2List(skuIDMap)) var skuPriceMap map[int]*model.PromotionSku
if err = err2; err != nil { if len(skuIDMap) > 0 {
globals.SugarLogger.Errorf("updateOrderSkuOtherInfo can not get sku promotion info for orderID:%s, error:%v", order.VendorOrderID, err) skuPriceMap, err = dao.GetPromotionSkuPriceMap(db, []int{jxStoreID}, jxutils.IntMap2List(skuIDMap), time.Now(), time.Now())
return err 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 { for _, v := range orderSkus {
v.VendorOrderID = order.VendorOrderID v.VendorOrderID = order.VendorOrderID
v.VendorID = order.VendorID 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 != "" { if skuPriceMap != nil {
index := jxutils.Combine2Int(jxStoreID, int(v.SalePrice)) if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 /*&& v.StoreSubName != ""*/ {
if skuPriceMap[index] != nil { index := skuID
v.EarningPrice = int64(skuPriceMap[index].EarningPrice) if skuPriceMap[index] != nil {
v.EarningPrice = int64(skuPriceMap[index].EarningPrice)
}
} }
} }
} }

View File

@@ -283,13 +283,25 @@ func CreateJdPromotion(ctx *jxcontext.Context, vendorID int, isIDJd bool, isAsyn
Source: PromotionSourceOpenPlatform, Source: PromotionSourceOpenPlatform,
} }
if vendorPromotionID == "" && vendorID == model.VendorIDJD { skuIDs := make([]int, len(params.SkuPrices))
skuIDs := make([]int, len(params.SkuPrices)) skuPriceMap := make(map[int64]*SkuPrice)
skuPriceMap := make(map[int64]*SkuPrice) for k, v := range params.SkuPrices {
for k, v := range params.SkuPrices { skuIDs[k] = v.SkuID
skuIDs[k] = v.SkuID skuPriceMap[int64(v.SkuID)] = v
skuPriceMap[int64(v.SkuID)] = v }
if len(skuIDs) == 0 {
return "", fmt.Errorf("商品列表为空")
}
if vendorID == model.VendorIDJX {
conflictPromotion, err2 := dao.GetPromotionSkuPriceMap(db, params.StoreIDs, skuIDs, promotion.BeginAt, promotion.EndAt)
if err = err2; err != nil {
return "", err
} }
if len(conflictPromotion) > 0 {
return "", fmt.Errorf("有冲突配置:%s", utils.Format4Output(conflictPromotion, true))
}
}
if vendorPromotionID == "" && vendorID == model.VendorIDJD {
sql := ` sql := `
SELECT t1.*, t2.jd_id, t3.vendor_store_id SELECT t1.*, t2.jd_id, t3.vendor_store_id
FROM store_sku_bind t1 FROM store_sku_bind t1

View File

@@ -26,11 +26,12 @@ type GoodsOrderExt struct {
WaybillCreatedAt time.Time `orm:"type(datetime);index" json:"waybillCreatedAt"` WaybillCreatedAt time.Time `orm:"type(datetime);index" json:"waybillCreatedAt"`
WaybillFinishedAt time.Time `orm:"type(datetime)" json:"waybillFinishedAt"` WaybillFinishedAt time.Time `orm:"type(datetime)" json:"waybillFinishedAt"`
SkuID int `orm:"column(sku_id)" json:"skuID,omitempty"` SkuID int `orm:"column(sku_id)" json:"skuID,omitempty"`
SkuShopPrice int `json:"skuShopPrice,omitempty"` SkuShopPrice int `json:"skuShopPrice,omitempty"`
SkuSalePrice int `json:"skuSalePrice,omitempty"` SkuSalePrice int `json:"skuSalePrice,omitempty"`
SkuCount2 int `json:"skuCount2,omitempty"` SkuEarningPrice int `json:"skuEarningPrice,omitempty"`
SkuInfo string `json:"skuInfo,omitempty"` SkuCount2 int `json:"skuCount2,omitempty"`
SkuInfo string `json:"skuInfo,omitempty"`
} }
type OrderSkuExt struct { type OrderSkuExt struct {

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
}