diff --git a/business/controller/jd/order.go b/business/controller/jd/order.go index 96e1f36dc..831077561 100644 --- a/business/controller/jd/order.go +++ b/business/controller/jd/order.go @@ -170,6 +170,7 @@ func (c *OrderController) callbackMsg2Status(msg *jdapi.CallbackOrderMsg) *model RefVendorID: model.VendorIDJD, VendorStatus: msg.StatusID, StatusTime: utils.Str2Time(msg.Timestamp), + Remark: msg.Remark, } return orderStatus } diff --git a/business/controller/jd/waybill.go b/business/controller/jd/waybill.go index abf0774a9..718f9786e 100644 --- a/business/controller/jd/waybill.go +++ b/business/controller/jd/waybill.go @@ -57,6 +57,7 @@ func (c *WaybillController) callbackMsg2Waybill(msg *jdapi.CallbackDeliveryStatu CourierMobile: msg.DeliveryManPhone, VendorStatus: msg.DeliveryStatus, StatusTime: utils.Str2Time(msg.DeliveryStatusTime), + Remark: msg.Remark, } return retVal } diff --git a/business/controller/mtps/waybill.go b/business/controller/mtps/waybill.go index 1b8591396..66fff2af5 100644 --- a/business/controller/mtps/waybill.go +++ b/business/controller/mtps/waybill.go @@ -92,6 +92,7 @@ func (c *WaybillController) callbackMsg2Waybill(msg *mtpsapi.CallbackOrderMsg) ( CourierMobile: msg.CourierPhone, VendorStatus: utils.Int2Str(msg.Status), StatusTime: utils.Timestamp2Time(msg.Timestamp), + Remark: msg.CancelReason, } retVal.VendorOrderID, retVal.OrderVendorID = jxutils.SplitUniversalOrderID(msg.OrderID) return retVal @@ -204,7 +205,7 @@ func (c *WaybillController) CreateWaybill(order *model.GoodsOrder) (err error) { 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) if err != nil { globals.SugarLogger.Debugf("CreateWaybill, orderID:%s, billParams:%v, addParams:%v", order.VendorOrderID, billParams, addParams) diff --git a/business/model/order.go b/business/model/order.go index 3b2d8116a..9d2969bbb 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -98,6 +98,7 @@ type Waybill struct { StatusTime time.Time `orm:"type(datetime)"` // last status time ModelTimeInfo OriginalData string `orm:"type(text)"` + Remark string `orm:"-"` // 用于传递remark } func (w *Waybill) TableUnique() [][]string { @@ -124,6 +125,7 @@ type OrderStatus struct { VendorStatus string `orm:"size(255)"` StatusTime time.Time `orm:"type(datetime);index"` DuplicatedCount int // 收到的重复状态转换(或消息)数,一般是由于重发造成的 + Remark string `orm:"size(255)"` ModelTimeInfo } diff --git a/business/scheduler/defsch/defsch.go b/business/scheduler/defsch/defsch.go index b015f55a6..de170f421 100644 --- a/business/scheduler/defsch/defsch.go +++ b/business/scheduler/defsch/defsch.go @@ -245,7 +245,8 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo s.resetTimer(savedOrderInfo, bill, isPending) if !isPending { // 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 { 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) { order := savedOrderInfo.order globals.SugarLogger.Debugf("swtich2SelfDeliverWithRetry orderID:%s", order.VendorOrderID) - if err := s.Swtich2SelfDeliver(order); err != nil { - globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry failed, bill:%v, err:%v", bill, err) - if retryCount > 0 { - time.AfterFunc(duration, func() { - jxutils.CallMsgHandlerAsync(func() { - 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) + if order.WaybillVendorID != order.VendorID { + if err := s.Swtich2SelfDeliver(order); err != nil { + globals.SugarLogger.Infof("swtich2SelfDeliverWithRetry failed, bill:%v, err:%v", bill, err) + if retryCount > 0 { + time.AfterFunc(duration, func() { + jxutils.CallMsgHandlerAsync(func() { + 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) - tmpLog := &legacymodel.TempLog{ - VendorOrderID: bill.VendorWaybillID, - RefVendorOrderID: order.VendorOrderID, - Msg: fmt.Sprintf("swtich2SelfDeliverWithRetry finally failed, orderID:%s bill:%v, err:%v", order.VendorOrderID, bill, err), - } - db := orm.NewOrm() - db.Insert(tmpLog) + tmpLog := &legacymodel.TempLog{ + VendorOrderID: bill.VendorWaybillID, + RefVendorOrderID: order.VendorOrderID, + Msg: fmt.Sprintf("swtich2SelfDeliverWithRetry finally failed, orderID:%s bill:%v, err:%v", order.VendorOrderID, bill, err), + } + db := orm.NewOrm() + db.Insert(tmpLog) - if s.CancelWaybill(bill) == nil { - // 转自送失败的取消,要将订单中的运单状态更新 - if s.isBillCandidate(order, bill) { - bill.WaybillVendorID = model.VendorIDUnknown - s.updateOrderByBill(order, bill, false) + if s.CancelWaybill(bill) == nil { + // 转自送失败的取消,要将订单中的运单状态更新 + if s.isBillCandidate(order, bill) { + bill.WaybillVendorID = model.VendorIDUnknown + s.updateOrderByBill(order, bill, false) + } } } + } else { + savedOrderInfo.isSwitched2SelfDelivery = true } } else { - savedOrderInfo.isSwitched2SelfDelivery = true + globals.SugarLogger.Warnf("swtich2SelfDeliverWithRetry orderID:%s status is wrong, order details:%v", order.VendorOrderID, order) } }