防止京东活动重复记录
This commit is contained in:
@@ -18,6 +18,10 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
actMapDuration = 2 * time.Hour
|
||||||
|
)
|
||||||
|
|
||||||
type LogicUpdateInfo struct {
|
type LogicUpdateInfo struct {
|
||||||
Item interface{}
|
Item interface{}
|
||||||
KVs map[string]interface{}
|
KVs map[string]interface{}
|
||||||
@@ -31,6 +35,8 @@ var (
|
|||||||
jdapi.PromotionStateCanceled: model.ActStatusCanceled,
|
jdapi.PromotionStateCanceled: model.ActStatusCanceled,
|
||||||
jdapi.PromotionStateEnded: model.ActStatusEnded,
|
jdapi.PromotionStateEnded: model.ActStatusEnded,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actMap jxutils.SyncMapWithTimeout
|
||||||
)
|
)
|
||||||
|
|
||||||
func splitPromotionSku(skus []*jdapi.PromotionSku, maxCount int) (skusList [][]*jdapi.PromotionSku) {
|
func splitPromotionSku(skus []*jdapi.PromotionSku, maxCount int) (skusList [][]*jdapi.PromotionSku) {
|
||||||
@@ -62,22 +68,25 @@ func jdSkuActStatus2Jx(jdActState int) int {
|
|||||||
func CreatePromotionInfos(promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising, traceId string) (infoId int64, err error) {
|
func CreatePromotionInfos(promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising, traceId string) (infoId int64, err error) {
|
||||||
if globals.EnableJdStoreWrite {
|
if globals.EnableJdStoreWrite {
|
||||||
if promotionType == model.ActSkuDirectDown {
|
if promotionType == model.ActSkuDirectDown {
|
||||||
return getAPI("").CreatePromotionInfosSingle(name, beginDate, endDate, outInfoId, advertising, traceId)
|
infoId, err = getAPI("").CreatePromotionInfosSingle(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||||
} else {
|
} else {
|
||||||
return getAPI("").CreatePromotionInfosLimitTime(name, beginDate, endDate, outInfoId, advertising, traceId)
|
infoId, err = getAPI("").CreatePromotionInfosLimitTime(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
infoId = jxutils.GenFakeID()
|
infoId = jxutils.GenFakeID()
|
||||||
}
|
}
|
||||||
|
if err == nil {
|
||||||
|
actMap.StoreWithTimeout(infoId, 1, actMapDuration)
|
||||||
|
}
|
||||||
return infoId, err
|
return infoId, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreatePromotionRules(promotionType int, infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int, traceId string) (err error) {
|
func CreatePromotionRules(promotionType int, infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int, traceId string) (err error) {
|
||||||
if globals.EnableJdStoreWrite {
|
if globals.EnableJdStoreWrite {
|
||||||
if promotionType == model.ActSkuDirectDown {
|
if promotionType == model.ActSkuDirectDown {
|
||||||
return getAPI("").CreatePromotionRulesSingle(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
err = getAPI("").CreatePromotionRulesSingle(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||||
} else {
|
} else {
|
||||||
return getAPI("").CreatePromotionRulesLimitTime(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
err = getAPI("").CreatePromotionRulesLimitTime(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -133,9 +142,9 @@ func ConfirmPromotion(promotionType int, infoId int64, outInfoId, traceId string
|
|||||||
func CancelPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
func CancelPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
||||||
if globals.EnableJdStoreWrite {
|
if globals.EnableJdStoreWrite {
|
||||||
if promotionType == model.ActSkuDirectDown {
|
if promotionType == model.ActSkuDirectDown {
|
||||||
return getAPI("").CancelPromotionSingle(infoId, outInfoId, traceId)
|
err = getAPI("").CancelPromotionSingle(infoId, outInfoId, traceId)
|
||||||
} else {
|
} else {
|
||||||
return getAPI("").CancelPromotionLimitTime(infoId, outInfoId, traceId)
|
err = getAPI("").CancelPromotionLimitTime(infoId, outInfoId, traceId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -144,9 +153,9 @@ func CancelPromotion(promotionType int, infoId int64, outInfoId, traceId string)
|
|||||||
func AdjustPromotionTime(promotionType int, infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
func AdjustPromotionTime(promotionType int, infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
||||||
if globals.EnableJdStoreWrite {
|
if globals.EnableJdStoreWrite {
|
||||||
if promotionType == model.ActSkuDirectDown {
|
if promotionType == model.ActSkuDirectDown {
|
||||||
return getAPI("").AdjustPromotionTimeSingle(infoId, outInfoId, endDate, traceId)
|
err = getAPI("").AdjustPromotionTimeSingle(infoId, outInfoId, endDate, traceId)
|
||||||
} else {
|
} else {
|
||||||
return getAPI("").AdjustPromotionTimeLimitTime(infoId, outInfoId, endDate, traceId)
|
err = getAPI("").AdjustPromotionTimeLimitTime(infoId, outInfoId, endDate, traceId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -155,9 +164,9 @@ func AdjustPromotionTime(promotionType int, infoId int64, outInfoId string, endD
|
|||||||
func AdjustPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
func AdjustPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
||||||
if globals.EnableJdStoreWrite {
|
if globals.EnableJdStoreWrite {
|
||||||
if promotionType == model.ActSkuDirectDown {
|
if promotionType == model.ActSkuDirectDown {
|
||||||
return getAPI("").AdjustPromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
skusResult, err = getAPI("").AdjustPromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
||||||
} else {
|
} else {
|
||||||
return getAPI("").AdjustPromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
skusResult, err = getAPI("").AdjustPromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return skusResult, err
|
return skusResult, err
|
||||||
@@ -312,19 +321,22 @@ func OnActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
|||||||
func (c *PurchaseHandler) onActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
func (c *PurchaseHandler) onActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||||
if msg.StatusID == jdapi.PromotionStatusSingleOK || msg.StatusID == jdapi.PromotionStatusLimitTimeOK {
|
if msg.StatusID == jdapi.PromotionStatusSingleOK || msg.StatusID == jdapi.PromotionStatusLimitTimeOK {
|
||||||
promotionID := msg.BillID
|
promotionID := msg.BillID
|
||||||
// 等几秒再执行的原因是防止通过后台自己创建时,本地还没有建好,消息就过来,导致重复记录
|
intPromotionID := utils.Str2Int64(promotionID)
|
||||||
// 可能的问题是在重启时丢失消息
|
if _, ok := actMap.Load(intPromotionID); !ok {
|
||||||
utils.AfterFuncWithRecover(5*time.Second, func() {
|
utils.CallFuncAsync(func() {
|
||||||
if !partner.CurActManager.IsVendorActExist(jxcontext.AdminCtx, promotionID, model.VendorIDJD) {
|
if !partner.CurActManager.IsVendorActExist(jxcontext.AdminCtx, promotionID, model.VendorIDJD) {
|
||||||
act, actStoreSkuList, err := getActFromJD(promotionID)
|
act, actStoreSkuList, err := getActFromJD(promotionID)
|
||||||
if err == nil && len(actStoreSkuList) > 0 {
|
if err == nil && len(actStoreSkuList) > 0 {
|
||||||
_, err = partner.CurActManager.CreateActFromVendor(jxcontext.AdminCtx, act, actStoreSkuList)
|
_, err = partner.CurActManager.CreateActFromVendor(jxcontext.AdminCtx, act, actStoreSkuList)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
retVal = jdapi.Err2CallbackResponse(err, promotionID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
})
|
||||||
retVal = jdapi.Err2CallbackResponse(err, promotionID)
|
} else {
|
||||||
}
|
actMap.Delete(intPromotionID)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user