From 2d5a2e8274c374aa2fb3d21103b81fc53e914d97 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 4 Jul 2019 12:07:43 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=B4=BB=E5=8A=A8=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E6=B5=8B=E8=AF=95=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/act/act.go | 22 ++++++++++++++---- business/jxstore/cms/cms.go | 1 + business/model/const.go | 5 ++++ business/partner/purchase/ebai/act.go | 27 ++++++++++++---------- business/partner/purchase/jd/act.go | 33 +++++++++++++++------------ business/partner/purchase/mtwm/act.go | 22 +++++++++--------- controllers/act.go | 21 +++++++++++++++++ routers/commentsRouter_controllers.go | 9 ++++++++ 8 files changed, 99 insertions(+), 41 deletions(-) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index 297f7d58e..fd3d5c3ab 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -15,6 +15,10 @@ import ( "git.rosy.net.cn/jx-callback/business/model/dao" ) +const ( + DefActSkuStock = 200 // 缺省活动库存 +) + type ActOrderRuleParam struct { SalePrice int64 `orm:"" json:"salePrice"` // 满的价格 DeductPrice int64 `orm:"" json:"deductPrice"` // 减的价格 @@ -127,6 +131,9 @@ func addActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actStoreSkuList []*m storeSkuMap := make(map[int64]int) for _, v := range actStoreSkuList { + if v.Stock == 0 { + v.Stock = DefActSkuStock + } err = dao.CreateEntity(db, v) if err != nil { dao.Rollback(db) @@ -151,14 +158,12 @@ func addActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actStoreSkuList []*m func AddActStoreBind(ctx *jxcontext.Context, actID int, actStoreSku []*ActStoreSkuParam) (err error) { db := dao.GetDB() - var vendorIDs []int actMap, err := dao.GetActVendorInfo(db, actID, nil) if err != nil { return err } - for vendorID := range actMap { - vendorIDs = append(vendorIDs, vendorID) - } + vendorIDs := partner.GetVendorIDsFromActMap(actMap) + var act *model.Act if len(vendorIDs) > 0 { act = &actMap[vendorIDs[0]].Act @@ -310,16 +315,25 @@ func DeleteActStoreBind(ctx *jxcontext.Context, actID int, actStoreSku []*ActSto return deleteActStoreBind(ctx, dao.GetDB(), actID, actStoreSku) } +// actStoreSkuParam为空,不会删除act_store_sku,但会删除act_store_sku_map func deleteActStoreBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actStoreSkuParam []*ActStoreSkuParam) (err error) { actMap, err := dao.GetActVendorInfo(db, actID, nil) if err != nil { return err } + if len(actMap) == 0 { + return fmt.Errorf("找不到活动:%d,或已被全部取消", actID) + } actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, nil, nil, nil) if err != nil { return err } + act := actMap[partner.GetVendorIDsFromActMap(actMap)[0]] + if act.Status != model.ActStatusCreated { + return fmt.Errorf("当前活动状态:%s不能进行此操作", model.ActStatusName[act.Status]) + } + dao.Begin(db) defer func() { if r := recover(); r != nil || err != nil { diff --git a/business/jxstore/cms/cms.go b/business/jxstore/cms/cms.go index e9307cb87..c46b71529 100644 --- a/business/jxstore/cms/cms.go +++ b/business/jxstore/cms/cms.go @@ -62,6 +62,7 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) { "purchaseVendorInfo": model.PurchaseVendorInfo, "afsReasonTypeName": model.AfsReasonTypeName, "afsAppealTypeName": model.AfsAppealTypeName, + "actStatusName": model.ActStatusName, }, } Init() diff --git a/business/model/const.go b/business/model/const.go index 1b7da9b68..8ad0cf6ba 100644 --- a/business/model/const.go +++ b/business/model/const.go @@ -189,6 +189,11 @@ var ( AfsAppealTypeReturnAndRefund: "退货退款", AfsAppealTypeNewGoods: "重发商品", } + ActStatusName = map[int]string{ + ActStatusCreated: "正常", + ActStatusCanceled: "取消", + ActStatusEnded: "结束", + } ) const ( diff --git a/business/partner/purchase/ebai/act.go b/business/partner/purchase/ebai/act.go index 3c8907196..0d320a64f 100644 --- a/business/partner/purchase/ebai/act.go +++ b/business/partner/purchase/ebai/act.go @@ -184,7 +184,10 @@ func cancelSkuAct(ctx *jxcontext.Context, parentTask tasksch.ITask, actStoreSkuM func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { vendorActID := batchItemList[0].(string) actStoreSkuList := actStoreSkuMap[vendorActID] - if err = ActivityDisable(utils.Str2Int64(vendorActID), utils.Int2Str(actStoreSkuList[0].StoreID), 0, 0); err == nil { + if vendorActID != "" { + err = ActivityDisable(utils.Str2Int64(vendorActID), utils.Int2Str(actStoreSkuList[0].StoreID), 0, 0) + } + if err == nil { retVal = []interface{}{actStoreSkuList} } return retVal, err @@ -274,31 +277,31 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa if vendorActIDMap[storeID] == "" && actStoreSku.VendorActID != "" { vendorActIDMap[storeID] = actStoreSku.VendorActID } - if model.IsSyncStatusNeedCreate(actStoreSku.SyncStatus) { - actStoreSkuList4Create = append(actStoreSkuList4Create, actStoreSku) - } else if model.IsSyncStatusNeedDelete(actStoreSku.SyncStatus) { + if model.IsSyncStatusDelete(actStoreSku.SyncStatus) { vendorActID := actStoreSku.VendorActID if vendorActID == "" { vendorActID = act.VendorActID } deleteActInfoMap[vendorActID] = append(deleteActInfoMap[vendorActID], actStoreSku) + } else if model.IsSyncStatusNew(actStoreSku.SyncStatus) { + actStoreSkuList4Create = append(actStoreSkuList4Create, actStoreSku) } } } err = func() (err error) { - if model.IsSyncStatusNeedCreate(act.SyncStatus) { - createdList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create) - updateItems = append(updateItems, partner.ActStoreSku2Update(createdList, model.SyncFlagNewMask)...) - if err = err2; err == nil { - updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask)) - } - } else if model.IsSyncStatusNeedDelete(act.SyncStatus) { + if model.IsSyncStatusDelete(act.SyncStatus) { canceledList, err2 := cancelSkuAct(ctx, nil, vendorActInfoMap) updateItems = append(updateItems, partner.ActStoreSku2Update(canceledList, model.SyncFlagDeletedMask)...) if err = err2; err == nil { updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagDeletedMask)) } - } else if model.IsSyncStatusNeedUpdate(act.SyncStatus) { + } else if model.IsSyncStatusNew(act.SyncStatus) { + createdList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create) + updateItems = append(updateItems, partner.ActStoreSku2Update(createdList, model.SyncFlagNewMask)...) + if err = err2; err == nil { + updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask)) + } + } else if model.IsSyncStatusUpdate(act.SyncStatus) { // globals.SugarLogger.Debug(utils.Format4Output(updateItems, false)) if len(actStoreSkuList4Create) > 0 { addedList, err2 := addSkuActSkus(ctx, nil, act, actStoreSkuList4Create, vendorActIDMap) diff --git a/business/partner/purchase/jd/act.go b/business/partner/purchase/jd/act.go index d84dd2892..563f8e68c 100644 --- a/business/partner/purchase/jd/act.go +++ b/business/partner/purchase/jd/act.go @@ -178,14 +178,18 @@ func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model. } func cancelSkuActSkus(ctx *jxcontext.Context, actType int, vendorActID string, actStoreSku []*model.ActStoreSku2) (err error) { - if skuList := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(skuList) > 0 { - err = CancelPromotionSku(actType, utils.Str2Int64(vendorActID), "", skuList, ctx.GetAccessUUID()) + if vendorActID != "" { + if skuList := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(skuList) > 0 { + err = CancelPromotionSku(actType, utils.Str2Int64(vendorActID), "", skuList, ctx.GetAccessUUID()) + } } return err } func cancelSkuAct(ctx *jxcontext.Context, actType int, vendorActID string) (err error) { - err = CancelPromotion(actType, utils.Str2Int64(vendorActID), "", ctx.GetAccessUUID()) + if vendorActID != "" { + err = CancelPromotion(actType, utils.Str2Int64(vendorActID), "", ctx.GetAccessUUID()) + } return err } @@ -200,25 +204,19 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa for storeID := range actStoreSkuMap { for _, actStoreSku := range actStoreSkuMap[storeID] { vendorActInfoMap[actStoreSku.VendorActID] = append(vendorActInfoMap[actStoreSku.VendorActID], actStoreSku) - if model.IsSyncStatusNeedCreate(actStoreSku.SyncStatus) { - actStoreSkuList4Create = append(actStoreSkuList4Create, actStoreSku) - } else if model.IsSyncStatusNeedDelete(actStoreSku.SyncStatus) { + if model.IsSyncStatusDelete(actStoreSku.SyncStatus) { vendorActID := actStoreSku.VendorActID if vendorActID == "" { vendorActID = act.VendorActID } deleteActInfoMap[vendorActID] = append(deleteActInfoMap[vendorActID], actStoreSku) + } else if model.IsSyncStatusNew(actStoreSku.SyncStatus) { + actStoreSkuList4Create = append(actStoreSkuList4Create, actStoreSku) } } } err = func() (err error) { - if model.IsSyncStatusNeedCreate(act.SyncStatus) { - if act.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil { - return err - } - updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList4Create, model.SyncFlagNewMask)...) - updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask)) - } else if model.IsSyncStatusNeedDelete(act.SyncStatus) { + if model.IsSyncStatusDelete(act.SyncStatus) { for vendorActID := range vendorActInfoMap { if vendorActID != "" { if err = cancelSkuAct(ctx, act.Type, vendorActID); err != nil { @@ -230,7 +228,13 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList, model.SyncFlagDeletedMask)...) } updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagDeletedMask)) - } else if model.IsSyncStatusNeedUpdate(act.SyncStatus) { + } else if model.IsSyncStatusNew(act.SyncStatus) { + if act.VendorActID, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil { + return err + } + updateItems = append(updateItems, partner.ActStoreSku2Update(actStoreSkuList4Create, model.SyncFlagNewMask)...) + updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask)) + } else if model.IsSyncStatusUpdate(act.SyncStatus) { // globals.SugarLogger.Debug(utils.Format4Output(updateItems, false)) if len(actStoreSkuList4Create) > 0 { if _, err = createSkuAct(ctx, act, actStoreSkuList4Create); err != nil { @@ -258,6 +262,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa return err }() db := dao.GetDB() + globals.SugarLogger.Debug(utils.Format4Output(updateItems, false)) _, err2 := dao.BatchUpdateEntityByKV(db, updateItems) if err == nil { err = err2 diff --git a/business/partner/purchase/mtwm/act.go b/business/partner/purchase/mtwm/act.go index b652d8d14..6d760ed6f 100644 --- a/business/partner/purchase/mtwm/act.go +++ b/business/partner/purchase/mtwm/act.go @@ -153,27 +153,27 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa actStoreSkuMap := partner.SplitActStoreSku(actStoreSkuList) for storeID := range actStoreSkuMap { for _, actStoreSku := range actStoreSkuMap[storeID] { - if model.IsSyncStatusNeedCreate(actStoreSku.SyncStatus) { - actStoreSkuList4Create = append(actStoreSkuList4Create, actStoreSku) - } else if model.IsSyncStatusNeedDelete(actStoreSku.SyncStatus) { + if model.IsSyncStatusDelete(actStoreSku.SyncStatus) { actStoreSkuList4Delete = append(actStoreSkuList4Delete, actStoreSku) + } else if model.IsSyncStatusNew(actStoreSku.SyncStatus) { + actStoreSkuList4Create = append(actStoreSkuList4Create, actStoreSku) } } } err = func() (err error) { - if model.IsSyncStatusNeedCreate(act.SyncStatus) { - createdList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create) - updateItems = append(updateItems, partner.ActStoreSku2Update(createdList, model.SyncFlagNewMask)...) - if err = err2; err == nil { - updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask)) - } - } else if model.IsSyncStatusNeedDelete(act.SyncStatus) { + if model.IsSyncStatusDelete(act.SyncStatus) { canceledList, err2 := cancelSkuAct(ctx, nil, actStoreSkuList) updateItems = append(updateItems, partner.ActStoreSku2Update(canceledList, model.SyncFlagDeletedMask)...) if err = err2; err == nil { updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagDeletedMask)) } - } else if model.IsSyncStatusNeedUpdate(act.SyncStatus) { + } else if model.IsSyncStatusNew(act.SyncStatus) { + createdList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create) + updateItems = append(updateItems, partner.ActStoreSku2Update(createdList, model.SyncFlagNewMask)...) + if err = err2; err == nil { + updateItems = append(updateItems, partner.Act2Update(act, model.SyncFlagNewMask)) + } + } else if model.IsSyncStatusUpdate(act.SyncStatus) { // globals.SugarLogger.Debug(utils.Format4Output(updateItems, false)) if len(actStoreSkuList4Create) > 0 { addedList, err2 := createSkuAct(ctx, nil, act, actStoreSkuList4Create) diff --git a/controllers/act.go b/controllers/act.go index ec2cd0aa1..258371896 100644 --- a/controllers/act.go +++ b/controllers/act.go @@ -139,3 +139,24 @@ func (c *ActController) GetActStoreSkuInfo() { return retVal, "", err }) } + +// @Title 同步活动 +// @Description 同步活动 +// @Param token header string true "认证token" +// @Param actID formData int true "活动id" +// @Param vendorIDs formData string false "厂商ID列表" +// @Param storeIDs formData string false "门店ID列表" +// @Param skuIDs formData string false "商品列表" +// @Param isAsync formData bool false "是否异步" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /SyncAct [put] +func (c *ActController) SyncAct() { + c.callSyncAct(func(params *tActSyncActParams) (retVal interface{}, errCode string, err error) { + var vendorIDs, storeIDs, skuIDs []int + if err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs, params.StoreIDs, &storeIDs, params.SkuIDs, &skuIDs); err == nil { + retVal, err = act.SyncAct(params.Ctx, nil, params.ActID, vendorIDs, storeIDs, skuIDs, params.IsAsync) + } + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 42827de40..734cb01cd 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -52,6 +52,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ActController"], + beego.ControllerComments{ + Method: "SyncAct", + Router: `/SyncAct`, + AllowHTTPMethods: []string{"put"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:Auth2Controller"], beego.ControllerComments{ Method: "AddAuthBind",