1.4.5.2
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package packages
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type UpdatePricesPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePricesPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePricesPopupAction) RunGet(params struct {
|
||||
PackageId int64
|
||||
}) {
|
||||
packageResp, err := this.RPC().TrafficPackageRPC().FindTrafficPackage(this.AdminContext(), &pb.FindTrafficPackageRequest{
|
||||
TrafficPackageId: params.PackageId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var p = packageResp.TrafficPackage
|
||||
if p == nil {
|
||||
this.NotFound("trafficPackage", params.PackageId)
|
||||
return
|
||||
}
|
||||
this.Data["package"] = maps.Map{
|
||||
"id": p.Id,
|
||||
"size": p.Size,
|
||||
"unit": strings.ToUpper(p.Unit),
|
||||
}
|
||||
|
||||
// 所有区域
|
||||
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 {
|
||||
regionMaps = append(regionMaps, maps.Map{
|
||||
"id": region.Id,
|
||||
"name": region.Name,
|
||||
})
|
||||
}
|
||||
this.Data["regions"] = regionMaps
|
||||
|
||||
// 有效期
|
||||
periodsResp, err := this.RPC().TrafficPackagePeriodRPC().FindAllAvailableTrafficPackagePeriods(this.AdminContext(), &pb.FindAllAvailableTrafficPackagePeriodsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var periodMaps = []maps.Map{}
|
||||
for _, period := range periodsResp.TrafficPackagePeriods {
|
||||
periodMaps = append(periodMaps, maps.Map{
|
||||
"id": period.Id,
|
||||
"name": types.String(period.Count) + userconfigs.TrafficPackagePeriodUnitName(period.Unit),
|
||||
})
|
||||
}
|
||||
this.Data["periods"] = periodMaps
|
||||
|
||||
// 所有价格
|
||||
pricesResp, err := this.RPC().TrafficPackagePriceRPC().FindTrafficPackagePrices(this.AdminContext(), &pb.FindTrafficPackagePricesRequest{TrafficPackageId: params.PackageId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var priceMap = map[string]float64{} // regionId@periodId => price
|
||||
for _, price := range pricesResp.TrafficPackagePrices {
|
||||
priceMap[types.String(price.NodeRegionId)+"@"+types.String(price.TrafficPackagePeriodId)] = price.Price
|
||||
}
|
||||
|
||||
this.Data["prices"] = priceMap
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user