Initial commit (code only without large binaries)
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user