Files
kami_boss/internal/models/transaction.go
danial c3906e940e refactor(account): 重构账户管理页面布局和样式
-精简HTML结构,优化`account.html`,`apple-card/account.html`,和`t-mall-game/account.html`中iframe的布局。
- 调整CSS样式,以增强用户界面的一致性和可读性。
- 优化`account_history.html`中的表格和搜索栏的样式与对齐。

fix(controller): 修正新增控制器参数顺序

- 修正`addController.go`中的参数顺序,确保交易类型正确传递给服务层。
- 更新数据库插入操作,确保UUID正确分配给新记录,防止SQL错误。
2024-09-04 09:54:18 +08:00

76 lines
2.2 KiB
Go

package models
import (
"boss/internal/common"
"boss/internal/models/accounts"
"context"
"errors"
"github.com/beego/beego/v2/client/orm"
"github.com/beego/beego/v2/core/logs"
"time"
)
func OperatorAccount(accountUid, operatorType string, amount float64) (string, bool) {
o := orm.NewOrm()
msg := ""
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
//处理事务
accountInfo := new(accounts.AccountInfo)
if err := txOrm.Raw("select * from account_info where account_uid = ? for update", accountUid).
QueryRow(accountInfo); err != nil || accountInfo.AccountUid == "" {
logs.Error("operator account get account info for update fail: ", err)
return err
}
accountInfo.UpdateTime = time.Now()
flag := true
switch operatorType {
case common.PLUS_AMOUNT: //处理加款操作
accountInfo.Balance = accountInfo.Balance + amount
accountInfo.SettleAmount = accountInfo.SettleAmount + amount
case common.SUB_AMOUNT: //处理减款
if accountInfo.Balance >= amount && accountInfo.SettleAmount >= amount {
accountInfo.Balance = accountInfo.Balance - amount
accountInfo.SettleAmount = accountInfo.SettleAmount - amount
} else {
msg = "账户余额不够减"
flag = false
}
case common.FREEZE_AMOUNT: //处理冻结款
accountInfo.FreezeAmount = accountInfo.FreezeAmount + amount
case common.UNFREEZE_AMOUNT: //处理解冻款
if accountInfo.FreezeAmount >= amount {
accountInfo.FreezeAmount = accountInfo.FreezeAmount - amount
} else {
msg = "账户冻结金额不够解冻款"
flag = false
}
}
if !flag {
return errors.New("处理失败")
}
if _, err := txOrm.Update(accountInfo); err != nil {
logs.Error("operator account update account fail: ", err)
return err
}
//往account_history表中插入一条动账记录
accountHistory := accounts.AccountHistoryInfo{AccountUid: accountUid, AccountName: accountInfo.AccountName, Type: operatorType,
Amount: amount, Balance: accountInfo.Balance, CreateTime: time.Now(), UpdateTime: time.Now()}
if _, err := txOrm.Insert(&accountHistory); err != nil {
logs.Error("operator account insert account history fail: ", err)
return err
}
return nil
}); err != nil {
return msg, false
}
return msg, true
}