- treat DeliveryStatusFailedGetGoods as WaybillStatusFailed for jd waybill

- adjust defsch.
This commit is contained in:
gazebo
2018-08-29 21:37:48 +08:00
parent 55ef8e9ea3
commit 0f68d904bd
5 changed files with 66 additions and 52 deletions

View File

@@ -281,10 +281,20 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
s.CancelWaybill(bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) s.CancelWaybill(bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
} else if order.WaybillVendorID != model.VendorIDUnknown { } else if order.WaybillVendorID != model.VendorIDUnknown {
globals.SugarLogger.Debugf("OnWaybillStatusChanged multiple waybill created, bill:%v", bill) globals.SugarLogger.Debugf("OnWaybillStatusChanged multiple waybill created, bill:%v", bill)
if !s.isBillCandidate(order, bill) && bill.WaybillVendorID != order.VendorID { if order.VendorID == bill.WaybillVendorID { // 是购物平台运单
if order.VendorID != order.WaybillVendorID { // 既有运单不是购物平台运单
globals.SugarLogger.Infof("OnWaybillStatusChanged bill:%v purchase platform bill came later than others, strange!!!", bill)
oldBill := savedOrderInfo.waybills[order.WaybillVendorID]
if oldBill != nil {
s.CancelWaybill(oldBill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
} else {
globals.SugarLogger.Warnf("OnWaybillStatusChanged bill:%v, oldBill is null, strange!!!", bill)
}
}
bill.WaybillVendorID = model.VendorIDUnknown
s.updateOrderByBill(order, bill, false)
} else {
s.CancelWaybill(bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) s.CancelWaybill(bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
} else if bill.WaybillVendorID == order.VendorID && order.WaybillVendorID != order.VendorID {
globals.SugarLogger.Warnf("OnWaybillStatusChanged bill:%v purchase platform bill came later than others, strange!!!", bill)
} }
} }
} }
@@ -423,6 +433,7 @@ func (s *DefScheduler) removeWaybillFromMap(savedOrderInfo *WatchOrderInfo, wayb
func (s *DefScheduler) createWaybillOn3rdProviders(savedOrderInfo *WatchOrderInfo, excludeBill *model.Waybill) (err error) { func (s *DefScheduler) createWaybillOn3rdProviders(savedOrderInfo *WatchOrderInfo, excludeBill *model.Waybill) (err error) {
order := savedOrderInfo.order order := savedOrderInfo.order
globals.SugarLogger.Debugf("createWaybillOn3rdProviders, orderID:%s, status:%d, excludeBill:%v", order.VendorOrderID, order.Status, excludeBill) globals.SugarLogger.Debugf("createWaybillOn3rdProviders, orderID:%s, status:%d, excludeBill:%v", order.VendorOrderID, order.Status, excludeBill)
if order.WaybillVendorID == model.VendorIDUnknown {
if order.LockStatus == model.OrderStatusUnknown && order.Status >= model.OrderStatusFinishedPickup && order.Status < model.OrderStatusEndBegin { // 订单在配送中被取消时就是配送中状态 if order.LockStatus == model.OrderStatusUnknown && order.Status >= model.OrderStatusFinishedPickup && order.Status < model.OrderStatusEndBegin { // 订单在配送中被取消时就是配送中状态
if (order.DeliveryFlag & model.OrderDeliveryFlagMaskScheduleDisabled) == 0 { if (order.DeliveryFlag & model.OrderDeliveryFlagMaskScheduleDisabled) == 0 {
if savedOrderInfo.retryCount <= maxWaybillRetryCount { if savedOrderInfo.retryCount <= maxWaybillRetryCount {
@@ -474,6 +485,9 @@ func (s *DefScheduler) createWaybillOn3rdProviders(savedOrderInfo *WatchOrderInf
} else { } else {
globals.SugarLogger.Debugf("createWaybillOn3rdProviders, orderID:%s, status:%d doesn't match model.OrderStatusFinishedPickup, bypass", order.VendorOrderID, order.Status) globals.SugarLogger.Debugf("createWaybillOn3rdProviders, orderID:%s, status:%d doesn't match model.OrderStatusFinishedPickup, bypass", order.VendorOrderID, order.Status)
} }
} else {
globals.SugarLogger.Debugf("createWaybillOn3rdProviders, orderID:%s, waybillVendorID:%d, vendorWaybilID:%s is not empty, bypass", order.VendorOrderID, order.WaybillVendorID, order.VendorWaybillID)
}
return err return err
} }

View File

@@ -155,7 +155,7 @@ func CallMsgHandlerAsync(handler func(), primaryID string) {
}, primaryID) }, primaryID)
} }
func SplitSkuName(fullName string) (name string, unit string) { func GetNameAndUnitFromSkuName(fullName string) (name string, unit string) {
unit = "份" unit = "份"
index := strings.Index(fullName, "/") index := strings.Index(fullName, "/")
if index >= 0 { if index >= 0 {

View File

@@ -29,24 +29,24 @@ func TestMapValue2Scope(t *testing.T) {
} }
} }
func TestSplitSkuName(t *testing.T) { func TestGetNameAndUnitFromSkuName(t *testing.T) {
name, unit := SplitSkuName("【满59免运】蒜苔肉丝约400g/个(蒜苔约250g 肉丝约150g/份)") name, unit := GetNameAndUnitFromSkuName("【满59免运】蒜苔肉丝约400g/个(蒜苔约250g 肉丝约150g/份)")
if name != "【满59免运】蒜苔肉丝约400g" || unit != "个" { if name != "【满59免运】蒜苔肉丝约400g" || unit != "个" {
t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit) t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit)
} }
name, unit = SplitSkuName("【满59免运】蒜苔肉丝约400g/g份(蒜苔约250g 肉丝约150g/份)") name, unit = GetNameAndUnitFromSkuName("【满59免运】蒜苔肉丝约400g/g份(蒜苔约250g 肉丝约150g/份)")
if name != "【满59免运】蒜苔肉丝约400g" || unit != "g" { if name != "【满59免运】蒜苔肉丝约400g" || unit != "g" {
t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit) t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit)
} }
name, unit = SplitSkuName("【满59免运】蒜苔肉丝约400g/个") name, unit = GetNameAndUnitFromSkuName("【满59免运】蒜苔肉丝约400g/个")
if name != "【满59免运】蒜苔肉丝约400g" || unit != "个" { if name != "【满59免运】蒜苔肉丝约400g" || unit != "个" {
t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit) t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit)
} }
name, unit = SplitSkuName("【满59免运】蒜苔肉丝约400g/") name, unit = GetNameAndUnitFromSkuName("【满59免运】蒜苔肉丝约400g/")
if name != "【满59免运】蒜苔肉丝约400g" || unit != "份" { if name != "【满59免运】蒜苔肉丝约400g" || unit != "份" {
t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit) t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit)
} }
name, unit = SplitSkuName("【满59免运】蒜苔肉丝约400g") name, unit = GetNameAndUnitFromSkuName("【满59免运】蒜苔肉丝约400g")
if name != "【满59免运】蒜苔肉丝约400g" || unit != "份" { if name != "【满59免运】蒜苔肉丝约400g" || unit != "份" {
t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit) t.Fatalf("SplitSkuName wrong, name:%s, unit:%s", name, unit)
} }

View File

@@ -126,8 +126,8 @@ func (c *DeliveryHandler) calculateOrderDeliveryFee(order *model.GoodsOrder, bil
return 0, 0, ErrStoreNoPriceInfo return 0, 0, ErrStoreNoPriceInfo
} }
lng := utils.Str2Float64(lists[0][1].(string)) lng := utils.Str2Float64(utils.Interface2String(lists[0][1]))
lat := utils.Str2Float64(lists[0][2].(string)) lat := utils.Str2Float64(utils.Interface2String(lists[0][2]))
if lng == 0 || lat == 0 { if lng == 0 || lat == 0 {
globals.SugarLogger.Warnf("calculateDeliveryFee can not calculate delivery fee for orderID:%s, because no coordinate info", order.VendorOrderID) globals.SugarLogger.Warnf("calculateDeliveryFee can not calculate delivery fee for orderID:%s, because no coordinate info", order.VendorOrderID)
return 0, 0, ErrStoreNoCoordinate return 0, 0, ErrStoreNoCoordinate
@@ -207,7 +207,7 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, policy func(del
GoodCount: sku.Count, GoodCount: sku.Count,
GoodPrice: jxutils.IntPrice2Standard(sku.SalePrice), GoodPrice: jxutils.IntPrice2Standard(sku.SalePrice),
} }
goodItem.GoodName, goodItem.GoodUnit = jxutils.SplitSkuName(sku.SkuName) goodItem.GoodName, goodItem.GoodUnit = jxutils.GetNameAndUnitFromSkuName(sku.SkuName)
// 好像SKU名不能重复否则会报错尝试处理一下 // 好像SKU名不能重复否则会报错尝试处理一下
if item, ok := goodItemMap[goodItem.GoodName]; !ok { if item, ok := goodItemMap[goodItem.GoodName]; !ok {
goods.Goods = append(goods.Goods, goodItem) goods.Goods = append(goods.Goods, goodItem)

View File

@@ -38,7 +38,7 @@ func (c *PurchaseHandler) onWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (re
order.Status = model.WaybillStatusDelivering order.Status = model.WaybillStatusDelivering
case jdapi.DeliveryStatusFinished: case jdapi.DeliveryStatusFinished:
order.Status = model.WaybillStatusDelivered order.Status = model.WaybillStatusDelivered
case jdapi.DeliveryStatusFailedDelivery: //, jdapi.DeliveryStatusFailedGetGoods: todo 取货失败不当成投递失败 case jdapi.DeliveryStatusFailedDelivery, jdapi.DeliveryStatusFailedGetGoods: // todo 取货失败需不需要当成运单失败
order.Status = model.WaybillStatusFailed order.Status = model.WaybillStatusFailed
default: default:
order.Status = model.WaybillStatusUnknown order.Status = model.WaybillStatusUnknown