- refactor.
This commit is contained in:
@@ -339,6 +339,15 @@ func (c *OrderManager) LoadOrder(vendorOrderID string, vendorID int) (order *mod
|
|||||||
return order, err
|
return order, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *OrderManager) UpdateOrderStatusDirectly(order *model.GoodsOrder) (err error) {
|
||||||
|
db := orm.NewOrm()
|
||||||
|
utils.CallFuncLogError(func() error {
|
||||||
|
_, err = db.Update(db, "Status")
|
||||||
|
return err
|
||||||
|
}, "UpdateOrderStatusDirectly orderID:%s failed with error:%v", order.VendorOrderID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
//Waybill
|
//Waybill
|
||||||
func (c *OrderManager) UpdateWaybillVendorID(bill *model.Waybill, revertStatus bool) (err error) {
|
func (c *OrderManager) UpdateWaybillVendorID(bill *model.Waybill, revertStatus bool) (err error) {
|
||||||
globals.SugarLogger.Debugf("UpdateWaybillVendorID bill:%v", bill)
|
globals.SugarLogger.Debugf("UpdateWaybillVendorID bill:%v", bill)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
CurOrderManager *OrderManager
|
curOrderManager *OrderManager
|
||||||
)
|
)
|
||||||
|
|
||||||
// 所有公共接口调用前,要求在order里或status中设置合适的Status
|
// 所有公共接口调用前,要求在order里或status中设置合适的Status
|
||||||
@@ -32,11 +32,11 @@ func NewOrderManager() *OrderManager {
|
|||||||
return &OrderManager{}
|
return &OrderManager{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatusTimer interface {
|
type IStatusTimer interface {
|
||||||
GetStatusTime() time.Time
|
GetStatusTime() time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatusTimerSlice []StatusTimer
|
type StatusTimerSlice []IStatusTimer
|
||||||
|
|
||||||
func (s StatusTimerSlice) Len() int {
|
func (s StatusTimerSlice) Len() int {
|
||||||
return len(s)
|
return len(s)
|
||||||
@@ -53,8 +53,8 @@ func (s StatusTimerSlice) Swap(i, j int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
CurOrderManager = NewOrderManager()
|
curOrderManager = NewOrderManager()
|
||||||
partner.Init(CurOrderManager)
|
partner.Init(curOrderManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addOrderOrWaybillStatus(status *model.OrderStatus, db orm.Ormer) (isDuplicated bool, err error) {
|
func addOrderOrWaybillStatus(status *model.OrderStatus, db orm.Ormer) (isDuplicated bool, err error) {
|
||||||
@@ -86,12 +86,12 @@ func addOrderOrWaybillStatus(status *model.OrderStatus, db orm.Ormer) (isDuplica
|
|||||||
|
|
||||||
// todo 最好还是改成全事件回放算了
|
// todo 最好还是改成全事件回放算了
|
||||||
func LoadPendingOrders() {
|
func LoadPendingOrders() {
|
||||||
orders := CurOrderManager.LoadPendingOrders()
|
orders := curOrderManager.LoadPendingOrders()
|
||||||
globals.SugarLogger.Infof("LoadPendingOrders orders count:%d", len(orders))
|
globals.SugarLogger.Infof("LoadPendingOrders orders count:%d", len(orders))
|
||||||
|
|
||||||
ordersCount := len(orders)
|
ordersCount := len(orders)
|
||||||
if ordersCount > 0 {
|
if ordersCount > 0 {
|
||||||
bills := CurOrderManager.LoadPendingWaybills()
|
bills := curOrderManager.LoadPendingWaybills()
|
||||||
globals.SugarLogger.Infof("LoadPendingOrders waybills count:%d", len(bills))
|
globals.SugarLogger.Infof("LoadPendingOrders waybills count:%d", len(bills))
|
||||||
var sortOrders StatusTimerSlice
|
var sortOrders StatusTimerSlice
|
||||||
for _, order := range orders {
|
for _, order := range orders {
|
||||||
|
|||||||
203
business/jxcallback/scheduler/basesch/basesch.go
Normal file
203
business/jxcallback/scheduler/basesch/basesch.go
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
package basesch
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BaseScheduler struct {
|
||||||
|
PurchasePlatformHandlers map[int]partner.IPurchasePlatformHandler
|
||||||
|
DeliveryPlatformHandlers map[int]*scheduler.DeliveryPlatformHandlerInfo
|
||||||
|
IsReallyCallPlatformAPI bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) Init() {
|
||||||
|
c.PurchasePlatformHandlers = make(map[int]partner.IPurchasePlatformHandler)
|
||||||
|
c.DeliveryPlatformHandlers = make(map[int]*scheduler.DeliveryPlatformHandlerInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) RegisterPurchasePlatform(vendorID int, handler partner.IPurchasePlatformHandler) {
|
||||||
|
if !(vendorID >= model.VendorIDPurchaseBegin && vendorID <= model.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 *BaseScheduler) RegisterDeliveryPlatform(vendorID int, handler partner.IDeliveryPlatformHandler, isUse4CreateWaybill bool) {
|
||||||
|
if !(vendorID >= model.VendorIDDeliveryBegin && vendorID <= model.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] = &scheduler.DeliveryPlatformHandlerInfo{
|
||||||
|
Handler: handler,
|
||||||
|
Use4CreateWaybill: isUse4CreateWaybill,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) GetPurchasePlatformFromVendorID(vendorID int) partner.IPurchasePlatformHandler {
|
||||||
|
return c.PurchasePlatformHandlers[vendorID]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) GetDeliveryPlatformFromVendorID(vendorID int) *scheduler.DeliveryPlatformHandlerInfo {
|
||||||
|
return c.DeliveryPlatformHandlers[vendorID]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool) (err error) {
|
||||||
|
globals.SugarLogger.Infof("AcceptOrRefuseOrder orderID:%s, isAcceptIt:%t", order.VendorOrderID, isAcceptIt)
|
||||||
|
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusNew {
|
||||||
|
if c.IsReallyCallPlatformAPI {
|
||||||
|
err = utils.CallFuncLogErrorWithInfo(func() error {
|
||||||
|
return c.GetPurchasePlatformFromVendorID(order.VendorID).AcceptOrRefuseOrder(order, isAcceptIt)
|
||||||
|
}, "AcceptOrRefuseOrder orderID:%s, isAcceptIt:%t", order.VendorOrderID, isAcceptIt)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Infof("AcceptOrRefuseOrder orderID:%s, status:%d is not suitable, isAcceptIt:%t", order.VendorOrderID, order.Status, isAcceptIt)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) PickupGoods(order *model.GoodsOrder) (err error) {
|
||||||
|
globals.SugarLogger.Infof("PickupGoods orderID:%s", order.VendorOrderID)
|
||||||
|
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusAccepted {
|
||||||
|
if c.IsReallyCallPlatformAPI {
|
||||||
|
err = utils.CallFuncLogErrorWithInfo(func() error {
|
||||||
|
return c.GetPurchasePlatformFromVendorID(order.VendorID).PickupGoods(order)
|
||||||
|
}, "PickupGoods orderID:%s", order.VendorOrderID)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Infof("PickupGoods orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) PickupGoodsExternal(vendorOrderID string, vendorID int) (err error) {
|
||||||
|
order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, vendorID)
|
||||||
|
if err == nil {
|
||||||
|
err = c.PickupGoods(order)
|
||||||
|
if err == nil {
|
||||||
|
order.Status = model.OrderStatusFinishedPickup
|
||||||
|
err = utils.CallFuncLogErrorWithInfo(func() error {
|
||||||
|
return partner.CurOrderManager.UpdateOrderStatusDirectly(order)
|
||||||
|
}, "PickupGoodsExternal orderID:%s", order.VendorOrderID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) Swtich2SelfDeliver(order *model.GoodsOrder) (err error) {
|
||||||
|
globals.SugarLogger.Infof("Swtich2SelfDeliver orderID:%s", order.VendorOrderID)
|
||||||
|
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusFinishedPickup {
|
||||||
|
if c.IsReallyCallPlatformAPI {
|
||||||
|
err = utils.CallFuncLogErrorWithInfo(func() error {
|
||||||
|
return c.GetPurchasePlatformFromVendorID(order.VendorID).Swtich2SelfDeliver(order)
|
||||||
|
}, "Swtich2SelfDeliver orderID:%s", order.VendorOrderID)
|
||||||
|
if err == nil { // 因为有些平台转自送后,不会再发送订单在配送中消息过来,所以成功后就强制设置状态为配送中
|
||||||
|
order.Status = model.OrderStatusDelivering
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Infof("Swtich2SelfDeliver orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) Swtich2SelfDeliverExternal(vendorOrderID string, vendorID int) (err error) {
|
||||||
|
order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, vendorID)
|
||||||
|
if err == nil {
|
||||||
|
err = c.Swtich2SelfDeliver(order)
|
||||||
|
if err == nil {
|
||||||
|
order.Status = model.OrderStatusDelivering
|
||||||
|
err = utils.CallFuncLogErrorWithInfo(func() error {
|
||||||
|
return partner.CurOrderManager.UpdateOrderStatusDirectly(order)
|
||||||
|
}, "Swtich2SelfDeliverExternal orderID:%s", order.VendorOrderID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) Swtich2SelfDelivered(order *model.GoodsOrder) (err error) {
|
||||||
|
globals.SugarLogger.Infof("Swtich2SelfDelivered orderID:%s", order.VendorOrderID)
|
||||||
|
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusDelivering {
|
||||||
|
if c.IsReallyCallPlatformAPI {
|
||||||
|
err = utils.CallFuncLogError(func() error {
|
||||||
|
return c.GetPurchasePlatformFromVendorID(order.VendorID).Swtich2SelfDelivered(order)
|
||||||
|
}, "Swtich2SelfDelivered orderID:%s", order.VendorOrderID)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Infof("Swtich2SelfDelivered orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) SelfDeliverDelievering(order *model.GoodsOrder) (err error) {
|
||||||
|
globals.SugarLogger.Infof("SelfDeliverDelievering orderID:%s", order.VendorOrderID)
|
||||||
|
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusFinishedPickup {
|
||||||
|
if c.IsReallyCallPlatformAPI {
|
||||||
|
err = utils.CallFuncLogError(func() error {
|
||||||
|
return c.GetPurchasePlatformFromVendorID(order.VendorID).SelfDeliverDelievering(order)
|
||||||
|
}, "SelfDeliverDelievering orderID:%s", order.VendorOrderID)
|
||||||
|
if err == nil { // 因为有些平台设置配送中后,不会发送订单在配送中消息过来,所以成功后就强制设置状态为配送中
|
||||||
|
order.Status = model.OrderStatusDelivering
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if order.Status == model.OrderStatusDelivering {
|
||||||
|
globals.SugarLogger.Debugf("SelfDeliverDelievering orderID:%s, status:%d already ok", order.VendorOrderID, order.Status)
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Infof("SelfDeliverDelievering orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) SelfDeliverDelievered(order *model.GoodsOrder) (err error) {
|
||||||
|
globals.SugarLogger.Infof("SelfDeliverDelievered orderID:%s", order.VendorOrderID)
|
||||||
|
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusDelivering {
|
||||||
|
if c.IsReallyCallPlatformAPI {
|
||||||
|
err = utils.CallFuncLogError(func() error {
|
||||||
|
return c.GetPurchasePlatformFromVendorID(order.VendorID).SelfDeliverDelievered(order)
|
||||||
|
}, "SelfDeliverDelievered orderID:%s", order.VendorOrderID)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Infof("SelfDeliverDelievered orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) CreateWaybill(platformVendorID int, order *model.GoodsOrder) (err error) {
|
||||||
|
globals.SugarLogger.Infof("CreateWaybill orderID:%s, vendorID:%d", order.VendorOrderID, platformVendorID)
|
||||||
|
if !model.IsOrderSolid(order) { // 如果订单是不完整的
|
||||||
|
globals.SugarLogger.Warnf("CreateWaybill orderID:%s, vendorID:%d is not solid!!!", order.VendorOrderID, platformVendorID)
|
||||||
|
return scheduler.ErrOrderIsNotSolid
|
||||||
|
}
|
||||||
|
if c.IsReallyCallPlatformAPI {
|
||||||
|
handlerInfo := c.GetDeliveryPlatformFromVendorID(platformVendorID)
|
||||||
|
if handlerInfo.Use4CreateWaybill {
|
||||||
|
if err = handlerInfo.Handler.CreateWaybill(order); err != nil {
|
||||||
|
globals.SugarLogger.Infof("CreateWaybill failed orderID:%s vendorID:%d with error:%v", order.VendorOrderID, platformVendorID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseScheduler) CancelWaybill(bill *model.Waybill) (err error) {
|
||||||
|
globals.SugarLogger.Infof("CancelWaybill bill:%v", bill)
|
||||||
|
if c.IsReallyCallPlatformAPI && bill.OrderVendorID != bill.WaybillVendorID {
|
||||||
|
if handlerInfo := c.GetDeliveryPlatformFromVendorID(bill.WaybillVendorID); handlerInfo != nil {
|
||||||
|
err = utils.CallFuncLogError(func() error {
|
||||||
|
return handlerInfo.Handler.CancelWaybill(bill)
|
||||||
|
}, "CancelWaybill bill:%v", bill)
|
||||||
|
globals.SugarLogger.Debugf("CancelWaybill bill:%v canceled by myself", bill)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
|
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
|
"git.rosy.net.cn/jx-callback/business/jxutils/weixinmsg"
|
||||||
"git.rosy.net.cn/jx-callback/business/legacymodel"
|
"git.rosy.net.cn/jx-callback/business/legacymodel"
|
||||||
@@ -58,7 +59,7 @@ type StatusActionConfig struct {
|
|||||||
|
|
||||||
// 重要:此调度器要求同一定单的处理逻辑必须是序列化了的,不然会有并发问题
|
// 重要:此调度器要求同一定单的处理逻辑必须是序列化了的,不然会有并发问题
|
||||||
type DefScheduler struct {
|
type DefScheduler struct {
|
||||||
scheduler.BaseScheduler
|
basesch.BaseScheduler
|
||||||
defWorkflowConfig []map[int]*StatusActionConfig
|
defWorkflowConfig []map[int]*StatusActionConfig
|
||||||
orderMap jxutils.SyncMapWithTimeout
|
orderMap jxutils.SyncMapWithTimeout
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,10 @@ package scheduler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"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/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
"git.rosy.net.cn/jx-callback/globals"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -32,7 +29,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
CurrentScheduler Scheduler
|
CurrentScheduler IScheduler
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -48,7 +45,7 @@ type DeliveryPlatformHandlerInfo struct {
|
|||||||
Use4CreateWaybill bool
|
Use4CreateWaybill bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Scheduler interface {
|
type IScheduler interface {
|
||||||
RegisterPurchasePlatform(vendorID int, handler partner.IPurchasePlatformHandler)
|
RegisterPurchasePlatform(vendorID int, handler partner.IPurchasePlatformHandler)
|
||||||
RegisterDeliveryPlatform(vendorID int, handler partner.IDeliveryPlatformHandler, isUse4CreateWaybill bool)
|
RegisterDeliveryPlatform(vendorID int, handler partner.IDeliveryPlatformHandler, isUse4CreateWaybill bool)
|
||||||
|
|
||||||
@@ -60,169 +57,6 @@ type Scheduler interface {
|
|||||||
OnWaybillStatusChanged(bill *model.Waybill, isPending bool) (err error)
|
OnWaybillStatusChanged(bill *model.Waybill, isPending bool) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseScheduler struct {
|
|
||||||
PurchasePlatformHandlers map[int]partner.IPurchasePlatformHandler
|
|
||||||
DeliveryPlatformHandlers map[int]*DeliveryPlatformHandlerInfo
|
|
||||||
IsReallyCallPlatformAPI bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) Init() {
|
|
||||||
c.PurchasePlatformHandlers = make(map[int]partner.IPurchasePlatformHandler)
|
|
||||||
c.DeliveryPlatformHandlers = make(map[int]*DeliveryPlatformHandlerInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) RegisterPurchasePlatform(vendorID int, handler partner.IPurchasePlatformHandler) {
|
|
||||||
if !(vendorID >= model.VendorIDPurchaseBegin && vendorID <= model.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 *BaseScheduler) RegisterDeliveryPlatform(vendorID int, handler partner.IDeliveryPlatformHandler, isUse4CreateWaybill bool) {
|
|
||||||
if !(vendorID >= model.VendorIDDeliveryBegin && vendorID <= model.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] = &DeliveryPlatformHandlerInfo{
|
|
||||||
Handler: handler,
|
|
||||||
Use4CreateWaybill: isUse4CreateWaybill,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) GetPurchasePlatformFromVendorID(vendorID int) partner.IPurchasePlatformHandler {
|
|
||||||
return c.PurchasePlatformHandlers[vendorID]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) GetDeliveryPlatformFromVendorID(vendorID int) *DeliveryPlatformHandlerInfo {
|
|
||||||
return c.DeliveryPlatformHandlers[vendorID]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool) (err error) {
|
|
||||||
globals.SugarLogger.Infof("AcceptOrRefuseOrder orderID:%s, isAcceptIt:%t", order.VendorOrderID, isAcceptIt)
|
|
||||||
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusNew {
|
|
||||||
if c.IsReallyCallPlatformAPI {
|
|
||||||
err = utils.CallFuncLogErrorWithInfo(func() error {
|
|
||||||
return c.GetPurchasePlatformFromVendorID(order.VendorID).AcceptOrRefuseOrder(order, isAcceptIt)
|
|
||||||
}, "AcceptOrRefuseOrder orderID:%s, isAcceptIt:%t", order.VendorOrderID, isAcceptIt)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
globals.SugarLogger.Infof("AcceptOrRefuseOrder orderID:%s, status:%d is not suitable, isAcceptIt:%t", order.VendorOrderID, order.Status, isAcceptIt)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
func (c *BaseScheduler) PickupGoods(order *model.GoodsOrder) (err error) {
|
|
||||||
globals.SugarLogger.Infof("PickupGoods orderID:%s", order.VendorOrderID)
|
|
||||||
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusAccepted {
|
|
||||||
if c.IsReallyCallPlatformAPI {
|
|
||||||
err = utils.CallFuncLogErrorWithInfo(func() error {
|
|
||||||
return c.GetPurchasePlatformFromVendorID(order.VendorID).PickupGoods(order)
|
|
||||||
}, "PickupGoods orderID:%s", order.VendorOrderID)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
globals.SugarLogger.Infof("PickupGoods orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) Swtich2SelfDeliver(order *model.GoodsOrder) (err error) {
|
|
||||||
globals.SugarLogger.Infof("Swtich2SelfDeliver orderID:%s", order.VendorOrderID)
|
|
||||||
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusFinishedPickup {
|
|
||||||
if c.IsReallyCallPlatformAPI {
|
|
||||||
err = utils.CallFuncLogErrorWithInfo(func() error {
|
|
||||||
return c.GetPurchasePlatformFromVendorID(order.VendorID).Swtich2SelfDeliver(order)
|
|
||||||
}, "Swtich2SelfDeliver orderID:%s", order.VendorOrderID)
|
|
||||||
if err == nil { // 因为有些平台转自送后,不会再发送订单在配送中消息过来,所以成功后就强制设置状态为配送中
|
|
||||||
order.Status = model.OrderStatusDelivering
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
globals.SugarLogger.Infof("Swtich2SelfDeliver orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) Swtich2SelfDelivered(order *model.GoodsOrder) (err error) {
|
|
||||||
globals.SugarLogger.Infof("Swtich2SelfDelivered orderID:%s", order.VendorOrderID)
|
|
||||||
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusDelivering {
|
|
||||||
if c.IsReallyCallPlatformAPI {
|
|
||||||
err = utils.CallFuncLogError(func() error {
|
|
||||||
return c.GetPurchasePlatformFromVendorID(order.VendorID).Swtich2SelfDelivered(order)
|
|
||||||
}, "Swtich2SelfDelivered orderID:%s", order.VendorOrderID)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
globals.SugarLogger.Infof("Swtich2SelfDelivered orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) SelfDeliverDelievering(order *model.GoodsOrder) (err error) {
|
|
||||||
globals.SugarLogger.Infof("SelfDeliverDelievering orderID:%s", order.VendorOrderID)
|
|
||||||
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusFinishedPickup {
|
|
||||||
if c.IsReallyCallPlatformAPI {
|
|
||||||
err = utils.CallFuncLogError(func() error {
|
|
||||||
return c.GetPurchasePlatformFromVendorID(order.VendorID).SelfDeliverDelievering(order)
|
|
||||||
}, "SelfDeliverDelievering orderID:%s", order.VendorOrderID)
|
|
||||||
if err == nil { // 因为有些平台设置配送中后,不会发送订单在配送中消息过来,所以成功后就强制设置状态为配送中
|
|
||||||
order.Status = model.OrderStatusDelivering
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if order.Status == model.OrderStatusDelivering {
|
|
||||||
globals.SugarLogger.Debugf("SelfDeliverDelievering orderID:%s, status:%d already ok", order.VendorOrderID, order.Status)
|
|
||||||
} else {
|
|
||||||
globals.SugarLogger.Infof("SelfDeliverDelievering orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) SelfDeliverDelievered(order *model.GoodsOrder) (err error) {
|
|
||||||
globals.SugarLogger.Infof("SelfDeliverDelievered orderID:%s", order.VendorOrderID)
|
|
||||||
if order.LockStatus == model.OrderStatusUnknown && order.Status == model.OrderStatusDelivering {
|
|
||||||
if c.IsReallyCallPlatformAPI {
|
|
||||||
err = utils.CallFuncLogError(func() error {
|
|
||||||
return c.GetPurchasePlatformFromVendorID(order.VendorID).SelfDeliverDelievered(order)
|
|
||||||
}, "SelfDeliverDelievered orderID:%s", order.VendorOrderID)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
globals.SugarLogger.Infof("SelfDeliverDelievered orderID:%s, status:%d is not suitable", order.VendorOrderID, order.Status)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) CreateWaybill(platformVendorID int, order *model.GoodsOrder) (err error) {
|
|
||||||
globals.SugarLogger.Infof("CreateWaybill orderID:%s, vendorID:%d", order.VendorOrderID, platformVendorID)
|
|
||||||
if !model.IsOrderSolid(order) { // 如果订单是不完整的
|
|
||||||
globals.SugarLogger.Warnf("CreateWaybill orderID:%s, vendorID:%d is not solid!!!", order.VendorOrderID, platformVendorID)
|
|
||||||
return ErrOrderIsNotSolid
|
|
||||||
}
|
|
||||||
if c.IsReallyCallPlatformAPI {
|
|
||||||
handlerInfo := c.GetDeliveryPlatformFromVendorID(platformVendorID)
|
|
||||||
if handlerInfo.Use4CreateWaybill {
|
|
||||||
if err = handlerInfo.Handler.CreateWaybill(order); err != nil {
|
|
||||||
globals.SugarLogger.Infof("CreateWaybill failed orderID:%s vendorID:%d with error:%v", order.VendorOrderID, platformVendorID, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *BaseScheduler) CancelWaybill(bill *model.Waybill) (err error) {
|
|
||||||
globals.SugarLogger.Infof("CancelWaybill bill:%v", bill)
|
|
||||||
if c.IsReallyCallPlatformAPI && bill.OrderVendorID != bill.WaybillVendorID {
|
|
||||||
if handlerInfo := c.GetDeliveryPlatformFromVendorID(bill.WaybillVendorID); handlerInfo != nil {
|
|
||||||
err = utils.CallFuncLogError(func() error {
|
|
||||||
return handlerInfo.Handler.CancelWaybill(bill)
|
|
||||||
}, "CancelWaybill bill:%v", bill)
|
|
||||||
globals.SugarLogger.Debugf("CancelWaybill bill:%v canceled by myself", bill)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
type BasePurchasePlatform struct {
|
type BasePurchasePlatform struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
"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"
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||||
@@ -23,7 +24,7 @@ func init() {
|
|||||||
|
|
||||||
func TestCreateWaybill(t *testing.T) {
|
func TestCreateWaybill(t *testing.T) {
|
||||||
orderID := "817540316000041"
|
orderID := "817540316000041"
|
||||||
if order, err := orderman.CurOrderManager.LoadOrder(orderID, model.VendorIDJD); err == nil {
|
if order, err := partner.CurOrderManager.LoadOrder(orderID, model.VendorIDJD); err == nil {
|
||||||
// globals.SugarLogger.Debug(order)
|
// globals.SugarLogger.Debug(order)
|
||||||
c := new(DeliveryHandler)
|
c := new(DeliveryHandler)
|
||||||
if err = c.CreateWaybill(order); err == nil {
|
if err = c.CreateWaybill(order); err == nil {
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package mtps
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
"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"
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||||
@@ -22,7 +23,7 @@ func init() {
|
|||||||
|
|
||||||
func TestCreateWaybill(t *testing.T) {
|
func TestCreateWaybill(t *testing.T) {
|
||||||
orerID := "817109342000022"
|
orerID := "817109342000022"
|
||||||
order, _ := orderman.CurOrderManager.LoadOrder(orerID, model.VendorIDJD)
|
order, _ := partner.CurOrderManager.LoadOrder(orerID, model.VendorIDJD)
|
||||||
// globals.SugarLogger.Debug(order)
|
// globals.SugarLogger.Debug(order)
|
||||||
c := new(DeliveryHandler)
|
c := new(DeliveryHandler)
|
||||||
if err := c.CreateWaybill(order); err != nil {
|
if err := c.CreateWaybill(order); err != nil {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ type IOrderManager interface {
|
|||||||
|
|
||||||
LoadOrder(vendorOrderID string, vendorID int) (order *model.GoodsOrder, err error)
|
LoadOrder(vendorOrderID string, vendorID int) (order *model.GoodsOrder, err error)
|
||||||
UpdateWaybillVendorID(bill *model.Waybill, revertStatus bool) (err error)
|
UpdateWaybillVendorID(bill *model.Waybill, revertStatus bool) (err error)
|
||||||
|
UpdateOrderStatusDirectly(order *model.GoodsOrder) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type IPurchasePlatformHandler interface {
|
type IPurchasePlatformHandler interface {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
//E:/goprojects/src/git.rosy.net.cn/jx-callback/conf/app.conf
|
//E:/goprojects/src/git.rosy.net.cn/jx-callback/conf/app.conf
|
||||||
///Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf
|
///Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf
|
||||||
beego.InitBeegoBeforeTest("Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
||||||
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
||||||
|
|
||||||
globals.Init()
|
globals.Init()
|
||||||
@@ -25,9 +25,9 @@ func TestGetOrder(t *testing.T) {
|
|||||||
orderID := "3025427524410871880"
|
orderID := "3025427524410871880"
|
||||||
order, err := new(PurchaseHandler).GetOrder(orderID)
|
order, err := new(PurchaseHandler).GetOrder(orderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
t.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
if order.VendorOrderID != orderID {
|
if order.VendorOrderID != orderID {
|
||||||
panic(err.Error())
|
t.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ package jd
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
"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"
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||||
@@ -22,7 +23,7 @@ func init() {
|
|||||||
|
|
||||||
func TestSwitch2SelfDeliver(t *testing.T) {
|
func TestSwitch2SelfDeliver(t *testing.T) {
|
||||||
orderID := "817540316000041"
|
orderID := "817540316000041"
|
||||||
if order, err := orderman.CurOrderManager.LoadOrder(orderID, model.VendorIDJD); err == nil {
|
if order, err := partner.CurOrderManager.LoadOrder(orderID, model.VendorIDJD); err == nil {
|
||||||
// globals.SugarLogger.Debug(order)
|
// globals.SugarLogger.Debug(order)
|
||||||
c := new(PurchaseHandler)
|
c := new(PurchaseHandler)
|
||||||
if err = c.Swtich2SelfDeliver(order); err == nil {
|
if err = c.Swtich2SelfDeliver(order); err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user