Преглед изворни кода

调整新建和编辑产品接口

lh пре 1 месец
родитељ
комит
e207d7e72f
2 измењених фајлова са 97 додато и 62 уклоњено
  1. 62 52
      app/Services/Anime/AnimeService.php
  2. 35 10
      app/Services/DeepSeek/DeepSeekService.php

+ 62 - 52
app/Services/Anime/AnimeService.php

@@ -114,6 +114,7 @@ class AnimeService
                 $acts[$actNumber] = [
                     'act_number' => $actNumber,
                     'act_title' => getProp($segment, 'act_title'),
+                    'act_duration' => getProp($segment, 'act_duration'),
                     'segments' => [$segmentInfo]
                 ];
             }
@@ -4328,6 +4329,7 @@ class AnimeService
      */
     public function globalProducts($data) {
         $cpid = Site::getCpid();
+        $id = getProp($data, 'id', 0);
         $parent_id = getProp($data, 'parent_id', 0);
         $product_name = getProp($data, 'product_name');
         $product = getProp($data, 'product'); // 1.角色 2.场景 3.道具
@@ -4336,7 +4338,7 @@ class AnimeService
         }
         
         // 如果有搜索关键词,只搜索角色图片
-        if ($product_name) {
+        if ($id) {
             $query = DB::table('mp_products')
                 ->where('cpid', $cpid)
                 ->where('is_deleted', 0)
@@ -4756,6 +4758,7 @@ class AnimeService
         if (!$product_name) Utils::throwError('20003:名称不能为空');
         $url = trim(getProp($data, 'url'));
         if (!$url) Utils::throwError('20003:图片地址不能为空');
+        $versions = getProp($data, 'versions');
         
         // 检查是否是正确的图片格式
         $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'];
@@ -4803,6 +4806,7 @@ class AnimeService
             'url'           => $url,
             'pic_prompt'    => $pic_prompt,
             'product'       => $product,
+            'versions'      => json_encode($versions, 256),
             'sort_order'    => time(), // 使用时间戳作为排序权重
             'created_at'    => date('Y-m-d H:i:s'),
             'updated_at'    => date('Y-m-d H:i:s')
@@ -4817,7 +4821,8 @@ class AnimeService
             'product_name'  => $product_name,
             'url'           => $url,
             'pic_prompt'    => $pic_prompt,
-            'product'       => $product
+            'product'       => $product,
+            'versions'      => json_decode($versions, true)
         ];
     }
 
@@ -4826,6 +4831,7 @@ class AnimeService
         $cpid = Site::getCpid();
         $id = getProp($data, 'id');
         if (!$id) Utils::throwError('20003:ID不能为空');
+        $versions = getProp($data, 'versions');
         
         // 检查是否存在且属于当前用户
         $role = DB::table('mp_products')
@@ -4835,7 +4841,7 @@ class AnimeService
         if (!$role) Utils::throwError('20003:记录不存在');
         
         $updateData = [];
-        $needVersionRecord = false; // 是否需要记录版本
+        // $needVersionRecord = false; // 是否需要记录版本
         
         // 名称
         $product_name = trim(getProp($data, 'product_name'));
@@ -4855,10 +4861,10 @@ class AnimeService
                 Utils::throwError('20003:图片格式不正确,仅支持 jpg、jpeg、png、gif、webp、bmp 格式');
             }
             
-            // 如果 url 有变更,记录版本
-            if ($url !== $role->url) {
-                $needVersionRecord = true;
-            }
+            // // 如果 url 有变更,记录版本
+            // if ($url !== $role->url) {
+            //     $needVersionRecord = true;
+            // }
             
             $updateData['url'] = $url;
         }
@@ -4866,10 +4872,10 @@ class AnimeService
         // 提示词
         $pic_prompt = trim(getProp($data, 'pic_prompt'));
         if ($pic_prompt) {
-            // 如果 pic_prompt 有变更,记录版本
-            if ($pic_prompt !== $role->pic_prompt) {
-                $needVersionRecord = true;
-            }
+            // // 如果 pic_prompt 有变更,记录版本
+            // if ($pic_prompt !== $role->pic_prompt) {
+            //     $needVersionRecord = true;
+            // }
             
             $updateData['pic_prompt'] = $pic_prompt;
         }
@@ -4878,50 +4884,53 @@ class AnimeService
             Utils::throwError('20003:没有需要更新的数据');
         }
         
-        // 如果需要记录版本,将数据添加到 versions 数组
-        if ($needVersionRecord) {
-            // 获取现有的 versions 数据
-            $versions = json_decode($role->versions, true) ?: [];
-            $isFirstVersion = empty($versions); // 判断是否是第一次记录版本
+        // // 如果需要记录版本,将数据添加到 versions 数组
+        // if ($needVersionRecord) {
+        //     // 获取现有的 versions 数据
+        //     $versions = json_decode($role->versions, true) ?: [];
+        //     $isFirstVersion = empty($versions); // 判断是否是第一次记录版本
             
-            // 如果是第一次记录版本,先添加旧版本(变更前)
-            if ($isFirstVersion) {
-                $oldVersion = [
-                    'url' => $role->url,
-                    'description' => $role->pic_prompt,
-                ];
-                // 旧版本添加到数组末尾
-                $versions[] = $oldVersion;
-            }
+        //     // 如果是第一次记录版本,先添加旧版本(变更前)
+        //     if ($isFirstVersion) {
+        //         $oldVersion = [
+        //             'url' => $role->url,
+        //             'description' => $role->pic_prompt,
+        //         ];
+        //         // 旧版本添加到数组末尾
+        //         $versions[] = $oldVersion;
+        //     }
             
-            // 构建新版本(变更后)
-            $newVersion = [
-                'url' => isset($updateData['url']) ? $updateData['url'] : $role->url,
-                'description' => isset($updateData['pic_prompt']) ? $updateData['pic_prompt'] : $role->pic_prompt,
-            ];
+        //     // 构建新版本(变更后)
+        //     $newVersion = [
+        //         'url' => isset($updateData['url']) ? $updateData['url'] : $role->url,
+        //         'description' => isset($updateData['pic_prompt']) ? $updateData['pic_prompt'] : $role->pic_prompt,
+        //     ];
             
-            // 检查新版本是否已存在于历史版本中
-            $existingIndex = -1;
-            foreach ($versions as $index => $version) {
-                if ($version['url'] === $newVersion['url'] && $version['description'] === $newVersion['description']) {
-                    $existingIndex = $index;
-                    break;
-                }
-            }
+        //     // 检查新版本是否已存在于历史版本中
+        //     $existingIndex = -1;
+        //     foreach ($versions as $index => $version) {
+        //         if ($version['url'] === $newVersion['url'] && $version['description'] === $newVersion['description']) {
+        //             $existingIndex = $index;
+        //             break;
+        //         }
+        //     }
             
-            if ($existingIndex !== -1) {
-                // 如果已存在,移除旧的位置
-                array_splice($versions, $existingIndex, 1);
-            }
+        //     if ($existingIndex !== -1) {
+        //         // 如果已存在,移除旧的位置
+        //         array_splice($versions, $existingIndex, 1);
+        //     }
             
-            // 新版本添加到数组开头(最新的在前)
-            array_unshift($versions, $newVersion);
+        //     // 新版本添加到数组开头(最新的在前)
+        //     array_unshift($versions, $newVersion);
             
-            // // 限制版本数量(可选,例如只保留最近10个版本)
-            // if (count($versions) > 10) {
-            //     $versions = array_slice($versions, 0, 10);
-            // }
+        //     // // 限制版本数量(可选,例如只保留最近10个版本)
+        //     // if (count($versions) > 10) {
+        //     //     $versions = array_slice($versions, 0, 10);
+        //     // }
             
+        //     $updateData['versions'] = json_encode($versions, 256);
+        // }
+        if ($versions) {
             $updateData['versions'] = json_encode($versions, 256);
         }
         
@@ -5036,19 +5045,20 @@ class AnimeService
         $cpid = Site::getCpid();
         $id = getProp($data, 'id');
         if (!$id) Utils::throwError('20003:ID不能为空');
+        $ids = explode(',', $id);
         
         // 检查是否存在且属于当前用户
         $role = DB::table('mp_products')
-        ->where('id', $id)
+        ->whereIn('id', [$ids])
         ->where('cpid', $cpid)
-        ->first();
+        ->get();
         if (!$role) Utils::throwError('20003:记录不存在');
         
         return DB::table('mp_products')
         ->where('cpid', $cpid)
-        ->where('id', $id)
+        ->whereIn('id', $id)
         ->update([
-            'is_delete' => 1,
+            'is_deleted' => 1,
             'updated_at' => date('Y-m-d H:i:s')
         ]);
     }

+ 35 - 10
app/Services/DeepSeek/DeepSeekService.php

@@ -5174,7 +5174,7 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
                     'role'    => 'user',
                     'content' => $question
                 ];
-                dd($messages);
+            dd($messages);
         }else {
             $content = $uploaded_content ? $chapter_content : trim((string)getProp($base_episode, 'content'));
             if (!$content) {
@@ -5730,6 +5730,7 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
                     'episode_number' => $episode_number,
                     'act_number' => getProp($act, 'act_number'),
                     'act_title' => getProp($act, 'act_title'),
+                    'act_duration' => getProp($act, 'act_duration'),
                     'segment_id' => getProp($segment, 'segment_id'),
                     'segment_number' => getProp($segment, 'segment_number'),
                     'segment_content' => getProp($segment, 'segment_content'),
@@ -5802,8 +5803,8 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
                 if ($pic_prompt) $content .= '{'.$pic_prompt.'}';
                 $voice_name = trim(getProp($item, 'voice_name'));
                 if ($voice_name) $content .= '{{'.$voice_name.'}}';
-                $timbre_prompt = trim(getProp($item, 'timbre_prompt'));
-                if ($timbre_prompt) $content .= '{{'.$timbre_prompt.'}}';
+                $voice_prompt = trim(getProp($item, 'voice_prompt'));
+                if ($voice_prompt) $content .= '{{'.$voice_prompt.'}}';
             }else {
                 $pic_prompt = trim(getProp($item, 'pic_prompt'));
                 if ($pic_prompt) $content .= '{'.$pic_prompt.'}';
@@ -5827,6 +5828,7 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
             if ($origin_content) $origin_content = '剧本全文内容:'.$origin_content;
         }
         
+        $ace_mode = DB::table('mp_animes')->where('id', $animeId)->value('ace_mode');
 
         // 获取分集信息
         $episode = DB::table('mp_anime_episodes')
@@ -5861,6 +5863,7 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
         
         // 添加主体列表
         $content .= "###主体列表\n";
+        $pangbai_voice_prompt = "";
         foreach ($roles as $role) {
             $name = getProp($role, 'role');
             $description = getProp($role, 'description');
@@ -5871,6 +5874,7 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
             if ($pic_prompt) $content .= '{'.$pic_prompt.'}';
             if ($voice_prompt) $content .= '{{'.$voice_prompt.'}}';
             if ($voice_name) $content .= '{{'.$voice_name.'}}';
+            if ($name == '旁白') $pangbai_voice_prompt = $voice_prompt;
             
             $content .= "\n";
         }
@@ -5896,12 +5900,24 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
             ->get();
         
         if ($segments && count($segments) > 0) {
-            $content .= "###分镜剧本\n";
+            if ((int)$ace_mode === 1) {
+                $content .= "###分段剧本\n";
+                // 获取片段数量
+                $act_count = DB::table('mp_episode_segments')->where('anime_id', $animeId)->where('episode_id', $episode_id)->groupBy('act_number')->count('act_number');
+                $content .= "片段数量:{$act_count}\n";
+                if ($pangbai_voice_prompt) $content .= "旁白音色:{$pangbai_voice_prompt}\n";
+                $content .= "\n";
+            }else {
+                $content .= "###分镜剧本\n";
+            }
+            
             
             // 按幕分组
             $currentAct = null;
             foreach ($segments as $segment) {
                 $act_number = getProp($segment, 'act_number');
+                $act_title = getProp($segment, 'act_title');
+                $act_duration = getProp($segment, 'act_duration');
                 $segment_number = getProp($segment, 'segment_number');
                 $segment_content = getProp($segment, 'segment_content');
                 $scene_description = getProp($segment, 'scene_description');
@@ -5914,15 +5930,24 @@ Q版卡通风格,头大身小,造型圆润可爱,线条简单,色彩明
                 $frame_type = getProp($segment, 'frame_type');
                 $tail_frame_description = getProp($segment, 'tail_frame_description');
                 
-                // 如果是新的幕,添加幕标题
-                if ($act_number !== $currentAct) {
-                    $currentAct = $act_number;
-                    $content .= "##第{$act_number}幕:{$scene_name}\n";
+                // 判断是否是全能模式
+                if ((int)$ace_mode === 1) {   // 全能模式
+                    // 如果是新的分段,添加分段标题
+                    if ($act_number !== $currentAct) {
+                        $content .= "##{$act_title}\n";
+                        $content .= "时长:{$act_duration}s\n";
+                    }
+                }else {
+                    // 如果是新的幕,添加幕标题
+                    if ($act_number !== $currentAct) {
+                        $currentAct = $act_number;
+                        $content .= "##第{$act_number}幕:{$scene_name}\n";
+                    }
                 }
-                
+
                 // 添加分镜信息
                 $content .= "分镜{$segment_number}\n";
-                $content .= "分镜内容:{$segment_content}\n";
+                $content .= "分镜内容:\n{$segment_content}\n";
                 // $content .= "画面描述:{$scene_description}\n";
                 // $content .= "场景:{$scene_name}\n";
                 // $content .= "构图设计:{$composition}\n";