添加运单,号,添加下单价格校验
This commit is contained in:
@@ -5,8 +5,6 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"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)
|
deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID)
|
||||||
// 运费相等为0或支出大于收入不做,
|
// 运费相等为0或支出大于收入不做,
|
||||||
isEqual, isZero, _ := partner.CurStoreAcctManager.CheckStoreAcctExpendExist(order.VendorOrderID)
|
isEqual, isZero, _ := partner.CurStoreAcctManager.CheckStoreAcctExpendExist(order.VendorOrderID)
|
||||||
// 收最贵的一个订单配送费
|
// 收最贵的一个订单配送费(配送费发送变化,收取最贵的价格)
|
||||||
if !isZero && !isEqual {
|
if !isZero && !isEqual {
|
||||||
var newPrice int64
|
var newPrice int64
|
||||||
if len(courierVendorIDs) == 1 {
|
if len(courierVendorIDs) == 1 {
|
||||||
@@ -249,7 +247,16 @@ func (s *DefScheduler) CheckStoreBalance(ctx *jxcontext.Context, order *model.Go
|
|||||||
//京西后台则是点一下发3个,len courierVendorIDs 是0
|
//京西后台则是点一下发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)
|
deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errCode, fmt.Errorf("获取账户余额失败!")
|
return errCode, fmt.Errorf("获取账户余额失败!")
|
||||||
@@ -280,24 +287,21 @@ func (s *DefScheduler) CheckStoreBalance(ctx *jxcontext.Context, order *model.Go
|
|||||||
}
|
}
|
||||||
_, lastFee, _ := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID)
|
_, lastFee, _ := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID)
|
||||||
if int(newPrice) > lastFee {
|
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)))
|
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(newPrice-int64(lastFee)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if storeAcct.AccountBalance < partner.MinCreateWaybillBalance {
|
//if storeAcct.AccountBalance < partner.MinCreateWaybillBalance {
|
||||||
//// 如果门店没钱,查看品牌
|
if result < partner.MinCreateWaybillBalance { // 门店品牌账户余额
|
||||||
//if storeAcct.AccountBalance == 0 {
|
|
||||||
// // 查询门店品牌id
|
|
||||||
// dao.GetStoreList(dao.GetDB(), []int{order.JxStoreID}, nil, nil, nil, nil, "")
|
|
||||||
// dao.GetBrandBalance(dao.GetDB(),brandId)
|
|
||||||
//}
|
|
||||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(partner.MinCreateWaybillBalance))
|
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(partner.MinCreateWaybillBalance))
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
if len(courierVendorIDs) == 1 {
|
if len(courierVendorIDs) == 1 {
|
||||||
courierVendorID := courierVendorIDs[0]
|
courierVendorID := courierVendorIDs[0]
|
||||||
if _, ok := deliveryFeeMap[courierVendorID]; ok {
|
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))
|
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
|
v.DeliveryFee = maxFee
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if maxFee > int64(storeAcct.AccountBalance) {
|
if maxFee > int64(result) {
|
||||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(maxFee))
|
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(maxFee))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,9 @@ func (s *StoreAcctManager) CheckStoreAcctExpendExist(vendorOrderID string) (isEq
|
|||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
)
|
)
|
||||||
globals.SugarLogger.Debugf("CheckStoreAcctExpendExist orderID:[%v]", vendorOrderID)
|
globals.SugarLogger.Debugf("CheckStoreAcctExpendExist orderID:[%v]", vendorOrderID)
|
||||||
|
// 发单扣除的临时运费
|
||||||
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.StoreAcctTypeRealFeeExpend}, vendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue)
|
||||||
|
// 真实运费 < 临时运费, 临时运费-真实运费的值
|
||||||
incomes, err = dao.GetStoreAcctIncomeTotal(db, 0, []int{partner.StoreAcctTypeRealFeeIncome, partner.StoreAcctTypeIncomeCancelTemp, partner.StoreAcctTypeIncomeCancelReal}, 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 {
|
||||||
if expends > incomes {
|
if expends > incomes {
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ func (c *DeliveryHandler) CancelWaybill(bill *model.Waybill, cancelReasonID int,
|
|||||||
bill.Status = model.WaybillStatusCanceled
|
bill.Status = model.WaybillStatusCanceled
|
||||||
bill.Remark = cancelReason
|
bill.Remark = cancelReason
|
||||||
partner.CurOrderManager.OnWaybillStatusChanged(bill)
|
partner.CurOrderManager.OnWaybillStatusChanged(bill)
|
||||||
fmt.Println("fn cancle order ============", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,8 +138,9 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee
|
|||||||
parameter.OrderSource = "109"
|
parameter.OrderSource = "109"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建蜂鸟订单
|
// 创建蜂鸟订单,运单id
|
||||||
if err = api.FnAPI.CreateOrder(parameter); err != nil {
|
fnOrderId, err := api.FnAPI.CreateOrder(parameter)
|
||||||
|
if err != nil {
|
||||||
globals.SugarLogger.Debugf("CreateWaybill failed, orderID:%s, billParams:%v, error:%v", order.VendorOrderID, parameter, err)
|
globals.SugarLogger.Debugf("CreateWaybill failed, orderID:%s, billParams:%v, error:%v", order.VendorOrderID, parameter, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -149,8 +149,8 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee
|
|||||||
bill = &model.Waybill{
|
bill = &model.Waybill{
|
||||||
VendorOrderID: order.VendorOrderID,
|
VendorOrderID: order.VendorOrderID,
|
||||||
OrderVendorID: order.VendorID,
|
OrderVendorID: order.VendorID,
|
||||||
VendorWaybillID: "",
|
VendorWaybillID: fnOrderId,
|
||||||
VendorWaybillID2: "",
|
VendorWaybillID2: order.VendorOrderID,
|
||||||
WaybillVendorID: model.VendorIDFengNiao,
|
WaybillVendorID: model.VendorIDFengNiao,
|
||||||
DesiredFee: GetDesiredFee(order.VendorOrderID),
|
DesiredFee: GetDesiredFee(order.VendorOrderID),
|
||||||
}
|
}
|
||||||
@@ -223,10 +223,7 @@ func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify) (resp *fnpsapi.CallbackRespon
|
|||||||
return fnpsapi.Err2CallbackResponse(err, "")
|
return fnpsapi.Err2CallbackResponse(err, "")
|
||||||
}
|
}
|
||||||
switch orderStatus {
|
switch orderStatus {
|
||||||
case fnpsapi.OrderStatusAcceptCreate: // 0 创建订单
|
case fnpsapi.OrderStatusAcceptCreate, fnpsapi.OrderStatusAccept: // 0 创建订单
|
||||||
order.DesiredFee = GetDesiredFee(order.VendorOrderID)
|
|
||||||
order.Status = model.WaybillStatusNew //5 带调度
|
|
||||||
case fnpsapi.OrderStatusAccept: // 1 新运单
|
|
||||||
order.DesiredFee = GetDesiredFee(order.VendorOrderID)
|
order.DesiredFee = GetDesiredFee(order.VendorOrderID)
|
||||||
order.Status = model.WaybillStatusNew //5 带调度
|
order.Status = model.WaybillStatusNew //5 带调度
|
||||||
case fnpsapi.OrderStatusAssigned: //20分配骑手
|
case fnpsapi.OrderStatusAssigned: //20分配骑手
|
||||||
|
|||||||
@@ -34,3 +34,4 @@ func TestCancelWaybill(t *testing.T) {
|
|||||||
t.Fatal(err.Error())
|
t.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user