aa
This commit is contained in:
@@ -338,7 +338,7 @@ func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order
|
||||
} else {
|
||||
//加小费成功扣钱
|
||||
if order.CreateDeliveryType == model.YES {
|
||||
if err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(tipFee), partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID); err == nil {
|
||||
if err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), 100, partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID); err == nil {
|
||||
flag = true
|
||||
}
|
||||
}
|
||||
@@ -374,7 +374,7 @@ func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order
|
||||
if !flag {
|
||||
//加小费成功扣钱
|
||||
if order.CreateDeliveryType == model.YES {
|
||||
partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(tipFee), partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID)
|
||||
partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), 100, partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,33 +134,44 @@ func (s *DefScheduler) CreateWaybillOnProviders4SavedOrder(ctx *jxcontext.Contex
|
||||
}
|
||||
//门店发单开始扣钱
|
||||
if order.CreateDeliveryType == model.YES {
|
||||
//暂时这么认为,len courierVendorIDs 为1表示是老板或者运营从小程序上点的立即发单,因为小程序上是点哪个发哪个
|
||||
//京西后台则是点一下发3个,len courierVendorIDs 是0
|
||||
//如果是小程序上点哪个扣哪个平台的钱
|
||||
//如果是后台,则选最高的那个扣
|
||||
// var deliveryDee int64
|
||||
// deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID)
|
||||
// if len(courierVendorIDs) == 1 {
|
||||
// courierVendorID := courierVendorIDs[0]
|
||||
// if _, ok := deliveryFeeMap[courierVendorID]; ok {
|
||||
// deliveryDee = deliveryFeeMap[courierVendorID].DeliveryFee
|
||||
// }
|
||||
// } else if len(courierVendorIDs) == 0 {
|
||||
// var maxFee int64
|
||||
// for _, v := range deliveryFeeMap {
|
||||
// if v.DeliveryFee > maxFee {
|
||||
// v.DeliveryFee = maxFee
|
||||
// }
|
||||
// }
|
||||
// deliveryDee = maxFee
|
||||
// }
|
||||
// handler := partner.CurStoreAcctManager
|
||||
//此订单没有因为发运单而扣除过门店账户
|
||||
// if isExist, err := handler.CheckStoreAcctExpendExist(order.VendorOrderID); err == nil && !isExist {
|
||||
// err = handler.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(deliveryDee), partner.StoreAcctTypeExpendCreateWaybillEx, order.VendorOrderID)
|
||||
// } else if isExist {
|
||||
// globals.SugarLogger.Debugf("CreateWaybillOnProviders4SavedOrder orderID:%s userName:%s ,storeAcctExpend isExist", order.VendorOrderID, ctx.GetUserName())
|
||||
// }
|
||||
deliveryFeeMap, _ := s.QueryOrderWaybillFeeInfoEx(ctx, order.VendorOrderID, order.VendorID)
|
||||
isEqual, isZero, _ := partner.CurStoreAcctManager.CheckStoreAcctExpendExist(order.VendorOrderID)
|
||||
if !isZero && !isEqual {
|
||||
var newPrice int64
|
||||
if len(courierVendorIDs) == 1 {
|
||||
courierVendorID := courierVendorIDs[0]
|
||||
if _, ok := deliveryFeeMap[courierVendorID]; ok {
|
||||
newPrice = deliveryFeeMap[courierVendorID].DeliveryFee
|
||||
}
|
||||
} else if len(courierVendorIDs) == 0 {
|
||||
var maxFee int64
|
||||
for _, v := range deliveryFeeMap {
|
||||
if v.DeliveryFee > maxFee {
|
||||
v.DeliveryFee = maxFee
|
||||
}
|
||||
}
|
||||
newPrice = maxFee
|
||||
}
|
||||
lastFee, _ := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID)
|
||||
if int(newPrice) > lastFee {
|
||||
partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(newPrice)-lastFee, partner.StoreAcctTypeExpendCreateWaybillEx, order.VendorOrderID)
|
||||
}
|
||||
} else {
|
||||
if len(courierVendorIDs) == 1 {
|
||||
courierVendorID := courierVendorIDs[0]
|
||||
if _, ok := deliveryFeeMap[courierVendorID]; ok {
|
||||
partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(deliveryFeeMap[courierVendorID].DeliveryFee), partner.StoreAcctTypeExpendCreateWaybillEx, order.VendorOrderID)
|
||||
}
|
||||
} else if len(courierVendorIDs) == 0 {
|
||||
var maxFee int64
|
||||
for _, v := range deliveryFeeMap {
|
||||
if v.DeliveryFee > maxFee {
|
||||
v.DeliveryFee = maxFee
|
||||
}
|
||||
}
|
||||
partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(maxFee), partner.StoreAcctTypeExpendCreateWaybillEx, order.VendorOrderID)
|
||||
}
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debugf("CreateWaybillOnProviders4SavedOrder orderID:%s userName:%s successfully", order.VendorOrderID, ctx.GetUserName())
|
||||
return bills, err
|
||||
@@ -253,7 +264,12 @@ func (s *DefScheduler) CheckStoreBalance(ctx *jxcontext.Context, order *model.Go
|
||||
}
|
||||
newPrice = maxFee
|
||||
}
|
||||
fmt.Println(newPrice)
|
||||
lastFee, _ := partner.CurStoreAcctManager.GetStoreAcctExpendLastCreateWayBillFee(order.VendorOrderID)
|
||||
if int(newPrice) > lastFee {
|
||||
if storeAcct.AccountBalance < int(newPrice)-lastFee {
|
||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(newPrice-int64(lastFee)))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if storeAcct.AccountBalance < partner.MinCreateWaybillBalance {
|
||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额小于[%v]元,不能发配送!", jxutils.IntPrice2Standard(partner.MinCreateWaybillBalance))
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type StoreAcctManager struct {
|
||||
DB *dao.DaoDB
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -17,14 +18,17 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
FixedStoreAcctManager = &StoreAcctManager{}
|
||||
FixedStoreAcctManager = &StoreAcctManager{
|
||||
DB: dao.GetDB(),
|
||||
}
|
||||
partner.InitStoreAcctManager(FixedStoreAcctManager)
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, db *dao.DaoDB, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||
func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||
var (
|
||||
userID, userName string
|
||||
goodsVendorOrderID string
|
||||
db = s.DB
|
||||
)
|
||||
if ctx != nil {
|
||||
userID = ctx.GetUserID()
|
||||
@@ -53,9 +57,10 @@ func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, db *dao
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) InsertStoreAcctExpend(ctx *jxcontext.Context, db *dao.DaoDB, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||
func (s *StoreAcctManager) InsertStoreAcctExpend(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||
var (
|
||||
userID, userName string
|
||||
db = s.DB
|
||||
)
|
||||
if ctx != nil {
|
||||
userID = ctx.GetUserID()
|
||||
@@ -84,7 +89,7 @@ func (s *StoreAcctManager) InsertStoreAcctExpend(ctx *jxcontext.Context, db *dao
|
||||
|
||||
func (s *StoreAcctManager) UpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price int, isIncome bool) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
db = s.DB
|
||||
)
|
||||
globals.SugarLogger.Debugf("UpdateStoreAcctBalance storeID: [%v] , price :[%v] ,", storeID, price)
|
||||
if ctx == nil {
|
||||
@@ -127,11 +132,8 @@ func (s *StoreAcctManager) UpdateStoreAcctBalance(ctx *jxcontext.Context, storeI
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
utils.CallFuncAsync(func() {
|
||||
if err = s.InsertStoreAcctExpend(ctx, db, storeID, price, acctType, vendorOrderID); err == nil {
|
||||
if err = s.InsertStoreAcctExpend(ctx, storeID, price, acctType, vendorOrderID); err == nil {
|
||||
s.UpdateStoreAcctBalance(ctx, storeID, price, false)
|
||||
}
|
||||
})
|
||||
@@ -139,11 +141,8 @@ func (s *StoreAcctManager) InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *j
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
utils.CallFuncAsync(func() {
|
||||
if err = s.InsertStoreAcctIncome(ctx, db, storeID, price, acctType, vendorOrderID); err == nil {
|
||||
if err = s.InsertStoreAcctIncome(ctx, storeID, price, acctType, vendorOrderID); err == nil {
|
||||
s.UpdateStoreAcctBalance(ctx, storeID, price, true)
|
||||
}
|
||||
})
|
||||
@@ -152,12 +151,11 @@ func (s *StoreAcctManager) InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *j
|
||||
|
||||
func (s *StoreAcctManager) CheckStoreAcctExpendExist(vendorOrderID string) (isEqual, isZero bool, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
expends, incomes int
|
||||
)
|
||||
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)
|
||||
expends, err = dao.GetStoreAcctExpendTotal(s.DB, 0, []int{partner.StoreAcctTypeExpendCreateWaybillEx, partner.StoreAcctTypeRealFeeExpend}, vendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue)
|
||||
incomes, err = dao.GetStoreAcctIncomeTotal(s.DB, 0, []int{partner.StoreAcctTypeRealFeeIncome, partner.StoreAcctTypeIncomeCancelTemp, partner.StoreAcctTypeIncomeCancelReal}, vendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue)
|
||||
if expends != incomes {
|
||||
if expends > incomes {
|
||||
return false, false, err
|
||||
@@ -173,3 +171,7 @@ func (s *StoreAcctManager) CheckStoreAcctExpendExist(vendorOrderID string) (isEq
|
||||
}
|
||||
return false, false, err
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) GetStoreAcctExpendLastCreateWayBillFee(vendorOrderID string) (lastFee int, err error) {
|
||||
return dao.GetStoreAcctExpendLastCreateWayBillFee(s.DB, vendorOrderID)
|
||||
}
|
||||
|
||||
@@ -1169,5 +1169,12 @@ func GetStoreAcctExpendLastCreateWayBillFee(db *DaoDB, vendorOrderID string) (la
|
||||
LIMIT 1
|
||||
`
|
||||
err = GetRow(db, &expend, sql, sqlParams)
|
||||
return expend.ExpendPrice, err
|
||||
lastFee = expend.ExpendPrice
|
||||
if expend.ExpID != 0 {
|
||||
lastFee += expend.MulitExpendPrice
|
||||
}
|
||||
if expend.IncID != 0 {
|
||||
lastFee -= expend.MulitIncomePrice
|
||||
}
|
||||
return lastFee, err
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package partner
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -13,7 +12,7 @@ const (
|
||||
StoreAcctTypeIncomeCancelReal = 19 //运单取消,回退的真实运费
|
||||
|
||||
//账户支出类型
|
||||
StoreAcctTypeExpendCreateWaybillEx = 20 //手动发单扣除的临时运费
|
||||
StoreAcctTypeExpendCreateWaybillEx = 20 //发单扣除的临时运费
|
||||
StoreAcctTypeExpendCreateWaybillTip = 21 //手动加小费扣除
|
||||
StoreAcctTypeRealFeeExpend = 25 //真实运费 > 临时运费, 真实运费的值 - 临时运费的值
|
||||
)
|
||||
@@ -32,12 +31,13 @@ func InitStoreAcctManager(curStoreManager IStoreAcctManager) {
|
||||
|
||||
type IStoreAcctManager interface {
|
||||
//增加一条收入流水
|
||||
InsertStoreAcctIncome(ctx *jxcontext.Context, db *dao.DaoDB, storeID, price, acctType int, vendorOrderID string) (err error)
|
||||
InsertStoreAcctIncome(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error)
|
||||
//增加一条支出流水
|
||||
InsertStoreAcctExpend(ctx *jxcontext.Context, db *dao.DaoDB, storeID, price, acctType int, vendorOrderID string) (err error)
|
||||
InsertStoreAcctExpend(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error)
|
||||
//更新门店账户
|
||||
UpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price int, isIncome bool) (err error)
|
||||
InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error)
|
||||
InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error)
|
||||
CheckStoreAcctExpendExist(vendorOrderID string) (isEqual, isZero bool, err error)
|
||||
GetStoreAcctExpendLastCreateWayBillFee(vendorOrderID string) (lastFee int, err error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user