package elm import ( "fmt" "git.rosy.net.cn/baseapi/platformapi/elmapi" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/controller" "git.rosy.net.cn/jx-callback/business/model" ) type WaybillController struct { } func init() { controller.WaybillManager.RegisterDeliveryProvider(controller.VendorIDELM, new(WaybillController)) } func (c *WaybillController) OnWaybillStatusMsg(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) { controller.CallMsgHandler(func() { retVal = c.onWaybillStatusMsg(msg) }, msg.OrderID) return retVal } func (c *WaybillController) onWaybillStatusMsg(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) { order := c.callbackMsg2Waybill(msg) if msg.MsgType == elmapi.MsgTypeWaybillWait4DeliveryVendor { order.Status = controller.WaybillStatusNew } else if msg.MsgType == elmapi.MsgTypeWaybillPickingUp { order.Status = controller.WaybillStatusAccepted } else if msg.MsgType == elmapi.MsgTypeWaybillCourierArrived { order.Status = controller.WaybillStatusCourierArrived } else if msg.MsgType == elmapi.MsgTypeWaybillDelivering { order.Status = controller.WaybillStatusDelivering } else if msg.MsgType == elmapi.MsgTypeWaybillDelivered { order.Status = controller.WaybillStatusDelivered } else if msg.MsgType >= elmapi.MsgTypeWaybillCanceledByMerchant && msg.MsgType <= elmapi.MsgTypeWaybillCanceledBySystem { order.Status = controller.WaybillStatusCanceled } else if msg.MsgType >= elmapi.MsgTypeWaybillFailedCallLate && msg.MsgType <= elmapi.MsgTypeRejectedSystemError && msg.MsgType != elmapi.MsgTypeDeiverBySelf { order.Status = controller.WaybillStatusFailed } else { // MsgTypeWait4Courier // MsgTypeDeiverBySelf order.Status = controller.WaybillStatusUnknown } return elmapi.Err2CallbackResponse(controller.WaybillManager.OnWaybillStatusChanged(order), order.VendorStatus) } func (c *WaybillController) callbackMsg2Waybill(msg *elmapi.CallbackWaybillStatusMsg) (retVal *model.Waybill) { retVal = &model.Waybill{ VendorOrderID: msg.OrderID, OrderVendorID: controller.VendorIDELM, VendorWaybillID: msg.OrderID, WaybillVendorID: controller.VendorIDELM, CourierName: msg.Name, CourierMobile: msg.Phone, VendorStatus: c.composeState(msg.State, msg.SubState, elmapi.MsgTypeWaybillWait4DeliveryVendor), WaybillCreatedAt: utils.Timestamp2Time(msg.UpdateAt / 1000), } return retVal } func (c *WaybillController) composeState(state, subState string, msgType int) string { return fmt.Sprintf("%s-%s-%d", state, subState, msgType) }