同步错误返回解决冲突
This commit is contained in:
@@ -65,12 +65,12 @@ 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) {
|
||||
func CreatePromotionInfos(vendorOrgCode string, promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising, traceId string) (infoId int64, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
infoId, err = getAPI("").CreatePromotionInfosSingle(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||
infoId, err = getAPI(vendorOrgCode).CreatePromotionInfosSingle(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||
} else {
|
||||
infoId, err = getAPI("").CreatePromotionInfosLimitTime(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||
infoId, err = getAPI(vendorOrgCode).CreatePromotionInfosLimitTime(name, beginDate, endDate, outInfoId, advertising, traceId)
|
||||
}
|
||||
} else {
|
||||
infoId = jxutils.GenFakeID()
|
||||
@@ -81,26 +81,26 @@ func CreatePromotionInfos(promotionType int, name string, beginDate, endDate tim
|
||||
return infoId, err
|
||||
}
|
||||
|
||||
func CreatePromotionRules(promotionType int, infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int, traceId string) (err error) {
|
||||
func CreatePromotionRules(vendorOrgCode string, promotionType int, infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
err = getAPI("").CreatePromotionRulesSingle(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||
err = getAPI(vendorOrgCode).CreatePromotionRulesSingle(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||
} else {
|
||||
err = getAPI("").CreatePromotionRulesLimitTime(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||
err = getAPI(vendorOrgCode).CreatePromotionRulesLimitTime(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func CreatePromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
||||
func CreatePromotionSku(vendorOrgCode string, promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
for _, batchSkus := range splitPromotionSku(skus, jdapi.MaxPromotionSkuCount) {
|
||||
var tmpSkusResult []*jdapi.PromotionSku
|
||||
var tmpErr error
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
tmpSkusResult, tmpErr = getAPI("").CreatePromotionSkuSingle(infoId, outInfoId, batchSkus, traceId)
|
||||
tmpSkusResult, tmpErr = getAPI(vendorOrgCode).CreatePromotionSkuSingle(infoId, outInfoId, batchSkus, traceId)
|
||||
} else {
|
||||
tmpSkusResult, tmpErr = getAPI("").CreatePromotionSkuLimitTime(infoId, outInfoId, batchSkus, traceId)
|
||||
tmpSkusResult, tmpErr = getAPI(vendorOrgCode).CreatePromotionSkuLimitTime(infoId, outInfoId, batchSkus, traceId)
|
||||
}
|
||||
if err = tmpErr; err != nil {
|
||||
break
|
||||
@@ -111,14 +111,14 @@ func CreatePromotionSku(promotionType int, infoId int64, outInfoId string, skus
|
||||
return skusResult, err
|
||||
}
|
||||
|
||||
func CancelPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (err error) {
|
||||
func CancelPromotionSku(vendorOrgCode string, promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
for _, batchSkus := range splitPromotionSku(skus, jdapi.MaxPromotionSkuCount) {
|
||||
var tmpErr error
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
tmpErr = getAPI("").CancelPromotionSkuSingle(infoId, outInfoId, batchSkus, traceId)
|
||||
tmpErr = getAPI(vendorOrgCode).CancelPromotionSkuSingle(infoId, outInfoId, batchSkus, traceId)
|
||||
} else {
|
||||
tmpErr = getAPI("").CancelPromotionSkuLimitTime(infoId, outInfoId, batchSkus, traceId)
|
||||
tmpErr = getAPI(vendorOrgCode).CancelPromotionSkuLimitTime(infoId, outInfoId, batchSkus, traceId)
|
||||
}
|
||||
if err = tmpErr; err != nil {
|
||||
break
|
||||
@@ -128,45 +128,45 @@ func CancelPromotionSku(promotionType int, infoId int64, outInfoId string, skus
|
||||
return err
|
||||
}
|
||||
|
||||
func ConfirmPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
||||
func ConfirmPromotion(vendorOrgCode string, promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
return getAPI("").ConfirmPromotionSingle(infoId, outInfoId, traceId)
|
||||
return getAPI(vendorOrgCode).ConfirmPromotionSingle(infoId, outInfoId, traceId)
|
||||
} else {
|
||||
return getAPI("").ConfirmPromotionLimitTime(infoId, outInfoId, traceId)
|
||||
return getAPI(vendorOrgCode).ConfirmPromotionLimitTime(infoId, outInfoId, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func CancelPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
||||
func CancelPromotion(vendorOrgCode string, promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
err = getAPI("").CancelPromotionSingle(infoId, outInfoId, traceId)
|
||||
err = getAPI(vendorOrgCode).CancelPromotionSingle(infoId, outInfoId, traceId)
|
||||
} else {
|
||||
err = getAPI("").CancelPromotionLimitTime(infoId, outInfoId, traceId)
|
||||
err = getAPI(vendorOrgCode).CancelPromotionLimitTime(infoId, outInfoId, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func AdjustPromotionTime(promotionType int, infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
||||
func AdjustPromotionTime(vendorOrgCode string, promotionType int, infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
err = getAPI("").AdjustPromotionTimeSingle(infoId, outInfoId, endDate, traceId)
|
||||
err = getAPI(vendorOrgCode).AdjustPromotionTimeSingle(infoId, outInfoId, endDate, traceId)
|
||||
} else {
|
||||
err = getAPI("").AdjustPromotionTimeLimitTime(infoId, outInfoId, endDate, traceId)
|
||||
err = getAPI(vendorOrgCode).AdjustPromotionTimeLimitTime(infoId, outInfoId, endDate, traceId)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func AdjustPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
||||
func AdjustPromotionSku(vendorOrgCode string, promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if promotionType == model.ActSkuDirectDown {
|
||||
skusResult, err = getAPI("").AdjustPromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
||||
skusResult, err = getAPI(vendorOrgCode).AdjustPromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
||||
} else {
|
||||
skusResult, err = getAPI("").AdjustPromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
||||
skusResult, err = getAPI(vendorOrgCode).AdjustPromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
||||
}
|
||||
}
|
||||
return skusResult, err
|
||||
@@ -194,12 +194,12 @@ func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.
|
||||
if act.VendorActID == "" {
|
||||
outInfoID = utils.Int2Str(act.ID)
|
||||
}
|
||||
infoID, err2 := CreatePromotionInfos(act.Type, act.GetRealActName(), act.BeginAt, act.EndAt, outInfoID, act.Advertising, traceInfo)
|
||||
infoID, err2 := CreatePromotionInfos(act.VendorOrgCode, act.Type, act.GetRealActName(), act.BeginAt, act.EndAt, outInfoID, act.Advertising, traceInfo)
|
||||
if err = err2; err == nil {
|
||||
vendorActID = utils.Int64ToStr(infoID)
|
||||
if err = CreatePromotionRules(act.Type, infoID, "", act.LimitUser, act.LimitUser, act.LimitCount, 1, traceInfo); err == nil {
|
||||
if _, err = CreatePromotionSku(act.Type, infoID, utils.Int2Str(act.ID), storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceInfo); err == nil {
|
||||
if err = ConfirmPromotion(act.Type, infoID, "", traceInfo); err == nil {
|
||||
if err = CreatePromotionRules(act.VendorOrgCode, act.Type, infoID, "", act.LimitUser, act.LimitUser, act.LimitCount, 1, traceInfo); err == nil {
|
||||
if _, err = CreatePromotionSku(act.VendorOrgCode, act.Type, infoID, utils.Int2Str(act.ID), storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceInfo); err == nil {
|
||||
if err = ConfirmPromotion(act.VendorOrgCode, act.Type, infoID, "", traceInfo); err == nil {
|
||||
for _, v := range actStoreSku {
|
||||
v.VendorActID = vendorActID
|
||||
}
|
||||
@@ -207,24 +207,24 @@ func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
CancelPromotion(act.Type, infoID, "", traceInfo)
|
||||
CancelPromotion(act.VendorOrgCode, act.Type, infoID, "", traceInfo)
|
||||
}
|
||||
}
|
||||
return vendorActID, err
|
||||
}
|
||||
|
||||
func cancelSkuActSkus(ctx *jxcontext.Context, actType int, vendorActID string, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
func cancelSkuActSkus(ctx *jxcontext.Context, vendorOrgCode string, actType int, vendorActID string, actStoreSku []*model.ActStoreSku2) (err error) {
|
||||
if vendorActID != "" {
|
||||
if skuList := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(skuList) > 0 {
|
||||
err = CancelPromotionSku(actType, utils.Str2Int64(vendorActID), "", skuList, ctx.GetTrackInfo())
|
||||
err = CancelPromotionSku(vendorOrgCode, actType, utils.Str2Int64(vendorActID), "", skuList, ctx.GetTrackInfo())
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func cancelSkuAct(ctx *jxcontext.Context, actType int, vendorActID string) (err error) {
|
||||
func cancelSkuAct(ctx *jxcontext.Context, vendorOrgCode string, actType int, vendorActID string) (err error) {
|
||||
if vendorActID != "" {
|
||||
err = CancelPromotion(actType, utils.Str2Int64(vendorActID), "", ctx.GetTrackInfo())
|
||||
err = CancelPromotion(vendorOrgCode, actType, utils.Str2Int64(vendorActID), "", ctx.GetTrackInfo())
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -256,7 +256,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
if model.IsSyncStatusDelete(act.SyncStatus) {
|
||||
for vendorActID := range vendorActInfoMap {
|
||||
if vendorActID != "" {
|
||||
if err = cancelSkuAct(ctx, act.Type, vendorActID); err != nil {
|
||||
if err = cancelSkuAct(ctx, act.VendorOrgCode, act.Type, vendorActID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -287,9 +287,9 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
if vendorActID != "" {
|
||||
if len(vendorActInfoMap[vendorActID]) == len(deleteActInfoMap[vendorActID]) {
|
||||
// todo 如果这个取消导致了整活动被取消的话,怎么设置京西活动的状态
|
||||
err = cancelSkuAct(ctx, act.Type, vendorActID)
|
||||
err = cancelSkuAct(ctx, act.VendorOrgCode, act.Type, vendorActID)
|
||||
} else {
|
||||
err = cancelSkuActSkus(ctx, act.Type, vendorActID, deleteActInfoMap[vendorActID])
|
||||
err = cancelSkuActSkus(ctx, act.VendorOrgCode, act.Type, vendorActID, deleteActInfoMap[vendorActID])
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -325,7 +325,7 @@ func (c *PurchaseHandler) onActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.C
|
||||
if _, ok := actMap.Load(intPromotionID); !ok {
|
||||
utils.CallFuncAsync(func() {
|
||||
if !partner.CurActManager.IsVendorActExist(jxcontext.AdminCtx, promotionID, model.VendorIDJD) {
|
||||
act, actStoreSkuList, err := getActFromJD(promotionID)
|
||||
act, actStoreSkuList, err := getActFromJD(appKey2OrgCode(msg.AppKey), promotionID)
|
||||
if err == nil && len(actStoreSkuList) > 0 {
|
||||
_, err = partner.CurActManager.CreateActFromVendor(jxcontext.AdminCtx, act, actStoreSkuList)
|
||||
}
|
||||
@@ -341,8 +341,8 @@ func (c *PurchaseHandler) onActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.C
|
||||
return retVal
|
||||
}
|
||||
|
||||
func getActFromJD(promotionID string) (act *model.Act2, actStoreSkuList []*model.ActStoreSku2, err error) {
|
||||
result, err := getAPI("").QueryPromotionInfo(utils.Str2Int64(promotionID))
|
||||
func getActFromJD(vendorOrgCode, promotionID string) (act *model.Act2, actStoreSkuList []*model.ActStoreSku2, err error) {
|
||||
result, err := getAPI(vendorOrgCode).QueryPromotionInfo(utils.Str2Int64(promotionID))
|
||||
if err == nil && len(result.SkuResultList) > 0 {
|
||||
act = &model.Act2{
|
||||
Act: model.Act{
|
||||
@@ -357,8 +357,9 @@ func getActFromJD(promotionID string) (act *model.Act2, actStoreSkuList []*model
|
||||
LimitDaily: result.SkuResultList[0].LimitDaily,
|
||||
LimitCount: 1,
|
||||
},
|
||||
VendorID: model.VendorIDJD,
|
||||
VendorActID: promotionID,
|
||||
VendorID: model.VendorIDJD,
|
||||
VendorOrgCode: vendorOrgCode,
|
||||
VendorActID: promotionID,
|
||||
}
|
||||
if utils.IsTimeZero(act.BeginAt) {
|
||||
act.BeginAt = result.BeginTime.GoTime()
|
||||
|
||||
@@ -6,21 +6,21 @@ import (
|
||||
|
||||
func OnOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if CurPurchaseHandler != nil {
|
||||
retVal = CurPurchaseHandler.OnOrderMsg(msg)
|
||||
retVal = CurPurchaseHandler.OnOrderMsg(appKey2OrgCode(msg.AppKey), msg)
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func OnWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if CurPurchaseHandler != nil {
|
||||
retVal = CurPurchaseHandler.OnWaybillMsg(msg)
|
||||
retVal = CurPurchaseHandler.OnWaybillMsg(appKey2OrgCode(msg.AppKey), msg)
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func OnStoreMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if CurPurchaseHandler != nil {
|
||||
retVal = CurPurchaseHandler.OnStoreMsg(msg)
|
||||
retVal = CurPurchaseHandler.OnStoreMsg(appKey2OrgCode(msg.AppKey), msg)
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
@@ -18,13 +18,14 @@ func (p *PurchaseHandler) OnFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *j
|
||||
// 京东正向/退款订单类型处理--存储
|
||||
func (p *PurchaseHandler) onFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
var err error
|
||||
a := GetAPIByAppKey(msg.AppKey)
|
||||
// if msg.StatusID == jdapi.OrderStatusPayFinishedSettle || msg.StatusID == jdapi.OrderStatusTipChanged || msg.StatusID == jdapi.OrderStatusSwitch2SelfSettle { // 如果是正向单
|
||||
if msg.StatusID == jdapi.OrderStatusPayFinishedSettle || msg.StatusID == jdapi.OrderStatusTipChanged || msg.StatusID == jdapi.OrderStatusAdjustSettle || msg.StatusID == jdapi.OrderStatusSwitch2SelfSettle { // 如果是正向单
|
||||
order, err2 := partner.CurOrderManager.LoadOrder(msg.BillID, model.VendorIDJD)
|
||||
if err = err2; err == nil {
|
||||
orderData, err2 := getAPI("").QuerySingleOrder(msg.BillID)
|
||||
orderData, err2 := a.QuerySingleOrder(msg.BillID)
|
||||
if err = err2; err == nil {
|
||||
orderFinancial, err2 := CurPurchaseHandler.OrderDetail2Financial(orderData, false, order)
|
||||
orderFinancial, err2 := CurPurchaseHandler.OrderDetail2Financial(a, orderData, false, order)
|
||||
if err = err2; err == nil {
|
||||
if msg.StatusID == jdapi.OrderStatusPayFinishedSettle {
|
||||
err = partner.CurOrderManager.SaveOrderFinancialInfo(orderFinancial, partner.CreatedPeration)
|
||||
@@ -37,7 +38,7 @@ func (p *PurchaseHandler) onFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *j
|
||||
err = nil
|
||||
}
|
||||
} else if msg.StatusID == jdapi.AfsServiceStateRefundSuccess || msg.StatusID == jdapi.AfsServiceStateReturnGoodsSuccess { // 如果是退款单
|
||||
orderData, err2 := getAPI("").GetAfsService(msg.BillID)
|
||||
orderData, err2 := a.GetAfsService(msg.BillID)
|
||||
if err = err2; err == nil {
|
||||
err = partner.CurOrderManager.SaveAfsOrderFinancialInfo(CurPurchaseHandler.AfsOrderDetail2Financial(orderData))
|
||||
}
|
||||
@@ -46,7 +47,7 @@ func (p *PurchaseHandler) onFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *j
|
||||
}
|
||||
|
||||
// 处理京东正向订单信息
|
||||
func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}, isFromOrderDetail bool, order *model.GoodsOrder) (orderFinancial *model.OrderFinancial, err error) {
|
||||
func (p *PurchaseHandler) OrderDetail2Financial(a *jdapi.API, orderData map[string]interface{}, isFromOrderDetail bool, order *model.GoodsOrder) (orderFinancial *model.OrderFinancial, err error) {
|
||||
orderFinancial = &model.OrderFinancial{
|
||||
VendorID: model.VendorIDJD,
|
||||
VendorOrderID: utils.Int64ToStr(utils.MustInterface2Int64(orderData["orderId"])),
|
||||
@@ -149,9 +150,9 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}
|
||||
}
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(orderFinancial.Discounts, false))
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(orderFinancial.Discounts, false))
|
||||
}
|
||||
order1, err2 := getAPI("").OrderShoudSettlementService(orderFinancial.VendorOrderID)
|
||||
order1, err2 := a.OrderShoudSettlementService(orderFinancial.VendorOrderID)
|
||||
if err = err2; err == nil {
|
||||
orderFinancial.ShopMoney = utils.Interface2Int64WithDefault(order1["settlementAmount"], 0)
|
||||
orderFinancial.PmMoney += utils.Interface2Int64WithDefault(order1["goodsCommission"], 0)
|
||||
@@ -160,10 +161,6 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}
|
||||
orderFinancial.PmMoney += utils.Interface2Int64WithDefault(order1["guaranteedCommission"], 0)
|
||||
orderFinancial.PmSkuSubsidyMoney = utils.Interface2Int64WithDefault(order1["platSkuGoodsDiscountMoney"], 0)
|
||||
orderFinancial.PmSubsidyMoney = utils.Interface2Int64WithDefault(order1["platOrderGoodsDiscountMoney"], 0) + orderFinancial.PmSkuSubsidyMoney
|
||||
} else {
|
||||
if !isFromOrderDetail {
|
||||
// globals.SugarLogger.Warnf("jd OrderDetail2Financial, orderID:%s is not found from getAPI("").OrderShoudSettlementService, err:%v", orderFinancial.VendorOrderID, err)
|
||||
}
|
||||
}
|
||||
return orderFinancial, err
|
||||
}
|
||||
@@ -182,6 +179,7 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac
|
||||
BoxMoney: utils.MustInterface2Int64(orderData["packagingMoney"]),
|
||||
TongchengFreightMoney: utils.MustInterface2Int64(orderData["tongchengFreightMoney"]),
|
||||
SkuBoxMoney: utils.MustInterface2Int64(orderData["mealBoxMoney"]),
|
||||
VendorOrgCode: utils.Interface2String(orderData["venderId"]),
|
||||
}
|
||||
order, err := partner.CurOrderManager.LoadOrder(afsOrder.VendorOrderID, afsOrder.VendorID)
|
||||
if err == nil {
|
||||
@@ -230,10 +228,10 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac
|
||||
return afsOrder
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) OnOrderDetail(orderDetail map[string]interface{}, peration string) (err error) {
|
||||
func (p *PurchaseHandler) OnOrderDetail(a *jdapi.API, orderDetail map[string]interface{}, peration string) (err error) {
|
||||
order, err := partner.CurOrderManager.LoadOrder(utils.Int64ToStr(utils.MustInterface2Int64(orderDetail["orderId"])), model.VendorIDJD)
|
||||
if err == nil {
|
||||
orderFinancial, err2 := CurPurchaseHandler.OrderDetail2Financial(orderDetail, true, order)
|
||||
orderFinancial, err2 := CurPurchaseHandler.OrderDetail2Financial(a, orderDetail, true, order)
|
||||
if err = err2; err == nil {
|
||||
err = partner.CurOrderManager.SaveOrderFinancialInfo(orderFinancial, peration)
|
||||
}
|
||||
|
||||
@@ -26,14 +26,30 @@ func getAPI(appOrgCode string) (apiObj *jdapi.API) {
|
||||
return partner.CurAPIManager.GetAPI(model.VendorIDJD, appOrgCode).(*jdapi.API)
|
||||
}
|
||||
|
||||
func GetAPIByToken(token string) (apiObj *jdapi.API) {
|
||||
if token == "" {
|
||||
func GetAPI(appOrgCode string) (apiObj *jdapi.API) {
|
||||
return getAPI(appOrgCode)
|
||||
}
|
||||
|
||||
func appKey2OrgCode(appKey string) (vendorOrgCode string) {
|
||||
apiList := partner.CurAPIManager.GetAppOrgCodeList(model.VendorIDJD)
|
||||
for _, v := range apiList {
|
||||
jdAPI := partner.CurAPIManager.GetAPI(model.VendorIDJD, v).(*jdapi.API)
|
||||
if jdAPI.GetAppKey() == appKey {
|
||||
vendorOrgCode = v
|
||||
break
|
||||
}
|
||||
}
|
||||
return vendorOrgCode
|
||||
}
|
||||
|
||||
func GetAPIByAppKey(appKey string) (apiObj *jdapi.API) {
|
||||
if appKey == "" {
|
||||
apiObj = getAPI("")
|
||||
} else {
|
||||
apiList := partner.CurAPIManager.GetAppOrgCodeList(model.VendorIDJD)
|
||||
for _, v := range apiList {
|
||||
jdAPI := partner.CurAPIManager.GetAPI(model.VendorIDJD, v).(*jdapi.API)
|
||||
if jdAPI.GetToken() == token {
|
||||
if jdAPI.GetAppKey() == appKey {
|
||||
apiObj = jdAPI
|
||||
break
|
||||
}
|
||||
@@ -75,6 +91,6 @@ func JxStoreStatus2JdStatus(status int) (yn, closeStatus int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UploadImg(ctx *jxcontext.Context, imgURL string, imgData []byte, imgName string, imgType int) (imgHint string, err error) {
|
||||
func (p *PurchaseHandler) UploadImg(ctx *jxcontext.Context, vendorOrgCode, imgURL string, imgData []byte, imgName string, imgType int) (imgHint string, err error) {
|
||||
return imgHint, err
|
||||
}
|
||||
|
||||
@@ -44,19 +44,19 @@ var (
|
||||
selfTakeCodeReg = regexp.MustCompile(`等待用户凭提货码(\d+)于`)
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) OnOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
func (c *PurchaseHandler) OnOrderMsg(vendorOrgCode string, msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
retVal = c.onOrderMsg(msg)
|
||||
retVal = c.onOrderMsg(vendorOrgCode, msg)
|
||||
}, jxutils.ComposeUniversalOrderID(msg.BillID, model.VendorIDJD))
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) updateOrderFinancialInfo(orderID string) (err error) {
|
||||
func (c *PurchaseHandler) updateOrderFinancialInfo(a *jdapi.API, orderID string) (err error) {
|
||||
order := &model.GoodsOrder{
|
||||
VendorOrderID: orderID,
|
||||
VendorID: model.VendorIDJD,
|
||||
}
|
||||
orderSettlement, err := getAPI("").OrderShoudSettlementService2(orderID)
|
||||
orderSettlement, err := a.OrderShoudSettlementService2(orderID)
|
||||
if err == nil {
|
||||
if orderSettlement != nil {
|
||||
updateOrderBySettleMent(order, orderSettlement)
|
||||
@@ -66,7 +66,8 @@ func (c *PurchaseHandler) updateOrderFinancialInfo(orderID string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) onOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
func (c *PurchaseHandler) onOrderMsg(vendorOrgCode string, msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
a := getAPI(vendorOrgCode)
|
||||
status := c.callbackMsg2Status(msg)
|
||||
if jdapi.StatusIDNewOrder == msg.StatusID {
|
||||
status.Status = model.OrderStatusNew // 因为京东将事件32000与状态32000混用,事件32000可能是新订单,也可能是已接单,统一当成新订单处理
|
||||
@@ -76,22 +77,22 @@ func (c *PurchaseHandler) onOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi
|
||||
}
|
||||
if msg.MsgURL == jdapi.CallbackMsgOrderAccounting {
|
||||
retVal = c.OnFinancialMsg(msg)
|
||||
retVal = jdapi.Err2CallbackResponse(c.updateOrderFinancialInfo(msg.BillID), status.VendorStatus)
|
||||
retVal = jdapi.Err2CallbackResponse(c.updateOrderFinancialInfo(a, msg.BillID), status.VendorStatus)
|
||||
} else if msg.MsgURL == jdapi.CallbackMsgAfterSaleBillStatus {
|
||||
retVal = c.OnAfsOrderMsg(msg)
|
||||
retVal = c.OnAfsOrderMsg(a, msg)
|
||||
} else {
|
||||
// 新订单事件,与订单状态有点冲突
|
||||
if jdapi.StatusIDNewOrder == msg.StatusID {
|
||||
retVal = c.onOrderNew(msg, status)
|
||||
retVal = c.onOrderNew(a, msg, status)
|
||||
} else if jdapi.OrderStatusAdjust == msg.StatusID {
|
||||
retVal = c.onOrderAdjust(msg, status)
|
||||
retVal = c.onOrderAdjust(a, msg, status)
|
||||
} else {
|
||||
if msg.StatusID == jdapi.OrderStatusAddComment || msg.StatusID == jdapi.OrderStatusModifyComment {
|
||||
utils.CallFuncAsync(func() {
|
||||
c.onOrderComment2(msg)
|
||||
c.onOrderComment2(a, msg)
|
||||
})
|
||||
}
|
||||
err := partner.CurOrderManager.OnOrderStatusChanged(status)
|
||||
err := partner.CurOrderManager.OnOrderStatusChanged(vendorOrgCode, status)
|
||||
// if globals.HandleLegacyJxOrder && err == nil {
|
||||
// c.legacyJdOrderStatusChanged(status)
|
||||
// }
|
||||
@@ -109,7 +110,7 @@ func updateOrderBySettleMent(order *model.GoodsOrder, orderSettlement *jdapi.Ord
|
||||
}
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) getOrder(orderID string) (order *model.GoodsOrder, orderMap map[string]interface{}, err error) {
|
||||
func (c *PurchaseHandler) getOrder(a *jdapi.API, orderID string) (order *model.GoodsOrder, orderMap map[string]interface{}, err error) {
|
||||
globals.SugarLogger.Debugf("jd getOrder orderID:%s", orderID)
|
||||
var (
|
||||
realMobile string
|
||||
@@ -120,16 +121,16 @@ func (c *PurchaseHandler) getOrder(orderID string) (order *model.GoodsOrder, ord
|
||||
taskIndex := batchItemList[0].(int)
|
||||
switch taskIndex {
|
||||
case 0:
|
||||
orderMap, err = getAPI("").QuerySingleOrder(orderID)
|
||||
orderMap, err = a.QuerySingleOrder(orderID)
|
||||
if err == nil {
|
||||
order = c.Map2Order(orderMap)
|
||||
realMobile, _ = getAPI("").GetRealMobile4Order(orderID, order.VendorStoreID)
|
||||
realMobile, _ = a.GetRealMobile4Order(orderID, order.VendorStoreID)
|
||||
if realMobile != "" {
|
||||
order.ConsigneeMobile2 = jxutils.FormalizeMobile(realMobile)
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
orderSettlement, _ = getAPI("").OrderShoudSettlementService2(orderID)
|
||||
orderSettlement, _ = a.OrderShoudSettlementService2(orderID)
|
||||
}
|
||||
return nil, err
|
||||
}, []int{0, 1})
|
||||
@@ -141,8 +142,8 @@ func (c *PurchaseHandler) getOrder(orderID string) (order *model.GoodsOrder, ord
|
||||
return order, orderMap, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetOrder(orderID string) (order *model.GoodsOrder, err error) {
|
||||
order, _, err = c.getOrder(orderID)
|
||||
func (c *PurchaseHandler) GetOrder(vendorOrgCode, orderID string) (order *model.GoodsOrder, err error) {
|
||||
order, _, err = c.getOrder(getAPI(vendorOrgCode), orderID)
|
||||
return order, err
|
||||
}
|
||||
|
||||
@@ -178,6 +179,7 @@ func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
ActualPayPrice: utils.MustInterface2Int64(result["orderBuyerPayableMoney"]),
|
||||
DistanceFreightMoney: utils.Interface2Int64WithDefault(result["merchantPaymentDistanceFreightMoney"], 0),
|
||||
DeliveryType: deliveryTypeMap[int(utils.Str2Int64WithDefault(utils.Interface2String(result["deliveryCarrierNo"]), 0))],
|
||||
VendorOrgCode: utils.Interface2String(result["orgCode"]),
|
||||
}
|
||||
if orderInvoice, ok := result["orderInvoice"].(map[string]interface{}); ok && orderInvoice != nil {
|
||||
order.InvoiceTitle = utils.Interface2String(orderInvoice["invoiceTitle"])
|
||||
@@ -240,27 +242,27 @@ func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
}
|
||||
|
||||
//
|
||||
func (c *PurchaseHandler) onOrderNew(msg *jdapi.CallbackOrderMsg, orderStatus *model.OrderStatus) (response *jdapi.CallbackResponse) {
|
||||
func (c *PurchaseHandler) onOrderNew(a *jdapi.API, msg *jdapi.CallbackOrderMsg, orderStatus *model.OrderStatus) (response *jdapi.CallbackResponse) {
|
||||
globals.SugarLogger.Debugf("onOrderNew orderID:%s", msg.BillID)
|
||||
order, orderMap, err := c.getOrder(msg.BillID)
|
||||
order, orderMap, err := c.getOrder(a, msg.BillID)
|
||||
if err == nil {
|
||||
globals.SugarLogger.Debugf("onOrderNew2 orderID:%s", msg.BillID)
|
||||
if err = partner.CurOrderManager.OnOrderNew(order, orderStatus); err == nil {
|
||||
utils.CallFuncAsync(func() {
|
||||
c.OnOrderDetail(orderMap, partner.CreatedPeration)
|
||||
c.OnOrderDetail(a, orderMap, partner.CreatedPeration)
|
||||
})
|
||||
}
|
||||
}
|
||||
return jdapi.Err2CallbackResponse(err, "jd onOrderNew")
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) onOrderAdjust(msg *jdapi.CallbackOrderMsg, orderStatus *model.OrderStatus) *jdapi.CallbackResponse {
|
||||
order, orderMap, err := c.getOrder(msg.BillID)
|
||||
func (c *PurchaseHandler) onOrderAdjust(a *jdapi.API, msg *jdapi.CallbackOrderMsg, orderStatus *model.OrderStatus) *jdapi.CallbackResponse {
|
||||
order, orderMap, err := c.getOrder(a, msg.BillID)
|
||||
if err == nil {
|
||||
err = partner.CurOrderManager.OnOrderAdjust(order, orderStatus)
|
||||
if err == nil {
|
||||
utils.CallFuncAsync(func() {
|
||||
c.OnOrderDetail(orderMap, partner.UpdatedPeration)
|
||||
c.OnOrderDetail(a, orderMap, partner.UpdatedPeration)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -284,9 +286,10 @@ func (c *PurchaseHandler) callbackMsg2Status(msg *jdapi.CallbackOrderMsg) *model
|
||||
|
||||
func (c *PurchaseHandler) postFakeMsg(vendorOrderID, vendorStatus string) {
|
||||
msg := &jdapi.CallbackOrderMsg{
|
||||
BillID: vendorOrderID,
|
||||
StatusID: vendorStatus,
|
||||
Timestamp: utils.Time2Str(time.Now()),
|
||||
CallbackMsg: &jdapi.CallbackMsg{},
|
||||
BillID: vendorOrderID,
|
||||
StatusID: vendorStatus,
|
||||
Timestamp: utils.Time2Str(time.Now()),
|
||||
}
|
||||
utils.CallFuncAsync(func() {
|
||||
OnOrderMsg(msg)
|
||||
@@ -303,8 +306,8 @@ func (c *PurchaseHandler) getStatusFromVendorStatus(vendorStatus string) int {
|
||||
|
||||
func (c *PurchaseHandler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool, userName string) (err error) {
|
||||
globals.SugarLogger.Debugf("jd AcceptOrRefuseOrder orderID:%s, isAcceptIt:%t", order.VendorOrderID, isAcceptIt)
|
||||
if globals.EnableStoreWrite {
|
||||
err = getAPI("").OrderAcceptOperate(order.VendorOrderID, isAcceptIt, userName)
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI(order.VendorOrgCode).OrderAcceptOperate(order.VendorOrderID, isAcceptIt, userName)
|
||||
if isAcceptIt && err == nil {
|
||||
c.postFakeMsg(order.VendorOrderID, jdapi.StatusIDWaitOutStore)
|
||||
}
|
||||
@@ -322,7 +325,7 @@ func (c *PurchaseHandler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptI
|
||||
func (c *PurchaseHandler) PickupGoods(order *model.GoodsOrder, isSelfDelivery bool, userName string) (err error) {
|
||||
globals.SugarLogger.Debugf("jd PickupGoods orderID:%s, isSelfDelivery:%t", order.VendorOrderID, isSelfDelivery)
|
||||
if !isSelfDelivery && globals.EnableJdStoreWrite {
|
||||
_, err = getAPI("").OrderJDZBDelivery(order.VendorOrderID, userName)
|
||||
_, err = getAPI(order.VendorOrgCode).OrderJDZBDelivery(order.VendorOrderID, userName)
|
||||
} else {
|
||||
c.postFakeMsg(order.VendorOrderID, jdapi.OrderStatusFinishedPickup)
|
||||
}
|
||||
@@ -331,21 +334,21 @@ func (c *PurchaseHandler) PickupGoods(order *model.GoodsOrder, isSelfDelivery bo
|
||||
|
||||
func (p *PurchaseHandler) AcceptOrRefuseFailedGetOrder(ctx *jxcontext.Context, order *model.GoodsOrder, isAcceptIt bool) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").ReceiveFailedAudit(order.VendorOrderID, isAcceptIt, ctx.GetUserName(), "")
|
||||
err = getAPI(order.VendorOrgCode).ReceiveFailedAudit(order.VendorOrderID, isAcceptIt, ctx.GetUserName(), "")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CallCourier(ctx *jxcontext.Context, order *model.GoodsOrder) (err error) { // 拣货失败后再次招唤平台配送
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").UrgeDispatching(order.VendorOrderID, ctx.GetUserName())
|
||||
err = getAPI(order.VendorOrgCode).UrgeDispatching(order.VendorOrderID, ctx.GetUserName())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) ConfirmReceiveGoods(ctx *jxcontext.Context, order *model.GoodsOrder) (err error) { // 投递失败后确认收到退货
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").ConfirmReceiveGoods(order.VendorOrderID)
|
||||
err = getAPI(order.VendorOrgCode).ConfirmReceiveGoods(order.VendorOrderID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -353,11 +356,11 @@ func (p *PurchaseHandler) ConfirmReceiveGoods(ctx *jxcontext.Context, order *mod
|
||||
func (c *PurchaseHandler) Swtich2SelfDeliver(order *model.GoodsOrder, userName string) (err error) {
|
||||
globals.SugarLogger.Debugf("jd Swtich2SelfDeliver orderID:%s", order.VendorOrderID)
|
||||
if globals.EnableJdStoreWrite {
|
||||
_, err = getAPI("").ModifySellerDelivery(order.VendorOrderID, userName)
|
||||
_, err = getAPI(order.VendorOrgCode).ModifySellerDelivery(order.VendorOrderID, userName)
|
||||
if err != nil {
|
||||
if errWithCode, ok := err.(*utils.ErrorWithCode); ok && errWithCode.Level() == 1 {
|
||||
globals.SugarLogger.Infof("Swtich2SelfDeliver failed with error:%v try get current status", err)
|
||||
if order2, err2 := c.GetOrder(order.VendorOrderID); err2 == nil {
|
||||
if order2, err2 := c.GetOrder(order.VendorOrgCode, order.VendorOrderID); err2 == nil {
|
||||
var mapData map[string]interface{}
|
||||
if err2 = utils.UnmarshalUseNumber([]byte(order2.OriginalData), &mapData); err2 == nil {
|
||||
if utils.Interface2String(mapData["deliveryCarrierNo"]) == "2938" { // 当前已经是自送状态了
|
||||
@@ -374,7 +377,7 @@ func (c *PurchaseHandler) Swtich2SelfDeliver(order *model.GoodsOrder, userName s
|
||||
func (c *PurchaseHandler) Swtich2SelfDelivered(order *model.GoodsOrder, userName string) (err error) {
|
||||
globals.SugarLogger.Debugf("jd Swtich2SelfDelivered orderID:%s", order.VendorOrderID)
|
||||
if globals.EnableJdStoreWrite {
|
||||
_, err = getAPI("").DeliveryEndOrder(order.VendorOrderID, userName)
|
||||
_, err = getAPI(order.VendorOrgCode).DeliveryEndOrder(order.VendorOrderID, userName)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -382,7 +385,7 @@ func (c *PurchaseHandler) Swtich2SelfDelivered(order *model.GoodsOrder, userName
|
||||
func (c *PurchaseHandler) SelfDeliverDelivering(order *model.GoodsOrder, userName string) (err error) {
|
||||
globals.SugarLogger.Debugf("jd SelfDeliverDelivering orderID:%s", order.VendorOrderID)
|
||||
if globals.EnableJdStoreWrite {
|
||||
_, err = getAPI("").OrderSerllerDelivery(order.VendorOrderID, userName)
|
||||
_, err = getAPI(order.VendorOrgCode).OrderSerllerDelivery(order.VendorOrderID, userName)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -397,13 +400,13 @@ func (c *PurchaseHandler) SelfDeliverDelivered(order *model.GoodsOrder, userName
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetOrderRealMobile(ctx *jxcontext.Context, order *model.GoodsOrder) (mobile string, err error) {
|
||||
mobile, err = getAPI("").GetRealMobile4Order(order.VendorOrderID, order.VendorStoreID)
|
||||
mobile, err = getAPI(order.VendorOrgCode).GetRealMobile4Order(order.VendorOrderID, order.VendorStoreID)
|
||||
return mobile, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) AgreeOrRefuseCancel(ctx *jxcontext.Context, order *model.GoodsOrder, isAgree bool, reason string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").OrderCancelOperate(order.VendorOrderID, isAgree, ctx.GetUserName(), reason)
|
||||
err = getAPI(order.VendorOrgCode).OrderCancelOperate(order.VendorOrderID, isAgree, ctx.GetUserName(), reason)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -411,7 +414,7 @@ func (c *PurchaseHandler) AgreeOrRefuseCancel(ctx *jxcontext.Context, order *mod
|
||||
func (c *PurchaseHandler) CancelOrder(ctx *jxcontext.Context, order *model.GoodsOrder, reason string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err1 := c.Swtich2SelfDeliver(order, ctx.GetUserName())
|
||||
if err = getAPI("").CancelAndRefund(order.VendorOrderID, ctx.GetUserName(), reason); err != nil {
|
||||
if err = getAPI(order.VendorOrgCode).CancelAndRefund(order.VendorOrderID, ctx.GetUserName(), reason); err != nil {
|
||||
if err1 != nil {
|
||||
err = fmt.Errorf("取消订单失败,京东取消订单是要先转为自送再处理,转自送失败:%v", err1)
|
||||
}
|
||||
@@ -430,12 +433,12 @@ func (c *PurchaseHandler) AdjustOrder(ctx *jxcontext.Context, order *model.Goods
|
||||
})
|
||||
}
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").AdjustOrder(order.VendorOrderID, ctx.GetUserName(), reason, oaosAdjustDTOList)
|
||||
err = getAPI(order.VendorOrgCode).AdjustOrder(order.VendorOrderID, ctx.GetUserName(), reason, oaosAdjustDTOList)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, parentTask tasksch.ITask, queryDate time.Time, vendorStoreID string) (vendorOrderIDs []string, err error) {
|
||||
func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, vendorOrgCode string, parentTask tasksch.ITask, queryDate time.Time, vendorStoreID string) (vendorOrderIDs []string, err error) {
|
||||
if utils.IsTimeZero(queryDate) {
|
||||
return nil, fmt.Errorf("queryDate必须指定")
|
||||
}
|
||||
@@ -449,7 +452,7 @@ func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, parentTask tasksch.
|
||||
if vendorStoreID != "" {
|
||||
queryParam.DeliveryStationNo = vendorStoreID
|
||||
}
|
||||
orderList, _, err := getAPI("").OrderQuery2(queryParam)
|
||||
orderList, _, err := getAPI(vendorOrgCode).OrderQuery2(queryParam)
|
||||
if err == nil {
|
||||
vendorOrderIDs = make([]string, len(orderList))
|
||||
for k, v := range orderList {
|
||||
@@ -460,12 +463,13 @@ func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, parentTask tasksch.
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateWaybillTip(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee int64) (err error) {
|
||||
orderInfo, err := getAPI("").QuerySingleOrder2(order.VendorOrderID)
|
||||
a := getAPI(order.VendorOrgCode)
|
||||
orderInfo, err := a.QuerySingleOrder2(order.VendorOrderID)
|
||||
if err == nil {
|
||||
tip2Add := int(tipFee) - orderInfo.Tips
|
||||
if tip2Add != 0 {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").OrderAddTips(order.VendorOrderID, tip2Add, ctx.GetUserName())
|
||||
err = a.OrderAddTips(order.VendorOrderID, tip2Add, ctx.GetUserName())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -473,7 +477,7 @@ func (c *PurchaseHandler) UpdateWaybillTip(ctx *jxcontext.Context, order *model.
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, order *model.GoodsOrder) (tipFee int64, err error) {
|
||||
orderInfo, err := getAPI("").QuerySingleOrder2(order.VendorOrderID)
|
||||
orderInfo, err := getAPI(order.VendorOrgCode).QuerySingleOrder2(order.VendorOrderID)
|
||||
if err == nil {
|
||||
tipFee = int64(orderInfo.Tips)
|
||||
}
|
||||
@@ -482,13 +486,13 @@ func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, order *model.Goo
|
||||
|
||||
func (c *PurchaseHandler) AddWaybillTip(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee2Add int64) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").OrderAddTips(order.VendorOrderID, int(tipFee2Add), ctx.GetUserName())
|
||||
err = getAPI(order.VendorOrgCode).OrderAddTips(order.VendorOrderID, int(tipFee2Add), ctx.GetUserName())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetSelfTakeCode(ctx *jxcontext.Context, vendorOrderID string) (selfTakeCode string, err error) {
|
||||
orderTrackList, err := getAPI("").GetByOrderNoForOaos(vendorOrderID)
|
||||
func (c *PurchaseHandler) GetSelfTakeCode(ctx *jxcontext.Context, order *model.GoodsOrder) (selfTakeCode string, err error) {
|
||||
orderTrackList, err := getAPI(order.VendorOrgCode).GetByOrderNoForOaos(order.VendorOrderID)
|
||||
if err == nil {
|
||||
for _, v := range orderTrackList {
|
||||
if v.TagCode == 180 {
|
||||
@@ -503,9 +507,9 @@ func (c *PurchaseHandler) GetSelfTakeCode(ctx *jxcontext.Context, vendorOrderID
|
||||
return selfTakeCode, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID, selfTakeCode string) (err error) {
|
||||
func (c *PurchaseHandler) ConfirmSelfTake(ctx *jxcontext.Context, order *model.GoodsOrder, selfTakeCode string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").CheckSelfPickCode(selfTakeCode, vendorOrderID, ctx.GetUserName())
|
||||
err = getAPI(order.VendorOrgCode).CheckSelfPickCode(selfTakeCode, order.VendorOrderID, ctx.GetUserName())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -58,15 +58,15 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) OnAfsOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
func (c *PurchaseHandler) OnAfsOrderMsg(a *jdapi.API, msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
jxutils.CallMsgHandlerAsync(func() {
|
||||
retVal = c.onAfsOrderMsg(msg)
|
||||
retVal = c.onAfsOrderMsg(a, msg)
|
||||
}, jxutils.ComposeUniversalOrderID(msg.BillID, model.VendorIDJD))
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) onAfsOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
afsInfo, err := getAPI("").GetAfsService2(msg.BillID)
|
||||
func (c *PurchaseHandler) onAfsOrderMsg(a *jdapi.API, msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
afsInfo, err := a.GetAfsService2(msg.BillID)
|
||||
if err == nil {
|
||||
status := c.callbackAfsMsg2Status(msg, afsInfo)
|
||||
if partner.CurOrderManager.GetStatusDuplicatedCount(status) > 0 {
|
||||
@@ -141,6 +141,7 @@ func (c *PurchaseHandler) buildAfsOrder(afsInfo *jdapi.AfsServiceResponse) (afsO
|
||||
ReasonImgList: utils.LimitUTF8StringLen(jdapi.ProcessQuestionPic(afsInfo.QuestionPic), 1024),
|
||||
VendorAppealType: afsInfo.ApplyDeal,
|
||||
AppealType: c.convertAfsAppealType(afsInfo.ApplyDeal),
|
||||
VendorOrgCode: afsInfo.VenderID,
|
||||
}
|
||||
afsOrder.Status = c.GetAfsStatusFromVendorStatus(afsOrder.VendorStatus)
|
||||
|
||||
@@ -181,7 +182,7 @@ func (c *PurchaseHandler) buildAfsOrder(afsInfo *jdapi.AfsServiceResponse) (afsO
|
||||
// 审核售后单申请
|
||||
func (c *PurchaseHandler) AgreeOrRefuseRefund(ctx *jxcontext.Context, order *model.AfsOrder, approveType int, reason string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").AfsOpenApprove(order.AfsOrderID, afsApproveTypeMap[approveType], reason, ctx.GetUserName())
|
||||
err = getAPI(order.VendorOrgCode).AfsOpenApprove(order.AfsOrderID, afsApproveTypeMap[approveType], reason, ctx.GetUserName())
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -189,7 +190,7 @@ func (c *PurchaseHandler) AgreeOrRefuseRefund(ctx *jxcontext.Context, order *mod
|
||||
// 确认收到退货
|
||||
func (c *PurchaseHandler) ConfirmReceivedReturnGoods(ctx *jxcontext.Context, order *model.AfsOrder) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").ConfirmReceipt(order.AfsOrderID, ctx.GetUserName())
|
||||
err = getAPI(order.VendorOrgCode).ConfirmReceipt(order.AfsOrderID, ctx.GetUserName())
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -217,7 +218,7 @@ func (c *PurchaseHandler) RefundOrder(ctx *jxcontext.Context, order *model.Goods
|
||||
// 发起部分退款
|
||||
func (c *PurchaseHandler) PartRefundOrder(ctx *jxcontext.Context, order *model.GoodsOrder, refundSkuList []*model.OrderSku, reason string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
_, err = getAPI("").AfsSubmit(order.VendorOrderID, ctx.GetUserName(), utils.Int2Str(jdapi.AfsReasonWrongPurchase), reason, "", order.ConsigneeName, order.ConsigneeMobile, order.ConsigneeAddress, orderSkus2AfsSkus(refundSkuList))
|
||||
_, err = getAPI(order.VendorOrgCode).AfsSubmit(order.VendorOrderID, ctx.GetUserName(), utils.Int2Str(jdapi.AfsReasonWrongPurchase), reason, "", order.ConsigneeName, order.ConsigneeMobile, order.ConsigneeAddress, orderSkus2AfsSkus(refundSkuList))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ const (
|
||||
JDDJ_BAD_COMMENTS_MAX_MODIFY_TIME = 72 // 小时
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) onOrderComment2(msg *jdapi.CallbackOrderMsg) (err error) {
|
||||
func (c *PurchaseHandler) onOrderComment2(a *jdapi.API, msg *jdapi.CallbackOrderMsg) (err error) {
|
||||
intOrderID := utils.Str2Int64(msg.BillID)
|
||||
result, err := getAPI("").GetCommentByOrderId2(intOrderID)
|
||||
result, err := a.GetCommentByOrderId2(intOrderID)
|
||||
if err == nil {
|
||||
globals.SugarLogger.Debugf("onOrderComment comment:%s", utils.Format4Output(result, true))
|
||||
orderCommend := &model.OrderComment{
|
||||
@@ -43,9 +43,9 @@ func (c *PurchaseHandler) onOrderComment2(msg *jdapi.CallbackOrderMsg) (err erro
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) ReplyOrderComment(ctx *jxcontext.Context, orderComment *model.OrderComment, replyComment string) (err error) {
|
||||
func (c *PurchaseHandler) ReplyOrderComment(ctx *jxcontext.Context, vendorOrgCode string, orderComment *model.OrderComment, replyComment string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").OrgReplyComment(utils.Str2Int64(orderComment.VendorOrderID), orderComment.VendorStoreID, replyComment, ctx.GetUserName())
|
||||
err = getAPI(vendorOrgCode).OrgReplyComment(utils.Str2Int64(orderComment.VendorOrderID), orderComment.VendorStoreID, replyComment, ctx.GetUserName())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -26,14 +26,14 @@ func TestSwitch2SelfDeliver(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOrder(t *testing.T) {
|
||||
_, err := CurPurchaseHandler.GetOrder("815536199000222")
|
||||
_, err := CurPurchaseHandler.GetOrder("", "815536199000222")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestListOrders(t *testing.T) {
|
||||
result, err := CurPurchaseHandler.ListOrders(jxcontext.AdminCtx, nil, time.Now(), "")
|
||||
result, err := CurPurchaseHandler.ListOrders(jxcontext.AdminCtx, "", nil, time.Now(), "")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
@@ -41,7 +41,11 @@ func TestListOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetSelfTakeCode(t *testing.T) {
|
||||
selfTakeCode, err := CurPurchaseHandler.GetSelfTakeCode(jxcontext.AdminCtx, "921160248000222")
|
||||
order, err := partner.CurOrderManager.LoadOrder("921160248000222", model.VendorIDJD)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
selfTakeCode, err := CurPurchaseHandler.GetSelfTakeCode(jxcontext.AdminCtx, order)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
@@ -9,20 +9,9 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
const (
|
||||
DefBrandID = 35247
|
||||
|
||||
DefJdCategoryID = 20362
|
||||
DefJdCategoryID4Jxgy = 22410 // 其他国产水果
|
||||
)
|
||||
|
||||
type tSkuInfoExt struct {
|
||||
@@ -39,13 +28,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func getDefJdCategoryID() int {
|
||||
if beego.BConfig.RunMode == "jxgy" {
|
||||
return DefJdCategoryID4Jxgy
|
||||
}
|
||||
return DefJdCategoryID
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) (err error) {
|
||||
var jdPid int64
|
||||
if cat.ParentID != 0 {
|
||||
@@ -57,66 +39,28 @@ func (p *PurchaseHandler) CreateCategory(db *dao.DaoDB, cat *model.SkuCategory,
|
||||
return err
|
||||
}
|
||||
}
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
result, err2 := getAPI("").AddShopCategory(jdPid, cat.Name, int(cat.Level), cat.Seq, userName)
|
||||
if err = err2; err == nil {
|
||||
if jdID := utils.Str2Int64WithDefault(result, 0); jdID != 0 {
|
||||
cat.JdID = jdID
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cat.JdID = jxutils.GenFakeID()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func jdCat2Jx(jdCat *jdapi.CategoryInfo) (jxCat *partner.BareCategoryInfo) {
|
||||
return &partner.BareCategoryInfo{
|
||||
VendorCatID: utils.Int64ToStr(jdCat.Id),
|
||||
Level: jdCat.Level,
|
||||
Name: jdCat.Name,
|
||||
Seq: jdCat.Sort,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetAllCategories(ctx *jxcontext.Context, vendorOrgCode string) (cats []*partner.BareCategoryInfo, err error) {
|
||||
result, err := getAPI(vendorOrgCode).QueryCategoriesByOrgCode()
|
||||
if err == nil {
|
||||
catMap := make(map[int64]*partner.BareCategoryInfo)
|
||||
level := 1
|
||||
for {
|
||||
processedCount := 0
|
||||
for _, jdCat := range result {
|
||||
if jdCat.Level == level {
|
||||
processedCount++
|
||||
jxCat := jdCat2Jx(jdCat)
|
||||
if level == 1 {
|
||||
cats = append(cats, jxCat)
|
||||
} else {
|
||||
parentCat := catMap[jdCat.ParentId]
|
||||
if parentCat != nil {
|
||||
parentCat.Children = append(parentCat.Children, jxCat)
|
||||
}
|
||||
}
|
||||
catMap[jdCat.Id] = jxCat
|
||||
}
|
||||
}
|
||||
if processedCount == 0 {
|
||||
break
|
||||
}
|
||||
level++
|
||||
}
|
||||
}
|
||||
return cats, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) error {
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
return getAPI("").UpdateShopCategory(cat.JdID, cat.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) error {
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
return getAPI("").DelShopCategory(cat.JdID)
|
||||
}
|
||||
return nil
|
||||
@@ -142,7 +86,7 @@ func (p *PurchaseHandler) ReorderCategories(db *dao.DaoDB, parentCatID int, user
|
||||
for k, v := range cats {
|
||||
jdCatIDs[k] = v.JdID
|
||||
}
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").ChangeShopCategoryOrder(parentJDID, jdCatIDs)
|
||||
}
|
||||
}
|
||||
@@ -215,7 +159,7 @@ func (p *PurchaseHandler) cuSku(db *dao.DaoDB, sku *model.Sku, handler func(skuE
|
||||
func (p *PurchaseHandler) CreateSku(db *dao.DaoDB, sku *model.Sku, userName string) (err error) {
|
||||
return p.cuSku(db, sku, func(skuExt *tSkuInfoExt, price int, skuName string, shopCategories []int64, addParams map[string]interface{}) (vendorSkuID string, err error) {
|
||||
if skuExt.IsSpu == 0 {
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
vendorSkuID, err = getAPI("").AddSku(utils.Int2Str(sku.ID), skuExt.JdCategoryID, shopCategories, skuExt.BrandID, skuName, price, jxutils.IntWeight2Float(sku.Weight), jxutils.BatchString2Slice(skuExt.Img, skuExt.Img2), jxStatus2jdStatus(sku.Status), true, addParams)
|
||||
if err != nil {
|
||||
if jdSkuID := jdapi.GetJdSkuIDFromError(err); jdSkuID > 0 {
|
||||
@@ -223,6 +167,8 @@ func (p *PurchaseHandler) CreateSku(db *dao.DaoDB, sku *model.Sku, userName stri
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vendorSkuID = utils.Int64ToStr(jxutils.GenFakeID())
|
||||
}
|
||||
} else {
|
||||
vendorSkuID, err = p.syncSkuNameAsSpu(db, sku, skuExt, price, skuName, shopCategories, addParams)
|
||||
@@ -231,74 +177,77 @@ func (p *PurchaseHandler) CreateSku(db *dao.DaoDB, sku *model.Sku, userName stri
|
||||
})
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) ReadSku(vendorSkuID string) (skuNameExt *model.SkuNameExt, err error) {
|
||||
jdSkuID := utils.Str2Int64(vendorSkuID)
|
||||
skuList, _, err := getAPI("").QuerySkuInfos(&jdapi.QuerySkuParam{
|
||||
SkuID: jdSkuID,
|
||||
})
|
||||
if err == nil {
|
||||
if len(skuList) >= 1 {
|
||||
skuNameExt = &model.SkuNameExt{}
|
||||
if imgList, err2 := getAPI("").QueryListBySkuIds(&jdapi.QueryListBySkuIdsParam{
|
||||
SkuIDs: []int64{jdSkuID},
|
||||
}); err2 == nil && len(imgList) > 0 {
|
||||
skuNameExt.Img = imgList[0].SourceImgURL
|
||||
}
|
||||
sku := skuList[0]
|
||||
prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(sku.SkuName)
|
||||
if name == "" {
|
||||
name = sku.SkuName
|
||||
unit = "份"
|
||||
specUnit = "g"
|
||||
}
|
||||
skuNameExt.Prefix = prefix
|
||||
skuNameExt.Name = name
|
||||
skuNameExt.Unit = unit
|
||||
skuNameExt.Price = sku.SkuPrice
|
||||
skuNameExt.Skus = []*model.Sku{
|
||||
&model.Sku{
|
||||
SpecQuality: specQuality,
|
||||
SpecUnit: specUnit,
|
||||
Weight: jxutils.FloatWeight2Int(float32(sku.Weight)),
|
||||
JdID: sku.SkuID,
|
||||
Status: jdStatus2jxStatus(sku.FixedStatus),
|
||||
Comment: comment,
|
||||
},
|
||||
}
|
||||
skuNameExt.Skus[0].ID = int(utils.Str2Int64(sku.OutSkuID))
|
||||
// func (p *PurchaseHandler) ReadSku(ctx *jxcontext.Context, vendorOrgCode, vendorSkuID string) (skuNameExt *model.SkuNameExt, err error) {
|
||||
// jdSkuID := utils.Str2Int64(vendorSkuID)
|
||||
// a := getAPI(vendorOrgCode)
|
||||
// skuList, _, err := a.QuerySkuInfos(&jdapi.QuerySkuParam{
|
||||
// SkuID: jdSkuID,
|
||||
// })
|
||||
// if err == nil {
|
||||
// if len(skuList) >= 1 {
|
||||
// skuNameExt = &model.SkuNameExt{}
|
||||
// if imgList, err2 := a.QueryListBySkuIds(&jdapi.QueryListBySkuIdsParam{
|
||||
// SkuIDs: []int64{jdSkuID},
|
||||
// }); err2 == nil && len(imgList) > 0 {
|
||||
// skuNameExt.Img = imgList[0].SourceImgURL
|
||||
// }
|
||||
// sku := skuList[0]
|
||||
// prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(sku.SkuName)
|
||||
// if name == "" {
|
||||
// name = sku.SkuName
|
||||
// unit = "份"
|
||||
// specUnit = "g"
|
||||
// }
|
||||
// skuNameExt.Prefix = prefix
|
||||
// skuNameExt.Name = name
|
||||
// skuNameExt.Unit = unit
|
||||
// skuNameExt.Price = sku.SkuPrice
|
||||
// skuNameExt.Skus = []*model.SkuWithVendor{
|
||||
// &model.SkuWithVendor{
|
||||
// Sku: &model.Sku{
|
||||
// SpecQuality: specQuality,
|
||||
// SpecUnit: specUnit,
|
||||
// Weight: jxutils.FloatWeight2Int(float32(sku.Weight)),
|
||||
// JdID: sku.SkuID,
|
||||
// Status: jdStatus2jxStatus(sku.FixedStatus),
|
||||
// Comment: comment,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// skuNameExt.Skus[0].ID = int(utils.Str2Int64(sku.OutSkuID))
|
||||
|
||||
db := dao.GetDB()
|
||||
shopCategories := sku.ShopCategories
|
||||
if len(shopCategories) > 0 {
|
||||
skuCat := &model.SkuCategory{}
|
||||
skuCat.JdID = shopCategories[0]
|
||||
if dao.GetEntity(db, skuCat, "JdID") == nil {
|
||||
skuNameExt.CategoryID = skuCat.ID
|
||||
}
|
||||
}
|
||||
sellCities := sku.SellCities
|
||||
for _, v := range sellCities {
|
||||
if v == 0 {
|
||||
skuNameExt.IsGlobal = 1
|
||||
}
|
||||
}
|
||||
if len(sellCities) == 0 || skuNameExt.IsGlobal == 1 {
|
||||
skuNameExt.IsGlobal = 1
|
||||
} else {
|
||||
var places []*model.Place
|
||||
if err = dao.GetRows(db, &places, "SELECT * FROM place WHERE jd_code IN ("+dao.GenQuestionMarks(len(sellCities))+") AND level = 2", sellCities); err == nil {
|
||||
skuNameExt.Places = make([]int, len(places))
|
||||
for k, v := range places {
|
||||
skuNameExt.Places[k] = v.Code
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = partner.ErrCanNotFindItem
|
||||
}
|
||||
}
|
||||
return skuNameExt, err
|
||||
}
|
||||
// db := dao.GetDB()
|
||||
// shopCategories := sku.ShopCategories
|
||||
// if len(shopCategories) > 0 {
|
||||
// skuCat := &model.SkuCategory{}
|
||||
// skuCat.JdID = shopCategories[0]
|
||||
// if dao.GetEntity(db, skuCat, "JdID") == nil {
|
||||
// skuNameExt.CategoryID = skuCat.ID
|
||||
// }
|
||||
// }
|
||||
// sellCities := sku.SellCities
|
||||
// for _, v := range sellCities {
|
||||
// if v == 0 {
|
||||
// skuNameExt.IsGlobal = 1
|
||||
// }
|
||||
// }
|
||||
// if len(sellCities) == 0 || skuNameExt.IsGlobal == 1 {
|
||||
// skuNameExt.IsGlobal = 1
|
||||
// } else {
|
||||
// var places []*model.Place
|
||||
// if err = dao.GetRows(db, &places, "SELECT * FROM place WHERE jd_code IN ("+dao.GenQuestionMarks(len(sellCities))+") AND level = 2", sellCities); err == nil {
|
||||
// skuNameExt.Places = make([]int, len(places))
|
||||
// for k, v := range places {
|
||||
// skuNameExt.Places[k] = v.Code
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// err = partner.ErrCanNotFindItem
|
||||
// }
|
||||
// }
|
||||
// return skuNameExt, err
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) UpdateSku(db *dao.DaoDB, sku *model.Sku, userName string) (err error) {
|
||||
return p.cuSku(db, sku, func(skuExt *tSkuInfoExt, price int, skuName string, shopCategories []int64, addParams map[string]interface{}) (vendorSkuID string, err error) {
|
||||
@@ -311,7 +260,7 @@ func (p *PurchaseHandler) UpdateSku(db *dao.DaoDB, sku *model.Sku, userName stri
|
||||
params[jdapi.KeyImages] = jxutils.BatchString2Slice(skuExt.Img, skuExt.Img2)
|
||||
params[jdapi.KeyFixedStatus] = jxStatus2jdStatus(sku.Status)
|
||||
if skuExt.IsSpu == 0 {
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
vendorSkuID, err = getAPI("").UpdateSku(utils.Int2Str(sku.ID), params)
|
||||
}
|
||||
} else {
|
||||
@@ -335,7 +284,7 @@ func (p *PurchaseHandler) DeleteSku(db *dao.DaoDB, sku *model.Sku, userName stri
|
||||
err = dao.GetRow(db, &skuExt, sql, sku.ID)
|
||||
if err == nil {
|
||||
if skuExt.IsSpu == 0 {
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
_, err = getAPI("").UpdateSku(utils.Int2Str(sku.ID), params)
|
||||
}
|
||||
} else {
|
||||
@@ -345,57 +294,57 @@ func (p *PurchaseHandler) DeleteSku(db *dao.DaoDB, sku *model.Sku, userName stri
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) RefreshAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("jd RefreshAllSkusID")
|
||||
// func (p *PurchaseHandler) RefreshAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool) (hint string, err error) {
|
||||
// globals.SugarLogger.Debugf("jd RefreshAllSkusID")
|
||||
|
||||
db := dao.GetDB()
|
||||
var skuPairs []*jdapi.SkuIDPair
|
||||
const stepCount = 2
|
||||
// db := dao.GetDB()
|
||||
// var skuPairs []*jdapi.SkuIDPair
|
||||
// const stepCount = 2
|
||||
|
||||
rootTask := tasksch.NewSeqTask("jd RefreshAllSkusID", ctx,
|
||||
func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
err = dao.GetRows(db, &skuPairs, `
|
||||
SELECT t1.id out_sku_id, t1.jd_id sku_id
|
||||
FROM sku t1
|
||||
WHERE t1.deleted_at = ?
|
||||
`, utils.DefaultTimeValue)
|
||||
default:
|
||||
taskName := "RefreshAllSkusID update id"
|
||||
if step != stepCount-1 {
|
||||
taskName = "RefreshAllSkusID update uuid"
|
||||
}
|
||||
task1 := tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetBatchSize(jdapi.MaxBatchSize4BatchUpdateOutSkuId), ctx,
|
||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
skuPairs := make([]*jdapi.SkuIDPair, len(batchItemList))
|
||||
for k, v := range batchItemList {
|
||||
pair := v.(*jdapi.SkuIDPair)
|
||||
skuPairs[k] = &jdapi.SkuIDPair{
|
||||
SkuId: pair.SkuId,
|
||||
OutSkuId: pair.OutSkuId,
|
||||
}
|
||||
if step != stepCount-1 {
|
||||
skuPairs[k].OutSkuId = utils.GetUUID()
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(skuPairs, false))
|
||||
if globals.EnableStoreWrite {
|
||||
_, err = getAPI("").BatchUpdateOutSkuId(skuPairs)
|
||||
}
|
||||
return nil, err
|
||||
}, skuPairs)
|
||||
rootTask.AddChild(task1).Run()
|
||||
_, err = task1.GetResult(0)
|
||||
}
|
||||
return nil, err
|
||||
}, stepCount)
|
||||
tasksch.HandleTask(rootTask, parentTask, false).Run()
|
||||
if !isAsync {
|
||||
_, err = rootTask.GetResult(0)
|
||||
}
|
||||
return rootTask.ID, err
|
||||
}
|
||||
// rootTask := tasksch.NewSeqTask("jd RefreshAllSkusID", ctx,
|
||||
// func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
// switch step {
|
||||
// case 0:
|
||||
// err = dao.GetRows(db, &skuPairs, `
|
||||
// SELECT t1.id out_sku_id, t1.jd_id sku_id
|
||||
// FROM sku t1
|
||||
// WHERE t1.deleted_at = ?
|
||||
// `, utils.DefaultTimeValue)
|
||||
// default:
|
||||
// taskName := "RefreshAllSkusID update id"
|
||||
// if step != stepCount-1 {
|
||||
// taskName = "RefreshAllSkusID update uuid"
|
||||
// }
|
||||
// task1 := tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetBatchSize(jdapi.MaxBatchSize4BatchUpdateOutSkuId), ctx,
|
||||
// func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
// skuPairs := make([]*jdapi.SkuIDPair, len(batchItemList))
|
||||
// for k, v := range batchItemList {
|
||||
// pair := v.(*jdapi.SkuIDPair)
|
||||
// skuPairs[k] = &jdapi.SkuIDPair{
|
||||
// SkuId: pair.SkuId,
|
||||
// OutSkuId: pair.OutSkuId,
|
||||
// }
|
||||
// if step != stepCount-1 {
|
||||
// skuPairs[k].OutSkuId = utils.GetUUID()
|
||||
// }
|
||||
// }
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(skuPairs, false))
|
||||
// if globals.EnableJdStoreWrite {
|
||||
// _, err = getAPI("").BatchUpdateOutSkuId(skuPairs)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, skuPairs)
|
||||
// rootTask.AddChild(task1).Run()
|
||||
// _, err = task1.GetResult(0)
|
||||
// }
|
||||
// return nil, err
|
||||
// }, stepCount)
|
||||
// tasksch.HandleTask(rootTask, parentTask, false).Run()
|
||||
// if !isAsync {
|
||||
// _, err = rootTask.GetResult(0)
|
||||
// }
|
||||
// return rootTask.ID, err
|
||||
// }
|
||||
|
||||
func splitAddParams(addParams map[string]interface{}) (spuAddParams, skuAddParams map[string]interface{}) {
|
||||
if addParams != nil {
|
||||
@@ -420,7 +369,7 @@ func (p *PurchaseHandler) syncSkuNameAsSpu(db *dao.DaoDB, sku *model.Sku, skuExt
|
||||
globals.SugarLogger.Debugf("syncSkuNameAsSpu1 sku.id=%d, bareSkuName:%s, skuName:%s, skuNameJdID:%d", sku.ID, skuExt.Name, skuName, skuNameJdID)
|
||||
spuAddParams, skuAddParams := splitAddParams(addParams)
|
||||
if !jxutils.IsEmptyID(skuNameJdID) && sku.JdSyncStatus&model.SyncFlagDeletedMask != 0 { // 删除SKU
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").UpdateSkuBaseInfo(utils.Int2Str(skuExt.ID), utils.Int2Str(sku.ID), utils.Params2Map(jdapi.KeyFixedStatus, jdapi.SkuFixedStatusDeleted))
|
||||
}
|
||||
}
|
||||
@@ -440,14 +389,14 @@ func (p *PurchaseHandler) syncSkuNameAsSpu(db *dao.DaoDB, sku *model.Sku, skuExt
|
||||
}
|
||||
if count.Ct <= 1 && sku.JdSyncStatus&model.SyncFlagDeletedMask != 0 { // 1就是最后删的那个
|
||||
updateFields = append(updateFields, model.FieldJdSyncStatus)
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
if err = getAPI("").UpdateSpu(utils.Int2Str(skuExt.ID), utils.Params2Map(jdapi.KeyFixedStatus, jdapi.SkuFixedStatusOffline)); err == nil {
|
||||
err = getAPI("").UpdateSpu(utils.Int2Str(skuExt.ID), utils.Params2Map(jdapi.KeyFixedStatus, jdapi.SkuFixedStatusDeleted))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if skuExt.JdSyncStatus&model.SyncFlagNewMask != 0 && jxutils.IsEmptyID(skuNameJdID) {
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
spuName := jxutils.ComposeSpuName(skuExt.Prefix, skuExt.Name, 0)
|
||||
skus := []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
@@ -462,7 +411,7 @@ func (p *PurchaseHandler) syncSkuNameAsSpu(db *dao.DaoDB, sku *model.Sku, skuExt
|
||||
}
|
||||
skus[0] = utils.MergeMaps(skus[0], skuAddParams)
|
||||
updateFields = append(updateFields, model.FieldJdSyncStatus)
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
vendorSpuID, skuPairs, err2 := getAPI("").AddSpu(utils.Int2Str(skuExt.ID), skuExt.JdCategoryID, shopCategories, skuExt.BrandID, spuName, []string{skuExt.Img}, jxStatus2jdStatus(skuExt.Status), spuAddParams, skus)
|
||||
if err = err2; err == nil {
|
||||
skuExt.JdID = vendorSpuID
|
||||
@@ -483,7 +432,7 @@ func (p *PurchaseHandler) syncSkuNameAsSpu(db *dao.DaoDB, sku *model.Sku, skuExt
|
||||
jdapi.KeyFixedStatus: jxStatus2jdStatus(skuExt.Status),
|
||||
}, spuAddParams)
|
||||
updateFields = append(updateFields, model.FieldJdSyncStatus)
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").UpdateSpu(utils.Int2Str(skuExt.ID), params)
|
||||
}
|
||||
}
|
||||
@@ -497,7 +446,7 @@ func (p *PurchaseHandler) syncSkuNameAsSpu(db *dao.DaoDB, sku *model.Sku, skuExt
|
||||
}
|
||||
if err == nil && !jxutils.IsEmptyID(skuNameJdID) {
|
||||
if sku.JdSyncStatus&model.SyncFlagNewMask != 0 { // 非首次新增SKU
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
vendorSkuID2, err2 := getAPI("").AppendSku(utils.Int2Str(skuExt.ID), utils.Int2Str(sku.ID), skuName, price, jxutils.IntWeight2Float(sku.Weight), []string{skuExt.Img}, jxStatus2jdStatus(sku.Status), true, composeSkuSpec(sku.SpecQuality, sku.SpecUnit, skuExt.Unit), skuAddParams)
|
||||
if err = err2; err == nil {
|
||||
vendorSkuID = utils.Int64ToStr(vendorSkuID2)
|
||||
@@ -510,7 +459,7 @@ func (p *PurchaseHandler) syncSkuNameAsSpu(db *dao.DaoDB, sku *model.Sku, skuExt
|
||||
params[jdapi.KeyFixedStatus] = jxStatus2jdStatus(sku.Status)
|
||||
params[jdapi.KeyWeight] = jxutils.IntWeight2Float(sku.Weight)
|
||||
params[jdapi.KeySkuPrice] = price
|
||||
if globals.EnableStoreWrite {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").UpdateSkuBaseInfo(utils.Int2Str(skuExt.ID), utils.Int2Str(sku.ID), utils.MergeMaps(params, skuAddParams))
|
||||
if sku.JdSyncStatus&model.SyncFlagSpecMask != 0 {
|
||||
skuIndex := sku.SkuIndex
|
||||
@@ -541,189 +490,3 @@ func composeSkuSpec(specQuality float32, specUnit, unit string) string {
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func jdStatus2jxStatus(jdStatus int) (jxStatus int) {
|
||||
switch jdStatus {
|
||||
case jdapi.SkuFixedStatusOnline:
|
||||
jxStatus = model.SkuStatusNormal
|
||||
case jdapi.SkuFixedStatusOffline:
|
||||
jxStatus = model.SkuStatusDontSale
|
||||
case jdapi.SkuFixedStatusDeleted:
|
||||
jxStatus = model.SkuStatusDeleted
|
||||
}
|
||||
return jxStatus
|
||||
}
|
||||
|
||||
func jxStatus2jdStatus(jxStatus int) (jdStatus int) {
|
||||
switch jxStatus {
|
||||
case model.SkuStatusNormal:
|
||||
jdStatus = jdapi.SkuFixedStatusOnline
|
||||
case model.SkuStatusDontSale:
|
||||
jdStatus = jdapi.SkuFixedStatusOffline
|
||||
case model.SkuStatusDeleted:
|
||||
jdStatus = jdapi.SkuFixedStatusDeleted
|
||||
}
|
||||
return jdStatus
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) getVendorCategories(level int, pid int64) (vendorCats []*model.SkuVendorCategory, err error) {
|
||||
cats, err := getAPI("").QueryChildCategoriesForOP(pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range cats {
|
||||
if v.Status == 1 {
|
||||
cat := &model.SkuVendorCategory{
|
||||
VendorID: model.VendorIDJD,
|
||||
Name: v.Name,
|
||||
Level: level,
|
||||
VendorCategoryID: utils.Int64ToStr(v.Id),
|
||||
}
|
||||
if level > 1 {
|
||||
cat.ParentID = utils.Int64ToStr(v.ParentId)
|
||||
if level == 3 {
|
||||
cat.IsLeaf = 1
|
||||
}
|
||||
}
|
||||
vendorCats = append(vendorCats, cat)
|
||||
if level < 3 {
|
||||
childVendorCats, err2 := p.getVendorCategories(level+1, v.Id)
|
||||
if err2 == nil && len(childVendorCats) > 0 {
|
||||
vendorCats = append(vendorCats, childVendorCats...)
|
||||
} else {
|
||||
cat.IsLeaf = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vendorCats, nil
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetVendorCategories(ctx *jxcontext.Context) (vendorCats []*model.SkuVendorCategory, err error) {
|
||||
vendorCats, err = p.getVendorCategories(1, 0)
|
||||
return vendorCats, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetSkus(ctx *jxcontext.Context, skuID int, vendorSkuID, skuName string) (skuNameList []*partner.SkuNameInfo, err error) {
|
||||
param := &jdapi.QuerySkuParam{
|
||||
SkuID: utils.Str2Int64WithDefault(vendorSkuID, 0),
|
||||
SkuName: skuName,
|
||||
IsFilterDel: jdapi.IsFilterDelTrue,
|
||||
PageNo: 1,
|
||||
PageSize: jdapi.MaxSkuIDsCount4QueryListBySkuIds, // 为了同时取图,这个值不要大于jdapi.MaxSkuIDsCount4QueryListBySkuIds
|
||||
}
|
||||
for {
|
||||
skuList, _, err2 := getAPI("").QuerySkuInfos(param)
|
||||
if err = err2; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(skuList) > 0 {
|
||||
batchSkuNameList := make([]*partner.SkuNameInfo, len(skuList))
|
||||
for k, v := range skuList {
|
||||
batchSkuNameList[k] = vendorSku2Jx(v)
|
||||
}
|
||||
setSkuNameListPic(batchSkuNameList)
|
||||
skuNameList = append(skuNameList, batchSkuNameList...)
|
||||
}
|
||||
if len(skuList) < param.PageSize {
|
||||
break
|
||||
}
|
||||
param.PageNo++
|
||||
}
|
||||
return skuNameList, err
|
||||
}
|
||||
|
||||
func setSkuNameListPic(skuNameList []*partner.SkuNameInfo) []*partner.SkuNameInfo {
|
||||
jdSkuIDs := make([]int64, len(skuNameList))
|
||||
for k, v := range skuNameList {
|
||||
jdSkuIDs[k] = utils.Str2Int64(v.SkuList[0].VendorSkuID)
|
||||
}
|
||||
|
||||
imgMap := make(map[int64]*jdapi.ImgHandleQueryResult)
|
||||
if imgList, err2 := getAPI("").QueryListBySkuIds(&jdapi.QueryListBySkuIdsParam{
|
||||
SkuIDs: jdSkuIDs,
|
||||
}); err2 == nil {
|
||||
for _, v := range imgList {
|
||||
if v.ImgType == jdapi.ImgTypeMain {
|
||||
imgResult := imgMap[v.SkuID]
|
||||
if imgResult == nil || imgResult.IsMain < v.IsMain {
|
||||
imgMap[v.SkuID] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用扒页面方式获取商品图片
|
||||
if false {
|
||||
var leftJdSkuIDs []int64
|
||||
for _, v := range jdSkuIDs {
|
||||
if imgMap[v] == nil {
|
||||
leftJdSkuIDs = append(leftJdSkuIDs, v)
|
||||
}
|
||||
}
|
||||
task := tasksch.NewParallelTask("jd setSkuNameListPic", nil, jxcontext.AdminCtx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
jdSkuID := batchItemList[0].(int64)
|
||||
imgList, err := getAPI("").GetSkuPageImageInfo(jdSkuID)
|
||||
if err == nil && len(imgList) > 0 {
|
||||
retVal = [][]string{
|
||||
[]string{utils.Int64ToStr(jdSkuID), imgList[0].Big},
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, leftJdSkuIDs)
|
||||
task.Run()
|
||||
if resultList, err := task.GetResult(0); err == nil {
|
||||
for _, v := range resultList {
|
||||
strList := v.([]string)
|
||||
imgMap[utils.Str2Int64(strList[0])] = &jdapi.ImgHandleQueryResult{
|
||||
SourceImgURL: strList[1],
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置商品图片
|
||||
for _, v := range skuNameList {
|
||||
if imgResult := imgMap[utils.Str2Int64(v.SkuList[0].VendorSkuID)]; imgResult != nil {
|
||||
v.PictureList = []string{imgResult.SourceImgURL}
|
||||
}
|
||||
}
|
||||
return skuNameList
|
||||
}
|
||||
|
||||
func vendorSku2Jx(vendorSku *jdapi.SkuMain) (skuName *partner.SkuNameInfo) {
|
||||
prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(vendorSku.SkuName)
|
||||
weight := int(vendorSku.Weight * 1000)
|
||||
if weight <= 0 {
|
||||
weight = jxutils.FormatSkuWeight(specQuality, specUnit)
|
||||
}
|
||||
skuID := int(utils.Str2Int64WithDefault(vendorSku.OutSkuID, 0))
|
||||
vendorSkuID := utils.Int64ToStr(vendorSku.SkuID)
|
||||
skuName = &partner.SkuNameInfo{
|
||||
NameID: skuID,
|
||||
VendorNameID: vendorSkuID,
|
||||
VendorCatIDList: []string{utils.Int64ToStr(vendorSku.CategoryID)},
|
||||
|
||||
Prefix: prefix,
|
||||
Name: name,
|
||||
Unit: unit,
|
||||
SkuList: []*partner.SkuInfo{
|
||||
&partner.SkuInfo{
|
||||
StoreSkuInfo: partner.StoreSkuInfo{
|
||||
VendorSkuID: vendorSkuID,
|
||||
SkuID: skuID,
|
||||
|
||||
VendorPrice: int64(vendorSku.SkuPrice),
|
||||
Status: jdStatus2jxStatus(vendorSku.FixedStatus),
|
||||
},
|
||||
SkuName: vendorSku.SkuName,
|
||||
Comment: comment,
|
||||
SpecQuality: float64(specQuality),
|
||||
SpecUnit: specUnit,
|
||||
Weight: weight,
|
||||
},
|
||||
},
|
||||
}
|
||||
return skuName
|
||||
}
|
||||
|
||||
359
business/partner/purchase/jd/sku2.go
Normal file
359
business/partner/purchase/jd/sku2.go
Normal file
@@ -0,0 +1,359 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
const (
|
||||
DefBrandID = 35247
|
||||
|
||||
DefJdCategoryID = 20362
|
||||
DefJdCategoryID4Jxgy = 22410 // 其他国产水果
|
||||
)
|
||||
|
||||
func getDefJdCategoryID() int {
|
||||
if beego.BConfig.RunMode == "jxgy" {
|
||||
return DefJdCategoryID4Jxgy
|
||||
}
|
||||
return DefJdCategoryID
|
||||
}
|
||||
|
||||
func jdCat2Jx(jdCat *jdapi.CategoryInfo) (jxCat *partner.BareCategoryInfo) {
|
||||
return &partner.BareCategoryInfo{
|
||||
VendorCatID: utils.Int64ToStr(jdCat.Id),
|
||||
Level: jdCat.Level,
|
||||
Name: jdCat.Name,
|
||||
Seq: jdCat.Sort,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetAllCategories(ctx *jxcontext.Context, vendorOrgCode string) (cats []*partner.BareCategoryInfo, err error) {
|
||||
result, err := getAPI(vendorOrgCode).QueryCategoriesByOrgCode()
|
||||
if err == nil {
|
||||
catMap := make(map[int64]*partner.BareCategoryInfo)
|
||||
level := 1
|
||||
for {
|
||||
processedCount := 0
|
||||
for _, jdCat := range result {
|
||||
if jdCat.Level == level {
|
||||
processedCount++
|
||||
jxCat := jdCat2Jx(jdCat)
|
||||
if level == 1 {
|
||||
cats = append(cats, jxCat)
|
||||
} else {
|
||||
parentCat := catMap[jdCat.ParentId]
|
||||
if parentCat != nil {
|
||||
parentCat.Children = append(parentCat.Children, jxCat)
|
||||
}
|
||||
}
|
||||
catMap[jdCat.Id] = jxCat
|
||||
}
|
||||
}
|
||||
if processedCount == 0 {
|
||||
break
|
||||
}
|
||||
level++
|
||||
}
|
||||
}
|
||||
return cats, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateCategory2(ctx *jxcontext.Context, cat *dao.SkuStoreCatInfo) (err error) {
|
||||
globals.SugarLogger.Debugf("CreateCategory2 cat:%s", utils.Format4Output(cat, true))
|
||||
parentID := int64(0)
|
||||
if cat.Level != 1 {
|
||||
parentID = utils.Str2Int64(cat.ParentVendorCatID)
|
||||
}
|
||||
if globals.EnableJdStoreWrite {
|
||||
result, err2 := getAPI(cat.VendorOrgCode).AddShopCategory(parentID, cat.Name, int(cat.Level), cat.Seq, ctx.GetUserName())
|
||||
if err = err2; err == nil {
|
||||
if jdID := utils.Str2Int64WithDefault(result, 0); jdID != 0 {
|
||||
cat.VendorCatID = utils.Int64ToStr(jdID)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cat.VendorCatID = utils.Int64ToStr(jxutils.GenFakeID())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateCategory2(ctx *jxcontext.Context, cat *dao.SkuStoreCatInfo) (err error) {
|
||||
globals.SugarLogger.Debugf("UpdateCategory2 cat:%s", utils.Format4Output(cat, true))
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI(cat.VendorOrgCode).UpdateShopCategory(utils.Str2Int64(cat.VendorCatID), cat.Name)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteCategory2(ctx *jxcontext.Context, vendorOrgCode, vendorCatID string) (err error) {
|
||||
globals.SugarLogger.Debugf("DeleteCategory2 vendorOrgCode:%s, vendorCatID:%s", vendorOrgCode, vendorCatID)
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI(vendorOrgCode).DelShopCategory(utils.Str2Int64(vendorCatID))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) ReorderCategories2(ctx *jxcontext.Context, vendorOrgCode, vendorParentCatID string, vendorCatIDList []string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI(vendorOrgCode).ChangeShopCategoryOrder(utils.Str2Int64(vendorParentCatID), utils.StringSlice2Int64(vendorCatIDList))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) getVendorCategories(level int, pid int64) (vendorCats []*model.SkuVendorCategory, err error) {
|
||||
// 得到平台的分类,不需要指定分账号
|
||||
cats, err := getAPI("").QueryChildCategoriesForOP(pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range cats {
|
||||
if v.Status == 1 {
|
||||
cat := &model.SkuVendorCategory{
|
||||
VendorID: model.VendorIDJD,
|
||||
Name: v.Name,
|
||||
Level: level,
|
||||
VendorCategoryID: utils.Int64ToStr(v.Id),
|
||||
}
|
||||
if level > 1 {
|
||||
cat.ParentID = utils.Int64ToStr(v.ParentId)
|
||||
if level == 3 {
|
||||
cat.IsLeaf = 1
|
||||
}
|
||||
}
|
||||
vendorCats = append(vendorCats, cat)
|
||||
if level < 3 {
|
||||
childVendorCats, err2 := p.getVendorCategories(level+1, v.Id)
|
||||
if err2 == nil && len(childVendorCats) > 0 {
|
||||
vendorCats = append(vendorCats, childVendorCats...)
|
||||
} else {
|
||||
cat.IsLeaf = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return vendorCats, nil
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetVendorCategories(ctx *jxcontext.Context) (vendorCats []*model.SkuVendorCategory, err error) {
|
||||
vendorCats, err = p.getVendorCategories(1, 0)
|
||||
return vendorCats, err
|
||||
}
|
||||
|
||||
func skuInfo2Param(ctx *jxcontext.Context, sku *dao.StoreSkuSyncInfo) (param *jdapi.OpSkuParam) {
|
||||
param = &jdapi.OpSkuParam{
|
||||
TraceID: ctx.GetTrackInfo(),
|
||||
OutSkuID: utils.Int2Str(sku.SkuID),
|
||||
ShopCategories: []int64{utils.Str2Int64(sku.VendorCatID)},
|
||||
CategoryID: sku.VendorVendorCatID,
|
||||
BrandID: DefBrandID,
|
||||
SkuName: utils.LimitUTF8StringLen(sku.SkuName, jdapi.MaxSkuNameCharCount),
|
||||
SkuPrice: int(sku.Price),
|
||||
Weight: float64(jxutils.IntWeight2Float(sku.Weight)),
|
||||
FixedStatus: jxStatus2jdStatus(sku.MergedStatus),
|
||||
IsSale: jdapi.IsSaleNo, // todo ?
|
||||
|
||||
Upc: sku.Upc,
|
||||
Images: jxutils.BatchString2Slice(sku.Img, sku.Img2),
|
||||
}
|
||||
if param.CategoryID == 0 {
|
||||
param.CategoryID = int64(getDefJdCategoryID())
|
||||
}
|
||||
if sku.IsGlobal == 0 && len(sku.SellCities) > 0 {
|
||||
param.SellCities = utils.StringSlice2Int64(sku.SellCities)
|
||||
}
|
||||
if sku.DescImg != "" {
|
||||
param.ProductDesc = fmt.Sprintf(`<img src="%s" alt="一张图片" />`, sku.DescImg)
|
||||
}
|
||||
return param
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateSku2(ctx *jxcontext.Context, sku *dao.StoreSkuSyncInfo) (err error) {
|
||||
globals.SugarLogger.Debugf("CreateSku2 sku:%s", utils.Format4Output(sku, true))
|
||||
param := skuInfo2Param(ctx, sku)
|
||||
if globals.EnableJdStoreWrite {
|
||||
sku.VendorSkuID, err = getAPI(sku.VendorOrgCode).AddSku2(param)
|
||||
} else {
|
||||
sku.VendorSkuID = utils.Int64ToStr(jxutils.GenFakeID())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateSku2(ctx *jxcontext.Context, sku *dao.StoreSkuSyncInfo) (err error) {
|
||||
globals.SugarLogger.Debugf("UpdateSku2 sku:%s", utils.Format4Output(sku, true))
|
||||
param := skuInfo2Param(ctx, sku)
|
||||
if globals.EnableJdStoreWrite {
|
||||
_, err = getAPI(sku.VendorOrgCode).UpdateSku2(param)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteSku2(ctx *jxcontext.Context, vendorOrgCode string, sku *partner.StoreSkuInfo) (err error) {
|
||||
globals.SugarLogger.Debugf("DeleteSku2 vendorOrgCode:%s, sku:%s", vendorOrgCode, utils.Format4Output(sku, true))
|
||||
param := &jdapi.OpSkuParam{
|
||||
TraceID: ctx.GetTrackInfo(),
|
||||
OutSkuID: utils.Int2Str(sku.SkuID),
|
||||
FixedStatus: jdapi.SkuFixedStatusDeleted,
|
||||
}
|
||||
if globals.EnableJdStoreWrite {
|
||||
_, err = getAPI(vendorOrgCode).UpdateSku2(param)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetSkus(ctx *jxcontext.Context, vendorOrgCode string, skuID int, vendorSkuID string) (skuNameList []*partner.SkuNameInfo, err error) {
|
||||
param := &jdapi.QuerySkuParam{
|
||||
SkuID: utils.Str2Int64WithDefault(vendorSkuID, 0),
|
||||
IsFilterDel: jdapi.IsFilterDelTrue,
|
||||
PageNo: 1,
|
||||
PageSize: jdapi.MaxSkuIDsCount4QueryListBySkuIds, // 为了同时取图,这个值不要大于jdapi.MaxSkuIDsCount4QueryListBySkuIds
|
||||
}
|
||||
for {
|
||||
skuList, _, err2 := getAPI(vendorOrgCode).QuerySkuInfos(param)
|
||||
if err = err2; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(skuList) > 0 {
|
||||
batchSkuNameList := make([]*partner.SkuNameInfo, len(skuList))
|
||||
for k, v := range skuList {
|
||||
batchSkuNameList[k] = vendorSku2Jx(v)
|
||||
}
|
||||
setSkuNameListPic(vendorOrgCode, batchSkuNameList)
|
||||
skuNameList = append(skuNameList, batchSkuNameList...)
|
||||
}
|
||||
if len(skuList) < param.PageSize {
|
||||
break
|
||||
}
|
||||
param.PageNo++
|
||||
}
|
||||
return skuNameList, err
|
||||
}
|
||||
|
||||
func setSkuNameListPic(vendorOrgCode string, skuNameList []*partner.SkuNameInfo) []*partner.SkuNameInfo {
|
||||
jdSkuIDs := make([]int64, len(skuNameList))
|
||||
for k, v := range skuNameList {
|
||||
jdSkuIDs[k] = utils.Str2Int64(v.SkuList[0].VendorSkuID)
|
||||
}
|
||||
|
||||
imgMap := make(map[int64]*jdapi.ImgHandleQueryResult)
|
||||
if imgList, err2 := getAPI(vendorOrgCode).QueryListBySkuIds(&jdapi.QueryListBySkuIdsParam{
|
||||
SkuIDs: jdSkuIDs,
|
||||
}); err2 == nil {
|
||||
for _, v := range imgList {
|
||||
if v.ImgType == jdapi.ImgTypeMain {
|
||||
imgResult := imgMap[v.SkuID]
|
||||
if imgResult == nil || imgResult.IsMain < v.IsMain {
|
||||
imgMap[v.SkuID] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用扒页面方式获取商品图片
|
||||
if false {
|
||||
var leftJdSkuIDs []int64
|
||||
for _, v := range jdSkuIDs {
|
||||
if imgMap[v] == nil {
|
||||
leftJdSkuIDs = append(leftJdSkuIDs, v)
|
||||
}
|
||||
}
|
||||
task := tasksch.NewParallelTask("jd setSkuNameListPic", nil, jxcontext.AdminCtx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
jdSkuID := batchItemList[0].(int64)
|
||||
imgList, err := getAPI(vendorOrgCode).GetSkuPageImageInfo(jdSkuID)
|
||||
if err == nil && len(imgList) > 0 {
|
||||
retVal = [][]string{
|
||||
[]string{utils.Int64ToStr(jdSkuID), imgList[0].Big},
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, leftJdSkuIDs)
|
||||
task.Run()
|
||||
if resultList, err := task.GetResult(0); err == nil {
|
||||
for _, v := range resultList {
|
||||
strList := v.([]string)
|
||||
imgMap[utils.Str2Int64(strList[0])] = &jdapi.ImgHandleQueryResult{
|
||||
SourceImgURL: strList[1],
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置商品图片
|
||||
for _, v := range skuNameList {
|
||||
if imgResult := imgMap[utils.Str2Int64(v.SkuList[0].VendorSkuID)]; imgResult != nil {
|
||||
v.PictureList = []string{imgResult.SourceImgURL}
|
||||
}
|
||||
}
|
||||
return skuNameList
|
||||
}
|
||||
|
||||
func vendorSku2Jx(vendorSku *jdapi.SkuMain) (skuName *partner.SkuNameInfo) {
|
||||
prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(vendorSku.SkuName)
|
||||
weight := int(vendorSku.Weight * 1000)
|
||||
if weight <= 0 {
|
||||
weight = jxutils.FormatSkuWeight(specQuality, specUnit)
|
||||
}
|
||||
skuID := int(utils.Str2Int64WithDefault(vendorSku.OutSkuID, 0))
|
||||
vendorSkuID := utils.Int64ToStr(vendorSku.SkuID)
|
||||
skuName = &partner.SkuNameInfo{
|
||||
NameID: skuID,
|
||||
VendorNameID: vendorSkuID,
|
||||
VendorCatIDList: []string{utils.Int64ToStr(vendorSku.CategoryID)},
|
||||
|
||||
Prefix: prefix,
|
||||
Name: name,
|
||||
Unit: unit,
|
||||
SkuList: []*partner.SkuInfo{
|
||||
&partner.SkuInfo{
|
||||
StoreSkuInfo: partner.StoreSkuInfo{
|
||||
VendorSkuID: vendorSkuID,
|
||||
SkuID: skuID,
|
||||
|
||||
VendorPrice: int64(vendorSku.SkuPrice),
|
||||
Status: jdStatus2jxStatus(vendorSku.FixedStatus),
|
||||
},
|
||||
SkuName: vendorSku.SkuName,
|
||||
Comment: comment,
|
||||
SpecQuality: float64(specQuality),
|
||||
SpecUnit: specUnit,
|
||||
Weight: weight,
|
||||
},
|
||||
},
|
||||
}
|
||||
return skuName
|
||||
}
|
||||
|
||||
func jdStatus2jxStatus(jdStatus int) (jxStatus int) {
|
||||
switch jdStatus {
|
||||
case jdapi.SkuFixedStatusOnline:
|
||||
jxStatus = model.SkuStatusNormal
|
||||
case jdapi.SkuFixedStatusOffline:
|
||||
jxStatus = model.SkuStatusDontSale
|
||||
case jdapi.SkuFixedStatusDeleted:
|
||||
jxStatus = model.SkuStatusDeleted
|
||||
}
|
||||
return jxStatus
|
||||
}
|
||||
|
||||
func jxStatus2jdStatus(jxStatus int) (jdStatus int) {
|
||||
switch jxStatus {
|
||||
case model.SkuStatusNormal:
|
||||
jdStatus = jdapi.SkuFixedStatusOnline
|
||||
case model.SkuStatusDontSale:
|
||||
jdStatus = jdapi.SkuFixedStatusOffline
|
||||
case model.SkuStatusDeleted:
|
||||
jdStatus = jdapi.SkuFixedStatusDeleted
|
||||
}
|
||||
return jdStatus
|
||||
}
|
||||
@@ -45,17 +45,17 @@ func TestGetAllCategories(t *testing.T) {
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestReadSku(t *testing.T) {
|
||||
skuName, err := CurPurchaseHandler.ReadSku("2005582952")
|
||||
t.Log(utils.Format4Output(skuName, false))
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
if skuName.Name != "味事达酱香鲜特级酿造酱油" || skuName.Skus[0].SpecUnit != "ml" {
|
||||
t.Fatal("ReadSku return data wrong")
|
||||
t.Log(string(utils.MustMarshal(skuName)))
|
||||
}
|
||||
}
|
||||
// func TestReadSku(t *testing.T) {
|
||||
// skuName, err := CurPurchaseHandler.ReadSku(jxcontext.AdminCtx, "", "2005582952")
|
||||
// t.Log(utils.Format4Output(skuName, false))
|
||||
// if err != nil {
|
||||
// t.Fatal(err.Error())
|
||||
// }
|
||||
// if skuName.Name != "味事达酱香鲜特级酿造酱油" || skuName.Skus[0].SpecUnit != "ml" {
|
||||
// t.Fatal("ReadSku return data wrong")
|
||||
// t.Log(string(utils.MustMarshal(skuName)))
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestGetVendorCategories(t *testing.T) {
|
||||
catList, err := CurPurchaseHandler.GetVendorCategories(jxcontext.AdminCtx)
|
||||
@@ -66,7 +66,7 @@ func TestGetVendorCategories(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetSkus(t *testing.T) {
|
||||
skuNameList, err := CurPurchaseHandler.GetSkus(jxcontext.AdminCtx, 0, "2023747677", "")
|
||||
skuNameList, err := CurPurchaseHandler.GetSkus(jxcontext.AdminCtx, "", 0, "2023747677")
|
||||
t.Log(utils.Format4Output(skuNameList, false))
|
||||
t.Log(len(skuNameList))
|
||||
if err != nil {
|
||||
|
||||
@@ -26,6 +26,7 @@ const (
|
||||
|
||||
type tJdStoreInfo struct {
|
||||
model.Store
|
||||
VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空
|
||||
|
||||
FreightDeductionPack string `orm:"size(32)" json:"freightDeductionPack"` //
|
||||
|
||||
@@ -37,8 +38,15 @@ type tJdStoreInfo struct {
|
||||
SyncStatus int
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorStoreID string) (*dao.StoreDetail, error) {
|
||||
result, err := getAPI("").GetStoreInfoByStationNo2(vendorStoreID)
|
||||
var (
|
||||
specialDistrictMap = map[int]int{
|
||||
13989: 310032,
|
||||
}
|
||||
)
|
||||
|
||||
func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string) (*dao.StoreDetail, error) {
|
||||
a := getAPI(vendorOrgCode)
|
||||
result, err := a.GetStoreInfoByStationNo2(vendorStoreID)
|
||||
if err == nil {
|
||||
retVal := &dao.StoreDetail{
|
||||
Store: model.Store{
|
||||
@@ -74,6 +82,7 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorStoreID string
|
||||
if cityCode != 0 {
|
||||
if city, err2 := dao.GetPlaceByJdCode(db, cityCode); err2 == nil {
|
||||
retVal.CityCode = city.Code
|
||||
retVal.CityName = utils.Interface2String(result.CityName)
|
||||
districtName := result.CountyName // 京东的市区号码与通用数据完全无法关联,只有通过名字来关联
|
||||
if retVal.CityCode != 0 && districtName != "" {
|
||||
if district, err2 := dao.GetPlaceByName(db, districtName, 3, city.Code); err2 == nil {
|
||||
@@ -90,9 +99,9 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorStoreID string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retVal.VendorStoreID = vendorStoreID
|
||||
retVal.ID = int(utils.Str2Int64WithDefault(result.OutSystemID, 0))
|
||||
deliveryRange, err2 := getAPI("").GetDeliveryRangeByStationNo2(vendorStoreID)
|
||||
deliveryRange, err2 := a.GetDeliveryRangeByStationNo2(vendorStoreID)
|
||||
if err = err2; err == nil {
|
||||
retVal.DeliveryRangeType = int8(deliveryRange.DeliveryRangeType)
|
||||
if retVal.DeliveryRangeType == model.DeliveryRangeTypePolygon {
|
||||
@@ -110,9 +119,11 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorStoreID string
|
||||
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
|
||||
var stores []*tJdStoreInfo
|
||||
sql := `
|
||||
SELECT t1.*, city.jd_code jd_city_code, district.jd_code jd_district_code,
|
||||
t2.status jd_store_status, t2.vendor_store_id, IF(t1.updated_at > t2.updated_at, t1.last_operator, t2.last_operator) real_last_operator,
|
||||
t2.sync_status, t2.freight_deduction_pack
|
||||
SELECT
|
||||
t1.*, city.jd_code jd_city_code, district.jd_code jd_district_code,
|
||||
t2.status jd_store_status, t2.vendor_store_id, IF(t1.updated_at > t2.updated_at, t1.last_operator,
|
||||
t2.last_operator) real_last_operator,
|
||||
t2.sync_status, t2.freight_deduction_pack, t2.vendor_org_code
|
||||
FROM store t1
|
||||
JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND (t2.deleted_at = ?)
|
||||
LEFT JOIN place city ON t1.city_code = city.code
|
||||
@@ -122,6 +133,7 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
||||
`
|
||||
if err = dao.GetRows(db, &stores, sql, model.VendorIDJD, utils.DefaultTimeValue, storeID); err == nil {
|
||||
for _, store := range stores {
|
||||
a := getAPI(store.VendorOrgCode)
|
||||
storeParams := &jdapi.OpStoreParams{
|
||||
StationNo: store.VendorStoreID,
|
||||
Operator: userName,
|
||||
@@ -154,6 +166,11 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
||||
storeParams.DeliveryRangeRadius = int(utils.Str2Int64WithDefault(store.DeliveryRange, 0))
|
||||
}
|
||||
}
|
||||
if specialDistrictMap[storeParams.County] != 0 {
|
||||
storeParams.City = storeParams.County
|
||||
storeParams.County = specialDistrictMap[storeParams.County]
|
||||
}
|
||||
|
||||
modifyCloseStatus := false
|
||||
if store.SyncStatus&(model.SyncFlagNewMask|model.SyncFlagDeletedMask|model.SyncFlagStoreStatus) != 0 {
|
||||
modifyCloseStatus = true
|
||||
@@ -163,7 +180,7 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
||||
globals.SugarLogger.Debug(utils.Format4Output(storeParams, false))
|
||||
errList := errlist.New()
|
||||
if globals.EnableJdStoreWrite {
|
||||
errList.AddErr(getAPI("").UpdateStoreInfo4Open2(storeParams, modifyCloseStatus))
|
||||
errList.AddErr(a.UpdateStoreInfo4Open2(storeParams, modifyCloseStatus))
|
||||
}
|
||||
if store.FreightDeductionPack != "" {
|
||||
storeDetail, err2 := dao.GetStoreDetail(db, store.ID, model.VendorIDJD)
|
||||
@@ -196,7 +213,7 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
||||
freightParams.IsFullFree = len(freightParams.FreeFreightInfoList) > 0
|
||||
globals.SugarLogger.Debug(utils.Format4Output(freightParams, false))
|
||||
if globals.EnableJdStoreWrite {
|
||||
errList.AddErr(getAPI("").UpdateStoreFreightConfigNew(freightParams))
|
||||
errList.AddErr(a.UpdateStoreFreightConfigNew(freightParams))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,7 +256,7 @@ func (p *PurchaseHandler) RefreshAllStoresID(ctx *jxcontext.Context, parentTask
|
||||
storeParams.OutSystemID = store.VendorStoreID
|
||||
}
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").UpdateStoreInfo4Open2(storeParams, false)
|
||||
err = getAPI(store.VendorOrgCode).UpdateStoreInfo4Open2(storeParams, false)
|
||||
}
|
||||
return nil, err
|
||||
}, stores)
|
||||
@@ -265,8 +282,8 @@ func JdDeliveryType2Jx(deliveryType int) int8 {
|
||||
return scheduler.StoreDeliveryTypeByPlatform
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeStatus int, err error) {
|
||||
result, err := getAPI("").GetStoreInfoByStationNo2(vendorStoreID)
|
||||
func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string) (storeStatus int, err error) {
|
||||
result, err := getAPI(vendorOrgCode).GetStoreInfoByStationNo2(vendorStoreID)
|
||||
if err == nil {
|
||||
storeStatus = JdStoreStatus2JxStatus(int(result.Yn), result.CloseStatus)
|
||||
}
|
||||
@@ -274,7 +291,7 @@ func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, storeID int, ve
|
||||
}
|
||||
|
||||
// 当前京东的storeCrud消息不会在门店状态改变时发送,所以意义不大,先放在这里
|
||||
func (c *PurchaseHandler) OnStoreMsg(msg *jdapi.CallbackOrderMsg) (response *jdapi.CallbackResponse) {
|
||||
func (c *PurchaseHandler) OnStoreMsg(vendorOrgCode string, msg *jdapi.CallbackOrderMsg) (response *jdapi.CallbackResponse) {
|
||||
var err error
|
||||
// if msg.StatusID == jdapi.StatusIDUpdateStore {
|
||||
// var storeStatus int
|
||||
@@ -291,15 +308,15 @@ func (c *PurchaseHandler) OnStoreMsg(msg *jdapi.CallbackOrderMsg) (response *jda
|
||||
return jdapi.Err2CallbackResponse(err, "")
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) EnableAutoAcceptOrder(ctx *jxcontext.Context, storeID int, vendorStoreID string, isSetEnable bool) (err error) {
|
||||
_, err = getAPI("").UpdateStoreConfig4Open(vendorStoreID, isSetEnable)
|
||||
func (p *PurchaseHandler) EnableAutoAcceptOrder(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, isSetEnable bool) (err error) {
|
||||
_, err = getAPI(vendorOrgCode).UpdateStoreConfig4Open(vendorStoreID, isSetEnable)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateStoreStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, status int) (err error) {
|
||||
func (c *PurchaseHandler) UpdateStoreStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, status int) (err error) {
|
||||
_, closeStatus := JxStoreStatus2JdStatus(status)
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").UpdateStoreInfo4Open2(&jdapi.OpStoreParams{
|
||||
err = getAPI(vendorOrgCode).UpdateStoreInfo4Open2(&jdapi.OpStoreParams{
|
||||
StationNo: vendorStoreID,
|
||||
Operator: ctx.GetUserName(),
|
||||
CloseStatus: closeStatus,
|
||||
@@ -331,26 +348,30 @@ func fillOpTimeParams(params *jdapi.OpStoreParams, opTimeList []int16) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateStoreOpTime(ctx *jxcontext.Context, storeID int, vendorStoreID string, opTimeList []int16) (err error) {
|
||||
func (c *PurchaseHandler) UpdateStoreOpTime(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, opTimeList []int16) (err error) {
|
||||
params := &jdapi.OpStoreParams{
|
||||
StationNo: vendorStoreID,
|
||||
Operator: ctx.GetUserName(),
|
||||
}
|
||||
fillOpTimeParams(params, opTimeList)
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").UpdateStoreInfo4Open2(params, false)
|
||||
err = getAPI(vendorOrgCode).UpdateStoreInfo4Open2(params, false)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetAllStoresVendorID(ctx *jxcontext.Context) (vendorStoreIDs []string, err error) {
|
||||
vendorStoreIDs, err = getAPI("").GetStationsByVenderId()
|
||||
func (c *PurchaseHandler) GetAllStoresVendorID(ctx *jxcontext.Context, vendorOrgCode string) (vendorStoreIDs []string, err error) {
|
||||
vendorStoreIDs, err = getAPI(vendorOrgCode).GetStationsByVenderId()
|
||||
return vendorStoreIDs, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) storeUploadImgByURL(inImgURL string) (imgURL string, err error) {
|
||||
func (c *PurchaseHandler) storeUploadImgByURL(vendorOrgCode, inImgURL string) (imgURL string, err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
imgURL, err = api.JdPageAPI.StoreUploadImgByURL(inImgURL)
|
||||
if vendorOrgCode == globals.JdOrgCode {
|
||||
imgURL, err = api.JdPageAPI.StoreUploadImgByURL(inImgURL)
|
||||
} else {
|
||||
imgURL, err = getAPI(vendorOrgCode).StoreUploadImgByURL(inImgURL)
|
||||
}
|
||||
} else {
|
||||
imgURL = utils.GetUUID()
|
||||
}
|
||||
@@ -378,7 +399,7 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
licenceURL, err := c.storeUploadImgByURL(storeDetail.Licence)
|
||||
licenceURL, err := c.storeUploadImgByURL(storeDetail.VendorOrgCode, storeDetail.Licence)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -400,7 +421,7 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S
|
||||
Scope: licenceDetail.Scope,
|
||||
})
|
||||
|
||||
idFrondURL, err := c.storeUploadImgByURL(storeDetail.IDCardFront)
|
||||
idFrondURL, err := c.storeUploadImgByURL(storeDetail.VendorOrgCode, storeDetail.IDCardFront)
|
||||
if err != nil {
|
||||
return addStoreInfo2Err(err, storeDetail.ID)
|
||||
}
|
||||
@@ -434,7 +455,7 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S
|
||||
qualifyList = append(qualifyList, addInfo)
|
||||
}
|
||||
if storeDetail.IDExpire == "" {
|
||||
idBackURL, err := c.storeUploadImgByURL(storeDetail.IDCardBack)
|
||||
idBackURL, err := c.storeUploadImgByURL(storeDetail.VendorOrgCode, storeDetail.IDCardBack)
|
||||
if err != nil {
|
||||
return addStoreInfo2Err(err, storeDetail.ID)
|
||||
}
|
||||
@@ -453,9 +474,9 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S
|
||||
return addStoreInfo2Err(err, storeDetail.ID)
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) UpdateStoreCustomID(ctx *jxcontext.Context, vendorStoreID string, storeID int64) (err error) {
|
||||
func (c *PurchaseHandler) UpdateStoreCustomID(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string, storeID int64) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").UpdateStoreInfo4Open2(
|
||||
err = getAPI(vendorOrgCode).UpdateStoreInfo4Open2(
|
||||
&jdapi.OpStoreParams{
|
||||
StationNo: vendorStoreID,
|
||||
Operator: ctx.GetUserName(),
|
||||
|
||||
@@ -20,7 +20,7 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
|
||||
return batchSize
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) getStoreSkusBareInfoLimitSize(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
|
||||
func (p *PurchaseHandler) getStoreSkusBareInfoLimitSize(ctx *jxcontext.Context, vendorOrgCode string, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
|
||||
var batchSkuInfoList []*jdapi.BaseStockCenterRequest
|
||||
batchSkuList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDIntList()
|
||||
for _, v := range inStoreSkuList {
|
||||
@@ -38,9 +38,9 @@ func (p *PurchaseHandler) getStoreSkusBareInfoLimitSize(ctx *jxcontext.Context,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
subTaskID := batchItemList[0].(int)
|
||||
if subTaskID == 0 {
|
||||
stockInfo, err = getAPI("").QueryOpenUseable(batchSkuInfoList)
|
||||
stockInfo, err = getAPI(vendorOrgCode).QueryOpenUseable(batchSkuInfoList)
|
||||
} else {
|
||||
priceInfo, err = getAPI("").GetStationInfoList(vendorStoreID, batchSkuList)
|
||||
priceInfo, err = getAPI(vendorOrgCode).GetStationInfoList(vendorStoreID, batchSkuList)
|
||||
}
|
||||
return nil, err
|
||||
}, []int{0, 1})
|
||||
@@ -65,9 +65,9 @@ func (p *PurchaseHandler) getStoreSkusBareInfoLimitSize(ctx *jxcontext.Context,
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreSkusBareInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
|
||||
func (p *PurchaseHandler) GetStoreSkusBareInfo(ctx *jxcontext.Context, vendorOrgCode string, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
|
||||
result, err := putils.FreeBatchStoreSkuInfo("获取门店商品信息", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
|
||||
list, err := p.getStoreSkusBareInfoLimitSize(ctx, task, storeID, vendorStoreID, batchedStoreSkuList)
|
||||
list, err := p.getStoreSkusBareInfoLimitSize(ctx, vendorOrgCode, task, storeID, vendorStoreID, batchedStoreSkuList)
|
||||
if err == nil {
|
||||
result = list
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func getStrOutSkuIDs(l []*jdapi.StoreSkuBatchUpdateResponse, isSuccess bool) (ou
|
||||
return outSkuIDs
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (successList []*partner.StoreSkuInfo, err error) {
|
||||
var skuVendibilityList []*jdapi.StockVendibility
|
||||
jdStatus := jxStoreSkuStatus2Jd(status)
|
||||
for _, v := range storeSkuList {
|
||||
@@ -120,7 +120,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
|
||||
})
|
||||
}
|
||||
if globals.EnableJdStoreWrite {
|
||||
responseList, err2 := getAPI("").BatchUpdateVendibility(ctx.GetTrackInfo(), "", vendorStoreID, skuVendibilityList, ctx.GetUserName())
|
||||
responseList, err2 := getAPI(vendorOrgCode).BatchUpdateVendibility(ctx.GetTrackInfo(), "", vendorStoreID, skuVendibilityList, ctx.GetUserName())
|
||||
if err = err2; isErrPartialFailed(err) {
|
||||
failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品状态")
|
||||
// successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false)))
|
||||
@@ -129,10 +129,10 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
if len(storeSkuList) == 1 {
|
||||
if globals.EnableJdStoreWrite {
|
||||
_, err = getAPI("").UpdateStationPrice(ctx.GetTrackInfo(), utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), vendorStoreID, int(storeSkuList[0].VendorPrice))
|
||||
_, err = getAPI(vendorOrgCode).UpdateStationPrice(ctx.GetTrackInfo(), utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), vendorStoreID, int(storeSkuList[0].VendorPrice))
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDJD, "更新商品价格")
|
||||
}
|
||||
} else {
|
||||
@@ -144,7 +144,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
|
||||
})
|
||||
}
|
||||
if globals.EnableJdStoreWrite {
|
||||
responseList, err2 := getAPI("").UpdateVendorStationPrice(ctx.GetTrackInfo(), "", vendorStoreID, skuPriceInfoList)
|
||||
responseList, err2 := getAPI(vendorOrgCode).UpdateVendorStationPrice(ctx.GetTrackInfo(), "", vendorStoreID, skuPriceInfoList)
|
||||
if err = err2; isErrPartialFailed(err) {
|
||||
failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品价格")
|
||||
}
|
||||
@@ -153,10 +153,10 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (failedList []*partner.StoreSkuInfoWithErr, err error) {
|
||||
if len(storeSkuList) == 1 {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").UpdateCurrentQty(ctx.GetTrackInfo(), vendorStoreID, utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), storeSkuList[0].Stock)
|
||||
err = getAPI(vendorOrgCode).UpdateCurrentQty(ctx.GetTrackInfo(), vendorStoreID, utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), storeSkuList[0].Stock)
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDJD, "更新商品库存")
|
||||
}
|
||||
} else {
|
||||
@@ -168,7 +168,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i
|
||||
})
|
||||
}
|
||||
if globals.EnableJdStoreWrite {
|
||||
responseList, err2 := getAPI("").BatchUpdateCurrentQtys(ctx.GetTrackInfo(), "", vendorStoreID, skuStockList, ctx.GetUserName())
|
||||
responseList, err2 := getAPI(vendorOrgCode).BatchUpdateCurrentQtys(ctx.GetTrackInfo(), "", vendorStoreID, skuStockList, ctx.GetUserName())
|
||||
if err = err2; isErrPartialFailed(err) {
|
||||
failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品库存")
|
||||
// successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false)))
|
||||
@@ -178,7 +178,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i
|
||||
return failedList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) SyncStoreProducts(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
func (p *PurchaseHandler) SyncStoreProducts(ctx *jxcontext.Context, vendorOrgCode string, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("jd SyncStoreProducts, storeID:%d", storeID)
|
||||
db := dao.GetDB()
|
||||
storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDJD)
|
||||
@@ -194,7 +194,7 @@ func (p *PurchaseHandler) SyncStoreProducts(ctx *jxcontext.Context, parentTask t
|
||||
storeSku := batchItemList[0].(*dao.StoreSkuSyncInfo)
|
||||
if storeSku.VendorSkuID != "" && storeSku.StoreSkuStatus == model.SkuStatusNormal {
|
||||
if globals.EnableJdStoreWrite {
|
||||
synchronized, err2 := getAPI("").SyncProduct(storeDetail.VendorStoreID, storeSku.VendorSkuID)
|
||||
synchronized, err2 := getAPI(vendorOrgCode).SyncProduct(storeDetail.VendorStoreID, storeSku.VendorSkuID)
|
||||
if err = err2; err == nil && synchronized {
|
||||
retVal = []int{1}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ func TestGetStoreSkusBareInfo(t *testing.T) {
|
||||
// for i := 0; i < 30-1; i++ {
|
||||
// list = append(list, list[0])
|
||||
// }
|
||||
skuNameList, err := CurPurchaseHandler.GetSkus(jxcontext.AdminCtx, 0, "", "")
|
||||
skuNameList, err := CurPurchaseHandler.GetSkus(jxcontext.AdminCtx, "", 0, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
list := putils.StoreSkuFullList2Bare(skuNameList)
|
||||
|
||||
storeSkuList, err := CurPurchaseHandler.GetStoreSkusBareInfo(jxcontext.AdminCtx, nil, 2, "11053496", list)
|
||||
storeSkuList, err := CurPurchaseHandler.GetStoreSkusBareInfo(jxcontext.AdminCtx, "", nil, 2, "11053496", list)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ const (
|
||||
)
|
||||
|
||||
func TestReadStore(t *testing.T) {
|
||||
result, err := new(PurchaseHandler).ReadStore(jxcontext.AdminCtx, TestJdStoreNo)
|
||||
result, err := new(PurchaseHandler).ReadStore(jxcontext.AdminCtx, "", TestJdStoreNo)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func TestReadStore(t *testing.T) {
|
||||
|
||||
func TestUpdateStore(t *testing.T) {
|
||||
handler := new(PurchaseHandler)
|
||||
result, err := handler.ReadStore(jxcontext.AdminCtx, TestJdStoreNo)
|
||||
result, err := handler.ReadStore(jxcontext.AdminCtx, "", TestJdStoreNo)
|
||||
|
||||
// result := &model.Store{}
|
||||
// result.ID = 100164
|
||||
@@ -43,7 +43,7 @@ func TestUpdateStore(t *testing.T) {
|
||||
}
|
||||
|
||||
// same
|
||||
result, err = handler.ReadStore(jxcontext.AdminCtx, TestJdStoreNo)
|
||||
result, err = handler.ReadStore(jxcontext.AdminCtx, "", TestJdStoreNo)
|
||||
if result.Name != newName {
|
||||
t.Fatalf("result is not same, desired newName:%s, newName:%s", newName, result.Name)
|
||||
}
|
||||
|
||||
@@ -8,21 +8,21 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) OnWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
||||
func (c *PurchaseHandler) OnWaybillMsg(vendorOrgCode string, msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
retVal = c.onWaybillMsg(msg)
|
||||
retVal = c.onWaybillMsg(vendorOrgCode, msg)
|
||||
}, jxutils.ComposeUniversalOrderID(msg.OrderID, model.VendorIDJD))
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) onWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
||||
func (c *PurchaseHandler) onWaybillMsg(vendorOrgCode string, msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
||||
order := c.callbackMsg2Waybill(msg)
|
||||
switch msg.DeliveryStatus {
|
||||
case jdapi.DeliveryStatusWait4Grap:
|
||||
order.Status = model.WaybillStatusNew
|
||||
case jdapi.DeliveryStatusAccepted, jdapi.DeliveryStatusCourierChaged: // 将更换配送员也当成接单消息
|
||||
// todo 性能问题,暂时取消调用
|
||||
// if result, err := getAPI("").QuerySingleOrder(msg.OrderID); err == nil {
|
||||
// if result, err := getAPI(vendorOrgCode).QuerySingleOrder(msg.OrderID); err == nil {
|
||||
// // 默认配送费=订单应付运费(orderReceivableFreight)
|
||||
// //订单应付运费为未优惠前应付运费(满免优惠,运费优惠券,VIP免基础运费,用户小费)ps:用户小费是用户给配送员的小费
|
||||
// order.DesiredFee = utils.Interface2Int64WithDefault(result["orderReceivableFreight"], 0) +
|
||||
@@ -63,6 +63,8 @@ func (c *PurchaseHandler) callbackMsg2Waybill(msg *jdapi.CallbackDeliveryStatusM
|
||||
VendorStatus: msg.DeliveryStatus,
|
||||
StatusTime: utils.Str2Time(msg.DeliveryStatusTime),
|
||||
Remark: msg.Remark,
|
||||
|
||||
VendorOrgCode: appKey2OrgCode(msg.AppKey),
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user