- add remark in orderstatus table.
- check order.waybill vendor id in swtich2SelfDeliverWithRetry.
This commit is contained in:
@@ -170,6 +170,7 @@ func (c *OrderController) callbackMsg2Status(msg *jdapi.CallbackOrderMsg) *model
|
|||||||
RefVendorID: model.VendorIDJD,
|
RefVendorID: model.VendorIDJD,
|
||||||
VendorStatus: msg.StatusID,
|
VendorStatus: msg.StatusID,
|
||||||
StatusTime: utils.Str2Time(msg.Timestamp),
|
StatusTime: utils.Str2Time(msg.Timestamp),
|
||||||
|
Remark: msg.Remark,
|
||||||
}
|
}
|
||||||
return orderStatus
|
return orderStatus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ func (c *WaybillController) callbackMsg2Waybill(msg *jdapi.CallbackDeliveryStatu
|
|||||||
CourierMobile: msg.DeliveryManPhone,
|
CourierMobile: msg.DeliveryManPhone,
|
||||||
VendorStatus: msg.DeliveryStatus,
|
VendorStatus: msg.DeliveryStatus,
|
||||||
StatusTime: utils.Str2Time(msg.DeliveryStatusTime),
|
StatusTime: utils.Str2Time(msg.DeliveryStatusTime),
|
||||||
|
Remark: msg.Remark,
|
||||||
}
|
}
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ func (c *WaybillController) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) (
|
|||||||
CourierMobile: msg.CourierPhone,
|
CourierMobile: msg.CourierPhone,
|
||||||
VendorStatus: utils.Int2Str(msg.Status),
|
VendorStatus: utils.Int2Str(msg.Status),
|
||||||
StatusTime: utils.Timestamp2Time(msg.Timestamp),
|
StatusTime: utils.Timestamp2Time(msg.Timestamp),
|
||||||
|
Remark: msg.CancelReason,
|
||||||
}
|
}
|
||||||
retVal.VendorOrderID, retVal.OrderVendorID = jxutils.SplitUniversalOrderID(msg.OrderID)
|
retVal.VendorOrderID, retVal.OrderVendorID = jxutils.SplitUniversalOrderID(msg.OrderID)
|
||||||
return retVal
|
return retVal
|
||||||
@@ -204,7 +205,7 @@ func (c *WaybillController) CreateWaybill(order *model.GoodsOrder) (err error) {
|
|||||||
item.GoodCount += goodItem.GoodCount
|
item.GoodCount += goodItem.GoodCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addParams := utils.Params2Map("note", order.BuyerComment, "goods_detail", string(utils.MustMarshal(goods)), "poi_seq", fmt.Sprintf("%s#%d", model.VendorChineseNames[order.VendorID], order.OrderSeq))
|
addParams := utils.Params2Map("note", order.BuyerComment, "goods_detail", string(utils.MustMarshal(goods)), "poi_seq", fmt.Sprintf("#%d", order.OrderSeq))
|
||||||
_, err = api.MtpsAPI.CreateOrderByShop(billParams, addParams)
|
_, err = api.MtpsAPI.CreateOrderByShop(billParams, addParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
globals.SugarLogger.Debugf("CreateWaybill, orderID:%s, billParams:%v, addParams:%v", order.VendorOrderID, billParams, addParams)
|
globals.SugarLogger.Debugf("CreateWaybill, orderID:%s, billParams:%v, addParams:%v", order.VendorOrderID, billParams, addParams)
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ type Waybill struct {
|
|||||||
StatusTime time.Time `orm:"type(datetime)"` // last status time
|
StatusTime time.Time `orm:"type(datetime)"` // last status time
|
||||||
ModelTimeInfo
|
ModelTimeInfo
|
||||||
OriginalData string `orm:"type(text)"`
|
OriginalData string `orm:"type(text)"`
|
||||||
|
Remark string `orm:"-"` // 用于传递remark
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Waybill) TableUnique() [][]string {
|
func (w *Waybill) TableUnique() [][]string {
|
||||||
@@ -124,6 +125,7 @@ type OrderStatus struct {
|
|||||||
VendorStatus string `orm:"size(255)"`
|
VendorStatus string `orm:"size(255)"`
|
||||||
StatusTime time.Time `orm:"type(datetime);index"`
|
StatusTime time.Time `orm:"type(datetime);index"`
|
||||||
DuplicatedCount int // 收到的重复状态转换(或消息)数,一般是由于重发造成的
|
DuplicatedCount int // 收到的重复状态转换(或消息)数,一般是由于重发造成的
|
||||||
|
Remark string `orm:"size(255)"`
|
||||||
ModelTimeInfo
|
ModelTimeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -245,7 +245,8 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
|||||||
s.resetTimer(savedOrderInfo, bill, isPending)
|
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||||
if !isPending {
|
if !isPending {
|
||||||
// todo 购买平台的运单,优先级最高,但这样写也可能带来问题,即在这个时间,因为之前3方已经接单,已经发出了转自送请求(而且可能成功了),所以加个isSwitched2SelfDelivery状态判断
|
// todo 购买平台的运单,优先级最高,但这样写也可能带来问题,即在这个时间,因为之前3方已经接单,已经发出了转自送请求(而且可能成功了),所以加个isSwitched2SelfDelivery状态判断
|
||||||
if order.WaybillVendorID == model.VendorIDUnknown || (bill.WaybillVendorID == order.VendorID && !savedOrderInfo.isSwitched2SelfDelivery) {
|
if order.WaybillVendorID == model.VendorIDUnknown ||
|
||||||
|
(order.VendorID == bill.WaybillVendorID && order.VendorID != order.WaybillVendorID && !savedOrderInfo.isSwitched2SelfDelivery) {
|
||||||
if order.WaybillVendorID != model.VendorIDUnknown {
|
if order.WaybillVendorID != model.VendorIDUnknown {
|
||||||
globals.SugarLogger.Warnf("OnWaybillStatusChanged orderID:%s purchase platform waybill arrvied later, may case problem", order.VendorOrderID)
|
globals.SugarLogger.Warnf("OnWaybillStatusChanged orderID:%s purchase platform waybill arrvied later, may case problem", order.VendorOrderID)
|
||||||
}
|
}
|
||||||
@@ -402,35 +403,39 @@ func (s *DefScheduler) cancelOtherWaybills(savedOrderInfo *WatchOrderInfo, bill2
|
|||||||
func (s *DefScheduler) swtich2SelfDeliverWithRetry(savedOrderInfo *WatchOrderInfo, bill *model.Waybill, retryCount int, duration time.Duration) {
|
func (s *DefScheduler) swtich2SelfDeliverWithRetry(savedOrderInfo *WatchOrderInfo, bill *model.Waybill, retryCount int, duration time.Duration) {
|
||||||
order := savedOrderInfo.order
|
order := savedOrderInfo.order
|
||||||
globals.SugarLogger.Debugf("swtich2SelfDeliverWithRetry orderID:%s", order.VendorOrderID)
|
globals.SugarLogger.Debugf("swtich2SelfDeliverWithRetry orderID:%s", order.VendorOrderID)
|
||||||
if err := s.Swtich2SelfDeliver(order); err != nil {
|
if order.WaybillVendorID != order.VendorID {
|
||||||
globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry failed, bill:%v, err:%v", bill, err)
|
if err := s.Swtich2SelfDeliver(order); err != nil {
|
||||||
if retryCount > 0 {
|
globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry failed, bill:%v, err:%v", bill, err)
|
||||||
time.AfterFunc(duration, func() {
|
if retryCount > 0 {
|
||||||
jxutils.CallMsgHandlerAsync(func() {
|
time.AfterFunc(duration, func() {
|
||||||
s.swtich2SelfDeliverWithRetry(savedOrderInfo, bill, retryCount-1, duration)
|
jxutils.CallMsgHandlerAsync(func() {
|
||||||
}, order.VendorOrderID)
|
s.swtich2SelfDeliverWithRetry(savedOrderInfo, bill, retryCount-1, duration)
|
||||||
})
|
}, order.VendorOrderID)
|
||||||
} else {
|
})
|
||||||
globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry finally failed, orderID:%s bill:%v, err:%v", order.VendorOrderID, bill, err)
|
} else {
|
||||||
|
globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry finally failed, orderID:%s bill:%v, err:%v", order.VendorOrderID, bill, err)
|
||||||
|
|
||||||
tmpLog := &legacymodel.TempLog{
|
tmpLog := &legacymodel.TempLog{
|
||||||
VendorOrderID: bill.VendorWaybillID,
|
VendorOrderID: bill.VendorWaybillID,
|
||||||
RefVendorOrderID: order.VendorOrderID,
|
RefVendorOrderID: order.VendorOrderID,
|
||||||
Msg: fmt.Sprintf("swtich2SelfDeliverWithRetry finally failed, orderID:%s bill:%v, err:%v", order.VendorOrderID, bill, err),
|
Msg: fmt.Sprintf("swtich2SelfDeliverWithRetry finally failed, orderID:%s bill:%v, err:%v", order.VendorOrderID, bill, err),
|
||||||
}
|
}
|
||||||
db := orm.NewOrm()
|
db := orm.NewOrm()
|
||||||
db.Insert(tmpLog)
|
db.Insert(tmpLog)
|
||||||
|
|
||||||
if s.CancelWaybill(bill) == nil {
|
if s.CancelWaybill(bill) == nil {
|
||||||
// 转自送失败的取消,要将订单中的运单状态更新
|
// 转自送失败的取消,要将订单中的运单状态更新
|
||||||
if s.isBillCandidate(order, bill) {
|
if s.isBillCandidate(order, bill) {
|
||||||
bill.WaybillVendorID = model.VendorIDUnknown
|
bill.WaybillVendorID = model.VendorIDUnknown
|
||||||
s.updateOrderByBill(order, bill, false)
|
s.updateOrderByBill(order, bill, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
savedOrderInfo.isSwitched2SelfDelivery = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
savedOrderInfo.isSwitched2SelfDelivery = true
|
globals.SugarLogger.Warnf("swtich2SelfDeliverWithRetry orderID:%s status is wrong, order details:%v", order.VendorOrderID, order)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user