- big big refactor.
This commit is contained in:
@@ -10,83 +10,59 @@ import (
|
||||
)
|
||||
|
||||
type WaybillController struct {
|
||||
controller.WaybillController
|
||||
}
|
||||
|
||||
func init() {
|
||||
controller.WaybillManager.RegisterDeliveryProvider(controller.VendorIDELM, new(WaybillController))
|
||||
}
|
||||
|
||||
func (c *WaybillController) OnWaybillStatusMsg(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||
controller.RoutinePool.CallFun(func() {
|
||||
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 {
|
||||
retVal = c.onWaybillWait4DeliveryVendor(msg)
|
||||
order.Status = controller.WaybillStatusNew
|
||||
} else if msg.MsgType == elmapi.MsgTypeWaybillPickingUp {
|
||||
retVal = c.onWaybillPickingUp(msg)
|
||||
order.Status = controller.WaybillStatusAccepted
|
||||
} else if msg.MsgType == elmapi.MsgTypeWaybillCourierArrived {
|
||||
order.Status = controller.WaybillStatusCourierArrived
|
||||
} else if msg.MsgType == elmapi.MsgTypeWaybillDelivering {
|
||||
retVal = c.onWaybillDelivering(msg)
|
||||
order.Status = controller.WaybillStatusDelivering
|
||||
} else if msg.MsgType == elmapi.MsgTypeWaybillDelivered {
|
||||
retVal = c.onWaybillDelivered(msg)
|
||||
order.Status = controller.WaybillStatusDelivered
|
||||
} else if msg.MsgType >= elmapi.MsgTypeWaybillCanceledByMerchant && msg.MsgType <= elmapi.MsgTypeWaybillCanceledBySystem {
|
||||
retVal = c.onWaybillCanceled(msg)
|
||||
order.Status = controller.WaybillStatusCanceled
|
||||
} else if msg.MsgType >= elmapi.MsgTypeWaybillFailedCallLate &&
|
||||
msg.MsgType <= elmapi.MsgTypeRejectedSystemError &&
|
||||
msg.MsgType != elmapi.MsgTypeDeiverBySelf {
|
||||
retVal = c.onWaybillFailed(msg)
|
||||
order.Status = controller.WaybillStatusFailed
|
||||
} else {
|
||||
// MsgTypeWait4Courier
|
||||
// MsgTypeDeiverBySelf
|
||||
retVal = c.onWaybillOtherStatus(msg)
|
||||
order.Status = controller.WaybillStatusUnknown
|
||||
}
|
||||
return retVal
|
||||
return elmapi.Err2CallbackResponse(controller.WaybillManager.OnWaybillStatusChanged(order), order.VendorStatus)
|
||||
}
|
||||
|
||||
func (c *WaybillController) onWaybillWait4DeliveryVendor(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||
order := &model.Waybill{
|
||||
func (c *WaybillController) callbackMsg2Waybill(msg *elmapi.CallbackWaybillStatusMsg) (retVal *model.Waybill) {
|
||||
retVal = &model.Waybill{
|
||||
VendorOrderID: msg.OrderID,
|
||||
VendorID: controller.VendorIDELM,
|
||||
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 elmapi.Err2CallbackResponse(c.OnWaybillNew(order), "elm onWaybillWait4DeliveryVendor")
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (c *WaybillController) onWaybillPickingUp(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||
return elmapi.Err2CallbackResponse(c.OnWaybillAccepted(c.callbackMsg2Status(msg)), "elm onWaybillPickingUp")
|
||||
}
|
||||
|
||||
func (c *WaybillController) onWaybillDelivering(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||
return elmapi.Err2CallbackResponse(c.OnWaybillDelivering(c.callbackMsg2Status(msg)), "elm onWaybillDelivering")
|
||||
}
|
||||
|
||||
func (c *WaybillController) onWaybillDelivered(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||
return elmapi.Err2CallbackResponse(c.OnWaybillDelivered(c.callbackMsg2Status(msg)), "elm onWaybillDelivered")
|
||||
}
|
||||
|
||||
func (c *WaybillController) onWaybillCanceled(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||
return elmapi.Err2CallbackResponse(c.OnWaybillCanceled(c.callbackMsg2Status(msg)), "elm onWaybillCanceled")
|
||||
}
|
||||
|
||||
func (c *WaybillController) onWaybillFailed(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||
return elmapi.Err2CallbackResponse(c.OnWaybillFailed(c.callbackMsg2Status(msg)), "elm onWaybillFailed")
|
||||
}
|
||||
|
||||
func (c *WaybillController) onWaybillOtherStatus(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||
return elmapi.Err2CallbackResponse(c.OnWaybillOtherStatus(c.callbackMsg2Status(msg)), "elm onWaybillOtherStatus")
|
||||
}
|
||||
|
||||
func (c *WaybillController) callbackMsg2Status(msg *elmapi.CallbackWaybillStatusMsg) (retVal *model.OrderStatus) {
|
||||
status := &model.OrderStatus{
|
||||
VendorOrderID: msg.OrderID,
|
||||
VendorID: controller.VendorIDELM,
|
||||
OrderType: controller.OrderTypeWaybill,
|
||||
VendorStatus: fmt.Sprintf("%s-%s-%d", msg.State, msg.SubState, msg.MsgType),
|
||||
StatusTime: utils.Timestamp2Time(msg.UpdateAt / 1000),
|
||||
}
|
||||
return status
|
||||
func (c *WaybillController) composeState(state, subState string, msgType int) string {
|
||||
return fmt.Sprintf("%s-%s-%d", state, subState, msgType)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user