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 BandwidthAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *BandwidthAction) Init() {
|
||||
this.Nav("", "", "bandwidth")
|
||||
}
|
||||
|
||||
func (this *BandwidthAction) 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.PriceTypeBandwidth})
|
||||
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.FormatBits(item.BitsTo)
|
||||
}
|
||||
|
||||
itemMaps = append(itemMaps, maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"minSize": numberutils.FormatBits(item.BitsFrom),
|
||||
"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()
|
||||
}
|
||||
104
EdgeAdmin/internal/web/actions/default/finance/fee/calculator.go
Normal file
104
EdgeAdmin/internal/web/actions/default/finance/fee/calculator.go
Normal file
@@ -0,0 +1,104 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package fee
|
||||
|
||||
import (
|
||||
"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/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type CalculatorAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CalculatorAction) Init() {
|
||||
this.Nav("", "", "calculator")
|
||||
}
|
||||
|
||||
func (this *CalculatorAction) RunGet(params struct{}) {
|
||||
// 财务相关配置
|
||||
config, err := financeutils.ReadPriceConfig(this.AdminContext())
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["config"] = config
|
||||
|
||||
// 所有区域
|
||||
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
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CalculatorAction) RunPost(params struct {
|
||||
PriceType string
|
||||
|
||||
Traffic float64
|
||||
TrafficUnit string
|
||||
|
||||
Bandwidth float64
|
||||
BandwidthUnit string
|
||||
|
||||
RegionId int64
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
var trafficGB float64 = 0
|
||||
var bandwidthMB float64 = 0
|
||||
|
||||
switch params.PriceType {
|
||||
case userconfigs.PriceTypeTraffic:
|
||||
switch params.TrafficUnit {
|
||||
case "gb":
|
||||
trafficGB = params.Traffic
|
||||
case "tb":
|
||||
trafficGB = params.Traffic * (1 << 10)
|
||||
case "eb":
|
||||
trafficGB = params.Traffic * (1 << 20)
|
||||
}
|
||||
case userconfigs.PriceTypeBandwidth:
|
||||
switch params.BandwidthUnit {
|
||||
case "mb":
|
||||
bandwidthMB = params.Bandwidth
|
||||
case "gb":
|
||||
bandwidthMB = params.Bandwidth * (1 << 10)
|
||||
case "tb":
|
||||
bandwidthMB = params.Bandwidth * (1 << 20)
|
||||
}
|
||||
default:
|
||||
this.Fail("请选择正确的计费类型")
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := this.RPC().PriceRPC().CalculatePrice(this.AdminContext(), &pb.CalculatePriceRequest{
|
||||
PriceType: params.PriceType,
|
||||
TrafficGB: trafficGB,
|
||||
BandwidthMB: bandwidthMB,
|
||||
NodeRegionId: params.RegionId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["amount"] = resp.Amount
|
||||
this.Data["amountFormatted"] = numberutils.FormatFloat(resp.Amount, 2)
|
||||
this.Data["hasRegionPrice"] = resp.HasNodeRegionPrice
|
||||
this.Success()
|
||||
}
|
||||
188
EdgeAdmin/internal/web/actions/default/finance/fee/index.go
Normal file
188
EdgeAdmin/internal/web/actions/default/finance/fee/index.go
Normal file
@@ -0,0 +1,188 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package fee
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/finance/financeutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "basic")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
config, err := financeutils.ReadPriceConfig(this.AdminContext())
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["config"] = config
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
IsOn bool
|
||||
PriceType string
|
||||
PricePeriod string
|
||||
TrafficPriceJSON []byte
|
||||
BandwidthPriceJSON []byte
|
||||
UserCanChangePriceType bool
|
||||
UserCanChangePricePeriod bool
|
||||
EnablePlans bool
|
||||
ShowPlansInUserSystem bool
|
||||
EnableTrafficPackages bool
|
||||
ShowTrafficPackages bool
|
||||
UserUIShowPrices bool
|
||||
|
||||
UnpaidBillPolicyIsOn bool
|
||||
UnpaidBillPolicyMinDailyBillDays int32
|
||||
UnpaidBillPolicyMinMonthlyBillDays int32
|
||||
UnpaidBillPolicyDisableServers bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.FinanceFee_LogUpdateFeeSetting)
|
||||
|
||||
valueResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserPriceConfig})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var valueJSON = valueResp.ValueJSON
|
||||
var priceConfig = userconfigs.DefaultUserPriceConfig()
|
||||
if len(valueJSON) > 0 {
|
||||
err = json.Unmarshal(valueJSON, priceConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
priceConfig.IsOn = params.IsOn
|
||||
|
||||
if !userconfigs.IsValidPricePeriod(params.PricePeriod) {
|
||||
this.Fail("错误的结算周期 '" + params.PricePeriod + "'")
|
||||
return
|
||||
}
|
||||
priceConfig.DefaultPricePeriod = params.PricePeriod
|
||||
priceConfig.UserCanChangePriceType = params.UserCanChangePriceType
|
||||
priceConfig.UserCanChangePricePeriod = params.UserCanChangePricePeriod
|
||||
|
||||
priceConfig.EnablePlans = params.EnablePlans
|
||||
priceConfig.ShowPlansInUserSystem = params.ShowPlansInUserSystem
|
||||
|
||||
priceConfig.EnableTrafficPackages = params.EnableTrafficPackages
|
||||
priceConfig.ShowTrafficPackages = params.ShowTrafficPackages
|
||||
priceConfig.UserUI.ShowPrices = params.UserUIShowPrices
|
||||
|
||||
priceConfig.DefaultPriceType = params.PriceType
|
||||
|
||||
switch params.PriceType {
|
||||
case serverconfigs.PlanPriceTypeTraffic:
|
||||
if len(params.TrafficPriceJSON) == 0 {
|
||||
this.Fail("请设置流量价格")
|
||||
}
|
||||
case serverconfigs.PlanPriceTypeBandwidth:
|
||||
if len(params.BandwidthPriceJSON) == 0 {
|
||||
this.Fail("请设置带宽价格")
|
||||
}
|
||||
default:
|
||||
this.Fail("请选择默认计费方式")
|
||||
return
|
||||
}
|
||||
|
||||
// 流量价格
|
||||
if len(params.TrafficPriceJSON) > 0 {
|
||||
var config = &serverconfigs.PlanTrafficPriceConfig{}
|
||||
err := json.Unmarshal(params.TrafficPriceJSON, config)
|
||||
if err != nil {
|
||||
this.Fail("流量价格设置错误:" + err.Error())
|
||||
}
|
||||
|
||||
if params.PriceType == serverconfigs.PlanPriceTypeTraffic || params.UserCanChangePriceType {
|
||||
if config.Base <= 0 && len(config.Ranges) == 0 {
|
||||
this.Fail("流量基础价格和流量阶梯价格必须至少填写一个")
|
||||
}
|
||||
}
|
||||
priceConfig.DefaultTrafficPriceConfig = config
|
||||
}
|
||||
|
||||
// 带宽价格
|
||||
if len(params.BandwidthPriceJSON) > 0 {
|
||||
var config = &serverconfigs.PlanBandwidthPriceConfig{}
|
||||
err := json.Unmarshal(params.BandwidthPriceJSON, config)
|
||||
if err != nil {
|
||||
this.Fail("带宽价格设置错误:" + err.Error())
|
||||
}
|
||||
|
||||
if params.PriceType == serverconfigs.PlanPriceTypeBandwidth || params.UserCanChangePriceType {
|
||||
if config.Percentile <= 0 {
|
||||
this.Fail("带宽百分位必须大于0")
|
||||
}
|
||||
if config.Percentile > 100 {
|
||||
this.Fail("带宽百分位必须不大于100")
|
||||
}
|
||||
if config.Base <= 0 && len(config.Ranges) == 0 {
|
||||
this.Fail("带宽基础价格和带宽阶梯价格必须至少填写一个")
|
||||
}
|
||||
}
|
||||
priceConfig.DefaultBandwidthPriceConfig = config
|
||||
|
||||
// 同步修改UserUI中的用量统计设置
|
||||
uiConfig, err := configloaders.LoadUserUIConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if uiConfig != nil && uiConfig.TrafficStats.BandwidthAlgo != config.BandwidthAlgo {
|
||||
uiConfig.TrafficStats.BandwidthAlgo = config.BandwidthAlgo
|
||||
err = configloaders.UpdateUserUIConfig(uiConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 未支付账单策略
|
||||
priceConfig.UnpaidBillPolicy.IsOn = params.UnpaidBillPolicyIsOn
|
||||
priceConfig.UnpaidBillPolicy.MinDailyBillDays = params.UnpaidBillPolicyMinDailyBillDays
|
||||
priceConfig.UnpaidBillPolicy.MinMonthlyBillDays = params.UnpaidBillPolicyMinMonthlyBillDays
|
||||
priceConfig.UnpaidBillPolicy.DisableServers = params.UnpaidBillPolicyDisableServers
|
||||
|
||||
financeConfigJSON, err := json.Marshal(priceConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
|
||||
Code: systemconfigs.SettingCodeUserPriceConfig,
|
||||
ValueJSON: financeConfigJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 重置配置
|
||||
configloaders.ResetUserPriceConfig(priceConfig)
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//go:build plus
|
||||
|
||||
package items
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type CreateBandwidthPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreateBandwidthPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreateBandwidthPopupAction) RunGet(params struct {
|
||||
}) {
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreateBandwidthPopupAction) RunPost(params struct {
|
||||
Name string
|
||||
MinMB uint32
|
||||
MaxMB uint32
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入名称")
|
||||
|
||||
if params.MinMB > params.MaxMB {
|
||||
params.MinMB, params.MaxMB = params.MaxMB, params.MinMB
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().NodePriceItemRPC().CreateNodePriceItem(this.AdminContext(), &pb.CreateNodePriceItemRequest{
|
||||
Name: params.Name,
|
||||
Type: userconfigs.PriceTypeBandwidth,
|
||||
BitsFrom: int64(params.MinMB) << 20,
|
||||
BitsTo: int64(params.MaxMB) << 20,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
defer this.CreateLogInfo(codes.NodePriceItem_LogCreateNodePriceItemBandwidth, createResp.NodePriceItemId)
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//go:build plus
|
||||
|
||||
package items
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
type CreateTrafficPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CreateTrafficPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *CreateTrafficPopupAction) RunGet(params struct {
|
||||
}) {
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *CreateTrafficPopupAction) RunPost(params struct {
|
||||
Name string
|
||||
MinGB uint32
|
||||
MaxGB uint32
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入名称")
|
||||
|
||||
if params.MinGB > 0 && params.MaxGB > 0 && params.MinGB > params.MaxGB {
|
||||
params.MinGB, params.MaxGB = params.MaxGB, params.MinGB
|
||||
}
|
||||
|
||||
createResp, err := this.RPC().NodePriceItemRPC().CreateNodePriceItem(this.AdminContext(), &pb.CreateNodePriceItemRequest{
|
||||
Name: params.Name,
|
||||
Type: userconfigs.PriceTypeTraffic,
|
||||
BitsFrom: int64(params.MinGB) << 33,
|
||||
BitsTo: int64(params.MaxGB) << 33,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
defer this.CreateLogInfo(codes.NodePriceItem_LogCreateNodePriceItemTraffic, createResp.NodePriceItemId)
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//go:build plus
|
||||
|
||||
package items
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NodePriceItem_LogDeleteNodePriceItem, params.ItemId)
|
||||
|
||||
_, err := this.RPC().NodePriceItemRPC().DeleteNodePriceItem(this.AdminContext(), &pb.DeleteNodePriceItemRequest{NodePriceItemId: params.ItemId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//go:build plus
|
||||
|
||||
package items
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeFinance)).
|
||||
Data("teaMenu", "clusters").
|
||||
Data("teaSubMenu", "region").
|
||||
Prefix("/finance/fee/items").
|
||||
GetPost("/createTrafficPopup", new(CreateTrafficPopupAction)).
|
||||
GetPost("/updateTrafficPopup", new(UpdateTrafficPopupAction)).
|
||||
GetPost("/createBandwidthPopup", new(CreateBandwidthPopupAction)).
|
||||
GetPost("/updateBandwidthPopup", new(UpdateBandwidthPopupAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//go:build plus
|
||||
|
||||
package items
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdateBandwidthPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateBandwidthPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdateBandwidthPopupAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
itemResp, err := this.RPC().NodePriceItemRPC().FindEnabledNodePriceItem(this.AdminContext(), &pb.FindEnabledNodePriceItemRequest{NodePriceItemId: params.ItemId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var item = itemResp.NodePriceItem
|
||||
if item == nil {
|
||||
this.NotFound("nodePriceItem", params.ItemId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["item"] = maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"minMB": item.BitsFrom / (1 << 20),
|
||||
"maxMB": item.BitsTo / (1 << 20),
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateBandwidthPopupAction) RunPost(params struct {
|
||||
ItemId int64
|
||||
Name string
|
||||
MinMB uint32
|
||||
MaxMB uint32
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NodePriceItem_LogUpdateNodePriceItemBandwidth, params.ItemId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入名称")
|
||||
|
||||
if params.MinMB > 0 && params.MaxMB > 0 && params.MinMB > params.MaxMB {
|
||||
params.MinMB, params.MaxMB = params.MaxMB, params.MinMB
|
||||
}
|
||||
|
||||
_, err := this.RPC().NodePriceItemRPC().UpdateNodePriceItem(this.AdminContext(), &pb.UpdateNodePriceItemRequest{
|
||||
NodePriceItemId: params.ItemId,
|
||||
Name: params.Name,
|
||||
BitsFrom: int64(params.MinMB) << 20,
|
||||
BitsTo: int64(params.MaxMB) << 20,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//go:build plus
|
||||
|
||||
package items
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdateTrafficPopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateTrafficPopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdateTrafficPopupAction) RunGet(params struct {
|
||||
ItemId int64
|
||||
}) {
|
||||
itemResp, err := this.RPC().NodePriceItemRPC().FindEnabledNodePriceItem(this.AdminContext(), &pb.FindEnabledNodePriceItemRequest{NodePriceItemId: params.ItemId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var item = itemResp.NodePriceItem
|
||||
if item == nil {
|
||||
this.NotFound("nodePriceItem", params.ItemId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["item"] = maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"minGB": item.BitsFrom / (1 << 33),
|
||||
"maxGB": item.BitsTo / (1 << 33),
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateTrafficPopupAction) RunPost(params struct {
|
||||
ItemId int64
|
||||
Name string
|
||||
MinGB uint32
|
||||
MaxGB uint32
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NodePriceItem_LogUpdateNodePriceItemTraffic, params.ItemId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
Require("请输入名称")
|
||||
|
||||
if params.MinGB > 0 && params.MaxGB > 0 && params.MinGB > params.MaxGB {
|
||||
params.MinGB, params.MaxGB = params.MaxGB, params.MinGB
|
||||
}
|
||||
|
||||
_, err := this.RPC().NodePriceItemRPC().UpdateNodePriceItem(this.AdminContext(), &pb.UpdateNodePriceItemRequest{
|
||||
NodePriceItemId: params.ItemId,
|
||||
Name: params.Name,
|
||||
BitsFrom: int64(params.MinGB) << 33,
|
||||
BitsTo: int64(params.MaxGB) << 33,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
//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/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type UpdatePricePopupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdatePricePopupAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdatePricePopupAction) RunGet(params struct {
|
||||
RegionId int64
|
||||
ItemId int64
|
||||
}) {
|
||||
// 区域
|
||||
regionResp, err := this.RPC().NodeRegionRPC().FindEnabledNodeRegion(this.AdminContext(), &pb.FindEnabledNodeRegionRequest{NodeRegionId: params.RegionId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var region = regionResp.NodeRegion
|
||||
if region == nil {
|
||||
this.NotFound("nodeRegion", params.RegionId)
|
||||
return
|
||||
}
|
||||
this.Data["region"] = maps.Map{
|
||||
"id": region.Id,
|
||||
"isOn": region.IsOn,
|
||||
"name": region.Name,
|
||||
}
|
||||
|
||||
// 当前价格
|
||||
var pricesMap = map[string]float32{}
|
||||
if len(region.PricesJSON) > 0 {
|
||||
err = json.Unmarshal(region.PricesJSON, &pricesMap)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
this.Data["price"] = pricesMap[numberutils.FormatInt64(params.ItemId)]
|
||||
|
||||
// 价格项
|
||||
itemResp, err := this.RPC().NodePriceItemRPC().FindEnabledNodePriceItem(this.AdminContext(), &pb.FindEnabledNodePriceItemRequest{NodePriceItemId: params.ItemId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var item = itemResp.NodePriceItem
|
||||
if item == nil {
|
||||
this.NotFound("nodePriceItem", params.ItemId)
|
||||
return
|
||||
}
|
||||
|
||||
var minSize = ""
|
||||
var maxSize = ""
|
||||
|
||||
switch item.Type {
|
||||
case userconfigs.PriceTypeTraffic:
|
||||
minSize = numberutils.FormatBytes(item.BitsFrom / 8)
|
||||
if item.BitsTo > 0 {
|
||||
maxSize = numberutils.FormatBytes(item.BitsTo / 8)
|
||||
} else {
|
||||
maxSize = "∞"
|
||||
}
|
||||
case userconfigs.PriceTypeBandwidth:
|
||||
minSize = numberutils.FormatBits(item.BitsFrom)
|
||||
if item.BitsTo > 0 {
|
||||
maxSize = numberutils.FormatBits(item.BitsTo)
|
||||
} else {
|
||||
maxSize = "∞"
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["item"] = maps.Map{
|
||||
"id": item.Id,
|
||||
"name": item.Name,
|
||||
"type": item.Type,
|
||||
"minSize": minSize,
|
||||
"maxSize": maxSize,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdatePricePopupAction) RunPost(params struct {
|
||||
RegionId int64
|
||||
ItemId int64
|
||||
Price float32
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NodeRegionPrice_LogUpdateNodeRegionPrice, params.RegionId, params.ItemId)
|
||||
|
||||
_, err := this.RPC().NodeRegionRPC().UpdateNodeRegionPrice(this.AdminContext(), &pb.UpdateNodeRegionPriceRequest{
|
||||
NodeRegionId: params.RegionId,
|
||||
NodeItemId: params.ItemId,
|
||||
Price: params.Price,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user