- 活动平台实际测试通过

This commit is contained in:
gazebo
2019-07-04 12:07:43 +08:00
parent a93b6889b3
commit 2d5a2e8274
8 changed files with 99 additions and 41 deletions

View File

@@ -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 {

View File

@@ -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()

View File

@@ -189,6 +189,11 @@ var (
AfsAppealTypeReturnAndRefund: "退货退款",
AfsAppealTypeNewGoods: "重发商品",
}
ActStatusName = map[int]string{
ActStatusCreated: "正常",
ActStatusCanceled: "取消",
ActStatusEnded: "结束",
}
)
const (

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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
})
}

View File

@@ -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",