Version: 0.9.81.dev.260506

后端:
1. Credit 价格规则补齐利润率与实际计费单价语义:新增 `profit_rate_bps` 与 `charge_*_price_micros` 展示字段,下沉共享价格推导 helper,tokenstore rpc/client/proto/model/default rule 全链路同步,LLM usage 扣费统一改按加价后的 charge 单价换算。
2. task-class 更新链路修正全量覆盖与归属校验:`runtime/conv` 保留 item id,DAO 更新前显式校验 task-class 与 item 归属,改用显式字段 map 落库 nil/空切片/零值,避免 `RowsAffected=0` 误判越权,同时补齐任务项可编辑字段更新。
3. GormCache task-class 失效补空 user_id 保护:更新语句缺少模型上下文时直接跳过失效,避免缓存插件因空指针影响主事务。

前端:
4. 课表中心补齐任务类编辑能力:新增 `updateTaskClass` API,创建弹窗支持编辑态回填与 item id 提交,日程页支持先拉详情再编辑并在保存后刷新任务类详情与列表。
5. 计划广场详情补点赞交互与奖励提示:详情页新增点赞/取消点赞按钮、奖励反馈文案与计数展示,论坛类型补 `reward_hint`,评论区与帖子作者头像统一接入兜底头像工具。
6. 品牌与展示细节收口:侧边栏与 favicon 切到项目 logo,首页标题改为 `SmartMate`,主面板缩放上限微调,论坛列表头像显示与整体品牌观感同步统一。
This commit is contained in:
Losita
2026-05-06 21:53:17 +08:00
parent 61db646805
commit 7b04b073ce
25 changed files with 594 additions and 123 deletions

View File

@@ -0,0 +1,57 @@
package creditstore
const (
// ProfitRateScaleBPS 表示利润率的基点精度10000 = 100%。
ProfitRateScaleBPS = int64(10_000)
)
// ChargePriceMicrosSet 表示在“原始 CNY 成本 + 利润率”之后得到的实际计费单价。
type ChargePriceMicrosSet struct {
InputChargePriceMicros int64
OutputChargePriceMicros int64
CachedChargePriceMicros int64
ReasoningChargePriceMicros int64
}
// DeriveChargePriceMicrosSet 负责把一条价格规则里的原始 CNY 成本推导成实际计费用单价。
//
// 职责边界:
// 1. 这里只处理“原始成本 + 利润率”的价格推导,不负责 token 数量聚合与 credit 折算。
// 2. cached/reasoning 仍复用现有兜底语义:未配置时分别退回 input/output 单价。
// 3. 若利润率配置为负且绝对值过大导致结果 <= 0则统一按 0 处理,避免落出负价格。
func DeriveChargePriceMicrosSet(inputPriceMicros, outputPriceMicros, cachedPriceMicros, reasoningPriceMicros, profitRateBps int64) ChargePriceMicrosSet {
if cachedPriceMicros <= 0 {
cachedPriceMicros = inputPriceMicros
}
if reasoningPriceMicros <= 0 {
reasoningPriceMicros = outputPriceMicros
}
return ChargePriceMicrosSet{
InputChargePriceMicros: ApplyProfitRateToPriceMicros(inputPriceMicros, profitRateBps),
OutputChargePriceMicros: ApplyProfitRateToPriceMicros(outputPriceMicros, profitRateBps),
CachedChargePriceMicros: ApplyProfitRateToPriceMicros(cachedPriceMicros, profitRateBps),
ReasoningChargePriceMicros: ApplyProfitRateToPriceMicros(reasoningPriceMicros, profitRateBps),
}
}
// ApplyProfitRateToPriceMicros 负责把“成本单价”按利润率转换成“实际计费单价”。
func ApplyProfitRateToPriceMicros(priceMicros int64, profitRateBps int64) int64 {
if priceMicros <= 0 {
return 0
}
scaledRate := ProfitRateScaleBPS + profitRateBps
if scaledRate <= 0 {
return 0
}
return ceilDivInt64(priceMicros*scaledRate, ProfitRateScaleBPS)
}
func ceilDivInt64(numerator int64, denominator int64) int64 {
if numerator <= 0 || denominator <= 0 {
return 0
}
return (numerator + denominator - 1) / denominator
}

View File

@@ -93,19 +93,30 @@ type CreditConsumptionDashboardView struct {
}
// CreditPriceRuleView 是 Credit 计价规则展示结构。
//
// 字段语义说明:
// 1. InputPriceMicros / OutputPriceMicros / CachedPriceMicros / ReasoningPriceMicros
// 表示原始 CNY 成本单价,方便管理端直接维护模型底价。
// 2. Charge*PriceMicros 表示后端按利润率自动推导出来的实际计费单价,
// LLM 扣费时会使用这一组价格继续换算 credit。
type CreditPriceRuleView struct {
RuleID uint64 `json:"rule_id"`
Scene string `json:"scene"`
ProviderName string `json:"provider_name"`
ModelName string `json:"model_name"`
InputPriceMicros int64 `json:"input_price_micros"`
OutputPriceMicros int64 `json:"output_price_micros"`
CachedPriceMicros int64 `json:"cached_price_micros"`
ReasoningPriceMicros int64 `json:"reasoning_price_micros"`
CreditPerYuan int64 `json:"credit_per_yuan"`
Status string `json:"status"`
Priority int `json:"priority"`
Description string `json:"description"`
RuleID uint64 `json:"rule_id"`
Scene string `json:"scene"`
ProviderName string `json:"provider_name"`
ModelName string `json:"model_name"`
InputPriceMicros int64 `json:"input_price_micros"`
OutputPriceMicros int64 `json:"output_price_micros"`
CachedPriceMicros int64 `json:"cached_price_micros"`
ReasoningPriceMicros int64 `json:"reasoning_price_micros"`
CreditPerYuan int64 `json:"credit_per_yuan"`
ProfitRateBps int64 `json:"profit_rate_bps"`
ChargeInputPriceMicros int64 `json:"charge_input_price_micros"`
ChargeOutputPriceMicros int64 `json:"charge_output_price_micros"`
ChargeCachedPriceMicros int64 `json:"charge_cached_price_micros"`
ChargeReasoningPriceMicros int64 `json:"charge_reasoning_price_micros"`
Status string `json:"status"`
Priority int `json:"priority"`
Description string `json:"description"`
}
// CreditRewardRuleView 是 Credit 奖励规则展示结构。

View File

@@ -69,6 +69,13 @@ func (p *GormCachePlugin) dispatchCacheLogic(modelObj interface{}) {
case model.Schedule:
p.invalidScheduleCache(m.UserID, m.Week)
case model.TaskClass:
// 1. update 场景若只用 Model(&model.TaskClass{}) 构造 SQL插件拿到的模型实例里 UserID 可能为空。
// 2. 这类情况下缓存插件不能影响主事务,更不能因为取缓存键时解引用空指针把服务打崩。
// 3. 若确实缺少 UserID则直接跳过本次失效由调用方补齐 Model 上下文或后续重读兜底。
if m.UserID == nil {
log.Printf("[GORM-Cache] Skip task class cache invalidation because UserID is nil")
return
}
p.invalidTaskClassCache(*m.UserID)
case model.Task:
p.invalidTaskCache(m.UserID)