- 根据京东回调存储京东到家活动信息至本地

This commit is contained in:
gazebo
2019-07-08 17:01:17 +08:00
parent 6c4ca2fd17
commit 9d08a1bcc9
9 changed files with 301 additions and 42 deletions

View File

@@ -9,6 +9,11 @@ import (
"git.rosy.net.cn/jx-callback/business/model/dao"
)
type IActManager interface {
IsVendorActExist(ctx *jxcontext.Context, vendorActID string, vendorID int) (isExist bool)
CreateActFromVendor(ctx *jxcontext.Context, act2 *model.Act2, actStoreSku []*model.ActStoreSku2) (actID int, err error)
}
type IPurchasePlatformActHandler interface {
// // 如果是单品级活动actOrderRules为空
// // 如果是订单级活动actStoreSku可以为空表示不限制SKU
@@ -20,6 +25,14 @@ type IPurchasePlatformActHandler interface {
SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actOrderRules []*model.ActOrderRule, actStoreSkuList []*model.ActStoreSku2) (err error)
}
var (
CurActManager IActManager
)
func InitActManager(p IActManager) {
CurActManager = p
}
func SplitActStoreSku(actStoreSkuList []*model.ActStoreSku2) (actStoreSkuMap map[int][]*model.ActStoreSku2) {
actStoreSkuMap = make(map[int][]*model.ActStoreSku2)
for _, v := range actStoreSkuList {

View File

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