From 476f8c09437e337841a0d1a2d5b77ef41af29fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 11 May 2023 10:58:50 +0800 Subject: [PATCH 01/52] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=A8=E5=BA=97?= =?UTF-8?q?=E5=8F=91=E5=8D=95=E5=92=8C=E5=93=81=E7=89=8C=E5=8F=91=E5=8D=95?= =?UTF-8?q?=E6=98=AF=E6=89=A3=E8=B4=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/bidding/logistics_Loading.go | 2 +- business/jxcallback/orderman/order.go | 88 +++----- .../jxcallback/scheduler/basesch/basesch.go | 37 ++-- .../scheduler/basesch/basesch_ext.go | 58 ++++-- .../jxcallback/scheduler/defsch/defsch.go | 30 ++- .../jxcallback/scheduler/defsch/defsch_ext.go | 190 ++++++++++-------- business/jxcallback/scheduler/scheduler.go | 1 + business/jxstore/cms/store.go | 8 - business/jxstore/cms/store_acct.go | 40 ++-- business/jxstore/misc/misc.go | 7 +- business/model/dao/dao_order.go | 10 +- business/model/dao/store.go | 15 +- business/model/error_code.go | 3 + business/model/store.go | 28 +-- business/partner/delivery/dada/waybill.go | 33 +++ business/partner/delivery/fn/waybill.go | 34 ++++ business/partner/delivery/jdeclp/waybill.go | 3 + business/partner/delivery/mtps/waybill.go | 3 + business/partner/delivery/rider.go | 2 +- business/partner/delivery/uupt/waybill.go | 4 + business/partner/partner_delivery.go | 10 +- business/partner/partner_store_acct.go | 13 +- .../purchase/jx/localjx/kuaishou_pay.go | 26 ++- business/partner/purchase/jx/localjx/order.go | 41 ++-- controllers/jx_order.go | 3 +- routers/router.go | 1 + 26 files changed, 417 insertions(+), 273 deletions(-) diff --git a/business/bidding/logistics_Loading.go b/business/bidding/logistics_Loading.go index 86378b1d6..3deda78ca 100644 --- a/business/bidding/logistics_Loading.go +++ b/business/bidding/logistics_Loading.go @@ -103,7 +103,7 @@ func LoadingLogistics(paramLogistic []*model.UpdateMaterialLogistic) []error { } // 获取当前订单运单状态 - wayBill, err := dao.GetWaybills(db, logistics.OrderId) + wayBill, err := dao.GetWaybills(db, logistics.OrderId, nil) if err != nil { errList = append(errList, err) continue diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 535c8cd89..511904858 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -262,9 +262,6 @@ func (c *OrderManager) OnOrderStatusChanged(vendorOrgCode string, orderStatus *m if err != nil { globals.SugarLogger.Debug("Get store Detail Err: ", err) } - - //门店发单的订单,取消后要退回配送费 - ResetCreateWaybillFee(db, order) } } @@ -453,71 +450,50 @@ func filterOrderInfo(order *model.GoodsOrder) { order.ConsigneeAddress = strings.ReplaceAll(order.ConsigneeAddress, "·", "") } -func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder) (err error) { +func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill) (err error) { if db == nil { db = dao.GetDB() } - store, _ := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, order.VendorOrgCode) - if store != nil && store.CreateDeliveryType == model.YES { // 门店发单(非京西品牌) - // 无运单不参与退款 - if order.VendorWaybillID == "" { - return err - } - // 自配送不参与退款 - if order.VendorOrderID == order.VendorWaybillID { - return err - } - // 获取运单记录 - orderStatusList, err := GetOrderStatusList2(order.VendorOrderID, order.VendorWaybillID, 2, order.WaybillVendorID) + if bill.WaybillVendorID != model.VendorIDMTPS && bill.WaybillVendorID != model.VendorIDDada && bill.WaybillVendorID != model.VendorIDFengNiao && bill.WaybillVendorID != model.VendorIDUUPT { + return nil + } + // 订单被取消了,所有运单应该也被取消了,检查是否退还配送费 + // 1.查询订单创建的所有运单,三方配送运单(达达,蜂鸟,uu,美团配送),平台自配送订单不参与 + if handlerInfo := partner.GetDeliveryPlatformFromVendorID(bill.WaybillVendorID); handlerInfo != nil { + deductFee, err := handlerInfo.Handler.GetDeliverLiquidatedDamages(bill.VendorOrderID, bill.VendorWaybillID) if err != nil { return err } - isRefund := false // 默认可以退费 - for _, v := range orderStatusList { - if order.WaybillVendorID == model.VendorIDMTPS && v.VendorStatus == "30" { - isRefund = true - break - } - if order.WaybillVendorID == model.VendorIDFengNiao && v.VendorStatus == "80" { - isRefund = true - break - } - if order.WaybillVendorID == model.VendorIDDada && v.VendorStatus == "3" { - isRefund = true - break - } + if deductFee == 0 { + return nil } - if isRefund { // 骑手已经到店了,无法退款 - return errors.New("骑手已到店,无法退款") - } + // 更新运单实际扣除费用 + bill.ActualFee = deductFee + dao.UpdateEntity(db, bill, "ActualFee") - // 获取品牌的支付记录 - orderBill, _ := dao.GetBrandBill(db, store.BrandID, order.VendorOrderID, 0, model.BrandBillFeeTypeDelivery, order.VendorWaybillID) - if len(orderBill) <= 0 { - return errors.New("无记录,不退款") + // 门店账户金额扣除 + store, _ := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, order.VendorOrgCode) + // 门店发单,扣除门店余额 + if store != nil && store.CreateDeliveryType == model.YES { + partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(deductFee), partner.StoreAcctTypeExpendCreateWaybillDeductFee, bill.VendorOrderID, bill.VendorWaybillID, 0) } - for _, v := range orderBill { - if v.BillType == model.BrandBillTypeIncome { // 已经退款了 - return errors.New("无法重复退款") + if store != nil && store.CreateDeliveryType == model.NO { + // 获取运单的支出记录 + orderBill, _ := dao.GetBrandBill(db, store.BrandID, order.VendorOrderID, model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorWaybillID) + if len(orderBill) == 0 { + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) + } else { + // 退回扣除的配送费 + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, orderBill[0].Price, model.BrandBillTypeIncome, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) + // 支出配送费违约金 + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) } } - - // 将支出记录修改为退款记录,支付类型为收入,且类型为三方配送时:退费 - newBill := &model.BrandBill{ - BrandID: store.BrandID, - Price: orderBill[0].Price, - BillType: model.BrandBillTypeIncome, - FeeType: model.BrandBillFeeTypeDelivery, - VendorOrderID: orderBill[0].VendorOrderID, - OrderID: orderBill[0].OrderID, - } - dao.WrapAddIDCULEntity(newBill, "系统退费") - err = dao.CreateEntity(db, newBill) - } + return err } @@ -1342,7 +1318,7 @@ func MergeJdsOrders(ctx *jxcontext.Context, vendorOrderIDs []string) (vendorOrde for _, order := range orders { var waybill *model.Waybill //将订单和运单取消 - waybills, err := dao.GetWaybills(db, order.VendorOrderID) + waybills, err := dao.GetWaybills(db, order.VendorOrderID, nil) if err != nil { return "", err } @@ -1475,7 +1451,7 @@ func TransferJdsOrder(ctx *jxcontext.Context, vendorOrderID string, storeID int) return "", fmt.Errorf("未查询到该订单商品!订单号:[%v]", vendorOrderID) } //将订单和运单取消 - waybills, err := dao.GetWaybills(db, vendorOrderID) + waybills, err := dao.GetWaybills(db, vendorOrderID, nil) if err != nil { return "", err } @@ -1656,7 +1632,7 @@ func SendJdwlForJdsOrder(ctx *jxcontext.Context, vendorOrderID string) (err erro return fmt.Errorf("订单当前状态不支持创建!") } waybill := &model.Waybill{} - waybills, err := dao.GetWaybills(db, vendorOrderID) + waybills, err := dao.GetWaybills(db, vendorOrderID, nil) if err != nil { return err } diff --git a/business/jxcallback/scheduler/basesch/basesch.go b/business/jxcallback/scheduler/basesch/basesch.go index 3e173dc8f..572e85dbc 100644 --- a/business/jxcallback/scheduler/basesch/basesch.go +++ b/business/jxcallback/scheduler/basesch/basesch.go @@ -216,28 +216,31 @@ func (c *BaseScheduler) CreateWaybill(platformVendorID int, order *model.GoodsOr // } storeDetail, _ := dao.GetStoreDetail(dao.GetDB(), jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, order.VendorOrgCode) - // 获取门店品牌余额 - storeAcct, err := cms.GetStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order)) // 获取门店余额 // 如果门店没钱,查看品牌,查询门店品牌id - result, err := partner.CurStoreAcctManager.GetBrandBalance(storeDetail.BrandID) // 品牌余额 - if err != nil { - return nil, err - } + //result, err := partner.CurStoreAcctManager.GetBrandBalance(storeDetail.BrandID) // 品牌余额 + //if err != nil { + // return nil, err + //} var balance int // 门店发单,如果是京西门店,直接使用京西余额,非京西门店使用门店余额,余额不足使用品牌余额! if order.CreateDeliveryType == model.YES { - 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 - } + storeAcct, err := cms.GetStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order)) // 获取门店余额 + if err != nil { + 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) } @@ -281,7 +284,7 @@ func (c *BaseScheduler) CancelWaybill(bill *model.Waybill, cancelReasonID int, c return err } order, _ := partner.CurOrderManager.LoadOrder(bill.VendorOrderID, bill.OrderVendorID) - return orderman.ResetCreateWaybillFee(nil, order) + return orderman.ResetCreateWaybillFee(nil, order, bill) }, "CancelWaybill bill:%v", bill); err == nil { bill.Status = model.WaybillStatusCanceled bill.DeliveryFlag |= model.WaybillDeliveryFlagMaskActiveCancel diff --git a/business/jxcallback/scheduler/basesch/basesch_ext.go b/business/jxcallback/scheduler/basesch/basesch_ext.go index 610d298c3..e8f991524 100644 --- a/business/jxcallback/scheduler/basesch/basesch_ext.go +++ b/business/jxcallback/scheduler/basesch/basesch_ext.go @@ -228,7 +228,7 @@ func (c *BaseScheduler) AgreeOrRefuseRefund(ctx *jxcontext.Context, afsOrderID s var ( db = dao.GetDB() ) - waybills, _ := dao.GetWaybills(db, order.VendorOrderID) + waybills, _ := dao.GetWaybills(db, order.VendorOrderID, nil) //美团的订单如果是同意全部退款,要取消所有三方运单并停止调度 if order.VendorID == model.VendorIDMTWM || order.VendorID == model.VendorIDJX || order.VendorID == model.VendorIDEBAI { var ( @@ -347,16 +347,23 @@ func (c *BaseScheduler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID st return err } -func (c *BaseScheduler) SetOrderWaybillTip(ctx *jxcontext.Context, vendorOrderID string, vendorID int, tipFee int64) (errCode string, err error) { +func (c *BaseScheduler) SetOrderWaybillTip(ctx *jxcontext.Context, vendorOrderID string, vendorID int, tipFee int64, isPay int) (errCode string, err error) { if order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, vendorID); err == nil { - if errCode, err = c.CheckStoreBalanceWithTip(ctx, order, tipFee); err == nil { + if errCode, err = c.CheckStoreBalanceWithTip(ctx, order, tipFee, isPay); err == nil { err = c.SetOrderWaybillTipByOrder(ctx, order, tipFee) } } return errCode, err } -func (c *BaseScheduler) CheckStoreBalanceWithTip(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee int64) (errCode string, err error) { +func (c *BaseScheduler) CheckStoreBalanceWithTip(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee int64, isPay int) (errCode string, err error) { + var ( + db = dao.GetDB() + ) + roundTipFee := tipFee / 100 * 100 + if roundTipFee != tipFee { + return model.ErrCodeOnePayTipFeeMore, fmt.Errorf("小费必须是1元的整数倍") + } if order.CreateDeliveryType == model.YES { //加小费只判断余额 storeAcct, err := cms.GetStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order)) @@ -366,10 +373,32 @@ func (c *BaseScheduler) CheckStoreBalanceWithTip(ctx *jxcontext.Context, order * if tipFee > int64(storeAcct.AccountBalance) { return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额不足,不能加小费!") } - if tipFee >= 1000 { - return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("小费单次加价金额大于十元") + if tipFee > 1000 { + return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("小费单次加价金额大于五元") + } + } else { + // 品牌发单 + storeDetail, err := dao.GetStoreDetail(db, order.JxStoreID, order.VendorID, order.VendorOrgCode) + if err != nil || storeDetail == nil { + return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("根据订单获取门店详情错误:%v", err) + } + + brandAcct, err := dao.GetBrandBalance(db, storeDetail.BrandID) + if err != nil { + return "", err + } + if tipFee > int64(brandAcct) { + return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("品牌账户余额不足,不能加小费!") + } + if tipFee > 1000 { + return model.ErrCodeOnePayTipFeeMore, fmt.Errorf("小费单次加价金额大于五元") } } + // 是否确认支付 + if isPay != model.YES { + return model.ErrCodeIsPaySure, fmt.Errorf("此订单已经支付小费[%d]元,本次增加小费[%d]元,总支出小费[%d]元", order.WaybillTipMoney/100, tipFee/100, order.WaybillTipMoney+tipFee/100) + } + return errCode, err } @@ -379,13 +408,6 @@ func isWaybillCanAddTip(waybill *model.Waybill) (isCan bool) { } func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee int64) (err error) { - roundTipFee := tipFee / 100 * 100 - if roundTipFee != tipFee { - return fmt.Errorf("小费必须是1元的整数倍") - } - if order.WaybillTipMoney >= tipFee { - return fmt.Errorf("当前小费已经是%s元,想要设置%s元", jxutils.IntPrice2StandardString(order.WaybillTipMoney), jxutils.IntPrice2StandardString(tipFee)) - } db := dao.GetDB() storeDetail, _ := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, "") flag := false @@ -396,7 +418,11 @@ func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order } else { //加小费成功扣钱 if order.CreateDeliveryType == model.YES { - if err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), 100, partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID, 0); err == nil { + if err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(tipFee), partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID, "", 0); err == nil { + flag = true + } + } else if order.CreateDeliveryType == model.NO { + if err = partner.CurStoreAcctManager.InsertBrandBill(ctx, storeDetail.BrandID, int(tipFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeTipFee, order.VendorOrderID, ""); err == nil { flag = true } } @@ -432,7 +458,9 @@ func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order if !flag { //加小费成功扣钱 if order.CreateDeliveryType == model.YES { - partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), 100, partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID, 0) + partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(tipFee), partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID, "", 0) + } else if order.CreateDeliveryType == model.NO { + partner.CurStoreAcctManager.InsertBrandBill(ctx, storeDetail.BrandID, int(tipFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeTipFee, order.VendorOrderID, "") } } } diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index 388b396bc..2216a0d95 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -2,6 +2,7 @@ package defsch import ( "fmt" + "git.rosy.net.cn/baseapi/platformapi/mtpsapi" "git.rosy.net.cn/jx-callback/business/jxutils/smsmsg" "math/rand" "strings" @@ -634,13 +635,19 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo //if bill.Status == model.WaybillStatusDelivering && order.VendorID == model.VendorIDJX && order.OrderType == model.OrderTypeNormal { // smsmsg.NotifyJxOrder(order, bill) //} - //扣除品牌费用 - if storeDetail, err2 := dao.GetStoreDetail(dao.GetDB(), jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, ""); err2 == nil { - if storeDetail.CreateDeliveryType == model.YES { - s.updateStoreAccount(order, bill) - } - if !model.IsWaybillPlatformOwn(bill) { - s.updateBrandAccount(storeDetail, bill) + // 当运单时三方配送时,美团状态20 + if bill.WaybillVendorID == model.VendorIDDada || bill.WaybillVendorID == model.VendorIDMTPS || bill.WaybillVendorID == model.VendorIDFengNiao || bill.WaybillVendorID == model.VendorIDUUPT { + if (bill.VendorStatus == utils.Int64ToStr(mtpsapi.OrderStatusPickedUp) && bill.OrderVendorID == model.VendorIDMTWM) || bill.Status == model.WaybillStatusCourierArrived { + if storeDetail, err2 := dao.GetStoreDetail(dao.GetDB(), jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, ""); err2 == nil { + if storeDetail.CreateDeliveryType == model.YES { + s.updateStoreAccount(order, bill) + } else { + s.updateBrandAccount(storeDetail, bill) + } + //if !model.IsWaybillPlatformOwn(bill) { + // s.updateBrandAccount(storeDetail, bill) + //} + } } } @@ -763,6 +770,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo // // s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) // globals.SugarLogger.Infof("OnWaybillStatusChanged Delivering order(%d, %s) bill(%d, %s), bill:%v shouldn't get here", order.WaybillVendorID, order.VendorWaybillID, bill.WaybillVendorID, bill.VendorWaybillID, bill) // } + case model.WaybillStatusDelivered: s.resetTimer(savedOrderInfo, bill, isPending) s.removeWaybillFromMap(savedOrderInfo, bill.WaybillVendorID) @@ -1439,10 +1447,10 @@ func (s *DefScheduler) updateStoreAccount(order *model.GoodsOrder, bill *model.W var diffFee int64 if lastFee64 > realDesiredFee { diffFee = lastFee64 - realDesiredFee - partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), int(diffFee), partner.StoreAcctTypeRealFeeIncome, order.VendorOrderID, expend.ID) + partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), int(diffFee), partner.StoreAcctTypeRealFeeIncome, order.VendorOrderID, bill.VendorWaybillID, expend.ID) } else { diffFee = realDesiredFee - lastFee64 - partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), int(diffFee), partner.StoreAcctTypeRealFeeExpend, order.VendorOrderID, expend.ID) + partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), int(diffFee), partner.StoreAcctTypeRealFeeExpend, order.VendorOrderID, "", expend.ID) } } } @@ -1460,6 +1468,10 @@ func (s *DefScheduler) updateBrandAccount(store *dao.StoreDetail, bill *model.Wa } if sum == 0 { partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(bill.DesiredFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, bill.VendorOrderID, bill.VendorWaybillID) + } else if bill.DesiredFee > int64(sum) { + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(bill.DesiredFee-int64(sum)), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, bill.VendorOrderID, bill.VendorWaybillID) + } else if bill.DesiredFee < int64(sum) { + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(int64(sum)-bill.DesiredFee), model.BrandBillTypeIncome, model.BrandBillFeeTypeDelivery, bill.VendorOrderID, bill.VendorWaybillID) } } } diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index 9a8c6eb06..f296e6cec 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -177,24 +177,20 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex // 获取门店品牌余额 storeAcct, err := cms.GetStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order)) // 获取门店余额 - // 如果门店没钱,查看品牌,查询门店品牌id - storeList, err := dao.GetStoreList(dao.GetDB(), []int{jxutils.GetSaleStoreIDFromOrder(order)}, nil, nil, nil, nil, "") - if err != nil || len(storeList) != 1 { - return nil, fmt.Errorf("门店id:[%d],所属品牌不唯一,或其他查询错误", order.JxStoreID) - } - result, err := dao.GetBrandBalance(dao.GetDB(), storeList[0].BrandID) // 品牌余额 + // 门店详细信息 + storeList, err := dao.GetStoreDetail(dao.GetDB(), jxutils.GetSaleStoreIDFromOrder(order), savedOrderInfo.order.VendorID, order.VendorOrgCode) if err != nil { return nil, err } - //门店发单开始扣钱 + deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID) + // 不管是门店发单还是品牌发单都要扣钱,门店发单扣门店,品牌发单扣品牌 if order.CreateDeliveryType == model.YES { - deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID) - // 运费相等为0或支出大于收入不做, - isEqual, isZero, _ := partner.CurStoreAcctManager.CheckStoreAcctExpendExist(order.VendorOrderID) - expend, lastFee, _ := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID) + // 获取平台配送费 + isEqual, isZero, _ := partner.CurStoreAcctManager.CheckStoreAcctExpendExist(order.VendorOrderID) // 当前订单的支出记录 + expend, lastFee, _ := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID) // 最后一个运单支出记录 // 收最贵的一个订单配送费(配送费发送变化,收取最贵的价格) - if !isZero && !isEqual { + if !isZero && !isEqual { // 满足此条件是,门店发单已经存在此订单的发单记录 var newPrice int64 if len(courierVendorIDs) == 1 { courierVendorID := courierVendorIDs[0] @@ -210,51 +206,45 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex } newPrice = maxFee } - // 门店支出运费 - if storeList[0].BrandID != scheduler.JXC4B_SHOP && storeList[0].BrandID != scheduler.JXC4B_RAND_JXGY { // 非京西品牌,先扣门店在扣品牌 + // 门店支出运费,门店发单 + if order.CreateDeliveryType == model.YES { if storeAcct.AccountBalance > int(newPrice) { if int(newPrice) > lastFee { // 门店支出费用 - partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(model.Waybill{}.DesiredFee), partner.StoreAcctTypeExpendCreateWaybill2ndMore, order.VendorOrderID, expend.ID) //int(newPrice)-lastFee + partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(newPrice)-lastFee, partner.StoreAcctTypeExpendCreateWaybill2ndMore, order.VendorOrderID, "", expend.ID) //int(newPrice)-lastFee } - } else if result > int(newPrice) { - // 品牌支出费用 - partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, storeList[0].BrandID, int(model.Waybill{}.DesiredFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorOrderID, order.VendorWaybillID) - } else { - return nil, fmt.Errorf("门店id:[%d],品牌id:[]%d,门店以及门店所属品牌余额不足,无法发单", order.JxStoreID, storeList[0].BrandID) } - } else { // 京西品牌 + } /*else { // 品牌发单,品牌支出运费 if storeAcct.AccountBalance > int(newPrice) { if int(newPrice) > lastFee { - // 门店支出费用 - partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(model.Waybill{}.DesiredFee), partner.StoreAcctTypeExpendCreateWaybill2ndMore, order.VendorOrderID, expend.ID) //int(newPrice)-lastFee + // 品牌支出费用 + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, storeList.BrandID, int(newPrice), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorOrderID, order.VendorWaybillID) } - } else { - return nil, fmt.Errorf("门店id:[%d],品牌id:[]%d,门店以及门店所属品牌余额不足,无法发单", order.JxStoreID, storeList[0].BrandID) } - } + }*/ - } else { + } else { // 新订单的发单记录,门店发单扣门店,品牌发单扣品牌 if len(courierVendorIDs) == 1 { courierVendorID := courierVendorIDs[0] if _, ok := deliveryFeeMap[courierVendorID]; ok { - if storeList[0].BrandID != scheduler.JXC4B_SHOP && storeList[0].BrandID != scheduler.JXC4B_RAND_JXGY { // 非京西品牌,先扣门店在扣品牌 - if storeAcct.AccountBalance > int(model.Waybill{}.DesiredFee) { - partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(model.Waybill{}.DesiredFee), partner.StoreAcctTypeExpendCreateWaybill2ndMore, order.VendorOrderID, expend.ID) //int(newPrice)-lastFee - } else if result > int(model.Waybill{}.DesiredFee) { - // 品牌支出费用 - partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, storeList[0].BrandID, int(model.Waybill{}.DesiredFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorOrderID, order.VendorWaybillID) - } else { - return nil, fmt.Errorf("门店id:[%d],品牌id:[]%d,门店以及门店所属品牌余额不足,无法发单", order.JxStoreID, storeList[0].BrandID) - } - } else { // 京西品牌 - if storeAcct.AccountBalance > int(model.Waybill{}.DesiredFee) { - // 门店支出费用 - partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(model.Waybill{}.DesiredFee), partner.StoreAcctTypeExpendCreateWaybill2ndMore, order.VendorOrderID, expend.ID) //int(newPrice)-lastFee - } else { - return nil, fmt.Errorf("门店id:[%d],品牌id:[]%d,门店以及门店所属品牌余额不足,无法发单", order.JxStoreID, storeList[0].BrandID) - } - } + //if storeList.BrandID != scheduler.JXC4B_SHOP && storeList.BrandID != scheduler.JXC4B_RAND_JXGY { // 非京西品牌,先扣门店在扣品牌 + //if storeAcct.AccountBalance > int(model.Waybill{}.DesiredFee) { + if order.CreateDeliveryType == model.YES { + err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(deliveryFeeMap[courierVendorID].DeliveryFee), partner.StoreAcctTypeExpendCreateWaybillEx, order.VendorOrderID, "", 0) //int(newPrice)-lastFee + globals.SugarLogger.Debugf("InsertStoreAcctExpendAndUpdateStoreAcctBalance 238 err := %v", err) + } /*else { + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, storeList.BrandID, int(bill.DesiredFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, bill.VendorOrderID, bill.VendorWaybillID) + }*/ + //} /*else if result > int(model.Waybill{}.DesiredFee) { + // 品牌支出费用 + // partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, storeList.BrandID, int(model.Waybill{}.DesiredFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorOrderID, order.VendorWaybillID) + //}*/ + //} else { // 京西品牌 + // if storeAcct.AccountBalance > int(model.Waybill{}.DesiredFee) { + // // 门店支出费用 + // partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(model.Waybill{}.DesiredFee), partner.StoreAcctTypeExpendCreateWaybill2ndMore, order.VendorOrderID, expend.ID) //int(newPrice)-lastFee + // } + //} } } else if len(courierVendorIDs) == 0 { var maxFee int64 @@ -263,12 +253,34 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex v.DeliveryFee = maxFee } } - partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(model.Waybill{}.DesiredFee), partner.StoreAcctTypeExpendCreateWaybillEx, order.VendorOrderID, 0) //int(maxFee) + err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(maxFee), partner.StoreAcctTypeExpendCreateWaybillEx, order.VendorOrderID, "", 0) //int(maxFee) + globals.SugarLogger.Debugf("InsertStoreAcctExpendAndUpdateStoreAcctBalance 260 err := %v", err) } } + } else { + // 看看此订单有无发单记录,小费记录 + // 品牌发单 + if len(courierVendorIDs) == 1 { + courierVendorID := courierVendorIDs[0] + if _, ok := deliveryFeeMap[courierVendorID]; ok { + err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, storeList.BrandID, int(deliveryFeeMap[courierVendorID].DeliveryFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorOrderID, order.VendorWaybillID) + } + } else if len(courierVendorIDs) == 0 { + var maxFee int64 + for _, v := range deliveryFeeMap { + if v.DeliveryFee > maxFee { + v.DeliveryFee = maxFee + } + } + err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, storeList.BrandID, int(maxFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorOrderID, order.VendorWaybillID) + globals.SugarLogger.Debugf("InsertStoreAcctExpendAndUpdateStoreAcctBalance 260 err := %v", err) + } + } - return bills, err + } + + return bills, err } } if err != nil { @@ -328,27 +340,54 @@ func (s *DefScheduler) CreateWaybillOnProvidersEx(ctx *jxcontext.Context, vendor } func (s *DefScheduler) CheckStoreBalance(ctx *jxcontext.Context, order *model.GoodsOrder, courierVendorIDs []int) (errCode string, err error) { - if order.CreateDeliveryType == model.YES { + var ( + db = dao.GetDB() + ) + deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID) + if err != nil { + return errCode, fmt.Errorf("获取订单配送费错误[%v]!", err) + } + + switch order.CreateDeliveryType { + case model.NO: // 品牌发单 + storeDetail, err := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, "") + if err != nil { + return "", err + } + brandAcct, err := dao.GetBrandBalance(db, storeDetail.BrandID) + if err != nil { + return "", err + } + + if len(courierVendorIDs) == 1 { + courierVendorID := courierVendorIDs[0] + if _, ok := deliveryFeeMap[courierVendorID]; ok { + if deliveryFeeMap[courierVendorID].DeliveryFee > int64(brandAcct) { + return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("品牌账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(deliveryFeeMap[courierVendorID].DeliveryFee)) + } + } + } else if len(courierVendorIDs) == 0 { + var maxFee int64 + for _, v := range deliveryFeeMap { + if v.DeliveryFee > maxFee { + v.DeliveryFee = maxFee + } + } + if maxFee > int64(brandAcct) { + return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("品牌账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(maxFee)) + } + } + + case model.YES: // 门店发单 //暂时这么认为,len courierVendorIDs 为1表示是老板或者运营从小程序上点的立即发单,因为小程序上是点哪个发哪个 //京西后台则是点一下发3个,len courierVendorIDs 是0 //如果是小程序上点哪个扣哪个平台的钱 //如果是后台,则选最高的那个扣 storeAcct, err := cms.GetStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order)) // 获取门店余额 - - // 如果门店没钱,查看品牌,查询门店品牌id - storeList, err := dao.GetStoreList(dao.GetDB(), []int{jxutils.GetSaleStoreIDFromOrder(order)}, nil, nil, nil, nil, "") - if err != nil || len(storeList) != 1 { - return "", fmt.Errorf("门店id:[%d],所属品牌不唯一,或其他查询错误", order.JxStoreID) - } - result, err := dao.GetBrandBalance(dao.GetDB(), storeList[0].BrandID) // 品牌余额 if err != nil { return "", err } - deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID) - if err != nil { - return errCode, fmt.Errorf("获取账户余额失败!") - } //1、先判断是不是第一次发:查询库里是否有这个订单的运费支出记录,再查询是否有相同金额并且类型为回退的收入记录(取消运单退回) //前者有,后者无, 表示已经发过了,暂未取消,若这这次的发单金额小于上次的金额则不进行判断也不多扣钱,若大于则扣除‘这次金额-上次金额’的钱,余额不足问题也根据这个判断 //前者有,后者有,表示发过并且取消过了,是多次发,直接扣 @@ -356,7 +395,7 @@ func (s *DefScheduler) CheckStoreBalance(ctx *jxcontext.Context, order *model.Go //2、小程序里这次金额用发单平台的金额,后台里这次金额用所有平台最高费用 isEqual, isZero, err := partner.CurStoreAcctManager.CheckStoreAcctExpendExist(order.VendorOrderID) //表示前者有,后者无 - if !isZero && !isEqual { + if !isZero && !isEqual { // 当前订单支出费用大于,退还费用 var newPrice int64 if len(courierVendorIDs) == 1 { courierVendorID := courierVendorIDs[0] @@ -375,28 +414,16 @@ func (s *DefScheduler) CheckStoreBalance(ctx *jxcontext.Context, order *model.Go _, lastFee, _ := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID) // 如果门店属于京西菜市,京西果园则只能扣门店的金额 if int(newPrice) > lastFee { - if storeList[0].BrandID == scheduler.JXC4B_RAND_JXGY || storeList[0].BrandID == scheduler.JXC4B_SHOP { // 订单所属门店属于京西菜市,果园,则不扣品牌只扣门店)(1果园,菜市,7京西超市) - if storeAcct.AccountBalance < int(newPrice)-lastFee { - return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店/品牌账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(newPrice-int64(lastFee))) - } - } else { - if storeAcct.AccountBalance < int(newPrice)-lastFee && result < int(newPrice)-lastFee { - return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店/品牌账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(newPrice-int64(lastFee))) - } + if storeAcct.AccountBalance < int(newPrice)-lastFee /*&& result < int(newPrice)-lastFee*/ { + return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(newPrice-int64(lastFee))) } } } else { if len(courierVendorIDs) == 1 { courierVendorID := courierVendorIDs[0] if _, ok := deliveryFeeMap[courierVendorID]; ok { - if storeList[0].BrandID == scheduler.JXC4B_RAND_JXGY || storeList[0].BrandID == scheduler.JXC4B_SHOP { // 订单所属门店属于京西菜市,果园,则不扣品牌只扣门店)(1果园,菜市,7京西超市) - if deliveryFeeMap[courierVendorID].DeliveryFee > int64(storeAcct.AccountBalance) { - return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店/品牌账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(partner.MinCreateWaybillBalance)) - } - } else { - if deliveryFeeMap[courierVendorID].DeliveryFee > int64(result) && deliveryFeeMap[courierVendorID].DeliveryFee > int64(storeAcct.AccountBalance) { - return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店/品牌 账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(deliveryFeeMap[courierVendorID].DeliveryFee)) - } + if deliveryFeeMap[courierVendorID].DeliveryFee > int64(storeAcct.AccountBalance) { + return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(deliveryFeeMap[courierVendorID].DeliveryFee)) } } } else if len(courierVendorIDs) == 0 { @@ -406,18 +433,15 @@ func (s *DefScheduler) CheckStoreBalance(ctx *jxcontext.Context, order *model.Go v.DeliveryFee = maxFee } } - if storeList[0].BrandID == scheduler.JXC4B_RAND_JXGY || storeList[0].BrandID == scheduler.JXC4B_SHOP { // 订单所属门店属于京西菜市,果园,则不扣品牌只扣门店)(1果园,菜市,7京西超市) - if maxFee > int64(storeAcct.AccountBalance) { - return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店/品牌账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(partner.MinCreateWaybillBalance)) - } - } else { - if maxFee > int64(result) && maxFee > int64(storeAcct.AccountBalance) { - return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店/品牌 账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(maxFee)) - } + if maxFee > int64(storeAcct.AccountBalance) { + return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(maxFee)) } } } + default: + return "", fmt.Errorf("不存在的订单发单类型,检查配置") } + return errCode, err } diff --git a/business/jxcallback/scheduler/scheduler.go b/business/jxcallback/scheduler/scheduler.go index a5c9e786a..2182752da 100644 --- a/business/jxcallback/scheduler/scheduler.go +++ b/business/jxcallback/scheduler/scheduler.go @@ -21,6 +21,7 @@ const ( const ( JXC4B_RAND_JXGY = 1 // 京西菜市和果园品牌id JXC4B_SHOP = 7 // 京西超市 + JXC4B_ZHIGONG = 8 // 京西直供 ) var ( diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index b4d4a9dbf..30a235188 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -4586,14 +4586,6 @@ func GetStoreAcctBalance(ctx *jxcontext.Context, storeID int) (storeAcct *model. }, err } -// func SendVendorStoreStatusChanged(ctx *jxcontext.Context) (err error) { -// var ( -// db = dao.GetDB() -// ) -// dao.GetStoresMapList(db, []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", "") -// return err -// } - func RefreshStoreBind(ctx *jxcontext.Context) (err error) { var ( db = dao.GetDB() diff --git a/business/jxstore/cms/store_acct.go b/business/jxstore/cms/store_acct.go index fffe3d757..583035836 100644 --- a/business/jxstore/cms/store_acct.go +++ b/business/jxstore/cms/store_acct.go @@ -23,7 +23,7 @@ func init() { partner.InitStoreAcctManager(FixedStoreAcctManager) } -func InsertStoreAcctIncome(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) { +func InsertStoreAcctIncome(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID, vendorWaybillId string, expendID int) (err error) { var ( userID, userName string goodsVendorOrderID string @@ -44,11 +44,12 @@ func InsertStoreAcctIncome(ctx *jxcontext.Context, storeID, price, acctType int, } } storeAcctIncome := &model.StoreAcctIncome{ - StoreID: storeID, - IncomePrice: price, - Type: acctType, - UserID: userID, - VendorOrderID: goodsVendorOrderID, + StoreID: storeID, + IncomePrice: price, + Type: acctType, + UserID: userID, + VendorOrderID: goodsVendorOrderID, + VendorWaybillID: vendorWaybillId, } dao.WrapAddIDCULEntity(storeAcctIncome, userName) if expendID != 0 { @@ -58,7 +59,7 @@ func InsertStoreAcctIncome(ctx *jxcontext.Context, storeID, price, acctType int, return err } -func InsertStoreAcctExpend(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) { +func InsertStoreAcctExpend(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID, vendorWaybillId string, expendID int) (err error) { var ( userID, userName string db = dao.GetDB() @@ -76,11 +77,12 @@ func InsertStoreAcctExpend(ctx *jxcontext.Context, storeID, price, acctType int, } } storeAcctExpend := &model.StoreAcctExpend{ - StoreID: storeID, - ExpendPrice: price, - Type: acctType, - UserID: userID, - VendorOrderID: vendorOrderID, + StoreID: storeID, + ExpendPrice: price, + Type: acctType, + UserID: userID, + VendorOrderID: vendorOrderID, + VendorWaybillID: vendorWaybillId, } dao.WrapAddIDCULEntity(storeAcctExpend, userName) if expendID != 0 { @@ -132,18 +134,18 @@ func (s *StoreAcctManager) UpdateStoreAcctBalance(ctx *jxcontext.Context, storeI } // 门店到账(老版本,修改门店的交易记录) -func (s *StoreAcctManager) InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) { +func (s *StoreAcctManager) InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID, vendorWaybillID string, expendID int) (err error) { utils.CallFuncAsync(func() { - if err = InsertStoreAcctExpend(ctx, storeID, price, acctType, vendorOrderID, expendID); err == nil { + if err = InsertStoreAcctExpend(ctx, storeID, price, acctType, vendorOrderID, vendorWaybillID, expendID); err == nil { s.UpdateStoreAcctBalance(ctx, storeID, price, false) } }) return err } -func (s *StoreAcctManager) InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) { +func (s *StoreAcctManager) InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID, vendorWaybillID string, expendID int) (err error) { utils.CallFuncAsync(func() { - if err = InsertStoreAcctIncome(ctx, storeID, price, acctType, vendorOrderID, expendID); err == nil { + if err = InsertStoreAcctIncome(ctx, storeID, price, acctType, vendorOrderID, vendorWaybillID, expendID); err == nil { s.UpdateStoreAcctBalance(ctx, storeID, price, true) } }) @@ -156,9 +158,9 @@ func (s *StoreAcctManager) CheckStoreAcctExpendExist(vendorOrderID string) (isEq expends, incomes int db = dao.GetDB() ) - // 发单扣除的临时运费 - expends, err = dao.GetStoreAcctExpendTotal(db, 0, []int{partner.StoreAcctTypeExpendCreateWaybillEx, partner.StoreAcctTypeRealFeeExpend}, vendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) - // 真实运费 < 临时运费, 临时运费-真实运费的值 + // 当前订单的支出金额(临时运费+真实运费)[小费] + expends, err = dao.GetStoreAcctExpendTotal(db, 0, []int{partner.StoreAcctTypeExpendCreateWaybillEx, partner.StoreAcctTypeExpendCreateWaybillTip, partner.StoreAcctTypeExpendCreateWaybill2ndMore, partner.StoreAcctTypeExpendCreateWaybillDeductFee, partner.StoreAcctTypeRealFeeExpend}, vendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) + // 当前订单的退费金额() incomes, err = dao.GetStoreAcctIncomeTotal(db, 0, []int{partner.StoreAcctTypeRealFeeIncome, partner.StoreAcctTypeIncomeCancelTemp, partner.StoreAcctTypeIncomeCancelReal}, vendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) if expends != incomes { if expends > incomes { diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 33c0fa3fa..2655ebd7b 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -199,6 +199,7 @@ func Init() { orderman.UpdateTiktokShopTotalMoney() }, []string{ "03:35:00", + "09:35:00", }) // 每分钟轮询一次,推送抖店骑手信息 @@ -593,8 +594,8 @@ func syncStoreSku() { tasksch.HandleTask(task, nil, true).Run() } -var storeIds = []int{ - 668802, 668787, 668785, 668777, 668769, 668776, 668770, 668760, 668758, 668756, 668748, 668727, 668723, 300372, 668715, 668717, 668707, 668667, 668668, 800306, 668628, 668681, 668673, 668544, 668619, 668614, 668600, 102217, 667405, 100988, 668353, 103022, 668283, 667208, 668266, 102101, 100610, 103201, 103459, 667154, 102691, 666747, 103417, 666744, 666864, 102186, 667271, 101750, 101031, 667452, 666942, 666927, 100068, 668339, 668306, 668310, 667352, 102544, 667014, 102280, 667134, 102945, 103062, 102443, 668218, 666913, 102742, 668360, 102851, 668580, 667252, 666746, 100455, 667037, 667317, 667473, 666816, 103063, 666800, 668210, 103079, 668200, 668176, 667462, 102426, 667116, 668309, 100193, 666828, 666944, 102852, 666900, 668521, 668373, 102596, 668444, 667071, 668264, 668395, 668090, 102172, 102790, 101935, 667480, 102479, 103197, 102703, 668386, 668229, 666948, 101008, 668249, 102374, 667464, 668468, 102490, 666756, 102976, 667467, 666707, 668270, 667429, 103098, 668135, 668523, 666907, 668407, 668358, 668385, 101134, 100887, 668568, 668003, 101763, 100829, 667476, 101078, 668099, 668503, 666807, 100167, 100433, 668107, 667262, 100849, 102771, 667173, 666847, 667485, 102821, 666955, 101107, 667229, 102950, 103435, 102497, 666916, 668163, 668061, 102147, 668248, 667066, 102853, 667944, 100002, 102865, 668219, 100184, 666840, 667057, 668202, 102223, 667101, 667128, 101110, 668511, 103151, 667093, 668154, 666905, 668268, 666929, 102935, 102074, 668174, 668217, 102350, 666940, 102980, 668117, 668384, 100067, 101916, 102987, 667250, 668570, 667466, 101099, 667082, 100229, 667553, 100215, 667991, 100217, 103073, 103074, 103037, 668180, 668583, 668462, 667891, 666811, 666736, 668173, 100267, 102962, 102752, 668284, 667296, 668175, 667806, 103103, 103084, 668453, 102970, 103184, 668548, 101036, 668182, 668157, 668257, 668166, 668543, 668170, 668071, 667744, 102925, 100115, 668093, 667745, 668164, 668156, 667743, 668165, 103408, 103038, 667268, 667094, 667321, 100726, 102333, 666742, 101775, 100028, 668304, 667305, 101942, 668575, 101755, 103425, 102833, 100699, 103190, 666711, 668396, 100334, 102533, 100336, 101995, 102320, 101842, 102519, 101999, 102433, 100920, 102594, 102951, 668506, 666667, 102963, 300034, 667212, 100236, 101909, 668541, 102857, 668417, 102955, 103031, 668545, 666790, 100328} +//var storeIds = []int{ +// 668802, 668787, 668785, 668777, 668769, 668776, 668770, 668760, 668758, 668756, 668748, 668727, 668723, 300372, 668715, 668717, 668707, 668667, 668668, 800306, 668628, 668681, 668673, 668544, 668619, 668614, 668600, 102217, 667405, 100988, 668353, 103022, 668283, 667208, 668266, 102101, 100610, 103201, 103459, 667154, 102691, 666747, 103417, 666744, 666864, 102186, 667271, 101750, 101031, 667452, 666942, 666927, 100068, 668339, 668306, 668310, 667352, 102544, 667014, 102280, 667134, 102945, 103062, 102443, 668218, 666913, 102742, 668360, 102851, 668580, 667252, 666746, 100455, 667037, 667317, 667473, 666816, 103063, 666800, 668210, 103079, 668200, 668176, 667462, 102426, 667116, 668309, 100193, 666828, 666944, 102852, 666900, 668521, 668373, 102596, 668444, 667071, 668264, 668395, 668090, 102172, 102790, 101935, 667480, 102479, 103197, 102703, 668386, 668229, 666948, 101008, 668249, 102374, 667464, 668468, 102490, 666756, 102976, 667467, 666707, 668270, 667429, 103098, 668135, 668523, 666907, 668407, 668358, 668385, 101134, 100887, 668568, 668003, 101763, 100829, 667476, 101078, 668099, 668503, 666807, 100167, 100433, 668107, 667262, 100849, 102771, 667173, 666847, 667485, 102821, 666955, 101107, 667229, 102950, 103435, 102497, 666916, 668163, 668061, 102147, 668248, 667066, 102853, 667944, 100002, 102865, 668219, 100184, 666840, 667057, 668202, 102223, 667101, 667128, 101110, 668511, 103151, 667093, 668154, 666905, 668268, 666929, 102935, 102074, 668174, 668217, 102350, 666940, 102980, 668117, 668384, 100067, 101916, 102987, 667250, 668570, 667466, 101099, 667082, 100229, 667553, 100215, 667991, 100217, 103073, 103074, 103037, 668180, 668583, 668462, 667891, 666811, 666736, 668173, 100267, 102962, 102752, 668284, 667296, 668175, 667806, 103103, 103084, 668453, 102970, 103184, 668548, 101036, 668182, 668157, 668257, 668166, 668543, 668170, 668071, 667744, 102925, 100115, 668093, 667745, 668164, 668156, 667743, 668165, 103408, 103038, 667268, 667094, 667321, 100726, 102333, 666742, 101775, 100028, 668304, 667305, 101942, 668575, 101755, 103425, 102833, 100699, 103190, 666711, 668396, 100334, 102533, 100336, 101995, 102320, 101842, 102519, 101999, 102433, 100920, 102594, 102951, 668506, 666667, 102963, 300034, 667212, 100236, 101909, 668541, 102857, 668417, 102955, 103031, 668545, 666790, 100328} func syncStoreSkuTiktok() { //syncFlag := 0 | model.SyncFlagSaleMask @@ -609,7 +610,7 @@ func syncStoreSkuTiktok() { if beego.BConfig.RunMode != "jxgy" { errList.AddErr(cms.DeleteSkuNameExPrefixOverdue(db)) errList.AddErr(cms.SetMultiStoreSkuSyncModifyStatus(db, partner.GetMultiStoreVendorIDs())) - _, err = cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, nil, 0, db, []int{model.VendorIDDD}, storeIds, false, nil, nil, syncFlag, true, true) + _, err = cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, nil, 0, db, []int{model.VendorIDDD}, nil, false, nil, nil, syncFlag, true, true) errList.AddErr(err) } case 1: diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 749211ec9..a50b9c593 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -1466,13 +1466,17 @@ func GetOrdersForJxPay(db *DaoDB, finishTimeBegin, finishTimeEnd time.Time) (goo return goods, err } -func GetWaybills(db *DaoDB, vendorOrderID string) (waybills []*model.Waybill, err error) { +func GetWaybills(db *DaoDB, vendorOrderID string, vendors []int64) (waybills []*model.Waybill, err error) { sql := ` SELECT * FROM waybill - WHERE vendor_order_id = ? ORDER BY waybill_created_at asc + WHERE vendor_order_id = ? ` - + if len(vendors) > model.NO { + sql += " AND waybill_vendor_id IN (" + GenQuestionMarks(len(vendors)) + ")" + } + sql += ` ORDER BY waybill_created_at asc` sqlParams := []interface{}{vendorOrderID} + sqlParams = append(sqlParams, vendors) err = GetRows(db, &waybills, sql, sqlParams) return waybills, err } diff --git a/business/model/dao/store.go b/business/model/dao/store.go index 35ed12a53..57fcf38a0 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -3,6 +3,7 @@ package dao import ( "errors" "fmt" + "git.rosy.net.cn/jx-callback/business/partner" "sort" "strings" "time" @@ -29,7 +30,7 @@ type StoreDetail struct { PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格 PricePercentagePackStr string `orm:"size(4096)" json:"-"` // PricePercentagePackObj model.PricePercentagePack `orm:"-" json:"-"` - CreateDeliveryType int `orm:"default(0)" json:"createDeliveryType"` //默认0系统发单,1为门店发单 + CreateDeliveryType int `orm:"default(0)" json:"createDeliveryType"` //默认0系统(品牌)发单,1为门店发单 FreightDeductionPackStr string `orm:"size(4096)" json:"-"` // FreightDeductionPackObj *model.FreightDeductionPack `orm:"-" json:"-"` @@ -1162,11 +1163,11 @@ func GetStoreAcctExpendTotal(db *DaoDB, storeID int, expendTypes []int, vendorOr type GetStoreAcctExpendLastCreateWayBillFeeResult struct { ID int `orm:"column(id)" json:"id"` - ExpID int `orm:"column(exp_id)" json:"expID"` //少扣的钱 - IncID int `orm:"column(inc_id)" json:"incID"` //多扣的钱 - ExpendPrice int `json:"expendPrice"` - MulitExpendPrice int `json:"mulitExpendPrice"` - MulitIncomePrice int `json:"mulitIncomePrice"` + ExpID int `orm:"column(exp_id)" json:"expID"` // 支出记录id(金额补充) + IncID int `orm:"column(inc_id)" json:"incID"` // 退费记录id(金额退款) + ExpendPrice int `json:"expendPrice"` // 运单支出金额 + MulitExpendPrice int `json:"mulitExpendPrice"` // 运单补充金额 + MulitIncomePrice int `json:"mulitIncomePrice"` // 运单退还金额 } func GetStoreAcctExpendLastCreateWayBillFee(db *DaoDB, vendorOrderID string) (expend *GetStoreAcctExpendLastCreateWayBillFeeResult, lastFee int, err error) { @@ -1180,7 +1181,7 @@ func GetStoreAcctExpendLastCreateWayBillFee(db *DaoDB, vendorOrderID string) (ex AND a.type = ? ` sqlParams := []interface{}{ - 20, + partner.StoreAcctTypeExpendCreateWaybillEx, } if vendorOrderID != "" { sql += " AND a.vendor_order_id = ?" diff --git a/business/model/error_code.go b/business/model/error_code.go index b5136c777..e5531c93a 100644 --- a/business/model/error_code.go +++ b/business/model/error_code.go @@ -20,6 +20,9 @@ const ( ErrCodeAccountBalanceNotEnough = "-201" //余额不足 ErrCodeNotAuthBindWeixin = "-202" //没有绑定微信认证方式 + + ErrCodeOnePayTipFeeMore = "10001" // 单次支付金额太多 + ErrCodeIsPaySure = "10000" // 是否确认支付 ) var ( diff --git a/business/model/store.go b/business/model/store.go index 90c634612..2693232e1 100644 --- a/business/model/store.go +++ b/business/model/store.go @@ -29,6 +29,8 @@ const ( BrandBillFeeTypeVoice = 4 //语音费用 BrandBillFeeTypeDelivery = 5 //三方配送费 BrandBillFeeTypeSecretNumber = 6 //隐私号电话 + BrandBillFeeTypeTipFee = 7 //小费 + BrandBillFeeTypeDeductFee = 8 //取消三方配送违约金 BrandOpenMTPS = 1 //品牌开关标志, 美团配送 BrandOpenDaDa = 2 //达达 @@ -904,12 +906,13 @@ func (*BrandStore) TableUnique() [][]string { type StoreAcctIncome struct { ModelIDCUL - StoreID int `orm:"column(store_id)" json:"storeID"` //门店ID - VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` - UserID string `orm:"column(user_id)" json:"userID"` //用户ID (谁消费的) - ExpID int `orm:"column(exp_id)" json:"expID"` //用于关联多退少补的金额是对应哪一笔收入(支出) - Type int `json:"type"` //收入类型 - IncomePrice int `json:"incomePrice"` //收入金额 + StoreID int `orm:"column(store_id)" json:"storeID"` //门店ID + VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` + VendorWaybillID string `orm:"column(vendor_waybill_id);size(48)" json:"vendorWaybillID"` // 运单id + UserID string `orm:"column(user_id)" json:"userID"` //用户ID (谁消费的) + ExpID int `orm:"column(exp_id)" json:"expID"` //用于关联多退少补的金额是对应哪一笔收入(支出) + Type int `json:"type"` //收入类型 + IncomePrice int `json:"incomePrice"` //收入金额 } func (v *StoreAcctIncome) TableIndex() [][]string { @@ -923,12 +926,13 @@ func (v *StoreAcctIncome) TableIndex() [][]string { type StoreAcctExpend struct { ModelIDCUL - StoreID int `orm:"column(store_id)" json:"storeID"` //门店ID - VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` - UserID string `orm:"column(user_id)" json:"userID"` //用户ID (谁消费的) - ExpID int `orm:"column(exp_id)" json:"expID"` //用于关联多退少补的金额是对应哪一笔收入(支出) - Type int `json:"type"` //支出类型 - ExpendPrice int `json:"expendPrice"` //支出金额 + StoreID int `orm:"column(store_id)" json:"storeID"` //门店ID + VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` // 订单id + VendorWaybillID string `orm:"column(vendor_waybill_id);size(48)" json:"vendorWaybillID"` // 运单id + UserID string `orm:"column(user_id)" json:"userID"` //用户ID (谁消费的) + ExpID int `orm:"column(exp_id)" json:"expID"` //用于关联多退少补的金额是对应哪一笔收入(支出) + Type int `json:"type"` //支出类型 + ExpendPrice int `json:"expendPrice"` //支出金额 } func (v *StoreAcctExpend) TableIndex() [][]string { diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index c47d3eee9..20c2eea9e 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "git.rosy.net.cn/baseapi/platformapi/mtpsapi" + "time" "git.rosy.net.cn/baseapi/platformapi/dadaapi" "git.rosy.net.cn/baseapi/utils" @@ -540,3 +541,35 @@ func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeiso } return result, nil } + +// GetDeliverLiquidatedDamages 获取达达平台扣除配送费 +// 待接单,待取货(小于一分钟,大于十五分钟)不扣钱 +// 待取货1-15分钟内取消扣两元 +func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) { + dadaOrder, err := api.DadaAPI.QueryOrderInfo(orderId) + if err != nil { + return 0, err + } + + // 未接单不扣款 + if dadaOrder.AcceptTime == "" { + return 0, nil + } + + // 有了接单时间,订单变成了待取货 + if dadaOrder.AcceptTime != "" && dadaOrder.FetchTime == "" { + nowTime := time.Now().Unix() + fetchTime := utils.Str2Time(dadaOrder.AcceptTime).Unix() + timeDiffer := nowTime - fetchTime + if timeDiffer > 15*60 || timeDiffer < 60 { + return 0, nil + } + return 200, nil + } + + if dadaOrder.FetchTime != "" { + return jxutils.StandardPrice2Int(dadaOrder.ActualFee), nil + } + + return 0, err +} diff --git a/business/partner/delivery/fn/waybill.go b/business/partner/delivery/fn/waybill.go index bed1375d1..7a632e46a 100644 --- a/business/partner/delivery/fn/waybill.go +++ b/business/partner/delivery/fn/waybill.go @@ -114,6 +114,7 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee ReceiverPrimaryPhone: order.ConsigneeMobile, OutShopCode: utils.Int2Str(order.JxStoreID), ChainStoreId: "", + SerialNumber: fmt.Sprintf("%s #%d", model.VendorChineseNames[order.VendorID], order.OrderSeq), } // 重量超标减少配送费 weight := 4.9500 @@ -380,3 +381,36 @@ func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeiso return result, nil } + +// GetDeliverLiquidatedDamages 获取运单取消违约金 +// 蜂鸟:骑手接单后-取餐之前,每单扣除2元,超过20分钟不扣款 +func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) { + // 获取订单状态 + order, err := api.FnAPI.QueryOrder(orderId) + if err != nil { + return 0, err + } + + // 已经分配骑手,且超过十五分钟,不扣款 + if len(order.EventLogDetails) != model.NO { + for i := len(order.EventLogDetails) - 1; i >= 0; i-- { + switch order.EventLogDetails[i].OrderStatus { + case fnpsapi.OrderStatusDelivered, fnpsapi.OrderStatusArrived, fnpsapi.OrderStatusDelivering: // 送达,到店,配送中 取消订单全额扣款 + return order.OrderActualAmountCent, nil + case fnpsapi.OrderStatusAcceptCacle, fnpsapi.OrderStatusException: // 取消和异常状态,跳过查看上一状态 + continue + case fnpsapi.OrderStatusAcceptCreate, fnpsapi.OrderStatusAccept: // 生成运单和系统接单取消不扣除费用 + return 0, nil + case fnpsapi.OrderStatusAssigned: + if time.Now().UnixNano()/1e6-order.EventLogDetails[i].OccurTime > fnpsapi.WayBillPressureOrderTime { + return 0, nil + } else { + return 200, nil + } + } + } + + } + + return 0, err +} diff --git a/business/partner/delivery/jdeclp/waybill.go b/business/partner/delivery/jdeclp/waybill.go index f2c8a7386..75ff86e9b 100644 --- a/business/partner/delivery/jdeclp/waybill.go +++ b/business/partner/delivery/jdeclp/waybill.go @@ -107,3 +107,6 @@ func (c *DeliveryHandler) ComplaintRider(bill *model.Waybill, resonID int, reson func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeisongId string) (rider *mtpsapi.RiderInfo, err error) { return nil, nil } +func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) { + return 0, err +} diff --git a/business/partner/delivery/mtps/waybill.go b/business/partner/delivery/mtps/waybill.go index 6c45aefed..ddc0f2073 100644 --- a/business/partner/delivery/mtps/waybill.go +++ b/business/partner/delivery/mtps/waybill.go @@ -483,3 +483,6 @@ func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeiso return result, nil } +func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) { + return 0, err +} diff --git a/business/partner/delivery/rider.go b/business/partner/delivery/rider.go index 01a479019..ebbca2e90 100644 --- a/business/partner/delivery/rider.go +++ b/business/partner/delivery/rider.go @@ -96,7 +96,7 @@ func GetOrderRiderInfoToPlatform(orderId string, wayBillStatus int) { } if orderId == "" { // 订单id为空是,是定时轮询操作,不做此状态 - waybillList, _ := dao.GetWaybills(dao.GetDB(), v.VendorOrderID) + waybillList, _ := dao.GetWaybills(dao.GetDB(), v.VendorOrderID, nil) if len(waybillList) > 0 && waybillList[0].Status > model.WaybillStatusEndBegin { globals.SugarLogger.Debugf("订单物流状态结束,不在推送订单状态:orderID[%s],wayBillId[%s]", v.VendorOrderID, waybillList[0].VendorWaybillID) continue diff --git a/business/partner/delivery/uupt/waybill.go b/business/partner/delivery/uupt/waybill.go index a2f0cadfc..635801492 100644 --- a/business/partner/delivery/uupt/waybill.go +++ b/business/partner/delivery/uupt/waybill.go @@ -240,6 +240,10 @@ func (d DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeison return param, nil } +func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) { + return api.UuAPI.GetOrderLiquidatedDamages(deliverId, orderId) +} + //辅助函数 func getOrderPrice(order *model.GoodsOrder) (orderPrice *uuptapi.GetOrderPriceResp, err error) { store, err := dao.GetStoreDetail(dao.GetDB(), getReallyStoreID(order.StoreID, order.JxStoreID), 0, "") diff --git a/business/partner/partner_delivery.go b/business/partner/partner_delivery.go index 55e89d65e..378fcfe82 100644 --- a/business/partner/partner_delivery.go +++ b/business/partner/partner_delivery.go @@ -40,8 +40,16 @@ type IDeliveryPlatformHandler interface { GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo *WaybillFeeInfo, err error) //投诉骑手 ComplaintRider(bill *model.Waybill, resonID int, resonContent string) (err error) - // 获取骑手信息 + // GetRiderInfo 获取骑手信息 GetRiderInfo(orderId string, deliveryId int64, mtPeisongId string) (rider *mtpsapi.RiderInfo, err error) + // 三方配送时,呼叫骑手在取消.可能存在违约赔付!获取每单的违约金额! + // 蜂鸟:骑手接单后-取餐之前,每单扣除2元,超过20分钟不扣款 + // 达达:骑手接单后-到店之前,接单1-15分钟内,扣款2元,超过不扣款 + // uu :接单后超过一定时间取消会产生违约金,取消后扣除费用退回剩余订单金额 + // 美团配送: 暂无 + + // GetDeliverLiquidatedDamages 获取配送单的违约金:京西订单id:orderId,配送方id:deliverId + GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) } type IDeliveryUpdateStoreHandler interface { diff --git a/business/partner/partner_store_acct.go b/business/partner/partner_store_acct.go index a1932c6b7..cd6bcad4b 100644 --- a/business/partner/partner_store_acct.go +++ b/business/partner/partner_store_acct.go @@ -13,10 +13,11 @@ const ( StoreAcctTypeIncomeCancelReal = 19 //运单取消,回退的真实运费 //账户支出类型 - StoreAcctTypeExpendCreateWaybillEx = 20 //发单扣除的临时运费 - StoreAcctTypeExpendCreateWaybillTip = 21 //手动加小费扣除 - StoreAcctTypeExpendCreateWaybill2ndMore = 22 //第二次发运单,并且比上次需要更多钱扣的差价 - StoreAcctTypeRealFeeExpend = 25 //真实运费 > 临时运费, 真实运费的值 - 临时运费的值 + StoreAcctTypeExpendCreateWaybillEx = 20 //发单扣除的临时运费 + StoreAcctTypeExpendCreateWaybillTip = 21 //手动加小费扣除 + StoreAcctTypeExpendCreateWaybill2ndMore = 22 //第二次发运单,并且比上次需要更多钱扣的差价 + StoreAcctTypeExpendCreateWaybillDeductFee = 23 //运单取消的违约金 + StoreAcctTypeRealFeeExpend = 25 //真实运费 > 临时运费, 真实运费的值 - 临时运费的值 ) const ( @@ -38,8 +39,8 @@ type IStoreAcctManager interface { //InsertStoreAcctExpend(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) //更新门店账户 UpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price int, isIncome bool) (err error) - InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) - InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string, expendID int) (err error) + InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID, vendorWaybillID string, expendID int) (err error) + InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID, vendOrderID string, expendID int) (err error) CheckStoreAcctExpendExist(vendorOrderID string) (isEqual, isZero bool, err error) GetStoreAcctExpendLastCreateWayBillFee(vendorOrderID string) (expend *dao.GetStoreAcctExpendLastCreateWayBillFeeResult, lastFee int, err error) diff --git a/business/partner/purchase/jx/localjx/kuaishou_pay.go b/business/partner/purchase/jx/localjx/kuaishou_pay.go index 6a54e5e3a..12c6ff47c 100644 --- a/business/partner/purchase/jx/localjx/kuaishou_pay.go +++ b/business/partner/purchase/jx/localjx/kuaishou_pay.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "git.rosy.net.cn/baseapi/platformapi/kuaishou_mini" + beego "github.com/astaxie/beego/server/web" "strings" "time" @@ -39,22 +40,27 @@ func pay4OrderByKs(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp } param := &kuaishou_mini.PreCreateOrderReq{ - OutOrderNo: utils.Int64ToStr(GenPayOrderID(order)), - OpenId: authBindList[0].AuthID, - TotalAmount: order.ActualPayPrice, - Subject: "蔬菜水果日用品", - Detail: getOrderBriefKs(order), - TypeDetail: 1832, // 蔬菜:费率2%,水果:1833%2 - ExpireTime: 60 * 10, - Sign: "", - Attach: "", - NotifyUrl: "http://callback.jxc4.com/kuaishou/KuaiShouCallback", + OutOrderNo: utils.Int64ToStr(GenPayOrderID(order)), + OpenId: authBindList[0].AuthID, + TotalAmount: order.ActualPayPrice, + Subject: "蔬菜水果日用品", + Detail: getOrderBriefKs(order), + TypeDetail: 1832, // 蔬菜:费率2%,水果:1833%2 + ExpireTime: 60 * 10, + Sign: "", + Attach: "", + //NotifyUrl: "https://callback.jxc4.com/kuaishou/kuaiShouCallback", GoodsId: "", GoodsDetailUrl: "", MultiCopiesGoodsInfo: "", CancelOrder: 0, } + if beego.BConfig.RunMode == "jxgy" { + param.NotifyUrl = "https://callback-jxgy.jxc4.com/kuaishou/kuaiShouCallback" + } else { + param.NotifyUrl = "https://callback.jxc4.com/kuaishou/kuaiShouCallback" + } // 预下单 prePayInfo, err := api.KuaiShouApi.PreCreateOrder(param) if err == nil { diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index a28d6fb04..59a2ff9cc 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -406,7 +406,7 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType dao.UpdateEntity(db, userMemberOrigin, "EndAt") } } - case model.PayTypeTL_StoreAcctPay: + case model.PayTypeTL_StoreAcctPay: // 门店账户充值 storeOrder := &model.StoreAcctOrder{ VendorOrderID: vendorOrderID, } @@ -421,7 +421,7 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType err = dao.CreateEntity(dao.GetDB(), orderPay) } } - case model.PayTypeTL_BrandBillCharge: + case model.PayTypeTL_BrandBillCharge: // 品牌账户充值 brandOrder := &model.BrandOrder{ VendorOrderID: vendorOrderID, } @@ -546,9 +546,11 @@ func GetAvailableDeliverTime(ctx *jxcontext.Context, storeID int) (deliverTimerL func OnPayFinished(orderPay *model.OrderPay) (err error) { // 查询订单是购物订单还是充值订单 + var ( + db = dao.GetDB() + ) order, err := partner.CurOrderManager.LoadOrder(orderPay.VendorOrderID, orderPay.VendorID) if err == nil { - db := dao.GetDB() dao.UpdateEntity(db, orderPay) if count, err2 := dao.GetJxOrderCount(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorOrderID, order.OrderCreatedAt); err2 == nil { order.OrderSeq = count + 1 @@ -584,44 +586,41 @@ func OnPayFinished(orderPay *model.OrderPay) (err error) { } else { switch orderPay.PayType { case model.PayTypeTL_DiscountCard: - userMembers, _ := dao.GetUserMember(dao.GetDB(), "", orderPay.VendorOrderID, "", model.VendorIDJX, model.MemberTypeDiscountCard, model.NO) + userMembers, _ := dao.GetUserMember(db, "", orderPay.VendorOrderID, "", model.VendorIDJX, model.MemberTypeDiscountCard, model.NO) if len(userMembers) > 0 { userMembers[0].IsPay = model.YES - dao.UpdateEntity(dao.GetDB(), userMembers[0], "IsPay") + dao.UpdateEntity(db, userMembers[0], "IsPay") err = nil } case model.PayTypeTL_StoreAcctPay: //门店账户充值完成后直接入账 storeOrder := &model.StoreAcctOrder{ VendorOrderID: orderPay.VendorOrderID, } - if err = dao.GetEntity(dao.GetDB(), storeOrder, "VendorOrderID"); err == nil && storeOrder.ID != 0 { + if err = dao.GetEntity(db, storeOrder, "VendorOrderID"); err == nil && storeOrder.ID != 0 { storeOrder.OrderFinishedAt = time.Now() storeOrder.Status = model.OrderStatusFinished - if _, err = dao.UpdateEntity(dao.GetDB(), storeOrder, "OrderFinishedAt", "Status"); err == nil { - // 获取门店的品牌ID - storeBrandId, err := GetStoreAcctOrderByVendorId(orderPay.VendorOrderID) - if err != nil { - return err - } - partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, storeBrandId, storeOrder.ActualPayPrice, model.BrandBillFeeTypeSys, model.BrandBillFeeTypeSys, "", "") + _, err = dao.UpdateEntity(db, storeOrder, "OrderFinishedAt", "Status") + if err != nil { + return err } + partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), storeOrder.ActualPayPrice, partner.StoreAcctTypeIncomePay, order.VendorOrderID, order.VendorWaybillID, 0) } - case model.PayTypeTL_BrandBillCharge: + case model.PayTypeTL_BrandBillCharge: // 品牌充值入账 brandOrder := &model.BrandOrder{ VendorOrderID: orderPay.VendorOrderID, } - if err = dao.GetEntity(dao.GetDB(), brandOrder, "VendorOrderID"); err == nil && brandOrder.ID != 0 { + if err = dao.GetEntity(db, brandOrder, "VendorOrderID"); err == nil && brandOrder.ID != 0 { brandOrder.OrderFinishedAt = time.Now() brandOrder.Status = model.OrderStatusFinished - if _, err = dao.UpdateEntity(dao.GetDB(), brandOrder, "OrderFinishedAt", "Status"); err == nil { + if _, err = dao.UpdateEntity(db, brandOrder, "OrderFinishedAt", "Status"); err == nil { partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, brandOrder.BrandID, brandOrder.ActualPayPrice, model.BrandBillTypeIncome, model.BrandBillFeeTypeCharge, orderPay.VendorOrderID, "") } } default: - priceDefendOrders, _ := dao.GetPriceDefendOrder(dao.GetDB(), orderPay.VendorOrderID, nil, nil, []int{jxutils.GetDefendPriceIssue()}, 0, -1, -1, 0, "", utils.ZeroTimeValue, utils.ZeroTimeValue, false) + priceDefendOrders, _ := dao.GetPriceDefendOrder(db, orderPay.VendorOrderID, nil, nil, []int{jxutils.GetDefendPriceIssue()}, 0, -1, -1, 0, "", utils.ZeroTimeValue, utils.ZeroTimeValue, false) if len(priceDefendOrders) > 0 { priceDefendOrders[0].IsPay = model.YES - dao.UpdateEntity(dao.GetDB(), priceDefendOrders[0], "IsPay") + dao.UpdateEntity(db, priceDefendOrders[0], "IsPay") err = nil } } @@ -1823,7 +1822,7 @@ func RefreshAllMatterOrderStatus(ctx *jxcontext.Context) (err error) { }() vv.Status = model.OrderStatusFinished dao.UpdateEntity(db, vv, "Status") - waybills, err := dao.GetWaybills(db, vv.VendorOrderID) + waybills, err := dao.GetWaybills(db, vv.VendorOrderID, nil) if err == nil && len(waybills) > 0 { waybills[0].Status = model.WaybillStatusDelivered dao.UpdateEntity(db, waybills[0], "Status") @@ -1939,7 +1938,7 @@ func updateMatterOrderStatus(db *dao.DaoDB, order *model.GoodsOrder, queryOrderS }() order.Status = model.OrderStatusFinished dao.UpdateEntity(db, order, "Status") - waybills, err := dao.GetWaybills(db, order.VendorOrderID) + waybills, err := dao.GetWaybills(db, order.VendorOrderID, nil) if err == nil && len(waybills) > 0 { waybills[0].Status = model.WaybillStatusDelivered dao.UpdateEntity(db, waybills[0], "Status") @@ -1977,7 +1976,7 @@ func updateJdWayBillInfo(db *dao.DaoDB, order *model.GoodsOrder, getTrackMessage break } } - waybills, err = dao.GetWaybills(db, order.VendorOrderID) + waybills, err = dao.GetWaybills(db, order.VendorOrderID, nil) if len(waybills) > 0 { waybills[0].VendorWaybillID = waybillCode waybills[0].CourierName = cName diff --git a/controllers/jx_order.go b/controllers/jx_order.go index 2549f1536..c0239ce03 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -243,12 +243,13 @@ func (c *OrderController) GetOrderWaybillInfo() { // @Param vendorOrderID formData string true "订单ID" // @Param vendorID formData int true "订单所属的厂商ID" // @Param tipFee formData int true "小费" +// @Param isPay formData int false "是否确认支付[1是]" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /UpdateOrderWaybillTip [post] func (c *OrderController) UpdateOrderWaybillTip() { c.callUpdateOrderWaybillTip(func(params *tOrderUpdateOrderWaybillTipParams) (retVal interface{}, errCode string, err error) { - errCode, err = defsch.FixedScheduler.SetOrderWaybillTip(params.Ctx, params.VendorOrderID, params.VendorID, int64(params.TipFee)) + errCode, err = defsch.FixedScheduler.SetOrderWaybillTip(params.Ctx, params.VendorOrderID, params.VendorID, int64(params.TipFee), params.IsPay) return retVal, "", err }) } diff --git a/routers/router.go b/routers/router.go index 2554e47ab..c90263650 100644 --- a/routers/router.go +++ b/routers/router.go @@ -197,6 +197,7 @@ func init() { web.AutoRouter(&controllers.TiktokController{}) // 订单 web.AutoRouter(&controllers.TiktokShopController{}) // 门店授权 web.AutoRouter(&controllers.LogisticsController{}) // 抖音快递信息同步 + web.AutoRouter(&controllers.KuaiShouController{}) // 快手支付回调 //web.AutoRouter(&controllers.IMController{}) //im // 如下都是用于检测存活的空接口 From 1c9760b540dc7116728cbb23f25157df7f951cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 15 May 2023 09:32:02 +0800 Subject: [PATCH 02/52] 1 --- .../jxcallback/auto_delivery/auto_delivery.go | 16 ++++++++++++---- .../scheduler/basesch/basesch_ext.go | 2 ++ .../jxcallback/scheduler/defsch/defsch_ext.go | 5 +++-- business/jxstore/misc/misc.go | 2 +- business/jxutils/smsmsg/smsmsg.go | 15 +++++++++++++-- business/model/api_config.go | 7 ++++--- business/model/dao/place.go | 14 ++++++++++++++ business/partner/delivery/fn/waybill.go | 18 ++++++++++-------- business/partner/delivery/mtps/waybill.go | 2 ++ business/partner/delivery/rider.go | 1 + business/partner/delivery/uupt/waybill.go | 6 ++++++ business/partner/partner_delivery.go | 8 ++++---- business/partner/partner_store_acct.go | 2 ++ 13 files changed, 74 insertions(+), 24 deletions(-) diff --git a/business/jxcallback/auto_delivery/auto_delivery.go b/business/jxcallback/auto_delivery/auto_delivery.go index 424a6bccb..a5e1057e8 100644 --- a/business/jxcallback/auto_delivery/auto_delivery.go +++ b/business/jxcallback/auto_delivery/auto_delivery.go @@ -90,6 +90,8 @@ func AutoSettingFakeDelivery() { return } + // todo 修改刷单门店配置 storeId-vendorId 指定刷单门店和平台 0京东/1美团/3饿了么/14抖音/99全部平台 + // 获取刷单门店订单 orderList, err := dao.GetOrderListByStoreList(db, utils.StringSlice2Int64(strings.Split(configList[0].Value, ","))) if err != nil { @@ -101,19 +103,26 @@ func AutoSettingFakeDelivery() { } for _, v := range orderList { - //jxutils.CallMsgHandler(func() { // 1.根据订单客户地址获取骑手列表 riderKey := "" - if strings.Contains(v.ConsigneeAddress, "重庆") || strings.Contains(v.ConsigneeAddress, "上海") || strings.Contains(v.ConsigneeAddress, "北京") { + if strings.Contains(v.ConsigneeAddress, "重庆") || strings.Contains(v.ConsigneeAddress, "上海") || strings.Contains(v.ConsigneeAddress, "北京") || strings.Contains(v.ConsigneeAddress, "天津") { riderKey = strings.Split(v.ConsigneeAddress, "市")[0] } else if strings.Contains(v.ConsigneeAddress, "省") { riderKey = strings.Split(v.ConsigneeAddress, "省")[0] } else { storeDetail, _ := dao.GetStoreDetail(db, v.JxStoreID, 0, "") - if strings.Contains(storeDetail.Address, "重庆") || strings.Contains(storeDetail.Address, "上海") || strings.Contains(storeDetail.Address, "北京") { + if strings.Contains(storeDetail.Address, "重庆") || strings.Contains(storeDetail.Address, "上海") || strings.Contains(storeDetail.Address, "北京") || strings.Contains(storeDetail.Address, "天津") { riderKey = strings.Split(storeDetail.Address, "市")[0] } else { riderKey = strings.Split(storeDetail.Address, "省")[0] + if riderKey == "" { + place, err := dao.GetParentCodeByCode(db, storeDetail.CityCode) + if err != nil { + globals.SugarLogger.Debugf("根据门店的城市code获取省份code错误: %s", err) + return + } + riderKey = place.Name[0 : len(place.Name)-3] + } } } @@ -160,6 +169,5 @@ func AutoSettingFakeDelivery() { break } } - //}, jxutils.ComposeUniversalOrderID(v.VendorOrderID, model.VendorIDDD)) } } diff --git a/business/jxcallback/scheduler/basesch/basesch_ext.go b/business/jxcallback/scheduler/basesch/basesch_ext.go index e8f991524..9bb020e8b 100644 --- a/business/jxcallback/scheduler/basesch/basesch_ext.go +++ b/business/jxcallback/scheduler/basesch/basesch_ext.go @@ -43,6 +43,8 @@ func (c *BaseScheduler) CreateWaybillOnProviders(ctx *jxcontext.Context, order * // 创建运单 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 diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index f296e6cec..287bc3c4a 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -81,7 +81,7 @@ func (s *DefScheduler) SelfDeliveringAndUpdateStatus(ctx *jxcontext.Context, ven } // 上面是真的转自送,支持美团,饿百,京东,如果时抖店,抖店暂时全部是自送的!但是有骑手信息时,就是一个白嫖单子! - if (order.VendorID == model.VendorIDDD || order.VendorID == model.VendorIDEBAI) && courierName != "" && courierMobile != "" && err == nil { + if courierName != "" && courierMobile != "" && err == nil { timeNow := time.Now() rand.Seed(timeNow.UnixNano()) randNumber := rand.Int63n(640) @@ -108,7 +108,7 @@ func (s *DefScheduler) SelfDeliveringAndUpdateStatus(ctx *jxcontext.Context, ven WaybillFinishedAt: utils.DefaultTimeValue, StatusTime: timeNow.Add(randTime), // 下一状态时间 OriginalData: "", - Remark: "自定义物流单(抖音/饿了么)", + Remark: "自定义物流单(全平台刷单)", VendorOrgCode: order.VendorOrgCode, } err = dao.CreateEntity(dao.GetDB(), bill) @@ -524,6 +524,7 @@ func (s *DefScheduler) QueryOrderWaybillFeeInfoEx(ctx *jxcontext.Context, vendor ErrStr: err.Error(), } } else { + feeInfo.DeliveryFee += model.WayBillDeliveryMarkUp // 加收两毛 feeInfo.TimeoutSecond = timeoutSecond } } else { diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 2655ebd7b..e124bf8e2 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -207,7 +207,7 @@ func Init() { delivery.UpdateFakeWayBillToTiktok() }, 10*time.Second, 5*time.Second) - // 抖音自动刷单 + // 抖音自动刷单(自动发单拣货,设置骑手) ScheduleTimerFuncByInterval(func() { if beego.BConfig.RunMode != "jxgy" { auto_delivery.AutoSettingFakeDelivery() diff --git a/business/jxutils/smsmsg/smsmsg.go b/business/jxutils/smsmsg/smsmsg.go index 8b8f2f231..970accba3 100644 --- a/business/jxutils/smsmsg/smsmsg.go +++ b/business/jxutils/smsmsg/smsmsg.go @@ -126,9 +126,20 @@ func NotifyPickOrder(order *model.GoodsOrder) (err error) { } updateSth := func(order *model.GoodsOrder, store *dao.StoreDetail, feeType int) (err error) { order.NotifyType = int(store.SMSNotify) - err = partner.CurOrderManager.UpdateOrderFields(order, []string{"NotifyType"}) + partner.CurOrderManager.UpdateOrderFields(order, []string{"NotifyType"}) //品牌余额, 一条5分 - err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, 5, model.BrandBillTypeExpend, feeType, order.VendorOrderID, "") + if order.CreateDeliveryType == model.YES { // 门店发单 + noticeType := 0 + switch feeType { + case model.BrandBillFeeTypeSms: + noticeType = partner.StoreAcctTypeExpendTextMessageNotify + case model.BrandBillFeeTypeVoice: + noticeType = partner.StoreAcctTypeExpendVoiceMessageNotify + } + err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, 5, noticeType, order.VendorOrderID, "", 0) + } else if order.CreateDeliveryType == model.NO { // 品牌发单 + err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, 5, model.BrandBillTypeExpend, feeType, order.VendorOrderID, "") + } return err } balance, _ := partner.CurStoreAcctManager.GetBrandBalance(store.BrandID) diff --git a/business/model/api_config.go b/business/model/api_config.go index 298283ac0..65a202e27 100644 --- a/business/model/api_config.go +++ b/business/model/api_config.go @@ -57,9 +57,10 @@ const ( VendorIDDDH5MicroApp = 311 // 钉钉H5微应用 VendorIDDDMobileQRCode = 312 // 钉钉移动接入应用(登录) - VendorIDAutonavi = 321 // 高德导航 - VendorIDQiNiuCloud = 323 // 七牛云 - VendorIDShowAPI = 325 // 万维易源 + VendorIDAutonavi = 321 // 高德导航 + VendorIDQiNiuCloud = 323 // 七牛云 + VendorIDShowAPI = 325 // 万维易源 + WayBillDeliveryMarkUp = 20 // 运单加价两毛钱 // 美团配送门店配送方式 MTWMStorePSWay1 = "1003" //美团跑腿(众包) diff --git a/business/model/dao/place.go b/business/model/dao/place.go index c98dbf68e..9b862a4b2 100644 --- a/business/model/dao/place.go +++ b/business/model/dao/place.go @@ -41,6 +41,20 @@ func GetPlacesByCond(db *DaoDB, enableCond int) (placeList []*model.Place, err e return placeList, err } +// GetParentCodeByCode 根据城市code获取省份code +func GetParentCodeByCode(db *DaoDB, code int) (*model.Place, error) { + sql := ` + SELECT p1.* FROM place p1 + INNER JOIN place p2 On p1.code = p2.parent_code + WHERE p2.code = ? ` + + place := &model.Place{} + if err := GetRow(db, place, sql, []interface{}{code}...); err != nil { + return nil, err + } + return place, nil +} + func GetPlaceByName(db *DaoDB, name string, level int, parentCode int) (place *model.Place, err error) { if db == nil { db = GetDB() diff --git a/business/partner/delivery/fn/waybill.go b/business/partner/delivery/fn/waybill.go index 7a632e46a..53b6df5d9 100644 --- a/business/partner/delivery/fn/waybill.go +++ b/business/partner/delivery/fn/waybill.go @@ -146,13 +146,15 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee } // 查询订单获取配送费 + desireFee, actualFee := GetDesiredFee(order.VendorOrderID) bill = &model.Waybill{ VendorOrderID: order.VendorOrderID, OrderVendorID: order.VendorID, VendorWaybillID: fnOrderId, VendorWaybillID2: order.VendorOrderID, WaybillVendorID: model.VendorIDFengNiao, - DesiredFee: GetDesiredFee(order.VendorOrderID), + DesiredFee: desireFee, + ActualFee: actualFee, } delivery.OnWaybillCreated(bill) return bill, err @@ -193,7 +195,7 @@ func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInf preCreateOrder.GoodsItemList = goodsList deliveryFeeInfo = &partner.WaybillFeeInfo{} - deliveryFeeInfo.RefDeliveryFee, deliveryFeeInfo.RefAddFee, err = api.FnAPI.PreCreateByShopFn(preCreateOrder) + deliveryFeeInfo.RefDeliveryFee, deliveryFeeInfo.RefAddFee, err = api.FnAPI.PreCreateByShopFn(preCreateOrder) // deliveryFeeInfo.DeliveryFee = deliveryFeeInfo.RefDeliveryFee return deliveryFeeInfo, err } @@ -229,14 +231,14 @@ func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify) (resp *fnpsapi.CallbackRespon orderStatus := utils.Str2Int64(order.VendorStatus) switch orderStatus { case fnpsapi.OrderStatusAcceptCreate, fnpsapi.OrderStatusAccept: // 0 创建订单 - order.DesiredFee = GetDesiredFee(order.VendorOrderID) + order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID) order.Status = model.WaybillStatusNew //5 带调度 case fnpsapi.OrderStatusAssigned: //20分配骑手 - order.DesiredFee = GetDesiredFee(order.VendorOrderID) + order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID) order.Status = model.WaybillStatusCourierAssigned //12 order.Remark = order.CourierName + "," + order.CourierMobile case fnpsapi.OrderStatusArrived: // 80 到店 - order.DesiredFee = GetDesiredFee(order.VendorOrderID) + order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID) order.Status = model.WaybillStatusCourierArrived case fnpsapi.OrderStatusDelivering: // 2 配送中 order.Status = model.WaybillStatusDelivering @@ -320,11 +322,11 @@ func (c *DeliveryHandler) OnWaybillExcept(msg *fnpsapi.AbnormalReportNotify) (re } // 查询订单配送费 -func GetDesiredFee(vendorOrderID string) (desiredFee int64) { +func GetDesiredFee(vendorOrderID string) (desiredFee, acuteFee int64) { if result, err := api.FnAPI.QueryOrder(vendorOrderID); err == nil { - return result.OrderActualAmountCent + return result.OrderActualAmountCent, result.OrderTotalAmountCent } - return desiredFee + return desiredFee, acuteFee } // 获取骑手信息 diff --git a/business/partner/delivery/mtps/waybill.go b/business/partner/delivery/mtps/waybill.go index ddc0f2073..9e00782ed 100644 --- a/business/partner/delivery/mtps/waybill.go +++ b/business/partner/delivery/mtps/waybill.go @@ -92,6 +92,7 @@ func (c *DeliveryHandler) onWaybillMsg(msg *mtpsapi.CallbackOrderMsg) (retVal *m return mtpsapi.Err2CallbackResponse(err, fmt.Sprintf("%s", "获取订单状态错误")) } order.DesiredFee = utils.Float64TwoInt64(utils.MustInterface2Float64(data["delivery_fee"]) * 100) + order.ActualFee = utils.Float64TwoInt64(utils.MustInterface2Float64(data["pay_amount"]) * 100) order.Status = model.WaybillStatusNew case mtpsapi.OrderStatusAccepted: // 已接单 data, err := api.MtpsAPI.QueryOrderStatus(msg.DeliveryID, msg.MtPeisongID) @@ -99,6 +100,7 @@ func (c *DeliveryHandler) onWaybillMsg(msg *mtpsapi.CallbackOrderMsg) (retVal *m return mtpsapi.Err2CallbackResponse(err, fmt.Sprintf("%s", "获取订单状态错误")) } order.DesiredFee = utils.Float64TwoInt64(utils.MustInterface2Float64(data["delivery_fee"]) * 100) + order.ActualFee = utils.Float64TwoInt64(utils.MustInterface2Float64(data["pay_amount"]) * 100) order.Status = model.WaybillStatusCourierAssigned order.Remark = order.CourierName + "," + order.CourierMobile case mtpsapi.OrderStatusPickedUp: // 已取货 diff --git a/business/partner/delivery/rider.go b/business/partner/delivery/rider.go index 59706748c..b720c4285 100644 --- a/business/partner/delivery/rider.go +++ b/business/partner/delivery/rider.go @@ -354,6 +354,7 @@ func UpdateFakeWayBillToTiktok() { LogisticsStatus: fakeWayBill[i].Status, } + // 设置骑手和下一状态时间 makeRiderInfo(fakeWayBill[i], riderInfo) if riderInfo.LogisticsContext != model.RiderGetOrderDeliverFailed && riderInfo.LogisticsContext != model.RiderGetOrderDeliverOther && riderInfo.LogisticsContext != model.RiderWaitRider { diff --git a/business/partner/delivery/uupt/waybill.go b/business/partner/delivery/uupt/waybill.go index 635801492..9154c31f5 100644 --- a/business/partner/delivery/uupt/waybill.go +++ b/business/partner/delivery/uupt/waybill.go @@ -317,22 +317,28 @@ func OnWaybillMsg(req *uuptapi.WaybillCallbackParam) (resp *uuptapi.CallbackResp case uuptapi.StateConfirmSuccess: param.Status = model.WaybillStatusNew //5 待调度 param.DesiredFee = reallyPrice + param.ActualFee = reallyPrice case uuptapi.StateRMGrabsOrder: param.Status = model.WaybillStatusCourierAssigned param.Remark = req.DriverName + "," + req.DriverMobile param.DesiredFee = reallyPrice + param.ActualFee = reallyPrice case uuptapi.StateArrivedStore: param.Status = model.WaybillStatusCourierArrived param.DesiredFee = reallyPrice + param.ActualFee = reallyPrice case uuptapi.StatePickUp: param.Status = model.WaybillStatusUuPickUp param.DesiredFee = reallyPrice + param.ActualFee = reallyPrice case uuptapi.StateArrivedDestination: param.Status = model.WaybillStatusUuArrivedDestination param.DesiredFee = reallyPrice + param.ActualFee = reallyPrice case uuptapi.StateReceiverGetGoods: param.Status = model.WaybillStatusDelivered param.DesiredFee = reallyPrice + param.ActualFee = reallyPrice case uuptapi.StateOrderCancel: param.Status = model.WaybillStatusCanceled default: diff --git a/business/partner/partner_delivery.go b/business/partner/partner_delivery.go index 378fcfe82..59ed20cc3 100644 --- a/business/partner/partner_delivery.go +++ b/business/partner/partner_delivery.go @@ -18,10 +18,10 @@ const ( type WaybillFeeInfo struct { ErrCode int `json:"errCode"` ErrStr string `json:"errStr"` - RefDeliveryFee int64 `json:"refDeliveryFee"` // 无用,待删除 - RefAddFee int64 `json:"refAddFee"` // 无用,待删除 - DeliveryFee int64 `json:"deliveryFee"` - TimeoutSecond int `json:"timeoutSecond"` // 系统会自动发运单的倒计时 + RefDeliveryFee int64 `json:"refDeliveryFee"` // 优惠后 + RefAddFee int64 `json:"refAddFee"` // 原始配送费 + DeliveryFee int64 `json:"deliveryFee"` // 优惠后 + TimeoutSecond int `json:"timeoutSecond"` // 系统会自动发运单的倒计时 Waybill *model.Waybill `json:"waybill"` } diff --git a/business/partner/partner_store_acct.go b/business/partner/partner_store_acct.go index cd6bcad4b..e186236df 100644 --- a/business/partner/partner_store_acct.go +++ b/business/partner/partner_store_acct.go @@ -17,6 +17,8 @@ const ( StoreAcctTypeExpendCreateWaybillTip = 21 //手动加小费扣除 StoreAcctTypeExpendCreateWaybill2ndMore = 22 //第二次发运单,并且比上次需要更多钱扣的差价 StoreAcctTypeExpendCreateWaybillDeductFee = 23 //运单取消的违约金 + StoreAcctTypeExpendTextMessageNotify = 24 //短信通知扣费 + StoreAcctTypeExpendVoiceMessageNotify = 26 //电话通知扣费 StoreAcctTypeRealFeeExpend = 25 //真实运费 > 临时运费, 真实运费的值 - 临时运费的值 ) From 8ba382e33f2142ae668e33fab87cdd42377be471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 15 May 2023 10:26:01 +0800 Subject: [PATCH 03/52] 1 --- business/jxstore/cms/user2.go | 2 +- business/model/dao/store.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index 7cf8b5e65..f51492527 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -412,7 +412,7 @@ func CreateUser(user *model.User, creatorName string) (err error) { } //支付宝注册电话需要解密 if user.GetMobile() != "" && user.GetName() != "" && user.GetID2() != "" { - if user.LastLoginType != "" && user.LastLoginType == alipay.AuthType { + if user.LastLoginType == alipay.AuthType { mobile := &alipayapi.KeyMobile{} data, _ := base64.StdEncoding.DecodeString(user.GetMobile()) key, _ := base64.StdEncoding.DecodeString(alipay.AuthKey) diff --git a/business/model/dao/store.go b/business/model/dao/store.go index c60404c91..0022599b9 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -3,7 +3,6 @@ package dao import ( "errors" "fmt" - "git.rosy.net.cn/jx-callback/business/partner" "sort" "strings" "time" @@ -1181,7 +1180,7 @@ func GetStoreAcctExpendLastCreateWayBillFee(db *DaoDB, vendorOrderID string) (ex AND a.type = ? ` sqlParams := []interface{}{ - partner.StoreAcctTypeExpendCreateWaybillEx, + 20, // partner.StoreAcctTypeExpendCreateWaybillEx 零食运费 } if vendorOrderID != "" { sql += " AND a.vendor_order_id = ?" From d3a35713cdce847937e15fe672425194219883db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 15 May 2023 11:42:19 +0800 Subject: [PATCH 04/52] 1 --- business/partner/purchase/jx/localjx/order.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index 59a2ff9cc..6c8db1282 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -422,7 +422,7 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType } } case model.PayTypeTL_BrandBillCharge: // 品牌账户充值 - brandOrder := &model.BrandOrder{ + brandOrder := &model.StoreAcctOrder{ VendorOrderID: vendorOrderID, } if err = dao.GetEntity(db, brandOrder, "VendorOrderID"); err == nil && brandOrder.ID != 0 { @@ -606,14 +606,15 @@ func OnPayFinished(orderPay *model.OrderPay) (err error) { partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), storeOrder.ActualPayPrice, partner.StoreAcctTypeIncomePay, order.VendorOrderID, order.VendorWaybillID, 0) } case model.PayTypeTL_BrandBillCharge: // 品牌充值入账 - brandOrder := &model.BrandOrder{ + brandOrder := &model.StoreAcctOrder{ VendorOrderID: orderPay.VendorOrderID, } if err = dao.GetEntity(db, brandOrder, "VendorOrderID"); err == nil && brandOrder.ID != 0 { brandOrder.OrderFinishedAt = time.Now() brandOrder.Status = model.OrderStatusFinished if _, err = dao.UpdateEntity(db, brandOrder, "OrderFinishedAt", "Status"); err == nil { - partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, brandOrder.BrandID, brandOrder.ActualPayPrice, model.BrandBillTypeIncome, model.BrandBillFeeTypeCharge, orderPay.VendorOrderID, "") + store, _ := dao.GetStoreDetail(db, brandOrder.StoreID, 0, "") + partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, brandOrder.ActualPayPrice, model.BrandBillTypeIncome, model.BrandBillFeeTypeCharge, orderPay.VendorOrderID, "") } } default: @@ -840,7 +841,7 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64 if jxOrder.OrderType != model.OrderTypeMatter || (jxOrder.OrderType == model.OrderTypeMatter && fromStoreID == -1) { outJxOrder.Skus = append(outJxOrder.Skus, jxSku) outJxOrder.OrderPrice += int64(jxSku.Count) * jxSku.SalePrice - } else { //以下else为物料订单袋子金额和数量处理 + } else { //以下else为物料订单袋子金额和数量处理 if !result.Flag { //只要flag是false就按原价申请,是true再按订单量 outJxOrder.Skus = append(outJxOrder.Skus, jxSku) outJxOrder.OrderPrice += int64(jxSku.Count) * jxSku.SalePrice From 6b0110d49f442a36cefc3c0aac41d95924fd2717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 15 May 2023 11:56:46 +0800 Subject: [PATCH 05/52] 1 --- business/partner/purchase/jx/localjx/order.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index 6c8db1282..cc4ba9cda 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -603,7 +603,7 @@ func OnPayFinished(orderPay *model.OrderPay) (err error) { if err != nil { return err } - partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), storeOrder.ActualPayPrice, partner.StoreAcctTypeIncomePay, order.VendorOrderID, order.VendorWaybillID, 0) + partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, storeOrder.StoreID, storeOrder.ActualPayPrice, partner.StoreAcctTypeIncomePay, order.VendorOrderID, order.VendorWaybillID, 0) } case model.PayTypeTL_BrandBillCharge: // 品牌充值入账 brandOrder := &model.StoreAcctOrder{ From 82caa218f26ad48ec9bfe100365ed95c7c4d84d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 15 May 2023 14:03:35 +0800 Subject: [PATCH 06/52] 1 --- business/partner/purchase/jx/localjx/order.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index cc4ba9cda..475c1d10b 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -603,7 +603,7 @@ func OnPayFinished(orderPay *model.OrderPay) (err error) { if err != nil { return err } - partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, storeOrder.StoreID, storeOrder.ActualPayPrice, partner.StoreAcctTypeIncomePay, order.VendorOrderID, order.VendorWaybillID, 0) + partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, storeOrder.StoreID, storeOrder.ActualPayPrice, partner.StoreAcctTypeIncomePay, storeOrder.VendorOrderID, "", 0) } case model.PayTypeTL_BrandBillCharge: // 品牌充值入账 brandOrder := &model.StoreAcctOrder{ From b8626bbb8223d730a29718f999528b13d351113a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 15 May 2023 15:42:44 +0800 Subject: [PATCH 07/52] 1 --- business/jxcallback/scheduler/basesch/basesch.go | 2 +- business/jxcallback/scheduler/defsch/defsch_ext.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/business/jxcallback/scheduler/basesch/basesch.go b/business/jxcallback/scheduler/basesch/basesch.go index 572e85dbc..064f05b51 100644 --- a/business/jxcallback/scheduler/basesch/basesch.go +++ b/business/jxcallback/scheduler/basesch/basesch.go @@ -266,7 +266,7 @@ func (c *BaseScheduler) CreateWaybill(platformVendorID int, order *model.GoodsOr } } else { - err = fmt.Errorf("CreateWaybill failed brand is close orderID: %s, isOpen: %d or store/brand money is enought ", order.VendorOrderID, storeDetail.BrandIsOpen) + err = fmt.Errorf("创建运单是门店余额不足十元,无法创建运单") } } else { err = scheduler.ErrDeliverProviderWrong diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index 287bc3c4a..76a3e52ff 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -184,12 +184,15 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex } deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID) + globals.SugarLogger.Debugf("=========deliveryFeeMap= := %s", utils.Format4Output(deliveryFeeMap, false)) // 不管是门店发单还是品牌发单都要扣钱,门店发单扣门店,品牌发单扣品牌 if order.CreateDeliveryType == model.YES { // 获取平台配送费 isEqual, isZero, _ := partner.CurStoreAcctManager.CheckStoreAcctExpendExist(order.VendorOrderID) // 当前订单的支出记录 expend, lastFee, _ := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID) // 最后一个运单支出记录 // 收最贵的一个订单配送费(配送费发送变化,收取最贵的价格) + globals.SugarLogger.Debugf("==========iszero,isequal := %s,%s", utils.Format4Output(isZero, false), utils.Format4Output(isZero, false)) + globals.SugarLogger.Debugf("==========expend,lastFee := %s,%s", utils.Format4Output(expend, false), utils.Format4Output(lastFee, false)) if !isZero && !isEqual { // 满足此条件是,门店发单已经存在此订单的发单记录 var newPrice int64 if len(courierVendorIDs) == 1 { @@ -206,6 +209,7 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex } newPrice = maxFee } + globals.SugarLogger.Debugf("==========newPrice := %d", newPrice) // 门店支出运费,门店发单 if order.CreateDeliveryType == model.YES { if storeAcct.AccountBalance > int(newPrice) { From 5d03698b8ad0a935053e0414e132efbd2a4d2332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 15 May 2023 16:10:12 +0800 Subject: [PATCH 08/52] 1 --- business/jxcallback/scheduler/defsch/defsch_ext.go | 2 ++ business/partner/delivery/rider.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index 76a3e52ff..0a80b688e 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -528,8 +528,10 @@ func (s *DefScheduler) QueryOrderWaybillFeeInfoEx(ctx *jxcontext.Context, vendor ErrStr: err.Error(), } } else { + globals.SugarLogger.Debugf("==============GetWaybillFee := %s", utils.Format4Output(feeInfo, false)) feeInfo.DeliveryFee += model.WayBillDeliveryMarkUp // 加收两毛 feeInfo.TimeoutSecond = timeoutSecond + globals.SugarLogger.Debugf("==============GetWaybillFee := %s", utils.Format4Output(feeInfo, false)) } } else { feeInfo = &partner.WaybillFeeInfo{ diff --git a/business/partner/delivery/rider.go b/business/partner/delivery/rider.go index b720c4285..c8ffb8d73 100644 --- a/business/partner/delivery/rider.go +++ b/business/partner/delivery/rider.go @@ -207,6 +207,8 @@ func GetOrderRiderInfoToPlatform(orderId string, wayBillStatus int) { continue case model.VendorIDDD: // 抖店小时达 continue + case model.VendorIDJX: // 京西平台 + continue default: globals.SugarLogger.Errorf("Order source error, non system order: %s", v.VendorOrderID) continue From 342bbbd7f97f7e15dfa554bf97cdb67e8c348d1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 15 May 2023 16:17:33 +0800 Subject: [PATCH 09/52] 1 --- business/jxcallback/scheduler/defsch/defsch_ext.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index 0a80b688e..75c0c33fa 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -506,6 +506,7 @@ func (s *DefScheduler) QueryOrderWaybillFeeInfoEx(ctx *jxcontext.Context, vendor if savedOrderInfo := s.loadSavedOrderByID(vendorOrderID, vendorID, false); savedOrderInfo != nil { timeoutSecond = savedOrderInfo.GetCreateWaybillTimeout() } + globals.SugarLogger.Debugf("==============storeCourierList := %s", utils.Format4Output(storeCourierList, false)) for _, storeCourier := range storeCourierList { var feeInfo *partner.WaybillFeeInfo if waybillMap[storeCourier.VendorID] != nil { From 57d0eb155f7e482026ae1d3c9505fde3d8fe7d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 15 May 2023 16:59:59 +0800 Subject: [PATCH 10/52] 1 --- business/jxcallback/scheduler/defsch/defsch_ext.go | 1 - business/partner/delivery/dada/waybill.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index 75c0c33fa..08606cbb0 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -529,7 +529,6 @@ func (s *DefScheduler) QueryOrderWaybillFeeInfoEx(ctx *jxcontext.Context, vendor ErrStr: err.Error(), } } else { - globals.SugarLogger.Debugf("==============GetWaybillFee := %s", utils.Format4Output(feeInfo, false)) feeInfo.DeliveryFee += model.WayBillDeliveryMarkUp // 加收两毛 feeInfo.TimeoutSecond = timeoutSecond globals.SugarLogger.Debugf("==============GetWaybillFee := %s", utils.Format4Output(feeInfo, false)) diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index 20c2eea9e..a4cf28ac0 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -282,6 +282,7 @@ func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInf if result, err = api.DadaAPI.QueryDeliverFee(billParams); err != nil { return nil, err } + globals.SugarLogger.Debugf("QueryDeliverFee===============:%s", utils.Format4Output(result, false)) deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(result.Fee) deliveryFeeInfo.RefDeliveryFee = deliveryFeeInfo.DeliveryFee } From 842ce37243f362390a52d97169e94949ddf05bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 15 May 2023 18:30:12 +0800 Subject: [PATCH 11/52] =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/scheduler/defsch/defsch_ext.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index 08606cbb0..d4466cd9f 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -204,7 +204,7 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex var maxFee int64 for _, v := range deliveryFeeMap { if v.DeliveryFee > maxFee { - v.DeliveryFee = maxFee + maxFee = v.DeliveryFee } } newPrice = maxFee @@ -254,7 +254,7 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex var maxFee int64 for _, v := range deliveryFeeMap { if v.DeliveryFee > maxFee { - v.DeliveryFee = maxFee + maxFee = v.DeliveryFee } } err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(maxFee), partner.StoreAcctTypeExpendCreateWaybillEx, order.VendorOrderID, "", 0) //int(maxFee) @@ -273,7 +273,7 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex var maxFee int64 for _, v := range deliveryFeeMap { if v.DeliveryFee > maxFee { - v.DeliveryFee = maxFee + maxFee = v.DeliveryFee } } err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, storeList.BrandID, int(maxFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorOrderID, order.VendorWaybillID) From aaca0e21af2aab19e1915b77f60d223f03e9ac12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 16 May 2023 14:51:50 +0800 Subject: [PATCH 12/52] 1 --- business/jxcallback/orderman/order.go | 115 +++++++++++++++--- .../jxcallback/scheduler/defsch/defsch.go | 8 +- 2 files changed, 103 insertions(+), 20 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 511904858..44c43d772 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -458,38 +458,115 @@ func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.W if bill.WaybillVendorID != model.VendorIDMTPS && bill.WaybillVendorID != model.VendorIDDada && bill.WaybillVendorID != model.VendorIDFengNiao && bill.WaybillVendorID != model.VendorIDUUPT { return nil } + // 订单被取消了,所有运单应该也被取消了,检查是否退还配送费 // 1.查询订单创建的所有运单,三方配送运单(达达,蜂鸟,uu,美团配送),平台自配送订单不参与 if handlerInfo := partner.GetDeliveryPlatformFromVendorID(bill.WaybillVendorID); handlerInfo != nil { + // 这一步必须要做,可能不是最后取消订单,需要更新违约金和取消状态 deductFee, err := handlerInfo.Handler.GetDeliverLiquidatedDamages(bill.VendorOrderID, bill.VendorWaybillID) if err != nil { return err } - if deductFee == 0 { - return nil + if deductFee != model.NO { + // 更新运单实际扣除费用 + bill.ActualFee = deductFee + bill.DesiredFee = deductFee + _, err = dao.UpdateEntity(db, bill, "ActualFee", "DesiredFee") } - // 更新运单实际扣除费用 - bill.ActualFee = deductFee - dao.UpdateEntity(db, bill, "ActualFee") - - // 门店账户金额扣除 + // 获取订单运单详情列表 store, _ := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, order.VendorOrgCode) - // 门店发单,扣除门店余额 - if store != nil && store.CreateDeliveryType == model.YES { - partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(deductFee), partner.StoreAcctTypeExpendCreateWaybillDeductFee, bill.VendorOrderID, bill.VendorWaybillID, 0) + // 门店发单,支付运单违约金 + if store != nil && store.CreateDeliveryType == model.YES && deductFee != model.NO { + err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(deductFee), partner.StoreAcctTypeExpendCreateWaybillDeductFee, bill.VendorOrderID, bill.VendorWaybillID, 0) + if err != nil { + globals.SugarLogger.Errorf("InsertStoreAcctIncomeAndUpdateStoreAcctBalance 483 : %v", err) + } } if store != nil && store.CreateDeliveryType == model.NO { - // 获取运单的支出记录 - orderBill, _ := dao.GetBrandBill(db, store.BrandID, order.VendorOrderID, model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorWaybillID) - if len(orderBill) == 0 { - partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) - } else { - // 退回扣除的配送费 - partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, orderBill[0].Price, model.BrandBillTypeIncome, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) - // 支出配送费违约金 - partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) + err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) + if err != nil { + globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err) + } + //// 获取运单的支出记录 + //orderBill, _ := dao.GetBrandBill(db, store.BrandID, order.VendorOrderID, model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorWaybillID) + //if len(orderBill) == 0 { + //} else { + // // 退回扣除的配送费 + // partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, orderBill[0].Price, model.BrandBillTypeIncome, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) + // // 支出配送费违约金 + // partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) + //} + } + + // 所有运单停止调度之后才开始退还余额 + bills, err := dao.GetWaybills(db, order.VendorOrderID, nil) + if err != nil { + return err + } + + // 所有取消的运单 + cancelWaybill := make(map[string]*model.Waybill, 0) + //finishWaybill := make(map[string]*model.Waybill, 0) + //deliveryWaybill := make(map[string]*model.Waybill, 0) + for _, v := range bills { + if v.Status == model.WaybillStatusCanceled && v.VendorWaybillID != bill.VendorWaybillID { + cancelWaybill[v.VendorWaybillID] = v + } + //if (v.Status == model.WaybillStatusDelivered || v.Status == model.OrderStatusFinished) && v.VendorWaybillID != bill.VendorWaybillID { + // finishWaybill[v.VendorWaybillID] = v + //} + //if v.Status < model.WaybillStatusDelivered && v.VendorWaybillID != bill.VendorWaybillID { + // deliveryWaybill[v.VendorOrderID] = v + //} + } + cancelWaybill[bill.VendorWaybillID] = bill + // 还有配送中的订单,暂不退款 + //if len(deliveryWaybill) != model.NO { + // return nil + //} + //// 如果已经有完成订单 + //if len(finishWaybill) != model.NO { + // var cancelDeductFee int64 = 0 + // var tipFee int64 = 0 + // for _, v := range cancelWaybill { + // cancelDeductFee += v.ActualFee + // tipFee += v.TipFee + // } + // + //} + // 已经全部运单取消,退款结算 + if len(bills) == len(cancelWaybill) { + // 门店结算,全部支出 + if store.CreateDeliveryType == model.YES { + // 此订单支出的费用 + expendType := []int{partner.StoreAcctTypeExpendCreateWaybillEx, partner.StoreAcctTypeExpendCreateWaybillTip, partner.StoreAcctTypeExpendCreateWaybill2ndMore, partner.StoreAcctTypeExpendCreateWaybillDeductFee, partner.StoreAcctTypeRealFeeExpend} + billExpend, err := dao.GetStoreAcctExpendTotal(db, store.ID, expendType, bill.VendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) + if err != nil { + globals.SugarLogger.Errorf("GetStoreAcctExpendTotal 545 err :%v", err) + return err + } + // 此订单退还的费用 + incomeType := []int{partner.StoreAcctTypeRealFeeIncome, partner.StoreAcctTypeIncomeCancelTemp, partner.StoreAcctTypeIncomeCancelReal} + billIncome, err := dao.GetStoreAcctIncomeTotal(db, store.ID, incomeType, bill.VendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) + if err != nil { + globals.SugarLogger.Errorf("GetStoreAcctIncomeTotal 551 err :%v", err) + return err + } + var allFee int = 0 + for _, v := range bills { + allFee += int(v.ActualFee) + allFee += int(v.TipFee) + } + globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,剩余退还费用:%d", billExpend, billIncome, billExpend-billIncome) + if allFee != billExpend-billIncome { + globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,剩余退还费用:%d", billExpend, billIncome, billExpend-billIncome) + } + } + // 品牌结算 + if store.CreateDeliveryType == model.NO { + } } } diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index 2216a0d95..f5e517296 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -2,7 +2,10 @@ package defsch import ( "fmt" + "git.rosy.net.cn/baseapi/platformapi/dadaapi" + "git.rosy.net.cn/baseapi/platformapi/fnpsapi" "git.rosy.net.cn/baseapi/platformapi/mtpsapi" + "git.rosy.net.cn/baseapi/platformapi/uuptapi" "git.rosy.net.cn/jx-callback/business/jxutils/smsmsg" "math/rand" "strings" @@ -637,7 +640,10 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo //} // 当运单时三方配送时,美团状态20 if bill.WaybillVendorID == model.VendorIDDada || bill.WaybillVendorID == model.VendorIDMTPS || bill.WaybillVendorID == model.VendorIDFengNiao || bill.WaybillVendorID == model.VendorIDUUPT { - if (bill.VendorStatus == utils.Int64ToStr(mtpsapi.OrderStatusPickedUp) && bill.OrderVendorID == model.VendorIDMTWM) || bill.Status == model.WaybillStatusCourierArrived { + if (bill.VendorStatus == utils.Int64ToStr(mtpsapi.OrderStatusPickedUp) && bill.OrderVendorID == model.VendorIDMTWM) || + (bill.VendorStatus == utils.Int64ToStr(dadaapi.OrderStatusDelivering) && bill.OrderVendorID == model.VendorIDDada) || + (bill.VendorStatus == utils.Int64ToStr(fnpsapi.OrderStatusArrived) && bill.OrderVendorID == model.VendorIDFengNiao) || + (bill.VendorStatus == uuptapi.StateArrivedStore && bill.OrderVendorID == model.VendorIDUUPT) { if storeDetail, err2 := dao.GetStoreDetail(dao.GetDB(), jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, ""); err2 == nil { if storeDetail.CreateDeliveryType == model.YES { s.updateStoreAccount(order, bill) From b7c1e8638b49e9beaf269809119cd0cb71f9dc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 16 May 2023 16:12:09 +0800 Subject: [PATCH 13/52] 1 --- business/jxcallback/orderman/order.go | 2 +- business/jxcallback/scheduler/defsch/defsch_ext.go | 3 +-- business/partner/delivery/dada/waybill.go | 5 ++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 44c43d772..4757addeb 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -484,7 +484,7 @@ func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.W globals.SugarLogger.Errorf("InsertStoreAcctIncomeAndUpdateStoreAcctBalance 483 : %v", err) } } - if store != nil && store.CreateDeliveryType == model.NO { + if store != nil && store.CreateDeliveryType == model.NO && deductFee != model.NO { err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) if err != nil { globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err) diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index d4466cd9f..b47ec0e50 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -506,7 +506,6 @@ func (s *DefScheduler) QueryOrderWaybillFeeInfoEx(ctx *jxcontext.Context, vendor if savedOrderInfo := s.loadSavedOrderByID(vendorOrderID, vendorID, false); savedOrderInfo != nil { timeoutSecond = savedOrderInfo.GetCreateWaybillTimeout() } - globals.SugarLogger.Debugf("==============storeCourierList := %s", utils.Format4Output(storeCourierList, false)) for _, storeCourier := range storeCourierList { var feeInfo *partner.WaybillFeeInfo if waybillMap[storeCourier.VendorID] != nil { @@ -531,7 +530,7 @@ func (s *DefScheduler) QueryOrderWaybillFeeInfoEx(ctx *jxcontext.Context, vendor } else { feeInfo.DeliveryFee += model.WayBillDeliveryMarkUp // 加收两毛 feeInfo.TimeoutSecond = timeoutSecond - globals.SugarLogger.Debugf("==============GetWaybillFee := %s", utils.Format4Output(feeInfo, false)) + globals.SugarLogger.Debugf("预下单加价==============GetWaybillFee := %s", utils.Format4Output(feeInfo, false)) } } else { feeInfo = &partner.WaybillFeeInfo{ diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index a4cf28ac0..4663dc914 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -282,7 +282,7 @@ func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInf if result, err = api.DadaAPI.QueryDeliverFee(billParams); err != nil { return nil, err } - globals.SugarLogger.Debugf("QueryDeliverFee===============:%s", utils.Format4Output(result, false)) + globals.SugarLogger.Debugf("QueryDeliverFee===============预下单获取配送费:%s", utils.Format4Output(result, false)) deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(result.Fee) deliveryFeeInfo.RefDeliveryFee = deliveryFeeInfo.DeliveryFee } @@ -359,6 +359,7 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee } // 重新发送订单 result, err = api.DadaAPI.ReaddOrder(billParams) + globals.SugarLogger.Debugf("重新发送订单多次发单======== := %s", utils.Format4Output(result, false)) if err != nil { return nil, err } @@ -368,6 +369,7 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee if result, err = api.DadaAPI.QueryDeliverFee(billParams); err != nil { return nil, err } + globals.SugarLogger.Debugf("查询达达订单费用(第一次发单)======== := %s", utils.Format4Output(result, false)) // 阀值警报 if err = delivery.CallCreateWaybillPolicy(jxutils.StandardPrice2Int(result.Fee), maxDeliveryFee, order, model.VendorIDDada); err != nil { return nil, err @@ -376,6 +378,7 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee if err = api.DadaAPI.AddOrderAfterQuery(result.DeliveryNo); err != nil { return nil, err } + globals.SugarLogger.Debugf("重新发送订单======== := %s", utils.Format4Output(result, false)) } if result == nil { return nil, errors.New("达达配送,平台调用错误,无订单数据返回") From 55600bedb061086ea7d119a4a12015a13fc128bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 09:02:07 +0800 Subject: [PATCH 14/52] 1 --- business/jxcallback/orderman/order.go | 243 ++++++++++++------ business/jxcallback/orderman/orderman_ext.go | 18 ++ .../jxcallback/scheduler/basesch/basesch.go | 6 +- .../scheduler/basesch/basesch_ext.go | 4 +- .../jxcallback/scheduler/defsch/defsch.go | 52 +--- business/jxstore/cms/sku.go | 10 +- business/model/order.go | 2 +- business/partner/delivery/dada/waybill.go | 14 +- business/partner/delivery/fn/waybill.go | 8 +- business/partner/delivery/mtps/waybill.go | 31 +++ business/partner/delivery/uupt/waybill.go | 23 +- business/partner/purchase/im/im_server.go | 4 +- .../purchase/jx/localjx/kuaishou_pay.go | 19 +- 13 files changed, 275 insertions(+), 159 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 4757addeb..1e1971948 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -450,6 +450,53 @@ func filterOrderInfo(order *model.GoodsOrder) { order.ConsigneeAddress = strings.ReplaceAll(order.ConsigneeAddress, "·", "") } +// FinisOrderWaybillFee 订单完成时,计算结算信息 +func FinisOrderWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill) (err error) { + if db == nil { + db = dao.GetDB() + } + if bill.WaybillVendorID != model.VendorIDMTPS && bill.WaybillVendorID != model.VendorIDDada && bill.WaybillVendorID != model.VendorIDFengNiao && bill.WaybillVendorID != model.VendorIDUUPT { + return nil + } + // 查询所有运单 + bills, err := dao.GetWaybills(db, order.VendorOrderID, nil) + if err != nil { + return err + } + + store, _ := dao.GetStoreDetail(db, order.JxStoreID, order.VendorID, order.VendorOrgCode) + // 正常来说只会出现一个完成运单,之前有bug会出现多个完成订单,这不做考虑.默认一个运单完成,其他运单取消状态 + // 1.完成当前运单的金额核算,正常完成的订单金额不需要核算 + // 2.取消运单的金额核算 + cancelWaybill := make(map[string]*model.Waybill, 0) + for _, v := range bills { + if v.Status != model.WaybillStatusCanceled { + continue + } + if v.VendorWaybillID == bill.VendorWaybillID { + continue + } + cancelWaybill[v.VendorWaybillID] = v + } + // 已经全部运单取消,退款结算 + for _, v := range bills { + if v.VendorWaybillID == bill.VendorWaybillID { + continue + } + // 已经取消订单的违约金计算 + if err = countWaybillSettleInfo(db, order, v, store); err != nil { + return err + } + } + + // 3.总的收支核算 + if err = orderFeeSettle(db, order, bill, bills, store); err != nil { + return err + } + return nil +} + +// ResetCreateWaybillFee 取消所有运单时计算结算信息 func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill) (err error) { if db == nil { db = dao.GetDB() @@ -459,12 +506,56 @@ func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.W return nil } + // 获取订单运单详情列表 + store, _ := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, order.VendorOrgCode) + // 订单被取消了,所有运单应该也被取消了,检查是否退还配送费 // 1.查询订单创建的所有运单,三方配送运单(达达,蜂鸟,uu,美团配送),平台自配送订单不参与 + if err := countWaybillSettleInfo(db, order, bill, store); err != nil { + return err + } + // 所有运单停止调度之后才开始退还余额 + bills, err := dao.GetWaybills(db, order.VendorOrderID, nil) + if err != nil { + return err + } + + // 所有取消的运单 + cancelWaybill := make(map[string]*model.Waybill, 0) + for _, v := range bills { + if v.Status == model.WaybillStatusCanceled && v.VendorWaybillID != bill.VendorWaybillID { + cancelWaybill[v.VendorWaybillID] = v + } + } + cancelWaybill[bill.VendorWaybillID] = bill + // 已经全部运单取消,退款结算 + if len(bills) == len(cancelWaybill) { + for _, v := range bills { + if v.VendorWaybillID == bill.VendorWaybillID { + continue + } + // 已经取消订单的违约金计算 + if err = countWaybillSettleInfo(db, order, v, store); err != nil { + return err + } + } + + // 最终的金额核算,多退少补 + if err = orderFeeSettle(db, order, bill, bills, store); err != nil { + return err + } + } + + return err +} + +// countWaybillSettleInfo 计算订单的结算信息 +func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill, store *dao.StoreDetail) error { if handlerInfo := partner.GetDeliveryPlatformFromVendorID(bill.WaybillVendorID); handlerInfo != nil { // 这一步必须要做,可能不是最后取消订单,需要更新违约金和取消状态 deductFee, err := handlerInfo.Handler.GetDeliverLiquidatedDamages(bill.VendorOrderID, bill.VendorWaybillID) if err != nil { + partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,获取违约金异常:%v", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err), "") return err } @@ -475,102 +566,104 @@ func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.W _, err = dao.UpdateEntity(db, bill, "ActualFee", "DesiredFee") } - // 获取订单运单详情列表 - store, _ := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, order.VendorOrgCode) // 门店发单,支付运单违约金 if store != nil && store.CreateDeliveryType == model.YES && deductFee != model.NO { err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(deductFee), partner.StoreAcctTypeExpendCreateWaybillDeductFee, bill.VendorOrderID, bill.VendorWaybillID, 0) if err != nil { + partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,获取违约金门店扣除失败:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, deductFee), "") globals.SugarLogger.Errorf("InsertStoreAcctIncomeAndUpdateStoreAcctBalance 483 : %v", err) + return err } } + if store != nil && store.CreateDeliveryType == model.NO && deductFee != model.NO { err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) if err != nil { + partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,获取违约金品牌扣除失败:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, deductFee), "") globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err) + return err } - //// 获取运单的支出记录 - //orderBill, _ := dao.GetBrandBill(db, store.BrandID, order.VendorOrderID, model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorWaybillID) - //if len(orderBill) == 0 { - //} else { - // // 退回扣除的配送费 - // partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, orderBill[0].Price, model.BrandBillTypeIncome, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) - // // 支出配送费违约金 - // partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) - //} } - - // 所有运单停止调度之后才开始退还余额 - bills, err := dao.GetWaybills(db, order.VendorOrderID, nil) - if err != nil { + if err == nil { + partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,违约金扣除成功:%d", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, deductFee), "") return err } + } + return nil +} - // 所有取消的运单 - cancelWaybill := make(map[string]*model.Waybill, 0) - //finishWaybill := make(map[string]*model.Waybill, 0) - //deliveryWaybill := make(map[string]*model.Waybill, 0) - for _, v := range bills { - if v.Status == model.WaybillStatusCanceled && v.VendorWaybillID != bill.VendorWaybillID { - cancelWaybill[v.VendorWaybillID] = v - } - //if (v.Status == model.WaybillStatusDelivered || v.Status == model.OrderStatusFinished) && v.VendorWaybillID != bill.VendorWaybillID { - // finishWaybill[v.VendorWaybillID] = v - //} - //if v.Status < model.WaybillStatusDelivered && v.VendorWaybillID != bill.VendorWaybillID { - // deliveryWaybill[v.VendorOrderID] = v - //} +// 订单金额核算 +func orderFeeSettle(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill, bills []*model.Waybill, store *dao.StoreDetail) (err error) { + billExpend := 0 + billIncome := 0 + allFee := 0 + // 门店结算,全部支出 + if store.CreateDeliveryType == model.YES { + // 此订单支出的费用 + expendType := []int{partner.StoreAcctTypeExpendCreateWaybillEx, partner.StoreAcctTypeExpendCreateWaybillTip, partner.StoreAcctTypeExpendCreateWaybill2ndMore, partner.StoreAcctTypeExpendCreateWaybillDeductFee, partner.StoreAcctTypeRealFeeExpend} + billExpend, err = dao.GetStoreAcctExpendTotal(db, store.ID, expendType, bill.VendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) + if err != nil { + globals.SugarLogger.Errorf("GetStoreAcctExpendTotal 545 err :%v", err) + return err } - cancelWaybill[bill.VendorWaybillID] = bill - // 还有配送中的订单,暂不退款 - //if len(deliveryWaybill) != model.NO { - // return nil - //} - //// 如果已经有完成订单 - //if len(finishWaybill) != model.NO { - // var cancelDeductFee int64 = 0 - // var tipFee int64 = 0 - // for _, v := range cancelWaybill { - // cancelDeductFee += v.ActualFee - // tipFee += v.TipFee - // } - // - //} - // 已经全部运单取消,退款结算 - if len(bills) == len(cancelWaybill) { - // 门店结算,全部支出 - if store.CreateDeliveryType == model.YES { - // 此订单支出的费用 - expendType := []int{partner.StoreAcctTypeExpendCreateWaybillEx, partner.StoreAcctTypeExpendCreateWaybillTip, partner.StoreAcctTypeExpendCreateWaybill2ndMore, partner.StoreAcctTypeExpendCreateWaybillDeductFee, partner.StoreAcctTypeRealFeeExpend} - billExpend, err := dao.GetStoreAcctExpendTotal(db, store.ID, expendType, bill.VendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) - if err != nil { - globals.SugarLogger.Errorf("GetStoreAcctExpendTotal 545 err :%v", err) - return err - } - // 此订单退还的费用 - incomeType := []int{partner.StoreAcctTypeRealFeeIncome, partner.StoreAcctTypeIncomeCancelTemp, partner.StoreAcctTypeIncomeCancelReal} - billIncome, err := dao.GetStoreAcctIncomeTotal(db, store.ID, incomeType, bill.VendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) - if err != nil { - globals.SugarLogger.Errorf("GetStoreAcctIncomeTotal 551 err :%v", err) - return err - } - var allFee int = 0 - for _, v := range bills { - allFee += int(v.ActualFee) - allFee += int(v.TipFee) - } - globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,剩余退还费用:%d", billExpend, billIncome, billExpend-billIncome) - if allFee != billExpend-billIncome { - globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,剩余退还费用:%d", billExpend, billIncome, billExpend-billIncome) - } - } - // 品牌结算 - if store.CreateDeliveryType == model.NO { + // 此订单退还的费用 + incomeType := []int{partner.StoreAcctTypeRealFeeIncome, partner.StoreAcctTypeIncomeCancelTemp, partner.StoreAcctTypeIncomeCancelReal} + billIncome, err = dao.GetStoreAcctIncomeTotal(db, store.ID, incomeType, bill.VendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) + if err != nil { + globals.SugarLogger.Errorf("GetStoreAcctIncomeTotal 551 err :%v", err) + return err + } + for _, v := range bills { + allFee += int(v.DesiredFee) + allFee += int(v.TipFee) + } + // 运单支出费用统计,应该等于 支出费用- 退还费用 + globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,运单计算费用:%d", billExpend, billIncome, allFee) + if allFee != billExpend-billIncome { + globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,剩余退还费用:%d", billExpend, billIncome, billExpend-billIncome) + } + } + if billExpend-billIncome == allFee { + globals.SugarLogger.Debugf("计算正确,运单消耗[%d],账户支出[%d],账户退回[%d]", allFee, billExpend, billIncome) + partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("计算正确,运单消耗[%d],账户支出[%d],账户退回[%d]", allFee, billExpend, billIncome), "") + return nil + } + abnormalAmount := billExpend - billIncome - allFee + switch store.CreateDeliveryType { + case model.NO: // 品牌结算 + if abnormalAmount > 0 { // 多退 + err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, abnormalAmount, model.BrandBillTypeIncome, model.BrandBillFeeTypeSys, order.VendorOrderID, order.VendorWaybillID) + if err != nil { + partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,品牌支出大于消耗,多退:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, abnormalAmount), "") + globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err) + return err + } + } + if abnormalAmount < 0 { + err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, abnormalAmount*-1, model.BrandBillTypeExpend, model.BrandBillFeeTypeSys, order.VendorOrderID, order.VendorWaybillID) + if err != nil { + partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,品牌支出小于消耗,少补:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, abnormalAmount), "") + globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err) + return err + } + } + case model.YES: // 门店结算 + if abnormalAmount > 0 { // 多退 + err = partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(billExpend-billIncome-allFee), partner.StoreAcctTypeIncomeCancelReal, bill.VendorOrderID, bill.VendorWaybillID, 0) + if err != nil { + partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,支出大于消耗,多退:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, abnormalAmount), "") + globals.SugarLogger.Errorf("InsertStoreAcctIncomeAndUpdateStoreAcctBalance 483 : %v", err) + } + } + if abnormalAmount < 0 { + err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(abnormalAmount)*-1, partner.StoreAcctTypeExpendCreateWaybill2ndMore, bill.VendorOrderID, bill.VendorWaybillID, 0) + if err != nil { + partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,支出小于消耗,少补:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, abnormalAmount), "") + globals.SugarLogger.Errorf("InsertStoreAcctIncomeAndUpdateStoreAcctBalance 483 : %v", err) } } } - return err } diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 18a815801..84d7d0b1b 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -715,6 +715,24 @@ func (c *OrderManager) GetLogisticsOrderStatusList(orderId, LogisticsId string, return result, nil } +// GetWayBillStatusList 根据订单号和物流号查询运单的变化状态 +func (c *OrderManager) GetWayBillStatusList(orderId, LogisticsId string, vendorId int) ([]*model.OrderStatus, error) { + sql := `SELECT * + FROM order_status t1 + WHERE t1.vendor_order_id = ? AND t1.ref_vendor_order_id = ? AND t1.vendor_id = ?` + sqlParams := []interface{}{ + LogisticsId, + orderId, + vendorId, + } + sql += ` ORDER BY status_time ASC ` + var result []*model.OrderStatus + if err := dao.GetRows(dao.GetDB(), &result, sql, sqlParams...); err != nil { + return nil, err + } + return result, nil +} + // GetOrderStatusList2 查询订单流程 refVendorOrderID 订单Id func GetOrderStatusList2(refVendorOrderID string, wayBillId string, orderType int, vendorID int) (statusList []*model.OrderStatus, err error) { sql := ` diff --git a/business/jxcallback/scheduler/basesch/basesch.go b/business/jxcallback/scheduler/basesch/basesch.go index 064f05b51..0c601adef 100644 --- a/business/jxcallback/scheduler/basesch/basesch.go +++ b/business/jxcallback/scheduler/basesch/basesch.go @@ -4,7 +4,6 @@ import ( "fmt" tiktokShop "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/jxcallback/orderman" "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler" "git.rosy.net.cn/jx-callback/business/jxstore/cms" "git.rosy.net.cn/jx-callback/business/jxutils" @@ -283,8 +282,9 @@ func (c *BaseScheduler) CancelWaybill(bill *model.Waybill, cancelReasonID int, c if err := handlerInfo.Handler.CancelWaybill(bill, cancelReasonID, cancelReason); err != nil { return err } - order, _ := partner.CurOrderManager.LoadOrder(bill.VendorOrderID, bill.OrderVendorID) - return orderman.ResetCreateWaybillFee(nil, order, bill) + return nil + //order, _ := partner.CurOrderManager.LoadOrder(bill.VendorOrderID, bill.OrderVendorID) + //return orderman.ResetCreateWaybillFee(nil, order, bill) }, "CancelWaybill bill:%v", bill); err == nil { bill.Status = model.WaybillStatusCanceled bill.DeliveryFlag |= model.WaybillDeliveryFlagMaskActiveCancel diff --git a/business/jxcallback/scheduler/basesch/basesch_ext.go b/business/jxcallback/scheduler/basesch/basesch_ext.go index 9bb020e8b..e9b99e14d 100644 --- a/business/jxcallback/scheduler/basesch/basesch_ext.go +++ b/business/jxcallback/scheduler/basesch/basesch_ext.go @@ -376,7 +376,7 @@ func (c *BaseScheduler) CheckStoreBalanceWithTip(ctx *jxcontext.Context, order * return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额不足,不能加小费!") } if tipFee > 1000 { - return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("小费单次加价金额大于五元") + return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("小费单次加价金额大于十元") } } else { // 品牌发单 @@ -393,7 +393,7 @@ func (c *BaseScheduler) CheckStoreBalanceWithTip(ctx *jxcontext.Context, order * return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("品牌账户余额不足,不能加小费!") } if tipFee > 1000 { - return model.ErrCodeOnePayTipFeeMore, fmt.Errorf("小费单次加价金额大于五元") + return model.ErrCodeOnePayTipFeeMore, fmt.Errorf("小费单次加价金额大于十元") } } // 是否确认支付 diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index f5e517296..93a0896d2 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -6,6 +6,7 @@ import ( "git.rosy.net.cn/baseapi/platformapi/fnpsapi" "git.rosy.net.cn/baseapi/platformapi/mtpsapi" "git.rosy.net.cn/baseapi/platformapi/uuptapi" + "git.rosy.net.cn/jx-callback/business/jxcallback/orderman" "git.rosy.net.cn/jx-callback/business/jxutils/smsmsg" "math/rand" "strings" @@ -511,20 +512,6 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo savedOrderInfo := s.loadSavedOrderFromMap(model.Waybill2Status(bill), true) order := savedOrderInfo.order - // 打印通知 - //netprinter.PrintOrderByOrder(jxcontext.AdminCtx, order, model.PrintTypeWayBill) - - // 获取订单配送平台,如果是美团则需要获取门店配置的配送方式 - //isBlendWay := false - //if bill.OrderVendorID == model.VendorIDMTWM { - // mtStoreInfo, err := api.MtwmAPI.PoiGet(utils.Int2Str(order.JxStoreID)) - // globals.SugarLogger.Debugf("从美团上获取门店失败:%s", err) - // isBlendWay = strings.Contains(mtStoreInfo.LogisticsCodes, model.MTWMStorePSWay8) - //} - //if order.VendorID == model.VendorIDDD { - // partner.GetPurchaseOrderHandlerFromVendorID(order.VendorID).GetOrderRider() - //} - // 暂时只处理抖音平台,抖音暂无配送,只要是抖音订单,三方配送压单了,直接通知送出 if bill.Status == model.WaybillStatusNew { s.addWaybill2Map(savedOrderInfo, bill) @@ -634,10 +621,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo if order.VendorID == model.VendorIDJDShop { s.solutionJdsOrder(bill) } - //如果是商城的订单, 骑手取货时,需要发短信提醒 - //if bill.Status == model.WaybillStatusDelivering && order.VendorID == model.VendorIDJX && order.OrderType == model.OrderTypeNormal { - // smsmsg.NotifyJxOrder(order, bill) - //} + // 当运单时三方配送时,美团状态20 if bill.WaybillVendorID == model.VendorIDDada || bill.WaybillVendorID == model.VendorIDMTPS || bill.WaybillVendorID == model.VendorIDFengNiao || bill.WaybillVendorID == model.VendorIDUUPT { if (bill.VendorStatus == utils.Int64ToStr(mtpsapi.OrderStatusPickedUp) && bill.OrderVendorID == model.VendorIDMTWM) || @@ -747,9 +731,6 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo if model.IsOrderHaveWaybill(order) { s.updateOrderByBill(order, nil, true) } - //if order.VendorID == model.VendorIDMTWM { - // order, _ = partner.CurOrderManager.LoadOrder(order.VendorOrderID, order.VendorID) - //} // 3方的运单取消才会重新发起创建3方订单,购物平台的运单取消后,它本身还会再创建新运单(NewWaybill事件有相应TIMER)),至少京东是这样的,暂时按京东的行为来 // 现在发现饿百取消订单后不会再创建运单了,所以饿百运单取消也允许直接创建三方运单 // 之前的条件是order.Status < model.OrderStatusDelivering,但像订单902322817000122确实有在配送中取消状态,改成非订单结束状态都可以 @@ -761,21 +742,12 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo //} globals.SugarLogger.Debugf("auto cancelWaybill created second, orderID:%s", order.VendorOrderID) } - //if order.Status < model.OrderStatusDelivering { - // if order.VendorID == model.VendorIDMTWM && order.DeliveryType == model.OrderDeliveryTypePlatform { - // s.CancelOrder(jxcontext.AdminCtx, order, "") - // } - //} } } - // case model.WaybillStatusDelivering: - // s.resetTimer(savedOrderInfo, bill, isPending) - // if s.isBillCandidate(order, bill) { - // // do nothing - // } else { - // // s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) - // globals.SugarLogger.Infof("OnWaybillStatusChanged Delivering order(%d, %s) bill(%d, %s), bill:%v shouldn't get here", order.WaybillVendorID, order.VendorWaybillID, bill.WaybillVendorID, bill.VendorWaybillID, bill) - // } + + if err := orderman.ResetCreateWaybillFee(nil, order, bill); err != nil { + globals.SugarLogger.Errorf("ResetCreateWaybillFee err : %v", err) + } case model.WaybillStatusDelivered: s.resetTimer(savedOrderInfo, bill, isPending) @@ -805,22 +777,18 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo if !isPending { s.notify3rdPartyWaybill(order, bill, false) } - // case model.WaybillStatusNeverSend: // 平台不配送,直接创建三方运单 - // s.resetTimer(savedOrderInfo, bill, isPending) - // s.removeWaybillFromMap(savedOrderInfo, bill.WaybillVendorID) - // if order.WaybillVendorID == model.VendorIDUnknown { - // s.createWaybillOn3rdProviders(savedOrderInfo, 0, nil) - // } // 将订单修改为完成状态 order.Status = model.OrderStatusFinished order.OrderFinishedAt = time.Now() partner.CurOrderManager.UpdateOrderFields(order, []string{"status", "OrderFinishedAt"}) + if err := orderman.FinisOrderWaybillFee(nil, order, bill); err != nil { + globals.SugarLogger.Debugf("FinisOrderWaybillFee count err : %v", err) + } + default: s.resetTimer(savedOrderInfo, bill, isPending) } - // s.updateBillsInfo(savedOrderInfo, bill) // 更新可能的运单状态变化 } - // } } return err } diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index 94d4b5813..ce73ea217 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -1328,19 +1328,19 @@ func updateOrCreateSkuVendorCategoryMap(db *dao.DaoDB, ctx *jxcontext.Context, n if payload["descImg"] != nil { imgs = append(imgs, payload["descImg"].(string)) } - if payload["img"] != "" { + if payload["img"] != nil { imgs = append(imgs, payload["descImg"].(string)) } - if payload["img2"] != "" { + if payload["img2"] != nil { imgs = append(imgs, payload["img2"].(string)) } - if payload["img3"] != "" { + if payload["img3"] != nil { imgs = append(imgs, payload["img3"].(string)) } - if payload["img4"] != "" { + if payload["img4"] != nil { imgs = append(imgs, payload["img4"].(string)) } - if payload["img5"] != "" { + if payload["img5"] != nil { imgs = append(imgs, payload["img5"].(string)) } ddCategoryID = getCategoryByImg(imgs...) diff --git a/business/model/order.go b/business/model/order.go index 2ec5a648c..efa1940f6 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -234,7 +234,7 @@ type Waybill struct { Status int `json:"status"` // 参见WaybillStatus*相关的常量定义 VendorStatus string `orm:"size(255)" json:"-"` ActualFee int64 `json:"actualFee"` // 实际要支付给快递公司的费用 - DesiredFee int64 `json:"desiredFee"` // 运单总费用 + DesiredFee int64 `json:"desiredFee"` // 运单总费用(原价+两毛)统计使用 TipFee int64 `json:"tipFee"` // 运单小费,不含在上两项中 DuplicatedCount int `json:"-"` // 重复新订单消息数,这个一般不是由于消息重发造成的(消息重发由OrderStatus过滤),一般是业务逻辑造成的 DeliveryFlag int8 `json:"deliveryFlag"` diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index 4663dc914..3cc8207b7 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -283,7 +283,7 @@ func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInf return nil, err } globals.SugarLogger.Debugf("QueryDeliverFee===============预下单获取配送费:%s", utils.Format4Output(result, false)) - deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(result.Fee) + deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(result.DeliverFee) // jxutils.StandardPrice2Int(result.Fee) deliveryFeeInfo.RefDeliveryFee = deliveryFeeInfo.DeliveryFee } return deliveryFeeInfo, err @@ -388,8 +388,8 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee VendorOrderID: order.VendorOrderID, OrderVendorID: order.VendorID, WaybillVendorID: model.VendorIDDada, - DesiredFee: jxutils.StandardPrice2Int(result.Fee), - ActualFee: jxutils.StandardPrice2Int(result.Fee), + DesiredFee: jxutils.StandardPrice2Int(result.DeliverFee), + ActualFee: jxutils.StandardPrice2Int(result.DeliverFee), } delivery.OnWaybillCreated(bill) return bill, err @@ -571,8 +571,14 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId return 200, nil } + // fetchTime 已经有时间了,代表已经取货.次数取消扣除此订单全部金额 + // 达达存在多个订单的运单违约金额统计在一起的情况 if dadaOrder.FetchTime != "" { - return jxutils.StandardPrice2Int(dadaOrder.ActualFee), nil + bill, err := partner.CurOrderManager.LoadWaybill(deliverId, model.VendorIDDada) + if err != nil { + return 0, err + } + return bill.DesiredFee, nil } return 0, err diff --git a/business/partner/delivery/fn/waybill.go b/business/partner/delivery/fn/waybill.go index 53b6df5d9..1708c1cf7 100644 --- a/business/partner/delivery/fn/waybill.go +++ b/business/partner/delivery/fn/waybill.go @@ -234,11 +234,11 @@ func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify) (resp *fnpsapi.CallbackRespon order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID) order.Status = model.WaybillStatusNew //5 带调度 case fnpsapi.OrderStatusAssigned: //20分配骑手 - order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID) + //order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID) order.Status = model.WaybillStatusCourierAssigned //12 order.Remark = order.CourierName + "," + order.CourierMobile case fnpsapi.OrderStatusArrived: // 80 到店 - order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID) + //order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID) order.Status = model.WaybillStatusCourierArrived case fnpsapi.OrderStatusDelivering: // 2 配送中 order.Status = model.WaybillStatusDelivering @@ -324,7 +324,7 @@ func (c *DeliveryHandler) OnWaybillExcept(msg *fnpsapi.AbnormalReportNotify) (re // 查询订单配送费 func GetDesiredFee(vendorOrderID string) (desiredFee, acuteFee int64) { if result, err := api.FnAPI.QueryOrder(vendorOrderID); err == nil { - return result.OrderActualAmountCent, result.OrderTotalAmountCent + return result.OrderTotalAmountCent + int64(utils.WayBillDeliveryMarkUp), result.OrderActualAmountCent } return desiredFee, acuteFee } @@ -398,7 +398,7 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId for i := len(order.EventLogDetails) - 1; i >= 0; i-- { switch order.EventLogDetails[i].OrderStatus { case fnpsapi.OrderStatusDelivered, fnpsapi.OrderStatusArrived, fnpsapi.OrderStatusDelivering: // 送达,到店,配送中 取消订单全额扣款 - return order.OrderActualAmountCent, nil + return order.OrderTotalAmountCent, nil case fnpsapi.OrderStatusAcceptCacle, fnpsapi.OrderStatusException: // 取消和异常状态,跳过查看上一状态 continue case fnpsapi.OrderStatusAcceptCreate, fnpsapi.OrderStatusAccept: // 生成运单和系统接单取消不扣除费用 diff --git a/business/partner/delivery/mtps/waybill.go b/business/partner/delivery/mtps/waybill.go index 9e00782ed..53c338db2 100644 --- a/business/partner/delivery/mtps/waybill.go +++ b/business/partner/delivery/mtps/waybill.go @@ -6,6 +6,7 @@ import ( "fmt" "git.rosy.net.cn/baseapi/platformapi/mtpsapi" "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/jxcallback/orderman" "git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/model" @@ -485,6 +486,36 @@ func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeiso return result, nil } + func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) { + statusList, err := orderman.FixedOrderManager.GetWayBillStatusList(orderId, deliverId, model.VendorIDMTPS) + if err != nil { + return 0, err + } + + // 已经分配骑手,且超过十五分钟,不扣款 + if len(statusList) != model.NO { + for i := len(statusList) - 1; i >= 0; i-- { + switch statusList[i].VendorStatus { + case utils.Int2Str(mtpsapi.OrderStatusWaitingForSchedule): // 待调度 + return 0, nil + case utils.Int2Str(mtpsapi.OrderStatusCanceled): // 取消不管 + continue + case utils.Int2Str(mtpsapi.OrderStatusDeliverred): // 送达 + continue + case utils.Int2Str(mtpsapi.OrderStatusAccepted): // 接单 + // 接单取消扣凉快 + return 200, nil + case utils.Int2Str(mtpsapi.OrderStatusPickedUp): // 取货 + bill, err := partner.CurOrderManager.LoadWaybill(deliverId, model.VendorIDDada) + if err != nil { + return 0, err + } + return bill.DesiredFee, nil + + } + } + + } return 0, err } diff --git a/business/partner/delivery/uupt/waybill.go b/business/partner/delivery/uupt/waybill.go index 9154c31f5..e7a7cbad2 100644 --- a/business/partner/delivery/uupt/waybill.go +++ b/business/partner/delivery/uupt/waybill.go @@ -170,7 +170,7 @@ func (d DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee i VendorWaybillID: orderCode, VendorWaybillID2: originID, WaybillVendorID: model.VendorIDUUPT, - DesiredFee: jxutils.StandardPrice2Int(utils.Str2Float64(price.NeedPayMoney)), + DesiredFee: jxutils.StandardPrice2Int(utils.Str2Float64(price.TotalMoney)), } } delivery.OnWaybillCreated(bill) @@ -192,7 +192,8 @@ func (d DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo return nil, err } else { deliveryFeeInfo = &partner.WaybillFeeInfo{} - deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(utils.Str2Float64(orderPrice.NeedPayMoney)) + // deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(utils.Str2Float64(orderPrice.NeedPayMoney)) 优惠后金额 + deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(utils.Str2Float64(orderPrice.TotalMoney)) // 原始金额 } return deliveryFeeInfo, err } @@ -308,37 +309,39 @@ func OnWaybillMsg(req *uuptapi.WaybillCallbackParam) (resp *uuptapi.CallbackResp dao.GetRow(dao.GetDB(), &good, sql, sqlParams) param.OrderVendorID = good.VendorID //查询运单价格 - if uuPrice, err := api.UuAPI.GetOrderDetail(req.OrderCode); err != nil { + uuPrice, err := api.UuAPI.GetOrderDetail(req.OrderCode) + if err != nil { reallyPrice = 0 } else { - reallyPrice = int64((utils.Str2Float64(uuPrice.OrderPrice) - utils.Str2Float64(uuPrice.PriceOff)) * 100) + reallyPrice = int64(utils.Str2Float64(uuPrice.OrderPrice) * 100) } + actualFee := int64((utils.Str2Float64(uuPrice.OrderPrice)-utils.Str2Float64(uuPrice.PriceOff))*100) - int64(utils.WayBillDeliveryMarkUp) switch req.State { case uuptapi.StateConfirmSuccess: param.Status = model.WaybillStatusNew //5 待调度 param.DesiredFee = reallyPrice - param.ActualFee = reallyPrice + param.ActualFee = actualFee case uuptapi.StateRMGrabsOrder: param.Status = model.WaybillStatusCourierAssigned param.Remark = req.DriverName + "," + req.DriverMobile param.DesiredFee = reallyPrice - param.ActualFee = reallyPrice + param.ActualFee = actualFee case uuptapi.StateArrivedStore: param.Status = model.WaybillStatusCourierArrived param.DesiredFee = reallyPrice - param.ActualFee = reallyPrice + param.ActualFee = actualFee case uuptapi.StatePickUp: param.Status = model.WaybillStatusUuPickUp param.DesiredFee = reallyPrice - param.ActualFee = reallyPrice + param.ActualFee = actualFee case uuptapi.StateArrivedDestination: param.Status = model.WaybillStatusUuArrivedDestination param.DesiredFee = reallyPrice - param.ActualFee = reallyPrice + param.ActualFee = actualFee case uuptapi.StateReceiverGetGoods: param.Status = model.WaybillStatusDelivered param.DesiredFee = reallyPrice - param.ActualFee = reallyPrice + param.ActualFee = actualFee case uuptapi.StateOrderCancel: param.Status = model.WaybillStatusCanceled default: diff --git a/business/partner/purchase/im/im_server.go b/business/partner/purchase/im/im_server.go index 2b9208bcb..2729aca39 100644 --- a/business/partner/purchase/im/im_server.go +++ b/business/partner/purchase/im/im_server.go @@ -8,8 +8,6 @@ import ( "git.rosy.net.cn/jx-callback/business/jxutils" - "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/globals" "github.com/gorilla/websocket" ) @@ -114,7 +112,7 @@ func WriteMessage() { clientInfo := <-ToClientChan //广播发送通知所有京西客户端 i++ - fmt.Printf("WriteMessage clientInfo=%s i=%d\n", utils.Format4Output(clientInfo, false), i) + //fmt.Printf("WriteMessage clientInfo=%s i=%d\n", utils.Format4Output(clientInfo, false), i) if Manager.AllClient() != nil { for _, conn := range Manager.AllClient() { if conn.ClientType == ClientTypeJx { //只发送给京西 diff --git a/business/partner/purchase/jx/localjx/kuaishou_pay.go b/business/partner/purchase/jx/localjx/kuaishou_pay.go index 12c6ff47c..a576bbd56 100644 --- a/business/partner/purchase/jx/localjx/kuaishou_pay.go +++ b/business/partner/purchase/jx/localjx/kuaishou_pay.go @@ -40,16 +40,15 @@ func pay4OrderByKs(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp } param := &kuaishou_mini.PreCreateOrderReq{ - OutOrderNo: utils.Int64ToStr(GenPayOrderID(order)), - OpenId: authBindList[0].AuthID, - TotalAmount: order.ActualPayPrice, - Subject: "蔬菜水果日用品", - Detail: getOrderBriefKs(order), - TypeDetail: 1832, // 蔬菜:费率2%,水果:1833%2 - ExpireTime: 60 * 10, - Sign: "", - Attach: "", - //NotifyUrl: "https://callback.jxc4.com/kuaishou/kuaiShouCallback", + OutOrderNo: utils.Int64ToStr(GenPayOrderID(order)), + OpenId: authBindList[0].AuthID, + TotalAmount: order.ActualPayPrice, + Subject: "蔬菜水果日用品", + Detail: getOrderBriefKs(order), + TypeDetail: 1832, // 蔬菜:费率2%,水果:1833%2 + ExpireTime: 60 * 10, + Sign: "", + Attach: "", GoodsId: "", GoodsDetailUrl: "", MultiCopiesGoodsInfo: "", From c0e491ff7f09b47fedce6ae2f442cfb190a5c39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 10:29:52 +0800 Subject: [PATCH 15/52] 1 --- business/jxcallback/orderman/order.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 1e1971948..eaf9c4df1 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -559,12 +559,12 @@ func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model. return err } - if deductFee != model.NO { - // 更新运单实际扣除费用 - bill.ActualFee = deductFee - bill.DesiredFee = deductFee - _, err = dao.UpdateEntity(db, bill, "ActualFee", "DesiredFee") - } + //if deductFee != model.NO { + // 更新运单实际扣除费用 + bill.ActualFee = deductFee + bill.DesiredFee = deductFee + _, err = dao.UpdateEntity(db, bill, "ActualFee", "DesiredFee") + //} // 门店发单,支付运单违约金 if store != nil && store.CreateDeliveryType == model.YES && deductFee != model.NO { From 9c85a2db604e17439e28a997da1fb96a5d1c06d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 10:40:49 +0800 Subject: [PATCH 16/52] 1 --- business/jxcallback/orderman/order.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index eaf9c4df1..3c1c4f17b 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -563,7 +563,9 @@ func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model. // 更新运单实际扣除费用 bill.ActualFee = deductFee bill.DesiredFee = deductFee - _, err = dao.UpdateEntity(db, bill, "ActualFee", "DesiredFee") + if _, err = dao.UpdateEntity(db, bill, "ActualFee", "DesiredFee"); err != nil { + globals.SugarLogger.Errorf("更新门店配送信息错误:%d,%v", deductFee, err) + } //} // 门店发单,支付运单违约金 From 7544fd420be670a4a86bd794bf606f2d249e2bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 10:46:15 +0800 Subject: [PATCH 17/52] 1' --- business/jxcallback/orderman/order.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 3c1c4f17b..2b6c05462 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -563,7 +563,7 @@ func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model. // 更新运单实际扣除费用 bill.ActualFee = deductFee bill.DesiredFee = deductFee - if _, err = dao.UpdateEntity(db, bill, "ActualFee", "DesiredFee"); err != nil { + if _, err = dao.UpdateEntity(db, &bill, "ActualFee", "DesiredFee"); err != nil { globals.SugarLogger.Errorf("更新门店配送信息错误:%d,%v", deductFee, err) } //} From 98eb7e1397ac934496c9f7793d81e428f7617697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 10:51:35 +0800 Subject: [PATCH 18/52] 1 --- business/jxcallback/orderman/order.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 2b6c05462..f8c19e337 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -563,7 +563,8 @@ func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model. // 更新运单实际扣除费用 bill.ActualFee = deductFee bill.DesiredFee = deductFee - if _, err = dao.UpdateEntity(db, &bill, "ActualFee", "DesiredFee"); err != nil { + globals.SugarLogger.Debugf("bill ======== %s", utils.Format4Output(bill, false)) + if _, err = dao.UpdateEntity(db, bill, "ActualFee", "DesiredFee"); err != nil { globals.SugarLogger.Errorf("更新门店配送信息错误:%d,%v", deductFee, err) } //} From a94f54973c43117b8e1872cf6cc50092b1b311cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 11:05:32 +0800 Subject: [PATCH 19/52] 1 --- business/jxcallback/orderman/order.go | 12 +++--------- business/model/dao/dao_order.go | 7 +++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index f8c19e337..25be1c691 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -559,16 +559,10 @@ func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model. return err } - //if deductFee != model.NO { - // 更新运单实际扣除费用 - bill.ActualFee = deductFee - bill.DesiredFee = deductFee - globals.SugarLogger.Debugf("bill ======== %s", utils.Format4Output(bill, false)) - if _, err = dao.UpdateEntity(db, bill, "ActualFee", "DesiredFee"); err != nil { - globals.SugarLogger.Errorf("更新门店配送信息错误:%d,%v", deductFee, err) + if err = dao.UpdateWaybillActualFee(db, bill.VendorWaybillID, bill.VendorOrderID, deductFee, deductFee); err != nil { + globals.SugarLogger.Debugf("================ err := %v", err) + return err } - //} - // 门店发单,支付运单违约金 if store != nil && store.CreateDeliveryType == model.YES && deductFee != model.NO { err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(deductFee), partner.StoreAcctTypeExpendCreateWaybillDeductFee, bill.VendorOrderID, bill.VendorWaybillID, 0) diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index a50b9c593..deccb62cd 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -1466,6 +1466,13 @@ func GetOrdersForJxPay(db *DaoDB, finishTimeBegin, finishTimeEnd time.Time) (goo return goods, err } +// UpdateWaybillActualFee 修改运单实际支付价格 +func UpdateWaybillActualFee(db *DaoDB, vendorWaybillId, vendorOrderId string, actualFee, desiredFee int64) error { + sql := ` UPDATE waybill SET actual_fee = ? ,desired_fee = ? WHERE vendor_order_id = ? AND vendor_waybill_id = ?` + _, err := ExecuteSQL(db, sql, []interface{}{actualFee, desiredFee, vendorOrderId, vendorWaybillId}...) + return err +} + func GetWaybills(db *DaoDB, vendorOrderID string, vendors []int64) (waybills []*model.Waybill, err error) { sql := ` SELECT * FROM waybill From 9555fc6e3d4b8da05125821a4d3e4974ea9eb2da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 11:59:18 +0800 Subject: [PATCH 20/52] 1 --- conf/app.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/app.conf b/conf/app.conf index 8257bc917..8a95e5cb6 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -682,7 +682,7 @@ fnAppID = "6705486294797503379" fnAppSecret = "c1e6c280-e618-4103-9d0a-673bc54fb22e" fnCode = "uDEyAmTbrfS2qjYbgi20Jm" fnMerchantId= "51658" -fnCallbackURL = "http://callback.jxc4.com/fn/msg" +fnCallbackURL = "http://callback.test.jxc4.com/fn/msg" # 快手授权地址 kuaiShouAppId = "ks680887971696897880" From 79aa575b8beb06fd196e86af04118338eca42ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 14:24:20 +0800 Subject: [PATCH 21/52] 1 --- .../jxcallback/scheduler/basesch/basesch_ext.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/business/jxcallback/scheduler/basesch/basesch_ext.go b/business/jxcallback/scheduler/basesch/basesch_ext.go index e9b99e14d..16f7cb1a0 100644 --- a/business/jxcallback/scheduler/basesch/basesch_ext.go +++ b/business/jxcallback/scheduler/basesch/basesch_ext.go @@ -350,11 +350,18 @@ func (c *BaseScheduler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID st } func (c *BaseScheduler) SetOrderWaybillTip(ctx *jxcontext.Context, vendorOrderID string, vendorID int, tipFee int64, isPay int) (errCode string, err error) { - if order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, vendorID); err == nil { - if errCode, err = c.CheckStoreBalanceWithTip(ctx, order, tipFee, isPay); err == nil { - err = c.SetOrderWaybillTipByOrder(ctx, order, tipFee) - } + order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, vendorID) + globals.SugarLogger.Debugf("========vendorOrderID : %s,%d,%d,%d", vendorOrderID, vendorID, tipFee, isPay) + globals.SugarLogger.Debugf("================order: %s", utils.Format4Output(order, false)) + if err != nil { + return "", err } + errCode, err = c.CheckStoreBalanceWithTip(ctx, order, tipFee, isPay) + globals.SugarLogger.Debugf("================errCode: %s,%v", errCode, err) + if err != nil { + return errCode, err + } + err = c.SetOrderWaybillTipByOrder(ctx, order, tipFee) return errCode, err } From 72c9b89faeb01d625a5db7280f2ed4773a53da1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 14:39:07 +0800 Subject: [PATCH 22/52] 1 --- business/jxcallback/scheduler/basesch/basesch_ext.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/business/jxcallback/scheduler/basesch/basesch_ext.go b/business/jxcallback/scheduler/basesch/basesch_ext.go index 16f7cb1a0..4e3d878ec 100644 --- a/business/jxcallback/scheduler/basesch/basesch_ext.go +++ b/business/jxcallback/scheduler/basesch/basesch_ext.go @@ -351,13 +351,10 @@ func (c *BaseScheduler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID st func (c *BaseScheduler) SetOrderWaybillTip(ctx *jxcontext.Context, vendorOrderID string, vendorID int, tipFee int64, isPay int) (errCode string, err error) { order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, vendorID) - globals.SugarLogger.Debugf("========vendorOrderID : %s,%d,%d,%d", vendorOrderID, vendorID, tipFee, isPay) - globals.SugarLogger.Debugf("================order: %s", utils.Format4Output(order, false)) if err != nil { return "", err } errCode, err = c.CheckStoreBalanceWithTip(ctx, order, tipFee, isPay) - globals.SugarLogger.Debugf("================errCode: %s,%v", errCode, err) if err != nil { return errCode, err } @@ -405,7 +402,7 @@ func (c *BaseScheduler) CheckStoreBalanceWithTip(ctx *jxcontext.Context, order * } // 是否确认支付 if isPay != model.YES { - return model.ErrCodeIsPaySure, fmt.Errorf("此订单已经支付小费[%d]元,本次增加小费[%d]元,总支出小费[%d]元", order.WaybillTipMoney/100, tipFee/100, order.WaybillTipMoney+tipFee/100) + return model.ErrCodeIsPaySure, fmt.Errorf("此订单已经支付小费[%d]元,本次增加小费[%d]元,总支出小费[%d]元", order.WaybillTipMoney/100, tipFee/100, (order.WaybillTipMoney+tipFee)/100) } return errCode, err From 423810a078bae5022defb522ab595c6ada8033c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 18:26:04 +0800 Subject: [PATCH 23/52] 1' --- business/partner/delivery/dada/waybill.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index 3cc8207b7..ecea9fcb5 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -550,6 +550,7 @@ func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeiso // 待接单,待取货(小于一分钟,大于十五分钟)不扣钱 // 待取货1-15分钟内取消扣两元 func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) { + return 200, nil dadaOrder, err := api.DadaAPI.QueryOrderInfo(orderId) if err != nil { return 0, err From f3d285495f840a3bf63a6631c25ca986c5ebc3b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 18 May 2023 18:42:21 +0800 Subject: [PATCH 24/52] 1 --- business/jxcallback/orderman/order.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 25be1c691..f610b159b 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -559,6 +559,7 @@ func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model. return err } + globals.SugarLogger.Debugf("========%s", utils.Format4Output(bill, false)) if err = dao.UpdateWaybillActualFee(db, bill.VendorWaybillID, bill.VendorOrderID, deductFee, deductFee); err != nil { globals.SugarLogger.Debugf("================ err := %v", err) return err From d6b96563a13884f03f4ca3c810813354ad32dc50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 09:19:24 +0800 Subject: [PATCH 25/52] 1 --- business/jxcallback/orderman/order.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index f610b159b..19c582ed9 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -530,15 +530,15 @@ func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.W cancelWaybill[bill.VendorWaybillID] = bill // 已经全部运单取消,退款结算 if len(bills) == len(cancelWaybill) { - for _, v := range bills { - if v.VendorWaybillID == bill.VendorWaybillID { - continue - } - // 已经取消订单的违约金计算 - if err = countWaybillSettleInfo(db, order, v, store); err != nil { - return err - } - } + //for _, v := range bills { + // if v.VendorWaybillID == bill.VendorWaybillID { + // continue + // } + // // 已经取消订单的违约金计算 + // if err = countWaybillSettleInfo(db, order, v, store); err != nil { + // return err + // } + //} // 最终的金额核算,多退少补 if err = orderFeeSettle(db, order, bill, bills, store); err != nil { From b8057327fd3611230f03e84ec95ee57bc617316a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 09:43:52 +0800 Subject: [PATCH 26/52] 1 --- business/jxcallback/scheduler/defsch/defsch_ext.go | 2 +- business/jxstore/cms/store_acct.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index b47ec0e50..4df82b1cc 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -193,7 +193,7 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex // 收最贵的一个订单配送费(配送费发送变化,收取最贵的价格) globals.SugarLogger.Debugf("==========iszero,isequal := %s,%s", utils.Format4Output(isZero, false), utils.Format4Output(isZero, false)) globals.SugarLogger.Debugf("==========expend,lastFee := %s,%s", utils.Format4Output(expend, false), utils.Format4Output(lastFee, false)) - if !isZero && !isEqual { // 满足此条件是,门店发单已经存在此订单的发单记录 + if !isZero && !isEqual { // 满足此条件是,门店发单已经存在此订单的发单记录,且支出记录大于退还记录 var newPrice int64 if len(courierVendorIDs) == 1 { courierVendorID := courierVendorIDs[0] diff --git a/business/jxstore/cms/store_acct.go b/business/jxstore/cms/store_acct.go index 583035836..5d7ae992f 100644 --- a/business/jxstore/cms/store_acct.go +++ b/business/jxstore/cms/store_acct.go @@ -158,8 +158,8 @@ func (s *StoreAcctManager) CheckStoreAcctExpendExist(vendorOrderID string) (isEq expends, incomes int db = dao.GetDB() ) - // 当前订单的支出金额(临时运费+真实运费)[小费] - expends, err = dao.GetStoreAcctExpendTotal(db, 0, []int{partner.StoreAcctTypeExpendCreateWaybillEx, partner.StoreAcctTypeExpendCreateWaybillTip, partner.StoreAcctTypeExpendCreateWaybill2ndMore, partner.StoreAcctTypeExpendCreateWaybillDeductFee, partner.StoreAcctTypeRealFeeExpend}, vendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) + // 当前订单的支出金额(临时运费+真实运费)[小费] partner.StoreAcctTypeExpendCreateWaybillDeductFee 违约金不参与计算,本来就要扣除 + expends, err = dao.GetStoreAcctExpendTotal(db, 0, []int{partner.StoreAcctTypeExpendCreateWaybillEx, partner.StoreAcctTypeExpendCreateWaybillTip, partner.StoreAcctTypeExpendCreateWaybill2ndMore, partner.StoreAcctTypeRealFeeExpend}, vendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) // 当前订单的退费金额() incomes, err = dao.GetStoreAcctIncomeTotal(db, 0, []int{partner.StoreAcctTypeRealFeeIncome, partner.StoreAcctTypeIncomeCancelTemp, partner.StoreAcctTypeIncomeCancelReal}, vendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue) if expends != incomes { From 987c02c0e2de0e151131cc21f304bbb5fe0c6254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 10:25:56 +0800 Subject: [PATCH 27/52] 1 --- .../jxcallback/auto_delivery/auto_delivery.go | 143 +++++++++--------- business/jxstore/misc/misc.go | 4 +- business/model/dao/dao_order.go | 4 +- 3 files changed, 71 insertions(+), 80 deletions(-) diff --git a/business/jxcallback/auto_delivery/auto_delivery.go b/business/jxcallback/auto_delivery/auto_delivery.go index 1e1a9e991..899e02e23 100644 --- a/business/jxcallback/auto_delivery/auto_delivery.go +++ b/business/jxcallback/auto_delivery/auto_delivery.go @@ -3,15 +3,15 @@ package auto_delivery import ( "crypto/rand" "encoding/json" + "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + "git.rosy.net.cn/jx-callback/business/partner" "math/big" "strings" "git.rosy.net.cn/baseapi/utils" - "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" - "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/dao" - "git.rosy.net.cn/jx-callback/business/partner" "git.rosy.net.cn/jx-callback/globals" ) @@ -91,86 +91,79 @@ func AutoSettingFakeDelivery() { return } - // todo 修改刷单门店配置 storeId-vendorId 指定刷单门店和平台 0京东/1美团/3饿了么/14抖音/99全部平台 - // 获取刷单门店订单 - orderList, err := dao.GetOrderListByStoreList(db, utils.StringSlice2Int64(strings.Split(configList[0].Value, ","))) - if err != nil { - globals.SugarLogger.Errorf("获取门店刷单记录错误") - return - } - if len(orderList) == model.NO { - return - } + storeList := strings.Split(configList[0].Value, ",") + for _, v := range storeList { + storeIdAndVendorId := strings.Split(v, "-") + orderList, err := dao.GetOrderListByStoreList(db, []int64{utils.Str2Int64(storeIdAndVendorId[0])}, utils.Str2Int(storeIdAndVendorId[1])) + if err != nil { + globals.SugarLogger.Errorf("获取门店刷单记录错误") + continue + } + if len(orderList) == model.NO { + return + } - for _, v := range orderList { // 1.根据订单客户地址获取骑手列表 riderKey := "" - if strings.Contains(v.ConsigneeAddress, "重庆") || strings.Contains(v.ConsigneeAddress, "上海") || strings.Contains(v.ConsigneeAddress, "北京") || strings.Contains(v.ConsigneeAddress, "天津") { - riderKey = strings.Split(v.ConsigneeAddress, "市")[0] - } else if strings.Contains(v.ConsigneeAddress, "省") { - riderKey = strings.Split(v.ConsigneeAddress, "省")[0] + storeDetail, _ := dao.GetStoreDetail(db, utils.Str2Int(storeIdAndVendorId[0]), 0, "") + place, err := dao.GetParentCodeByCode(db, storeDetail.CityCode) + if err != nil { + globals.SugarLogger.Debugf("根据门店的城市code获取省份code错误: %s", err) + return + } + if strings.Contains(place.Name, "省") { + riderKey = strings.Split(place.Name, "省")[0] } else { - storeDetail, _ := dao.GetStoreDetail(db, v.JxStoreID, 0, "") - if strings.Contains(storeDetail.Address, "重庆") || strings.Contains(storeDetail.Address, "上海") || strings.Contains(storeDetail.Address, "北京") || strings.Contains(storeDetail.Address, "天津") { - riderKey = strings.Split(storeDetail.Address, "市")[0] - } else { - riderKey = strings.Split(storeDetail.Address, "省")[0] - if riderKey == "" { - place, err := dao.GetParentCodeByCode(db, storeDetail.CityCode) - if err != nil { - globals.SugarLogger.Debugf("根据门店的城市code获取省份code错误: %s", err) - return - } - riderKey = place.Name[0 : len(place.Name)-3] + riderKey = strings.Split(place.Name, "市")[0] + } + + for _, v := range orderList { + if len(riderListInfo[riderKey]) == model.NO { + // 骑手列表 + configRiderList, err := dao.QueryConfigs(db, "riderList", "Sys", "") + if err != nil { + globals.SugarLogger.Errorf("抖音自动刷单获取骑手列表错误:%v", err) + return + } + if err := json.Unmarshal([]byte(configRiderList[0].Value), &riderListInfo); err != nil { + globals.SugarLogger.Errorf("抖音自动刷单获取骑手列表错误:%v", err) + return + } + } + randNumber, _ := rand.Int(rand.Reader, big.NewInt(int64(len(riderListInfo[riderKey])))) + randTime := randNumber.Int64() + if randTime < 0 { + randTime = 1 + } + if randTime >= int64(len(riderListInfo[riderKey])) { + randTime = int64(len(riderListInfo[riderKey])) - 1 + } + if (v.PhoneAscription == "" || strings.Split(v.PhoneAscription, "-")[0] != model.PhoneAscriptionAddressYes) && v.VendorID == model.VendorIDDD { + continue + } + // 自动拣货 + if v.Status < model.OrderStatusFinishedPickup { // 未拣货 + handler := partner.GetPurchaseOrderHandlerFromVendorID(v.VendorID) + flag := model.IsOrderDeliveryByStore(v) || model.IsOrderDeliveryBySelf(v) + if err := handler.PickupGoods(v, flag, jxcontext.AdminCtx.GetUserName()); err != nil { + globals.SugarLogger.Errorf("自动拣货错误:[%v]", err) + break + } + } + //自动发单 + if len(riderListInfo[riderKey]) == 0 { + globals.SugarLogger.Errorf("riderListInfo[riderKey][randTime] :%s,%s,%d", riderListInfo[riderKey][randTime], riderKey, randTime) + break + } + for riderName, riderPhone := range riderListInfo[riderKey][randTime] { + if err := defsch.FixedScheduler.SelfDeliveringAndUpdateStatus(jxcontext.AdminCtx, v.VendorOrderID, v.VendorID, jxcontext.AdminCtx.GetUserName(), riderName, riderPhone); err != nil { + globals.SugarLogger.Errorf("自动发货错误:[%v]", err) + break } } } - if len(riderListInfo[riderKey]) == model.NO { - // 骑手列表 - configRiderList, err := dao.QueryConfigs(db, "riderList", "Sys", "") - if err != nil { - globals.SugarLogger.Errorf("抖音自动刷单获取骑手列表错误:%v", err) - return - } - if err := json.Unmarshal([]byte(configRiderList[0].Value), &riderListInfo); err != nil { - globals.SugarLogger.Errorf("抖音自动刷单获取骑手列表错误:%v", err) - return - } - } - globals.SugarLogger.Debug("==========%s,%d", riderKey, len(riderListInfo[riderKey])) - globals.SugarLogger.Debug("==========%s", utils.Format4Output(riderListInfo[riderKey], false)) - randNumber, _ := rand.Int(rand.Reader, big.NewInt(int64(len(riderListInfo[riderKey])))) - randTime := randNumber.Int64() - if randTime < 0 { - randTime = 1 - } - if randTime >= int64(len(riderListInfo[riderKey])) { - randTime = int64(len(riderListInfo[riderKey])) - 1 - } - if (v.PhoneAscription == "" || strings.Split(v.PhoneAscription, "-")[0] != model.PhoneAscriptionAddressYes) && v.VendorID == model.VendorIDDD { - continue - } - // 自动拣货 - if v.Status < model.OrderStatusFinishedPickup { // 未拣货 - handler := partner.GetPurchaseOrderHandlerFromVendorID(v.VendorID) - flag := model.IsOrderDeliveryByStore(v) || model.IsOrderDeliveryBySelf(v) - if err := handler.PickupGoods(v, flag, jxcontext.AdminCtx.GetUserName()); err != nil { - globals.SugarLogger.Errorf("自动拣货错误:[%v]", err) - break - } - } - //自动发单 - if len(riderListInfo[riderKey]) == 0 { - globals.SugarLogger.Errorf("riderListInfo[riderKey][randTime] :%s,%s,%d", riderListInfo[riderKey][randTime], riderKey, randTime) - break - } - for riderName, riderPhone := range riderListInfo[riderKey][randTime] { - if err := defsch.FixedScheduler.SelfDeliveringAndUpdateStatus(jxcontext.AdminCtx, v.VendorOrderID, v.VendorID, jxcontext.AdminCtx.GetUserName(), riderName, riderPhone); err != nil { - globals.SugarLogger.Errorf("自动发货错误:[%v]", err) - break - } - } } + } diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index dd539dc81..3274713a8 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -210,9 +210,7 @@ func Init() { // 抖音自动刷单(自动发单拣货,设置骑手) ScheduleTimerFuncByInterval(func() { - if beego.BConfig.RunMode != "jxgy" { - auto_delivery.AutoSettingFakeDelivery() - } + auto_delivery.AutoSettingFakeDelivery() }, 10*time.Second, 3*time.Minute) // 定时任务更新负责人信息 diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index deccb62cd..1090193bf 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -1906,9 +1906,9 @@ func GetOrderStoreIDs(db *DaoDB, beginAt, endAt time.Time, vendorID int) (storeI } // GetOrderListByStoreList 根据门店id获取正在刷单的门店商品 -func GetOrderListByStoreList(db *DaoDB, storeId []int64) (order []*model.GoodsOrder, err error) { +func GetOrderListByStoreList(db *DaoDB, storeId []int64, vendorId int) (order []*model.GoodsOrder, err error) { sql := `SELECT * FROM goods_order g WHERE g.order_created_at >= ? AND g.order_created_at <= ? AND g.jx_store_id IN (` + GenQuestionMarks(len(storeId)) + `)` + `AND g.vendor_id IN (` + GenQuestionMarks(2) + `)` + `AND g.status < ?` - sqlParam := []interface{}{time.Now().AddDate(0, 0, -5), time.Now().AddDate(0, 0, 1), storeId, []int{model.VendorIDDD, model.VendorIDEBAI}, model.OrderStatusDelivering} + sqlParam := []interface{}{time.Now().AddDate(0, 0, -5), time.Now().AddDate(0, 0, 1), storeId, []int{vendorId}, model.OrderStatusDelivering} if err := GetRows(db, &order, sql, sqlParam...); err != nil { return nil, err From b1db0f1b8cdf7f0c027734d608ad168f34997fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 10:39:04 +0800 Subject: [PATCH 28/52] 1 --- business/model/dao/dao_order.go | 4 ++-- business/partner/delivery/rider.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 1090193bf..7cf9e2e11 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -1907,8 +1907,8 @@ func GetOrderStoreIDs(db *DaoDB, beginAt, endAt time.Time, vendorID int) (storeI // GetOrderListByStoreList 根据门店id获取正在刷单的门店商品 func GetOrderListByStoreList(db *DaoDB, storeId []int64, vendorId int) (order []*model.GoodsOrder, err error) { - sql := `SELECT * FROM goods_order g WHERE g.order_created_at >= ? AND g.order_created_at <= ? AND g.jx_store_id IN (` + GenQuestionMarks(len(storeId)) + `)` + `AND g.vendor_id IN (` + GenQuestionMarks(2) + `)` + `AND g.status < ?` - sqlParam := []interface{}{time.Now().AddDate(0, 0, -5), time.Now().AddDate(0, 0, 1), storeId, []int{vendorId}, model.OrderStatusDelivering} + sql := `SELECT * FROM goods_order g WHERE g.order_created_at >= ? AND g.order_created_at <= ? AND g.jx_store_id IN (` + GenQuestionMarks(len(storeId)) + `)` + `AND g.vendor_id = ?` + `AND g.status < ?` + sqlParam := []interface{}{time.Now().AddDate(0, 0, -5), time.Now().AddDate(0, 0, 1), storeId, vendorId, model.OrderStatusDelivering} if err := GetRows(db, &order, sql, sqlParam...); err != nil { return nil, err diff --git a/business/partner/delivery/rider.go b/business/partner/delivery/rider.go index c8ffb8d73..168d09057 100644 --- a/business/partner/delivery/rider.go +++ b/business/partner/delivery/rider.go @@ -362,7 +362,7 @@ func UpdateFakeWayBillToTiktok() { if riderInfo.LogisticsContext != model.RiderGetOrderDeliverFailed && riderInfo.LogisticsContext != model.RiderGetOrderDeliverOther && riderInfo.LogisticsContext != model.RiderWaitRider { riderInfo.LogisticsContext = fmt.Sprintf(riderInfo.LogisticsContext, riderInfo.CourierName, riderInfo.CourierPhone) } - + // 推送骑手信息 paramsMap := utils.Struct2Map(riderInfo, "", true) handler := partner.GetPurchaseOrderHandlerFromVendorID(fakeWayBill[i].OrderVendorID) From 63e48268bf2287b9ee953550806398f196a84cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 11:02:35 +0800 Subject: [PATCH 29/52] 1 --- business/jxcallback/auto_delivery/auto_delivery.go | 1 + business/model/dao/dao_order.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/business/jxcallback/auto_delivery/auto_delivery.go b/business/jxcallback/auto_delivery/auto_delivery.go index 899e02e23..4d356a810 100644 --- a/business/jxcallback/auto_delivery/auto_delivery.go +++ b/business/jxcallback/auto_delivery/auto_delivery.go @@ -95,6 +95,7 @@ func AutoSettingFakeDelivery() { storeList := strings.Split(configList[0].Value, ",") for _, v := range storeList { storeIdAndVendorId := strings.Split(v, "-") + globals.SugarLogger.Debugf("========storeIdAndVendorId : %s", utils.Format4Output(storeIdAndVendorId, false)) orderList, err := dao.GetOrderListByStoreList(db, []int64{utils.Str2Int64(storeIdAndVendorId[0])}, utils.Str2Int(storeIdAndVendorId[1])) if err != nil { globals.SugarLogger.Errorf("获取门店刷单记录错误") diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 7cf9e2e11..26c1116f6 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -2,6 +2,7 @@ package dao import ( "fmt" + "git.rosy.net.cn/jx-callback/globals" "regexp" "strconv" "time" @@ -1907,9 +1908,11 @@ func GetOrderStoreIDs(db *DaoDB, beginAt, endAt time.Time, vendorID int) (storeI // GetOrderListByStoreList 根据门店id获取正在刷单的门店商品 func GetOrderListByStoreList(db *DaoDB, storeId []int64, vendorId int) (order []*model.GoodsOrder, err error) { - sql := `SELECT * FROM goods_order g WHERE g.order_created_at >= ? AND g.order_created_at <= ? AND g.jx_store_id IN (` + GenQuestionMarks(len(storeId)) + `)` + `AND g.vendor_id = ?` + `AND g.status < ?` + sql := `SELECT * FROM goods_order g WHERE g.order_created_at >= ? AND g.order_created_at <= ? AND g.jx_store_id IN (` + GenQuestionMarks(len(storeId)) + `)` + ` AND g.vendor_id = ?` + `AND g.status < ?` sqlParam := []interface{}{time.Now().AddDate(0, 0, -5), time.Now().AddDate(0, 0, 1), storeId, vendorId, model.OrderStatusDelivering} + globals.SugarLogger.Debugf("======sql : %s", sql) + globals.SugarLogger.Debugf("======sql : %s", utils.Format4Output(sqlParam, false)) if err := GetRows(db, &order, sql, sqlParam...); err != nil { return nil, err } From 8a4c389aa5400919dc6728b30697bceac5e30204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 11:05:35 +0800 Subject: [PATCH 30/52] 1 --- business/jxcallback/auto_delivery/auto_delivery.go | 1 - business/model/dao/dao_order.go | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/business/jxcallback/auto_delivery/auto_delivery.go b/business/jxcallback/auto_delivery/auto_delivery.go index 4d356a810..899e02e23 100644 --- a/business/jxcallback/auto_delivery/auto_delivery.go +++ b/business/jxcallback/auto_delivery/auto_delivery.go @@ -95,7 +95,6 @@ func AutoSettingFakeDelivery() { storeList := strings.Split(configList[0].Value, ",") for _, v := range storeList { storeIdAndVendorId := strings.Split(v, "-") - globals.SugarLogger.Debugf("========storeIdAndVendorId : %s", utils.Format4Output(storeIdAndVendorId, false)) orderList, err := dao.GetOrderListByStoreList(db, []int64{utils.Str2Int64(storeIdAndVendorId[0])}, utils.Str2Int(storeIdAndVendorId[1])) if err != nil { globals.SugarLogger.Errorf("获取门店刷单记录错误") diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 26c1116f6..a9063e530 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -2,7 +2,6 @@ package dao import ( "fmt" - "git.rosy.net.cn/jx-callback/globals" "regexp" "strconv" "time" @@ -1908,11 +1907,9 @@ func GetOrderStoreIDs(db *DaoDB, beginAt, endAt time.Time, vendorID int) (storeI // GetOrderListByStoreList 根据门店id获取正在刷单的门店商品 func GetOrderListByStoreList(db *DaoDB, storeId []int64, vendorId int) (order []*model.GoodsOrder, err error) { - sql := `SELECT * FROM goods_order g WHERE g.order_created_at >= ? AND g.order_created_at <= ? AND g.jx_store_id IN (` + GenQuestionMarks(len(storeId)) + `)` + ` AND g.vendor_id = ?` + `AND g.status < ?` + sql := `SELECT * FROM goods_order g WHERE g.order_created_at >= ? AND g.order_created_at <= ? AND g.jx_store_id IN (` + GenQuestionMarks(len(storeId)) + `)` + ` AND g.vendor_id = ? ` + `AND g.status < ?` sqlParam := []interface{}{time.Now().AddDate(0, 0, -5), time.Now().AddDate(0, 0, 1), storeId, vendorId, model.OrderStatusDelivering} - globals.SugarLogger.Debugf("======sql : %s", sql) - globals.SugarLogger.Debugf("======sql : %s", utils.Format4Output(sqlParam, false)) if err := GetRows(db, &order, sql, sqlParam...); err != nil { return nil, err } From 764d74e902a04f2b3690d6975bb7ea099a84ed2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 11:13:07 +0800 Subject: [PATCH 31/52] 1 --- business/partner/delivery/fn/waybill.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/business/partner/delivery/fn/waybill.go b/business/partner/delivery/fn/waybill.go index 1708c1cf7..c6b403c6a 100644 --- a/business/partner/delivery/fn/waybill.go +++ b/business/partner/delivery/fn/waybill.go @@ -73,6 +73,9 @@ func (c *DeliveryHandler) CancelWaybill(bill *model.Waybill, cancelReasonID int, err = nil } } + if err != nil { + return err + } bill.Status = model.WaybillStatusCanceled bill.Remark = cancelReason From 538479d55d016f125534f7f02713f729712a03e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 11:42:41 +0800 Subject: [PATCH 32/52] 1 --- business/jxcallback/orderman/order.go | 4 ---- business/jxcallback/scheduler/defsch/defsch_ext.go | 3 --- business/partner/delivery/dada/waybill.go | 1 - business/partner/delivery/mtps/waybill.go | 2 +- main.go | 8 +++----- 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 19c582ed9..72f001fc0 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -559,9 +559,7 @@ func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model. return err } - globals.SugarLogger.Debugf("========%s", utils.Format4Output(bill, false)) if err = dao.UpdateWaybillActualFee(db, bill.VendorWaybillID, bill.VendorOrderID, deductFee, deductFee); err != nil { - globals.SugarLogger.Debugf("================ err := %v", err) return err } // 门店发单,支付运单违约金 @@ -569,7 +567,6 @@ func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model. err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(deductFee), partner.StoreAcctTypeExpendCreateWaybillDeductFee, bill.VendorOrderID, bill.VendorWaybillID, 0) if err != nil { partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,获取违约金门店扣除失败:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, deductFee), "") - globals.SugarLogger.Errorf("InsertStoreAcctIncomeAndUpdateStoreAcctBalance 483 : %v", err) return err } } @@ -578,7 +575,6 @@ func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model. err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID) if err != nil { partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,获取违约金品牌扣除失败:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, deductFee), "") - globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err) return err } } diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index 4df82b1cc..3c06d220d 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -184,15 +184,12 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex } deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID) - globals.SugarLogger.Debugf("=========deliveryFeeMap= := %s", utils.Format4Output(deliveryFeeMap, false)) // 不管是门店发单还是品牌发单都要扣钱,门店发单扣门店,品牌发单扣品牌 if order.CreateDeliveryType == model.YES { // 获取平台配送费 isEqual, isZero, _ := partner.CurStoreAcctManager.CheckStoreAcctExpendExist(order.VendorOrderID) // 当前订单的支出记录 expend, lastFee, _ := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID) // 最后一个运单支出记录 // 收最贵的一个订单配送费(配送费发送变化,收取最贵的价格) - globals.SugarLogger.Debugf("==========iszero,isequal := %s,%s", utils.Format4Output(isZero, false), utils.Format4Output(isZero, false)) - globals.SugarLogger.Debugf("==========expend,lastFee := %s,%s", utils.Format4Output(expend, false), utils.Format4Output(lastFee, false)) if !isZero && !isEqual { // 满足此条件是,门店发单已经存在此订单的发单记录,且支出记录大于退还记录 var newPrice int64 if len(courierVendorIDs) == 1 { diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index ecea9fcb5..3cc8207b7 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -550,7 +550,6 @@ func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeiso // 待接单,待取货(小于一分钟,大于十五分钟)不扣钱 // 待取货1-15分钟内取消扣两元 func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) { - return 200, nil dadaOrder, err := api.DadaAPI.QueryOrderInfo(orderId) if err != nil { return 0, err diff --git a/business/partner/delivery/mtps/waybill.go b/business/partner/delivery/mtps/waybill.go index 53c338db2..364dabddc 100644 --- a/business/partner/delivery/mtps/waybill.go +++ b/business/partner/delivery/mtps/waybill.go @@ -507,7 +507,7 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId // 接单取消扣凉快 return 200, nil case utils.Int2Str(mtpsapi.OrderStatusPickedUp): // 取货 - bill, err := partner.CurOrderManager.LoadWaybill(deliverId, model.VendorIDDada) + bill, err := partner.CurOrderManager.LoadWaybill(deliverId, model.VendorIDMTPS) if err != nil { return 0, err } diff --git a/main.go b/main.go index 48d01c5c7..681d09769 100644 --- a/main.go +++ b/main.go @@ -167,11 +167,9 @@ func main() { return } - if web.BConfig.RunMode != "jxgy" { - if err := tasks.RefreshFnToken(); err != nil { - globals.SugarLogger.Errorf("RefreshFnToken failed with error:%s", err) - return - } + if err := tasks.RefreshFnToken(); err != nil { + globals.SugarLogger.Errorf("RefreshFnToken failed with error:%s", err) + return } if err := tasks.RefreshQywxToken(); err != nil { globals.SugarLogger.Errorf("RefreshQywxToken failed with error:%s", err) From 99a1c0b58c5ba9a767393f437cbfb58239f52f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 13:44:24 +0800 Subject: [PATCH 33/52] 1 --- business/partner/delivery/fn/store.go | 1 + conf/app.conf | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/business/partner/delivery/fn/store.go b/business/partner/delivery/fn/store.go index 29c9fbddf..831467f85 100644 --- a/business/partner/delivery/fn/store.go +++ b/business/partner/delivery/fn/store.go @@ -83,6 +83,7 @@ func shopStatus2JX(status int) (jxStatus int) { func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) { shopInfo, err := api.FnAPI.GetStore(vendorStoreID) + globals.SugarLogger.Debugf("============fn %s,%v", utils.Format4Output(shopInfo, false), err) if err == nil { storeDetail = &dao.StoreDetail2{ Store: model.Store{ diff --git a/conf/app.conf b/conf/app.conf index 8a95e5cb6..6c558737f 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -474,10 +474,9 @@ jdShopAccessToken2 = "9ad9cf5fc8b140b19a1dbbb700b47676kown" jdShopAppKey2 = "D5E8352BE0786ED16F77B4548F62F09A" jdShopAppSecret2 = "71e1061ac2f246f6ac27efb900edba12" -fnAppID = "6a3e2073-1850-413b-9eb7-6c342ec36e1c" -fnAppSecret = "a8248088-a742-4c33-a0db-03aeae00ca7d" -fnMerchantId = "51658" -fnCode = "uDEyAmTbrfS2qjYbgi20Jm" +fnAppID = "6705486294797503379" +fnAppSecret = "c1e6c280-e618-4103-9d0a-673bc54fb22e" +fnMerchantId= "51658" fnCallbackURL = "http://callback-jxgy.jxc4.com/fn/msg" # 快手授权地址 From a86873d5e275da376aa9e4ad9a782d9d494375d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 13:53:03 +0800 Subject: [PATCH 34/52] 1 --- business/partner/delivery/fn/store.go | 1 - business/partner/delivery/fn/waybill.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/business/partner/delivery/fn/store.go b/business/partner/delivery/fn/store.go index 831467f85..29c9fbddf 100644 --- a/business/partner/delivery/fn/store.go +++ b/business/partner/delivery/fn/store.go @@ -83,7 +83,6 @@ func shopStatus2JX(status int) (jxStatus int) { func (c *DeliveryHandler) GetStore(ctx *jxcontext.Context, storeID int, vendorStoreID string) (storeDetail *dao.StoreDetail2, err error) { shopInfo, err := api.FnAPI.GetStore(vendorStoreID) - globals.SugarLogger.Debugf("============fn %s,%v", utils.Format4Output(shopInfo, false), err) if err == nil { storeDetail = &dao.StoreDetail2{ Store: model.Store{ diff --git a/business/partner/delivery/fn/waybill.go b/business/partner/delivery/fn/waybill.go index c6b403c6a..82cce00ed 100644 --- a/business/partner/delivery/fn/waybill.go +++ b/business/partner/delivery/fn/waybill.go @@ -69,6 +69,7 @@ func (c *DeliveryHandler) CancelWaybill(bill *model.Waybill, cancelReasonID int, } parameter.PartnerOrderCode = bill.VendorOrderID if err = api.FnAPI.CancelOrder(parameter); err != nil { + globals.SugarLogger.Debugf("============err := %v ", err) if strings.Contains(err.Error(), "运单暂未生成") { err = nil } From aa2a7cbcbf1ed994f442d0e9335198e71b089f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 14:14:48 +0800 Subject: [PATCH 35/52] 1 --- .../jxcallback/scheduler/defsch/defsch_ext.go | 2 -- business/jxstore/cms/store.go | 1 - business/jxutils/tasksch/task.go | 3 +-- business/model/dao/dao_order.go | 1 - business/partner/delivery/dada/waybill.go | 1 - business/partner/delivery/fn/waybill.go | 18 ++++++++++++------ controllers/fn_callback.go | 6 ++---- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/business/jxcallback/scheduler/defsch/defsch_ext.go b/business/jxcallback/scheduler/defsch/defsch_ext.go index 3c06d220d..4f61ed2ed 100644 --- a/business/jxcallback/scheduler/defsch/defsch_ext.go +++ b/business/jxcallback/scheduler/defsch/defsch_ext.go @@ -206,7 +206,6 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex } newPrice = maxFee } - globals.SugarLogger.Debugf("==========newPrice := %d", newPrice) // 门店支出运费,门店发单 if order.CreateDeliveryType == model.YES { if storeAcct.AccountBalance > int(newPrice) { @@ -527,7 +526,6 @@ func (s *DefScheduler) QueryOrderWaybillFeeInfoEx(ctx *jxcontext.Context, vendor } else { feeInfo.DeliveryFee += model.WayBillDeliveryMarkUp // 加收两毛 feeInfo.TimeoutSecond = timeoutSecond - globals.SugarLogger.Debugf("预下单加价==============GetWaybillFee := %s", utils.Format4Output(feeInfo, false)) } } else { feeInfo = &partner.WaybillFeeInfo{ diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 30a235188..8d0953306 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -1856,7 +1856,6 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor // 更新商品 if isSyncStoreMapSku { - globals.SugarLogger.Debugf("修改门店调价包是同步门店商品价格=============: %v", err) singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) task := tasksch.NewParallelTask("修改门店调价包的时候,同时同步门店商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index ae2df0469..2179e462f 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -511,8 +511,7 @@ func SendMessage(t *BaseTask) { } if err := ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "异步任务完成", content); err != nil { - err2 := enterprise_msg.SendUserMessage(authInfo.Mobile, "异步任务完成", "", content) - globals.SugarLogger.Errorf("==============errr ddd %v", err2) + enterprise_msg.SendUserMessage(authInfo.Mobile, "异步任务完成", "", content) } } } diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index a9063e530..1f8f61857 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -1030,7 +1030,6 @@ func GetOrders(db *DaoDB, ids []int64, isIncludeSku, isIncludeFake bool, fromDat if len(statuss) > 0 { sqlWhere += " AND t1.status IN (" + GenQuestionMarks(len(statuss)) + ")" sqlParams = append(sqlParams, statuss) - //globals.SugarLogger.Debugf("sqlParams statuss===========%d", statuss) } } if params["lockStatuss"] != nil { diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index 3cc8207b7..086b19b66 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -282,7 +282,6 @@ func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInf if result, err = api.DadaAPI.QueryDeliverFee(billParams); err != nil { return nil, err } - globals.SugarLogger.Debugf("QueryDeliverFee===============预下单获取配送费:%s", utils.Format4Output(result, false)) deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(result.DeliverFee) // jxutils.StandardPrice2Int(result.Fee) deliveryFeeInfo.RefDeliveryFee = deliveryFeeInfo.DeliveryFee } diff --git a/business/partner/delivery/fn/waybill.go b/business/partner/delivery/fn/waybill.go index 82cce00ed..cfa109344 100644 --- a/business/partner/delivery/fn/waybill.go +++ b/business/partner/delivery/fn/waybill.go @@ -205,11 +205,22 @@ func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInf } // 订单状态 -func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify) (resp *fnpsapi.CallbackResponse) { +func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify, resultParam *fnpsapi.ShortStatus) (resp *fnpsapi.CallbackResponse) { cc := &fnpsapi.OrderCallbackParam{} if err := utils.Map2StructByJson(msg.Param, cc, true); err != nil { return fnpsapi.Err2CallbackResponse(err, "") } + var good *model.GoodsOrder + sql := `SELECT * FROM goods_order WHERE vendor_order_id = ? ORDER BY order_created_at DESC LIMIT 1 OFFSET 0` + sqlParams := []interface{}{cc.PartnerOrderCode} + dao.GetRow(dao.GetDB(), &good, sql, sqlParams) + if good == nil || good.VendorOrderID == "" { + _, err := fnpsapi.HttpToGuoYuanFN(utils.Struct2MapByJson(resultParam), "order") + if err != nil { + return fnpsapi.Err2CallbackResponse(err, "") + } + return fnpsapi.Err2CallbackResponse(nil, "") + } order := &model.Waybill{ VendorWaybillID: utils.Int64ToStr(cc.OrderId), @@ -225,11 +236,6 @@ func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify) (resp *fnpsapi.CallbackRespon order.StatusTime = time.Now() } order.VendorOrderID, order.OrderVendorID = jxutils.SplitUniversalOrderID(cc.PartnerOrderCode) - - var good *model.GoodsOrder - sql := `SELECT * FROM goods_order WHERE vendor_order_id = ? ORDER BY order_created_at DESC LIMIT 1 OFFSET 0` - sqlParams := []interface{}{cc.PartnerOrderCode} - dao.GetRow(dao.GetDB(), &good, sql, sqlParams) order.OrderVendorID = good.VendorID orderStatus := utils.Str2Int64(order.VendorStatus) diff --git a/controllers/fn_callback.go b/controllers/fn_callback.go index 09a3a21f9..997fe77fc 100644 --- a/controllers/fn_callback.go +++ b/controllers/fn_callback.go @@ -11,7 +11,6 @@ type FnController struct { web.Controller } - // 门店回掉 func (c *FnController) FnStore() { if c.Ctx.Input.Method() == http.MethodPost { @@ -33,7 +32,7 @@ func (c *FnController) FnStore() { // 订单状态 func (c *FnController) FnOrder() { if c.Ctx.Input.Method() == http.MethodPost { - msg, callbackResponse := api.FnAPI.GetChainOrderStatusNotify(c.Ctx.Request) + msg, result, callbackResponse := api.FnAPI.GetChainOrderStatusNotify(c.Ctx.Request) if callbackResponse.Code == -1 { c.Data["code"] = callbackResponse c.ServeJSON() @@ -41,7 +40,7 @@ func (c *FnController) FnOrder() { } // 订单回调 - callbackResponse = fn.OnWaybillMsg(msg) + callbackResponse = fn.OnWaybillMsg(msg, result) c.Data["code"] = callbackResponse c.ServeJSON() } else { @@ -66,4 +65,3 @@ func (c *FnController) FnAbnormal() { c.Abort("404") } } - From 583e4d696c8c21c3a8a1ae5345a1cca785782d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 15:18:29 +0800 Subject: [PATCH 36/52] 1 --- business/jxcallback/orderman/order.go | 26 ++++++++++++++++++------- business/model/dao/store.go | 28 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 72f001fc0..6e4ba8e3e 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -607,16 +607,28 @@ func orderFeeSettle(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill, globals.SugarLogger.Errorf("GetStoreAcctIncomeTotal 551 err :%v", err) return err } - for _, v := range bills { - allFee += int(v.DesiredFee) - allFee += int(v.TipFee) + + } else { + billExpend, err = dao.GetBrandBillOrderExpend(db, store.BrandID, bill.VendorOrderID) + if err != nil { + return err } - // 运单支出费用统计,应该等于 支出费用- 退还费用 - globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,运单计算费用:%d", billExpend, billIncome, allFee) - if allFee != billExpend-billIncome { - globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,剩余退还费用:%d", billExpend, billIncome, billExpend-billIncome) + billIncome, err = dao.GetBrandBillOrderIncome(db, store.BrandID, bill.VendorOrderID) + if err != nil { + return err } } + + for _, v := range bills { + allFee += int(v.DesiredFee) + allFee += int(v.TipFee) + } + // 运单支出费用统计,应该等于 支出费用- 退还费用 + globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,运单计算费用:%d", billExpend, billIncome, allFee) + if allFee != billExpend-billIncome { + globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,剩余退还费用:%d", billExpend, billIncome, billExpend-billIncome) + } + if billExpend-billIncome == allFee { globals.SugarLogger.Debugf("计算正确,运单消耗[%d],账户支出[%d],账户退回[%d]", allFee, billExpend, billIncome) partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("计算正确,运单消耗[%d],账户支出[%d],账户退回[%d]", allFee, billExpend, billIncome), "") diff --git a/business/model/dao/store.go b/business/model/dao/store.go index 0022599b9..c53c61894 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -1397,6 +1397,34 @@ func GetBrandBalance(db *DaoDB, brandID int) (result int, err error) { return balance.Balance, err } +// GetBrandBillOrderExpend 获取订单品牌支出记录 +func GetBrandBillOrderExpend(db *DaoDB, brandId int, vendorOrderID string) (int, error) { + var Price = &struct { + Price int + }{} + + sql := `SELECT IFNULL(SUM(price),0) balance FROM brand_bill + WHERE brand_id = ? AND bill_type = ? AND vendor_order_id = ? AND fee_type IN (?,?,?) ` + sqlParam := []interface{}{brandId, model.BrandBillTypeExpend, vendorOrderID, model.BrandBillFeeTypeDelivery, model.BrandBillFeeTypeTipFee, model.BrandBillFeeTypeDeductFee} + + err := GetRow(db, &Price, sql, sqlParam) + return Price.Price, err +} + +// GetBrandBillOrderIncome 获取品牌订单的退还记录 +func GetBrandBillOrderIncome(db *DaoDB, brandId int, vendorOrderID string) (int, error) { + var Price = &struct { + Price int + }{} + + sql := `SELECT IFNULL(SUM(price),0) balance FROM brand_bill + WHERE brand_id = ? AND bill_type = ? AND vendor_order_id = ? AND fee_type IN (?,?,?) ` + sqlParam := []interface{}{brandId, model.BrandBillTypeIncome, vendorOrderID, model.BrandBillFeeTypeDelivery, model.BrandBillFeeTypeTipFee, model.BrandBillFeeTypeDeductFee} + + err := GetRow(db, &Price, sql, sqlParam) + return Price.Price, err +} + func GetBrandBill(db *DaoDB, brandID int, vendorOrderID string, billType, feeType int, vendorWaybillOrderID string) (result []*model.BrandBill, err error) { sql := ` SELECT * From 8193a47a8a7a3bd161d709d0f6d572302a91287c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 15:29:11 +0800 Subject: [PATCH 37/52] 1 --- business/model/dao/store.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/business/model/dao/store.go b/business/model/dao/store.go index c53c61894..9fa3a02b5 100644 --- a/business/model/dao/store.go +++ b/business/model/dao/store.go @@ -1403,7 +1403,7 @@ func GetBrandBillOrderExpend(db *DaoDB, brandId int, vendorOrderID string) (int, Price int }{} - sql := `SELECT IFNULL(SUM(price),0) balance FROM brand_bill + sql := `SELECT IFNULL(SUM(price),0) price FROM brand_bill WHERE brand_id = ? AND bill_type = ? AND vendor_order_id = ? AND fee_type IN (?,?,?) ` sqlParam := []interface{}{brandId, model.BrandBillTypeExpend, vendorOrderID, model.BrandBillFeeTypeDelivery, model.BrandBillFeeTypeTipFee, model.BrandBillFeeTypeDeductFee} @@ -1417,7 +1417,7 @@ func GetBrandBillOrderIncome(db *DaoDB, brandId int, vendorOrderID string) (int, Price int }{} - sql := `SELECT IFNULL(SUM(price),0) balance FROM brand_bill + sql := `SELECT IFNULL(SUM(price),0) price FROM brand_bill WHERE brand_id = ? AND bill_type = ? AND vendor_order_id = ? AND fee_type IN (?,?,?) ` sqlParam := []interface{}{brandId, model.BrandBillTypeIncome, vendorOrderID, model.BrandBillFeeTypeDelivery, model.BrandBillFeeTypeTipFee, model.BrandBillFeeTypeDeductFee} From 188835f764276f457ec532b35143207b69afb9de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 15:33:40 +0800 Subject: [PATCH 38/52] 1 --- business/partner/delivery/dada/waybill.go | 1 + main.go | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index 086b19b66..82b1f8057 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -549,6 +549,7 @@ func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeiso // 待接单,待取货(小于一分钟,大于十五分钟)不扣钱 // 待取货1-15分钟内取消扣两元 func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) { + return 200, nil dadaOrder, err := api.DadaAPI.QueryOrderInfo(orderId) if err != nil { return 0, err diff --git a/main.go b/main.go index 681d09769..48d01c5c7 100644 --- a/main.go +++ b/main.go @@ -167,9 +167,11 @@ func main() { return } - if err := tasks.RefreshFnToken(); err != nil { - globals.SugarLogger.Errorf("RefreshFnToken failed with error:%s", err) - return + if web.BConfig.RunMode != "jxgy" { + if err := tasks.RefreshFnToken(); err != nil { + globals.SugarLogger.Errorf("RefreshFnToken failed with error:%s", err) + return + } } if err := tasks.RefreshQywxToken(); err != nil { globals.SugarLogger.Errorf("RefreshQywxToken failed with error:%s", err) From 220a7bf2fe0abf94c0fcf1e2175827093bf3b1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 15:40:44 +0800 Subject: [PATCH 39/52] 1 --- business/jxcallback/orderman/order.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 6e4ba8e3e..dcb7c6f87 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -639,7 +639,7 @@ func orderFeeSettle(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill, switch store.CreateDeliveryType { case model.NO: // 品牌结算 if abnormalAmount > 0 { // 多退 - err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, abnormalAmount, model.BrandBillTypeIncome, model.BrandBillFeeTypeSys, order.VendorOrderID, order.VendorWaybillID) + err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, abnormalAmount, model.BrandBillTypeIncome, model.BrandBillFeeTypeDelivery, order.VendorOrderID, order.VendorWaybillID) if err != nil { partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,品牌支出大于消耗,多退:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, abnormalAmount), "") globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err) @@ -647,7 +647,7 @@ func orderFeeSettle(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill, } } if abnormalAmount < 0 { - err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, abnormalAmount*-1, model.BrandBillTypeExpend, model.BrandBillFeeTypeSys, order.VendorOrderID, order.VendorWaybillID) + err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, abnormalAmount*-1, model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorOrderID, order.VendorWaybillID) if err != nil { partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,品牌支出小于消耗,少补:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, abnormalAmount), "") globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err) From ff76d8512e4f972c370cc1a632bced7d55ef3026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 16:13:03 +0800 Subject: [PATCH 40/52] 1 --- business/partner/purchase/jx/localjx/kuaishou_pay.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/partner/purchase/jx/localjx/kuaishou_pay.go b/business/partner/purchase/jx/localjx/kuaishou_pay.go index a576bbd56..d2639f239 100644 --- a/business/partner/purchase/jx/localjx/kuaishou_pay.go +++ b/business/partner/purchase/jx/localjx/kuaishou_pay.go @@ -62,6 +62,7 @@ func pay4OrderByKs(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp } // 预下单 prePayInfo, err := api.KuaiShouApi.PreCreateOrder(param) + globals.SugarLogger.Debugf("=======err : %v", err) if err == nil { orderPay = &model.OrderPay{ PayOrderID: order.VendorOrderID, // 抖音订单id From 6978db379d31ec53c7d4ee52e859bdbde306168e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 17:14:55 +0800 Subject: [PATCH 41/52] 1 --- business/partner/purchase/jx/localjx/tonglianpay.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/business/partner/purchase/jx/localjx/tonglianpay.go b/business/partner/purchase/jx/localjx/tonglianpay.go index c0953c940..3e69fe493 100644 --- a/business/partner/purchase/jx/localjx/tonglianpay.go +++ b/business/partner/purchase/jx/localjx/tonglianpay.go @@ -64,6 +64,8 @@ func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, err = api.TLpayAPI.CreateH5UnitorderOrder(param2) } else { result, err := api.TLpayAPI.CreateUnitorderOrder(param) + globals.SugarLogger.Debugf("===============result: %s", utils.Format4Output(result, false)) + globals.SugarLogger.Debugf("===============result: %s", utils.Format4Output(err, false)) if err == nil { var result2 tonglianpayapi.PayInfo json.Unmarshal([]byte(result.PayInfo), &result2) From 7c7def7436e011d439b417de9ce6580abc75a446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 17:23:03 +0800 Subject: [PATCH 42/52] 1 --- .../purchase/jx/localjx/kuaishou_pay.go | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/business/partner/purchase/jx/localjx/kuaishou_pay.go b/business/partner/purchase/jx/localjx/kuaishou_pay.go index d2639f239..1cd8dcf8e 100644 --- a/business/partner/purchase/jx/localjx/kuaishou_pay.go +++ b/business/partner/purchase/jx/localjx/kuaishou_pay.go @@ -40,19 +40,19 @@ func pay4OrderByKs(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp } param := &kuaishou_mini.PreCreateOrderReq{ - OutOrderNo: utils.Int64ToStr(GenPayOrderID(order)), - OpenId: authBindList[0].AuthID, - TotalAmount: order.ActualPayPrice, - Subject: "蔬菜水果日用品", - Detail: getOrderBriefKs(order), - TypeDetail: 1832, // 蔬菜:费率2%,水果:1833%2 - ExpireTime: 60 * 10, - Sign: "", - Attach: "", - GoodsId: "", - GoodsDetailUrl: "", - MultiCopiesGoodsInfo: "", - CancelOrder: 0, + OutOrderNo: utils.Int64ToStr(GenPayOrderID(order)), + OpenId: authBindList[0].AuthID, + TotalAmount: order.ActualPayPrice, + Subject: "蔬菜水果日用品", + Detail: getOrderBriefKs(order), + TypeDetail: 1832, // 蔬菜:费率2%,水果:1833%2 + ExpireTime: 60 * 10, + Sign: "", + //Attach: "", + //GoodsId: "", + //GoodsDetailUrl: "", + //MultiCopiesGoodsInfo: "", + CancelOrder: 0, } if beego.BConfig.RunMode == "jxgy" { From 20cda2be44650e742ea7864ea7e53b6db13854bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 18:26:23 +0800 Subject: [PATCH 43/52] 1 --- business/auth2/authprovider/weixin/weixin.go | 13 +++++++++++++ business/partner/purchase/jx/localjx/order.go | 14 +++++++------- .../partner/purchase/jx/localjx/tonglianpay.go | 10 +++++++++- controllers/jx_order2.go | 3 ++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/business/auth2/authprovider/weixin/weixin.go b/business/auth2/authprovider/weixin/weixin.go index d554b8726..1295f2341 100644 --- a/business/auth2/authprovider/weixin/weixin.go +++ b/business/auth2/authprovider/weixin/weixin.go @@ -122,3 +122,16 @@ func (a *Auther) getAPI() *weixinapi.API { func (a *Auther) GetUserType() (userType int8) { return model.UserTypeStoreBoss } + +func GetAPI(authType string) *weixinapi.API { + if authType == AuthTypeWeixin { + return api.WeixinPageAPI + } + if authType == AuthTypeWxApp { + return api.WeixinApp + } + if authType == AuthTypeWxAppCaishi { + return api.WeixinApp2 + } + return api.WeixinAPI +} diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index 475c1d10b..4cc2b2d39 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -324,7 +324,7 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType //if subAppID == tiktok.TiktokAppId || subAppID == tiktok.TiktokJXDJAppID { // subAppID = model.JXC4AppId // 京西商城 //} - if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID, ""); err == nil && orderPay != nil { dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } @@ -351,7 +351,7 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType ActualPayPrice: priceDefendOrders[0].ActualPayPrice, VendorID: model.VendorIDJX, } - if orderPay, err = pay4OrderByTL(ctx, order2, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + if orderPay, err = pay4OrderByTL(ctx, order2, payType, vendorPayType, subAppID, ""); err == nil && orderPay != nil { dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } @@ -359,7 +359,7 @@ func Pay4Order(ctx *jxcontext.Context, orderID int64, payType int, vendorPayType return orderPay, err } -func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType int, vendorPayType, subAppID string) (orderPay *model.OrderPay, err error) { +func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType int, vendorPayType, subAppID, code string) (orderPay *model.OrderPay, err error) { var ( db = dao.GetDB() order *model.GoodsOrder @@ -383,7 +383,7 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType ActualPayPrice: int64(discountCard.Price), VendorID: model.VendorIDJX, } - if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID, code); err == nil && orderPay != nil { dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } @@ -416,7 +416,7 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType ActualPayPrice: int64(storeOrder.ActualPayPrice), VendorID: model.VendorIDJX, } - if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID, code); err == nil && orderPay != nil { dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } @@ -431,7 +431,7 @@ func Pay4User(ctx *jxcontext.Context, thingID int, vendorOrderID string, payType ActualPayPrice: int64(brandOrder.ActualPayPrice), VendorID: model.VendorIDJX, } - if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID); err == nil && orderPay != nil { + if orderPay, err = pay4OrderByTL(ctx, order, payType, vendorPayType, subAppID, code); err == nil && orderPay != nil { dao.WrapAddIDCULDEntity(orderPay, ctx.GetUserName()) err = dao.CreateEntity(dao.GetDB(), orderPay) } @@ -841,7 +841,7 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64 if jxOrder.OrderType != model.OrderTypeMatter || (jxOrder.OrderType == model.OrderTypeMatter && fromStoreID == -1) { outJxOrder.Skus = append(outJxOrder.Skus, jxSku) outJxOrder.OrderPrice += int64(jxSku.Count) * jxSku.SalePrice - } else { //以下else为物料订单袋子金额和数量处理 + } else { //以下else为物料订单袋子金额和数量处理 if !result.Flag { //只要flag是false就按原价申请,是true再按订单量 outJxOrder.Skus = append(outJxOrder.Skus, jxSku) outJxOrder.OrderPrice += int64(jxSku.Count) * jxSku.SalePrice diff --git a/business/partner/purchase/jx/localjx/tonglianpay.go b/business/partner/purchase/jx/localjx/tonglianpay.go index 3e69fe493..ba1896650 100644 --- a/business/partner/purchase/jx/localjx/tonglianpay.go +++ b/business/partner/purchase/jx/localjx/tonglianpay.go @@ -19,7 +19,7 @@ import ( "git.rosy.net.cn/jx-callback/globals/api" ) -func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, vendorPayType, subAppID string) (orderPay *model.OrderPay, err error) { +func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, vendorPayType, subAppID, code string) (orderPay *model.OrderPay, err error) { // if order.FromStoreID != 0 { // result, _ := orderman.GetMatterStoreOrderCount(nil, order.FromStoreID) // if !result.Flag { @@ -45,6 +45,14 @@ func pay4OrderByTL(ctx *jxcontext.Context, order *model.GoodsOrder, payType int, if err == nil && authInfo.GetAuthType() == weixin.AuthTypeMini && authInfo.GetAuthTypeID() == subAppID { param.Acct = authInfo.GetAuthID() } + if code != "" { + appAuth := strings.Split(code, "_") + sessionInfo, err := weixin.GetAPI(appAuth[0]).SNSCode2Session(appAuth[1]) + if err != nil { + return nil, err + } + param.Acct = sessionInfo.OpenID + } } if vendorPayType == tonglianpayapi.PayTypeZfbJS || vendorPayType == tonglianpayapi.PayTypeZfbApp { if authInfo, err := ctx.GetV2AuthInfo(); err == nil { diff --git a/controllers/jx_order2.go b/controllers/jx_order2.go index b8f1220c1..b3a6c9c7e 100644 --- a/controllers/jx_order2.go +++ b/controllers/jx_order2.go @@ -123,12 +123,13 @@ func (c *JxOrderController) Pay4StoreMyselfDeliverOrder() { // @Param vendorOrderID formData string false "订单ID" // @Param payType formData int true "支付类型" // @Param vendorPayType formData string true "平台支付类型" +// @Param code formData string false "app吊起微信支付时,需要code获取openID" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /Pay4User [post] func (c *JxOrderController) Pay4User() { c.callPay4User(func(params *tJxorderPay4UserParams) (retVal interface{}, errCode string, err error) { - retVal, err = localjx.Pay4User(params.Ctx, params.ThingID, params.VendorOrderID, params.PayType, params.VendorPayType, params.SubAppID) + retVal, err = localjx.Pay4User(params.Ctx, params.ThingID, params.VendorOrderID, params.PayType, params.VendorPayType, params.SubAppID, params.Code) return retVal, "", err }) } From cbd17ccf6f3bb92f8717b20026e05fe06c4ff193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 18:58:46 +0800 Subject: [PATCH 44/52] 1 --- .../jxcallback/auto_delivery/auto_delivery.go | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/business/jxcallback/auto_delivery/auto_delivery.go b/business/jxcallback/auto_delivery/auto_delivery.go index 899e02e23..0e93d0087 100644 --- a/business/jxcallback/auto_delivery/auto_delivery.go +++ b/business/jxcallback/auto_delivery/auto_delivery.go @@ -107,15 +107,21 @@ func AutoSettingFakeDelivery() { // 1.根据订单客户地址获取骑手列表 riderKey := "" storeDetail, _ := dao.GetStoreDetail(db, utils.Str2Int(storeIdAndVendorId[0]), 0, "") - place, err := dao.GetParentCodeByCode(db, storeDetail.CityCode) - if err != nil { - globals.SugarLogger.Debugf("根据门店的城市code获取省份code错误: %s", err) - return - } - if strings.Contains(place.Name, "省") { - riderKey = strings.Split(place.Name, "省")[0] + if strings.Contains(storeDetail.Address, "重庆") || strings.Contains(storeDetail.Address, "上海") || strings.Contains(storeDetail.Address, "北京") || strings.Contains(storeDetail.Address, "天津") { + riderKey = strings.Split(storeDetail.Address, "市")[0] + } else if strings.Contains(storeDetail.Address, "省") { + riderKey = strings.Split(storeDetail.Address, "省")[0] } else { - riderKey = strings.Split(place.Name, "市")[0] + place, err := dao.GetParentCodeByCode(db, storeDetail.CityCode) + if err != nil { + globals.SugarLogger.Debugf("根据门店的城市code获取省份code错误: %s", err) + return + } + if strings.Contains(place.Name, "省") { + riderKey = strings.Split(place.Name, "省")[0] + } else { + riderKey = strings.Split(place.Name, "市")[0] + } } for _, v := range orderList { From 9c5b43d367c018d598c509c32af0675b8ee92970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 19:08:28 +0800 Subject: [PATCH 45/52] 1 --- business/jxcallback/auto_delivery/auto_delivery.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/business/jxcallback/auto_delivery/auto_delivery.go b/business/jxcallback/auto_delivery/auto_delivery.go index 0e93d0087..ebd82049a 100644 --- a/business/jxcallback/auto_delivery/auto_delivery.go +++ b/business/jxcallback/auto_delivery/auto_delivery.go @@ -90,12 +90,14 @@ func AutoSettingFakeDelivery() { globals.SugarLogger.Errorf("newConfig 刷单门店设置异常") return } + globals.SugarLogger.Debugf("======configList : %s", utils.Format4Output(configList, false)) // 获取刷单门店订单 storeList := strings.Split(configList[0].Value, ",") for _, v := range storeList { storeIdAndVendorId := strings.Split(v, "-") orderList, err := dao.GetOrderListByStoreList(db, []int64{utils.Str2Int64(storeIdAndVendorId[0])}, utils.Str2Int(storeIdAndVendorId[1])) + globals.SugarLogger.Debugf("======orderList : %s", utils.Format4Output(orderList, false)) if err != nil { globals.SugarLogger.Errorf("获取门店刷单记录错误") continue @@ -123,6 +125,7 @@ func AutoSettingFakeDelivery() { riderKey = strings.Split(place.Name, "市")[0] } } + globals.SugarLogger.Debugf("======riderKey : %s", utils.Format4Output(riderKey, false)) for _, v := range orderList { if len(riderListInfo[riderKey]) == model.NO { From 4e1bd2775b9944bd54671c165e73ed1b1e38eda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 19 May 2023 19:11:56 +0800 Subject: [PATCH 46/52] 1 --- business/jxcallback/auto_delivery/auto_delivery.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/business/jxcallback/auto_delivery/auto_delivery.go b/business/jxcallback/auto_delivery/auto_delivery.go index ebd82049a..63ce01ff5 100644 --- a/business/jxcallback/auto_delivery/auto_delivery.go +++ b/business/jxcallback/auto_delivery/auto_delivery.go @@ -103,7 +103,7 @@ func AutoSettingFakeDelivery() { continue } if len(orderList) == model.NO { - return + continue } // 1.根据订单客户地址获取骑手列表 From bcdd4c164e262db41a4339384bef02815db69697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 22 May 2023 09:27:45 +0800 Subject: [PATCH 47/52] 1 --- main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 48d01c5c7..30f9eaeef 100644 --- a/main.go +++ b/main.go @@ -167,12 +167,12 @@ func main() { return } - if web.BConfig.RunMode != "jxgy" { - if err := tasks.RefreshFnToken(); err != nil { - globals.SugarLogger.Errorf("RefreshFnToken failed with error:%s", err) - return - } + //if web.BConfig.RunMode != "jxgy" { + if err := tasks.RefreshFnToken(); err != nil { + globals.SugarLogger.Errorf("RefreshFnToken failed with error:%s", err) + return } + //} if err := tasks.RefreshQywxToken(); err != nil { globals.SugarLogger.Errorf("RefreshQywxToken failed with error:%s", err) return From 85f17d4c644603f63dc688c734ec67d95ed2160f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 22 May 2023 13:41:59 +0800 Subject: [PATCH 48/52] 1 --- business/jxcallback/auto_delivery/auto_delivery.go | 3 --- business/jxstore/misc/misc.go | 4 ++-- business/partner/delivery/rider.go | 8 ++++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/business/jxcallback/auto_delivery/auto_delivery.go b/business/jxcallback/auto_delivery/auto_delivery.go index 63ce01ff5..aaff62cb6 100644 --- a/business/jxcallback/auto_delivery/auto_delivery.go +++ b/business/jxcallback/auto_delivery/auto_delivery.go @@ -90,14 +90,12 @@ func AutoSettingFakeDelivery() { globals.SugarLogger.Errorf("newConfig 刷单门店设置异常") return } - globals.SugarLogger.Debugf("======configList : %s", utils.Format4Output(configList, false)) // 获取刷单门店订单 storeList := strings.Split(configList[0].Value, ",") for _, v := range storeList { storeIdAndVendorId := strings.Split(v, "-") orderList, err := dao.GetOrderListByStoreList(db, []int64{utils.Str2Int64(storeIdAndVendorId[0])}, utils.Str2Int(storeIdAndVendorId[1])) - globals.SugarLogger.Debugf("======orderList : %s", utils.Format4Output(orderList, false)) if err != nil { globals.SugarLogger.Errorf("获取门店刷单记录错误") continue @@ -125,7 +123,6 @@ func AutoSettingFakeDelivery() { riderKey = strings.Split(place.Name, "市")[0] } } - globals.SugarLogger.Debugf("======riderKey : %s", utils.Format4Output(riderKey, false)) for _, v := range orderList { if len(riderListInfo[riderKey]) == model.NO { diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 3274713a8..ff244ed19 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -203,12 +203,12 @@ func Init() { "09:35:00", }) - // 每分钟轮询一次,推送抖店骑手信息 + // 每分钟轮询一次,推送骑手信息 ScheduleTimerFuncByInterval(func() { delivery.UpdateFakeWayBillToTiktok() }, 10*time.Second, 5*time.Second) - // 抖音自动刷单(自动发单拣货,设置骑手) + // (自动发单拣货,设置骑手) ScheduleTimerFuncByInterval(func() { auto_delivery.AutoSettingFakeDelivery() }, 10*time.Second, 3*time.Minute) diff --git a/business/partner/delivery/rider.go b/business/partner/delivery/rider.go index 168d09057..d4b830103 100644 --- a/business/partner/delivery/rider.go +++ b/business/partner/delivery/rider.go @@ -292,7 +292,7 @@ func makeRiderInfo(fakeWayBill *model.Waybill, riderInfo *mtpsapi.RiderInfo) { fakeWayBill.VendorStatus = utils.Int64ToStr(model.WaybillStatusCourierAssigned) case 12: // 骑手接单 riderInfo.LogisticsContext = model.RiderWaitGetGoods - riderInfo.LogisticsStatus = 12 + riderInfo.LogisticsStatus = 10 riderInfo.OpCode = tiktok_api.TiktokLogisticsORDERRECEIVED // 下一状态以及推送时间 fakeWayBill.Status = model.WaybillStatusCourierArrived @@ -324,7 +324,7 @@ func makeRiderInfo(fakeWayBill *model.Waybill, riderInfo *mtpsapi.RiderInfo) { return } -// UpdateFakeWayBillToTiktok 轮询更新假订单到抖音 +// UpdateFakeWayBillToTiktok 轮询更新假订单到抖音(抖音/美团/饿百) func UpdateFakeWayBillToTiktok() { scheduleTimer, _ := rand.Int(rand.Reader, big.NewInt(1000)) randTimeSchedule := scheduleTimer.Int64() @@ -362,7 +362,7 @@ func UpdateFakeWayBillToTiktok() { if riderInfo.LogisticsContext != model.RiderGetOrderDeliverFailed && riderInfo.LogisticsContext != model.RiderGetOrderDeliverOther && riderInfo.LogisticsContext != model.RiderWaitRider { riderInfo.LogisticsContext = fmt.Sprintf(riderInfo.LogisticsContext, riderInfo.CourierName, riderInfo.CourierPhone) } - + // 推送骑手信息 paramsMap := utils.Struct2Map(riderInfo, "", true) handler := partner.GetPurchaseOrderHandlerFromVendorID(fakeWayBill[i].OrderVendorID) @@ -401,7 +401,7 @@ func UpdateFakeWayBillToTiktok() { globals.SugarLogger.Debugf("UPDATA goods_order Err :%s", err.Error()) } // 饿百订单推送订单送达 - if fakeWayBill[i].OrderVendorID == model.VendorIDEBAI { + if fakeWayBill[i].OrderVendorID == model.VendorIDEBAI || fakeWayBill[i].OrderVendorID == model.VendorIDMTWM { if err := handler.Swtich2SelfDelivered(order, "JingXiAdmin"); err != nil { globals.SugarLogger.Errorf("Swtich2SelfDelivered err := %v", err) } From d936e5fc54108b76fdaa4238c27cdcd12dc773a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 22 May 2023 14:01:20 +0800 Subject: [PATCH 49/52] 1 --- business/partner/delivery/dada/waybill.go | 1 - 1 file changed, 1 deletion(-) diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index 82b1f8057..086b19b66 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -549,7 +549,6 @@ func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeiso // 待接单,待取货(小于一分钟,大于十五分钟)不扣钱 // 待取货1-15分钟内取消扣两元 func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) { - return 200, nil dadaOrder, err := api.DadaAPI.QueryOrderInfo(orderId) if err != nil { return 0, err From 784d60912c9522faa0883c6e623e731506e0907f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 22 May 2023 14:42:26 +0800 Subject: [PATCH 50/52] 1 --- business/auth2/authprovider/weixin/weixin.go | 16 +++++++------- business/jxutils/smsmsg/smsmsg.go | 22 ++++++++++---------- business/model/dao/dao_order.go | 6 ++---- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/business/auth2/authprovider/weixin/weixin.go b/business/auth2/authprovider/weixin/weixin.go index 1295f2341..5fe831d12 100644 --- a/business/auth2/authprovider/weixin/weixin.go +++ b/business/auth2/authprovider/weixin/weixin.go @@ -123,15 +123,13 @@ func (a *Auther) GetUserType() (userType int8) { return model.UserTypeStoreBoss } -func GetAPI(authType string) *weixinapi.API { - if authType == AuthTypeWeixin { - return api.WeixinPageAPI +func GetAPI(appID string) *weixinapi.API { + miniApi := api.WeixinMiniAPI + if len(appID) > 0 && appID == api.WeixinMiniAppID2 { + miniApi = api.WeixinMiniAPI2 } - if authType == AuthTypeWxApp { - return api.WeixinApp + if len(appID) > 0 && appID == api.WeixinMiniAppIDsc { + miniApi = api.WeixinMiniAPIsc } - if authType == AuthTypeWxAppCaishi { - return api.WeixinApp2 - } - return api.WeixinAPI + return miniApi } diff --git a/business/jxutils/smsmsg/smsmsg.go b/business/jxutils/smsmsg/smsmsg.go index 970accba3..4e908a8b8 100644 --- a/business/jxutils/smsmsg/smsmsg.go +++ b/business/jxutils/smsmsg/smsmsg.go @@ -128,18 +128,18 @@ func NotifyPickOrder(order *model.GoodsOrder) (err error) { order.NotifyType = int(store.SMSNotify) partner.CurOrderManager.UpdateOrderFields(order, []string{"NotifyType"}) //品牌余额, 一条5分 - if order.CreateDeliveryType == model.YES { // 门店发单 - noticeType := 0 - switch feeType { - case model.BrandBillFeeTypeSms: - noticeType = partner.StoreAcctTypeExpendTextMessageNotify - case model.BrandBillFeeTypeVoice: - noticeType = partner.StoreAcctTypeExpendVoiceMessageNotify - } - err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, 5, noticeType, order.VendorOrderID, "", 0) - } else if order.CreateDeliveryType == model.NO { // 品牌发单 - err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, 5, model.BrandBillTypeExpend, feeType, order.VendorOrderID, "") + //if order.CreateDeliveryType == model.YES { // 门店发单 + noticeType := 0 + switch feeType { + case model.BrandBillFeeTypeSms: + noticeType = partner.StoreAcctTypeExpendTextMessageNotify + case model.BrandBillFeeTypeVoice: + noticeType = partner.StoreAcctTypeExpendVoiceMessageNotify } + err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, 5, noticeType, order.VendorOrderID, "", 0) + /*} else if order.CreateDeliveryType == model.NO { // 品牌发单 + err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, 5, model.BrandBillTypeExpend, feeType, order.VendorOrderID, "") + }*/ return err } balance, _ := partner.CurStoreAcctManager.GetBrandBalance(store.BrandID) diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index 1f8f61857..a9e6ff004 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -448,13 +448,11 @@ type DeliveryFee struct { // GetPlatformDesiredFee 统计平台的订单的配送费信息 func GetPlatformDesiredFee(db *DaoDB, storeIDs []int, finishedAtBegin, finishedAtEnd time.Time) (fee []*DeliveryFee, err error) { sql := ` - SELECT sum(b.actual_fee) actual_fee,b.order_vendor_id vendor_id FROM goods_order t2 - RIGHT JOIN waybill b ON t2.vendor_order_id = b.vendor_order_id AND b.status IN (?,?) AND b.vendor_order_id <> b.vendor_waybill_id + SELECT sum(b.desired_fee) actual_fee,b.order_vendor_id vendor_id FROM goods_order t2 + RIGHT JOIN waybill b ON t2.vendor_order_id = b.vendor_order_id AND b.vendor_order_id <> b.vendor_waybill_id WHERE t2.order_finished_at >= ? AND t2.order_finished_at <= ? ` sqlParams := []interface{}{ - model.WaybillStatusDelivered, - 110, finishedAtBegin, finishedAtEnd, } From c011092a2bf0185bfde24a0a4621f93e736f6c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 22 May 2023 16:58:14 +0800 Subject: [PATCH 51/52] 1 --- business/jxcallback/orderman/orderman_ext.go | 33 ++++++-------------- business/model/api.go | 3 +- business/model/dao/dao_order.go | 2 +- business/partner/delivery/rider.go | 17 ++++++++++ controllers/jx_report.go | 2 +- 5 files changed, 31 insertions(+), 26 deletions(-) diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 84d7d0b1b..410968963 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -336,11 +336,7 @@ func (c *OrderManager) GetOrders(ctx *jxcontext.Context, isIncludeFake bool, fro } } } - //if isJxIncomeArea { - // begin = utils.MustInterface2Int64(params["jxIncomeBegin"]) - // end = utils.MustInterface2Int64(params["jxIncomeEnd"]) - //pageSize = math.MaxInt32 - //} + orders, totalCount, err := dao.GetOrders(db, nil, false, isIncludeFake, fromDateStr, toDateStr, isDateFinish, skuIDs, isJxFirst, "", params, offset, pageSize) if err == nil { pagedInfo = &model.PagedInfo{ @@ -382,24 +378,15 @@ func (c *OrderManager) GetOrders(ctx *jxcontext.Context, isIncludeFake bool, fro } } } - //count := &struct { - // Count int - //}{} - //sql2 := ` - // SELECT COUNT(*) count - // FROM goods_order WHERE IF(store_id = 0, jx_store_id ,store_id) = ? - // WHERE order_created_at > ? AND order_created_at < ? - //` - //storeID := 0 - //if order.StoreID == 0 { - // storeID = order.JxStoreID - //} else { - // storeID = order.StoreID - //} - //sqlParams2 := []interface{}{storeID, time.Now().Format("2006-01-02 00:00:00"), time.Now().Format("2006-01-02 23:59:59")} - //if err = dao.GetRow(db, &count, sql2, sqlParams2); err == nil { - // order.StoreDayOrderCount = count.Count - //} + // 统计订单的违约金 + var damages = &struct { + Damages int64 `json:"damages"` + }{} + sqlDamages := ` SELECT SUM(w.desired_fee) damages FROM waybill w WHERE w.vendor_order_id = ? AND w.status = ? ` + paramDamages := []interface{}{order.VendorOrderID, model.OrderStatusCanceled} + if err := dao.GetRow(db, damages, sqlDamages, paramDamages); err == nil { + order.LiquidatedDamages = damages.Damages + } return retVal, err }, orders) tasksch.HandleTask(task, nil, true).Run() diff --git a/business/model/api.go b/business/model/api.go index 50ecaeb4d..a62208e1f 100644 --- a/business/model/api.go +++ b/business/model/api.go @@ -70,7 +70,8 @@ type GoodsOrderExt struct { OperatorPhone3 string `orm:"size(16)" json:"operatorPhone3"` // 饿百运营人电话 OperatorName3 string `orm:"size(32)" json:"operatorName3"` // 饿百运营人组(角色) - VendorPayType string `json:"vendorPayType"` // 支付方式,当订单来源小程序时通过支付方式区分订单来源(w06微信/tt抖音/ks快手/支付宝) + VendorPayType string `json:"vendorPayType"` // 支付方式,当订单来源小程序时通过支付方式区分订单来源(w06微信/tt抖音/ks快手/支付宝) + LiquidatedDamages int64 `json:"liquidated_damages"` // 违约金 } type OrderSkuExt struct { diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index a9e6ff004..ac116e38b 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -449,7 +449,7 @@ type DeliveryFee struct { func GetPlatformDesiredFee(db *DaoDB, storeIDs []int, finishedAtBegin, finishedAtEnd time.Time) (fee []*DeliveryFee, err error) { sql := ` SELECT sum(b.desired_fee) actual_fee,b.order_vendor_id vendor_id FROM goods_order t2 - RIGHT JOIN waybill b ON t2.vendor_order_id = b.vendor_order_id AND b.vendor_order_id <> b.vendor_waybill_id + RIGHT JOIN waybill b ON t2.vendor_order_id = b.vendor_order_id AND b.vendor_order_id <> b.vendor_waybill_id WHERE t2.order_finished_at >= ? AND t2.order_finished_at <= ? ` sqlParams := []interface{}{ diff --git a/business/partner/delivery/rider.go b/business/partner/delivery/rider.go index d4b830103..d71d86b9b 100644 --- a/business/partner/delivery/rider.go +++ b/business/partner/delivery/rider.go @@ -3,6 +3,7 @@ package delivery import ( "crypto/rand" "fmt" + "git.rosy.net.cn/jx-callback/business/jxutils" "math/big" "time" @@ -279,6 +280,14 @@ func UpdateOrder2Complete() { } func makeRiderInfo(fakeWayBill *model.Waybill, riderInfo *mtpsapi.RiderInfo) { + order, _ := partner.CurOrderManager.LoadOrder(fakeWayBill.VendorOrderID, fakeWayBill.OrderVendorID) + storeId := 0 + if order.StoreID != 0 { + storeId = order.StoreID + } else { + storeId = order.JxStoreID + } + storeDetail, _ := dao.GetStoreDetail(dao.GetDB(), storeId, order.VendorID, order.VendorOrgCode) switch fakeWayBill.Status { case 5: // 呼叫骑手 riderInfo.LogisticsContext = "呼叫骑手,新建运单" @@ -294,6 +303,8 @@ func makeRiderInfo(fakeWayBill *model.Waybill, riderInfo *mtpsapi.RiderInfo) { riderInfo.LogisticsContext = model.RiderWaitGetGoods riderInfo.LogisticsStatus = 10 riderInfo.OpCode = tiktok_api.TiktokLogisticsORDERRECEIVED + riderInfo.Latitude = utils.Float64ToStr(jxutils.IntCoordinate2Standard(storeDetail.Lat)) + riderInfo.Longitude = utils.Float64ToStr(jxutils.IntCoordinate2Standard(storeDetail.Lng)) // 下一状态以及推送时间 fakeWayBill.Status = model.WaybillStatusCourierArrived fakeWayBill.VendorStatus = utils.Int64ToStr(model.WaybillStatusCourierArrived) @@ -301,6 +312,8 @@ func makeRiderInfo(fakeWayBill *model.Waybill, riderInfo *mtpsapi.RiderInfo) { riderInfo.LogisticsContext = model.RiderToStore riderInfo.LogisticsStatus = 15 riderInfo.OpCode = tiktok_api.TiktokLogisticsRIDERARRIVED + riderInfo.Latitude = utils.Float64ToStr(jxutils.IntCoordinate2Standard(storeDetail.Lat)) + riderInfo.Longitude = utils.Float64ToStr(jxutils.IntCoordinate2Standard(storeDetail.Lng)) // 下一状态以及推送时间 fakeWayBill.Status = model.WaybillStatusDelivering fakeWayBill.VendorStatus = utils.Int64ToStr(model.WaybillStatusDelivering) @@ -308,6 +321,8 @@ func makeRiderInfo(fakeWayBill *model.Waybill, riderInfo *mtpsapi.RiderInfo) { riderInfo.LogisticsContext = model.RiderGetOrderDelivering riderInfo.LogisticsStatus = 20 riderInfo.OpCode = tiktok_api.TiktokLogisticsRIDERPICKUP + riderInfo.Latitude = utils.Float64ToStr(jxutils.IntCoordinate2Standard(storeDetail.Lat)) + riderInfo.Longitude = utils.Float64ToStr(jxutils.IntCoordinate2Standard(storeDetail.Lng)) // 下一状态以及推送时间 fakeWayBill.Status = model.WaybillStatusDelivered fakeWayBill.VendorStatus = utils.Int64ToStr(model.WaybillStatusDelivered) @@ -315,6 +330,8 @@ func makeRiderInfo(fakeWayBill *model.Waybill, riderInfo *mtpsapi.RiderInfo) { riderInfo.LogisticsContext = model.RiderGetOrderDelivered riderInfo.LogisticsStatus = 40 riderInfo.OpCode = tiktok_api.TiktokLogisticsDELIVERED + riderInfo.Latitude = utils.Float64ToStr(jxutils.IntCoordinate2Standard(order.ConsigneeLat)) + riderInfo.Longitude = utils.Float64ToStr(jxutils.IntCoordinate2Standard(order.ConsigneeLng)) // 下一状态以及推送时间 fakeWayBill.Status = model.WaybillStatusFailed fakeWayBill.VendorStatus = utils.Int64ToStr(model.WaybillStatusFailed) diff --git a/controllers/jx_report.go b/controllers/jx_report.go index 2d6159861..7ad99b8cf 100644 --- a/controllers/jx_report.go +++ b/controllers/jx_report.go @@ -126,7 +126,7 @@ func (c *ReportController) GetManageState() { // @Param storeIDs query string false "门店ID列表[1,2,3]" // @Param brandIDs query string false "品牌ID列表[1,2,3]" // @Param vendorID query int true "平台ID" -// @Param sortType query int false "排序类型,1 覆盖范围,2市场规模,3营业时长,4商品数,5虚高商品数,6活动丰富度,7无效订单数,8拒绝订单数,9门店评分,正升序,负倒序" +// @Param sortType query int false "排序类型,1 覆盖范围,2市场规模,3营业时长,4商品数,5虚高商品数,6活动丰富度,7无效订单数,8拒绝订单数,9门店评分,10完成订单数,正升序,负倒序" // @Param offset query int false "门店列表起始序号(以0开始,缺省为0)" // @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)" // @Success 200 {object} controllers.CallResult From 77e7b21917302f9a2ed77c6f355fe96c9a4dd5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 23 May 2023 09:34:23 +0800 Subject: [PATCH 52/52] 1 --- business/jxcallback/orderman/orderman_ext.go | 10 +++ business/jxstore/misc/misc.go | 1 + business/model/store.go | 89 +++++++++----------- main.go | 5 +- 4 files changed, 52 insertions(+), 53 deletions(-) diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 410968963..b2167f1e9 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -502,6 +502,15 @@ func (c *OrderManager) ExportOrders(ctx *jxcontext.Context, fromDateStr, toDateS v.CourierVendorName = model.VendorChineseNames[v.WaybillVendorID] v.Status2 = model.OrderStatusName[v.Status] v.SkuInfo = skuStr + // 统计订单的违约金 + var damages = &struct { + Damages int64 `json:"damages"` + }{} + sqlDamages := ` SELECT SUM(w.desired_fee) damages FROM waybill w WHERE w.vendor_order_id = ? AND w.status = ? ` + paramDamages := []interface{}{v.VendorOrderID, model.OrderStatusCanceled} + if err := dao.GetRow(dao.GetDB(), damages, sqlDamages, paramDamages); err == nil { + v.LiquidatedDamages = damages.Damages + } orders2 = append(orders2, v) } else { order.SkuInfo += ";" + skuStr @@ -542,6 +551,7 @@ func (c *OrderManager) ExportOrders(ctx *jxcontext.Context, fromDateStr, toDateS "courierMobile", "courierMobile", "desiredFee", + "liquidated_damages", "waybillCreatedAt", "waybillFinishedAt", "status2", diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index ff244ed19..a850c0968 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -210,6 +210,7 @@ func Init() { // (自动发单拣货,设置骑手) ScheduleTimerFuncByInterval(func() { + auto_delivery.Init() // 初始化骑手列表 auto_delivery.AutoSettingFakeDelivery() }, 10*time.Second, 3*time.Minute) diff --git a/business/model/store.go b/business/model/store.go index 2693232e1..ea501f06a 100644 --- a/business/model/store.go +++ b/business/model/store.go @@ -473,55 +473,46 @@ func (*StoreSub) TableUnique() [][]string { type StoreMap struct { ModelIDCULD - StoreID int `orm:"column(store_id)" json:"storeID"` - VendorID int `orm:"column(vendor_id)" json:"vendorID"` - VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空 - - VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"` - Status int `json:"status"` // 取值同Store.Status - IsOnline int `json:"isOnline"` //上下线状态, -1是下线,1是上线 - StoreName string `orm:"size(255)" json:"storeName"` // 平台门店的名字,由平台到京西 - VendorStoreName string `orm:"size(255)" json:"vendorStoreName"` //平台门店名,由京西到平台 - VendorPayPercentage int `json:"vendorPayPercentage"` //平台结算比例 - - PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格 - PricePercentagePack string `orm:"size(32)" json:"pricePercentagePack"` // - FreightDeductionPack string `orm:"size(32)" json:"freightDeductionPack"` // - - AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货 - DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型 - DeliveryFeeDeductionSill int `json:"deliveryFeeDeductionSill"` //在vendorID=14,存储满 x 包邮金额 - DeliveryFeeDeductionFee int `json:"deliveryFeeDeductionFee"` //在vendorID=14,存储打包费 - DeliveryCompetition int8 `orm:"default(1)" json:"deliveryCompetition"` // 是否支持配送竞争 - CreateDeliveryType int `orm:"default(0)" json:"createDeliveryType"` //默认0系统发单,1为门店发单 - IsService int `orm:"default(0)" json:"isService"` // 默认0非服务商,1服务商 - - SyncStatus int8 `orm:"default(2)" json:"syncStatus"` - IsSync int8 `orm:"default(1)" json:"isSync"` // 是否同步 - SyncRule int8 `orm:"default(0)" json:"syncRule"` //目前用于京东商城晚上的同步规则,0表示关闭,1表示小同步,2表示大同步 - FakeOpenStart int16 `orm:"default(0)" json:"fakeOpenStart"` // 假开店开始 - FakeOpenStop int16 `orm:"default(0)" json:"fakeOpenStop"` // 假开店结束 - JdStoreLevel string `orm:"size(32)" json:"jdStoreLevel"` //京东门店等级 - JdsStreetCode int `orm:"default(0)" json:"jdsStreetCode"` //京东商城直辖市街道code - JdsStreetName string `orm:"size(32)" json:"jdsStreetName"` //京东商城直辖市街道 - - IsOrder int `orm:"default(0)" json:"isOrder"` //是否是下预订单门店 - IsSysCat int `orm:"default(0)" json:"isSysCat"` //是否使用京西分类 - IsSupplyGoods int `orm:"default(0)" json:"isSupplyGoods"` // 是否是货源门店 - - YbAppID string `orm:"column(yb_app_id);size(255)" json:"ybAppID"` - YbAppKey string `orm:"size(255)" json:"ybAppKey"` - YbStorePrefix string `orm:"size(255)" json:"ybStorePrefix"` //在vendorID=14,存储抖店门店起送金额 单位分 - - MtwmToken string `orm:"size(512)" json:"mtwmToken"` //美团外卖商超token,有效期30天,每20天刷一次 - MtwmRefreshToken string `orm:"size(255)" json:"mtwmRefreshToken"` //美团外卖商超refreshToken - EbaiSupplierID string `orm:"column(ebai_supplier_id)" json:"ebaiSupplierID"` //饿百供应商ID - - BussinessStatus int `orm:"-" json:"bussinessStatus"` - - VendorAccount string `orm:"size(255)" json:"vendorAccount"` //商户在平台上的账号(授权用 - VendorPasswaord string `orm:"size(255)" json:"vendorPasswaord"` //商户在平台上的密码( aes cbc base64后的 - AuditStatus int `json:"auditStatus"` //审核状态(授权状态 + StoreID int `orm:"column(store_id)" json:"storeID"` + VendorID int `orm:"column(vendor_id)" json:"vendorID"` + VendorOrgCode string `orm:"size(32)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空 + VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"` + Status int `json:"status"` // 取值同Store.Status + IsOnline int `json:"isOnline"` //上下线状态, -1是下线,1是上线 + StoreName string `orm:"size(255)" json:"storeName"` // 平台门店的名字,由平台到京西 + VendorStoreName string `orm:"size(255)" json:"vendorStoreName"` //平台门店名,由京西到平台 + VendorPayPercentage int `json:"vendorPayPercentage"` //平台结算比例 + PricePercentage int16 `orm:"default(100)" json:"pricePercentage"` // todo 厂商价格相对于本地价格的百分比,这个字段的修改会比较特殊,因为可能需要刷新厂商价格 + PricePercentagePack string `orm:"size(32)" json:"pricePercentagePack"` // + FreightDeductionPack string `orm:"size(32)" json:"freightDeductionPack"` // + AutoPickup int8 `orm:"default(1)" json:"autoPickup"` // 是否自动拣货 + DeliveryType int8 `orm:"default(0)" json:"deliveryType"` // 配送类型 + DeliveryFeeDeductionSill int `json:"deliveryFeeDeductionSill"` //在vendorID=14,存储满 x 包邮金额 + DeliveryFeeDeductionFee int `json:"deliveryFeeDeductionFee"` //在vendorID=14,存储打包费 + DeliveryCompetition int8 `orm:"default(1)" json:"deliveryCompetition"` // 是否支持配送竞争 + CreateDeliveryType int `orm:"default(0)" json:"createDeliveryType"` //默认0系统发单,1为门店发单 + IsService int `orm:"default(0)" json:"isService"` // 默认0非服务商,1服务商 + SyncStatus int8 `orm:"default(2)" json:"syncStatus"` + IsSync int8 `orm:"default(1)" json:"isSync"` // 是否同步 + SyncRule int8 `orm:"default(0)" json:"syncRule"` //目前用于京东商城晚上的同步规则,0表示关闭,1表示小同步,2表示大同步 + FakeOpenStart int16 `orm:"default(0)" json:"fakeOpenStart"` // 假开店开始 + FakeOpenStop int16 `orm:"default(0)" json:"fakeOpenStop"` // 假开店结束 + JdStoreLevel string `orm:"size(32)" json:"jdStoreLevel"` //京东门店等级 + JdsStreetCode int `orm:"default(0)" json:"jdsStreetCode"` //京东商城直辖市街道code + JdsStreetName string `orm:"size(32)" json:"jdsStreetName"` //京东商城直辖市街道 + IsOrder int `orm:"default(0)" json:"isOrder"` //是否是下预订单门店 + IsSysCat int `orm:"default(0)" json:"isSysCat"` //是否使用京西分类 + IsSupplyGoods int `orm:"default(0)" json:"isSupplyGoods"` // 是否是货源门店 + YbAppID string `orm:"column(yb_app_id);size(255)" json:"ybAppID"` + YbAppKey string `orm:"size(255)" json:"ybAppKey"` + YbStorePrefix string `orm:"size(255)" json:"ybStorePrefix"` //在vendorID=14,存储抖店门店起送金额 单位分 + MtwmToken string `orm:"size(512)" json:"mtwmToken"` //美团外卖商超token,有效期30天,每20天刷一次 + MtwmRefreshToken string `orm:"size(255)" json:"mtwmRefreshToken"` //美团外卖商超refreshToken + EbaiSupplierID string `orm:"column(ebai_supplier_id)" json:"ebaiSupplierID"` //饿百供应商ID + BussinessStatus int `orm:"-" json:"bussinessStatus"` + VendorAccount string `orm:"size(255)" json:"vendorAccount"` //商户在平台上的账号(授权用 + VendorPasswaord string `orm:"size(255)" json:"vendorPasswaord"` //商户在平台上的密码( aes cbc base64后的 + AuditStatus int `json:"auditStatus"` //审核状态(授权状态 } func (*StoreMap) TableUnique() [][]string { diff --git a/main.go b/main.go index 30f9eaeef..8bbdc397b 100644 --- a/main.go +++ b/main.go @@ -11,8 +11,6 @@ import ( "git.rosy.net.cn/jx-callback/business/partner/purchase/im" "git.rosy.net.cn/jx-callback/business/enterprise" - "git.rosy.net.cn/jx-callback/business/jxcallback/auto_delivery" - "git.rosy.net.cn/jx-callback/business/partner/purchase/jdshop" "git.rosy.net.cn/jx-callback/business/partner/purchase/yb" @@ -93,8 +91,7 @@ func Init() { jdshop.CurPurchaseHandler.StartRefreshComment() } misc.Init() - enterprise.Init() // 初始化enterprise key - auto_delivery.Init() // 初始化骑手列表 + enterprise.Init() // 初始化enterprise key im.Init() //初始化ws连接