1.4.5.2
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
//go:build plus
|
||||
|
||||
package fee
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"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/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type TrafficAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TrafficAction) Init() {
|
||||
this.Nav("", "", "traffic")
|
||||
}
|
||||
|
||||
func (this *TrafficAction) RunGet(params struct{}) {
|
||||
// 财务相关配置
|
||||
config, err := financeutils.ReadPriceConfig(this.AdminContext())
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["config"] = config
|
||||
|
||||
// 所有价格项目
|
||||
itemsResp, err := this.RPC().NodePriceItemRPC().FindAllAvailableNodePriceItems(this.AdminContext(), &pb.FindAllAvailableNodePriceItemsRequest{Type: userconfigs.PriceTypeTraffic})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var itemMaps = []maps.Map{}
|
||||
for _, item := range itemsResp.NodePriceItems {
|
||||
var maxSize string
|
||||
if item.BitsTo == 0 {
|
||||
maxSize = "∞"
|
||||
} else {
|
||||
maxSize = numberutils.FormatBytes(item.BitsTo / 8)
|
||||
}
|
||||
|
||||
itemMaps = append(itemMaps, maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"minSize": numberutils.FormatBytes(item.BitsFrom / 8),
|
||||
"maxSize": maxSize,
|
||||
})
|
||||
}
|
||||
this.Data["items"] = itemMaps
|
||||
|
||||
// 所有区域
|
||||
regionsResp, err := this.RPC().NodeRegionRPC().FindAllAvailableNodeRegions(this.AdminContext(), &pb.FindAllAvailableNodeRegionsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var regionMaps = []maps.Map{}
|
||||
for _, region := range regionsResp.NodeRegions {
|
||||
pricesMap := map[string]float32{}
|
||||
if len(region.PricesJSON) > 0 {
|
||||
err = json.Unmarshal(region.PricesJSON, &pricesMap)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
regionMaps = append(regionMaps, maps.Map{
|
||||
"id": region.Id,
|
||||
"isOn": region.IsOn,
|
||||
"name": region.Name,
|
||||
"prices": pricesMap,
|
||||
})
|
||||
}
|
||||
this.Data["regions"] = regionMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user