- empty scheduler added.

This commit is contained in:
gazebo
2018-07-12 20:53:22 +08:00
parent 1c6ba2e43a
commit 52248ca427
13 changed files with 338 additions and 238 deletions

View File

@@ -12,13 +12,14 @@ import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/controller"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/scheduler"
)
type OrderController struct {
}
func init() {
controller.OrderManager.RegisterPurchasePlatform(controller.VendorIDJD, new(OrderController))
scheduler.CurrentScheduler.RegisterPurchasePlatform(model.VendorIDJD, new(OrderController))
}
func (c *OrderController) OnOrderStatusMsg(msg *elmapi.CallbackOrderStatusMsg) (retVal *elmapi.CallbackResponse) {
@@ -45,8 +46,8 @@ func (c *OrderController) OnOrderCancelRefundMsg(msg *elmapi.CallbackOrderCancel
func (c *OrderController) orderStatusMsg2Status(msg *elmapi.CallbackOrderStatusMsg) *model.OrderStatus {
orderStatus := &model.OrderStatus{
VendorOrderID: msg.OrderID,
VendorID: controller.VendorIDELM,
OrderType: controller.OrderTypeOrder,
VendorID: model.VendorIDELM,
OrderType: model.OrderTypeOrder,
VendorStatus: c.stateAndType2Str(msg.State, msg.MsgType),
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
}
@@ -56,8 +57,8 @@ func (c *OrderController) orderStatusMsg2Status(msg *elmapi.CallbackOrderStatusM
func (c *OrderController) cancelRefundMsg2Status(msg *elmapi.CallbackOrderCancelRefundMsg) *model.OrderStatus {
orderStatus := &model.OrderStatus{
VendorOrderID: msg.OrderID,
VendorID: controller.VendorIDELM,
OrderType: controller.OrderTypeOrder,
VendorID: model.VendorIDELM,
OrderType: model.OrderTypeOrder,
VendorStatus: utils.Int2Str(msg.MsgType),
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
}
@@ -68,11 +69,11 @@ func (c *OrderController) onOrderStatusMsg(msg *elmapi.CallbackOrderStatusMsg) (
status := c.orderStatusMsg2Status(msg)
switch msg.MsgType {
case elmapi.MsgTypeOrderAccepted:
status.Status = controller.OrderStatusAccepted
status.Status = model.OrderStatusAccepted
case elmapi.MsgTypeOrderCanceled, elmapi.MsgTypeOrderInvalid, elmapi.MsgTypeOrderForceInvalid:
status.Status = controller.OrderStatusCanceled
status.Status = model.OrderStatusCanceled
case elmapi.MsgTypeOrderFinished:
status.Status = controller.OrderStatusFinished
status.Status = model.OrderStatusFinished
default:
globals.SugarLogger.Warnf("elm msg:%d not handled", msg.MsgType)
return elmapi.SuccessResponse
@@ -84,11 +85,11 @@ func (c *OrderController) onOrderCancelRefundMsg(msg *elmapi.CallbackOrderCancel
status := c.cancelRefundMsg2Status(msg)
switch msg.MsgType {
case elmapi.MsgTypeUserApplyCancel:
status.Status = controller.OrderStatusApplyCancel
status.Status = model.OrderStatusApplyCancel
case elmapi.MsgTypeUserApplyRefund:
status.Status = controller.OrderStatusApplyRefund
status.Status = model.OrderStatusApplyRefund
default:
status.Status = controller.OrderStatusUnknown
status.Status = model.OrderStatusUnknown
}
return elmapi.Err2CallbackResponse(controller.OrderManager.OnOrderStatusChanged(status), status.VendorStatus)
}
@@ -105,7 +106,7 @@ func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (orde
// globals.SugarLogger.Debug(result)
order = &model.GoodsOrder{
VendorOrderID: msg.OrderID,
VendorID: controller.VendorIDELM,
VendorID: model.VendorIDELM,
VendorStoreID: utils.Int64ToStr(utils.MustInterface2Int64(result["shopId"])),
StoreID: int(utils.Str2Int64WithDefault(utils.Interface2String(result["openId"]), 0)),
StoreName: result["shopName"].(string),
@@ -118,7 +119,7 @@ func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (orde
}
deliveryGeo := strings.Split(utils.Interface2String(result["deliveryGeo"]), ",")
if len(deliveryGeo) == 2 {
order.CoordinateType = controller.CoordinateTypeMars
order.CoordinateType = model.CoordinateTypeMars
order.ConsigneeLng = controller.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[0]))
order.ConsigneeLat = controller.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[1]))
}
@@ -130,7 +131,7 @@ func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (orde
product := product2.(map[string]interface{})
sku := &model.OrderSku{
VendorOrderID: msg.OrderID,
VendorID: controller.VendorIDELM,
VendorID: model.VendorIDELM,
Count: int(utils.MustInterface2Int64(product["quantity"])),
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["extendCode"]), 0)),
VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])),
@@ -159,6 +160,7 @@ func (c *OrderController) onOrderNew(msg map[string]interface{}) (response *elma
}
order, orderSkus, err := c.getOrderInfo(fakeOrderMsg)
if err == nil {
order.Status = model.OrderStatusNew
err = controller.OrderManager.OnOrderNew(order, orderSkus)
}
return elmapi.Err2CallbackResponse(err, "elm onOrderNew")
@@ -167,24 +169,33 @@ func (c *OrderController) onOrderNew(msg map[string]interface{}) (response *elma
func (c *OrderController) onOrderUserUrgeOrder(msg *elmapi.CallbackOrderUrgeMsg) *elmapi.CallbackResponse {
status := &model.OrderStatus{
VendorOrderID: msg.OrderID,
VendorID: controller.VendorIDELM,
OrderType: controller.OrderTypeOrder,
Status: controller.OrderStatusApplyUrgeOrder,
VendorID: model.VendorIDELM,
OrderType: model.OrderTypeOrder,
Status: model.OrderStatusApplyUrgeOrder,
VendorStatus: utils.Int2Str(msg.MsgType),
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
}
return elmapi.Err2CallbackResponse(controller.OrderManager.OnOrderStatusChanged(status), status.VendorStatus)
}
// PurchasePlatformHandler
func (c *OrderController) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool) {
if isAcceptIt {
api.ElmAPI.ConfirmOrder(order.VendorOrderID)
} else {
api.ElmAPI.CancelOrder(order.VendorOrderID, elmapi.CancelOrderTypeOthers, "")
}
}
func (c *OrderController) stateAndType2Str(state string, msgType int) string {
return fmt.Sprintf("%s-%d", state, msgType)
}
// PurchasePlatformHandler
func (c *OrderController) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool) (err error) {
if isAcceptIt {
err = api.ElmAPI.ConfirmOrder(order.VendorOrderID)
} else {
err = api.ElmAPI.CancelOrder(order.VendorOrderID, elmapi.CancelOrderTypeOthers, "")
}
return err
}
func (c *OrderController) ForcePickUp(order *model.GoodsOrder) (err error) {
return nil
}
func (c *OrderController) SwtichSelfDeliver(order *model.GoodsOrder) (err error) {
return nil
}