aa
This commit is contained in:
107
business/jxstore/cms/store_acct.go
Normal file
107
business/jxstore/cms/store_acct.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"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/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
)
|
||||
|
||||
type StoreAcctManager struct {
|
||||
}
|
||||
|
||||
var (
|
||||
FixedStoreAcctManager *StoreAcctManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
FixedStoreAcctManager = &StoreAcctManager{}
|
||||
partner.InitStoreAcctManager(FixedStoreAcctManager)
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) InsertStoreAcctIncome(ctx *jxcontext.Context, db *dao.DaoDB, storeID, price, acctType int) (err error) {
|
||||
storeAcctIncome := &model.StoreAcctIncome{
|
||||
StoreID: storeID,
|
||||
IncomePrice: price,
|
||||
Type: acctType,
|
||||
UserID: ctx.GetUserID(),
|
||||
}
|
||||
dao.WrapAddIDCULEntity(storeAcctIncome, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, storeAcctIncome)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) InsertStoreAcctExpend(ctx *jxcontext.Context, db *dao.DaoDB, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||
storeAcctExpend := &model.StoreAcctExpend{
|
||||
StoreID: storeID,
|
||||
ExpendPrice: price,
|
||||
Type: acctType,
|
||||
UserID: ctx.GetUserID(),
|
||||
VendorOrderID: vendorOrderID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(storeAcctExpend, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, storeAcctExpend)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) UpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price int, isIncome bool) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
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 {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
if err = dao.GetEntity(db, storeAcct, "StoreID"); err != nil && dao.IsNoRowsError(err) {
|
||||
//新增门店账单
|
||||
dao.WrapAddIDCULEntity(storeAcct, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, storeAcct); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err = dao.UpdateEntity(db, storeAcct, "AccountBalance"); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int, vendorOrderID string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if err = s.InsertStoreAcctExpend(ctx, db, storeID, price, acctType, vendorOrderID); err == nil {
|
||||
s.UpdateStoreAcctBalance(ctx, storeID, price, false)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) InsertStoreAcctIncomeAndUpdateStoreAcctBalance(ctx *jxcontext.Context, storeID, price, acctType int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if err = s.InsertStoreAcctIncome(ctx, db, storeID, price, acctType); err == nil {
|
||||
s.UpdateStoreAcctBalance(ctx, storeID, price, true)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *StoreAcctManager) CheckStoreAcctExpendExist(storeID int, vendorOrderID string) (result bool, err error) {
|
||||
return false, err
|
||||
}
|
||||
Reference in New Issue
Block a user