- empty scheduler added.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
@@ -11,83 +9,25 @@ import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
const (
|
||||
OrderStatusApplyUrgeOrder = -15
|
||||
OrderStatusApplyRefund = -10
|
||||
OrderStatusApplyCancel = -5
|
||||
|
||||
OrderStatusUnknown = 0
|
||||
|
||||
OrderStatusNew = 5 // 新定单
|
||||
OrderStatusAdjust = 8 // 定单调整
|
||||
OrderStatusAccepted = 10 // 已经接单,也即待出库,待拣货
|
||||
OrderStatusFinishedPickup = 15 // 拣货完成
|
||||
OrderStatusDelivering = 20 // 开始配送,配送员已取货,从这里开始就是运单消息了
|
||||
|
||||
OrderStatusEndBegin = 100 // 以上的状态就是结束状态
|
||||
OrderStatusDelivered = 105 // 妥投
|
||||
OrderStatusFinished = 110 // 定单已完成
|
||||
OrderStatusCanceled = 115 // 定单已取消
|
||||
OrderStatusFailed = 120 // 定单已失败
|
||||
)
|
||||
|
||||
const (
|
||||
LockStatusUnlocked = 0
|
||||
LockStatusLocked = 1
|
||||
)
|
||||
|
||||
type PurchasePlatformHandler interface {
|
||||
AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool)
|
||||
}
|
||||
|
||||
type DeliveryPlatformHandler interface {
|
||||
DeliveryProvider
|
||||
}
|
||||
|
||||
// 所有公共接口调用前,要求在order里或status中设置合适的Status
|
||||
type OrderController struct {
|
||||
orderMap SyncMapWithTimeout
|
||||
purchasePlatformHandlers map[int]PurchasePlatformHandler
|
||||
deliveryPlatformHandlers map[int]DeliveryPlatformHandler
|
||||
orderMap SyncMapWithTimeout
|
||||
}
|
||||
|
||||
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
|
||||
return &OrderController{}
|
||||
}
|
||||
|
||||
func (c *OrderController) OnOrderNew(order *model.GoodsOrder, orderSkus []*model.OrderSku) (err error) {
|
||||
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.purchasePlatformHandlers[order.VendorID].AcceptOrRefuseOrder(order, isAccept)
|
||||
if isAccept {
|
||||
order.Status = OrderStatusAccepted
|
||||
order.Status = model.OrderStatusAccepted
|
||||
} else {
|
||||
order.Status = OrderStatusFailed
|
||||
order.Status = model.OrderStatusFailed
|
||||
}
|
||||
})
|
||||
if err = c.updateOrderOtherInfo(order, db); err == nil {
|
||||
@@ -131,7 +71,6 @@ func (c *OrderController) OnOrderNew(order *model.GoodsOrder, orderSkus []*model
|
||||
|
||||
func (c *OrderController) OnOrderAdjust(order *model.GoodsOrder, orderSkus []*model.OrderSku) (err error) {
|
||||
db := orm.NewOrm()
|
||||
order.Status = OrderStatusAdjust
|
||||
isDuplicated, err := addOrderOrWaybillStatus(c.order2Status(order), db)
|
||||
if err == nil && !isDuplicated {
|
||||
err = utils.CallFuncLogError(func() error {
|
||||
@@ -207,7 +146,7 @@ func (c *OrderController) addOrderStatus(orderStatus *model.OrderStatus, db orm.
|
||||
db = orm.NewOrm()
|
||||
}
|
||||
isDuplicated, err = addOrderOrWaybillStatus(orderStatus, db)
|
||||
if !isDuplicated && orderStatus.Status > OrderStatusUnknown {
|
||||
if !isDuplicated && orderStatus.Status > model.OrderStatusUnknown {
|
||||
order := &model.GoodsOrder{
|
||||
VendorOrderID: orderStatus.VendorOrderID,
|
||||
VendorID: orderStatus.VendorID,
|
||||
@@ -217,7 +156,7 @@ func (c *OrderController) addOrderStatus(orderStatus *model.OrderStatus, db orm.
|
||||
order.VendorStatus = orderStatus.VendorStatus
|
||||
utils.CallFuncLogError(func() error {
|
||||
columns := []string{"Status", "VendorStatus"}
|
||||
if orderStatus.Status >= OrderStatusEndBegin {
|
||||
if orderStatus.Status >= model.OrderStatusEndBegin {
|
||||
order.OrderFinishedAt = orderStatus.StatusTime
|
||||
columns = append(columns, "OrderFinishedAt")
|
||||
}
|
||||
@@ -248,7 +187,7 @@ func (c *OrderController) order2Status(order *model.GoodsOrder) (retVal *model.O
|
||||
retVal = &model.OrderStatus{
|
||||
VendorOrderID: order.VendorOrderID,
|
||||
VendorID: order.VendorID,
|
||||
OrderType: OrderTypeOrder,
|
||||
OrderType: model.OrderTypeOrder,
|
||||
Status: order.Status,
|
||||
VendorStatus: order.VendorStatus,
|
||||
StatusTime: order.OrderCreatedAt,
|
||||
@@ -270,7 +209,7 @@ func (c *OrderController) updateOrderByWaybill(bill *model.Waybill, db orm.Ormer
|
||||
VendorID: bill.OrderVendorID,
|
||||
}
|
||||
if err = db.Read(order, "VendorOrderID", "VendorID"); err == nil {
|
||||
if order.Status < OrderStatusEndBegin {
|
||||
if order.Status < model.OrderStatusEndBegin {
|
||||
order.WaybillStatus = bill.Status
|
||||
order.WaybillVendorStatus = bill.VendorStatus
|
||||
db.Update(order, "WaybillStatus", "WaybillVendorStatus")
|
||||
|
||||
Reference in New Issue
Block a user