- first compilable version of order handler.

This commit is contained in:
gazebo
2018-07-10 13:37:35 +08:00
parent 49ec11baf8
commit a76213e8f0
15 changed files with 1319 additions and 5 deletions

View File

@@ -0,0 +1,92 @@
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 {
controller.WaybillController
}
func (c *WaybillController) OnWaybillStatusMsg(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
controller.RoutinePool.CallFun(func() {
retVal = c.onWaybillStatusMsg(msg)
}, msg.OrderID)
return retVal
}
func (c *WaybillController) onWaybillStatusMsg(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
if msg.MsgType == elmapi.MsgTypeWaybillWait4DeliveryVendor {
retVal = c.onWaybillWait4DeliveryVendor(msg)
} else if msg.MsgType == elmapi.MsgTypeWaybillPickingUp {
retVal = c.onWaybillPickingUp(msg)
} else if msg.MsgType == elmapi.MsgTypeWaybillDelivering {
retVal = c.onWaybillDelivering(msg)
} else if msg.MsgType == elmapi.MsgTypeWaybillDelivered {
retVal = c.onWaybillDelivered(msg)
} else if msg.MsgType >= elmapi.MsgTypeWaybillCanceledByMerchant && msg.MsgType <= elmapi.MsgTypeWaybillCanceledBySystem {
retVal = c.onWaybillCanceled(msg)
} else if msg.MsgType >= elmapi.MsgTypeWaybillFailedCallLate &&
msg.MsgType <= elmapi.MsgTypeRejectedSystemError &&
msg.MsgType != elmapi.MsgTypeDeiverBySelf {
retVal = c.onWaybillFailed(msg)
} else {
// MsgTypeWait4Courier
// MsgTypeDeiverBySelf
retVal = c.onWaybillOtherStatus(msg)
}
return retVal
}
func (c *WaybillController) onWaybillWait4DeliveryVendor(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
order := &model.Waybill{
VendorOrderID: msg.OrderID,
VendorID: controller.VendorIDELM,
VendorWaybillID: msg.OrderID,
WaybillVendorID: controller.VendorIDELM,
CourierName: msg.Name,
CourierMobile: msg.Phone,
WaybillCreatedAt: utils.Timestamp2Time(msg.UpdateAt / 1000),
}
return elmapi.Err2CallbackResponse(c.OnWaybillNew(order), "elm onWaybillWait4DeliveryVendor")
}
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
}