Files
jx-callback/business/partner/purchase/mtwm/waybill.go
2018-11-30 15:45:34 +08:00

50 lines
1.8 KiB
Go

package mtwm
import (
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/partner"
)
var (
VendorWaybillStatus2StatusMap = map[string]int{
mtwmapi.WaybillStatusWait4Delivery: model.WaybillStatusNew,
mtwmapi.WaybillStatusAccepted: model.WaybillStatusAccepted,
mtwmapi.WaybillStatusCourierArrived: model.WaybillStatusCourierArrived,
mtwmapi.WaybillStatusPickedup: model.WaybillStatusDelivering,
mtwmapi.WaybillStatusDelivered: model.WaybillStatusDelivered,
mtwmapi.WaybillStatusCanceled: model.WaybillStatusCanceled,
}
)
func (p *PurchaseHandler) GetWaybillStatusFromVendorStatus(vendorStatus string) int {
if status, ok := VendorWaybillStatus2StatusMap[vendorStatus]; ok {
return status
}
return model.WaybillStatusUnknown
}
func (c *PurchaseHandler) onWaybillMsg(msg *mtwmapi.CallbackMsg) (response *mtwmapi.CallbackResponse) {
waybill := c.callbackMsg2Waybill(msg)
return mtwmapi.Err2CallbackResponse(partner.CurOrderManager.OnWaybillStatusChanged(waybill), "")
}
func (c *PurchaseHandler) callbackMsg2Waybill(msg *mtwmapi.CallbackMsg) (retVal *model.Waybill) {
orderID := GetOrderIDFromMsg(msg)
vendorStatus := msg.Data.Get("logistics_status")
retVal = &model.Waybill{
VendorOrderID: orderID,
OrderVendorID: model.VendorIDMTWM,
VendorWaybillID: orderID,
WaybillVendorID: model.VendorIDMTWM,
CourierName: msg.Data.Get("dispatcher_name"),
CourierMobile: msg.Data.Get("dispatcher_mobile"),
VendorStatus: vendorStatus,
Status: c.GetWaybillStatusFromVendorStatus(vendorStatus),
StatusTime: getTimeFromTimestamp(utils.Str2Int64(msg.Data.Get("time"))),
Remark: "",
}
return retVal
}