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 *