- RefreshPromotionStatus

- call UpdatePromotionStatusFromRemote in LockPromotionSkus.
This commit is contained in:
gazebo
2018-11-09 10:09:13 +08:00
parent 1313fefe0d
commit 534761f993
3 changed files with 51 additions and 4 deletions

View File

@@ -461,7 +461,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW
if _, err = dao.UpdateEntityLogically(db, promotion, map[string]interface{}{
model.FieldStatus: model.PromotionStatusRemoteCreated,
}, ctx.GetUserName(), nil); err == nil {
RefreshJdPromotionLockStatus(promotion.ID)
RefreshJdPromotionLockStatus(ctx, promotion.ID)
}
}
}
@@ -644,7 +644,7 @@ func CancelJdPromotion(ctx *jxcontext.Context, promotionID int) (err error) {
if _, err = dao.UpdateEntityLogically(db, promotion, map[string]interface{}{
"Status": model.PromotionStatusCanceled,
}, ctx.GetUserName(), nil); err == nil {
RefreshJdPromotionLockStatus(promotionID)
RefreshJdPromotionLockStatus(ctx, promotionID)
}
}
return err
@@ -787,7 +787,7 @@ func RefreshJdPromotionItemListLockStatus(promotionItemList []*tPromotionItemInf
return err
}
func RefreshJdPromotionLockStatus(promotionID int) (err error) {
func RefreshJdPromotionLockStatus(ctx *jxcontext.Context, promotionID int) (err error) {
globals.SugarLogger.Debugf("RefreshJdPromotionLockStatus promotionID:%d", promotionID)
sql := `
@@ -840,7 +840,12 @@ func LockPromotionSkus(ctx *jxcontext.Context, promotionID int, isLock int, skuI
db := dao.GetDB()
num, err = dao.ExecuteSQL(db, sql, sqlParams...)
if err == nil {
RefreshJdPromotionLockStatus(promotionID)
if isLock != 0 {
if err = UpdatePromotionStatusFromRemote(ctx, promotionID); err != nil {
return 0, err
}
}
RefreshJdPromotionLockStatus(ctx, promotionID)
if isLock != 0 {
RefreshJdStoreSkuStock()
}
@@ -978,6 +983,26 @@ func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.Callba
return jdapi.Err2CallbackResponse(nil, "")
}
func UpdatePromotionStatusFromRemote(ctx *jxcontext.Context, prommotionID int) (err error) {
db := dao.GetDB()
promotion := &model.Promotion{}
promotion.ID = prommotionID
if err = dao.GetEntity(db, promotion); err != nil {
return err
}
result, err := api.JdAPI.QueryPromotionInfo(utils.Str2Int64(promotion.VendorPromotionID))
if err != nil {
return err
}
newStatus := jd2jxPromotionStatusMap[result.PromotionState]
if newStatus != promotion.Status {
_, err = dao.UpdateEntityLogically(db, promotion, map[string]interface{}{
model.FieldStatus: newStatus,
}, ctx.GetUserName(), nil)
}
return err
}
func excelStr2Time(timeStr string) (tm time.Time, err error) {
return time.ParseInLocation("2006年1月2日15点4分5秒", timeStr, time.Local)
}

View File

@@ -175,3 +175,17 @@ func (c *PromotionController) LockPromotionSkus() {
return retVal, "", err
})
}
// @Title 锁定解锁活动SKU
// @Description 锁定解锁活动SKU
// @Param token header string true "认证token"
// @Param promotionID formData int true "活动id"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /RefreshPromotionStatus [put]
func (c *PromotionController) RefreshPromotionStatus() {
c.callRefreshPromotionStatus(func(params *tPromotionRefreshPromotionStatusParams) (retVal interface{}, errCode string, err error) {
err = promotion.UpdatePromotionStatusFromRemote(params.Ctx, params.PromotionID)
return retVal, "", err
})
}

View File

@@ -247,6 +247,14 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:PromotionController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:PromotionController"],
beego.ControllerComments{
Method: "RefreshPromotionStatus",
Router: `/RefreshPromotionStatus`,
AllowHTTPMethods: []string{"put"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:PromotionController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:PromotionController"],
beego.ControllerComments{
Method: "SendAdvertingByGoodsOrder",