- dao.GetPromotionSkuPriceMap
- 京西活动要求不能冲突
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,13 +283,25 @@ func CreateJdPromotion(ctx *jxcontext.Context, vendorID int, isIDJd bool, isAsyn
|
||||
Source: PromotionSourceOpenPlatform,
|
||||
}
|
||||
|
||||
if vendorPromotionID == "" && vendorID == model.VendorIDJD {
|
||||
skuIDs := make([]int, len(params.SkuPrices))
|
||||
skuPriceMap := make(map[int64]*SkuPrice)
|
||||
for k, v := range params.SkuPrices {
|
||||
skuIDs[k] = v.SkuID
|
||||
skuPriceMap[int64(v.SkuID)] = v
|
||||
skuIDs := make([]int, len(params.SkuPrices))
|
||||
skuPriceMap := make(map[int64]*SkuPrice)
|
||||
for k, v := range params.SkuPrices {
|
||||
skuIDs[k] = v.SkuID
|
||||
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 := `
|
||||
SELECT t1.*, t2.jd_id, t3.vendor_store_id
|
||||
FROM store_sku_bind t1
|
||||
|
||||
@@ -26,11 +26,12 @@ type GoodsOrderExt struct {
|
||||
WaybillCreatedAt time.Time `orm:"type(datetime);index" json:"waybillCreatedAt"`
|
||||
WaybillFinishedAt time.Time `orm:"type(datetime)" json:"waybillFinishedAt"`
|
||||
|
||||
SkuID int `orm:"column(sku_id)" json:"skuID,omitempty"`
|
||||
SkuShopPrice int `json:"skuShopPrice,omitempty"`
|
||||
SkuSalePrice int `json:"skuSalePrice,omitempty"`
|
||||
SkuCount2 int `json:"skuCount2,omitempty"`
|
||||
SkuInfo string `json:"skuInfo,omitempty"`
|
||||
SkuID int `orm:"column(sku_id)" json:"skuID,omitempty"`
|
||||
SkuShopPrice int `json:"skuShopPrice,omitempty"`
|
||||
SkuSalePrice int `json:"skuSalePrice,omitempty"`
|
||||
SkuEarningPrice int `json:"skuEarningPrice,omitempty"`
|
||||
SkuCount2 int `json:"skuCount2,omitempty"`
|
||||
SkuInfo string `json:"skuInfo,omitempty"`
|
||||
}
|
||||
|
||||
type OrderSkuExt struct {
|
||||
|
||||
48
business/model/dao/promotion.go
Normal file
48
business/model/dao/promotion.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user