Files
jx-callback/business/partner/purchase/jd/waybill.go
2018-08-17 16:42:16 +08:00

63 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package jd
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/model"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals/api"
)
func (c *PurchaseHandler) OnWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
jxutils.CallMsgHandler(func() {
retVal = c.onWaybillMsg(msg)
}, jxutils.ComposeUniversalOrderID(msg.OrderID, model.VendorIDJD))
return retVal
}
func (c *PurchaseHandler) onWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
order := c.callbackMsg2Waybill(msg)
switch msg.DeliveryStatus {
case jdapi.DeliveryStatusWait4Grap:
order.Status = model.WaybillStatusNew
case jdapi.DeliveryStatusAccepted:
if result, err := api.JdAPI.QuerySingleOrder(msg.OrderID); err == nil {
// 默认配送费=订单应付运费(orderReceivableFreight)
//订单应付运费为未优惠前应付运费(满免优惠运费优惠券VIP免基础运费用户小费)ps用户小费是用户给配送员的小费
order.DesiredFee = utils.Interface2Int64WithDefault(result["orderReceivableFreight"], 0) +
utils.Interface2Int64WithDefault(result["merchantPaymentDistanceFreightMoney"], 0) +
utils.Interface2Int64WithDefault(result["tips"], 0)
}
order.Status = model.WaybillStatusAccepted
case jdapi.DeliveryStatusCourierCanceled:
order.Status = model.WaybillStatusCanceled
case jdapi.DeliveryStatusCourierArrived:
order.Status = model.WaybillStatusCourierArrived
case jdapi.DeliveryStatusGotGoods:
order.Status = model.WaybillStatusDelivering
case jdapi.DeliveryStatusFinished:
order.Status = model.WaybillStatusDelivered
case jdapi.DeliveryStatusFailedDelivery, jdapi.DeliveryStatusFailedGetGoods:
order.Status = model.WaybillStatusFailed
default:
order.Status = model.WaybillStatusUnknown
}
return jdapi.Err2CallbackResponse(partner.CurOrderManager.OnWaybillStatusChanged(order), order.VendorStatus)
}
func (c *PurchaseHandler) callbackMsg2Waybill(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *model.Waybill) {
retVal = &model.Waybill{
VendorOrderID: msg.OrderID,
OrderVendorID: model.VendorIDJD,
VendorWaybillID: msg.OrderID,
WaybillVendorID: model.VendorIDJD,
CourierName: msg.DeliveryManName,
CourierMobile: msg.DeliveryManPhone,
VendorStatus: msg.DeliveryStatus,
StatusTime: utils.Str2Time(msg.DeliveryStatusTime),
Remark: msg.Remark,
}
return retVal
}