115 lines
2.9 KiB
Go
115 lines
2.9 KiB
Go
package accounts
|
|
|
|
import (
|
|
"context"
|
|
"gateway/internal/otelTrace"
|
|
|
|
"time"
|
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type AccountInfo struct {
|
|
Id int
|
|
Status string
|
|
AccountUid string
|
|
AccountName string
|
|
Balance float64 // 账户总余额
|
|
SettleAmount float64 // 已经结算的金额
|
|
LoanAmount float64 // 账户押款金额
|
|
FreezeAmount float64 // 账户冻结金额
|
|
WaitAmount float64 // 待结算资金
|
|
PayforAmount float64 // 代付在途金额
|
|
// AbleBalance float64 //账户可用金额
|
|
CreateTime time.Time
|
|
UpdateTime time.Time
|
|
}
|
|
|
|
const ACCOUNT_INFO = "account_info"
|
|
|
|
func InsetAcount(ctx context.Context, account AccountInfo) bool {
|
|
o := orm.NewOrm()
|
|
_, err := o.Insert(&account)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("insert account fail: ", zap.Error(err))
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func GetAccountByUid(ctx context.Context, accountUid string) AccountInfo {
|
|
o := orm.NewOrm()
|
|
var account AccountInfo
|
|
_, err := o.QueryTable(ACCOUNT_INFO).Filter("account_uid", accountUid).Limit(1).All(&account)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get account by uid fail: ", zap.Error(err))
|
|
}
|
|
|
|
return account
|
|
}
|
|
|
|
func GetAccountLenByMap(ctx context.Context, params map[string]string) int {
|
|
o := orm.NewOrm()
|
|
qs := o.QueryTable(ACCOUNT_INFO)
|
|
for k, v := range params {
|
|
if len(v) > 0 {
|
|
qs = qs.Filter(k, v)
|
|
}
|
|
}
|
|
cnt, err := qs.Limit(-1).OrderBy("-update_time").Count()
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get account len by map fail: ", zap.Error(err))
|
|
}
|
|
return int(cnt)
|
|
}
|
|
|
|
func GetAccountByMap(ctx context.Context, params map[string]string, displayCount, offset int) []AccountInfo {
|
|
o := orm.NewOrm()
|
|
var accountList []AccountInfo
|
|
qs := o.QueryTable(ACCOUNT_INFO)
|
|
for k, v := range params {
|
|
if len(v) > 0 {
|
|
qs = qs.Filter(k, v)
|
|
}
|
|
}
|
|
|
|
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&accountList)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get account by map fail: ", zap.Error(err))
|
|
}
|
|
return accountList
|
|
}
|
|
|
|
func GetAllAccount(ctx context.Context) []AccountInfo {
|
|
o := orm.NewOrm()
|
|
var accountList []AccountInfo
|
|
|
|
_, err := o.QueryTable(ACCOUNT_INFO).Limit(-1).All(&accountList)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get all account fail: ", zap.Error(err))
|
|
}
|
|
|
|
return accountList
|
|
}
|
|
|
|
func UpdateAccount(ctx context.Context, account AccountInfo) bool {
|
|
o := orm.NewOrm()
|
|
_, err := o.Update(&account)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("update account fail: ", zap.Error(err))
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func DeleteAccountByUid(ctx context.Context, accountUid string) bool {
|
|
o := orm.NewOrm()
|
|
_, err := o.QueryTable(ACCOUNT_INFO).Filter("account_uid", accountUid).Delete()
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("delete account fail: ", zap.Error(err))
|
|
return false
|
|
}
|
|
return true
|
|
}
|