- 营销活动API临时版本
This commit is contained in:
@@ -172,6 +172,7 @@ type IStoreManager interface {
|
||||
// 所有非以Sync,Refresh开头的函数不用自己清理sync_status标记(VendorSync统一处理)
|
||||
|
||||
type IPurchasePlatformHandler interface {
|
||||
// IPurchasePlatformPromotionHandler
|
||||
GetVendorID() int
|
||||
|
||||
GetStatusFromVendorStatus(vendorStatus string) int
|
||||
|
||||
23
business/partner/partner_act.go
Normal file
23
business/partner/partner_act.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type IPurchasePlatformPromotionHandler interface {
|
||||
// 如果是单品级活动,actOrderRules为空
|
||||
// 如果是订单级活动,actStoreSku可以为空(表示不限制SKU)
|
||||
CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error)
|
||||
UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error)
|
||||
DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error)
|
||||
}
|
||||
|
||||
func ActStoreSku2Map(actStoreSku []*model.ActStoreSku2) (actStoreSkuMap map[int][]*model.ActStoreSku2) {
|
||||
actStoreSkuMap = make(map[int][]*model.ActStoreSku2)
|
||||
for _, storeSku := range actStoreSku {
|
||||
actStoreSkuMap[storeSku.StoreID] = append(actStoreSkuMap[storeSku.StoreID], storeSku)
|
||||
}
|
||||
return actStoreSkuMap
|
||||
}
|
||||
184
business/partner/purchase/ebai/act.go
Normal file
184
business/partner/purchase/ebai/act.go
Normal file
@@ -0,0 +1,184 @@
|
||||
package ebai
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func actType2Ebai(actType int) int {
|
||||
if actType < model.ActOrderBegin {
|
||||
return ebaiapi.ActivityTypeDirectDown
|
||||
}
|
||||
return ebaiapi.ActivityTypeFullDiscount
|
||||
}
|
||||
|
||||
func actOrderRules2Ebai(actOrderRules []*model.ActOrderRule) (ebaiRules []*ebaiapi.ActivityRule) {
|
||||
for _, v := range actOrderRules {
|
||||
ebaiRules = append(ebaiRules, &ebaiapi.ActivityRule{
|
||||
Accords: int(jxutils.IntPrice2Standard(v.SalePrice)),
|
||||
Sale: int(jxutils.IntPrice2Standard(v.DeductPrice)),
|
||||
})
|
||||
}
|
||||
return ebaiRules
|
||||
}
|
||||
|
||||
func actStoreSu2Ebai4Add(oneStoreActSku []*model.ActStoreSku2) (skus []*ebaiapi.ActivitySkuInfo4Add) {
|
||||
for _, v := range oneStoreActSku {
|
||||
if model.IsSyncStatusNeedCreate(v.SyncStatus) {
|
||||
skus = append(skus, &ebaiapi.ActivitySkuInfo4Add{
|
||||
SkuID: v.VendorSkuID,
|
||||
SpecialPrice: v.ActPrice,
|
||||
})
|
||||
}
|
||||
}
|
||||
return skus
|
||||
}
|
||||
|
||||
func actStoreSu2Ebai4Update(oneStoreActSku []*model.ActStoreSku2) (skus []*ebaiapi.ActivitySkuInfo4Update) {
|
||||
for _, v := range oneStoreActSku {
|
||||
if model.IsSyncStatusNeedUpdate(v.SyncStatus) {
|
||||
skus = append(skus, &ebaiapi.ActivitySkuInfo4Update{
|
||||
ShopID: utils.Int2Str(v.StoreID),
|
||||
SkuID: v.VendorSkuID,
|
||||
SpecialPrice: v.ActPrice,
|
||||
})
|
||||
}
|
||||
}
|
||||
return skus
|
||||
}
|
||||
|
||||
func actStoreSu2Ebai4Delete(oneStoreActSku []*model.ActStoreSku2) (skus []string) {
|
||||
for _, v := range oneStoreActSku {
|
||||
if model.IsSyncStatusNeedDelete(v.SyncStatus) {
|
||||
skus = append(skus, v.VendorSkuID)
|
||||
}
|
||||
}
|
||||
return skus
|
||||
}
|
||||
|
||||
func act2EbaiActivity(act *model.Act2, actOrderRules []*model.ActOrderRule) (activity *ebaiapi.ActivityInfo) {
|
||||
activity = &ebaiapi.ActivityInfo{
|
||||
ActivityName: act.Name,
|
||||
ActivityType: actType2Ebai(act.Type),
|
||||
StartTime: act.BeginAt.Unix(),
|
||||
EndTime: act.EndAt.Unix(),
|
||||
ActivityDesc: act.Advertising,
|
||||
ShowCategory: act.Name,
|
||||
PromotionSkuDesc: act.Name,
|
||||
Rule: actOrderRules2Ebai(actOrderRules),
|
||||
}
|
||||
return activity
|
||||
}
|
||||
|
||||
func createOneShopAct(shopID string, activity *ebaiapi.ActivityInfo, oneStoreActSku []*model.ActStoreSku2) (ebaiActIDStr string, err error) {
|
||||
if globals.EnableEbaiStoreWrite {
|
||||
ebaiActID, err := api.EbaiAPI.ActivityCreate(shopID, 0, 0, activity)
|
||||
if err == nil {
|
||||
ebaiActIDStr = utils.Int64ToStr(ebaiActID)
|
||||
_, err = ActivitySkuAddBatch(ebaiActID, shopID, 0, activity.ActivityType, actStoreSu2Ebai4Add(oneStoreActSku), false)
|
||||
}
|
||||
} else {
|
||||
ebaiActIDStr = utils.Int64ToStr(jxutils.GenFakeID())
|
||||
}
|
||||
return ebaiActIDStr, err
|
||||
}
|
||||
|
||||
func ActivitySkuAddBatch(activityID int64, shopID string, baiduShopID int64, activityType int, skuList []*ebaiapi.ActivitySkuInfo4Add, isSkuIDCustom bool) (successIDs []string, err error) {
|
||||
return api.EbaiAPI.ActivitySkuAddBatch(activityID, shopID, baiduShopID, activityType, skuList, isSkuIDCustom)
|
||||
}
|
||||
|
||||
func ActivitySkuDeleteBatch(activityID int64, shopID string, baiduShopID int64, skuIDs []string, isSkuIDCustom bool) (successIDs []string, err error) {
|
||||
return api.EbaiAPI.ActivitySkuDeleteBatch(activityID, shopID, baiduShopID, skuIDs, isSkuIDCustom)
|
||||
}
|
||||
|
||||
func ActivitySkuUpdateBatch(activityID int64, actSkuInfoList []*ebaiapi.ActivitySkuInfo4Update) (faildInfoList []string, err error) {
|
||||
return api.EbaiAPI.ActivitySkuUpdateBatch(activityID, actSkuInfoList)
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
activity := act2EbaiActivity(act, actOrderRules)
|
||||
if act.Type < model.ActOrderBegin {
|
||||
actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku)
|
||||
task := tasksch.NewParallelTask("ebai CreateAct", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*model.ActStore2)
|
||||
store.VendorActID, err = createOneShopAct(utils.Int2Str(store.StoreID), activity, actStoreSkuMap[store.StoreID])
|
||||
return nil, err
|
||||
}, actStoreMap)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
if act.Type < model.ActOrderBegin {
|
||||
actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku)
|
||||
if len(actStoreMap2Remove) > 0 {
|
||||
if err = c.DeleteAct(ctx, parentTask, act, actStoreMap2Remove, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range actStoreMap2Remove {
|
||||
delete(actStoreSkuMap, v.StoreID)
|
||||
}
|
||||
}
|
||||
if len(actStoreMap2Add) > 0 {
|
||||
if err = c.CreateAct(ctx, parentTask, act, actOrderRules, actStoreMap2Add, actStoreSku); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range actStoreMap2Add {
|
||||
delete(actStoreSkuMap, v.StoreID)
|
||||
}
|
||||
}
|
||||
task := tasksch.NewParallelTask("ebai UpdateAct", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(*model.ActStore2)
|
||||
if storeSkus := actStoreSkuMap[v.StoreID]; storeSkus != nil {
|
||||
if list := actStoreSu2Ebai4Delete(storeSkus); len(list) > 0 {
|
||||
if _, err = ActivitySkuDeleteBatch(utils.Str2Int64(v.VendorActID), utils.Int2Str(v.StoreID), 0, list, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if list := actStoreSu2Ebai4Add(storeSkus); len(list) > 0 {
|
||||
if _, err = ActivitySkuAddBatch(utils.Str2Int64(v.VendorActID), utils.Int2Str(v.StoreID), 0, actType2Ebai(act.Type), list, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if list := actStoreSu2Ebai4Update(storeSkus); len(list) > 0 {
|
||||
if _, err = ActivitySkuUpdateBatch(utils.Str2Int64(v.VendorActID), list); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}, actStoreMap2Update)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
if act.Type < model.ActOrderBegin {
|
||||
task := tasksch.NewParallelTask("ebai DeleteAct", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(*model.ActStore2)
|
||||
err = api.EbaiAPI.ActivityDisable(utils.Str2Int64(v.VendorActID), utils.Int2Str(v.StoreID), 0, 0)
|
||||
return nil, err
|
||||
}, actStoreMap)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return err
|
||||
}
|
||||
19
business/partner/purchase/elm/act.go
Normal file
19
business/partner/purchase/elm/act.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package elm
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
return err
|
||||
}
|
||||
183
business/partner/purchase/jd/act.go
Normal file
183
business/partner/purchase/jd/act.go
Normal file
@@ -0,0 +1,183 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func CreatePromotionInfos(promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising, traceId string) (infoId int64, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return api.JdAPI.CreatePromotionInfosSingle(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||
} else {
|
||||
return api.JdAPI.CreatePromotionInfosLimitTime(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||
}
|
||||
} else {
|
||||
infoId = jxutils.GenFakeID()
|
||||
}
|
||||
return infoId, err
|
||||
}
|
||||
|
||||
func CreatePromotionRules(promotionType int, infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return api.JdAPI.CreatePromotionRulesSingle(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||
} else {
|
||||
return api.JdAPI.CreatePromotionRulesLimitTime(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func CreatePromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return api.JdAPI.CreatePromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
||||
} else {
|
||||
return api.JdAPI.CreatePromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
||||
}
|
||||
}
|
||||
return skusResult, err
|
||||
}
|
||||
|
||||
func CancelPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return api.JdAPI.CancelPromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
||||
} else {
|
||||
return api.JdAPI.CancelPromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func ConfirmPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return api.JdAPI.ConfirmPromotionSingle(infoId, outInfoId, traceId)
|
||||
} else {
|
||||
return api.JdAPI.ConfirmPromotionLimitTime(infoId, outInfoId, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func CancelPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return api.JdAPI.CancelPromotionSingle(infoId, outInfoId, traceId)
|
||||
} else {
|
||||
return api.JdAPI.CancelPromotionLimitTime(infoId, outInfoId, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func AdjustPromotionTime(promotionType int, infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return api.JdAPI.AdjustPromotionTimeSingle(infoId, outInfoId, endDate, traceId)
|
||||
} else {
|
||||
return api.JdAPI.AdjustPromotionTimeLimitTime(infoId, outInfoId, endDate, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func AdjustPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return api.JdAPI.AdjustPromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
||||
} else {
|
||||
return api.JdAPI.AdjustPromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
||||
}
|
||||
}
|
||||
return skusResult, err
|
||||
}
|
||||
|
||||
func getTraceID(ctx *jxcontext.Context) (traceID string) {
|
||||
traceID = ctx.GetUserName() + utils.GetUUID()
|
||||
return traceID
|
||||
}
|
||||
|
||||
func storeSku2Jd(actStoreSku []*model.ActStoreSku2, handler func(syncStatus int) bool) (jdActStoreSku []*jdapi.PromotionSku) {
|
||||
for _, v := range actStoreSku {
|
||||
if handler(v.SyncStatus) {
|
||||
jdActStoreSku = append(jdActStoreSku, &jdapi.PromotionSku{
|
||||
StationNo: utils.Str2Int64(v.VendorStoreID),
|
||||
SkuID: utils.Str2Int64(v.VendorSkuID),
|
||||
PromotionPrice: v.ActPrice,
|
||||
// LimitSkuCount:0,
|
||||
})
|
||||
}
|
||||
}
|
||||
return jdActStoreSku
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
traceID := getTraceID(ctx)
|
||||
if act.Type < model.ActOrderBegin {
|
||||
outInfoID := utils.Int2Str(act.ID)
|
||||
infoID, err2 := CreatePromotionInfos(act.Type, act.Name, act.BeginAt, act.EndAt, outInfoID, act.Advertising, traceID)
|
||||
if err = err2; err == nil {
|
||||
act.VendorActID = utils.Int64ToStr(infoID)
|
||||
if err = CreatePromotionRules(act.Type, infoID, "", act.LimitDevice, act.LimitPin, act.LimitCount, act.LimitDaily, traceID); err == nil {
|
||||
if _, err = CreatePromotionSku(act.Type, infoID, "", storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceID); err == nil {
|
||||
err = ConfirmPromotion(act.Type, infoID, "", traceID)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
traceID := getTraceID(ctx)
|
||||
if act.Type < model.ActOrderBegin {
|
||||
outInfoID := utils.Int2Str(act.ID)
|
||||
if !utils.IsTimeZero(act.EndAt) {
|
||||
if err = AdjustPromotionTime(act.Type, 0, outInfoID, act.EndAt, traceID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if toBeDeleted := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(toBeDeleted) > 0 {
|
||||
if err = CancelPromotionSku(act.Type, 0, outInfoID, toBeDeleted, traceID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// if toBeAdded := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(toBeAdded) > 0 {
|
||||
// if _, err = CreatePromotionSku(act.Type, 0, outInfoID, toBeAdded, traceID); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// if toBeUpdated := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(toBeUpdated) > 0 {
|
||||
// if _, err = AdjustPromotionSku(act.Type, 0, outInfoID, toBeUpdated, traceID); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
traceID := getTraceID(ctx)
|
||||
if act.Type < model.ActOrderBegin {
|
||||
outInfoID := utils.Int2Str(act.ID)
|
||||
err = CancelPromotion(act.Type, 0, outInfoID, traceID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
167
business/partner/purchase/mtwm/act.go
Normal file
167
business/partner/purchase/mtwm/act.go
Normal file
@@ -0,0 +1,167 @@
|
||||
package mtwm
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func actOrderRules2Mtwm(actOrderRules []*model.ActOrderRule) (actDetails []*mtwmapi.FullDiscountActDetail) {
|
||||
for _, v := range actOrderRules {
|
||||
actDetails = append(actDetails, &mtwmapi.FullDiscountActDetail{
|
||||
OriginalPrice: jxutils.IntPrice2Standard(v.SalePrice),
|
||||
ActPrice: jxutils.IntPrice2Standard(v.DeductPrice),
|
||||
})
|
||||
}
|
||||
return actDetails
|
||||
}
|
||||
|
||||
func storeSku2ActData(act *model.Act2, actStoreSku []*model.ActStoreSku2, handler func(int) bool) (actData []*mtwmapi.RetailDiscountActData) {
|
||||
for _, v := range actStoreSku {
|
||||
if handler == nil || handler(v.SyncStatus) {
|
||||
actData = append(actData, &mtwmapi.RetailDiscountActData{
|
||||
AppFoodCode: utils.Int2Str(v.SkuID),
|
||||
// UserType: 0,
|
||||
StartTime: act.BeginAt.Unix(),
|
||||
EndTime: act.EndAt.Unix(),
|
||||
OrderLimit: act.LimitCount,
|
||||
DayLimit: act.LimitDaily,
|
||||
// Period: "",
|
||||
// WeeksTime: "",
|
||||
SettingType: mtwmapi.SettingTypeAsPrice,
|
||||
ActPrice: jxutils.IntPrice2Standard(v.ActPrice),
|
||||
// DiscountCoefficient: 0,
|
||||
Sequence: int(v.ActPrice),
|
||||
ItemID: utils.Str2Int64WithDefault(v.VendorActID, 0),
|
||||
})
|
||||
}
|
||||
}
|
||||
return actData
|
||||
}
|
||||
|
||||
func storeSku2ActData4Delete(actStoreSku []*model.ActStoreSku2, handler func(int) bool) (actIDList []string) {
|
||||
for _, v := range actStoreSku {
|
||||
if handler == nil || handler(v.SyncStatus) {
|
||||
if v.VendorActID != "" {
|
||||
actIDList = append(actIDList, v.VendorActID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return actIDList
|
||||
}
|
||||
|
||||
func isCreateOrUpdate(syncStatus int) bool {
|
||||
return model.IsSyncStatusNeedCreate(syncStatus) || model.IsSyncStatusNeedUpdate(syncStatus)
|
||||
}
|
||||
|
||||
func createOneShopAct(act *model.Act2, storeMap *model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
actData := storeSku2ActData(act, actStoreSku, isCreateOrUpdate)
|
||||
if len(actData) > 0 {
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
actResult, err2 := api.MtwmAPI.RetailDiscountBatchSave(storeMap.VendorStoreID, actData)
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
actResultMap := make(map[string]*mtwmapi.RetailDiscountActResult)
|
||||
for _, v := range actResult {
|
||||
actResultMap[v.AppFoodCode] = v
|
||||
}
|
||||
for _, v := range actStoreSku {
|
||||
if result := actResultMap[utils.Int2Str(v.SkuID)]; result != nil {
|
||||
v.VendorActID = utils.Int64ToStr(result.ActID)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, v := range actStoreSku {
|
||||
v.VendorActID = utils.Int64ToStr(jxutils.GenFakeID())
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
globals.SugarLogger.Debugf("mtwm CreateAct actID:%d", act.ID)
|
||||
if act.Type < model.ActOrderBegin {
|
||||
actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku)
|
||||
task := tasksch.NewParallelTask("mtwm CreateAct", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*model.ActStore2)
|
||||
err = createOneShopAct(act, store, actStoreSkuMap[store.StoreID])
|
||||
return nil, err
|
||||
}, actStoreMap)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
if act.Type < model.ActOrderBegin {
|
||||
actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku)
|
||||
if len(actStoreMap2Remove) > 0 {
|
||||
if err = c.DeleteAct(ctx, parentTask, act, actStoreMap2Remove, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range actStoreMap2Remove {
|
||||
delete(actStoreSkuMap, v.StoreID)
|
||||
}
|
||||
}
|
||||
if len(actStoreMap2Add) > 0 {
|
||||
if err = c.CreateAct(ctx, parentTask, act, actOrderRules, actStoreMap2Add, actStoreSku); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range actStoreMap2Add {
|
||||
delete(actStoreSkuMap, v.StoreID)
|
||||
}
|
||||
}
|
||||
task := tasksch.NewParallelTask("mtwm UpdateAct", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(*model.ActStore2)
|
||||
if storeSkus := actStoreSkuMap[v.StoreID]; storeSkus != nil {
|
||||
if list := storeSku2ActData4Delete(storeSkus, model.IsSyncStatusNeedDelete); len(list) > 0 {
|
||||
if err = api.MtwmAPI.RetailDiscountDelete(v.VendorStoreID, list); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err = createOneShopAct(act, v, actStoreSkuMap[v.StoreID]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}, actStoreMap2Update)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
if act.Type < model.ActOrderBegin {
|
||||
actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku)
|
||||
task := tasksch.NewParallelTask("mtwm DeleteAct", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(*model.ActStore2)
|
||||
actIDList := storeSku2ActData4Delete(actStoreSkuMap[v.StoreID], nil)
|
||||
if len(actIDList) > 0 {
|
||||
err = api.MtwmAPI.RetailDiscountDelete(v.VendorStoreID, actIDList)
|
||||
}
|
||||
return nil, err
|
||||
}, actStoreMap)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
|
||||
}
|
||||
return err
|
||||
}
|
||||
19
business/partner/purchase/weimob/wsc/act.go
Normal file
19
business/partner/purchase/weimob/wsc/act.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package wsc
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user