修改门店发单和品牌发单是扣费问题

This commit is contained in:
邹宗楠
2023-05-11 10:58:50 +08:00
parent 85b2870a5e
commit 476f8c0943
26 changed files with 417 additions and 273 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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, "")
}
}
}

View File

@@ -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)
}
}
}

View File

@@ -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
}

View File

@@ -21,6 +21,7 @@ const (
const (
JXC4B_RAND_JXGY = 1 // 京西菜市和果园品牌id
JXC4B_SHOP = 7 // 京西超市
JXC4B_ZHIGONG = 8 // 京西直供
)
var (

View File

@@ -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()

View File

@@ -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 {

View File

@@ -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:

View File

@@ -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
}

View File

@@ -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 = ?"

View File

@@ -20,6 +20,9 @@ const (
ErrCodeAccountBalanceNotEnough = "-201" //余额不足
ErrCodeNotAuthBindWeixin = "-202" //没有绑定微信认证方式
ErrCodeOnePayTipFeeMore = "10001" // 单次支付金额太多
ErrCodeIsPaySure = "10000" // 是否确认支付
)
var (

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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, "")

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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

View File

@@ -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
})
}

View File

@@ -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
// 如下都是用于检测存活的空接口