- big big refactor.
This commit is contained in:
@@ -6,6 +6,10 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/orm"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/baseapi/utils/routinepool"
|
"git.rosy.net.cn/baseapi/utils/routinepool"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
@@ -13,12 +17,16 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
VenderIDUnknown = -1
|
VenderIDUnknown = -1
|
||||||
|
VendorIDPurchaseBegin = 0
|
||||||
VendorIDJD = 0
|
VendorIDJD = 0
|
||||||
VendorIDMTWM = 1
|
VendorIDMTWM = 1
|
||||||
VendorIDELM = 2
|
VendorIDELM = 2
|
||||||
|
VendorIDPurchaseEnd = 2
|
||||||
|
|
||||||
|
VendorIDDeliveryBegin = 101
|
||||||
VendorIDDada = 101
|
VendorIDDada = 101
|
||||||
VendorIDMTPS = 102
|
VendorIDMTPS = 102
|
||||||
|
VendorIDDeliveryEnd = 102
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -26,18 +34,33 @@ const (
|
|||||||
OrderTypeWaybill = 2
|
OrderTypeWaybill = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
CoordinateTypeMars = 0 // 火星坐标
|
||||||
|
CoordinateTypeReal = 1 // 真实坐标
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultOrderCacheTimeout = 24 * time.Hour
|
DefaultOrderCacheTimeout = 24 * time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
RoutinePool *routinepool.Pool
|
DefaultTimeValue = utils.Str2Time("1970-01-01 00:00:00")
|
||||||
|
OrderManager *OrderController
|
||||||
|
WaybillManager *WaybillController
|
||||||
|
|
||||||
|
routinePool *routinepool.Pool
|
||||||
)
|
)
|
||||||
|
|
||||||
type SyncMapWithTimeout struct {
|
type SyncMapWithTimeout struct {
|
||||||
sync.Map
|
sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
routinePool = routinepool.New(1000, 1000)
|
||||||
|
OrderManager = NewOrderManager()
|
||||||
|
WaybillManager = NewWaybillManager()
|
||||||
|
}
|
||||||
|
|
||||||
func (m *SyncMapWithTimeout) StoreWithTimeout(key, value interface{}, timeout time.Duration) {
|
func (m *SyncMapWithTimeout) StoreWithTimeout(key, value interface{}, timeout time.Duration) {
|
||||||
m.Map.Store(key, value)
|
m.Map.Store(key, value)
|
||||||
time.AfterFunc(timeout, func() {
|
time.AfterFunc(timeout, func() {
|
||||||
@@ -49,26 +72,61 @@ func (m *SyncMapWithTimeout) Store(key, value interface{}) {
|
|||||||
m.StoreWithTimeout(key, value, DefaultOrderCacheTimeout)
|
m.StoreWithTimeout(key, value, DefaultOrderCacheTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetVendorIDFromUniversalOrderID(orderID string) (vendorID int) {
|
func SplitUniversalOrderID(universalOrderID string) (orderID string, vendorID int) {
|
||||||
index := strings.Index(orderID, "|")
|
index := strings.Index(universalOrderID, "|")
|
||||||
if index != -1 {
|
if index != -1 {
|
||||||
vendorID = int(utils.Str2Int64(orderID[index:]))
|
orderID = universalOrderID[:index]
|
||||||
|
vendorID = int(utils.Str2Int64(universalOrderID[index:]))
|
||||||
} else {
|
} else {
|
||||||
// 800402581000221 jd order
|
// 800402581000221 jd order
|
||||||
// 3022716176275221584 elm order
|
// 3022716176275221584 elm order
|
||||||
orderIDLen := len(orderID)
|
orderIDLen := len(universalOrderID)
|
||||||
if orderIDLen == len("800402581000221") {
|
if orderIDLen == len("800402581000221") {
|
||||||
vendorID = VendorIDJD
|
vendorID = VendorIDJD
|
||||||
} else if orderIDLen == len("3022716176275221584") {
|
} else if orderIDLen == len("3022716176275221584") {
|
||||||
vendorID = VendorIDELM
|
vendorID = VendorIDELM
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Errorf("unkown order type:%v", orderID)
|
globals.SugarLogger.Errorf("unkown order type:%v", universalOrderID)
|
||||||
vendorID = VenderIDUnknown
|
vendorID = VenderIDUnknown
|
||||||
}
|
}
|
||||||
|
orderID = universalOrderID
|
||||||
}
|
}
|
||||||
return vendorID
|
return orderID, vendorID
|
||||||
}
|
}
|
||||||
|
|
||||||
func ComposeUniversalOrderID(orderID string, vendorID int) string {
|
func ComposeUniversalOrderID(orderID string, vendorID int) string {
|
||||||
return fmt.Sprintf("%s|%d", orderID, vendorID)
|
return fmt.Sprintf("%s|%d", orderID, vendorID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StandardCoordinate2Int(value float64) int {
|
||||||
|
return int(value * 1000000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IntCoordinate2Standard(value int) float64 {
|
||||||
|
return float64(value / 1000000)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addOrderOrWaybillStatus(status *model.OrderStatus, db orm.Ormer) (isDuplicated bool, err error) {
|
||||||
|
status.ID = 0
|
||||||
|
created, _, err := db.ReadOrCreate(status, "VendorOrderID", "VendorID", "OrderType", "VendorStatus", "StatusTime")
|
||||||
|
if err == nil {
|
||||||
|
if !created {
|
||||||
|
isDuplicated = true
|
||||||
|
status.DuplicatedCount++
|
||||||
|
_, err = db.Update(status, "DuplicatedCount")
|
||||||
|
globals.SugarLogger.Infof("duplicated event:%v", status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
// todo 这里居然会有主键重复错误,逻辑上是不应该的
|
||||||
|
globals.SugarLogger.Warnf("access db error:%v", err)
|
||||||
|
}
|
||||||
|
return isDuplicated, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func CallMsgHandler(handler func(), primaryID string) {
|
||||||
|
handler()
|
||||||
|
// controller.routinePool.CallFun(func() {
|
||||||
|
// handler()
|
||||||
|
// }, primaryID)
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,80 +8,49 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type WaybillController struct {
|
type WaybillController struct {
|
||||||
controller.WaybillController
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
controller.OrderManager.RegisterDeliveryPlatform(controller.VendorIDDada, new(WaybillController))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) OnWaybillMsg(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
func (c *WaybillController) OnWaybillMsg(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
||||||
controller.RoutinePool.CallFun(func() {
|
controller.CallMsgHandler(func() {
|
||||||
retVal = c.onWaybillMsg(msg)
|
retVal = c.onWaybillMsg(msg)
|
||||||
}, msg.OrderID)
|
}, msg.OrderID)
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) callbackMsg2Status(msg *dadaapi.CallbackMsg) *model.OrderStatus {
|
|
||||||
orderStatus := &model.OrderStatus{
|
|
||||||
VendorOrderID: msg.ClientID,
|
|
||||||
VendorID: controller.VendorIDDada,
|
|
||||||
OrderType: controller.OrderTypeWaybill,
|
|
||||||
VendorStatus: utils.Int2Str(msg.OrderStatus),
|
|
||||||
StatusTime: utils.Timestamp2Time(int64(msg.UpdateTime)),
|
|
||||||
}
|
|
||||||
return orderStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillMsg(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
func (c *WaybillController) onWaybillMsg(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
||||||
|
order := c.callbackMsg2Waybill(msg)
|
||||||
switch msg.OrderStatus {
|
switch msg.OrderStatus {
|
||||||
case dadaapi.OrderStatusWaitingForAccept:
|
case dadaapi.OrderStatusWaitingForAccept:
|
||||||
retVal = c.onWaybillNew(msg)
|
order.Status = controller.WaybillStatusNew
|
||||||
case dadaapi.OrderStatusAccepted:
|
case dadaapi.OrderStatusAccepted:
|
||||||
retVal = c.onWaybillAccepted(msg)
|
order.Status = controller.WaybillStatusAccepted
|
||||||
case dadaapi.OrderStatusDeliverying:
|
case dadaapi.OrderStatusDeliverying:
|
||||||
retVal = c.onWaybillDelivering(msg)
|
order.Status = controller.WaybillStatusDelivering
|
||||||
case dadaapi.OrderStatusFinished:
|
case dadaapi.OrderStatusFinished:
|
||||||
retVal = c.onWaybillDelivered(msg)
|
order.Status = controller.WaybillStatusDelivered
|
||||||
case dadaapi.OrderStatusCanceled:
|
case dadaapi.OrderStatusCanceled:
|
||||||
retVal = c.onWaybillCanceled(msg)
|
order.Status = controller.WaybillStatusCanceled
|
||||||
case dadaapi.OrderStatusExpired, dadaapi.OrderStatusAddOrderFailed:
|
case dadaapi.OrderStatusExpired, dadaapi.OrderStatusAddOrderFailed:
|
||||||
retVal = c.onWaybillFailed(msg)
|
order.Status = controller.WaybillStatusFailed
|
||||||
default:
|
default:
|
||||||
retVal = c.onWaybillOtherStatus(msg)
|
order.Status = controller.WaybillStatusUnknown
|
||||||
}
|
}
|
||||||
return retVal
|
return dadaapi.Err2CallbackResponse(controller.WaybillManager.OnWaybillStatusChanged(order), utils.Int2Str(order.Status))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillNew(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
func (c *WaybillController) callbackMsg2Waybill(msg *dadaapi.CallbackMsg) (retVal *model.Waybill) {
|
||||||
order := &model.Waybill{
|
retVal = &model.Waybill{
|
||||||
VendorOrderID: msg.OrderID,
|
|
||||||
VendorID: controller.GetVendorIDFromUniversalOrderID(msg.OrderID),
|
|
||||||
VendorWaybillID: msg.ClientID,
|
VendorWaybillID: msg.ClientID,
|
||||||
WaybillVendorID: controller.VendorIDDada,
|
WaybillVendorID: controller.VendorIDDada,
|
||||||
CourierName: msg.DmName,
|
CourierName: msg.DmName,
|
||||||
CourierMobile: msg.DmMobile,
|
CourierMobile: msg.DmMobile,
|
||||||
|
VendorStatus: utils.Int2Str(msg.OrderStatus),
|
||||||
WaybillCreatedAt: utils.Timestamp2Time(int64(msg.UpdateTime)),
|
WaybillCreatedAt: utils.Timestamp2Time(int64(msg.UpdateTime)),
|
||||||
}
|
}
|
||||||
return dadaapi.Err2CallbackResponse(c.OnWaybillNew(order), "dada onWaybillNew")
|
retVal.VendorOrderID, retVal.OrderVendorID = controller.SplitUniversalOrderID(msg.OrderID)
|
||||||
}
|
return retVal
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillAccepted(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
|
||||||
return dadaapi.Err2CallbackResponse(c.OnWaybillAccepted(c.callbackMsg2Status(msg)), "dada onWaybillAccepted")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillDelivering(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
|
||||||
return dadaapi.Err2CallbackResponse(c.OnWaybillDelivering(c.callbackMsg2Status(msg)), "dada onWaybillDelivering")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillDelivered(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
|
||||||
return dadaapi.Err2CallbackResponse(c.OnWaybillDelivered(c.callbackMsg2Status(msg)), "dada onWaybillDelivered")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillCanceled(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
|
||||||
return dadaapi.Err2CallbackResponse(c.OnWaybillCanceled(c.callbackMsg2Status(msg)), "dada onWaybillCanceled")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillFailed(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
|
||||||
return dadaapi.Err2CallbackResponse(c.OnWaybillFailed(c.callbackMsg2Status(msg)), "dada onWaybillFailed")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillOtherStatus(msg *dadaapi.CallbackMsg) (retVal *dadaapi.CallbackResponse) {
|
|
||||||
return dadaapi.Err2CallbackResponse(c.OnWaybillOtherStatus(c.callbackMsg2Status(msg)), "dada onWaybillOtherStatus")
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (c *Controller) OnCallbackMsg(msg *elmapi.CallbackMsg) (retVal *elmapi.Call
|
|||||||
retVal = elmapi.Err2CallbackResponse(err, "")
|
retVal = elmapi.Err2CallbackResponse(err, "")
|
||||||
} else {
|
} else {
|
||||||
innerMsg.MsgType = msg.Type
|
innerMsg.MsgType = msg.Type
|
||||||
controller.RoutinePool.CallFun(func() {
|
controller.CallMsgHandler(func() {
|
||||||
retVal = new(OrderController).onOrderUserUrgeOrder(&innerMsg)
|
retVal = new(OrderController).onOrderUserUrgeOrder(&innerMsg)
|
||||||
}, innerMsg.OrderID)
|
}, innerMsg.OrderID)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package elm
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
@@ -14,25 +15,28 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type OrderController struct {
|
type OrderController struct {
|
||||||
controller.OrderController
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
controller.OrderManager.RegisterPurchasePlatform(controller.VendorIDJD, new(OrderController))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) OnOrderStatusMsg(msg *elmapi.CallbackOrderStatusMsg) (retVal *elmapi.CallbackResponse) {
|
func (c *OrderController) OnOrderStatusMsg(msg *elmapi.CallbackOrderStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||||
controller.RoutinePool.CallFun(func() {
|
controller.CallMsgHandler(func() {
|
||||||
retVal = c.onOrderStatusMsg(msg)
|
retVal = c.onOrderStatusMsg(msg)
|
||||||
}, msg.OrderID)
|
}, msg.OrderID)
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) OnOrderNewMsg(msg map[string]interface{}) (retVal *elmapi.CallbackResponse) {
|
func (c *OrderController) OnOrderNewMsg(msg map[string]interface{}) (retVal *elmapi.CallbackResponse) {
|
||||||
controller.RoutinePool.CallFun(func() {
|
controller.CallMsgHandler(func() {
|
||||||
retVal = c.onOrderNew(msg)
|
retVal = c.onOrderNew(msg)
|
||||||
}, msg["orderId"].(string))
|
}, msg["orderId"].(string))
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) OnOrderCancelRefundMsg(msg *elmapi.CallbackOrderCancelRefundMsg) (retVal *elmapi.CallbackResponse) {
|
func (c *OrderController) OnOrderCancelRefundMsg(msg *elmapi.CallbackOrderCancelRefundMsg) (retVal *elmapi.CallbackResponse) {
|
||||||
controller.RoutinePool.CallFun(func() {
|
controller.CallMsgHandler(func() {
|
||||||
retVal = c.onOrderCancelRefundMsg(msg)
|
retVal = c.onOrderCancelRefundMsg(msg)
|
||||||
}, msg.OrderID)
|
}, msg.OrderID)
|
||||||
return retVal
|
return retVal
|
||||||
@@ -43,7 +47,7 @@ func (c *OrderController) orderStatusMsg2Status(msg *elmapi.CallbackOrderStatusM
|
|||||||
VendorOrderID: msg.OrderID,
|
VendorOrderID: msg.OrderID,
|
||||||
VendorID: controller.VendorIDELM,
|
VendorID: controller.VendorIDELM,
|
||||||
OrderType: controller.OrderTypeOrder,
|
OrderType: controller.OrderTypeOrder,
|
||||||
VendorStatus: fmt.Sprintf("%s-%d", msg.State, msg.MsgType),
|
VendorStatus: c.stateAndType2Str(msg.State, msg.MsgType),
|
||||||
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
|
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
|
||||||
}
|
}
|
||||||
return orderStatus
|
return orderStatus
|
||||||
@@ -54,7 +58,6 @@ func (c *OrderController) cancelRefundMsg2Status(msg *elmapi.CallbackOrderCancel
|
|||||||
VendorOrderID: msg.OrderID,
|
VendorOrderID: msg.OrderID,
|
||||||
VendorID: controller.VendorIDELM,
|
VendorID: controller.VendorIDELM,
|
||||||
OrderType: controller.OrderTypeOrder,
|
OrderType: controller.OrderTypeOrder,
|
||||||
Status: controller.OrderStatusEvent,
|
|
||||||
VendorStatus: utils.Int2Str(msg.MsgType),
|
VendorStatus: utils.Int2Str(msg.MsgType),
|
||||||
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
|
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
|
||||||
}
|
}
|
||||||
@@ -62,34 +65,32 @@ func (c *OrderController) cancelRefundMsg2Status(msg *elmapi.CallbackOrderCancel
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) onOrderStatusMsg(msg *elmapi.CallbackOrderStatusMsg) (retVal *elmapi.CallbackResponse) {
|
func (c *OrderController) onOrderStatusMsg(msg *elmapi.CallbackOrderStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||||
|
status := c.orderStatusMsg2Status(msg)
|
||||||
switch msg.MsgType {
|
switch msg.MsgType {
|
||||||
case elmapi.MsgTypeOrderAccepted:
|
case elmapi.MsgTypeOrderAccepted:
|
||||||
retVal = c.onOrderAccepted(msg)
|
status.Status = controller.OrderStatusAccepted
|
||||||
case elmapi.MsgTypeOrderCanceled:
|
case elmapi.MsgTypeOrderCanceled, elmapi.MsgTypeOrderInvalid, elmapi.MsgTypeOrderForceInvalid:
|
||||||
retVal = c.onOrderCanceled(msg)
|
status.Status = controller.OrderStatusCanceled
|
||||||
case elmapi.MsgTypeOrderInvalid:
|
|
||||||
retVal = c.onOrderInvalid(msg)
|
|
||||||
case elmapi.MsgTypeOrderForceInvalid:
|
|
||||||
retVal = c.onOrderForceInvalid(msg)
|
|
||||||
case elmapi.MsgTypeOrderFinished:
|
case elmapi.MsgTypeOrderFinished:
|
||||||
retVal = c.onOrderFinished(msg)
|
status.Status = controller.OrderStatusFinished
|
||||||
default:
|
default:
|
||||||
globals.SugarLogger.Warnf("elm msg:%d not handled", msg.MsgType)
|
globals.SugarLogger.Warnf("elm msg:%d not handled", msg.MsgType)
|
||||||
retVal = elmapi.SuccessResponse
|
return elmapi.SuccessResponse
|
||||||
}
|
}
|
||||||
return retVal
|
return elmapi.Err2CallbackResponse(controller.OrderManager.OnOrderStatusChanged(status), status.VendorStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) onOrderCancelRefundMsg(msg *elmapi.CallbackOrderCancelRefundMsg) (retVal *elmapi.CallbackResponse) {
|
func (c *OrderController) onOrderCancelRefundMsg(msg *elmapi.CallbackOrderCancelRefundMsg) (retVal *elmapi.CallbackResponse) {
|
||||||
|
status := c.cancelRefundMsg2Status(msg)
|
||||||
switch msg.MsgType {
|
switch msg.MsgType {
|
||||||
case elmapi.MsgTypeUserApplyCancel:
|
case elmapi.MsgTypeUserApplyCancel:
|
||||||
retVal = c.onOrderUserApplyCancel(msg)
|
status.Status = controller.OrderStatusApplyCancel
|
||||||
case elmapi.MsgTypeUserApplyRefund:
|
case elmapi.MsgTypeUserApplyRefund:
|
||||||
retVal = c.onOrderUserApplyRefund(msg)
|
status.Status = controller.OrderStatusApplyRefund
|
||||||
default:
|
default:
|
||||||
retVal = c.onOrderOtherCancelRefundStatus(msg)
|
status.Status = controller.OrderStatusUnknown
|
||||||
}
|
}
|
||||||
return retVal
|
return elmapi.Err2CallbackResponse(controller.OrderManager.OnOrderStatusChanged(status), status.VendorStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (order *model.GoodsOrder, orderSkus []*model.OrderSku, err error) {
|
func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (order *model.GoodsOrder, orderSkus []*model.OrderSku, err error) {
|
||||||
@@ -100,6 +101,7 @@ func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (orde
|
|||||||
if len(phoneList) > 0 {
|
if len(phoneList) > 0 {
|
||||||
consigneeMobile = phoneList[0].(string)
|
consigneeMobile = phoneList[0].(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// globals.SugarLogger.Debug(result)
|
// globals.SugarLogger.Debug(result)
|
||||||
order = &model.GoodsOrder{
|
order = &model.GoodsOrder{
|
||||||
VendorOrderID: msg.OrderID,
|
VendorOrderID: msg.OrderID,
|
||||||
@@ -109,10 +111,17 @@ func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (orde
|
|||||||
StoreName: result["shopName"].(string),
|
StoreName: result["shopName"].(string),
|
||||||
ConsigneeName: result["consignee"].(string),
|
ConsigneeName: result["consignee"].(string),
|
||||||
ConsigneeMobile: consigneeMobile,
|
ConsigneeMobile: consigneeMobile,
|
||||||
|
ConsigneeAddress: result["address"].(string),
|
||||||
VendorStatus: msg.State,
|
VendorStatus: msg.State,
|
||||||
OrderCreatedAt: utils.Str2Time(result["createdAt"].(string)),
|
OrderCreatedAt: utils.Str2Time(result["createdAt"].(string)),
|
||||||
OriginalData: string(utils.MustMarshal(result)),
|
OriginalData: string(utils.MustMarshal(result)),
|
||||||
}
|
}
|
||||||
|
deliveryGeo := strings.Split(utils.Interface2String(result["deliveryGeo"]), ",")
|
||||||
|
if len(deliveryGeo) == 2 {
|
||||||
|
order.CoordinateType = controller.CoordinateTypeMars
|
||||||
|
order.ConsigneeLng = controller.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[0]))
|
||||||
|
order.ConsigneeLat = controller.StandardCoordinate2Int(utils.Str2Float64(deliveryGeo[1]))
|
||||||
|
}
|
||||||
|
|
||||||
orderSkus = []*model.OrderSku{}
|
orderSkus = []*model.OrderSku{}
|
||||||
for _, group2 := range result["groups"].([]interface{}) {
|
for _, group2 := range result["groups"].([]interface{}) {
|
||||||
@@ -121,21 +130,23 @@ func (c *OrderController) getOrderInfo(msg *elmapi.CallbackOrderStatusMsg) (orde
|
|||||||
product := product2.(map[string]interface{})
|
product := product2.(map[string]interface{})
|
||||||
sku := &model.OrderSku{
|
sku := &model.OrderSku{
|
||||||
VendorOrderID: msg.OrderID,
|
VendorOrderID: msg.OrderID,
|
||||||
VendorID: controller.VendorIDJD,
|
VendorID: controller.VendorIDELM,
|
||||||
Count: int(utils.MustInterface2Int64(product["quantity"])),
|
Count: int(utils.MustInterface2Int64(product["quantity"])),
|
||||||
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["extendCode"]), 0)),
|
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["extendCode"]), 0)),
|
||||||
VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])),
|
VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])),
|
||||||
SkuName: product["name"].(string),
|
SkuName: product["name"].(string),
|
||||||
SalePrice: int64(math.Round(utils.MustInterface2Float64(product["userPrice"]) * 100)),
|
SalePrice: int64(math.Round(utils.MustInterface2Float64(product["userPrice"]) * 100)),
|
||||||
|
Weight: int(math.Round(utils.Interface2Float64(product["weight"]))),
|
||||||
OrderCreatedAt: order.OrderCreatedAt,
|
OrderCreatedAt: order.OrderCreatedAt,
|
||||||
}
|
}
|
||||||
orderSkus = append(orderSkus, sku)
|
orderSkus = append(orderSkus, sku)
|
||||||
order.SkuCount++
|
order.SkuCount++
|
||||||
|
order.GoodsCount += sku.Count
|
||||||
order.SalePrice += sku.SalePrice
|
order.SalePrice += sku.SalePrice
|
||||||
|
order.Weight += sku.Weight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return order, orderSkus, err
|
return order, orderSkus, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,63 +155,25 @@ func (c *OrderController) onOrderNew(msg map[string]interface{}) (response *elma
|
|||||||
// todo 这里应该可以直接用msg里的内容,而不用再次去查
|
// todo 这里应该可以直接用msg里的内容,而不用再次去查
|
||||||
fakeOrderMsg := &elmapi.CallbackOrderStatusMsg{
|
fakeOrderMsg := &elmapi.CallbackOrderStatusMsg{
|
||||||
OrderID: msg["orderId"].(string),
|
OrderID: msg["orderId"].(string),
|
||||||
State: elmapi.OrderStatusFake,
|
State: c.stateAndType2Str(msg["status"].(string), elmapi.MsgTypeOrderValid),
|
||||||
}
|
}
|
||||||
order, orderSkus, err := c.getOrderInfo(fakeOrderMsg)
|
order, orderSkus, err := c.getOrderInfo(fakeOrderMsg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = c.OnOrderNew(c, order, orderSkus)
|
err = controller.OrderManager.OnOrderNew(order, orderSkus)
|
||||||
}
|
}
|
||||||
return elmapi.Err2CallbackResponse(err, "elm onOrderNew")
|
return elmapi.Err2CallbackResponse(err, "elm onOrderNew")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) onOrderAccepted(msg *elmapi.CallbackOrderStatusMsg) *elmapi.CallbackResponse {
|
|
||||||
status := c.orderStatusMsg2Status(msg)
|
|
||||||
err := c.OnOrderAccepted(c, status)
|
|
||||||
if err == nil {
|
|
||||||
status.VendorStatus = "fakeautopickup"
|
|
||||||
err = c.OnOrderFinishedPickup(c, c.orderStatusMsg2Status(msg))
|
|
||||||
}
|
|
||||||
return elmapi.Err2CallbackResponse(err, "elm onOrderAccepted")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderCanceled(msg *elmapi.CallbackOrderStatusMsg) *elmapi.CallbackResponse {
|
|
||||||
return elmapi.Err2CallbackResponse(c.OnOrderCanceled(c, c.orderStatusMsg2Status(msg)), "elm onOrderCanceled")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderInvalid(msg *elmapi.CallbackOrderStatusMsg) *elmapi.CallbackResponse {
|
|
||||||
return c.onOrderCanceled(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderForceInvalid(msg *elmapi.CallbackOrderStatusMsg) *elmapi.CallbackResponse {
|
|
||||||
return c.onOrderCanceled(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderFinished(msg *elmapi.CallbackOrderStatusMsg) *elmapi.CallbackResponse {
|
|
||||||
return elmapi.Err2CallbackResponse(c.OnOrderDelivered(c, c.orderStatusMsg2Status(msg)), "elm onOrderFinished")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderUserUrgeOrder(msg *elmapi.CallbackOrderUrgeMsg) *elmapi.CallbackResponse {
|
func (c *OrderController) onOrderUserUrgeOrder(msg *elmapi.CallbackOrderUrgeMsg) *elmapi.CallbackResponse {
|
||||||
orderStatus := &model.OrderStatus{
|
status := &model.OrderStatus{
|
||||||
VendorOrderID: msg.OrderID,
|
VendorOrderID: msg.OrderID,
|
||||||
VendorID: controller.VendorIDELM,
|
VendorID: controller.VendorIDELM,
|
||||||
OrderType: controller.OrderTypeOrder,
|
OrderType: controller.OrderTypeOrder,
|
||||||
Status: controller.OrderStatusEvent,
|
Status: controller.OrderStatusApplyUrgeOrder,
|
||||||
VendorStatus: utils.Int2Str(msg.MsgType),
|
VendorStatus: utils.Int2Str(msg.MsgType),
|
||||||
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
|
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
|
||||||
}
|
}
|
||||||
return elmapi.Err2CallbackResponse(c.OnOrderUserUrgeOrder(c, orderStatus), "elm onOrderUserUrgeOrder")
|
return elmapi.Err2CallbackResponse(controller.OrderManager.OnOrderStatusChanged(status), status.VendorStatus)
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderUserApplyCancel(msg *elmapi.CallbackOrderCancelRefundMsg) *elmapi.CallbackResponse {
|
|
||||||
return elmapi.Err2CallbackResponse(c.OnOrderUserApplyCancel(c, c.cancelRefundMsg2Status(msg)), "elm onOrderUserApplyCancel")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderUserApplyRefund(msg *elmapi.CallbackOrderCancelRefundMsg) *elmapi.CallbackResponse {
|
|
||||||
return elmapi.Err2CallbackResponse(c.OnOrderUserApplyRefund(c, c.cancelRefundMsg2Status(msg)), "elm onOrderUserApplyRefund")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderOtherCancelRefundStatus(msg *elmapi.CallbackOrderCancelRefundMsg) *elmapi.CallbackResponse {
|
|
||||||
return elmapi.Err2CallbackResponse(c.OnOrderOtherStatus(c, c.cancelRefundMsg2Status(msg)), "elm onOrderOtherCancelRefundStatus")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PurchasePlatformHandler
|
// PurchasePlatformHandler
|
||||||
@@ -211,3 +184,7 @@ func (c *OrderController) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptI
|
|||||||
api.ElmAPI.CancelOrder(order.VendorOrderID, elmapi.CancelOrderTypeOthers, "")
|
api.ElmAPI.CancelOrder(order.VendorOrderID, elmapi.CancelOrderTypeOthers, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *OrderController) stateAndType2Str(state string, msgType int) string {
|
||||||
|
return fmt.Sprintf("%s-%d", state, msgType)
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,83 +10,59 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type WaybillController struct {
|
type WaybillController struct {
|
||||||
controller.WaybillController
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
controller.WaybillManager.RegisterDeliveryProvider(controller.VendorIDELM, new(WaybillController))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) OnWaybillStatusMsg(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
func (c *WaybillController) OnWaybillStatusMsg(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||||
controller.RoutinePool.CallFun(func() {
|
controller.CallMsgHandler(func() {
|
||||||
retVal = c.onWaybillStatusMsg(msg)
|
retVal = c.onWaybillStatusMsg(msg)
|
||||||
}, msg.OrderID)
|
}, msg.OrderID)
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillStatusMsg(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
func (c *WaybillController) onWaybillStatusMsg(msg *elmapi.CallbackWaybillStatusMsg) (retVal *elmapi.CallbackResponse) {
|
||||||
|
order := c.callbackMsg2Waybill(msg)
|
||||||
if msg.MsgType == elmapi.MsgTypeWaybillWait4DeliveryVendor {
|
if msg.MsgType == elmapi.MsgTypeWaybillWait4DeliveryVendor {
|
||||||
retVal = c.onWaybillWait4DeliveryVendor(msg)
|
order.Status = controller.WaybillStatusNew
|
||||||
} else if msg.MsgType == elmapi.MsgTypeWaybillPickingUp {
|
} 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 {
|
} else if msg.MsgType == elmapi.MsgTypeWaybillDelivering {
|
||||||
retVal = c.onWaybillDelivering(msg)
|
order.Status = controller.WaybillStatusDelivering
|
||||||
} else if msg.MsgType == elmapi.MsgTypeWaybillDelivered {
|
} else if msg.MsgType == elmapi.MsgTypeWaybillDelivered {
|
||||||
retVal = c.onWaybillDelivered(msg)
|
order.Status = controller.WaybillStatusDelivered
|
||||||
} else if msg.MsgType >= elmapi.MsgTypeWaybillCanceledByMerchant && msg.MsgType <= elmapi.MsgTypeWaybillCanceledBySystem {
|
} else if msg.MsgType >= elmapi.MsgTypeWaybillCanceledByMerchant && msg.MsgType <= elmapi.MsgTypeWaybillCanceledBySystem {
|
||||||
retVal = c.onWaybillCanceled(msg)
|
order.Status = controller.WaybillStatusCanceled
|
||||||
} else if msg.MsgType >= elmapi.MsgTypeWaybillFailedCallLate &&
|
} else if msg.MsgType >= elmapi.MsgTypeWaybillFailedCallLate &&
|
||||||
msg.MsgType <= elmapi.MsgTypeRejectedSystemError &&
|
msg.MsgType <= elmapi.MsgTypeRejectedSystemError &&
|
||||||
msg.MsgType != elmapi.MsgTypeDeiverBySelf {
|
msg.MsgType != elmapi.MsgTypeDeiverBySelf {
|
||||||
retVal = c.onWaybillFailed(msg)
|
order.Status = controller.WaybillStatusFailed
|
||||||
} else {
|
} else {
|
||||||
// MsgTypeWait4Courier
|
// MsgTypeWait4Courier
|
||||||
// MsgTypeDeiverBySelf
|
// 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) {
|
func (c *WaybillController) callbackMsg2Waybill(msg *elmapi.CallbackWaybillStatusMsg) (retVal *model.Waybill) {
|
||||||
order := &model.Waybill{
|
retVal = &model.Waybill{
|
||||||
VendorOrderID: msg.OrderID,
|
VendorOrderID: msg.OrderID,
|
||||||
VendorID: controller.VendorIDELM,
|
OrderVendorID: controller.VendorIDELM,
|
||||||
VendorWaybillID: msg.OrderID,
|
VendorWaybillID: msg.OrderID,
|
||||||
WaybillVendorID: controller.VendorIDELM,
|
WaybillVendorID: controller.VendorIDELM,
|
||||||
CourierName: msg.Name,
|
CourierName: msg.Name,
|
||||||
CourierMobile: msg.Phone,
|
CourierMobile: msg.Phone,
|
||||||
|
VendorStatus: c.composeState(msg.State, msg.SubState, elmapi.MsgTypeWaybillWait4DeliveryVendor),
|
||||||
WaybillCreatedAt: utils.Timestamp2Time(msg.UpdateAt / 1000),
|
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) {
|
func (c *WaybillController) composeState(state, subState string, msgType int) string {
|
||||||
return elmapi.Err2CallbackResponse(c.OnWaybillAccepted(c.callbackMsg2Status(msg)), "elm onWaybillPickingUp")
|
return fmt.Sprintf("%s-%s-%d", state, subState, msgType)
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,47 +10,41 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type OrderController struct {
|
type OrderController struct {
|
||||||
controller.OrderController
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
controller.OrderManager.RegisterPurchasePlatform(controller.VendorIDELM, new(OrderController))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) OnOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
func (c *OrderController) OnOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||||
controller.RoutinePool.CallFun(func() {
|
controller.CallMsgHandler(func() {
|
||||||
retVal = c.onOrderMsg(msg)
|
retVal = c.onOrderMsg(msg)
|
||||||
}, msg.BillID)
|
}, msg.BillID)
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) callbackMsg2Status(msg *jdapi.CallbackOrderMsg) *model.OrderStatus {
|
|
||||||
orderStatus := &model.OrderStatus{
|
|
||||||
VendorOrderID: msg.BillID,
|
|
||||||
VendorID: controller.VendorIDJD,
|
|
||||||
OrderType: controller.OrderTypeOrder,
|
|
||||||
VendorStatus: msg.StatusID,
|
|
||||||
StatusTime: utils.Str2Time(msg.Timestamp),
|
|
||||||
}
|
|
||||||
return orderStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
func (c *OrderController) onOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.CallbackResponse) {
|
||||||
switch msg.StatusID {
|
if jdapi.OrderStatusNew == msg.StatusID || jdapi.OrderStatusAdjust == msg.StatusID {
|
||||||
case jdapi.OrderStatusNew:
|
|
||||||
retVal = c.onOrderNew(msg)
|
retVal = c.onOrderNew(msg)
|
||||||
case jdapi.OrderStatusAdjust:
|
} else {
|
||||||
retVal = c.onOrderAdjust(msg)
|
status := c.callbackMsg2Status(msg)
|
||||||
|
switch msg.StatusID {
|
||||||
case jdapi.OrderStatusWaitOutStore:
|
case jdapi.OrderStatusWaitOutStore:
|
||||||
retVal = c.onOrderWaitOutStore(msg)
|
status.Status = controller.OrderStatusAccepted
|
||||||
case jdapi.OrderStatusFinishedPickup:
|
case jdapi.OrderStatusFinishedPickup:
|
||||||
retVal = c.onOrderFinishedPickup(msg)
|
status.Status = controller.OrderStatusFinishedPickup
|
||||||
case jdapi.OrderStatusDelivering:
|
case jdapi.OrderStatusDelivering:
|
||||||
retVal = c.onOrderDelivering(msg)
|
status.Status = controller.OrderStatusDelivering
|
||||||
case jdapi.OrderStatusDelivered:
|
case jdapi.OrderStatusDelivered:
|
||||||
retVal = c.onOrderDelivered(msg)
|
status.Status = controller.OrderStatusDelivered
|
||||||
case jdapi.OrderStatusCanceled:
|
case jdapi.OrderStatusCanceled:
|
||||||
retVal = c.onOrderCanceled(msg)
|
status.Status = controller.OrderStatusCanceled
|
||||||
case jdapi.OrderStatusUserApplyCancel:
|
case jdapi.OrderStatusUserApplyCancel:
|
||||||
retVal = c.onOrderUserApplyCancel(msg)
|
status.Status = controller.OrderStatusApplyCancel
|
||||||
default:
|
default:
|
||||||
retVal = c.onOrderOtherStatus(msg)
|
status.Status = controller.OrderStatusUnknown
|
||||||
|
}
|
||||||
|
retVal = jdapi.Err2CallbackResponse(controller.OrderManager.OnOrderStatusChanged(status), status.VendorStatus)
|
||||||
}
|
}
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
@@ -67,6 +61,10 @@ func (c *OrderController) getOrderInfo(msg *jdapi.CallbackOrderMsg) (order *mode
|
|||||||
StoreName: result["produceStationName"].(string),
|
StoreName: result["produceStationName"].(string),
|
||||||
ConsigneeName: result["buyerFullName"].(string),
|
ConsigneeName: result["buyerFullName"].(string),
|
||||||
ConsigneeMobile: result["buyerMobile"].(string),
|
ConsigneeMobile: result["buyerMobile"].(string),
|
||||||
|
ConsigneeAddress: result["buyerFullAddress"].(string),
|
||||||
|
ConsigneeLat: controller.StandardCoordinate2Int(utils.MustInterface2Float64(result["buyerLat"])),
|
||||||
|
ConsigneeLng: controller.StandardCoordinate2Int(utils.MustInterface2Float64(result["buyerLng"])),
|
||||||
|
CoordinateType: controller.CoordinateTypeMars,
|
||||||
VendorStatus: msg.StatusID,
|
VendorStatus: msg.StatusID,
|
||||||
OrderCreatedAt: utils.Str2Time(result["orderPurchaseTime"].(string)),
|
OrderCreatedAt: utils.Str2Time(result["orderPurchaseTime"].(string)),
|
||||||
OriginalData: string(utils.MustMarshal(result)),
|
OriginalData: string(utils.MustMarshal(result)),
|
||||||
@@ -82,15 +80,17 @@ func (c *OrderController) getOrderInfo(msg *jdapi.CallbackOrderMsg) (order *mode
|
|||||||
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["skuIdIsv"]), 0)),
|
SkuID: int(utils.Str2Int64WithDefault(utils.Interface2String(product["skuIdIsv"]), 0)),
|
||||||
VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])),
|
VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])),
|
||||||
SkuName: product["skuName"].(string),
|
SkuName: product["skuName"].(string),
|
||||||
|
Weight: int(utils.MustInterface2Float64(product["skuWeight"]) * 1000),
|
||||||
SalePrice: utils.MustInterface2Int64(product["skuJdPrice"]),
|
SalePrice: utils.MustInterface2Int64(product["skuJdPrice"]),
|
||||||
OrderCreatedAt: order.OrderCreatedAt,
|
OrderCreatedAt: order.OrderCreatedAt,
|
||||||
}
|
}
|
||||||
orderSkus = append(orderSkus, sku)
|
orderSkus = append(orderSkus, sku)
|
||||||
order.SkuCount++
|
order.SkuCount++
|
||||||
|
order.GoodsCount += sku.Count
|
||||||
order.SalePrice += sku.SalePrice
|
order.SalePrice += sku.SalePrice
|
||||||
|
order.Weight += sku.Weight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return order, orderSkus, err
|
return order, orderSkus, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ func (c *OrderController) getOrderInfo(msg *jdapi.CallbackOrderMsg) (order *mode
|
|||||||
func (c *OrderController) onOrderNew(msg *jdapi.CallbackOrderMsg) (response *jdapi.CallbackResponse) {
|
func (c *OrderController) onOrderNew(msg *jdapi.CallbackOrderMsg) (response *jdapi.CallbackResponse) {
|
||||||
order, orderSkus, err := c.getOrderInfo(msg)
|
order, orderSkus, err := c.getOrderInfo(msg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = c.OnOrderNew(c, order, orderSkus)
|
err = controller.OrderManager.OnOrderNew(order, orderSkus)
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Debugf("get order error:%v", err)
|
globals.SugarLogger.Debugf("get order error:%v", err)
|
||||||
}
|
}
|
||||||
@@ -108,40 +108,23 @@ func (c *OrderController) onOrderNew(msg *jdapi.CallbackOrderMsg) (response *jda
|
|||||||
func (c *OrderController) onOrderAdjust(msg *jdapi.CallbackOrderMsg) *jdapi.CallbackResponse {
|
func (c *OrderController) onOrderAdjust(msg *jdapi.CallbackOrderMsg) *jdapi.CallbackResponse {
|
||||||
order, orderSkus, err := c.getOrderInfo(msg)
|
order, orderSkus, err := c.getOrderInfo(msg)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = c.OnOrderAdjust(c, order, orderSkus)
|
err = controller.OrderManager.OnOrderAdjust(order, orderSkus)
|
||||||
}
|
}
|
||||||
return jdapi.Err2CallbackResponse(err, "jd onOrderAdjust")
|
return jdapi.Err2CallbackResponse(err, "jd onOrderAdjust")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) onOrderWaitOutStore(msg *jdapi.CallbackOrderMsg) *jdapi.CallbackResponse {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnOrderAccepted(c, c.callbackMsg2Status(msg)), "jd onOrderWaitOutStore")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderFinishedPickup(msg *jdapi.CallbackOrderMsg) *jdapi.CallbackResponse {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnOrderFinishedPickup(c, c.callbackMsg2Status(msg)), "jd onOrderFinishedPickup")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderDelivering(msg *jdapi.CallbackOrderMsg) *jdapi.CallbackResponse {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnOrderDelivering(c, c.callbackMsg2Status(msg)), "jd onOrderDelivering")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderDelivered(msg *jdapi.CallbackOrderMsg) *jdapi.CallbackResponse {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnOrderDelivered(c, c.callbackMsg2Status(msg)), "jd onOrderDelivered")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderCanceled(msg *jdapi.CallbackOrderMsg) *jdapi.CallbackResponse {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnOrderCanceled(c, c.callbackMsg2Status(msg)), "jd onOrderCanceled")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderUserApplyCancel(msg *jdapi.CallbackOrderMsg) *jdapi.CallbackResponse {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnOrderUserApplyCancel(c, c.callbackMsg2Status(msg)), "jd onOrderUserApplyCancel")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) onOrderOtherStatus(msg *jdapi.CallbackOrderMsg) *jdapi.CallbackResponse {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnOrderOtherStatus(c, c.callbackMsg2Status(msg)), "jd onOrderOtherStatus")
|
|
||||||
}
|
|
||||||
|
|
||||||
// PurchasePlatformHandler
|
// PurchasePlatformHandler
|
||||||
func (c *OrderController) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool) {
|
func (c *OrderController) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool) {
|
||||||
api.JdAPI.OrderAcceptOperate(order.VendorOrderID, isAcceptIt)
|
api.JdAPI.OrderAcceptOperate(order.VendorOrderID, isAcceptIt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *OrderController) callbackMsg2Status(msg *jdapi.CallbackOrderMsg) *model.OrderStatus {
|
||||||
|
orderStatus := &model.OrderStatus{
|
||||||
|
VendorOrderID: msg.BillID,
|
||||||
|
VendorID: controller.VendorIDJD,
|
||||||
|
OrderType: controller.OrderTypeOrder,
|
||||||
|
VendorStatus: msg.StatusID,
|
||||||
|
StatusTime: utils.Str2Time(msg.Timestamp),
|
||||||
|
}
|
||||||
|
return orderStatus
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,80 +8,52 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type WaybillController struct {
|
type WaybillController struct {
|
||||||
controller.WaybillController
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
controller.WaybillManager.RegisterDeliveryProvider(controller.VendorIDJD, new(WaybillController))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) OnWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
func (c *WaybillController) OnWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
||||||
controller.RoutinePool.CallFun(func() {
|
controller.CallMsgHandler(func() {
|
||||||
retVal = c.onWaybillMsg(msg)
|
retVal = c.onWaybillMsg(msg)
|
||||||
}, msg.OrderID)
|
}, msg.OrderID)
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) callbackMsg2Status(msg *jdapi.CallbackDeliveryStatusMsg) *model.OrderStatus {
|
|
||||||
status := &model.OrderStatus{
|
|
||||||
VendorOrderID: msg.OrderID,
|
|
||||||
VendorID: controller.VendorIDJD,
|
|
||||||
OrderType: controller.OrderTypeWaybill,
|
|
||||||
VendorStatus: msg.DeliveryStatus,
|
|
||||||
StatusTime: utils.Str2Time(msg.DeliveryStatusTime),
|
|
||||||
}
|
|
||||||
return status
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
func (c *WaybillController) onWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
||||||
|
order := c.callbackMsg2Waybill(msg)
|
||||||
switch msg.DeliveryStatus {
|
switch msg.DeliveryStatus {
|
||||||
case jdapi.DeliveryStatusWait4Grap:
|
case jdapi.DeliveryStatusWait4Grap:
|
||||||
retVal = c.onWaybillNew(msg)
|
order.Status = controller.WaybillStatusNew
|
||||||
case jdapi.DeliveryStatusAccepted:
|
case jdapi.DeliveryStatusAccepted:
|
||||||
retVal = c.onWaybillAccepted(msg)
|
order.Status = controller.WaybillStatusAccepted
|
||||||
case jdapi.DeliveryStatusCourierCanceled:
|
case jdapi.DeliveryStatusCourierCanceled:
|
||||||
retVal = c.onWaybillAcceptCanceled(msg)
|
order.Status = controller.WaybillStatusCanceled
|
||||||
|
case jdapi.DeliveryStatusCourierArrived:
|
||||||
|
order.Status = controller.WaybillStatusCourierArrived
|
||||||
case jdapi.DeliveryStatusGotGoods:
|
case jdapi.DeliveryStatusGotGoods:
|
||||||
retVal = c.onWaybillGotGoods(msg)
|
order.Status = controller.WaybillStatusDelivering
|
||||||
case jdapi.DeliveryStatusFinished:
|
case jdapi.DeliveryStatusFinished:
|
||||||
retVal = c.onWaybillFinished(msg)
|
order.Status = controller.WaybillStatusDelivered
|
||||||
case jdapi.DeliveryStatusFailedDelivery:
|
case jdapi.DeliveryStatusFailedDelivery:
|
||||||
retVal = c.onWaybillFailed(msg)
|
order.Status = controller.WaybillStatusFailed
|
||||||
default:
|
default:
|
||||||
retVal = c.onWaybillOtherStatus(msg)
|
order.Status = controller.WaybillStatusUnknown
|
||||||
}
|
}
|
||||||
return retVal
|
return jdapi.Err2CallbackResponse(controller.WaybillManager.OnWaybillStatusChanged(order), order.VendorStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillNew(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
func (c *WaybillController) callbackMsg2Waybill(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *model.Waybill) {
|
||||||
order := &model.Waybill{
|
retVal = &model.Waybill{
|
||||||
VendorOrderID: msg.OrderID,
|
VendorOrderID: msg.OrderID,
|
||||||
VendorID: controller.VendorIDJD,
|
OrderVendorID: controller.VendorIDJD,
|
||||||
VendorWaybillID: msg.OrderID,
|
VendorWaybillID: msg.OrderID,
|
||||||
WaybillVendorID: controller.VendorIDJD,
|
WaybillVendorID: controller.VendorIDJD,
|
||||||
CourierName: msg.DeliveryManName,
|
CourierName: msg.DeliveryManName,
|
||||||
CourierMobile: msg.DeliveryManPhone,
|
CourierMobile: msg.DeliveryManPhone,
|
||||||
|
VendorStatus: msg.DeliveryStatus,
|
||||||
WaybillCreatedAt: utils.Str2Time(msg.DeliveryStatusTime),
|
WaybillCreatedAt: utils.Str2Time(msg.DeliveryStatusTime),
|
||||||
}
|
}
|
||||||
return jdapi.Err2CallbackResponse(c.OnWaybillNew(order), "jd onWaybillNew")
|
return retVal
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillAccepted(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnWaybillAccepted(c.callbackMsg2Status(msg)), "jd onWaybillAccepted")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillAcceptCanceled(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnWaybillAcceptCanceled(c.callbackMsg2Status(msg)), "jd onWaybillAcceptCanceled")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillGotGoods(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnWaybillDelivering(c.callbackMsg2Status(msg)), "jd onWaybillGotGoods")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillFinished(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnWaybillDelivered(c.callbackMsg2Status(msg)), "jd onWaybillFinished")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillFailed(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnWaybillFailed(c.callbackMsg2Status(msg)), "jd onWaybillFailed")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillOtherStatus(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackResponse) {
|
|
||||||
return jdapi.Err2CallbackResponse(c.OnWaybillOtherStatus(c.callbackMsg2Status(msg)), "jd onWaybillOtherStatus")
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,86 +9,67 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type WaybillController struct {
|
type WaybillController struct {
|
||||||
controller.WaybillController
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
controller.OrderManager.RegisterDeliveryPlatform(controller.VendorIDMTPS, new(WaybillController))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) OnWaybillMsg(msg *mtpsapi.CallbackOrderMsg) (retVal *mtpsapi.CallbackResponse) {
|
func (c *WaybillController) OnWaybillMsg(msg *mtpsapi.CallbackOrderMsg) (retVal *mtpsapi.CallbackResponse) {
|
||||||
controller.RoutinePool.CallFun(func() {
|
controller.CallMsgHandler(func() {
|
||||||
retVal = c.onWaybillMsg(msg)
|
retVal = c.onWaybillMsg(msg)
|
||||||
}, msg.MtPeisongID)
|
}, msg.MtPeisongID)
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) OnWaybillExcept(msg *mtpsapi.CallbackOrderExceptionMsg) (retVal *mtpsapi.CallbackResponse) {
|
func (c *WaybillController) OnWaybillExcept(msg *mtpsapi.CallbackOrderExceptionMsg) (retVal *mtpsapi.CallbackResponse) {
|
||||||
controller.RoutinePool.CallFun(func() {
|
controller.CallMsgHandler(func() {
|
||||||
status := &model.OrderStatus{
|
|
||||||
VendorOrderID: msg.MtPeisongID,
|
|
||||||
VendorID: controller.VendorIDMTPS,
|
|
||||||
OrderType: controller.OrderTypeWaybill,
|
|
||||||
VendorStatus: utils.Int2Str(msg.ExceptionCode),
|
|
||||||
StatusTime: utils.Timestamp2Time(int64(msg.Timestamp)),
|
|
||||||
}
|
|
||||||
retVal = mtpsapi.Err2CallbackResponse(c.OnWaybillFailed(status), "mtps OnWaybillExcept")
|
|
||||||
}, msg.MtPeisongID)
|
|
||||||
return retVal
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) callbackMsg2Status(msg *mtpsapi.CallbackOrderMsg) *model.OrderStatus {
|
|
||||||
status := &model.OrderStatus{
|
|
||||||
VendorOrderID: msg.MtPeisongID,
|
|
||||||
VendorID: controller.VendorIDMTPS,
|
|
||||||
OrderType: controller.OrderTypeWaybill,
|
|
||||||
VendorStatus: utils.Int2Str(msg.Status),
|
|
||||||
StatusTime: utils.Timestamp2Time(int64(msg.Timestamp)),
|
|
||||||
}
|
|
||||||
return status
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillMsg(msg *mtpsapi.CallbackOrderMsg) (retVal *mtpsapi.CallbackResponse) {
|
|
||||||
switch msg.Status {
|
|
||||||
case mtpsapi.OrderStatusWaitingForSchedule:
|
|
||||||
retVal = c.onWaybillNew(msg)
|
|
||||||
case mtpsapi.OrderStatusAccepted:
|
|
||||||
retVal = c.onWaybillAccepted(msg)
|
|
||||||
case mtpsapi.OrderStatusPickedUp:
|
|
||||||
retVal = c.onWaybillPickedUp(msg)
|
|
||||||
case mtpsapi.OrderStatusDeliverred:
|
|
||||||
retVal = c.onWaybillDelivered(msg)
|
|
||||||
case mtpsapi.OrderStatusCanceled:
|
|
||||||
retVal = c.onWaybillCanceled(msg)
|
|
||||||
default:
|
|
||||||
globals.SugarLogger.Warnf("unknown msg:%v", msg)
|
|
||||||
retVal = mtpsapi.SuccessResponse
|
|
||||||
}
|
|
||||||
return retVal
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillNew(msg *mtpsapi.CallbackOrderMsg) (retVal *mtpsapi.CallbackResponse) {
|
|
||||||
order := &model.Waybill{
|
order := &model.Waybill{
|
||||||
VendorOrderID: msg.OrderID,
|
|
||||||
VendorID: controller.GetVendorIDFromUniversalOrderID(msg.OrderID),
|
|
||||||
VendorWaybillID: msg.MtPeisongID,
|
VendorWaybillID: msg.MtPeisongID,
|
||||||
VendorWaybillID2: utils.Int64ToStr(msg.DeliveryID),
|
VendorWaybillID2: utils.Int64ToStr(msg.DeliveryID),
|
||||||
WaybillVendorID: controller.VendorIDMTPS,
|
WaybillVendorID: controller.VendorIDMTPS,
|
||||||
CourierName: msg.CourierName,
|
CourierName: msg.CourierName,
|
||||||
CourierMobile: msg.CourierPhone,
|
CourierMobile: msg.CourierPhone,
|
||||||
|
Status: controller.WaybillStatusFailed,
|
||||||
|
VendorStatus: utils.Int2Str(msg.ExceptionCode),
|
||||||
WaybillCreatedAt: utils.Timestamp2Time(msg.Timestamp),
|
WaybillCreatedAt: utils.Timestamp2Time(msg.Timestamp),
|
||||||
}
|
}
|
||||||
return mtpsapi.Err2CallbackResponse(c.OnWaybillNew(order), "mtps onWaybillNew")
|
order.VendorOrderID, order.OrderVendorID = controller.SplitUniversalOrderID(msg.OrderID)
|
||||||
|
retVal = mtpsapi.Err2CallbackResponse(controller.WaybillManager.OnWaybillStatusChanged(order), "mtps OnWaybillExcept")
|
||||||
|
}, msg.MtPeisongID)
|
||||||
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillAccepted(msg *mtpsapi.CallbackOrderMsg) (retVal *mtpsapi.CallbackResponse) {
|
func (c *WaybillController) onWaybillMsg(msg *mtpsapi.CallbackOrderMsg) (retVal *mtpsapi.CallbackResponse) {
|
||||||
return mtpsapi.Err2CallbackResponse(c.OnWaybillAccepted(c.callbackMsg2Status(msg)), "mtps onWaybillAccepted")
|
order := c.callbackMsg2Waybill(msg)
|
||||||
|
switch msg.Status {
|
||||||
|
case mtpsapi.OrderStatusWaitingForSchedule:
|
||||||
|
order.Status = controller.WaybillStatusNew
|
||||||
|
case mtpsapi.OrderStatusAccepted:
|
||||||
|
order.Status = controller.WaybillStatusAccepted
|
||||||
|
case mtpsapi.OrderStatusPickedUp:
|
||||||
|
order.Status = controller.WaybillStatusDelivering
|
||||||
|
case mtpsapi.OrderStatusDeliverred:
|
||||||
|
order.Status = controller.WaybillStatusDelivered
|
||||||
|
case mtpsapi.OrderStatusCanceled:
|
||||||
|
order.Status = controller.WaybillStatusCanceled
|
||||||
|
default:
|
||||||
|
globals.SugarLogger.Warnf("unknown msg:%v", msg)
|
||||||
|
return mtpsapi.SuccessResponse
|
||||||
|
}
|
||||||
|
return mtpsapi.Err2CallbackResponse(controller.WaybillManager.OnWaybillStatusChanged(order), order.VendorStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WaybillController) onWaybillPickedUp(msg *mtpsapi.CallbackOrderMsg) (retVal *mtpsapi.CallbackResponse) {
|
func (c *WaybillController) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) (retVal *model.Waybill) {
|
||||||
return mtpsapi.Err2CallbackResponse(c.OnWaybillDelivering(c.callbackMsg2Status(msg)), "mtps onWaybillPickedUp")
|
retVal = &model.Waybill{
|
||||||
}
|
VendorWaybillID: msg.MtPeisongID,
|
||||||
|
VendorWaybillID2: utils.Int64ToStr(msg.DeliveryID),
|
||||||
func (c *WaybillController) onWaybillDelivered(msg *mtpsapi.CallbackOrderMsg) (retVal *mtpsapi.CallbackResponse) {
|
WaybillVendorID: controller.VendorIDMTPS,
|
||||||
return mtpsapi.Err2CallbackResponse(c.OnWaybillDelivered(c.callbackMsg2Status(msg)), "mtps onWaybillDelivered")
|
CourierName: msg.CourierName,
|
||||||
}
|
CourierMobile: msg.CourierPhone,
|
||||||
|
VendorStatus: utils.Int2Str(msg.Status),
|
||||||
func (c *WaybillController) onWaybillCanceled(msg *mtpsapi.CallbackOrderMsg) (retVal *mtpsapi.CallbackResponse) {
|
WaybillCreatedAt: utils.Timestamp2Time(msg.Timestamp),
|
||||||
return mtpsapi.Err2CallbackResponse(c.OnWaybillCanceled(c.callbackMsg2Status(msg)), "mtps onWaybillCanceled")
|
}
|
||||||
|
retVal.VendorOrderID, retVal.OrderVendorID = controller.SplitUniversalOrderID(msg.OrderID)
|
||||||
|
return retVal
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/baseapi/utils/routinepool"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/legacy/models"
|
"git.rosy.net.cn/jx-callback/legacy/models"
|
||||||
@@ -11,15 +12,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
OrderStatusEvent = -1
|
OrderStatusApplyUrgeOrder = -15
|
||||||
|
OrderStatusApplyRefund = -10
|
||||||
|
OrderStatusApplyCancel = -5
|
||||||
|
|
||||||
OrderStatusUnknown = 0
|
OrderStatusUnknown = 0
|
||||||
|
|
||||||
OrderStatusNew = 5 // 新定单
|
OrderStatusNew = 5 // 新定单
|
||||||
|
OrderStatusAdjust = 8 // 定单调整
|
||||||
OrderStatusAccepted = 10 // 已经接单,也即待出库,待拣货
|
OrderStatusAccepted = 10 // 已经接单,也即待出库,待拣货
|
||||||
OrderStatusFinishedPickup = 15 // 拣货完成
|
OrderStatusFinishedPickup = 15 // 拣货完成
|
||||||
OrderStatusDelivering = 20 // 开始配送,配送员已取货,从这里开始就是运单消息了
|
OrderStatusDelivering = 20 // 开始配送,配送员已取货,从这里开始就是运单消息了
|
||||||
|
|
||||||
|
OrderStatusEndBegin = 100 // 以上的状态就是结束状态
|
||||||
OrderStatusDelivered = 105 // 妥投
|
OrderStatusDelivered = 105 // 妥投
|
||||||
OrderStatusFinished = 110 // 定单已完成
|
OrderStatusFinished = 110 // 定单已完成
|
||||||
OrderStatusCanceled = 115 // 定单已取消
|
OrderStatusCanceled = 115 // 定单已取消
|
||||||
@@ -35,21 +40,50 @@ type PurchasePlatformHandler interface {
|
|||||||
AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool)
|
AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
type DeliveryPlatformHandler interface {
|
||||||
OrderMap SyncMapWithTimeout
|
DeliveryProvider
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RoutinePool = routinepool.New(1000, 1000)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderController struct {
|
type OrderController struct {
|
||||||
|
orderMap SyncMapWithTimeout
|
||||||
|
purchasePlatformHandlers map[int]PurchasePlatformHandler
|
||||||
|
deliveryPlatformHandlers map[int]DeliveryPlatformHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) OnOrderNew(purchasePlatform PurchasePlatformHandler, order *model.GoodsOrder, orderSkus []*model.OrderSku) (err error) {
|
func NewOrderManager() *OrderController {
|
||||||
|
return &OrderController{
|
||||||
|
purchasePlatformHandlers: make(map[int]PurchasePlatformHandler),
|
||||||
|
deliveryPlatformHandlers: make(map[int]DeliveryPlatformHandler),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *OrderController) RegisterPurchasePlatform(vendorID int, handler PurchasePlatformHandler) {
|
||||||
|
if !(vendorID >= VendorIDPurchaseBegin && vendorID <= VendorIDPurchaseEnd) {
|
||||||
|
panic(fmt.Sprintf("purchase vendor:%d is illegal", vendorID))
|
||||||
|
}
|
||||||
|
if _, ok := c.purchasePlatformHandlers[vendorID]; ok {
|
||||||
|
panic(fmt.Sprintf("purchase vendor:%d, already exists", vendorID))
|
||||||
|
}
|
||||||
|
c.purchasePlatformHandlers[vendorID] = handler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *OrderController) RegisterDeliveryPlatform(vendorID int, handler DeliveryPlatformHandler) {
|
||||||
|
if !(vendorID >= VendorIDDeliveryBegin && vendorID <= VendorIDDeliveryEnd) {
|
||||||
|
panic(fmt.Sprintf("delivery vendor:%d is illegal", vendorID))
|
||||||
|
}
|
||||||
|
if _, ok := c.deliveryPlatformHandlers[vendorID]; ok {
|
||||||
|
panic(fmt.Sprintf("delivery vendor:%d, already exists", vendorID))
|
||||||
|
}
|
||||||
|
c.deliveryPlatformHandlers[vendorID] = handler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *OrderController) OnOrderNew(order *model.GoodsOrder, orderSkus []*model.OrderSku) (err error) {
|
||||||
db := orm.NewOrm()
|
db := orm.NewOrm()
|
||||||
|
order.Status = OrderStatusNew
|
||||||
|
isDuplicated, err := addOrderOrWaybillStatus(c.order2Status(order), db)
|
||||||
|
if !isDuplicated {
|
||||||
c.handleAutoAcceptOrder(order.VendorOrderID, order.VendorID, order.ConsigneeMobile, order.StoreID, db, func(isAccept bool) {
|
c.handleAutoAcceptOrder(order.VendorOrderID, order.VendorID, order.ConsigneeMobile, order.StoreID, db, func(isAccept bool) {
|
||||||
// purchasePlatform.AcceptOrRefuseOrder(order, isAccept)
|
// c.purchasePlatformHandlers[order.VendorID].AcceptOrRefuseOrder(order, isAccept)
|
||||||
if isAccept {
|
if isAccept {
|
||||||
order.Status = OrderStatusAccepted
|
order.Status = OrderStatusAccepted
|
||||||
} else {
|
} else {
|
||||||
@@ -63,23 +97,20 @@ func (c *OrderController) OnOrderNew(purchasePlatform PurchasePlatformHandler, o
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
db.Begin()
|
db.Begin()
|
||||||
// globals.SugarLogger.Debugf("new order:%v", order)
|
// globals.SugarLogger.Debugf("new order:%v", order)
|
||||||
|
order.OrderFinishedAt = DefaultTimeValue
|
||||||
|
order.ID = 0
|
||||||
created, _, err2 := db.ReadOrCreate(order, "VendorOrderID", "VendorID")
|
created, _, err2 := db.ReadOrCreate(order, "VendorOrderID", "VendorID")
|
||||||
err = err2
|
err = err2
|
||||||
if err == nil {
|
if err == nil {
|
||||||
OrderMap.Store(ComposeUniversalOrderID(order.VendorOrderID, order.VendorID), order.ID)
|
c.orderMap.Store(ComposeUniversalOrderID(order.VendorOrderID, order.VendorID), order.ID)
|
||||||
if created {
|
if created {
|
||||||
sql := ""
|
sql := "INSERT INTO order_sku(vendor_order_id, vendor_id, count, sku_id, vendor_sku_id, sku_name, shop_price, sale_price, weight, order_created_at) VALUES"
|
||||||
params := []interface{}{}
|
params := []interface{}{}
|
||||||
for _, sku := range orderSkus {
|
for _, sku := range orderSkus {
|
||||||
if sql == "" {
|
sql += "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?),"
|
||||||
sql = "INSERT INTO order_sku(vendor_order_id, vendor_id, count, sku_id, vendor_sku_id, sku_name, shop_price, sale_price, order_created_at) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
params = append(params, sku.VendorOrderID, sku.VendorID, sku.Count, sku.SkuID, sku.VendorSkuID, sku.SkuName, sku.ShopPrice, sku.SalePrice, order.Weight, order.OrderCreatedAt)
|
||||||
|
|
||||||
} else {
|
|
||||||
sql += ",(?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
|
||||||
}
|
}
|
||||||
params = append(params, sku.VendorOrderID, sku.VendorID, sku.Count, sku.SkuID, sku.VendorSkuID, sku.SkuName, sku.ShopPrice, sku.SalePrice, order.OrderCreatedAt)
|
sql = sql[:len(sql)-1] + ";"
|
||||||
}
|
|
||||||
sql += ";"
|
|
||||||
_, err = db.Raw(sql, params...).Exec()
|
_, err = db.Raw(sql, params...).Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
db.Rollback()
|
db.Rollback()
|
||||||
@@ -88,8 +119,10 @@ func (c *OrderController) OnOrderNew(purchasePlatform PurchasePlatformHandler, o
|
|||||||
db.Commit()
|
db.Commit()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
db.Rollback()
|
order.DuplicatedCount++
|
||||||
baseapi.SugarLogger.Warnf("duplicated order:%v msg received", order)
|
db.Update(order, "DuplicatedCount")
|
||||||
|
db.Commit()
|
||||||
|
baseapi.SugarLogger.Infof("duplicated order:%s vendorID:%d, msg received", order.VendorOrderID, order.VendorID)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
db.Rollback()
|
db.Rollback()
|
||||||
@@ -97,12 +130,14 @@ func (c *OrderController) OnOrderNew(purchasePlatform PurchasePlatformHandler, o
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) OnOrderAdjust(purchasePlatform PurchasePlatformHandler, order *model.GoodsOrder, orderSkus []*model.OrderSku) (err error) {
|
func (c *OrderController) OnOrderAdjust(order *model.GoodsOrder, orderSkus []*model.OrderSku) (err error) {
|
||||||
db := orm.NewOrm()
|
db := orm.NewOrm()
|
||||||
|
order.Status = OrderStatusAdjust
|
||||||
|
if isDuplicated, err := addOrderOrWaybillStatus(c.order2Status(order), db); err == nil && !isDuplicated {
|
||||||
err = utils.CallFuncLogError(func() error {
|
err = utils.CallFuncLogError(func() error {
|
||||||
_, err := db.Raw("DELETE FROM order_sku WHERE vendor_order_id = ? AND vendor_id = ?", order.VendorOrderID, order.VendorID).Exec()
|
_, err := db.Raw("DELETE FROM order_sku WHERE vendor_order_id = ? AND vendor_id = ?", order.VendorOrderID, order.VendorID).Exec()
|
||||||
return err
|
return err
|
||||||
@@ -118,60 +153,14 @@ func (c *OrderController) OnOrderAdjust(purchasePlatform PurchasePlatformHandler
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return c.OnOrderNew(purchasePlatform, order, orderSkus)
|
return c.OnOrderNew(order, orderSkus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) OnOrderAccepted(purchasePlatform PurchasePlatformHandler, msg *model.OrderStatus) (err error) {
|
func (c *OrderController) OnOrderStatusChanged(orderStatus *model.OrderStatus) (err error) {
|
||||||
msg.Status = OrderStatusAccepted
|
if isDuplicated, err := c.addOrderStatus(orderStatus, nil); err == nil && !isDuplicated {
|
||||||
return c.addOrderStatus(msg)
|
}
|
||||||
}
|
return err
|
||||||
|
|
||||||
func (c *OrderController) OnOrderFinishedPickup(purchasePlatform PurchasePlatformHandler, msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = OrderStatusFinishedPickup
|
|
||||||
return c.addOrderStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) OnOrderDelivering(purchasePlatform PurchasePlatformHandler, msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = OrderStatusDelivering
|
|
||||||
return c.addOrderStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) OnOrderDelivered(purchasePlatform PurchasePlatformHandler, msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = OrderStatusDelivered
|
|
||||||
return c.addOrderStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) OnOrderCanceled(purchasePlatform PurchasePlatformHandler, msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = OrderStatusFailed
|
|
||||||
return c.addOrderStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) OnOrderFailed(purchasePlatform PurchasePlatformHandler, msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = OrderStatusFailed
|
|
||||||
return c.addOrderStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
func (c *OrderController) OnOrderUserApplyCancel(purchasePlatform PurchasePlatformHandler, msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = OrderStatusEvent
|
|
||||||
return c.addOrderStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) OnOrderUserApplyRefund(purchasePlatform PurchasePlatformHandler, msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = OrderStatusEvent
|
|
||||||
return c.addOrderStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *OrderController) OnOrderUserUrgeOrder(purchasePlatform PurchasePlatformHandler, msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = OrderStatusEvent
|
|
||||||
return c.addOrderStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
func (c *OrderController) OnOrderOtherStatus(purchasePlatform PurchasePlatformHandler, msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = OrderStatusEvent
|
|
||||||
return c.addOrderStatus(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
@@ -213,41 +202,83 @@ func (c *OrderController) handleAutoAcceptOrder(orderID string, vendorID int, us
|
|||||||
} else if handleType == -1 {
|
} else if handleType == -1 {
|
||||||
handler(false)
|
handler(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return handleType
|
return handleType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OrderController) addOrderStatus(msg *model.OrderStatus) (err error) {
|
func (c *OrderController) addOrderStatus(orderStatus *model.OrderStatus, db orm.Ormer) (isDuplicated bool, err error) {
|
||||||
|
if db == nil {
|
||||||
|
db = orm.NewOrm()
|
||||||
|
}
|
||||||
|
isDuplicated, err = addOrderOrWaybillStatus(orderStatus, db)
|
||||||
|
if !isDuplicated && orderStatus.Status > OrderStatusUnknown {
|
||||||
order := &model.GoodsOrder{
|
order := &model.GoodsOrder{
|
||||||
VendorOrderID: msg.VendorOrderID,
|
VendorOrderID: orderStatus.VendorOrderID,
|
||||||
VendorID: msg.VendorID,
|
VendorID: orderStatus.VendorID,
|
||||||
}
|
}
|
||||||
db := orm.NewOrm()
|
if err = c.updateOrderPKID(order, db); err == nil {
|
||||||
value, ok := OrderMap.Load(ComposeUniversalOrderID(msg.VendorOrderID, msg.VendorID))
|
order.Status = orderStatus.Status
|
||||||
if !ok {
|
order.VendorStatus = orderStatus.VendorStatus
|
||||||
// globals.SugarLogger.Infof("can not get order:%v, from cache", order)
|
|
||||||
err = db.Read(order, "VendorOrderID", "VendorID")
|
|
||||||
} else {
|
|
||||||
order.ID = value.(int64)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
if msg.Status != OrderStatusEvent {
|
|
||||||
order.Status = msg.Status
|
|
||||||
utils.CallFuncLogError(func() error {
|
utils.CallFuncLogError(func() error {
|
||||||
columns := []string{"Status"}
|
columns := []string{"Status", "VendorStatus"}
|
||||||
if msg.Status >= OrderStatusDelivered {
|
if orderStatus.Status >= OrderStatusDelivered {
|
||||||
order.OrderFinishedAt = msg.StatusTime
|
order.OrderFinishedAt = orderStatus.StatusTime
|
||||||
columns = append(columns, "OrderFinishedAt")
|
columns = append(columns, "OrderFinishedAt")
|
||||||
}
|
}
|
||||||
_, err := db.Update(order, columns...)
|
_, err := db.Update(order, columns...)
|
||||||
return err
|
return err
|
||||||
}, "update order")
|
}, "update order")
|
||||||
}
|
}
|
||||||
utils.CallFuncLogError(func() error {
|
}
|
||||||
_, err := db.Insert(msg)
|
return isDuplicated, err
|
||||||
return err
|
}
|
||||||
}, "insert status")
|
|
||||||
|
func (c *OrderController) updateOrderPKID(order *model.GoodsOrder, db orm.Ormer) (err error) {
|
||||||
|
value, ok := c.orderMap.Load(ComposeUniversalOrderID(order.VendorOrderID, order.VendorID))
|
||||||
|
if !ok {
|
||||||
|
err = db.Read(order, "VendorOrderID", "VendorID")
|
||||||
|
// todo 这里应该要报警,但测试阶段先去掉
|
||||||
|
// utils.CallFuncLogError(func() error {
|
||||||
|
// err = db.Read(order, "VendorOrderID", "VendorID")
|
||||||
|
// return err
|
||||||
|
// }, "can not get order info from db")
|
||||||
|
} else {
|
||||||
|
order.ID = value.(int64)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *OrderController) order2Status(order *model.GoodsOrder) (retVal *model.OrderStatus) {
|
||||||
|
retVal = &model.OrderStatus{
|
||||||
|
VendorOrderID: order.VendorOrderID,
|
||||||
|
VendorID: order.VendorID,
|
||||||
|
OrderType: OrderTypeOrder,
|
||||||
|
Status: order.Status,
|
||||||
|
VendorStatus: order.VendorStatus,
|
||||||
|
StatusTime: order.OrderCreatedAt,
|
||||||
|
}
|
||||||
|
return retVal
|
||||||
|
}
|
||||||
|
|
||||||
|
//Waybill
|
||||||
|
|
||||||
|
func (c *OrderController) OnWaybillStatusChanged(bill *model.Waybill, db orm.Ormer) (err error) {
|
||||||
|
return c.updateOrderByWaybill(bill, db)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *OrderController) updateOrderByWaybill(bill *model.Waybill, db orm.Ormer) (err error) {
|
||||||
|
if db == nil {
|
||||||
|
db = orm.NewOrm()
|
||||||
|
}
|
||||||
|
order := &model.GoodsOrder{
|
||||||
|
VendorOrderID: bill.VendorOrderID,
|
||||||
|
VendorID: bill.OrderVendorID,
|
||||||
|
}
|
||||||
|
if err = db.Read(order, "VendorOrderID", "VendorID"); err == nil {
|
||||||
|
if order.Status < OrderStatusEndBegin {
|
||||||
|
order.WaybillStatus = bill.Status
|
||||||
|
order.WaybillVendorStatus = bill.VendorStatus
|
||||||
|
db.Update(order, "WaybillStatus", "WaybillVendorStatus")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rosy.net.cn/baseapi"
|
"fmt"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
@@ -12,7 +13,9 @@ const (
|
|||||||
WaybillStatusUnknown = 0
|
WaybillStatusUnknown = 0
|
||||||
|
|
||||||
WaybillStatusNew = 5
|
WaybillStatusNew = 5
|
||||||
|
WaybillStatusAcceptCanceled = 8
|
||||||
WaybillStatusAccepted = 10
|
WaybillStatusAccepted = 10
|
||||||
|
WaybillStatusCourierArrived = 15 // 此状态是可选的,明确写出来是因为还是较重要的状态,但业务逻辑不应依赖此状态
|
||||||
WaybillStatusDelivering = 20
|
WaybillStatusDelivering = 20
|
||||||
|
|
||||||
WaybillStatusDelivered = 105
|
WaybillStatusDelivered = 105
|
||||||
@@ -20,95 +23,137 @@ const (
|
|||||||
WaybillStatusFailed = 120
|
WaybillStatusFailed = 120
|
||||||
)
|
)
|
||||||
|
|
||||||
type WaybillController struct {
|
type DeliveryProvider interface {
|
||||||
OrderController
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
type WaybillController struct {
|
||||||
WaybillMap SyncMapWithTimeout
|
WaybillMap SyncMapWithTimeout
|
||||||
)
|
deliveryProviders map[int]DeliveryProvider
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WaybillController) OnWaybillNew(bill *model.Waybill) (err error) {
|
func NewWaybillManager() *WaybillController {
|
||||||
|
return &WaybillController{
|
||||||
|
deliveryProviders: make(map[int]DeliveryProvider),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WaybillController) RegisterDeliveryProvider(vendorID int, handler DeliveryProvider) {
|
||||||
|
if !(vendorID >= VendorIDDeliveryBegin && vendorID <= VendorIDDeliveryEnd ||
|
||||||
|
vendorID >= VendorIDPurchaseBegin && vendorID <= VendorIDPurchaseEnd) {
|
||||||
|
panic(fmt.Sprintf("delivery provider vendor:%d is illegal", vendorID))
|
||||||
|
}
|
||||||
|
if _, ok := w.deliveryProviders[vendorID]; ok {
|
||||||
|
panic(fmt.Sprintf("delivery provider vendor:%d, already exists", vendorID))
|
||||||
|
}
|
||||||
|
w.deliveryProviders[vendorID] = handler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WaybillController) onWaybillNew(bill *model.Waybill) (err error) {
|
||||||
db := orm.NewOrm()
|
db := orm.NewOrm()
|
||||||
bill.Status = WaybillStatusNew
|
bill.Status = WaybillStatusNew
|
||||||
|
isDuplicated, err := addOrderOrWaybillStatus(w.waybill2Status(bill), db)
|
||||||
|
if !isDuplicated {
|
||||||
|
bill.Status = WaybillStatusNew
|
||||||
|
bill.WaybillFinishedAt = DefaultTimeValue
|
||||||
|
bill.ID = 0
|
||||||
created, _, err := db.ReadOrCreate(bill, "VendorWaybillID", "WaybillVendorID")
|
created, _, err := db.ReadOrCreate(bill, "VendorWaybillID", "WaybillVendorID")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
WaybillMap.Store(ComposeUniversalOrderID(bill.VendorWaybillID, bill.WaybillVendorID), bill.ID)
|
w.WaybillMap.Store(ComposeUniversalOrderID(bill.VendorWaybillID, bill.WaybillVendorID), bill.ID)
|
||||||
if !created {
|
if !created {
|
||||||
baseapi.SugarLogger.Warnf("duplicated waybill:%v msg received", bill)
|
bill.DuplicatedCount++
|
||||||
|
db.Update(bill, "DuplicatedCount")
|
||||||
|
globals.SugarLogger.Infof("duplicated bill:%v vendorID:%d, msg received", bill.VendorWaybillID, bill.WaybillVendorID)
|
||||||
}
|
}
|
||||||
|
err = OrderManager.OnWaybillStatusChanged(bill, db)
|
||||||
} else {
|
} else {
|
||||||
globals.SugarLogger.Warnf("create bill:%v, error:%v", bill, err)
|
globals.SugarLogger.Warnf("create bill:%v, error:%v", bill, err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WaybillController) OnWaybillAccepted(msg *model.OrderStatus) (err error) {
|
func (w *WaybillController) OnWaybillStatusChanged(bill *model.Waybill) (err error) {
|
||||||
msg.Status = WaybillStatusAccepted
|
if bill.Status == WaybillStatusNew {
|
||||||
return w.addWaybillStatus(msg)
|
err = w.onWaybillNew(bill)
|
||||||
}
|
} else if bill.Status == WaybillStatusAccepted {
|
||||||
|
err = w.onWaybillAccepted(bill)
|
||||||
func (w *WaybillController) OnWaybillAcceptCanceled(msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = WaybillStatusNew
|
|
||||||
return w.addWaybillStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WaybillController) OnWaybillDelivering(msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = WaybillStatusDelivering
|
|
||||||
return w.addWaybillStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WaybillController) OnWaybillDelivered(msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = WaybillStatusDelivered
|
|
||||||
return w.addWaybillStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WaybillController) OnWaybillCanceled(msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = WaybillStatusCanceled
|
|
||||||
return w.addWaybillStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WaybillController) OnWaybillFailed(msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = WaybillStatusFailed
|
|
||||||
return w.addWaybillStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WaybillController) OnWaybillOtherStatus(msg *model.OrderStatus) (err error) {
|
|
||||||
msg.Status = OrderStatusEvent
|
|
||||||
return w.addWaybillStatus(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WaybillController) addWaybillStatus(msg *model.OrderStatus) (err error) {
|
|
||||||
order := &model.Waybill{
|
|
||||||
VendorWaybillID: msg.VendorOrderID,
|
|
||||||
WaybillVendorID: msg.VendorID,
|
|
||||||
}
|
|
||||||
db := orm.NewOrm()
|
|
||||||
value, ok := OrderMap.Load(ComposeUniversalOrderID(msg.VendorOrderID, msg.VendorID))
|
|
||||||
if !ok {
|
|
||||||
// globals.SugarLogger.Infof("can not get order:%v, from cache", order)
|
|
||||||
err = db.Read(order, "VendorWaybillID", "WaybillVendorID")
|
|
||||||
} else {
|
} else {
|
||||||
order.ID = value.(int64)
|
db := orm.NewOrm()
|
||||||
|
isDuplicated, err2 := w.addWaybillStatus(bill, db)
|
||||||
|
if err2 == nil && !isDuplicated {
|
||||||
|
err2 = OrderManager.OnWaybillStatusChanged(bill, db)
|
||||||
}
|
}
|
||||||
|
err = err2
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WaybillController) onWaybillAccepted(bill *model.Waybill) (err error) {
|
||||||
|
db := orm.NewOrm()
|
||||||
|
bill.Status = WaybillStatusAccepted
|
||||||
|
isDuplicated, err := w.addWaybillStatus(bill, db)
|
||||||
|
if !isDuplicated {
|
||||||
|
err = w.updateWaybillPKID(bill, db)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if msg.Status != OrderStatusEvent {
|
|
||||||
order.Status = msg.Status
|
|
||||||
utils.CallFuncLogError(func() error {
|
utils.CallFuncLogError(func() error {
|
||||||
columns := []string{"Status"}
|
_, err = db.Update(bill, "CourierName", "CourierMobile")
|
||||||
if msg.Status >= OrderStatusDelivered {
|
return err
|
||||||
order.WaybillFinishedAt = msg.StatusTime
|
}, "update waybill info")
|
||||||
|
if err == nil {
|
||||||
|
err = OrderManager.OnWaybillStatusChanged(bill, db)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WaybillController) addWaybillStatus(bill *model.Waybill, db orm.Ormer) (isDuplicated bool, err error) {
|
||||||
|
if db == nil {
|
||||||
|
db = orm.NewOrm()
|
||||||
|
}
|
||||||
|
waybillStatus := w.waybill2Status(bill)
|
||||||
|
isDuplicated, err = addOrderOrWaybillStatus(waybillStatus, db)
|
||||||
|
if !isDuplicated && waybillStatus.Status > WaybillStatusUnknown {
|
||||||
|
if err = w.updateWaybillPKID(bill, db); err == nil {
|
||||||
|
bill.Status = waybillStatus.Status
|
||||||
|
bill.VendorStatus = waybillStatus.VendorStatus
|
||||||
|
utils.CallFuncLogError(func() error {
|
||||||
|
columns := []string{"Status", "VendorStatus"}
|
||||||
|
if waybillStatus.Status >= OrderStatusDelivered {
|
||||||
|
bill.WaybillFinishedAt = waybillStatus.StatusTime
|
||||||
columns = append(columns, "WaybillFinishedAt")
|
columns = append(columns, "WaybillFinishedAt")
|
||||||
}
|
}
|
||||||
_, err := db.Update(order, columns...)
|
_, err := db.Update(bill, columns...)
|
||||||
return err
|
return err
|
||||||
}, "update order")
|
}, "update waybill")
|
||||||
}
|
}
|
||||||
utils.CallFuncLogError(func() error {
|
}
|
||||||
_, err := db.Insert(msg)
|
return isDuplicated, err
|
||||||
return err
|
}
|
||||||
}, "insert status")
|
|
||||||
|
func (w *WaybillController) waybill2Status(bill *model.Waybill) (retVal *model.OrderStatus) {
|
||||||
|
retVal = &model.OrderStatus{
|
||||||
|
VendorOrderID: bill.VendorWaybillID,
|
||||||
|
VendorID: bill.WaybillVendorID,
|
||||||
|
OrderType: OrderTypeWaybill,
|
||||||
|
Status: bill.Status,
|
||||||
|
VendorStatus: bill.VendorStatus,
|
||||||
|
StatusTime: bill.WaybillCreatedAt,
|
||||||
|
}
|
||||||
|
return retVal
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WaybillController) updateWaybillPKID(bill *model.Waybill, db orm.Ormer) (err error) {
|
||||||
|
value, ok := w.WaybillMap.Load(ComposeUniversalOrderID(bill.VendorWaybillID, bill.WaybillVendorID))
|
||||||
|
if !ok {
|
||||||
|
err = db.Read(bill, "VendorWaybillID", "WaybillVendorID")
|
||||||
|
// todo 这里应该要报警,但测试阶段先去掉
|
||||||
|
// utils.CallFuncLogError(func() error {
|
||||||
|
// err = db.Read(bill, "VendorWaybillID", "WaybillVendorID")
|
||||||
|
// return err
|
||||||
|
// }, "can not get waybill info from db")
|
||||||
|
} else {
|
||||||
|
bill.ID = value.(int64)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,19 +17,28 @@ type GoodsOrder struct {
|
|||||||
StoreName string `orm:"size(64)"`
|
StoreName string `orm:"size(64)"`
|
||||||
SubStoreID int `orm:"column(sub_store_id)"`
|
SubStoreID int `orm:"column(sub_store_id)"`
|
||||||
SubStoreName string `orm:"size(64)"`
|
SubStoreName string `orm:"size(64)"`
|
||||||
ShopPrice int64
|
ShopPrice int64 // 单位为分
|
||||||
SalePrice int64
|
SalePrice int64 // 单位为分
|
||||||
|
Weight int // 单位为克
|
||||||
ConsigneeName string `orm:"size(32)"`
|
ConsigneeName string `orm:"size(32)"`
|
||||||
ConsigneeMobile string `orm:"size(32)"`
|
ConsigneeMobile string `orm:"size(32)"`
|
||||||
SkuCount int
|
ConsigneeAddress string `orm:"size(255)"`
|
||||||
Status int
|
ConsigneeLng int // 坐标 * (10的六次方)
|
||||||
|
ConsigneeLat int // 坐标 * (10的六次方)
|
||||||
|
CoordinateType int
|
||||||
|
SkuCount int // 商品类别数量,即有多少种商品(注意在某些情况下,相同SKU的商品由于售价不同,也会当成不同商品在这个值里)
|
||||||
|
GoodsCount int // 商品个数
|
||||||
|
Status int // 参见相关常量定义
|
||||||
VendorStatus string `orm:"size(16)"`
|
VendorStatus string `orm:"size(16)"`
|
||||||
LockStatus int
|
LockStatus int
|
||||||
CancelApplyReason string `orm:"size(255);null;default(null)"` // null表示没有申请,不为null表示用户正在取消申请
|
CancelApplyReason string `orm:"size(255)"` // ""表示没有申请,不为null表示用户正在取消申请
|
||||||
WaybillVendorID int `orm:"column(waybill_vendor_id);default(-1)"`
|
WaybillVendorID int `orm:"column(waybill_vendor_id)"`
|
||||||
|
WaybillStatus int
|
||||||
|
WaybillVendorStatus string `orm:"size(16)"`
|
||||||
|
DuplicatedCount int // 重复新定单消息数,这个一般不是由于消息重发赞成的(消息重发由OrderStatus过滤),一般是业务逻辑赞成的
|
||||||
OriginalData string `orm:"type(text)"`
|
OriginalData string `orm:"type(text)"`
|
||||||
OrderCreatedAt time.Time `orm:"type(datetime);index"`
|
OrderCreatedAt time.Time `orm:"type(datetime);index"`
|
||||||
OrderFinishedAt time.Time `orm:"type(datetime);null;default(null)"`
|
OrderFinishedAt time.Time `orm:"type(datetime)"`
|
||||||
ModelTimeInfo
|
ModelTimeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +59,7 @@ type OrderSku struct {
|
|||||||
SkuName string `orm:"size(255)"`
|
SkuName string `orm:"size(255)"`
|
||||||
ShopPrice int64
|
ShopPrice int64
|
||||||
SalePrice int64
|
SalePrice int64
|
||||||
|
Weight int // 单位为克
|
||||||
OrderCreatedAt time.Time `orm:"type(datetime);index"`
|
OrderCreatedAt time.Time `orm:"type(datetime);index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +74,7 @@ func (o *OrderSku) TableIndex() [][]string {
|
|||||||
type Waybill struct {
|
type Waybill struct {
|
||||||
ID int64 `orm:"column(id)"`
|
ID int64 `orm:"column(id)"`
|
||||||
VendorOrderID string `orm:"column(vendor_order_id);size(48)"`
|
VendorOrderID string `orm:"column(vendor_order_id);size(48)"`
|
||||||
VendorID int `orm:"column(vendor_id)"`
|
OrderVendorID int `orm:"column(order_vendor_id)"`
|
||||||
VendorWaybillID string `orm:"column(vendor_waybill_id);size(48)"`
|
VendorWaybillID string `orm:"column(vendor_waybill_id);size(48)"`
|
||||||
VendorWaybillID2 string `orm:"column(vendor_waybill_id2);size(48)"`
|
VendorWaybillID2 string `orm:"column(vendor_waybill_id2);size(48)"`
|
||||||
WaybillVendorID int `orm:"column(waybill_vendor_id)"`
|
WaybillVendorID int `orm:"column(waybill_vendor_id)"`
|
||||||
@@ -73,8 +83,9 @@ type Waybill struct {
|
|||||||
Status int
|
Status int
|
||||||
VendorStatus string `orm:"size(16)"`
|
VendorStatus string `orm:"size(16)"`
|
||||||
ActualFee int64
|
ActualFee int64
|
||||||
|
DuplicatedCount int // 重复新定单消息数,这个一般不是由于消息重发赞成的(消息重发由OrderStatus过滤),一般是业务逻辑赞成的
|
||||||
WaybillCreatedAt time.Time `orm:"type(datetime);index"`
|
WaybillCreatedAt time.Time `orm:"type(datetime);index"`
|
||||||
WaybillFinishedAt time.Time `orm:"type(datetime);null;default(null)"`
|
WaybillFinishedAt time.Time `orm:"type(datetime)"`
|
||||||
ModelTimeInfo
|
ModelTimeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,15 +107,15 @@ type OrderStatus struct {
|
|||||||
VendorOrderID string `orm:"column(vendor_order_id);size(48)"`
|
VendorOrderID string `orm:"column(vendor_order_id);size(48)"`
|
||||||
VendorID int `orm:"column(vendor_id)"`
|
VendorID int `orm:"column(vendor_id)"`
|
||||||
OrderType int // 0:定单,1:运单
|
OrderType int // 0:定单,1:运单
|
||||||
Status int // 如果Status为OrderStatusEvent,表示VendorStatus只是一个事件,不是状态
|
Status int // 如果Status为OrderStatusEvent,表示VendorStatus只是一个通知事件,不是状态变化
|
||||||
VendorStatus string `orm:"size(16)"`
|
VendorStatus string `orm:"size(16)"`
|
||||||
StatusTime time.Time `orm:"type(datetime);index"`
|
StatusTime time.Time `orm:"type(datetime);index"`
|
||||||
Count int `orm:"default(1)"`
|
DuplicatedCount int // 收到的重复状态转换(或消息)数,一般是由于重发赞成的
|
||||||
ModelTimeInfo
|
ModelTimeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *OrderStatus) TableIndex() [][]string {
|
func (v *OrderStatus) TableIndex() [][]string {
|
||||||
return [][]string{
|
return [][]string{
|
||||||
[]string{"VendorOrderID", "Status"},
|
[]string{"VendorOrderID", "VendorStatus", "Status"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ routinePoolSize = 1000
|
|||||||
dadaAppKey = "dada9623324449cd250"
|
dadaAppKey = "dada9623324449cd250"
|
||||||
dadaAppSecret = "30c2abbfe8a8780ad5aace46300c64b9"
|
dadaAppSecret = "30c2abbfe8a8780ad5aace46300c64b9"
|
||||||
|
|
||||||
|
callLegacy = true
|
||||||
|
callNew = false
|
||||||
|
|
||||||
[dev]
|
[dev]
|
||||||
freshFoodServerURL = "http://portal.beta.jxc4.com"
|
freshFoodServerURL = "http://portal.beta.jxc4.com"
|
||||||
|
|
||||||
@@ -84,3 +87,5 @@ weixinSecret = "6bbbed1443cc062c20a015a64c07a531"
|
|||||||
|
|
||||||
dbConnectStr = "root:WebServer@1@tcp(127.0.0.1:3306)/jxd_dev_0?charset=utf8&loc=Local"
|
dbConnectStr = "root:WebServer@1@tcp(127.0.0.1:3306)/jxd_dev_0?charset=utf8&loc=Local"
|
||||||
|
|
||||||
|
callLegacy = false
|
||||||
|
callNew = true
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/controller/dada"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
"git.rosy.net.cn/jx-callback/legacy/dada/controller"
|
"git.rosy.net.cn/jx-callback/legacy/dada/controller"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
@@ -24,15 +26,18 @@ func (c *DadaOrderController) URLMapping() {
|
|||||||
func (c *DadaOrderController) OrderStatusChanged() {
|
func (c *DadaOrderController) OrderStatusChanged() {
|
||||||
obj, callbackResponse := api.DadaAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
|
obj, callbackResponse := api.DadaAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
|
||||||
if callbackResponse == nil {
|
if callbackResponse == nil {
|
||||||
|
if globals.CallLegacy {
|
||||||
cc := &controller.OrderController{}
|
cc := &controller.OrderController{}
|
||||||
callbackResponse = cc.OrderStatusChanged(obj)
|
callbackResponse = cc.OrderStatusChanged(obj)
|
||||||
|
|
||||||
// utils.CallFuncAsync(func() {
|
|
||||||
// cc2 := &dada.WaybillController{}
|
|
||||||
// cc2.OnWaybillMsg(obj)
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
if callbackResponse.Code != 200 {
|
if globals.CallNew {
|
||||||
|
utils.CallFuncAsync(func() {
|
||||||
|
cc2 := &dada.WaybillController{}
|
||||||
|
cc2.OnWaybillMsg(obj)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if callbackResponse != nil && callbackResponse.Code != 200 {
|
||||||
c.CustomAbort(callbackResponse.Code, string(utils.MustMarshal(callbackResponse)))
|
c.CustomAbort(callbackResponse.Code, string(utils.MustMarshal(callbackResponse)))
|
||||||
} else {
|
} else {
|
||||||
c.Data["json"] = callbackResponse
|
c.Data["json"] = callbackResponse
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rosy.net.cn/baseapi/platformapi/elmapi"
|
"git.rosy.net.cn/baseapi/platformapi/elmapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/controller/elm"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
"git.rosy.net.cn/jx-callback/legacy/elm/controller"
|
"git.rosy.net.cn/jx-callback/legacy/elm/controller"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
@@ -25,13 +28,16 @@ func (c *ELMOrderController) URLMapping() {
|
|||||||
func (c *ELMOrderController) MsgPost() {
|
func (c *ELMOrderController) MsgPost() {
|
||||||
obj, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody)
|
obj, callbackResponse := api.ElmAPI.GetCallbackMsg(c.Ctx.Input.RequestBody)
|
||||||
if callbackResponse == nil {
|
if callbackResponse == nil {
|
||||||
|
if globals.CallLegacy {
|
||||||
cc := &controller.OrderController{}
|
cc := &controller.OrderController{}
|
||||||
callbackResponse = cc.OrderMessage(obj)
|
callbackResponse = cc.OrderMessage(obj)
|
||||||
|
}
|
||||||
// utils.CallFuncAsync(func() {
|
if globals.CallNew {
|
||||||
// cc2 := &elm.Controller{}
|
utils.CallFuncAsync(func() {
|
||||||
// cc2.OnCallbackMsg(obj)
|
cc2 := &elm.Controller{}
|
||||||
// })
|
cc2.OnCallbackMsg(obj)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.Data["json"] = callbackResponse
|
c.Data["json"] = callbackResponse
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/controller/jd"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
"git.rosy.net.cn/jx-callback/legacy/jd/controller"
|
"git.rosy.net.cn/jx-callback/legacy/jd/controller"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
@@ -34,13 +37,16 @@ func (c *JDOrderController) orderStatus(isCancelOrder bool) {
|
|||||||
obj, callbackResponse = api.JdAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
|
obj, callbackResponse = api.JdAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
|
||||||
}
|
}
|
||||||
if callbackResponse == nil {
|
if callbackResponse == nil {
|
||||||
|
if globals.CallLegacy {
|
||||||
cc := controller.OrderController{}
|
cc := controller.OrderController{}
|
||||||
callbackResponse = cc.OrderStatus(obj)
|
callbackResponse = cc.OrderStatus(obj)
|
||||||
|
}
|
||||||
// utils.CallFuncAsync(func() {
|
if globals.CallNew {
|
||||||
// cc2 := &jd.OrderController{}
|
utils.CallFuncAsync(func() {
|
||||||
// cc2.OnOrderMsg(obj)
|
cc2 := &jd.OrderController{}
|
||||||
// })
|
cc2.OnOrderMsg(obj)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.Data["json"] = callbackResponse
|
c.Data["json"] = callbackResponse
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
@@ -145,13 +151,16 @@ func (c *JDOrderController) ApplyCancelOrder() {
|
|||||||
func (c *JDOrderController) PushDeliveryStatus() {
|
func (c *JDOrderController) PushDeliveryStatus() {
|
||||||
obj, callbackResponse := api.JdAPI.GetOrderDeliveryCallbackMsg(c.Ctx.Input.RequestBody)
|
obj, callbackResponse := api.JdAPI.GetOrderDeliveryCallbackMsg(c.Ctx.Input.RequestBody)
|
||||||
if callbackResponse == nil {
|
if callbackResponse == nil {
|
||||||
|
if globals.CallLegacy {
|
||||||
cc := controller.OrderController{}
|
cc := controller.OrderController{}
|
||||||
callbackResponse = cc.OrderDeliveryStatus(obj)
|
callbackResponse = cc.OrderDeliveryStatus(obj)
|
||||||
|
}
|
||||||
// utils.CallFuncAsync(func() {
|
if globals.CallNew {
|
||||||
// cc2 := &jd.WaybillController{}
|
utils.CallFuncAsync(func() {
|
||||||
// cc2.OnWaybillMsg(obj)
|
cc2 := &jd.WaybillController{}
|
||||||
// })
|
cc2.OnWaybillMsg(obj)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.Data["json"] = callbackResponse
|
c.Data["json"] = callbackResponse
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/controller/mtps"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
"git.rosy.net.cn/jx-callback/legacy/mtps/controller"
|
"git.rosy.net.cn/jx-callback/legacy/mtps/controller"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
@@ -24,13 +27,16 @@ func (c *MTPSOrderController) URLMapping() {
|
|||||||
func (c *MTPSOrderController) Status() {
|
func (c *MTPSOrderController) Status() {
|
||||||
obj, callbackResponse := api.MtpsAPI.GetOrderCallbackMsg(c.Ctx.Request)
|
obj, callbackResponse := api.MtpsAPI.GetOrderCallbackMsg(c.Ctx.Request)
|
||||||
if callbackResponse == nil {
|
if callbackResponse == nil {
|
||||||
|
if globals.CallLegacy {
|
||||||
cc := &controller.OrderController{}
|
cc := &controller.OrderController{}
|
||||||
callbackResponse = cc.OrderStatusChanged(obj)
|
callbackResponse = cc.OrderStatusChanged(obj)
|
||||||
|
}
|
||||||
// utils.CallFuncAsync(func() {
|
if globals.CallNew {
|
||||||
// cc2 := &mtps.WaybillController{}
|
utils.CallFuncAsync(func() {
|
||||||
// cc2.OnWaybillMsg(obj)
|
cc2 := &mtps.WaybillController{}
|
||||||
// })
|
cc2.OnWaybillMsg(obj)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.Data["json"] = callbackResponse
|
c.Data["json"] = callbackResponse
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
@@ -44,13 +50,16 @@ func (c *MTPSOrderController) Status() {
|
|||||||
func (c *MTPSOrderController) Except() {
|
func (c *MTPSOrderController) Except() {
|
||||||
obj, callbackResponse := api.MtpsAPI.GetOrderExceptionCallbackMsg(c.Ctx.Request)
|
obj, callbackResponse := api.MtpsAPI.GetOrderExceptionCallbackMsg(c.Ctx.Request)
|
||||||
if callbackResponse == nil {
|
if callbackResponse == nil {
|
||||||
|
if globals.CallLegacy {
|
||||||
cc := &controller.OrderController{}
|
cc := &controller.OrderController{}
|
||||||
callbackResponse = cc.OrderException(obj)
|
callbackResponse = cc.OrderException(obj)
|
||||||
|
}
|
||||||
// utils.CallFuncAsync(func() {
|
if globals.CallNew {
|
||||||
// cc2 := &mtps.WaybillController{}
|
utils.CallFuncAsync(func() {
|
||||||
// cc2.OnWaybillExcept(obj)
|
cc2 := &mtps.WaybillController{}
|
||||||
// })
|
cc2.OnWaybillExcept(obj)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.Data["json"] = callbackResponse
|
c.Data["json"] = callbackResponse
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
|
|||||||
@@ -16,10 +16,16 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
CallLegacy bool
|
||||||
|
CallNew bool
|
||||||
|
|
||||||
SugarLogger *zap.SugaredLogger
|
SugarLogger *zap.SugaredLogger
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
CallLegacy = beego.AppConfig.DefaultBool("callLegacy", true)
|
||||||
|
CallNew = beego.AppConfig.DefaultBool("callNew", false)
|
||||||
|
|
||||||
logs.SetLogFuncCallDepth(3)
|
logs.SetLogFuncCallDepth(3)
|
||||||
beego.BConfig.Log.AccessLogs = true
|
beego.BConfig.Log.AccessLogs = true
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const (
|
|||||||
|
|
||||||
URL_FRESHFOOD_ELEME_TOKENUPDATE = "eleme/token/update"
|
URL_FRESHFOOD_ELEME_TOKENUPDATE = "eleme/token/update"
|
||||||
URL_FRESHFOOD_ORDER_CREATE_ELEME = "order/eleme"
|
URL_FRESHFOOD_ORDER_CREATE_ELEME = "order/eleme"
|
||||||
URL_FRESHFOOD_ELEME_USER_URGE_ORDER = "reminders/pushElmSmsReminders "
|
URL_FRESHFOOD_ELEME_USER_URGE_ORDER = "reminders/pushElmSmsReminders"
|
||||||
|
|
||||||
URL_FRESHFOOD_MTPS_DELIVERYSTATUS = "mtps/status"
|
URL_FRESHFOOD_MTPS_DELIVERYSTATUS = "mtps/status"
|
||||||
URL_FRESHFOOD_MTPS_EXCEPTION = "mtps/except"
|
URL_FRESHFOOD_MTPS_EXCEPTION = "mtps/except"
|
||||||
|
|||||||
Reference in New Issue
Block a user