Files
waf-platform/EdgeUser/internal/web/actions/default/servers/fee/index.go
2026-02-04 20:27:13 +08:00

71 lines
1.9 KiB
Go

// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package fee
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
"github.com/TeaOSLab/EdgeUser/internal/configloaders"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "index")
}
func (this *IndexAction) RunGet(params struct{}) {
config, err := configloaders.LoadCacheableUserPriceConfig()
if err != nil {
this.ErrorPage(err)
return
}
if config == nil || !config.IsOn {
this.WriteString("管理员未开启此配置")
return
}
this.Data["showPrices"] = config.UserUI.ShowPrices
// 配置
// 仅显示有限的配置,防止信息泄露
var priceType = config.DefaultPriceType
var pricePeriod = config.DefaultPricePeriod
priceInfoResp, err := this.RPC().UserRPC().FindUserPriceInfo(this.UserContext(), &pb.FindUserPriceInfoRequest{UserId: this.UserId()})
if err != nil {
this.ErrorPage(err)
return
}
// 计费方式
if config.UserCanChangePriceType {
if len(priceInfoResp.PriceType) > 0 && userconfigs.IsValidPriceType(priceInfoResp.PriceType) {
priceType = priceInfoResp.PriceType
}
}
// 计费周期
if config.UserCanChangePricePeriod {
if len(priceInfoResp.PricePeriod) > 0 && userconfigs.IsValidPricePeriod(priceInfoResp.PricePeriod) {
pricePeriod = priceInfoResp.PricePeriod
}
}
this.Data["config"] = maps.Map{
"priceType": priceType,
"priceTypeName": userconfigs.PriceTypeName(priceType),
"pricePeriod": pricePeriod,
"pricePeriodName": userconfigs.PricePeriodName(pricePeriod),
"canChangeType": config.UserCanChangePriceType,
"canChangePeriod": config.UserCanChangePricePeriod,
}
this.Show()
}