Initial commit (code only without large binaries)

This commit is contained in:
robin
2026-02-15 18:58:44 +08:00
commit 35df75498f
9442 changed files with 1495866 additions and 0 deletions

View File

@@ -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()
}

View File

@@ -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()
}