1.4.5.2
This commit is contained in:
110
EdgeCommon/pkg/userconfigs/user_price_config_plus.go
Normal file
110
EdgeCommon/pkg/userconfigs/user_price_config_plus.go
Normal file
@@ -0,0 +1,110 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package userconfigs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
|
||||
type PriceType = string
|
||||
|
||||
const (
|
||||
PriceTypeTraffic PriceType = "traffic" // 按流量
|
||||
PriceTypeBandwidth PriceType = "bandwidth" // 按带宽
|
||||
PriceTypePeriod PriceType = "period" // 按周期
|
||||
PriceTypePlan PriceType = "plan" // 套餐
|
||||
)
|
||||
|
||||
func IsValidPriceType(priceType string) bool {
|
||||
return priceType == PriceTypeTraffic ||
|
||||
priceType == PriceTypeBandwidth ||
|
||||
priceType == PriceTypePeriod ||
|
||||
priceType == PriceTypePlan
|
||||
}
|
||||
|
||||
func PriceTypeName(priceType PriceType) string {
|
||||
switch priceType {
|
||||
case PriceTypeTraffic:
|
||||
return "按流量"
|
||||
case PriceTypeBandwidth:
|
||||
return "按带宽"
|
||||
case PriceTypePeriod:
|
||||
return "按周期"
|
||||
case PriceTypePlan:
|
||||
return "按套餐"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// UserPriceConfig 计费相关设置
|
||||
type UserPriceConfig struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||
|
||||
EnablePlans bool `yaml:"enablePlans" json:"enablePlans"` // 是否使用套餐
|
||||
ShowPlansInUserSystem bool `yaml:"showPlansInUserSystem" json:"showPlansInUserSystem"` // 是否在用户系统显示套餐
|
||||
|
||||
EnableTrafficPackages bool `yaml:"enableTrafficPackages" json:"enableTrafficPackages"` // 是否可以使用流量包
|
||||
ShowTrafficPackages bool `yaml:"showTrafficPackages" json:"showTrafficPackages"` // 在用户界面显示流量包
|
||||
MaxTrafficPackagesInOrder int32 `yaml:"maxTrafficPackagesInOrder" json:"maxTrafficPackagesInOrder"` // 单次订单能购买的流量包数量 TODO 暂时不实现
|
||||
|
||||
DefaultPriceType PriceType `yaml:"priceType" json:"priceType"` // 默认计费方式
|
||||
DefaultPricePeriod string `yaml:"pricePeriod" json:"pricePeriod"` // 默认计费周期
|
||||
UserCanChangePriceType bool `yaml:"userCanChangePriceType" json:"userCanChangePriceType"` // 用户是否可以自定义计费方式
|
||||
UserCanChangePricePeriod bool `yaml:"userCanChangePricePeriod" json:"userCanChangePricePeriod"` // 用户可以自定义计费周期
|
||||
|
||||
DefaultTrafficPriceConfig *serverconfigs.PlanTrafficPriceConfig `yaml:"trafficPrice" json:"trafficPrice"` // 默认流量价格
|
||||
DefaultBandwidthPriceConfig *serverconfigs.PlanBandwidthPriceConfig `yaml:"bandwidthPrice" json:"bandwidthPrice"` // 默认带宽价格
|
||||
|
||||
UnpaidBillPolicy struct { // 未支付账单策略
|
||||
IsOn bool `json:"isOn"` // 是否启用
|
||||
MinDailyBillDays int32 `json:"minDailyBillDays"` // 日账单:允许未支付的最大天数
|
||||
MinMonthlyBillDays int32 `json:"minMonthlyBillDays"` // 月账单:允许未支付的最大天数
|
||||
DisableServers bool `json:"disableServers"` // 是否停止服务运行
|
||||
} `json:"unpaidBillPolicy"`
|
||||
|
||||
UserUI struct {
|
||||
ShowPrices bool `yaml:"showPrices" json:"showPrices"` // 显示价格和价格计算器
|
||||
} `yaml:"userUI" json:"userUI"` // 用户界面相关配置
|
||||
}
|
||||
|
||||
func (this *UserPriceConfig) Clone() (*UserPriceConfig, error) {
|
||||
jsonBytes, err := json.Marshal(this)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var config = &UserPriceConfig{}
|
||||
err = json.Unmarshal(jsonBytes, config)
|
||||
return config, err
|
||||
}
|
||||
|
||||
func DefaultUserPriceConfig() *UserPriceConfig {
|
||||
return &UserPriceConfig{
|
||||
DefaultPriceType: PriceTypeBandwidth,
|
||||
DefaultPricePeriod: PricePeriodMonthly,
|
||||
ShowPlansInUserSystem: true,
|
||||
}
|
||||
}
|
||||
|
||||
type PricePeriod = string
|
||||
|
||||
const (
|
||||
PricePeriodDaily PricePeriod = "daily" // 日结
|
||||
PricePeriodMonthly PricePeriod = "monthly" // 月结
|
||||
)
|
||||
|
||||
func IsValidPricePeriod(period string) bool {
|
||||
return period == PricePeriodDaily || period == PricePeriodMonthly
|
||||
}
|
||||
|
||||
func PricePeriodName(period PricePeriod) string {
|
||||
switch period {
|
||||
case PricePeriodDaily:
|
||||
return "按日"
|
||||
case PricePeriodMonthly:
|
||||
return "按月"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user