- 活动调整,DeleteAct改名为CancelAct
This commit is contained in:
@@ -4,11 +4,10 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
@@ -16,6 +15,10 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
const (
|
||||
ActionTypeNA = 0
|
||||
)
|
||||
|
||||
type ActOrderRuleParam struct {
|
||||
SalePrice int64 `orm:"" json:"salePrice"` // 满的价格
|
||||
DeductPrice int64 `orm:"" json:"deductPrice"` // 减的价格
|
||||
@@ -164,11 +167,9 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
dao.WrapAddIDCULDEntity(act, ctx.GetUserName())
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
err = dao.CreateEntity(db, act)
|
||||
@@ -186,15 +187,19 @@ func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules
|
||||
if len(utils.Interface2Slice(list)) > 0 {
|
||||
err = dao.CreateMultiEntities(db, list)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
}
|
||||
isEmptyAct = false
|
||||
}
|
||||
}
|
||||
if isEmptyAct {
|
||||
dao.Rollback(db)
|
||||
return 0, fmt.Errorf("没有门店及SKU满足需求,空操作")
|
||||
}
|
||||
dao.Commit(db)
|
||||
actID = act.ID
|
||||
err = SyncAct(ctx, actID, nil, nil, nil)
|
||||
return actID, err
|
||||
}
|
||||
|
||||
@@ -218,11 +223,42 @@ func GetActDetail(ctx *jxcontext.Context, actID int) (actDetail *ActDetail, err
|
||||
// return err
|
||||
// }
|
||||
|
||||
func parseActStoreSkuParam(actStoreSku []*ActStoreSkuParam) {
|
||||
|
||||
}
|
||||
|
||||
func UpdateAct(ctx *jxcontext.Context, act *model.Act, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteAct(ctx *jxcontext.Context, actID int) (err error) {
|
||||
func CancelAct(ctx *jxcontext.Context, actID int) (err error) {
|
||||
db := dao.GetDB()
|
||||
act := &model.Act{}
|
||||
act.ID = actID
|
||||
if err = dao.GetEntity(db, act); err != nil {
|
||||
return err
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
|
||||
dao.UpdateEntityLogically(db, act, map[string]interface{}{
|
||||
model.FieldStatus: model.ActStatusCanceled,
|
||||
}, ctx.GetUserName(), nil)
|
||||
_, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, &model.ActMap{}, nil, ctx.GetUserName(), map[string]interface{}{
|
||||
model.FieldActID: actID,
|
||||
}, model.FieldSyncStatus, model.SyncFlagModifiedMask)
|
||||
if err == nil {
|
||||
dao.Commit(db)
|
||||
globals.SugarLogger.Debugf("CancelAct track:%s", ctx.GetTrackInfo())
|
||||
err = SyncAct(ctx, actID, nil, nil, nil)
|
||||
} else {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -260,15 +296,15 @@ func SyncAct(ctx *jxcontext.Context, actID int, vendorIDs, storeIDs, skuIDs []in
|
||||
// globals.SugarLogger.Debugf("%s", utils.Format4Output(actStore, false))
|
||||
// globals.SugarLogger.Debugf("%s", utils.Format4Output(actStoreSku, false))
|
||||
if act != nil && actStore != nil && actStoreSku != nil {
|
||||
if model.IsSyncStatusNeedDelete(act.SyncStatus) {
|
||||
if !dao.IsVendorThingIDEmpty(act.VendorActID) {
|
||||
}
|
||||
} else if model.IsSyncStatusNeedCreate(act.SyncStatus) {
|
||||
globals.SugarLogger.Debug("fuck")
|
||||
if model.IsSyncStatusNeedCreate(act.SyncStatus) {
|
||||
err = handler.CreateAct(ctx, task, act, actOrderRules, actStore, actStoreSku)
|
||||
} else /*if model.IsSyncStatusNeedUpdate(act.SyncStatus)*/ {
|
||||
actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update := splitActStore(actStore)
|
||||
err = handler.UpdateAct(ctx, task, act, actOrderRules, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update, actStoreSku)
|
||||
} else if model.IsSyncStatusNeedUpdate(act.SyncStatus) {
|
||||
if act.Status == model.ActStatusCanceled {
|
||||
err = handler.CancelAct(ctx, task, act, actStore, actStoreSku)
|
||||
} else {
|
||||
// actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update := splitActStore(actStore)
|
||||
// err = handler.UpdateAct(ctx, task, act, actOrderRules, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update, actStoreSku)
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
actMap := &model.ActMap{}
|
||||
|
||||
@@ -53,6 +53,13 @@ func TestCreateAct(t *testing.T) {
|
||||
globals.SugarLogger.Debug(actID)
|
||||
}
|
||||
|
||||
func TestCancelAct(t *testing.T) {
|
||||
err := CancelAct(jxcontext.AdminCtx, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncAct(t *testing.T) {
|
||||
err := SyncAct(jxcontext.AdminCtx, 1, nil, nil, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,6 +13,12 @@ const (
|
||||
ActOrderReduceFreightCoupon = 14
|
||||
)
|
||||
|
||||
const (
|
||||
ActStatusCreated = 1 // 需同步
|
||||
ActStatusCanceled = 2 // 需同步
|
||||
ActStatusEnded = 3 // 不需要同步,根据活动时间自动刷新的
|
||||
)
|
||||
|
||||
type Act struct {
|
||||
ModelIDCULD
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ const (
|
||||
FieldVendorOrderID = "VendorOrderID"
|
||||
FieldVendorOrderID2 = "VendorOrderID2"
|
||||
|
||||
FieldActID = "ActID"
|
||||
FieldVendorActID = "VendorActID"
|
||||
)
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ type IStoreManager interface {
|
||||
// 所有非以Sync,Refresh开头的函数不用自己清理sync_status标记(VendorSync统一处理)
|
||||
|
||||
type IPurchasePlatformHandler interface {
|
||||
// IPurchasePlatformPromotionHandler
|
||||
IPurchasePlatformPromotionHandler
|
||||
GetVendorID() int
|
||||
|
||||
GetStatusFromVendorStatus(vendorStatus string) int
|
||||
|
||||
@@ -11,7 +11,8 @@ type IPurchasePlatformPromotionHandler interface {
|
||||
// 如果是订单级活动,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)
|
||||
// 取消整个京西活动
|
||||
CancelAct(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) {
|
||||
|
||||
@@ -124,7 +124,7 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
if act.Type < model.ActOrderBegin {
|
||||
actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku)
|
||||
if len(actStoreMap2Remove) > 0 {
|
||||
if err = c.DeleteAct(ctx, parentTask, act, actStoreMap2Remove, nil); err != nil {
|
||||
if err = c.CancelAct(ctx, parentTask, act, actStoreMap2Remove, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range actStoreMap2Remove {
|
||||
@@ -169,12 +169,14 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func (c *PurchaseHandler) CancelAct(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)
|
||||
if globals.EnableEbaiStoreWrite {
|
||||
err = api.EbaiAPI.ActivityDisable(utils.Str2Int64(v.VendorActID), utils.Int2Str(v.StoreID), 0, 0)
|
||||
}
|
||||
return nil, err
|
||||
}, actStoreMap)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
|
||||
@@ -14,6 +14,6 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func (c *PurchaseHandler) CancelAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func (c *PurchaseHandler) CancelAct(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)
|
||||
|
||||
@@ -108,7 +108,7 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
if act.Type < model.ActOrderBegin {
|
||||
actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku)
|
||||
if len(actStoreMap2Remove) > 0 {
|
||||
if err = c.DeleteAct(ctx, parentTask, act, actStoreMap2Remove, nil); err != nil {
|
||||
if err = c.CancelAct(ctx, parentTask, act, actStoreMap2Remove, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range actStoreMap2Remove {
|
||||
@@ -146,7 +146,7 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func (c *PurchaseHandler) CancelAct(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,
|
||||
@@ -154,7 +154,9 @@ func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
v := batchItemList[0].(*model.ActStore2)
|
||||
actIDList := storeSku2ActData4Delete(actStoreSkuMap[v.StoreID], nil)
|
||||
if len(actIDList) > 0 {
|
||||
err = api.MtwmAPI.RetailDiscountDelete(v.VendorStoreID, actIDList)
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = api.MtwmAPI.RetailDiscountDelete(v.VendorStoreID, actIDList)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}, actStoreMap)
|
||||
|
||||
@@ -14,6 +14,6 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) DeleteAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func (c *PurchaseHandler) CancelAct(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