lh hace 1 mes
padre
commit
cb169b1786
Se han modificado 2 ficheros con 37 adiciones y 18 borrados
  1. 6 2
      app/Services/DeepSeek/DeepSeekService.php
  2. 31 16
      app/Services/PointsStatsService.php

+ 6 - 2
app/Services/DeepSeek/DeepSeekService.php

@@ -526,11 +526,15 @@ class DeepSeekService
      */
     private function chargeChatSuccess(int $uid, int $tokens, array $chargeInfo): void
     {
+        // api_type 记录真实模型名(缺失时回退 deepseek 大类),保证明细与统计口径准确
+        $model = (string)getProp($chargeInfo, 'model', '');
         $result = $this->pointsService->recordChatCharge(
             $uid,
-            $this->pointsService->getChatChargePoints((string)getProp($chargeInfo, 'model', '')),
+            $this->pointsService->getChatChargePoints($model),
             $tokens,
-            $chargeInfo
+            $chargeInfo,
+            '',
+            $model !== '' ? $model : 'deepseek'
         );
         if (empty($result['charged'])) {
             throw new \Exception('AI对话计费失败: ' . (string)($result['reason'] ?? 'unknown'));

+ 31 - 16
app/Services/PointsStatsService.php

@@ -237,7 +237,9 @@ class PointsStatsService
     }
 
     /**
-     * 筛选项来源:用户/模型/中转站/日期范围。
+     * 筛选项来源:用户/模型/中转站/模型类型/日期范围。
+     *
+     * 选项统一为 {name: 显示名称, value: 传给后端的筛选值},前端展示 name、提交 value。
      */
     public function getFilters(array $params = []): array
     {
@@ -252,10 +254,13 @@ class PointsStatsService
             ->orderBy('id')
             ->get()
             ->map(function ($u) {
+                $name = (string)$u->nickname;
+                if ($name === '') {
+                    $name = (string)$u->account;
+                }
                 return [
-                    'id'       => (int)$u->id,
-                    'nickname' => (string)$u->nickname,
-                    'account'  => (string)$u->account,
+                    'name'  => $name,
+                    'value' => (int)$u->id,
                 ];
             })->all();
 
@@ -263,20 +268,30 @@ class PointsStatsService
         if ($cpid > 0) {
             $statsQuery->where('s.cpid', $cpid);
         }
-        $models = (clone $statsQuery)->distinct()->pluck('s.model')->values()->all();
-        $relays = (clone $statsQuery)->distinct()->pluck('s.relay')->values()->all();
-        $modelTypes = (clone $statsQuery)->distinct()->pluck('s.model_type')->values()->all();
-        $dateRange = (clone $statsQuery)->selectRaw('MIN(stat_date) AS min_date, MAX(stat_date) AS max_date')->first();
+        $models = (clone $statsQuery)->distinct()->orderBy('s.model')->pluck('s.model')->values()->map(function ($model) {
+            return ['name' => (string)$model, 'value' => (string)$model];
+        })->all();
+        $relays = (clone $statsQuery)->distinct()->orderBy('s.relay')->pluck('s.relay')->values()->map(function ($relay) {
+            return ['name' => (string)$relay, 'value' => (string)$relay];
+        })->all();
+        $modelTypes = (clone $statsQuery)->distinct()->pluck('s.model_type')->values()->map(function ($type) {
+            $labels = ['chat' => '文本', 'image' => '图片', 'video' => '视频'];
+            return [
+                'name'  => $labels[$type] ?? (string)$type,
+                'value' => (string)$type,
+            ];
+        })->all();
+        // $dateRange = (clone $statsQuery)->selectRaw('MIN(stat_date) AS min_date, MAX(stat_date) AS max_date')->first();
 
         return [
-            'users'      => $users,
-            'models'     => $models,
-            'relays'     => $relays,
-            'model_types'=> $modelTypes,
-            'date_range' => [
-                'min' => $dateRange->min_date ?? null,
-                'max' => $dateRange->max_date ?? null,
-            ],
+            'users'       => $users,
+            'models'      => $models,
+            'relays'      => $relays,
+            'model_types' => $modelTypes,
+            // 'date_range'  => [
+            //     'min' => $dateRange->min_date ?? null,
+            //     'max' => $dateRange->max_date ?? null,
+            // ],
         ];
     }