Merge remote-tracking branch 'origin/mark' into don
This commit is contained in:
@@ -225,6 +225,13 @@ func GetPurchasePlatformFromVendorID(vendorID int) IPurchasePlatformHandler {
|
||||
return PurchasePlatformHandlers[vendorID]
|
||||
}
|
||||
|
||||
func GetPurchasePlatformVendorIDs() (vendorIDs []int) {
|
||||
for k := range PurchasePlatformHandlers {
|
||||
vendorIDs = append(vendorIDs, k)
|
||||
}
|
||||
return vendorIDs
|
||||
}
|
||||
|
||||
func GetMultiStoreVendorIDs() (vendorIDs []int) {
|
||||
for k, v := range PurchasePlatformHandlers {
|
||||
if _, ok := v.(IMultipleStoresHandler); ok {
|
||||
|
||||
@@ -5,6 +5,11 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type OrderPhoneNumberInfo struct {
|
||||
VendorOrderID string
|
||||
PhoneNumber string
|
||||
}
|
||||
|
||||
type IPurchasePlatformOrderHandler interface {
|
||||
Map2Order(orderData map[string]interface{}) (order *model.GoodsOrder)
|
||||
GetOrder(vendorOrderID string) (order *model.GoodsOrder, err error)
|
||||
|
||||
@@ -2,8 +2,9 @@ package partner
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
@@ -39,6 +40,7 @@ type StoreSkuInfo struct {
|
||||
Stock int `json:"stock,omitempty"`
|
||||
VendorPrice int64 `json:"price,omitempty"`
|
||||
Status int `json:"status,omitempty"`
|
||||
Seq int `json:"seq,omitempty"`
|
||||
}
|
||||
|
||||
type SkuInfo struct {
|
||||
@@ -94,6 +96,21 @@ func (l BareStoreSkuInfoList) GetSkuIDList() (skuIDList []int) {
|
||||
return skuIDList
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) Len() int {
|
||||
return len(l)
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) Less(i, j int) bool {
|
||||
if l[i].Seq != l[j].Seq {
|
||||
return l[i].Seq < l[j].Seq
|
||||
}
|
||||
return l[i].VendorPrice < l[j].VendorPrice
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) Swap(i, j int) {
|
||||
l[i], l[j] = l[j], l[i]
|
||||
}
|
||||
|
||||
type BareCategoryInfo struct {
|
||||
VendorCatID string `json:"vendorCatID"`
|
||||
|
||||
@@ -141,6 +158,10 @@ type ISingleStoreStoreSkuHandler interface {
|
||||
GetSensitiveWordRegexp() *regexp.Regexp
|
||||
}
|
||||
|
||||
type IStoreSkuSorter interface {
|
||||
ReorderStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, vendorCatID string, storeSkuList []*StoreSkuInfo) (err error)
|
||||
}
|
||||
|
||||
func BuildSkuName(skuID int, vendorSkuID string) (skuName *SkuNameInfo) {
|
||||
return &SkuNameInfo{
|
||||
SkuList: []*SkuInfo{
|
||||
|
||||
@@ -171,6 +171,7 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
VendorStoreID: shopMap["baidu_shop_id"].(string),
|
||||
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(shopMap["id"]), 0)),
|
||||
StoreName: shopMap["name"].(string),
|
||||
VendorUserID: utils.Interface2String(userMap["user_id"]),
|
||||
ConsigneeName: userMap["name"].(string),
|
||||
ConsigneeMobile: jxutils.FormalizeMobile(userMap["phone"].(string)),
|
||||
ConsigneeAddress: userMap["address"].(string),
|
||||
|
||||
@@ -300,7 +300,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
||||
|
||||
func OnActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
retVal = curPurchaseHandler.onActMsg(msg)
|
||||
retVal = CurPurchaseHandler.onActMsg(msg)
|
||||
}, jxutils.ComposeUniversalOrderID(msg.BillID, model.VendorIDJD))
|
||||
return retVal
|
||||
}
|
||||
|
||||
@@ -5,22 +5,22 @@ import (
|
||||
)
|
||||
|
||||
func OnOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if curPurchaseHandler != nil {
|
||||
retVal = curPurchaseHandler.OnOrderMsg(msg)
|
||||
if CurPurchaseHandler != nil {
|
||||
retVal = CurPurchaseHandler.OnOrderMsg(msg)
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func OnWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if curPurchaseHandler != nil {
|
||||
retVal = curPurchaseHandler.OnWaybillMsg(msg)
|
||||
if CurPurchaseHandler != nil {
|
||||
retVal = CurPurchaseHandler.OnWaybillMsg(msg)
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func OnStoreMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
if curPurchaseHandler != nil {
|
||||
retVal = curPurchaseHandler.OnStoreMsg(msg)
|
||||
if CurPurchaseHandler != nil {
|
||||
retVal = CurPurchaseHandler.OnStoreMsg(msg)
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func (p *PurchaseHandler) onFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *j
|
||||
if err = err2; err == nil {
|
||||
orderData, err2 := getAPI("").QuerySingleOrder(msg.BillID)
|
||||
if err = err2; err == nil {
|
||||
orderFinancial, err2 := curPurchaseHandler.OrderDetail2Financial(orderData, false, order)
|
||||
orderFinancial, err2 := CurPurchaseHandler.OrderDetail2Financial(orderData, false, order)
|
||||
if err = err2; err == nil {
|
||||
if msg.StatusID == jdapi.OrderStatusPayFinishedSettle {
|
||||
err = partner.CurOrderManager.SaveOrderFinancialInfo(orderFinancial, partner.CreatedPeration)
|
||||
@@ -39,7 +39,7 @@ func (p *PurchaseHandler) onFinancialMsg(msg *jdapi.CallbackOrderMsg) (retVal *j
|
||||
} else if msg.StatusID == jdapi.AfsServiceStateRefundSuccess || msg.StatusID == jdapi.AfsServiceStateReturnGoodsSuccess { // 如果是退款单
|
||||
orderData, err2 := getAPI("").GetAfsService(msg.BillID)
|
||||
if err = err2; err == nil {
|
||||
err = partner.CurOrderManager.SaveAfsOrderFinancialInfo(curPurchaseHandler.AfsOrderDetail2Financial(orderData))
|
||||
err = partner.CurOrderManager.SaveAfsOrderFinancialInfo(CurPurchaseHandler.AfsOrderDetail2Financial(orderData))
|
||||
}
|
||||
}
|
||||
return jdapi.Err2CallbackResponse(nil, "jd OnFinancialMsg") // todo 强制返回成功
|
||||
@@ -101,7 +101,7 @@ func (p *PurchaseHandler) OrderDetail2Financial(orderData map[string]interface{}
|
||||
}
|
||||
}
|
||||
// orderFinancial.DeliveryConfirmTime = utils.Str2TimeWithDefault(utils.Interface2String(orderData["deliveryConfirmTime"]), utils.DefaultTimeValue)
|
||||
if utils.Interface2String(orderData["deliveryCarrierNo"]) == jdapi.SelfDeliveryCarrierNo {
|
||||
if int(utils.Str2Int64WithDefault(utils.Interface2String(orderData["deliveryCarrierNo"]), 0)) == jdapi.CarrierNoSelfDelivery {
|
||||
// 如果为自配送,自配送补贴=订单初始运费,远距离费=0
|
||||
orderFinancial.SelfDeliveryDiscountMoney = utils.MustInterface2Int64(orderData["orderReceivableFreight"])
|
||||
orderFinancial.DistanceFreightMoney = 0
|
||||
@@ -233,7 +233,7 @@ func (p *PurchaseHandler) AfsOrderDetail2Financial(orderData map[string]interfac
|
||||
func (p *PurchaseHandler) OnOrderDetail(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(orderDetail, true, order)
|
||||
if err = err2; err == nil {
|
||||
err = partner.CurOrderManager.SaveOrderFinancialInfo(orderFinancial, peration)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ func TestOnFinancialMsg(t *testing.T) {
|
||||
BillID: "907315020000322",
|
||||
StatusID: "330902",
|
||||
}
|
||||
res := curPurchaseHandler.onFinancialMsg(msg)
|
||||
res := CurPurchaseHandler.onFinancialMsg(msg)
|
||||
fmt.Println(res)
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ type PurchaseHandler struct {
|
||||
}
|
||||
|
||||
var (
|
||||
curPurchaseHandler *PurchaseHandler
|
||||
CurPurchaseHandler *PurchaseHandler
|
||||
)
|
||||
|
||||
func init() {
|
||||
globals.SugarLogger.Debug("init jd")
|
||||
if getAPI("") != nil {
|
||||
curPurchaseHandler = new(PurchaseHandler)
|
||||
partner.RegisterPurchasePlatform(curPurchaseHandler)
|
||||
CurPurchaseHandler = new(PurchaseHandler)
|
||||
partner.RegisterPurchasePlatform(CurPurchaseHandler)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package jd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -34,6 +35,13 @@ var (
|
||||
jdapi.OrderStatusLocked: model.OrderStatusLocked,
|
||||
jdapi.OrderStatusUnlocked: model.OrderStatusUnlocked,
|
||||
}
|
||||
deliveryTypeMap = map[int]string{
|
||||
jdapi.CarrierNoCrowdSourcing: model.OrderDeliveryTypePlatform,
|
||||
jdapi.CarrierNoSelfDelivery: model.OrderDeliveryTypeStoreSelf,
|
||||
jdapi.CarrierNoSelfTake: model.OrderDeliveryTypeSelfTake,
|
||||
}
|
||||
|
||||
selfTakeCodeReg = regexp.MustCompile(`等待用户凭提货码(\d+)于`)
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) OnOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||
@@ -130,18 +138,6 @@ func (c *PurchaseHandler) getOrder(orderID string) (order *model.GoodsOrder, ord
|
||||
if order != nil && orderSettlement != nil {
|
||||
updateOrderBySettleMent(order, orderSettlement)
|
||||
}
|
||||
// if orderMap, err = getAPI("").QuerySingleOrder(orderID); err == nil {
|
||||
// globals.SugarLogger.Debugf("jd getOrder2 orderID:%s", orderID)
|
||||
// order = c.Map2Order(orderMap)
|
||||
// if jxutils.IsMobileFake(order.ConsigneeMobile) {
|
||||
// if realMobile, err := getAPI("").GetRealMobile4Order(orderID, order.VendorStoreID); err == nil { // 故意强制忽略取不到真实手机号错误
|
||||
// globals.SugarLogger.Debugf("jd getOrder3 orderID:%s", orderID)
|
||||
// order.ConsigneeMobile2 = jxutils.FormalizeMobile(realMobile)
|
||||
// } else {
|
||||
// // globals.SugarLogger.Warnf("jd GetOrder orderID:%s, GetRealMobile4Order failed with error:%v", orderID, err2)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return order, orderMap, err
|
||||
}
|
||||
|
||||
@@ -166,6 +162,7 @@ func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
VendorStoreID: utils.Interface2String(result["produceStationNo"]),
|
||||
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["produceStationNoIsv"]), 0)),
|
||||
StoreName: utils.Interface2String(result["produceStationName"]),
|
||||
VendorUserID: utils.Interface2String(result["buyerPin"]),
|
||||
ConsigneeName: utils.Interface2String(result["buyerFullName"]),
|
||||
ConsigneeMobile: jxutils.FormalizeMobile(utils.Interface2String(result["buyerMobile"])),
|
||||
ConsigneeAddress: utils.Interface2String(result["buyerFullAddress"]),
|
||||
@@ -180,6 +177,7 @@ func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
OriginalData: string(utils.MustMarshal(result)),
|
||||
ActualPayPrice: utils.MustInterface2Int64(result["orderBuyerPayableMoney"]),
|
||||
DistanceFreightMoney: utils.Interface2Int64WithDefault(result["merchantPaymentDistanceFreightMoney"], 0),
|
||||
DeliveryType: deliveryTypeMap[int(utils.Str2Int64WithDefault(utils.Interface2String(result["deliveryCarrierNo"]), 0))],
|
||||
}
|
||||
order.Status = c.getStatusFromVendorStatus(order.VendorStatus)
|
||||
businessTage := utils.Interface2String(result["businessTag"])
|
||||
@@ -471,3 +469,26 @@ func (c *PurchaseHandler) AddWaybillTip(ctx *jxcontext.Context, order *model.Goo
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetSelfTakeCode(ctx *jxcontext.Context, vendorOrderID string) (selfTakeCode string, err error) {
|
||||
orderTrackList, err := getAPI("").GetByOrderNoForOaos(vendorOrderID)
|
||||
if err == nil {
|
||||
for _, v := range orderTrackList {
|
||||
if v.TagCode == 180 {
|
||||
searchResult := selfTakeCodeReg.FindStringSubmatch(v.MsgContent)
|
||||
if searchResult != nil && len(searchResult[1]) > 0 {
|
||||
selfTakeCode = searchResult[1]
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return selfTakeCode, err
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID, selfTakeCode string) (err error) {
|
||||
if globals.EnableJdStoreWrite {
|
||||
err = getAPI("").CheckSelfPickCode(selfTakeCode, vendorOrderID, ctx.GetUserName())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func TestSwitch2SelfDeliver(t *testing.T) {
|
||||
orderID := "817540316000041"
|
||||
if order, err := partner.CurOrderManager.LoadOrder(orderID, model.VendorIDJD); err == nil {
|
||||
// globals.SugarLogger.Debug(order)
|
||||
if err = curPurchaseHandler.Swtich2SelfDeliver(order, ""); err == nil {
|
||||
if err = CurPurchaseHandler.Swtich2SelfDeliver(order, ""); err == nil {
|
||||
} else {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
@@ -26,16 +26,24 @@ 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())
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestGetSelfTakeCode(t *testing.T) {
|
||||
selfTakeCode, err := CurPurchaseHandler.GetSelfTakeCode(jxcontext.AdminCtx, "921160248000222")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
t.Log(selfTakeCode)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestCreateSku(t *testing.T) {
|
||||
sku.ID = skuID
|
||||
dao.GetEntity(nil, sku)
|
||||
t.Log(sku)
|
||||
// err := curPurchaseHandler.CreateSku(sku)
|
||||
// err := CurPurchaseHandler.CreateSku(sku)
|
||||
// if err != nil {
|
||||
// t.Fatal(err.Error())
|
||||
// }
|
||||
@@ -31,14 +31,14 @@ func TestUpdateSku(t *testing.T) {
|
||||
sku.ID = skuID
|
||||
dao.GetEntity(db, sku)
|
||||
|
||||
err := curPurchaseHandler.UpdateSku(db, sku, "autotest")
|
||||
err := CurPurchaseHandler.UpdateSku(db, sku, "autotest")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAllCategories(t *testing.T) {
|
||||
result, err := curPurchaseHandler.GetAllCategories(jxcontext.AdminCtx, "")
|
||||
result, err := CurPurchaseHandler.GetAllCategories(jxcontext.AdminCtx, "")
|
||||
if err != nil || len(result) == 0 {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func TestGetAllCategories(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReadSku(t *testing.T) {
|
||||
skuName, err := curPurchaseHandler.ReadSku("2005582952")
|
||||
skuName, err := CurPurchaseHandler.ReadSku("2005582952")
|
||||
t.Log(utils.Format4Output(skuName, false))
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
@@ -58,7 +58,7 @@ func TestReadSku(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetVendorCategories(t *testing.T) {
|
||||
catList, err := curPurchaseHandler.GetVendorCategories(jxcontext.AdminCtx)
|
||||
catList, err := CurPurchaseHandler.GetVendorCategories(jxcontext.AdminCtx)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -394,7 +394,7 @@ func (c *PurchaseHandler) SyncQualify(ctx *jxcontext.Context, storeDetail *dao.S
|
||||
}
|
||||
expireStart, err := utils.TryStr2Time(licenceDetail.StartDate)
|
||||
if err != nil {
|
||||
return fmt.Errorf("证照有效开始时间:%s非法,请手动处理", licenceDetail.StartDate)
|
||||
return fmt.Errorf("执照有效开始时间:%s非法,请手动处理", licenceDetail.StartDate)
|
||||
}
|
||||
qualifyList = append(qualifyList, &jdapi.QualifyItem{
|
||||
QualifyType: jdapi.QualifyTypeCompany,
|
||||
|
||||
@@ -209,3 +209,17 @@ func (p *PurchaseHandler) SyncStoreProducts(ctx *jxcontext.Context, parentTask t
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
// func (p *PurchaseHandler) ReorderStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, vendorCatID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
|
||||
// storeSkuCount := len(storeSkuList)
|
||||
// if storeSkuCount > 0 {
|
||||
// if storeSkuCount > jdapi.MaxAddByStoreAndSkusCount {
|
||||
// storeSkuList = storeSkuList[:jdapi.MaxAddByStoreAndSkusCount]
|
||||
// }
|
||||
// vendorSkuIDs := partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDIntList()
|
||||
// if globals.EnableJdStoreWrite {
|
||||
// err = getAPI("").AddByStoreAndSkus(utils.Str2Int64(vendorStoreID), vendorSkuIDs)
|
||||
// }
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ func TestSyncQualify(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
err = curPurchaseHandler.SyncQualify(jxcontext.AdminCtx, storeDetail)
|
||||
err = CurPurchaseHandler.SyncQualify(jxcontext.AdminCtx, storeDetail)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ func init() {
|
||||
globals.SugarLogger.Debug("init jx")
|
||||
if true {
|
||||
CurPurchaseHandler = new(PurchaseHandler)
|
||||
partner.RegisterPurchasePlatform(CurPurchaseHandler)
|
||||
// 不能注册京西
|
||||
// partner.RegisterPurchasePlatform(CurPurchaseHandler)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,24 +6,28 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func OnOrderCallbackMsg(msg *mtwmapi.CallbackMsg) (response *mtwmapi.CallbackResponse) {
|
||||
func OnCallbackMsg(msg *mtwmapi.CallbackMsg) (response *mtwmapi.CallbackResponse) {
|
||||
if curPurchaseHandler != nil {
|
||||
if orderID := GetOrderIDFromMsg(msg); orderID != "" {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
switch msg.Cmd {
|
||||
case mtwmapi.MsgTypeWaybillStatus:
|
||||
response = curPurchaseHandler.onWaybillMsg(msg)
|
||||
default:
|
||||
response = curPurchaseHandler.onOrderMsg(msg)
|
||||
}
|
||||
}, jxutils.ComposeUniversalOrderID(orderID, model.VendorIDMTWM))
|
||||
}
|
||||
/*if msg.Cmd == mtwmapi.MsgTypeOrderRefund || msg.Cmd == mtwmapi.MsgTypeOrderPartialRefund {
|
||||
utils.CallFuncAsync(func() {
|
||||
OnFinancialMsg(msg)
|
||||
})
|
||||
} else */if msg.Cmd == mtwmapi.MsgTypeStoreStatusChanged {
|
||||
if msg.Cmd == mtwmapi.MsgTypeStoreStatusChanged {
|
||||
response = curPurchaseHandler.onStoreStatusChanged(msg)
|
||||
} else if msg.Cmd == mtwmapi.MsgTypePrivateNumberDowngrade {
|
||||
response = curPurchaseHandler.onNumberDowngrade(msg)
|
||||
} else {
|
||||
if orderID := GetOrderIDFromMsg(msg); orderID != "" {
|
||||
jxutils.CallMsgHandler(func() {
|
||||
switch msg.Cmd {
|
||||
case mtwmapi.MsgTypeWaybillStatus:
|
||||
response = curPurchaseHandler.onWaybillMsg(msg)
|
||||
default:
|
||||
response = curPurchaseHandler.onOrderMsg(msg)
|
||||
}
|
||||
}, jxutils.ComposeUniversalOrderID(orderID, model.VendorIDMTWM))
|
||||
}
|
||||
/*if msg.Cmd == mtwmapi.MsgTypeOrderRefund || msg.Cmd == mtwmapi.MsgTypeOrderPartialRefund {
|
||||
utils.CallFuncAsync(func() {
|
||||
OnFinancialMsg(msg)
|
||||
})
|
||||
} */
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"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"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
@@ -121,6 +122,10 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo
|
||||
OriginalData: string(utils.MustMarshal(result)),
|
||||
ActualPayPrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(result["total"])),
|
||||
}
|
||||
openUID := utils.Interface2Int64WithDefault(result["openUid"], 0)
|
||||
if openUID > 0 {
|
||||
order.VendorUserID = utils.Int64ToStr(openUID)
|
||||
}
|
||||
if utils.IsTimeZero(order.PickDeadline) && !utils.IsTimeZero(order.StatusTime) {
|
||||
order.PickDeadline = order.StatusTime.Add(pickupOrderDelay) // 美团外卖要求在5分钟内拣货,不然订单会被取消
|
||||
}
|
||||
@@ -382,7 +387,7 @@ func (c *PurchaseHandler) postFakeMsg(vendorOrderID, cmd, vendorStatus string) {
|
||||
msg.FormData.Set("timestamp", timeStr)
|
||||
msg.FormData.Set("utime", timeStr)
|
||||
utils.CallFuncAsync(func() {
|
||||
OnOrderCallbackMsg(msg)
|
||||
c.onOrderMsg(msg)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -582,3 +587,112 @@ func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, parentTask tasksch.
|
||||
// }
|
||||
// return err
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) GetOrderConsigneeNumber(ctx *jxcontext.Context, storeID int, vendorStoreID string) (numberList []*partner.OrderPhoneNumberInfo, err error) {
|
||||
offset := 0
|
||||
for {
|
||||
result, err2 := api.MtwmAPI.OrderBatchPullPhoneNumber(vendorStoreID, 0, mtwmapi.MaxBatchPullPhoneNumberLimit)
|
||||
if err = err2; err == nil {
|
||||
for _, v := range result {
|
||||
v2 := &partner.OrderPhoneNumberInfo{
|
||||
VendorOrderID: utils.Int64ToStr(v.OrderID),
|
||||
PhoneNumber: v.RealPhoneNumber,
|
||||
}
|
||||
if v2.PhoneNumber == "" {
|
||||
v2.PhoneNumber = v.RealOrderPhoneNumber
|
||||
}
|
||||
numberList = append(numberList, v2)
|
||||
}
|
||||
if len(result) <= mtwmapi.MaxBatchPullPhoneNumberLimit {
|
||||
break
|
||||
}
|
||||
offset += mtwmapi.MaxBatchPullPhoneNumberLimit
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return numberList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetOrderCourierNumber(ctx *jxcontext.Context, storeID int, vendorStoreID string) (numberList []*partner.OrderPhoneNumberInfo, err error) {
|
||||
offset := 0
|
||||
for {
|
||||
result, err2 := api.MtwmAPI.OrderGetRiderInfoPhoneNumber(vendorStoreID, 0, mtwmapi.MaxBatchPullPhoneNumberLimit)
|
||||
if err = err2; err == nil {
|
||||
for _, v := range result {
|
||||
numberList = append(numberList, &partner.OrderPhoneNumberInfo{
|
||||
VendorOrderID: utils.Int64ToStr(v.OrderID),
|
||||
PhoneNumber: v.RiderRealPhoneNumber,
|
||||
})
|
||||
}
|
||||
if len(result) <= mtwmapi.MaxBatchPullPhoneNumberLimit {
|
||||
break
|
||||
}
|
||||
offset += mtwmapi.MaxBatchPullPhoneNumberLimit
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return numberList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) onNumberDowngrade(msg *mtwmapi.CallbackMsg) (response *mtwmapi.CallbackResponse) {
|
||||
userNumberMap := make(map[string]*partner.OrderPhoneNumberInfo)
|
||||
courierNumberMap := make(map[string]*partner.OrderPhoneNumberInfo)
|
||||
orderMap := make(map[string]int)
|
||||
ctx := jxcontext.AdminCtx
|
||||
task := tasksch.NewParallelTask("美团外卖平台处理隐私号降级通知", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 0:
|
||||
userNumberList, err2 := p.GetOrderConsigneeNumber(ctx, 0, "")
|
||||
if err = err2; err == nil {
|
||||
for _, v := range userNumberList {
|
||||
userNumberMap[v.VendorOrderID] = v
|
||||
orderMap[v.VendorOrderID] = 1
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
courierNumberList, err2 := p.GetOrderCourierNumber(ctx, 0, "")
|
||||
if err = err2; err == nil {
|
||||
for _, v := range courierNumberList {
|
||||
courierNumberMap[v.VendorOrderID] = v
|
||||
orderMap[v.VendorOrderID] = 1
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
orderList := jxutils.StringMap2List(orderMap)
|
||||
if len(orderList) > 0 {
|
||||
updateTask := tasksch.NewParallelTask("美团外卖平台处理隐私号降级通知/处理订单", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorOrderID := batchItemList[0].(string)
|
||||
db := dao.GetDB()
|
||||
if userNumberMap[vendorOrderID] != nil {
|
||||
_, err = dao.UpdateEntityByKV(db, &model.GoodsOrder{}, map[string]interface{}{
|
||||
"ConsigneeMobile": userNumberMap[vendorOrderID].PhoneNumber,
|
||||
"ConsigneeMobile2": userNumberMap[vendorOrderID].PhoneNumber,
|
||||
}, map[string]interface{}{
|
||||
model.FieldVendorOrderID: vendorOrderID,
|
||||
model.FieldVendorID: model.VendorIDMTWM,
|
||||
})
|
||||
}
|
||||
if courierNumberMap[vendorOrderID] != nil {
|
||||
_, err = dao.UpdateEntityByKV(db, &model.Waybill{}, map[string]interface{}{
|
||||
"CourierMobile": courierNumberMap[vendorOrderID].PhoneNumber,
|
||||
}, map[string]interface{}{
|
||||
"VendorWaybillID": vendorOrderID,
|
||||
"WaybillVendorID": model.VendorIDMTWM,
|
||||
})
|
||||
}
|
||||
return retVal, err
|
||||
}, orderList)
|
||||
tasksch.HandleTask(updateTask, task, true).Run()
|
||||
_, err = updateTask.GetResult(0)
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{0, 1, 2})
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
return response
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func (c *PurchaseHandler) onWaybillMsg(msg *mtwmapi.CallbackMsg) (response *mtwm
|
||||
msg.FormData.Set(mtwmapi.KeyOrderID, waybill.VendorOrderID)
|
||||
msg.FormData.Set("status", mtwmapi.OrderStatusDelivering)
|
||||
utils.CallFuncAsync(func() {
|
||||
OnOrderCallbackMsg(msg)
|
||||
c.onOrderMsg(msg)
|
||||
})
|
||||
}
|
||||
return mtwmapi.Err2CallbackResponse(err, "")
|
||||
|
||||
Reference in New Issue
Block a user