添加运单,号,添加下单价格校验

This commit is contained in:
邹宗楠
2022-04-06 16:35:56 +08:00
parent 204b3bf215
commit 2c366de072
4 changed files with 27 additions and 23 deletions

View File

@@ -5,8 +5,6 @@ import (
"math"
"time"
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model/dao"
@@ -140,7 +138,7 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex
deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID)
// 运费相等为0或支出大于收入不做
isEqual, isZero, _ := partner.CurStoreAcctManager.CheckStoreAcctExpendExist(order.VendorOrderID)
// 收最贵的一个订单配送费
// 收最贵的一个订单配送费(配送费发送变化,收取最贵的价格)
if !isZero && !isEqual {
var newPrice int64
if len(courierVendorIDs) == 1 {
@@ -249,7 +247,16 @@ func (s *DefScheduler) CheckStoreBalance(ctx *jxcontext.Context, order *model.Go
//京西后台则是点一下发3个len courierVendorIDs 是0
//如果是小程序上点哪个扣哪个平台的钱
//如果是后台,则选最高的那个扣
storeAcct, err := cms.GetStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order)) // 0.0
//storeAcct, err := cms.GetStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order)) // 0.0
// 如果门店没钱,查看品牌查询门店品牌id
storeList, err := dao.GetStoreList(dao.GetDB(), []int{order.JxStoreID}, 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("获取账户余额失败!")
@@ -280,24 +287,21 @@ func (s *DefScheduler) CheckStoreBalance(ctx *jxcontext.Context, order *model.Go
}
_, lastFee, _ := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID)
if int(newPrice) > lastFee {
if storeAcct.AccountBalance < int(newPrice)-lastFee {
if result < int(newPrice)-lastFee {
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(newPrice-int64(lastFee)))
}
}
} else {
if storeAcct.AccountBalance < partner.MinCreateWaybillBalance {
//// 如果门店没钱,查看品牌
//if storeAcct.AccountBalance == 0 {
// // 查询门店品牌id
// dao.GetStoreList(dao.GetDB(), []int{order.JxStoreID}, nil, nil, nil, nil, "")
// dao.GetBrandBalance(dao.GetDB(),brandId)
//}
//if storeAcct.AccountBalance < partner.MinCreateWaybillBalance {
if result < partner.MinCreateWaybillBalance { // 门店品牌账户余额
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(partner.MinCreateWaybillBalance))
}
//}
if len(courierVendorIDs) == 1 {
courierVendorID := courierVendorIDs[0]
if _, ok := deliveryFeeMap[courierVendorID]; ok {
if deliveryFeeMap[courierVendorID].DeliveryFee > int64(storeAcct.AccountBalance) {
//if deliveryFeeMap[courierVendorID].DeliveryFee > int64(storeAcct.AccountBalance) {
if deliveryFeeMap[courierVendorID].DeliveryFee > int64(result) {
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(deliveryFeeMap[courierVendorID].DeliveryFee))
}
}
@@ -308,7 +312,7 @@ func (s *DefScheduler) CheckStoreBalance(ctx *jxcontext.Context, order *model.Go
v.DeliveryFee = maxFee
}
}
if maxFee > int64(storeAcct.AccountBalance) {
if maxFee > int64(result) {
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(maxFee))
}
}

View File

@@ -162,7 +162,9 @@ func (s *StoreAcctManager) CheckStoreAcctExpendExist(vendorOrderID string) (isEq
db = dao.GetDB()
)
globals.SugarLogger.Debugf("CheckStoreAcctExpendExist orderID:[%v]", vendorOrderID)
// 发单扣除的临时运费
expends, err = dao.GetStoreAcctExpendTotal(db, 0, []int{partner.StoreAcctTypeExpendCreateWaybillEx, 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 {

View File

@@ -77,7 +77,6 @@ func (c *DeliveryHandler) CancelWaybill(bill *model.Waybill, cancelReasonID int,
bill.Status = model.WaybillStatusCanceled
bill.Remark = cancelReason
partner.CurOrderManager.OnWaybillStatusChanged(bill)
fmt.Println("fn cancle order ============", err)
return err
}
@@ -139,8 +138,9 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee
parameter.OrderSource = "109"
}
// 创建蜂鸟订单
if err = api.FnAPI.CreateOrder(parameter); err != nil {
// 创建蜂鸟订单,运单id
fnOrderId, err := api.FnAPI.CreateOrder(parameter)
if err != nil {
globals.SugarLogger.Debugf("CreateWaybill failed, orderID:%s, billParams:%v, error:%v", order.VendorOrderID, parameter, err)
return nil, err
}
@@ -149,8 +149,8 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee
bill = &model.Waybill{
VendorOrderID: order.VendorOrderID,
OrderVendorID: order.VendorID,
VendorWaybillID: "",
VendorWaybillID2: "",
VendorWaybillID: fnOrderId,
VendorWaybillID2: order.VendorOrderID,
WaybillVendorID: model.VendorIDFengNiao,
DesiredFee: GetDesiredFee(order.VendorOrderID),
}
@@ -223,10 +223,7 @@ func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify) (resp *fnpsapi.CallbackRespon
return fnpsapi.Err2CallbackResponse(err, "")
}
switch orderStatus {
case fnpsapi.OrderStatusAcceptCreate: // 0 创建订单
order.DesiredFee = GetDesiredFee(order.VendorOrderID)
order.Status = model.WaybillStatusNew //5 带调度
case fnpsapi.OrderStatusAccept: // 1 新运单
case fnpsapi.OrderStatusAcceptCreate, fnpsapi.OrderStatusAccept: // 0 创建订单
order.DesiredFee = GetDesiredFee(order.VendorOrderID)
order.Status = model.WaybillStatusNew //5 带调度
case fnpsapi.OrderStatusAssigned: //20分配骑手

View File

@@ -34,3 +34,4 @@ func TestCancelWaybill(t *testing.T) {
t.Fatal(err.Error())
}
}