- 添加京西活动,用于记录活动商品结算价格
This commit is contained in:
@@ -236,6 +236,29 @@ 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)
|
||||
@@ -253,11 +276,16 @@ func (c *OrderManager) updateOrderSkuOtherInfo(order *model.GoodsOrder, db *dao.
|
||||
orderSkus := order.Skus
|
||||
|
||||
vendorSkuIDs := make([]int64, 0)
|
||||
skuIDMap := make(map[int]int)
|
||||
for _, v := range orderSkus {
|
||||
intVendorSkuID := utils.Str2Int64WithDefault(v.VendorSkuID, 0)
|
||||
if intVendorSkuID != 0 {
|
||||
vendorSkuIDs = append(vendorSkuIDs, intVendorSkuID)
|
||||
}
|
||||
|
||||
if skuID := jxutils.GetSkuIDFromOrderSku(v); skuID > 0 {
|
||||
skuIDMap[skuID] = 1
|
||||
}
|
||||
}
|
||||
if len(vendorSkuIDs) > 0 {
|
||||
tableName := "t2"
|
||||
@@ -281,6 +309,12 @@ 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
|
||||
}
|
||||
|
||||
for _, v := range orderSkus {
|
||||
v.VendorOrderID = order.VendorOrderID
|
||||
v.VendorID = order.VendorID
|
||||
@@ -300,6 +334,13 @@ 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -88,6 +88,7 @@ func (c *OrderManager) GetOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID str
|
||||
t1.sku_name,
|
||||
IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price,
|
||||
t1.sale_price,
|
||||
t1.earning_price,
|
||||
t1.weight,
|
||||
t1.sku_type,
|
||||
t1.promotion_type,
|
||||
@@ -116,6 +117,7 @@ func (c *OrderManager) GetOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID str
|
||||
t1.sku_name,
|
||||
IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price,
|
||||
t1.sale_price,
|
||||
t1.earning_price,
|
||||
t1.weight,
|
||||
t1.sku_type,
|
||||
t1.promotion_type,
|
||||
@@ -145,6 +147,7 @@ func (c *OrderManager) GetOrderSkuInfo(ctx *jxcontext.Context, vendorOrderID str
|
||||
t1.sku_name,
|
||||
IF(t1.shop_price = 0, t1.sale_price, t1.shop_price) shop_price,
|
||||
t1.sale_price,
|
||||
t1.earning_price,
|
||||
t1.weight,
|
||||
t1.sku_type,
|
||||
t1.promotion_type,
|
||||
@@ -285,7 +288,7 @@ func (c *OrderManager) getOrders(ctx *jxcontext.Context, isIncludeSku bool, from
|
||||
t2.actual_fee, t2.desired_fee, t2.waybill_created_at, t2.waybill_finished_at`
|
||||
if isIncludeSku {
|
||||
sql += `,
|
||||
t3.sku_id, t3.count sku_count2, t3.shop_price sku_shop_price, t3.sale_price sku_sale_price`
|
||||
t3.sku_id, t3.count sku_count2, t3.shop_price sku_shop_price, IF(t3.earning_price <> 0, t3.earning_price, t3.sale_price) sku_sale_price`
|
||||
}
|
||||
sql += `
|
||||
FROM goods_order t1
|
||||
|
||||
@@ -72,6 +72,8 @@ type SkuPrice struct {
|
||||
Price int `json:"price"` // 分,这个不是单价,是这个sku的活动价
|
||||
LimitSkuCount int `json:"limitSkuCount"`
|
||||
IsLock int8 `json:"isLock"`
|
||||
|
||||
EarningPrice int `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱
|
||||
}
|
||||
|
||||
type tPromotionItemInfo struct {
|
||||
@@ -230,10 +232,13 @@ func Init() {
|
||||
// scheduleRoutine(true)
|
||||
}
|
||||
|
||||
func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueWhenError bool, vendorPromotionID string, params *PromotionParams, mapData map[string]interface{}) (hint string, err error) {
|
||||
func CreateJdPromotion(ctx *jxcontext.Context, vendorID int, isIDJd bool, isAsync, isContinueWhenError bool, vendorPromotionID string, params *PromotionParams, mapData map[string]interface{}) (hint string, err error) {
|
||||
if vendorPromotionID != "" && len(vendorPromotionID) != len("14863853") {
|
||||
return "", fmt.Errorf("%s看起来不像是一个有效的京东活动ID,请仔细检查一下", vendorPromotionID)
|
||||
}
|
||||
if vendorID != model.VendorIDJD && vendorID != model.VendorIDJX {
|
||||
return "", fmt.Errorf("当前只支持京西与京东活动")
|
||||
}
|
||||
if len(params.SkuPrices) == 0 {
|
||||
return "", ErrEmptySkus
|
||||
}
|
||||
@@ -265,7 +270,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW
|
||||
promotion := &model.Promotion{
|
||||
Name: params.Name,
|
||||
Advertising: params.Advertising,
|
||||
VendorID: model.VendorIDJD,
|
||||
VendorID: vendorID,
|
||||
Type: params.Type,
|
||||
Status: model.PromotionStatusLocalCreated,
|
||||
LimitDevice: int8(limitDevice),
|
||||
@@ -323,7 +328,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW
|
||||
if promotionSkuPrice.PriceType == PriceTypePercentage {
|
||||
promotionSkuPrice.Price = skuBind.Price * promotionSkuPrice.Price / 100
|
||||
}
|
||||
if promotionSkuPrice.Price >= skuBind.Price {
|
||||
if vendorID != model.VendorIDJX && promotionSkuPrice.Price >= skuBind.Price {
|
||||
errMsg += fmt.Sprintf("活动价大于等于原价,storeID:%d, skuID:%d\n", skuBind.StoreID, skuBind.SkuID)
|
||||
}
|
||||
if promotionSkuPrice.LimitSkuCount <= 0 {
|
||||
@@ -407,7 +412,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW
|
||||
}
|
||||
}
|
||||
|
||||
if vendorPromotionID == "" {
|
||||
if vendorID != model.VendorIDJX && vendorPromotionID == "" {
|
||||
promotionHandler := getPromotionHander(params.Type)
|
||||
if promotionHandler == nil {
|
||||
return "", errors.New("非法的活动类型")
|
||||
@@ -879,6 +884,34 @@ func LockPromotionSkus(ctx *jxcontext.Context, promotionID int, isLock int, skuI
|
||||
return num, err
|
||||
}
|
||||
|
||||
func UpdatePromotionSkusEarningPrice(ctx *jxcontext.Context, promotionID int, skuPriceList []*SkuPrice) (num int64, err error) {
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
for _, v := range skuPriceList {
|
||||
var tmpNum int64
|
||||
if tmpNum, err = dao.UpdateEntityLogically(db, &model.PromotionSku{}, map[string]interface{}{
|
||||
"EarningPrice": v.EarningPrice,
|
||||
}, ctx.GetUserName(), map[string]interface{}{
|
||||
"PromotionID": promotionID,
|
||||
model.FieldSkuID: v.SkuID,
|
||||
model.FieldDeletedAt: utils.DefaultTimeValue,
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
num += tmpNum
|
||||
}
|
||||
dao.Commit(db)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func OnStoreStockMsg(msg *jdapi.CallbackStoreStockMsg) (retVal *jdapi.CallbackResponse) {
|
||||
var err error
|
||||
// globals.SugarLogger.Debugf("OnStoreStockMsg IsJdStoreSkuLocked:%t", storeskulock.IsJdStoreSkuLocked(msg.StationNo, msg.SkuId))
|
||||
@@ -1000,7 +1033,7 @@ func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.Callba
|
||||
mapData[keyLimitDevice] = skuResult.LimitDevice
|
||||
mapData[keyLimitPin] = skuResult.LimitPin
|
||||
}
|
||||
_, err = CreateJdPromotion(jxcontext.AdminCtx, false, true, false, utils.Int64ToStr(promotionInfoId), promotionParams, mapData)
|
||||
_, err = CreateJdPromotion(jxcontext.AdminCtx, model.VendorIDJD, false, true, false, utils.Int64ToStr(promotionInfoId), promotionParams, mapData)
|
||||
if dao.IsDuplicateError(err) || err == ErrLimitDeviceIsInvalid {
|
||||
err = nil
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ const (
|
||||
VendorIDMTWM = 1
|
||||
VendorIDELM = 2
|
||||
VendorIDEBAI = 3
|
||||
VendorIDJX = 9 // 这是一个假的京西VendorID
|
||||
VendorIDWSC = 11 // 微盟微商城
|
||||
VendorIDPurchaseEnd = 11
|
||||
VendorIDJX = 99 // 这是一个假的京西VendorID
|
||||
|
||||
VendorIDDeliveryBegin = 101
|
||||
VendorIDDada = 101
|
||||
|
||||
@@ -91,6 +91,7 @@ type OrderSku struct {
|
||||
ShopPrice int64 `json:"shopPrice"` // 京西价
|
||||
VendorPrice int64 `json:"vendorPrice"` // 平台价
|
||||
SalePrice int64 `json:"salePrice"` // 售卖价
|
||||
EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱
|
||||
Weight int `json:"weight"` // 单位为克
|
||||
SkuType int `json:"skuType"` // 当前如果为gift就为1,否则缺省为0
|
||||
PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换
|
||||
|
||||
@@ -75,6 +75,8 @@ type PromotionSku struct {
|
||||
Price int `json:"price"` // 分,活动价,这个不是单价
|
||||
LimitSkuCount int `json:"limitSkuCount"`
|
||||
IsLock int8 `json:"isLock"` // 是否锁定门店商品信息
|
||||
|
||||
EarningPrice int `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱
|
||||
}
|
||||
|
||||
func (*PromotionSku) TableUnique() [][]string {
|
||||
|
||||
Reference in New Issue
Block a user