|
|
@@ -956,80 +956,74 @@ class DeepSeekService
|
|
|
}
|
|
|
|
|
|
// 处理结果
|
|
|
+ if ($content) {
|
|
|
+ $script_arr = handleScriptContent($content);
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'script' => $script_arr,
|
|
|
+ 'answer' => $content,
|
|
|
+ 'usage' => $usage
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function saveScript($data) {
|
|
|
+ $script_arr =getProp($data, 'script', []);
|
|
|
+ if (!$script_arr) Utils::throwError('20003:剧本内容不能为空');
|
|
|
+ $start_episode_sequence = getProp($data, 'start_episode_sequence', 1);
|
|
|
+ $script_id = getProp($data, 'script_id');
|
|
|
+ if (!$script_id) Utils::throwError('20003:剧本ID不能为空');
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
- if ($content) {
|
|
|
- $script_arr = handleScriptContent($content);
|
|
|
- // dd($script_arr);
|
|
|
- $update_data = [
|
|
|
- 'intro' => isset($script_arr['intro']) ? $script_arr['intro'] : '',
|
|
|
- 'highlights' => isset($script_arr['highlights']) ? $script_arr['highlights'] : '',
|
|
|
- 'role_relationship' => isset($script_arr['role_relationship']) ? $script_arr['role_relationship'] : '',
|
|
|
- 'core_contradiction' => isset($script_arr['core_contradiction']) ? $script_arr['core_contradiction'] : '',
|
|
|
- 'roles' => isset($script_arr['roles']) ? $script_arr['roles'] : '',
|
|
|
- 'art_style' => isset($script_arr['art_style']) ? $script_arr['art_style'] : '',
|
|
|
- 'scenes' => isset($script_arr['scenes']) ? $script_arr['scenes'] : '',
|
|
|
- 'status' => 3,
|
|
|
- 'start_episode_sequence' => $start_episode_sequence,
|
|
|
- 'end_episode_sequence' => $start_episode_sequence + count($script_arr['episodes']) - 1,
|
|
|
- 'episode_num' => count($script_arr['episodes']),
|
|
|
+ $update_data = [
|
|
|
+ 'intro' => isset($script_arr['intro']) ? $script_arr['intro'] : '',
|
|
|
+ 'highlights' => isset($script_arr['highlights']) ? $script_arr['highlights'] : '',
|
|
|
+ 'role_relationship' => isset($script_arr['role_relationship']) ? $script_arr['role_relationship'] : '',
|
|
|
+ 'core_contradiction' => isset($script_arr['core_contradiction']) ? $script_arr['core_contradiction'] : '',
|
|
|
+ 'roles' => isset($script_arr['roles']) ? $script_arr['roles'] : '',
|
|
|
+ 'art_style' => isset($script_arr['art_style']) ? $script_arr['art_style'] : '',
|
|
|
+ 'scenes' => isset($script_arr['scenes']) ? $script_arr['scenes'] : '',
|
|
|
+ 'status' => 3,
|
|
|
+ 'start_episode_sequence' => $start_episode_sequence,
|
|
|
+ 'end_episode_sequence' => $start_episode_sequence + count($script_arr['episodes']) - 1,
|
|
|
+ 'episode_num' => count($script_arr['episodes']),
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ];
|
|
|
+ // 保存剧本内容
|
|
|
+ $boolen = DB::table('mp_scripts')->where('id', $script_id)->update($update_data);
|
|
|
+ if (!$boolen) {
|
|
|
+ dLog('deepseek')->info('剧本内容保存失败', $update_data);
|
|
|
+ Utils::throwError('20003:剧本内容保存失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存分集内容
|
|
|
+ // 删除历史分集内容
|
|
|
+ $boolen1 = DB::table('mp_script_episodes')->where('script_id', $script_id)->delete();
|
|
|
+
|
|
|
+ $episodes = [];
|
|
|
+ foreach ($script_arr['episodes'] as $episode) {
|
|
|
+ $episodes[] = [
|
|
|
+ 'script_id' => $script_id,
|
|
|
+ 'episode_number' => $episode['episode_number'],
|
|
|
+ 'title' => $episode['title'],
|
|
|
+ 'content' => $episode['content'],
|
|
|
+ 'created_at' => date('Y-m-d H:i:s'),
|
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
|
];
|
|
|
- // 保存剧本内容
|
|
|
- $boolen = DB::table('mp_scripts')->where('id', $script_id)->update($update_data);
|
|
|
- if (!$boolen) {
|
|
|
- dLog('deepseek')->info('剧本内容保存失败', $update_data);
|
|
|
- Utils::throwError('20003:剧本内容保存失败');
|
|
|
- }
|
|
|
-
|
|
|
- // 保存分集内容
|
|
|
- // 删除历史分集内容
|
|
|
- $boolen1 = DB::table('mp_script_episodes')->where('script_id', $script_id)->delete();
|
|
|
-
|
|
|
- $episodes = [];
|
|
|
- foreach ($script_arr['episodes'] as $episode) {
|
|
|
- $episodes[] = [
|
|
|
- 'script_id' => $script_id,
|
|
|
- 'episode_number' => $episode['episode_number'],
|
|
|
- 'title' => $episode['title'],
|
|
|
- 'content' => $episode['content'],
|
|
|
- 'created_at' => date('Y-m-d H:i:s'),
|
|
|
- 'updated_at' => date('Y-m-d H:i:s')
|
|
|
- ];
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- $boolen2 = DB::table('mp_script_episodes')->insert($episodes);
|
|
|
- if (!$boolen2) {
|
|
|
- dLog('deepseek')->info('分集内容保存失败', $episodes);
|
|
|
- Utils::throwError('20003:分集内容保存失败');
|
|
|
- }
|
|
|
- }else{
|
|
|
- $boolen = DB::table('mp_scripts')->where('id', $script_id)->update([
|
|
|
- 'status' => 4,
|
|
|
- 'updated_at' => date('Y-m-d H:i:s')
|
|
|
- ]);
|
|
|
- if (!$boolen) {
|
|
|
- dLog('deepseek')->info('剧本状态更新失败', ['script_id' => $script_id]);
|
|
|
- Utils::throwError('20003:剧本状态更新失败');
|
|
|
- }
|
|
|
+ $boolen2 = DB::table('mp_script_episodes')->insert($episodes);
|
|
|
+ if (!$boolen2) {
|
|
|
+ dLog('deepseek')->info('分集内容保存失败', $episodes);
|
|
|
+ Utils::throwError('20003:分集内容保存失败');
|
|
|
}
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
DB::rollBack();
|
|
|
Utils::throwError('20003:'.$e->getMessage());
|
|
|
}
|
|
|
-
|
|
|
DB::commit();
|
|
|
-
|
|
|
- return [
|
|
|
- 'script' => $script_arr,
|
|
|
- 'answer' => $content,
|
|
|
- 'usage' => $usage
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- public function generateScript($data) {
|
|
|
-
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
|