- 活动调整,DeleteAct改名为CancelAct

This commit is contained in:
gazebo
2019-06-11 17:28:15 +08:00
parent d0df80ac1e
commit 208e52a669
11 changed files with 81 additions and 26 deletions

View File

@@ -4,11 +4,10 @@ import (
"fmt" "fmt"
"time" "time"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/partner" "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/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch" "git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
@@ -16,6 +15,10 @@ import (
"git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/model/dao"
) )
const (
ActionTypeNA = 0
)
type ActOrderRuleParam struct { type ActOrderRuleParam struct {
SalePrice int64 `orm:"" json:"salePrice"` // 满的价格 SalePrice int64 `orm:"" json:"salePrice"` // 满的价格
DeductPrice int64 `orm:"" json:"deductPrice"` // 减的价格 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.WrapAddIDCULDEntity(act, ctx.GetUserName())
dao.Begin(db) dao.Begin(db)
defer func() { defer func() {
if r := recover(); r != nil || err != nil { if r := recover(); r != nil {
dao.Rollback(db) dao.Rollback(db)
if r != nil { panic(r)
panic(r)
}
} }
}() }()
err = dao.CreateEntity(db, act) 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 { if len(utils.Interface2Slice(list)) > 0 {
err = dao.CreateMultiEntities(db, list) err = dao.CreateMultiEntities(db, list)
if err != nil { if err != nil {
dao.Rollback(db)
return 0, err return 0, err
} }
isEmptyAct = false isEmptyAct = false
} }
} }
if isEmptyAct { if isEmptyAct {
dao.Rollback(db)
return 0, fmt.Errorf("没有门店及SKU满足需求空操作") return 0, fmt.Errorf("没有门店及SKU满足需求空操作")
} }
dao.Commit(db) dao.Commit(db)
actID = act.ID
err = SyncAct(ctx, actID, nil, nil, nil)
return actID, err return actID, err
} }
@@ -218,11 +223,42 @@ func GetActDetail(ctx *jxcontext.Context, actID int) (actDetail *ActDetail, err
// return err // return err
// } // }
func parseActStoreSkuParam(actStoreSku []*ActStoreSkuParam) {
}
func UpdateAct(ctx *jxcontext.Context, act *model.Act, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam) (err error) { func UpdateAct(ctx *jxcontext.Context, act *model.Act, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam) (err error) {
return err 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 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(actStore, false))
// globals.SugarLogger.Debugf("%s", utils.Format4Output(actStoreSku, false)) // globals.SugarLogger.Debugf("%s", utils.Format4Output(actStoreSku, false))
if act != nil && actStore != nil && actStoreSku != nil { if act != nil && actStore != nil && actStoreSku != nil {
if model.IsSyncStatusNeedDelete(act.SyncStatus) { if model.IsSyncStatusNeedCreate(act.SyncStatus) {
if !dao.IsVendorThingIDEmpty(act.VendorActID) {
}
} else if model.IsSyncStatusNeedCreate(act.SyncStatus) {
globals.SugarLogger.Debug("fuck")
err = handler.CreateAct(ctx, task, act, actOrderRules, actStore, actStoreSku) err = handler.CreateAct(ctx, task, act, actOrderRules, actStore, actStoreSku)
} else /*if model.IsSyncStatusNeedUpdate(act.SyncStatus)*/ { } else if model.IsSyncStatusNeedUpdate(act.SyncStatus) {
actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update := splitActStore(actStore) if act.Status == model.ActStatusCanceled {
err = handler.UpdateAct(ctx, task, act, actOrderRules, actStoreMap2Remove, actStoreMap2Add, actStoreMap2Update, actStoreSku) 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 { if err == nil {
actMap := &model.ActMap{} actMap := &model.ActMap{}

View File

@@ -53,6 +53,13 @@ func TestCreateAct(t *testing.T) {
globals.SugarLogger.Debug(actID) 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) { func TestSyncAct(t *testing.T) {
err := SyncAct(jxcontext.AdminCtx, 1, nil, nil, nil) err := SyncAct(jxcontext.AdminCtx, 1, nil, nil, nil)
if err != nil { if err != nil {

View File

@@ -13,6 +13,12 @@ const (
ActOrderReduceFreightCoupon = 14 ActOrderReduceFreightCoupon = 14
) )
const (
ActStatusCreated = 1 // 需同步
ActStatusCanceled = 2 // 需同步
ActStatusEnded = 3 // 不需要同步,根据活动时间自动刷新的
)
type Act struct { type Act struct {
ModelIDCULD ModelIDCULD

View File

@@ -46,6 +46,7 @@ const (
FieldVendorOrderID = "VendorOrderID" FieldVendorOrderID = "VendorOrderID"
FieldVendorOrderID2 = "VendorOrderID2" FieldVendorOrderID2 = "VendorOrderID2"
FieldActID = "ActID"
FieldVendorActID = "VendorActID" FieldVendorActID = "VendorActID"
) )

View File

@@ -172,7 +172,7 @@ type IStoreManager interface {
// 所有非以SyncRefresh开头的函数不用自己清理sync_status标记VendorSync统一处理 // 所有非以SyncRefresh开头的函数不用自己清理sync_status标记VendorSync统一处理
type IPurchasePlatformHandler interface { type IPurchasePlatformHandler interface {
// IPurchasePlatformPromotionHandler IPurchasePlatformPromotionHandler
GetVendorID() int GetVendorID() int
GetStatusFromVendorStatus(vendorStatus string) int GetStatusFromVendorStatus(vendorStatus string) int

View File

@@ -11,7 +11,8 @@ type IPurchasePlatformPromotionHandler interface {
// 如果是订单级活动actStoreSku可以为空表示不限制SKU // 如果是订单级活动actStoreSku可以为空表示不限制SKU
CreateAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreMap []*model.ActStore2, actStoreSku []*model.ActStoreSku2) (err error) 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) 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) { func ActStoreSku2Map(actStoreSku []*model.ActStoreSku2) (actStoreSkuMap map[int][]*model.ActStoreSku2) {

View File

@@ -124,7 +124,7 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
if act.Type < model.ActOrderBegin { if act.Type < model.ActOrderBegin {
actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku) actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku)
if len(actStoreMap2Remove) > 0 { 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 return err
} }
for _, v := range actStoreMap2Remove { for _, v := range actStoreMap2Remove {
@@ -169,12 +169,14 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
return err 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 { if act.Type < model.ActOrderBegin {
task := tasksch.NewParallelTask("ebai DeleteAct", nil, ctx, task := tasksch.NewParallelTask("ebai DeleteAct", nil, ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
v := batchItemList[0].(*model.ActStore2) 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 return nil, err
}, actStoreMap) }, actStoreMap)
tasksch.HandleTask(task, parentTask, true).Run() tasksch.HandleTask(task, parentTask, true).Run()

View File

@@ -14,6 +14,6 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
return err 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 return err
} }

View File

@@ -173,7 +173,7 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
return err 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) traceID := getTraceID(ctx)
if act.Type < model.ActOrderBegin { if act.Type < model.ActOrderBegin {
outInfoID := utils.Int2Str(act.ID) outInfoID := utils.Int2Str(act.ID)

View File

@@ -108,7 +108,7 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
if act.Type < model.ActOrderBegin { if act.Type < model.ActOrderBegin {
actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku) actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku)
if len(actStoreMap2Remove) > 0 { 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 return err
} }
for _, v := range actStoreMap2Remove { for _, v := range actStoreMap2Remove {
@@ -146,7 +146,7 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
return err 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 { if act.Type < model.ActOrderBegin {
actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku) actStoreSkuMap := partner.ActStoreSku2Map(actStoreSku)
task := tasksch.NewParallelTask("mtwm DeleteAct", nil, ctx, 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) v := batchItemList[0].(*model.ActStore2)
actIDList := storeSku2ActData4Delete(actStoreSkuMap[v.StoreID], nil) actIDList := storeSku2ActData4Delete(actStoreSkuMap[v.StoreID], nil)
if len(actIDList) > 0 { if len(actIDList) > 0 {
err = api.MtwmAPI.RetailDiscountDelete(v.VendorStoreID, actIDList) if globals.EnableMtwmStoreWrite {
err = api.MtwmAPI.RetailDiscountDelete(v.VendorStoreID, actIDList)
}
} }
return nil, err return nil, err
}, actStoreMap) }, actStoreMap)

View File

@@ -14,6 +14,6 @@ func (c *PurchaseHandler) UpdateAct(ctx *jxcontext.Context, parentTask tasksch.I
return err 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 return err
} }