diff --git a/controller/channel_pricing.go b/controller/channel_pricing.go index 5e9d456..9768e70 100644 --- a/controller/channel_pricing.go +++ b/controller/channel_pricing.go @@ -365,16 +365,7 @@ func GetChannelPricingWithTags(c *gin.Context) { for _, cp := range list { item := &ChannelPricingWithTags{ ChannelPricing: cp, - Tags: make([]*model.PricingTag, 0), - } - if cp.TagIds != "" { - for _, idStr := range strings.Split(cp.TagIds, ",") { - if id, err := strconv.Atoi(idStr); err == nil { - if tag, ok := tagMap[id]; ok { - item.Tags = append(item.Tags, tag) - } - } - } + Tags: model.ParseTagIds(cp.TagIds, tagMap), } result = append(result, item) } diff --git a/model/channel_pricing.go b/model/channel_pricing.go index a5280fb..9a5c05d 100644 --- a/model/channel_pricing.go +++ b/model/channel_pricing.go @@ -172,6 +172,22 @@ func GetEffectivePricing(modelName string, channelId int) (*ChannelPricing, bool return cp, true } +// ParseTagIds 解析逗号分隔的标签ID字符串为 PricingTag 切片 +func ParseTagIds(tagIds string, tagMap map[int]*PricingTag) []*PricingTag { + if tagIds == "" { + return nil + } + tags := make([]*PricingTag, 0) + for _, idStr := range strings.Split(tagIds, ",") { + if id, err := strconv.Atoi(strings.TrimSpace(idStr)); err == nil { + if tag, ok := tagMap[id]; ok { + tags = append(tags, tag) + } + } + } + return tags +} + // LoadChannelPricingCache 全量加载渠道定价到内存(启动时调用) func LoadChannelPricingCache() { var pricings []*ChannelPricing @@ -234,8 +250,6 @@ func GetChannelPricingByModelWithChannelInfo(modelName string) ([]*ChannelPricin if !hasPrice { globalModelPrice = 0 } - - // 获取全局扩展比率(用于 CASE WHEN 回退) globalCacheRatio, _ := ratio_setting.GetCacheRatio(modelName) globalCacheCreationRatio, _ := ratio_setting.GetCreateCacheRatio(modelName) @@ -283,16 +297,7 @@ func GetChannelPricingByModelWithChannelInfo(modelName string) ([]*ChannelPricin // 为每个渠道定价填充标签 for _, result := range results { - if result.TagIds != "" { - result.Tags = make([]*PricingTag, 0) - for _, idStr := range strings.Split(result.TagIds, ",") { - if id, err := strconv.Atoi(strings.TrimSpace(idStr)); err == nil { - if tag, ok := tagMap[id]; ok { - result.Tags = append(result.Tags, tag) - } - } - } - } + result.Tags = ParseTagIds(result.TagIds, tagMap) } return results, nil diff --git a/web/src/pages/Setting/Ratio/ChannelPricingView.jsx b/web/src/pages/Setting/Ratio/ChannelPricingView.jsx index f097bc9..cd09e3e 100644 --- a/web/src/pages/Setting/Ratio/ChannelPricingView.jsx +++ b/web/src/pages/Setting/Ratio/ChannelPricingView.jsx @@ -463,7 +463,6 @@ const ChannelPricingView = ({ channels, channelPricings, tags, onRefresh }) => { rowKey="modelName" expandedRowKeys={expandedRowKeys} onExpandedRowsChange={(keys) => { - console.log('Expanded keys:', keys); setExpandedRowKeys(keys); }} expandedRowRender={expandedRowRender}