Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package userPlans
|
||||
|
||||
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/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
// 所有套餐
|
||||
plansResp, err := this.RPC().NSPlanRPC().FindAllEnabledNSPlans(this.AdminContext(), &pb.FindAllEnabledNSPlansRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var planMaps = []maps.Map{}
|
||||
for _, plan := range plansResp.NsPlans {
|
||||
planMaps = append(planMaps, maps.Map{
|
||||
"id": plan.Id,
|
||||
"name": plan.Name,
|
||||
})
|
||||
}
|
||||
this.Data["plans"] = planMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
UserId int64
|
||||
PlanId int64
|
||||
PeriodUnit string
|
||||
DayTo string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSUserPlan_LogCreateNSUserPlan, params.UserId, params.PlanId)
|
||||
|
||||
params.Must.
|
||||
Field("userId", params.UserId).
|
||||
Gt(0, "请选择用户").
|
||||
Field("planId", params.PlanId).
|
||||
Gt(0, "请选择套餐")
|
||||
|
||||
if len(params.DayTo) == 0 {
|
||||
this.FailField("dayTo", "请选择到期时间")
|
||||
}
|
||||
|
||||
if !regexp.MustCompile(`^\d{4}-\d{2}-\d{2}$`).MatchString(params.DayTo) {
|
||||
this.FailField("dayTo", "请输入正确的到期时间")
|
||||
}
|
||||
|
||||
if params.DayTo < timeutil.Format("Y-m-d") {
|
||||
this.FailField("dayTo", "过期时间不能小于今天")
|
||||
}
|
||||
|
||||
_, err := this.RPC().NSUserPlanRPC().CreateNSUserPlan(this.AdminContext(), &pb.CreateNSUserPlanRequest{
|
||||
UserId: params.UserId,
|
||||
NsPlanId: params.PlanId,
|
||||
DayFrom: timeutil.Format("Ymd"),
|
||||
DayTo: strings.ReplaceAll(params.DayTo, "-", ""),
|
||||
PeriodUnit: params.PeriodUnit,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
163
EdgeAdmin/internal/web/actions/default/ns/userPlans/index.go
Normal file
163
EdgeAdmin/internal/web/actions/default/ns/userPlans/index.go
Normal file
@@ -0,0 +1,163 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package userPlans
|
||||
|
||||
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("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
Type string
|
||||
UserId int64
|
||||
PlanId int64
|
||||
PeriodUnit string
|
||||
}) {
|
||||
if len(params.Type) == 0 {
|
||||
params.Type = "available"
|
||||
}
|
||||
|
||||
this.Data["userId"] = params.UserId
|
||||
this.Data["planId"] = params.PlanId
|
||||
this.Data["periodUnit"] = params.PeriodUnit
|
||||
this.Data["type"] = params.Type
|
||||
|
||||
var expireDays int32 = 0
|
||||
var isExpired = false
|
||||
switch params.Type {
|
||||
case "expiring7":
|
||||
expireDays = 7
|
||||
case "expiring30":
|
||||
expireDays = 30
|
||||
case "expired":
|
||||
isExpired = true
|
||||
}
|
||||
|
||||
// 统计数据
|
||||
countAvailableResp, err := this.RPC().NSUserPlanRPC().CountNSUserPlans(this.AdminContext(), &pb.CountNSUserPlansRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["countAvailable"] = countAvailableResp.Count
|
||||
|
||||
countExpiring7Resp, err := this.RPC().NSUserPlanRPC().CountNSUserPlans(this.AdminContext(), &pb.CountNSUserPlansRequest{
|
||||
ExpireDays: 7,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["countExpiring7"] = countExpiring7Resp.Count
|
||||
|
||||
countExpiring30Resp, err := this.RPC().NSUserPlanRPC().CountNSUserPlans(this.AdminContext(), &pb.CountNSUserPlansRequest{
|
||||
ExpireDays: 30,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["countExpiring30"] = countExpiring30Resp.Count
|
||||
|
||||
countExpiredResp, err := this.RPC().NSUserPlanRPC().CountNSUserPlans(this.AdminContext(), &pb.CountNSUserPlansRequest{
|
||||
IsExpired: true,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["countExpired"] = countExpiredResp.Count
|
||||
|
||||
// 所有套餐
|
||||
plansResp, err := this.RPC().NSPlanRPC().FindAllNSPlans(this.AdminContext(), &pb.FindAllNSPlansRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var planMaps = []maps.Map{}
|
||||
for _, plan := range plansResp.NsPlans {
|
||||
planMaps = append(planMaps, maps.Map{
|
||||
"id": plan.Id,
|
||||
"name": plan.Name,
|
||||
})
|
||||
}
|
||||
this.Data["plans"] = planMaps
|
||||
|
||||
// 用户套餐数量
|
||||
countResp, err := this.RPC().NSUserPlanRPC().CountNSUserPlans(this.AdminContext(), &pb.CountNSUserPlansRequest{
|
||||
UserId: params.UserId,
|
||||
NsPlanId: params.PlanId,
|
||||
PeriodUnit: params.PeriodUnit,
|
||||
IsExpired: isExpired,
|
||||
ExpireDays: expireDays,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
userPlansResp, err := this.RPC().NSUserPlanRPC().ListNSUserPlans(this.AdminContext(), &pb.ListNSUserPlansRequest{
|
||||
UserId: params.UserId,
|
||||
NsPlanId: params.PlanId,
|
||||
PeriodUnit: params.PeriodUnit,
|
||||
IsExpired: isExpired,
|
||||
ExpireDays: expireDays,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var userPlanMaps = []maps.Map{}
|
||||
for _, userPlan := range userPlansResp.NsUserPlans {
|
||||
// plan
|
||||
var planMap maps.Map
|
||||
if userPlan.NsPlan != nil {
|
||||
planMap = maps.Map{
|
||||
"id": userPlan.NsPlan.Id,
|
||||
"name": userPlan.NsPlan.Name,
|
||||
}
|
||||
}
|
||||
|
||||
// user
|
||||
var userMap maps.Map
|
||||
if userPlan.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": userPlan.User.Id,
|
||||
"username": userPlan.User.Username,
|
||||
"fullname": userPlan.User.Fullname,
|
||||
}
|
||||
}
|
||||
|
||||
// 错误的结束日期跳过,防止下面格式化的时候出错
|
||||
if len(userPlan.DayTo) < 8 {
|
||||
continue
|
||||
}
|
||||
|
||||
userPlanMaps = append(userPlanMaps, maps.Map{
|
||||
"id": userPlan.Id,
|
||||
"dayFrom": userPlan.DayFrom,
|
||||
"dayTo": userPlan.DayTo[:4] + "-" + userPlan.DayTo[4:6] + "-" + userPlan.DayTo[6:],
|
||||
"periodUnit": userPlan.PeriodUnit,
|
||||
"plan": planMap,
|
||||
"user": userMap,
|
||||
})
|
||||
}
|
||||
this.Data["userPlans"] = userPlanMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package userPlan
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
UserPlanId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSUserPlan_LogDeleteNSUserPlan, params.UserPlanId)
|
||||
|
||||
_, err := this.RPC().NSUserPlanRPC().DeleteNSUserPlan(this.AdminContext(), &pb.DeleteNSUserPlanRequest{NsUserPlanId: params.UserPlanId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package userPlan
|
||||
|
||||
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/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
UserPlanId int64
|
||||
}) {
|
||||
userPlanResp, err := this.RPC().NSUserPlanRPC().FindNSUserPlan(this.AdminContext(), &pb.FindNSUserPlanRequest{NsUserPlanId: params.UserPlanId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var userPlan = userPlanResp.NsUserPlan
|
||||
if userPlan == nil {
|
||||
this.NotFound("NSUserPlan", params.UserPlanId)
|
||||
return
|
||||
}
|
||||
|
||||
var userMap maps.Map
|
||||
if userPlan.User != nil {
|
||||
userMap = maps.Map{
|
||||
"id": userPlan.User.Id,
|
||||
"username": userPlan.User.Username,
|
||||
"fullname": userPlan.User.Fullname,
|
||||
}
|
||||
}
|
||||
|
||||
// 修复可能产生的意外错误
|
||||
if len(userPlan.DayTo) < 6 {
|
||||
userPlan.DayTo = timeutil.Format("Ymd")
|
||||
}
|
||||
|
||||
this.Data["userPlan"] = maps.Map{
|
||||
"id": userPlan.Id,
|
||||
"planId": userPlan.NsPlanId,
|
||||
"userId": userPlan.UserId,
|
||||
"periodUnit": userPlan.PeriodUnit,
|
||||
"dayTo": userPlan.DayTo[:4] + "-" + userPlan.DayTo[4:6] + "-" + userPlan.DayTo[6:],
|
||||
"user": userMap,
|
||||
}
|
||||
|
||||
// 所有套餐
|
||||
plansResp, err := this.RPC().NSPlanRPC().FindAllEnabledNSPlans(this.AdminContext(), &pb.FindAllEnabledNSPlansRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var planMaps = []maps.Map{}
|
||||
for _, plan := range plansResp.NsPlans {
|
||||
planMaps = append(planMaps, maps.Map{
|
||||
"id": plan.Id,
|
||||
"name": plan.Name,
|
||||
})
|
||||
}
|
||||
this.Data["plans"] = planMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePopupAction) RunPost(params struct {
|
||||
UserPlanId int64
|
||||
|
||||
PlanId int64
|
||||
PeriodUnit string
|
||||
DayTo string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NSUserPlan_LogUpdateNSUserPlan, params.UserPlanId)
|
||||
|
||||
params.Must.
|
||||
Field("planId", params.PlanId).
|
||||
Gt(0, "请选择套餐")
|
||||
|
||||
if len(params.DayTo) == 0 {
|
||||
this.FailField("dayTo", "请选择到期时间")
|
||||
}
|
||||
|
||||
if !regexp.MustCompile(`^\d{4}-\d{2}-\d{2}$`).MatchString(params.DayTo) {
|
||||
this.FailField("dayTo", "请输入正确的到期时间")
|
||||
}
|
||||
|
||||
if params.DayTo < timeutil.Format("Y-m-d") {
|
||||
this.FailField("dayTo", "过期时间不能小于今天")
|
||||
}
|
||||
|
||||
_, err := this.RPC().NSUserPlanRPC().UpdateNSUserPlan(this.AdminContext(), &pb.UpdateNSUserPlanRequest{
|
||||
NsUserPlanId: params.UserPlanId,
|
||||
NsPlanId: params.PlanId,
|
||||
DayFrom: timeutil.Format("Ymd"),
|
||||
DayTo: strings.ReplaceAll(params.DayTo, "-", ""),
|
||||
PeriodUnit: params.PeriodUnit,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user