aa
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
package cms
|
package cms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StoreAcctManager struct {
|
type StoreAcctManager struct {
|
||||||
@@ -19,28 +21,64 @@ func init() {
|
|||||||
partner.InitStoreAcctManager(FixedStoreAcctManager)
|
partner.InitStoreAcctManager(FixedStoreAcctManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, db *dao.DaoDB, storeID, price, acctType int) (err error) {
|
func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, db *dao.DaoDB, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||||
|
var (
|
||||||
|
userID, userName string
|
||||||
|
goodsVendorOrderID string
|
||||||
|
)
|
||||||
|
if ctx != nil {
|
||||||
|
userID = ctx.GetUserID()
|
||||||
|
userName = ctx.GetUserName()
|
||||||
|
goodsVendorOrderID = vendorOrderID
|
||||||
|
} else {
|
||||||
|
storeOrder := &model.StoreAcctOrder{
|
||||||
|
VendorOrderID: vendorOrderID,
|
||||||
|
}
|
||||||
|
if err = dao.GetEntity(db, storeOrder, "VendorOrderID"); err == nil && storeOrder.ID != 0 {
|
||||||
|
userID = storeOrder.UserID
|
||||||
|
userName = storeOrder.LastOperator
|
||||||
|
goodsVendorOrderID = storeOrder.GoodsVendorOrderID
|
||||||
|
}
|
||||||
|
}
|
||||||
storeAcctIncome := &model.StoreAcctIncome{
|
storeAcctIncome := &model.StoreAcctIncome{
|
||||||
StoreID: storeID,
|
StoreID: storeID,
|
||||||
IncomePrice: price,
|
IncomePrice: price,
|
||||||
Type: acctType,
|
Type: acctType,
|
||||||
UserID: ctx.GetUserID(),
|
UserID: userID,
|
||||||
|
VendorOrderID: goodsVendorOrderID,
|
||||||
}
|
}
|
||||||
dao.WrapAddIDCULEntity(storeAcctIncome, ctx.GetUserName())
|
dao.WrapAddIDCULEntity(storeAcctIncome, userName)
|
||||||
err = dao.CreateEntity(db, storeAcctIncome)
|
err = dao.CreateEntity(db, storeAcctIncome)
|
||||||
|
globals.SugarLogger.Debugf("InsertStoreAcctIncome orderID: [%v] , price :[%v] , type :[%v]", vendorOrderID, price, acctType)
|
||||||
return err
|
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, db *dao.DaoDB, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||||
|
var (
|
||||||
|
userID, userName string
|
||||||
|
)
|
||||||
|
if ctx != nil {
|
||||||
|
userID = ctx.GetUserID()
|
||||||
|
userName = ctx.GetUserName()
|
||||||
|
} else {
|
||||||
|
storeOrder := &model.StoreAcctOrder{
|
||||||
|
VendorOrderID: vendorOrderID,
|
||||||
|
}
|
||||||
|
if err = dao.GetEntity(db, storeOrder, "VendorOrderID"); err == nil && storeOrder.ID != 0 {
|
||||||
|
userID = storeOrder.UserID
|
||||||
|
userName = storeOrder.LastOperator
|
||||||
|
}
|
||||||
|
}
|
||||||
storeAcctExpend := &model.StoreAcctExpend{
|
storeAcctExpend := &model.StoreAcctExpend{
|
||||||
StoreID: storeID,
|
StoreID: storeID,
|
||||||
ExpendPrice: price,
|
ExpendPrice: price,
|
||||||
Type: acctType,
|
Type: acctType,
|
||||||
UserID: ctx.GetUserID(),
|
UserID: userID,
|
||||||
VendorOrderID: vendorOrderID,
|
VendorOrderID: vendorOrderID,
|
||||||
}
|
}
|
||||||
dao.WrapAddIDCULEntity(storeAcctExpend, ctx.GetUserName())
|
dao.WrapAddIDCULEntity(storeAcctExpend, userName)
|
||||||
err = dao.CreateEntity(db, storeAcctExpend)
|
err = dao.CreateEntity(db, storeAcctExpend)
|
||||||
|
globals.SugarLogger.Debugf("InsertStoreAcctExpend orderID: [%v] , price :[%v] , type :[%v]", vendorOrderID, price, acctType)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,14 +86,13 @@ func (s *StoreAcctManager) UpdateStoreAcctBalance(ctx *jxcontext.Context, storeI
|
|||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
)
|
)
|
||||||
|
globals.SugarLogger.Debugf("UpdateStoreAcctBalance storeID: [%v] , price :[%v] ,", storeID, price)
|
||||||
|
if ctx == nil {
|
||||||
|
ctx = jxcontext.AdminCtx
|
||||||
|
}
|
||||||
storeAcct := &model.StoreAcct{
|
storeAcct := &model.StoreAcct{
|
||||||
StoreID: storeID,
|
StoreID: storeID,
|
||||||
}
|
}
|
||||||
if isIncome {
|
|
||||||
storeAcct.AccountBalance += price
|
|
||||||
} else {
|
|
||||||
storeAcct.AccountBalance -= price
|
|
||||||
}
|
|
||||||
dao.Begin(db)
|
dao.Begin(db)
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil || err != nil {
|
if r := recover(); r != nil || err != nil {
|
||||||
@@ -73,10 +110,17 @@ func (s *StoreAcctManager) UpdateStoreAcctBalance(ctx *jxcontext.Context, storeI
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
if _, err = dao.UpdateEntity(db, storeAcct, "AccountBalance"); err != nil {
|
||||||
dao.Rollback(db)
|
dao.Rollback(db)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
globals.SugarLogger.Debugf("UpdateStoreAcctBalance2 storeID: [%v] , balance :[%v] ,", storeID, storeAcct.AccountBalance)
|
||||||
}
|
}
|
||||||
dao.Commit(db)
|
dao.Commit(db)
|
||||||
return err
|
return err
|
||||||
@@ -86,22 +130,46 @@ func (s *StoreAcctManager) InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *j
|
|||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
)
|
)
|
||||||
|
utils.CallFuncAsync(func() {
|
||||||
if err = s.InsertStoreAcctExpend(ctx, db, storeID, price, acctType, vendorOrderID); err == nil {
|
if err = s.InsertStoreAcctExpend(ctx, db, storeID, price, acctType, vendorOrderID); err == nil {
|
||||||
s.UpdateStoreAcctBalance(ctx, storeID, price, false)
|
s.UpdateStoreAcctBalance(ctx, storeID, price, false)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StoreAcctManager) InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int) (err error) {
|
func (s *StoreAcctManager) InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
)
|
)
|
||||||
if err = s.InsertStoreAcctIncome(ctx, db, storeID, price, acctType); err == nil {
|
utils.CallFuncAsync(func() {
|
||||||
|
if err = s.InsertStoreAcctIncome(ctx, db, storeID, price, acctType, vendorOrderID); err == nil {
|
||||||
s.UpdateStoreAcctBalance(ctx, storeID, price, true)
|
s.UpdateStoreAcctBalance(ctx, storeID, price, true)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StoreAcctManager) CheckStoreAcctExpendExist(storeID int, vendorOrderID string) (result bool, err error) {
|
func (s *StoreAcctManager) CheckStoreAcctExpendExist(vendorOrderID string) (isEqual, isZero bool, err error) {
|
||||||
return false, err
|
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)
|
||||||
|
if expends != incomes {
|
||||||
|
if expends > incomes {
|
||||||
|
return false, false, err
|
||||||
|
} else {
|
||||||
|
globals.SugarLogger.Debugf("CheckStoreAcctExpendExist 收入大于支出! orderID:[%v]", vendorOrderID)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if expends == 0 && incomes == 0 {
|
||||||
|
return true, true, err
|
||||||
|
} else {
|
||||||
|
return true, false, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, false, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -808,6 +808,7 @@ type StoreAcctIncome struct {
|
|||||||
ModelIDCUL
|
ModelIDCUL
|
||||||
|
|
||||||
StoreID int `orm:"column(store_id)" json:"storeID"` //门店ID
|
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 (谁消费的)
|
UserID string `orm:"column(user_id)" json:"userID"` //用户ID (谁消费的)
|
||||||
Type int `json:"type"` //收入类型
|
Type int `json:"type"` //收入类型
|
||||||
IncomePrice int `json:"incomePrice"` //收入金额
|
IncomePrice int `json:"incomePrice"` //收入金额
|
||||||
|
|||||||
Reference in New Issue
Block a user