This commit is contained in:
邹宗楠
2023-06-05 13:54:19 +08:00
parent b52bd5556f
commit 42213a4ff0
7 changed files with 71 additions and 45 deletions

View File

@@ -204,22 +204,8 @@ func (c *BaseScheduler) CreateWaybill(platformVendorID int, order *model.GoodsOr
if !model.IsOrderSolid(order) { // 如果订单是不完整的
return nil, scheduler.ErrOrderIsNotSolid
}
// if order.DeliveryFlag&model.OrderDeliveryFlagMaskScheduleDisabled != 0 {
// waybillList, err := partner.CurOrderManager.GetOrderWaybillInfo(jxcontext.AdminCtx, order.VendorOrderID, order.VendorID, true)
// if err != nil {
// return nil, err
// }
// if len(waybillList) > 0 {
// return nil, fmt.Errorf("转商家自送的订单只允许有一个有效运单,当前已经有%s运单", jxutils.GetVendorName(waybillList[0].WaybillVendorID))
// }
// }
storeDetail, _ := dao.GetStoreDetail(dao.GetDB(), jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, order.VendorOrgCode)
// 如果门店没钱,查看品牌查询门店品牌id
//result, err := partner.CurStoreAcctManager.GetBrandBalance(storeDetail.BrandID) // 品牌余额
//if err != nil {
// return nil, err
//}
var balance int
// 门店发单,如果是京西门店,直接使用京西余额,非京西门店使用门店余额,余额不足使用品牌余额!
@@ -229,30 +215,19 @@ func (c *BaseScheduler) CreateWaybill(platformVendorID int, order *model.GoodsOr
return nil, err
}
balance = storeAcct.AccountBalance
//if storeDetail.BrandID == scheduler.JXC4B_SHOP || storeDetail.BrandID == scheduler.JXC4B_RAND_JXGY { // 京西品牌,扣门店
// balance = storeAcct.AccountBalance
//} else {
// if storeAcct.AccountBalance >= model.BrandBalanceLimit {
// balance = storeAcct.AccountBalance
// } else if storeAcct.AccountBalance < model.BrandBalanceLimit && result >= model.BrandBalanceLimit {
// balance = result
// } else {
// balance = 0
// }
//}
} else {
balance, _ = partner.CurStoreAcctManager.GetBrandBalance(storeDetail.BrandID)
}
handlerInfo := partner.GetDeliveryPlatformFromVendorID(platformVendorID)
if handlerInfo != nil && handlerInfo.Use4CreateWaybill {
//if model.DeliveryBrandMarkMap[platformVendorID]&storeDetail.BrandIsOpen != 0 && balance >= model.BrandBalanceLimit {
if _, ok := model.DeliveryBrandMarkMap[platformVendorID]; ok && storeDetail.BrandIsOpen != 0 && balance >= model.BrandBalanceLimit {
if c.IsReallyCallPlatformAPI {
// 如果门店是美团服务商且订单为美团订单
if storeDetail.IsService == model.YES && order.VendorID == model.VendorIDMTWM {
err = fmt.Errorf("京西ID:[%d],平台id[%s],平台[美团]:错误:[%s]", storeDetail.Store.ID, storeDetail.VendorStoreID, "此门店美团平台为服务商模式,不支持本系统提供的三方配送![仅美团,其余平台订单正常使用.]")
} else {
// 生成三方运单
bill, err = handlerInfo.Handler.CreateWaybill(order, maxDeliveryFee)
if err != nil {

View File

@@ -36,23 +36,28 @@ func (c *BaseScheduler) CreateWaybillOnProviders(ctx *jxcontext.Context, order *
errList := errlist.New()
for _, storeCourier := range storeCourierList {
if (courierVendorIDs == nil || courierVendorIDMap[storeCourier.VendorID] == 1) &&
(excludeCourierVendorIDs == nil || excludeCourierVendorIDMap[storeCourier.VendorID] == 0) {
if handler := partner.GetDeliveryPlatformFromVendorID(storeCourier.VendorID); handler != nil && handler.Use4CreateWaybill {
courierVendorID := storeCourier.VendorID
// 创建运单
bill, err2 := c.CreateWaybill(courierVendorID, order, maxDeliveryFee)
if err = err2; err == nil {
bill.DesiredFee += model.WayBillDeliveryMarkUp
bill.ActualFee += model.WayBillDeliveryMarkUp
bills = append(bills, bill)
if createOnlyOne {
break
switch storeCourier.Status {
case model.YES:
if (courierVendorIDs == nil || courierVendorIDMap[storeCourier.VendorID] == 1) &&
(excludeCourierVendorIDs == nil || excludeCourierVendorIDMap[storeCourier.VendorID] == 0) {
if handler := partner.GetDeliveryPlatformFromVendorID(storeCourier.VendorID); handler != nil && handler.Use4CreateWaybill {
courierVendorID := storeCourier.VendorID
// 创建运单
bill, err2 := c.CreateWaybill(courierVendorID, order, maxDeliveryFee)
if err = err2; err == nil {
bill.DesiredFee += model.WayBillDeliveryMarkUp
bill.ActualFee += model.WayBillDeliveryMarkUp
bills = append(bills, bill)
if createOnlyOne {
break
}
} else {
errList.AddErr(fmt.Errorf("平台:%s,%s", jxutils.GetVendorName(courierVendorID), err.Error()))
}
} else {
errList.AddErr(fmt.Errorf("平台:%s,%s", jxutils.GetVendorName(courierVendorID), err.Error()))
}
}
case model.NO:
errList.AddErr(fmt.Errorf("平台:%s,发单配送被关闭,打开后发单", jxutils.GetVendorName(storeCourier.VendorID)))
}
}
if len(bills) > 0 {
@@ -208,7 +213,8 @@ func (c *BaseScheduler) CancelWaybillByID(ctx *jxcontext.Context, vendorWaybillI
if err := c.CancelWaybill(bill, cancelReasonID, cancelReason); err != nil {
return err
}
order, _ := partner.CurOrderManager.LoadOrder(bill.VendorOrderID, bill.OrderVendorID)
partner.CurOrderManager.OnOrderMsg(order, utils.Int64ToStr(model.WaybillStatusCancel), "商户发起运单取消")
return err
}

View File

@@ -1005,6 +1005,7 @@ func (s *DefScheduler) cancelOtherWaybills(savedOrderInfo *WatchOrderInfo, bill2
if err2 == nil {
// 在这里就从map里删除而不是等收到运单结束事件才删除可避免不必要的重复取消第二次取消还会失败
s.removeWaybillFromMap(savedOrderInfo, v.WaybillVendorID)
partner.CurOrderManager.OnOrderMsg(savedOrderInfo.order, utils.Int64ToStr(model.WaybillStatusCancel), "管理系统取消或自动取消")
} else {
// 至少返回一个错误
if err == nil {

View File

@@ -362,6 +362,8 @@ const (
WaybillStatusCanceled = 115
WaybillStatusFailed = 120 // 这个状态存在的意义是区分于WaybillStatusCanceled比如达达平台在这种状态下再次创建运单的方式不一样
WaybillStatusEndEnd = 120
WaybillStatusCancel = 1150 // 115为取消,但是分不清是商户取消还是骑手取消!1150标志着商户取消记录
)
const (

View File

@@ -557,6 +557,15 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
return 0, err
}
isMerchantCancel := false
// 获取发起取消的人员
for _, v := range orderStatus {
if v.VendorStatus == utils.Int64ToStr(model.WaybillStatusCancel) {
isMerchantCancel = true // 商户取消
break
}
}
dadaOrder, err := api.DadaAPI.QueryOrderInfo(orderId)
if err != nil {
return 0, err
@@ -569,7 +578,11 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
continue
}
if orderStatus[i].VendorStatus == utils.Int2Str(dadaapi.OrderStatusFinished) || orderStatus[i].VendorStatus == utils.Int2Str(dadaapi.OrderStatusDelivering) || orderStatus[i].VendorStatus == utils.Int2Str(dadaapi.OrderStatusReturningInOrder) {
localPrice = utils.Float64TwoInt64(dadaOrder.DeliveryFee * float64(100))
if isMerchantCancel {
localPrice = utils.Float64TwoInt64(dadaOrder.DeliveryFee * float64(100))
} else {
localPrice = 0
}
break
}
if orderStatus[i].VendorStatus == utils.Int2Str(dadaapi.OrderStatusAccepted) {

View File

@@ -422,12 +422,26 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
if err != nil {
return 0, err
}
isMerchantCancel := false
// 获取发起取消的人员
for _, v := range orderStatus {
if v.VendorStatus == utils.Int64ToStr(model.WaybillStatusCancel) {
isMerchantCancel = true // 商户取消
break
}
}
for i := len(orderStatus) - 1; i >= 0; i-- {
if orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusAcceptCacle) {
continue
}
if orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusArrived) || orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusDelivering) || orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusDelivered) {
localPrice = order.OrderTotalAmountCent
if isMerchantCancel {
localPrice = order.OrderTotalAmountCent
} else {
localPrice = 0
}
break
}
if orderStatus[i].VendorStatus == utils.Int2Str(fnpsapi.OrderStatusAssigned) {

View File

@@ -503,6 +503,15 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
return 0, err
}
isMerchantCancel := false
// 获取发起取消的人员
for _, v := range statusList {
if v.VendorStatus == utils.Int64ToStr(model.WaybillStatusCancel) {
isMerchantCancel = true // 商户取消
break
}
}
bill, err := partner.CurOrderManager.LoadWaybill(deliverId, model.VendorIDMTPS)
if err != nil {
return 0, err
@@ -520,11 +529,17 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
}
// 到店
if statusList[i].VendorStatus == utils.Int2Str(mtpsapi.OrderStatusPickedUp) {
return bill.DesiredFee, nil
if isMerchantCancel {
return bill.DesiredFee, nil
}
return 0, nil
}
// 接单
if statusList[i].VendorStatus == utils.Int2Str(mtpsapi.OrderStatusAccepted) {
return 200, nil
if isMerchantCancel {
return 200, nil
}
return 0, nil
}
// 待调度
if statusList[i].VendorStatus == utils.Int2Str(mtpsapi.OrderStatusWaitingForSchedule) {