- GetStoresSkus返回商品活动价格信息
This commit is contained in:
@@ -286,9 +286,9 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
|
||||
skumapper[v.VendorSkuID] = v
|
||||
}
|
||||
|
||||
var skuPriceMap map[int]*model.PromotionSku
|
||||
var skuPriceMap map[int64]*dao.PromotionStoreSku
|
||||
if len(skuIDMap) > 0 {
|
||||
skuPriceMap, err = dao.GetPromotionSkuPriceMap(db, []int{jxStoreID}, jxutils.IntMap2List(skuIDMap), time.Now(), time.Now())
|
||||
skuPriceMap, err = dao.GetPromotionSkuPriceMap(db, model.VendorIDJX, []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
|
||||
@@ -316,7 +316,7 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
|
||||
|
||||
if skuPriceMap != nil {
|
||||
if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 /*&& v.StoreSubName != ""*/ {
|
||||
index := skuID
|
||||
index := dao.GenSkuPriceMapKey(jxStoreID, v.SkuID)
|
||||
if skuPriceMap[index] != nil {
|
||||
v.EarningPrice = int64(skuPriceMap[index].EarningPrice)
|
||||
}
|
||||
|
||||
@@ -191,19 +191,8 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword
|
||||
sql += " AND t1.unit = ?"
|
||||
sqlParams = append(sqlParams, params["unit"].(string))
|
||||
}
|
||||
if params["skuID"] != nil {
|
||||
skuID, ok := params["skuID"].(int)
|
||||
if ok {
|
||||
sql += " AND t2.id = ?"
|
||||
sqlParams = append(sqlParams, skuID)
|
||||
} else { // todo 这里是没有用的,应该删除掉
|
||||
skuIDs := params["skuID"].([]interface{})
|
||||
sql += " AND t2.id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
}
|
||||
var skuIDs []int
|
||||
if params["skuIDs"] != nil {
|
||||
var skuIDs []int
|
||||
if err = utils.UnmarshalUseNumber([]byte(params["skuIDs"].(string)), &skuIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -211,6 +200,13 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword
|
||||
sql += " AND t2.id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
} else if params["skuID"] != nil {
|
||||
skuID, ok := params["skuID"].(int)
|
||||
if ok {
|
||||
skuIDs = append(skuIDs, skuID)
|
||||
sql += " AND t2.id = ?"
|
||||
sqlParams = append(sqlParams, skuID)
|
||||
}
|
||||
}
|
||||
if isFocus {
|
||||
if params["fromStatus"] != nil {
|
||||
@@ -287,7 +283,7 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword
|
||||
CONCAT("[", GROUP_CONCAT(DISTINCT CONCAT('{"id":', t2.id, ',"comment":"', t2.comment, '","status":', t2.status, ',"createdAt":"',
|
||||
CONCAT(REPLACE(IF(t4.created_at IS NULL, '1970-01-01 00:00:00', t4.created_at)," ","T"),"+08:00"), '","updatedAt":"', CONCAT(REPLACE(IF(t4.updated_at IS NULL, '1970-01-01 00:00:00', t4.updated_at)," ","T"),"+08:00"),
|
||||
'","lastOperator":"', IF(t4.last_operator IS NULL, '', t4.last_operator), '","specQuality":', t2.spec_quality, ',"specUnit":"', t2.spec_unit, '","weight":', t2.weight,
|
||||
',"categoryID":', t2.category_id, ',"nameID":', t2.name_id, ',"subStoreID":', IF(t4.sub_store_id IS NULL, 0, t4.sub_store_id),
|
||||
',"categoryID":', t2.category_id, ',"subStoreID":', IF(t4.sub_store_id IS NULL, 0, t4.sub_store_id),
|
||||
',"price":', IF(t4.price IS NULL, 0, t4.price), ',"unitPrice":', IF(t4.unit_price IS NULL, t1.price, t4.unit_price),
|
||||
',"storeSkuStatus":', IF(t4.status IS NULL, 0, t4.status),
|
||||
',"jdID":', t2.jd_id, ',"jdSyncStatus":', IF(t4.jd_sync_status IS NULL, 0, t4.jd_sync_status),
|
||||
@@ -319,6 +315,20 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword
|
||||
// globals.SugarLogger.Debug(sqlData, sqlParams)
|
||||
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
|
||||
skuNamesInfo.TotalCount = dao.GetLastTotalRowCount(db)
|
||||
|
||||
// 活动商品信息
|
||||
jxSkuPriceMap, err2 := dao.GetPromotionSkuPriceMap(db, model.VendorIDJX, storeIDs, skuIDs, time.Now(), time.Now())
|
||||
if err = err2; err != nil {
|
||||
dao.Rollback(db)
|
||||
globals.SugarLogger.Errorf("GetStoresSkus can not get sku promotion info for error:%v", err)
|
||||
return nil, err
|
||||
}
|
||||
jdSkuPriceMap, err2 := dao.GetPromotionSkuPriceMap(db, model.VendorIDJD, storeIDs, skuIDs, time.Now(), time.Now())
|
||||
if err = err2; err != nil {
|
||||
dao.Rollback(db)
|
||||
globals.SugarLogger.Errorf("GetStoresSkus can not get sku promotion info for error:%v", err)
|
||||
return nil, err
|
||||
}
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
if skuName.SkusStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(skuName.SkusStr), &skuName.Skus); err != nil {
|
||||
@@ -328,7 +338,17 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword
|
||||
if len(skuName.Skus) > 0 {
|
||||
skuName.UnitPrice = int(utils.MustInterface2Int64(skuName.Skus[0]["unitPrice"]))
|
||||
for _, v := range skuName.Skus {
|
||||
delete(v, "unitPrice")
|
||||
index := dao.GenSkuPriceMapKey(skuName.StoreID, int(utils.MustInterface2Int64(v["id"])))
|
||||
if jdSkuPriceMap[index] != nil {
|
||||
v["actPrice"] = jdSkuPriceMap[index].Price
|
||||
} else {
|
||||
v["actPrice"] = 0
|
||||
}
|
||||
if jxSkuPriceMap[index] != nil {
|
||||
v["earningPrice"] = jxSkuPriceMap[index].EarningPrice
|
||||
} else {
|
||||
v["earningPrice"] = 0
|
||||
}
|
||||
}
|
||||
} else {
|
||||
skuName.UnitPrice = skuName.Price
|
||||
|
||||
@@ -293,7 +293,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, vendorID int, isIDJd bool, isAsyn
|
||||
return "", fmt.Errorf("商品列表为空")
|
||||
}
|
||||
if vendorID == model.VendorIDJX {
|
||||
conflictPromotion, err2 := dao.GetPromotionSkuPriceMap(db, params.StoreIDs, skuIDs, promotion.BeginAt, promotion.EndAt)
|
||||
conflictPromotion, err2 := dao.GetPromotionSkuPriceMap(db, model.VendorIDJX, params.StoreIDs, skuIDs, promotion.BeginAt, promotion.EndAt)
|
||||
if err = err2; err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -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