1.4.5.2
This commit is contained in:
146
EdgeAdmin/internal/web/actions/default/plans/index.go
Normal file
146
EdgeAdmin/internal/web/actions/default/plans/index.go
Normal file
@@ -0,0 +1,146 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package plans
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/financeutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
countResp, err := this.RPC().PlanRPC().CountAllEnabledPlans(this.AdminContext(), &pb.CountAllEnabledPlansRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count, 100)
|
||||
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
plansResp, err := this.RPC().PlanRPC().ListEnabledPlans(this.AdminContext(), &pb.ListEnabledPlansRequest{
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var planMaps = []maps.Map{}
|
||||
for _, plan := range plansResp.Plans {
|
||||
// 集群
|
||||
clusterResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeCluster(this.AdminContext(), &pb.FindEnabledNodeClusterRequest{NodeClusterId: plan.ClusterId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var clusterMap = maps.Map{
|
||||
"id": 0,
|
||||
"name": "",
|
||||
}
|
||||
if clusterResp.NodeCluster != nil {
|
||||
clusterMap["id"] = clusterResp.NodeCluster.Id
|
||||
clusterMap["name"] = clusterResp.NodeCluster.Name
|
||||
}
|
||||
|
||||
// 流量价格
|
||||
var trafficPrice = &serverconfigs.PlanTrafficPriceConfig{}
|
||||
if len(plan.TrafficPriceJSON) > 0 {
|
||||
err = json.Unmarshal(plan.TrafficPriceJSON, trafficPrice)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 带宽价格
|
||||
var bandwidthPrice = &serverconfigs.PlanBandwidthPriceConfig{}
|
||||
if len(plan.BandwidthPriceJSON) > 0 {
|
||||
err = json.Unmarshal(plan.BandwidthPriceJSON, bandwidthPrice)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 流量限制
|
||||
var trafficLimit = &serverconfigs.TrafficLimitConfig{}
|
||||
if len(plan.TrafficLimitJSON) > 0 {
|
||||
err = json.Unmarshal(plan.TrafficLimitJSON, trafficLimit)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 带宽限制
|
||||
// bandwidth limit
|
||||
var bandwidthLimitPerNode = &shared.BitSizeCapacity{}
|
||||
if len(plan.BandwidthLimitPerNodeJSON) > 0 {
|
||||
err = json.Unmarshal(plan.BandwidthLimitPerNodeJSON, bandwidthLimitPerNode)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// max upload size
|
||||
var maxUploadSize = &shared.SizeCapacity{}
|
||||
if len(plan.MaxUploadSizeJSON) > 0 {
|
||||
err = json.Unmarshal(plan.MaxUploadSizeJSON, maxUploadSize)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
planMaps = append(planMaps, maps.Map{
|
||||
"id": plan.Id,
|
||||
"name": plan.Name,
|
||||
"description": plan.Description,
|
||||
"isOn": plan.IsOn,
|
||||
"cluster": clusterMap,
|
||||
"priceType": plan.PriceType,
|
||||
"monthlyPrice": plan.MonthlyPrice,
|
||||
"seasonallyPrice": plan.SeasonallyPrice,
|
||||
"yearlyPrice": plan.YearlyPrice,
|
||||
"trafficPrice": trafficPrice,
|
||||
"bandwidthPrice": bandwidthPrice,
|
||||
"trafficLimit": trafficLimit,
|
||||
"bandwidthLimitPerNode": bandwidthLimitPerNode,
|
||||
"totalServers": plan.TotalServers,
|
||||
"dailyRequests": plan.DailyRequests,
|
||||
"monthlyRequests": plan.MonthlyRequests,
|
||||
"dailyWebsocketConnections": plan.DailyWebsocketConnections,
|
||||
"monthlyWebsocketConnections": plan.MonthlyWebsocketConnections,
|
||||
"maxUploadSize": maxUploadSize,
|
||||
})
|
||||
}
|
||||
this.Data["plans"] = planMaps
|
||||
|
||||
// 价格设置
|
||||
priceConfig, err := financeutils.ReadPriceConfig(this.AdminContext())
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["canUsePlans"] = priceConfig != nil && priceConfig.EnablePlans
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user