// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . //go:build plus package plans import ( "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/langs/codes" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/iwind/TeaGo/actions" ) type CreatePopupAction struct { actionutils.ParentAction } func (this *CreatePopupAction) Init() { this.Nav("", "", "") } func (this *CreatePopupAction) RunGet(params struct{}) { this.Show() } func (this *CreatePopupAction) RunPost(params struct { Name string MonthlyPrice float32 YearlyPrice float32 SupportCountryRoutes bool SupportChinaProvinceRoutes bool SupportISPRoutes bool SupportAgentRoutes bool SupportPublicRoutes bool SupportHealthCheck bool MinTTL int32 MaxDomains int32 MaxRecordsPerDomain int32 MaxLoadBalanceRecordsPerRecord int32 MaxCustomRoutes int32 Must *actions.Must CSRF *actionutils.CSRF }) { var planId int64 defer func() { this.CreateLogInfo(codes.NSPlan_LogCreateNSPlan, planId) }() params.Must. Field("name", params.Name). Require("请输入套餐名称"). Field("monthlyPrice", params.MonthlyPrice). Gt(0, "请输入按月价格"). Field("yearlyPrice", params.YearlyPrice). Gt(0, "请输入按年价格") var config = dnsconfigs.DefaultNSPlanConfig() config.SupportCountryRoutes = params.SupportCountryRoutes config.SupportChinaProvinceRoutes = params.SupportChinaProvinceRoutes config.SupportISPRoutes = params.SupportISPRoutes config.SupportAgentRoutes = params.SupportAgentRoutes config.SupportPublicRoutes = params.SupportPublicRoutes config.SupportHealthCheck = params.SupportHealthCheck config.MinTTL = params.MinTTL config.MaxDomains = params.MaxDomains config.MaxRecordsPerDomain = params.MaxRecordsPerDomain config.MaxLoadBalanceRecordsPerRecord = params.MaxLoadBalanceRecordsPerRecord config.MaxCustomRoutes = params.MaxCustomRoutes err := config.Init() if err != nil { this.Fail("配置校验失败:" + err.Error()) } configJSON, err := json.Marshal(config) if err != nil { this.ErrorPage(err) return } createResp, err := this.RPC().NSPlanRPC().CreateNSPlan(this.AdminContext(), &pb.CreateNSPlanRequest{ Name: params.Name, MonthlyPrice: params.MonthlyPrice, YearlyPrice: params.YearlyPrice, ConfigJSON: configJSON, }) if err != nil { this.ErrorPage(err) return } planId = createResp.NsPlanId this.Success() }