Files

49 lines
1.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package entity
import (
pricingConsts "shop-user-trade/consts/pricing"
"gitea.redpowerfuture.com/red-future/common/beans"
)
type pricingConfigCol struct {
beans.SQLBaseCol
SubjectType string
SubjectID string
Rules string
MinBalance string
Currency string
Enabled string
}
var PricingConfigCol = pricingConfigCol{
SQLBaseCol: beans.DefSQLBaseCol,
SubjectType: "subject_type",
SubjectID: "subject_id",
Rules: "rules",
MinBalance: "min_balance",
Currency: "currency",
Enabled: "enabled",
}
// PricingConfig 计价配置实体(费率全 DB 配置,改价/加档只改 rules,代码不写死金额)
type PricingConfig struct {
beans.SQLBaseDO `orm:",inherit"`
SubjectType pricingConsts.SubjectType `orm:"subject_type" json:"subjectType" description:"计价对象类型:workflow/model/business"`
SubjectID string `orm:"subject_id" json:"subjectId" description:"计价对象IDworkflow/模型ID/业务模块标识)"`
Rules map[string]any `orm:"rules" json:"rules" description:"费率JSON对象(见设计§4rules 自描述不再有 charge_mode 列)"`
MinBalance float64 `orm:"min_balance" json:"minBalance" description:"门禁:调用前可用余额须>=该值(元),0=不校验"`
Currency string `orm:"currency" json:"currency" description:"货币类型"`
Enabled int `orm:"enabled" json:"enabled" description:"1启用 0停用"`
}
// Unit 从 rules 中解析模型计费单位(仅 subject_type=model 有效,其余返回空)。
// service 层 per_token 结算/建单解析计费方式时使用,避免重复解析 rules。
func (e *PricingConfig) Unit() pricingConsts.ChargeMode {
if unit, ok := e.Rules["unit"].(string); ok {
return pricingConsts.ChargeMode(unit)
}
return ""
}