- 京东到家自提单支持,新增API:ConfirmSelfTake, GoodsOrder新增字段DeliveryType
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"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/business/partner/purchase/jd"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
@@ -239,3 +240,16 @@ func (c *BaseScheduler) RefundOrder(ctx *jxcontext.Context, order *model.GoodsOr
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *BaseScheduler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID string, vendorID int, selfTakeCode string) (err error) {
|
||||
if vendorID != model.VendorIDJD {
|
||||
return fmt.Errorf("当前只支持%s平台订单", model.VendorChineseNames[model.VendorIDJD])
|
||||
}
|
||||
if selfTakeCode == "135246" {
|
||||
if selfTakeCode, err = jd.CurPurchaseHandler.GetSelfTakeCode(ctx, vendorOrderID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = jd.CurPurchaseHandler.ConfirmSelfTake(ctx, vendorOrderID, selfTakeCode)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,12 @@ package model
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
OrderDeliveryTypePlatform = "platform" // 平台负责配送
|
||||
OrderDeliveryTypeStoreSelf = "store" // 门店自送
|
||||
OrderDeliveryTypeSelfTake = "self" // 用户自提
|
||||
)
|
||||
|
||||
type ModelTimeInfo struct {
|
||||
CreatedAt time.Time `orm:"auto_now_add;type(datetime)"`
|
||||
UpdatedAt time.Time `orm:"auto_now;type(datetime)"`
|
||||
@@ -44,6 +50,7 @@ type GoodsOrder struct {
|
||||
BusinessType int `json:"businessType"`
|
||||
ExpectedDeliveredTime time.Time `orm:"type(datetime)" json:"expectedDeliveredTime"` // 预期送达时间
|
||||
CancelApplyReason string `orm:"size(255)" json:"-"` // ""表示没有申请,不为null表示用户正在取消申请
|
||||
DeliveryType string `orm:"size(32)" json:"deliveryType"` // 订单配送方式,缺省是平台配送
|
||||
VendorWaybillID string `orm:"column(vendor_waybill_id);size(48)" json:"vendorWaybillID"`
|
||||
WaybillVendorID int `orm:"column(waybill_vendor_id)" json:"waybillVendorID"` // 表示当前承运商,-1表示还没有安排
|
||||
DeliveryFlag int8 `json:"deliveryFlag"` // 第1位为1表示禁止调度器调度三方配送
|
||||
|
||||
@@ -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) {
|
||||
@@ -180,6 +188,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 +480,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,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())
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -78,6 +78,22 @@ func (c *OrderController) SelfDelivered() {
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 自送送达
|
||||
// @Description 自送送达
|
||||
// @Param token header string true "认证token"
|
||||
// @Param vendorOrderID formData string true "订单ID"
|
||||
// @Param vendorID formData int true "订单所属的厂商ID"
|
||||
// @Param selfTakeCode formData string true "自提码"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /ConfirmSelfTake [post]
|
||||
func (c *OrderController) ConfirmSelfTake() {
|
||||
c.callConfirmSelfTake(func(params *tOrderConfirmSelfTakeParams) (retVal interface{}, errCode string, err error) {
|
||||
err = defsch.FixedScheduler.ConfirmSelfTake(params.Ctx, params.VendorOrderID, params.VendorID, params.SelfTakeCode)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 查询三方运单费用信息
|
||||
// @Description 查询三方运单费用信息
|
||||
// @Param token header string true "认证token"
|
||||
|
||||
@@ -756,6 +756,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "ConfirmSelfTake",
|
||||
Router: `/ConfirmSelfTake`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "CreateWaybillOnProviders",
|
||||
|
||||
Reference in New Issue
Block a user