支持套餐相关操作

This commit is contained in:
GoEdgeLab
2021-11-09 15:36:18 +08:00
parent 92a0c7acbc
commit 63a09bb5a6
12 changed files with 294 additions and 23 deletions

View File

@@ -0,0 +1,37 @@
package users
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type OptionsAction struct {
actionutils.ParentAction
}
func (this *OptionsAction) RunPost(params struct {
Keyword string
}) {
usersResp, err := this.RPC().UserRPC().ListEnabledUsers(this.AdminContext(), &pb.ListEnabledUsersRequest{
Keyword: params.Keyword,
Offset: 0,
Size: 10000, // TODO 改进 <plan-user-selector> 组件
})
if err != nil {
this.ErrorPage(err)
return
}
userMaps := []maps.Map{}
for _, user := range usersResp.Users {
userMaps = append(userMaps, maps.Map{
"id": user.Id,
"fullname": user.Fullname,
"username": user.Username,
})
}
this.Data["users"] = userMaps
this.Success()
}

View File

@@ -0,0 +1,49 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package users
import (
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type PlansAction struct {
actionutils.ParentAction
}
func (this *PlansAction) RunPost(params struct {
UserId int64
ServerId int64
}) {
if !teaconst.IsPlus || params.UserId <= 0 {
this.Data["plans"] = []maps.Map{}
this.Success()
}
// TODO 优化用户套餐查询
userPlansResp, err := this.RPC().UserPlanRPC().FindAllEnabledUserPlansForServer(this.AdminContext(), &pb.FindAllEnabledUserPlansForServerRequest{
UserId: params.UserId,
ServerId: params.ServerId,
})
if err != nil {
this.ErrorPage(err)
return
}
var userPlanMaps = []maps.Map{}
for _, userPlan := range userPlansResp.UserPlans {
if userPlan.Plan == nil {
continue
}
userPlanMaps = append(userPlanMaps, maps.Map{
"id": userPlan.Id,
"name": userPlan.Plan.Name,
"dayTo": userPlan.DayTo,
})
}
this.Data["plans"] = userPlanMaps
this.Success()
}