Files
waf-platform/EdgeAdmin/internal/web/actions/default/ns/plans/index.go

55 lines
1.3 KiB
Go

// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package plans
import (
"encoding/json"
"fmt"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"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{}) {
// 当前所有套餐
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 {
var config = dnsconfigs.DefaultNSPlanConfig()
if len(plan.ConfigJSON) > 0 {
err = json.Unmarshal(plan.ConfigJSON, config)
if err != nil {
this.ErrorPage(err)
return
}
}
planMaps = append(planMaps, maps.Map{
"id": plan.Id,
"name": plan.Name,
"isOn": plan.IsOn,
"monthlyPriceFormat": fmt.Sprintf("%.2f", plan.MonthlyPrice),
"yearlyPriceFormat": fmt.Sprintf("%.2f", plan.YearlyPrice),
"config": config,
})
}
this.Data["plans"] = planMaps
this.Show()
}