aa
This commit is contained in:
@@ -289,12 +289,27 @@ func (c *BaseScheduler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID st
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *BaseScheduler) SetOrderWaybillTip(ctx *jxcontext.Context, vendorOrderID string, vendorID int, tipFee int64) (err error) {
|
||||
order, err2 := partner.CurOrderManager.LoadOrder(vendorOrderID, vendorID)
|
||||
if err = err2; err == nil {
|
||||
err = c.SetOrderWaybillTipByOrder(ctx, order, tipFee)
|
||||
func (c *BaseScheduler) SetOrderWaybillTip(ctx *jxcontext.Context, vendorOrderID string, vendorID int, tipFee int64) (errCode string, err error) {
|
||||
if order, err := partner.CurOrderManager.LoadOrder(vendorOrderID, vendorID); err == nil {
|
||||
if errCode, err = c.CheckStoreBalanceWithTip(ctx, order, tipFee); err == nil {
|
||||
c.SetOrderWaybillTipByOrder(ctx, order, tipFee)
|
||||
}
|
||||
}
|
||||
return err
|
||||
return errCode, err
|
||||
}
|
||||
|
||||
func (c *BaseScheduler) CheckStoreBalanceWithTip(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee int64) (errCode string, err error) {
|
||||
if order.CreateDeliveryType == model.YES {
|
||||
//加小费只判断余额
|
||||
storeAcct, err := cms.GetStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order))
|
||||
if err != nil {
|
||||
return errCode, fmt.Errorf("获取账户余额失败!")
|
||||
}
|
||||
if tipFee > int64(storeAcct.AccountBalance) {
|
||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额不足,不能加小费!")
|
||||
}
|
||||
}
|
||||
return errCode, err
|
||||
}
|
||||
|
||||
func isWaybillCanAddTip(waybill *model.Waybill) (isCan bool) {
|
||||
@@ -310,19 +325,26 @@ func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order
|
||||
if order.WaybillTipMoney >= tipFee {
|
||||
return fmt.Errorf("当前小费已经是%s元,想要设置%s元", jxutils.IntPrice2StandardString(order.WaybillTipMoney), jxutils.IntPrice2StandardString(tipFee))
|
||||
}
|
||||
|
||||
db := dao.GetDB()
|
||||
storeDetail, err2 := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, "")
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
flag := false
|
||||
// 如果平台支持设置配送小费,必须要成功设置
|
||||
if handler := partner.GetWaybillTipUpdater(order.VendorID); handler != nil {
|
||||
if err = handler.UpdateWaybillTip(ctx, order.VendorOrgCode, order.VendorStoreID, order.VendorOrderID, "", "", utils.Int2Str(storeDetail.CityCode), tipFee); err != nil {
|
||||
return err
|
||||
} else {
|
||||
//加小费成功扣钱
|
||||
if order.CreateDeliveryType == model.YES {
|
||||
if err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(tipFee), partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID); err == nil {
|
||||
flag = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} //有可能进else,没加得起平台小费,就要到下面扣账户
|
||||
|
||||
order.WaybillTipMoney = tipFee
|
||||
partner.CurOrderManager.UpdateOrderFields(order, []string{"WaybillTipMoney"})
|
||||
|
||||
@@ -347,6 +369,15 @@ func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order
|
||||
}, waybills2)
|
||||
tasksch.HandleTask(task, nil, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
if err == nil {
|
||||
//加起了至少只扣一次钱
|
||||
if !flag {
|
||||
//加小费成功扣钱
|
||||
if order.CreateDeliveryType == model.YES {
|
||||
partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(tipFee), partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
type StoreAcctManager struct {
|
||||
@@ -22,11 +23,13 @@ func init() {
|
||||
|
||||
func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, db *dao.DaoDB, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||
var (
|
||||
userID, userName string
|
||||
userID, userName string
|
||||
goodsVendorOrderID string
|
||||
)
|
||||
if ctx != nil {
|
||||
userID = ctx.GetUserID()
|
||||
userName = ctx.GetUserName()
|
||||
goodsVendorOrderID = vendorOrderID
|
||||
} else {
|
||||
storeOrder := &model.StoreAcctOrder{
|
||||
VendorOrderID: vendorOrderID,
|
||||
@@ -34,16 +37,19 @@ func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, db *dao
|
||||
if err = dao.GetEntity(db, storeOrder, "VendorOrderID"); err == nil && storeOrder.ID != 0 {
|
||||
userID = storeOrder.UserID
|
||||
userName = storeOrder.LastOperator
|
||||
goodsVendorOrderID = storeOrder.GoodsVendorOrderID
|
||||
}
|
||||
}
|
||||
storeAcctIncome := &model.StoreAcctIncome{
|
||||
StoreID: storeID,
|
||||
IncomePrice: price,
|
||||
Type: acctType,
|
||||
UserID: userID,
|
||||
StoreID: storeID,
|
||||
IncomePrice: price,
|
||||
Type: acctType,
|
||||
UserID: userID,
|
||||
VendorOrderID: goodsVendorOrderID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(storeAcctIncome, userName)
|
||||
err = dao.CreateEntity(db, storeAcctIncome)
|
||||
globals.SugarLogger.Debugf("InsertStoreAcctIncome orderID: [%v] , price :[%v] , type :[%v]", vendorOrderID, price, acctType)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -72,6 +78,7 @@ func (s *StoreAcctManager) InsertStoreAcctExpend(ctx *jxcontext.Context, db *dao
|
||||
}
|
||||
dao.WrapAddIDCULEntity(storeAcctExpend, userName)
|
||||
err = dao.CreateEntity(db, storeAcctExpend)
|
||||
globals.SugarLogger.Debugf("InsertStoreAcctExpend orderID: [%v] , price :[%v] , type :[%v]", vendorOrderID, price, acctType)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -79,17 +86,13 @@ func (s *StoreAcctManager) UpdateStoreAcctBalance(ctx *jxcontext.Context, storeI
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
globals.SugarLogger.Debugf("UpdateStoreAcctBalance storeID: [%v] , price :[%v] ,", storeID, price)
|
||||
if ctx == nil {
|
||||
ctx = jxcontext.AdminCtx
|
||||
}
|
||||
storeAcct := &model.StoreAcct{
|
||||
StoreID: storeID,
|
||||
}
|
||||
if isIncome {
|
||||
storeAcct.AccountBalance += price
|
||||
} else {
|
||||
storeAcct.AccountBalance -= price
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
@@ -107,10 +110,17 @@ func (s *StoreAcctManager) UpdateStoreAcctBalance(ctx *jxcontext.Context, storeI
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("UpdateStoreAcctBalance1 storeID: [%v] , balance :[%v] ,", storeID, storeAcct.AccountBalance)
|
||||
if isIncome {
|
||||
storeAcct.AccountBalance += price
|
||||
} else {
|
||||
storeAcct.AccountBalance -= price
|
||||
}
|
||||
if _, err = dao.UpdateEntity(db, storeAcct, "AccountBalance"); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
globals.SugarLogger.Debugf("UpdateStoreAcctBalance2 storeID: [%v] , balance :[%v] ,", storeID, storeAcct.AccountBalance)
|
||||
}
|
||||
dao.Commit(db)
|
||||
return err
|
||||
|
||||
@@ -1124,3 +1124,34 @@ func GetStoreAcctExpendTotal(db *DaoDB, storeID, expendType int, fromTime, toTim
|
||||
err = GetRow(db, &expend, sql, sqlParams)
|
||||
return expend.ExpendPrice, err
|
||||
}
|
||||
|
||||
func GetStoreAcctExpendMore(db *DaoDB, storeID, expendType int, vendorOrderID string, fromTime, toTime time.Time) (storeAcctExpends []*model.StoreAcctExpend, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM store_acct_expend
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if storeID != 0 {
|
||||
sql += " AND store_id = ?"
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
}
|
||||
if expendType != 0 {
|
||||
sql += " AND type = ?"
|
||||
sqlParams = append(sqlParams, expendType)
|
||||
}
|
||||
if vendorOrderID != "" {
|
||||
sql += " AND vendor_order_id = ?"
|
||||
sqlParams = append(sqlParams, vendorOrderID)
|
||||
}
|
||||
if utils.IsTimeZero(fromTime) {
|
||||
sql += " AND created_at >= ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if utils.IsTimeZero(toTime) {
|
||||
sql += " AND created_at <= ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
err = GetRows(db, &storeAcctExpends, sql, sqlParams)
|
||||
return storeAcctExpends, err
|
||||
}
|
||||
|
||||
@@ -490,14 +490,15 @@ func (v *StoreCoupons) TableIndex() [][]string {
|
||||
type StoreAcctOrder struct {
|
||||
ModelIDCUL
|
||||
|
||||
VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid
|
||||
ActualPayPrice int `json:"actualPayPrice"` // 单位为分 顾客实际支付
|
||||
UserID string `orm:"column(user_id);size(48);index" json:"userID"`
|
||||
OrderType int `json:"orderType"`
|
||||
Status int `json:"status"` // 参见OrderStatus*相关的常量定义 // 重复新订单消息数,这个一般不是由于消息重发造成的(消息重发由OrderStatus过滤),一般是业务逻辑造成的
|
||||
OrderFinishedAt time.Time `orm:"type(datetime)" json:"orderFinishedAt"`
|
||||
VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid
|
||||
ActualPayPrice int `json:"actualPayPrice"` // 单位为分 顾客实际支付
|
||||
UserID string `orm:"column(user_id);size(48);index" json:"userID"`
|
||||
OrderType int `json:"orderType"`
|
||||
Status int `json:"status"` // 参见OrderStatus*相关的常量定义
|
||||
OrderFinishedAt time.Time `orm:"type(datetime)" json:"orderFinishedAt"`
|
||||
GoodsVendorOrderID string `orm:"column(goods_vendor_order_id);size(48)" json:"goodsVendorOrderID"` //goodsOrder表的vendorOrderID(主动充值此值为空,从配送管理中余额不足充值则是该订单号)
|
||||
}
|
||||
|
||||
func (v *StoreAcctOrder) TableUnique() [][]string {
|
||||
|
||||
@@ -807,10 +807,11 @@ func (*BrandStore) TableUnique() [][]string {
|
||||
type StoreAcctIncome struct {
|
||||
ModelIDCUL
|
||||
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"` //门店ID
|
||||
UserID string `orm:"column(user_id)" json:"userID"` //用户ID (谁消费的)
|
||||
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"`
|
||||
UserID string `orm:"column(user_id)" json:"userID"` //用户ID (谁消费的)
|
||||
Type int `json:"type"` //收入类型
|
||||
IncomePrice int `json:"incomePrice"` //收入金额
|
||||
}
|
||||
|
||||
func (v *StoreAcctIncome) TableIndex() [][]string {
|
||||
|
||||
@@ -7,10 +7,13 @@ import (
|
||||
|
||||
const (
|
||||
//账户收入类型
|
||||
StoreAcctTypeIncomePay = 1 //主动充值
|
||||
StoreAcctTypeIncomePay = 10 //主动充值
|
||||
StoreAcctTypeRealFeeIncome = 15 //真实运费 < 临时运费, 临时运费-真实运费的值
|
||||
|
||||
//账户支出类型
|
||||
StoreAcctTypeExpendCreateWaybillEx = 2 //手动发单扣除的临时运费
|
||||
StoreAcctTypeExpendCreateWaybillEx = 20 //手动发单扣除的临时运费
|
||||
StoreAcctTypeExpendCreateWaybillTip = 21 //手动加小费扣除
|
||||
StoreAcctTypeRealFeeExpend = 25 //真实运费 > 临时运费, 真实运费的值 - 临时运费的值
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -2456,7 +2456,7 @@ func RefreshCouponsStatus(ctx *jxcontext.Context) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func CreateStoreAcctOrder(ctx *jxcontext.Context, orderType, storeID, price int) (vendorOrderID string, err error) {
|
||||
func CreateStoreAcctOrder(ctx *jxcontext.Context, orderType, storeID, price int, goodsVendorOrderID string) (vendorOrderID string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
storeAcct = &model.StoreAcct{
|
||||
@@ -2470,13 +2470,14 @@ func CreateStoreAcctOrder(ctx *jxcontext.Context, orderType, storeID, price int)
|
||||
}
|
||||
|
||||
order := &model.StoreAcctOrder{
|
||||
VendorOrderID: utils.Int64ToStr(jxutils.GenOrderNo()),
|
||||
UserID: ctx.GetUserID(),
|
||||
StoreID: storeID,
|
||||
OrderType: orderType,
|
||||
Status: model.OrderStatusWait4Pay,
|
||||
ActualPayPrice: price,
|
||||
VendorID: model.VendorIDJX,
|
||||
VendorOrderID: utils.Int64ToStr(jxutils.GenOrderNo()),
|
||||
UserID: ctx.GetUserID(),
|
||||
StoreID: storeID,
|
||||
OrderType: orderType,
|
||||
Status: model.OrderStatusWait4Pay,
|
||||
ActualPayPrice: price,
|
||||
VendorID: model.VendorIDJX,
|
||||
GoodsVendorOrderID: goodsVendorOrderID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(order, ctx.GetUserName())
|
||||
dao.Begin(db)
|
||||
|
||||
@@ -232,8 +232,8 @@ func (c *OrderController) GetOrderWaybillInfo() {
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 补全遗漏的订单
|
||||
// @Description 补全遗漏的订单
|
||||
// @Title 加小费
|
||||
// @Description 加小费
|
||||
// @Param token header string true "认证token"
|
||||
// @Param vendorOrderID formData string true "订单ID"
|
||||
// @Param vendorID formData int true "订单所属的厂商ID"
|
||||
@@ -243,7 +243,7 @@ func (c *OrderController) GetOrderWaybillInfo() {
|
||||
// @router /UpdateOrderWaybillTip [post]
|
||||
func (c *OrderController) UpdateOrderWaybillTip() {
|
||||
c.callUpdateOrderWaybillTip(func(params *tOrderUpdateOrderWaybillTipParams) (retVal interface{}, errCode string, err error) {
|
||||
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))
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -374,6 +374,7 @@ func (c *JxOrderController) ReceiveCoupons() {
|
||||
// @Title 创建门店账户订单
|
||||
// @Description 创建门店账户订单
|
||||
// @Param token header string true "认证token"
|
||||
// @Param vendorOrderID formData string false "订单ID"
|
||||
// @Param orderType formData int true "订单类型,4为门店账户订单"
|
||||
// @Param storeID formData int true "门店ID"
|
||||
// @Param price formData int true "支付金额"
|
||||
@@ -382,7 +383,7 @@ func (c *JxOrderController) ReceiveCoupons() {
|
||||
// @router /CreateStoreAcctOrder [post]
|
||||
func (c *JxOrderController) CreateStoreAcctOrder() {
|
||||
c.callCreateStoreAcctOrder(func(params *tJxorderCreateStoreAcctOrderParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = localjx.CreateStoreAcctOrder(params.Ctx, params.OrderType, params.StoreID, params.Price)
|
||||
retVal, err = localjx.CreateStoreAcctOrder(params.Ctx, params.OrderType, params.StoreID, params.Price, params.VendorOrderID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user