feat(models): 模型目录与计费 - 按展示名分组并隔离管理员积分成本

This commit is contained in:
ddCat committed 2026-09-19 09:54:27 +08:00
1 parent 5ad05efb58
commit 237f2e2a6e
49 files changed
+802 -276

No files matched your search

@@ -278,7 +278,7 @@ func (r *Repository) RouteAttempts(taskID string, routeRun int) ([]model.RouteAt
// SwitchTaskLogicalRoute 同时更新任务执行目标和账单。跟随供应价格时会原子调整预留积分,
// 保证明确未创建上游任务后的故障切线不会沿用上一条线路的价格快照。
func (r *Repository) SwitchTaskLogicalRoute(taskID string, expectedRouteID string, routeID string, inputJSON string, billingOrderID string, channelID string, channelModelID string, replacement *model.BillingOrder) error {
func (r *Repository) SwitchTaskLogicalRoute(taskID string, expectedRouteID string, routeID string, inputJSON string, billingOrderID string, channelID string, channelModelID string, replacement *model.BillingOrder, cost model.BillingCostSnapshot) error {
return r.db.Transaction(func(tx *gorm.DB) error {
updated := tx.Model(&model.Task{}).
Where("id = ? AND status = ? AND route_id = ?", taskID, model.TaskStatusRunning, expectedRouteID).
@@ -298,6 +298,14 @@ func (r *Repository) SwitchTaskLogicalRoute(taskID string, expectedRouteID strin
}
now := time.Now()
updates := map[string]any{"channel_id": channelID, "channel_model_id": channelModelID, "updated_at": now}
updates["cost_configured"] = cost.CostPricing.Configured
updates["cost_unit_price_microcredits"] = cost.CostPricing.UnitPriceMicrocredits
updates["cost_input_token_price_microcredits"] = cost.CostPricing.InputTokenPriceMicrocredits
updates["cost_output_token_price_microcredits"] = cost.CostPricing.OutputTokenPriceMicrocredits
updates["cost_cached_token_price_microcredits"] = cost.CostPricing.CachedTokenPriceMicrocredits
updates["cost_billing_mode"] = cost.CostBillingMode
updates["cost_quantity"] = cost.CostQuantity
updates["cost_video_formula_tokens"] = cost.CostVideoFormulaTokens
if replacement != nil {
if replacement.UserID != order.UserID || replacement.TaskID != taskID || replacement.AmountMicrocredits <= 0 {
return ErrBillingStateConflict