lh 1 день назад
Родитель
Сommit
1b7e43a593
1 измененных файлов с 28 добавлено и 3 удалено
  1. 28 3
      app/Services/DeepSeek/DeepSeekService.php

+ 28 - 3
app/Services/DeepSeek/DeepSeekService.php

@@ -596,7 +596,7 @@ class DeepSeekService
                 // 获取用户原始的prompt(不包含剧本内容)
                 $originalPrompt = getProp($data, 'prompt', '');
                 
-                $records = [
+                $recordsToInsert = [
                     [
                         'uid' => $uid,
                         'script_id' => $script_id,
@@ -617,9 +617,34 @@ class DeepSeekService
                     ]
                 ];
                 
-                DB::table('mp_script_records')->insert($records);
+                DB::table('mp_script_records')->insert($recordsToInsert);
+                
+                // 获取刚插入的记录ID(假设按插入顺序返回)
+                $insertedRecords = DB::table('mp_script_records')
+                    ->where('uid', $uid)
+                    ->where('script_id', $script_id)
+                    ->where('sequence', $sequence)
+                    ->orderBy('id', 'desc')
+                    ->limit(2)
+                    ->get()
+                    ->map(function ($record) {
+                        return [
+                            'rid' => $record->id,
+                            'script_id' => $record->script_id,
+                            'sequence' => $record->sequence,
+                            'role' => $record->role,
+                            'content' => $record->content,
+                            'created_at' => $record->created_at,
+                        ];
+                    })
+                    ->reverse()
+                    ->values()
+                    ->toArray();
+                
+                // 将记录信息添加到返回结果中
+                $aiResult['records'] = $insertedRecords;
                 
-                dLog('deepseek')->info('保存剧本对话记录成功', ['script_id' => $script_id, 'sequence' => $sequence]);
+                dLog('deepseek')->info('保存剧本对话记录成功', ['script_id' => $script_id, 'sequence' => $sequence, 'record_ids' => array_column($insertedRecords, 'rid')]);
             } catch (\Exception $e) {
                 // 记录错误但不影响主流程
                 dLog('deepseek')->error('保存剧本对话记录失败: ' . $e->getMessage());