- 根据京东回调存储京东到家活动信息至本地
This commit is contained in:
@@ -24,6 +24,15 @@ type LogicUpdateInfo struct {
|
||||
Condition map[string]interface{}
|
||||
}
|
||||
|
||||
var (
|
||||
jdSkuActStatusMap = map[int]int{
|
||||
jdapi.PromotionStateNotConfirm: model.ActStatusNA,
|
||||
jdapi.PromotionStateConfirmed: model.ActStatusCreated,
|
||||
jdapi.PromotionStateCanceled: model.ActStatusCanceled,
|
||||
jdapi.PromotionStateEnded: model.ActStatusEnded,
|
||||
}
|
||||
)
|
||||
|
||||
func splitPromotionSku(skus []*jdapi.PromotionSku, maxCount int) (skusList [][]*jdapi.PromotionSku) {
|
||||
for {
|
||||
skusLen := len(skus)
|
||||
@@ -37,6 +46,19 @@ func splitPromotionSku(skus []*jdapi.PromotionSku, maxCount int) (skusList [][]*
|
||||
return skusList
|
||||
}
|
||||
|
||||
func jdSkuActType2Jx(actType int) int {
|
||||
if actType == jdapi.PromotionTypeDirectDown {
|
||||
return model.ActSkuDirectDown
|
||||
} else if actType == jdapi.PromotionTypeSeckill || actType == jdapi.PromotionTypeLimitedTime {
|
||||
return model.ActSkuSecKill
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func jdSkuActStatus2Jx(jdActState int) int {
|
||||
return jdSkuActStatusMap[jdActState]
|
||||
}
|
||||
|
||||
func CreatePromotionInfos(promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising, traceId string) (infoId int64, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
@@ -273,17 +295,60 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) OnActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
func OnActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
retVal = c.onActMsg(msg)
|
||||
retVal = curPurchaseHandler.onActMsg(msg)
|
||||
}, jxutils.ComposeUniversalOrderID(msg.BillID, model.VendorIDJD))
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) onActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if msg.StatusID == jdapi.PromotionStatusSingleOK || msg.StatusID == jdapi.PromotionStatusLimitTimeOK {
|
||||
promotionID := msg.BillID
|
||||
if !partner.CurActManager.IsVendorActExist(jxcontext.AdminCtx, promotionID, model.VendorIDJD) {
|
||||
act, actStoreSkuList, err := getActFromJD(promotionID)
|
||||
if err == nil {
|
||||
_, err = partner.CurActManager.CreateActFromVendor(jxcontext.AdminCtx, act, actStoreSkuList)
|
||||
}
|
||||
if err != nil {
|
||||
retVal = jdapi.Err2CallbackResponse(err, promotionID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func getActFromJD(promotionID int64) (act *model.Act, actStoreSkuList []*model.ActStoreSku) {
|
||||
return act, actStoreSkuList
|
||||
func getActFromJD(promotionID string) (act *model.Act2, actStoreSkuList []*model.ActStoreSku2, err error) {
|
||||
result, err := api.JdAPI.QueryPromotionInfo(utils.Str2Int64(promotionID))
|
||||
if err == nil && len(result.SkuResultList) > 0 {
|
||||
act = &model.Act2{
|
||||
Act: model.Act{Name: result.Source + "-" + utils.Int64ToStr(result.PromotionInfoID),
|
||||
Type: jdSkuActType2Jx(result.PromotionType),
|
||||
Status: jdSkuActStatus2Jx(result.PromotionState),
|
||||
BeginAt: result.BeginTime.GoTime(),
|
||||
EndAt: result.EndTime.GoTime(),
|
||||
Source: result.Source,
|
||||
CreateType: model.ActCreateTypeCallback,
|
||||
PricePercentage: 0,
|
||||
LimitDaily: result.SkuResultList[0].LimitDaily,
|
||||
LimitCount: 1,
|
||||
},
|
||||
VendorID: model.VendorIDJD,
|
||||
VendorActID: promotionID,
|
||||
}
|
||||
if result.SkuResultList[0].LimitPin == 1 || result.SkuResultList[0].LimitDevice == 1 {
|
||||
act.LimitUser = 1
|
||||
}
|
||||
|
||||
for _, v := range result.SkuResultList {
|
||||
if v.PromotionState != jdapi.PromotionStateCanceled {
|
||||
actStoreSkuList = append(actStoreSkuList, &model.ActStoreSku2{
|
||||
VendorStoreID: utils.Int64ToStr(v.StationNo),
|
||||
VendorSkuID: utils.Int64ToStr(v.SkuID),
|
||||
ActualActPrice: int64(v.PromotionPrice),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return act, actStoreSkuList, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user