feat(payment): add payment settings configuration and update payment methods handling

This commit is contained in:
CaIon
2025-09-12 19:11:17 +08:00
parent 04cc668430
commit d8410d2f11
20 changed files with 655 additions and 275 deletions

View File

@@ -0,0 +1,23 @@
package operation_setting
import "one-api/setting/config"
type PaymentSetting struct {
AmountOptions []int `json:"amount_options"`
AmountDiscount map[int]float64 `json:"amount_discount"` // 充值金额对应的折扣,例如 100 元 0.9 表示 100 元充值享受 9 折优惠
}
// 默认配置
var paymentSetting = PaymentSetting{
AmountOptions: []int{10, 20, 50, 100, 200, 500},
AmountDiscount: map[int]float64{},
}
func init() {
// 注册到全局配置管理器
config.GlobalConfig.Register("payment_setting", &paymentSetting)
}
func GetPaymentSetting() *PaymentSetting {
return &paymentSetting
}

View File

@@ -1,6 +1,13 @@
package setting
/**
此文件为旧版支付设置文件如需增加新的参数变量等请在 payment_setting.go 中添加
This file is the old version of the payment settings file. If you need to add new parameters, variables, etc., please add them in payment_setting.go
*/
import "encoding/json"
package operation_setting
import (
"one-api/common"
)
var PayAddress = ""
var CustomCallbackAddress = ""
@@ -21,15 +28,21 @@ var PayMethods = []map[string]string{
"color": "rgba(var(--semi-green-5), 1)",
"type": "wxpay",
},
{
"name": "自定义1",
"color": "black",
"type": "custom1",
"min_topup": "50",
},
}
func UpdatePayMethodsByJsonString(jsonString string) error {
PayMethods = make([]map[string]string, 0)
return json.Unmarshal([]byte(jsonString), &PayMethods)
return common.Unmarshal([]byte(jsonString), &PayMethods)
}
func PayMethods2JsonString() string {
jsonBytes, err := json.Marshal(PayMethods)
jsonBytes, err := common.Marshal(PayMethods)
if err != nil {
return "[]"
}