This commit is contained in:
unknown
2026-02-04 20:27:13 +08:00
commit 3b042d1dad
9410 changed files with 1488147 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package accountutils
import (
"errors"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
)
// InitAccount 初始化账户
func InitAccount(parent *actionutils.ParentAction, accountId int64) (*pb.UserAccount, error) {
resp, err := parent.RPC().UserAccountRPC().FindEnabledUserAccount(parent.AdminContext(), &pb.FindEnabledUserAccountRequest{UserAccountId: accountId})
if err != nil {
return nil, err
}
var account = resp.UserAccount
if account == nil {
return nil, errors.New("can not find account with id '" + types.String(accountId) + "'")
}
var userMap = maps.Map{"fullname": "", "username": ""}
var user = account.User
if user != nil {
userMap = maps.Map{"fullname": user.Fullname, "username": user.Username}
}
parent.Data["account"] = maps.Map{
"id": account.Id,
"user": userMap,
}
return account, nil
}

View File

@@ -0,0 +1,65 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package account
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/accounts/account/accountutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "index")
}
func (this *IndexAction) RunGet(params struct {
AccountId int64
Keyword string
}) {
this.Data["keyword"] = ""
account, err := accountutils.InitAccount(this.Parent(), params.AccountId)
if err != nil {
this.ErrorPage(err)
return
}
var accountMap = this.Data.GetMap("account")
accountMap["total"] = account.Total
accountMap["totalFrozen"] = account.TotalFrozen
this.Data["account"] = accountMap
// 最近操作记录
logsResp, err := this.RPC().UserAccountLogRPC().ListUserAccountLogs(this.AdminContext(), &pb.ListUserAccountLogsRequest{
UserAccountId: account.Id,
Offset: 0,
Size: 10,
})
if err != nil {
this.ErrorPage(err)
return
}
var logMaps = []maps.Map{}
for _, log := range logsResp.UserAccountLogs {
logMaps = append(logMaps, maps.Map{
"id": log.Id,
"description": log.Description,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
"delta": log.Delta,
"deltaFrozen": log.DeltaFrozen,
"total": log.Total,
"totalFrozen": log.TotalFrozen,
"event": userconfigs.FindAccountEvent(log.EventType),
})
}
this.Data["logs"] = logMaps
this.Show()
}

View File

@@ -0,0 +1,68 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package account
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/accounts/account/accountutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type LogsAction struct {
actionutils.ParentAction
}
func (this *LogsAction) Init() {
this.Nav("", "", "log")
}
func (this *LogsAction) RunGet(params struct {
AccountId int64
Keyword string
}) {
this.Data["keyword"] = params.Keyword
_, err := accountutils.InitAccount(this.Parent(), params.AccountId)
if err != nil {
this.ErrorPage(err)
return
}
countResp, err := this.RPC().UserAccountLogRPC().CountUserAccountLogs(this.AdminContext(), &pb.CountUserAccountLogsRequest{UserAccountId: params.AccountId})
if err != nil {
this.ErrorPage(err)
return
}
var count = countResp.Count
var page = this.NewPage(count)
this.Data["page"] = page.AsHTML()
logsResp, err := this.RPC().UserAccountLogRPC().ListUserAccountLogs(this.AdminContext(), &pb.ListUserAccountLogsRequest{
UserAccountId: params.AccountId,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var logMaps = []maps.Map{}
for _, log := range logsResp.UserAccountLogs {
logMaps = append(logMaps, maps.Map{
"id": log.Id,
"description": log.Description,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
"delta": log.Delta,
"deltaFrozen": log.DeltaFrozen,
"total": log.Total,
"totalFrozen": log.TotalFrozen,
"event": userconfigs.FindAccountEvent(log.EventType),
})
}
this.Data["logs"] = logMaps
this.Show()
}

View File

@@ -0,0 +1,98 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package account
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/accounts/account/accountutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/types"
)
type UpdateAction struct {
actionutils.ParentAction
}
func (this *UpdateAction) Init() {
this.Nav("", "", "update")
}
func (this *UpdateAction) RunGet(params struct {
AccountId int64
}) {
account, err := accountutils.InitAccount(this.Parent(), params.AccountId)
if err != nil {
this.ErrorPage(err)
return
}
var accountMap = this.Data.GetMap("account")
accountMap["total"] = account.Total
accountMap["totalFrozen"] = account.TotalFrozen
this.Data["account"] = accountMap
this.Data["eventTypes"] = userconfigs.FindAllAccountEventTypes()
this.Show()
}
func (this *UpdateAction) RunPost(params struct {
AccountId int64
EventType string
Delta float64
Description string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo(codes.UserAccount_LogUpdateUserAccount, params.AccountId, params.Description)
if params.AccountId <= 0 {
this.Fail("请选择要操作的账户")
}
var event = userconfigs.FindAccountEvent(params.EventType)
if event == nil {
this.Fail("请选择操作类型")
}
if params.Delta < 0 {
this.Fail("操作金额不能小于0")
}
var delta = params.Delta
if !event.IsPositive {
delta = -delta
}
accountResp, err := this.RPC().UserAccountRPC().FindEnabledUserAccount(this.AdminContext(), &pb.FindEnabledUserAccountRequest{UserAccountId: params.AccountId})
if err != nil {
this.ErrorPage(err)
return
}
var account = accountResp.UserAccount
if account == nil {
this.Fail("找不到用户的账户")
}
// 检查余额是否足够
if !event.IsPositive && delta+account.Total < 0 {
this.Fail("账户余额不足,最多只能操作" + types.String(account.Total) + "元")
}
_, err = this.RPC().UserAccountRPC().UpdateUserAccount(this.AdminContext(), &pb.UpdateUserAccountRequest{
UserAccountId: account.Id,
Delta: delta,
EventType: params.EventType,
Description: params.Description,
ParamsJSON: nil,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,62 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package accounts
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "index")
}
func (this *IndexAction) RunGet(params struct {
Keyword string
}) {
this.Data["keyword"] = params.Keyword
countResp, err := this.RPC().UserAccountRPC().CountUserAccounts(this.AdminContext(), &pb.CountUserAccountsRequest{Keyword: params.Keyword})
if err != nil {
this.ErrorPage(err)
return
}
var count = countResp.Count
var page = this.NewPage(count)
this.Data["page"] = page.AsHTML()
accountsResp, err := this.RPC().UserAccountRPC().ListUserAccounts(this.AdminContext(), &pb.ListUserAccountsRequest{
Keyword: params.Keyword,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var accountMaps = []maps.Map{}
for _, account := range accountsResp.UserAccounts {
if account.User == nil {
account.User = &pb.User{}
}
accountMaps = append(accountMaps, maps.Map{
"id": account.Id,
"total": account.Total,
"user": maps.Map{
"id": account.UserId,
"username": account.User.Username,
"fullname": account.User.Fullname,
},
})
}
this.Data["accounts"] = accountMaps
this.Show()
}

View File

@@ -0,0 +1,36 @@
//go:build plus
package accounts
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/accounts/account"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(plus.NewHelper(plus.ComponentCodeFinance)).
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeFinance)).
Data("teaMenu", "finance").
Data("teaSubMenu", "accounts").
// 财务管理
Prefix("/finance/accounts").
Get("", new(IndexAction)).
GetPost("/update", new(UpdateAction)).
Post("/userAccount", new(UserAccountAction)).
// 账户
Prefix("/finance/accounts/account").
Get("", new(account.IndexAction)).
Get("/logs", new(account.LogsAction)).
GetPost("/update", new(account.UpdateAction)).
//
EndAll()
})
}

View File

@@ -0,0 +1,84 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package accounts
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/types"
)
type UpdateAction struct {
actionutils.ParentAction
}
func (this *UpdateAction) Init() {
this.Nav("", "", "update")
}
func (this *UpdateAction) RunGet(params struct{}) {
this.Data["eventTypes"] = userconfigs.FindAllAccountEventTypes()
this.Show()
}
func (this *UpdateAction) RunPost(params struct {
UserId int64
EventType string
Delta float64
Description string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo(codes.UserAccount_LogUpdateUserAccount, params.UserId, params.Description)
if params.UserId <= 0 {
this.Fail("请选择要操作的用户")
}
var event = userconfigs.FindAccountEvent(params.EventType)
if event == nil {
this.Fail("请选择操作类型")
}
if params.Delta < 0 {
this.Fail("操作金额不能小于0")
}
var delta = params.Delta
if !event.IsPositive {
delta = -delta
}
accountResp, err := this.RPC().UserAccountRPC().FindEnabledUserAccountWithUserId(this.AdminContext(), &pb.FindEnabledUserAccountWithUserIdRequest{UserId: params.UserId})
if err != nil {
this.ErrorPage(err)
return
}
var account = accountResp.UserAccount
if account == nil {
this.Fail("找不到用户的账户")
}
// 检查余额是否足够
if !event.IsPositive && delta+account.Total < 0 {
this.Fail("账户余额不足,最多只能操作" + types.String(account.Total) + "元")
}
_, err = this.RPC().UserAccountRPC().UpdateUserAccount(this.AdminContext(), &pb.UpdateUserAccountRequest{
UserAccountId: account.Id,
Delta: delta,
EventType: params.EventType,
Description: params.Description,
ParamsJSON: nil,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,34 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package accounts
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type UserAccountAction struct {
actionutils.ParentAction
}
func (this *UserAccountAction) RunPost(params struct {
UserId int64
}) {
resp, err := this.RPC().UserAccountRPC().FindEnabledUserAccountWithUserId(this.AdminContext(), &pb.FindEnabledUserAccountWithUserIdRequest{UserId: params.UserId})
if err != nil {
this.ErrorPage(err)
return
}
var account = resp.UserAccount
if account == nil {
account = &pb.UserAccount{}
}
this.Data["account"] = maps.Map{
"total": account.Total,
"totalFrozen": account.TotalFrozen,
}
this.Success()
}