From 42213a4ff030f5382b09d2bc91c1ed692a915ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 5 Jun 2023 13:54:19 +0800 Subject: [PATCH] 1 --- .../jxcallback/scheduler/basesch/basesch.go | 27 +------------- .../scheduler/basesch/basesch_ext.go | 36 +++++++++++-------- .../jxcallback/scheduler/defsch/defsch.go | 1 + business/model/const.go | 2 ++ business/partner/delivery/dada/waybill.go | 15 +++++++- business/partner/delivery/fn/waybill.go | 16 ++++++++- business/partner/delivery/mtps/waybill.go | 19 ++++++++-- 7 files changed, 71 insertions(+), 45 deletions(-) diff --git a/business/jxcallback/scheduler/basesch/basesch.go b/business/jxcallback/scheduler/basesch/basesch.go index 81de0173c..37633da05 100644 --- a/business/jxcallback/scheduler/basesch/basesch.go +++ b/business/jxcallback/scheduler/basesch/basesch.go @@ -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 { diff --git a/business/jxcallback/scheduler/basesch/basesch_ext.go b/business/jxcallback/scheduler/basesch/basesch_ext.go index d9af0f538..374cdcad4 100644 --- a/business/jxcallback/scheduler/basesch/basesch_ext.go +++ b/business/jxcallback/scheduler/basesch/basesch_ext.go @@ -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 } diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index 540c53817..eb265e669 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -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 { diff --git a/business/model/const.go b/business/model/const.go index 151f5e790..29c29b26b 100644 --- a/business/model/const.go +++ b/business/model/const.go @@ -362,6 +362,8 @@ const ( WaybillStatusCanceled = 115 WaybillStatusFailed = 120 // 这个状态存在的意义是区分于WaybillStatusCanceled,比如达达平台在这种状态下再次创建运单的方式不一样 WaybillStatusEndEnd = 120 + + WaybillStatusCancel = 1150 // 115为取消,但是分不清是商户取消还是骑手取消!1150标志着商户取消记录 ) const ( diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index 9feea5a0e..54e099ce6 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -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) { diff --git a/business/partner/delivery/fn/waybill.go b/business/partner/delivery/fn/waybill.go index fa89e4f4d..ad0727bb7 100644 --- a/business/partner/delivery/fn/waybill.go +++ b/business/partner/delivery/fn/waybill.go @@ -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) { diff --git a/business/partner/delivery/mtps/waybill.go b/business/partner/delivery/mtps/waybill.go index cf1b24812..bdd90496b 100644 --- a/business/partner/delivery/mtps/waybill.go +++ b/business/partner/delivery/mtps/waybill.go @@ -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) {