lh há 1 dia atrás
pai
commit
0e7870e293
1 ficheiros alterados com 125 adições e 130 exclusões
  1. 125 130
      app/Services/Anime/AnimeService.php

+ 125 - 130
app/Services/Anime/AnimeService.php

@@ -5732,15 +5732,20 @@ class AnimeService
         $parent_id = getProp($data, 'parent_id', 0);
         $product_name = getProp($data, 'product_name');
         $product = getProp($data, 'product'); // 1.角色 2.场景 3.道具
+        $is_public = getProp($data, 'is_public', 0); // 0=个人资产库 1=公共资产库
+        
         if (!$product) {
             Utils::throwError('20003:请选择产品类型');
         }
         
+        // 根据is_public参数确定查询的user_id(公共库user_id=0,cpid保持不变)
+        $query_uid = $is_public ? 0 : $uid;
+        
         // 如果有搜索条件(product_name 或 id),按条件搜索文件夹和产品
         if ($id || $product_name) {
             $query = DB::table('mp_products')
                 ->where('cpid', $cpid)
-                ->where('user_id', $uid)
+                ->where('user_id', $query_uid)
                 ->where('is_deleted', 0);
             
             // 如果指定了 id,按 id 精确查询
@@ -5777,7 +5782,7 @@ class AnimeService
         }
         
         // 递归获取所有子目录和角色
-        return $this->getChildrenRecursive($cpid, $parent_id, $product, $uid);
+        return $this->getChildrenRecursive($cpid, $parent_id, $product, $query_uid);
     }
     
     /**
@@ -5796,7 +5801,7 @@ class AnimeService
             ->where('parent_id', $parent_id);
         
         // 添加用户ID验证
-        if ($uid) {
+        if ($uid !== '') {
             $query->where('user_id', $uid);
         }
         
@@ -5850,6 +5855,10 @@ class AnimeService
         $cpid = Site::getCpid();
         $parent_id = getProp($data, 'parent_id', 0);
         $folder_name = getProp($data, 'product_name', '新建文件夹');
+        $is_public = getProp($data, 'is_public', 0); // 0=个人资产库 1=公共资产库
+        
+        // 根据is_public参数确定存储的user_id(公共库user_id=0,cpid保持不变)
+        $store_uid = $is_public ? 0 : $uid;
         
         // 获取 product 字段:1.角色 2.场景 3.道具,默认为1
         $product = getProp($data, 'product');
@@ -5862,6 +5871,8 @@ class AnimeService
         if ($parent_id > 0) {
             $parent = DB::table('mp_products')
                 ->where('id', $parent_id)
+                ->where('cpid', $cpid)
+                ->where('user_id', $store_uid)
                 ->where('type', 2)
                 ->where('is_deleted', 0)
                 ->first();
@@ -5886,6 +5897,8 @@ class AnimeService
         // 检查当前目录下是否已存在空白文件夹
         $empty_folder_exists = DB::table('mp_products')
             ->where('parent_id', $parent_id)
+            ->where('cpid', $cpid)
+            ->where('user_id', $store_uid)
             ->where('type', 2)
             ->where('product', $product)
             ->where('product_name', '新建文件夹')
@@ -5898,7 +5911,7 @@ class AnimeService
         
         // 创建文件夹
         $folder_id = DB::table('mp_products')->insertGetId([
-            'user_id' => $uid,
+            'user_id' => $store_uid,
             'cpid' => $cpid,
             'type' => 2,
             'parent_id' => $parent_id,
@@ -5931,15 +5944,20 @@ class AnimeService
         $cpid = Site::getCpid();
         $id = getProp($data, 'id');
         $new_name = getProp($data, 'product_name');
+        $is_public = getProp($data, 'is_public', 0); // 0=个人资产库 1=公共资产库
         
         if (!$id || !$new_name) {
             Utils::throwError('20003:参数不完整');
         }
         
+        // 根据is_public参数确定查询的user_id(公共库user_id=0,cpid保持不变)
+        $query_uid = $is_public ? 0 : $uid;
+        
         // 检查是否存在
         $item = DB::table('mp_products')
             ->where('id', $id)
             ->where('cpid', $cpid)
+            ->where('user_id', $query_uid)
             ->where('is_deleted', 0)
             ->first();
         
@@ -5950,6 +5968,7 @@ class AnimeService
         return DB::table('mp_products')
             ->where('id', $id)
             ->where('cpid', $cpid)
+            ->where('user_id', $query_uid)
             ->update([
                 'product_name' => $new_name,
                 'updated_at' => date('Y-m-d H:i:s')
@@ -5962,18 +5981,24 @@ class AnimeService
      * @return bool
      */
     public function moveProductOrFolder($data) {
+        $uid = Site::getUid();
         $cpid = Site::getCpid();
         $id = getProp($data, 'id');
         $target_parent_id = getProp($data, 'target_parent_id', 0);
+        $is_public = getProp($data, 'is_public', 0); // 0=个人资产库 1=公共资产库
         
         if (!$id) {
             Utils::throwError('20003:请选择要移动的项目');
         }
         
+        // 根据is_public参数确定查询的user_id(公共库user_id=0,cpid保持不变)
+        $query_uid = $is_public ? 0 : $uid;
+        
         // 检查要移动的项目
         $item = DB::table('mp_products')
             ->where('id', $id)
             ->where('cpid', $cpid)
+            ->where('user_id', $query_uid)
             ->where('is_deleted', 0)
             ->first();
         
@@ -5989,6 +6014,7 @@ class AnimeService
             $target_parent = DB::table('mp_products')
                 ->where('id', $target_parent_id)
                 ->where('cpid', $cpid)
+                ->where('user_id', $query_uid)
                 ->where('type', 2)
                 ->where('is_deleted', 0)
                 ->first();
@@ -6128,7 +6154,10 @@ class AnimeService
      * @return array 返回路径数组
      */
     public function getFolderPath($data) {
+        $uid = Site::getUid();
+        $cpid = Site::getCpid();
         $folder_id = getProp($data, 'id', 0);
+        $is_public = getProp($data, 'is_public', 0); // 0=个人资产库 1=公共资产库
         
         if ($folder_id == 0) {
             return [
@@ -6136,6 +6165,9 @@ class AnimeService
             ];
         }
         
+        // 根据is_public参数确定查询的user_id(公共库user_id=0,cpid保持不变)
+        $query_uid = $is_public ? 0 : $uid;
+        
         $path = [];
         $current_id = $folder_id;
 
@@ -6143,6 +6175,8 @@ class AnimeService
         while ($current_id > 0) {
             $folder = DB::table('mp_products')
                 ->where('id', $current_id)
+                ->where('cpid', $cpid)
+                ->where('user_id', $query_uid)
                 ->where('type', 2)
                 ->where('is_deleted', 0)
                 ->first();
@@ -6168,6 +6202,11 @@ class AnimeService
     public function createProduct($data) {
         $uid = Site::getUid();
         $cpid = Site::getCpid();
+        $is_public = getProp($data, 'is_public', 0); // 0=个人资产库 1=公共资产库
+        
+        // 根据is_public参数确定存储的user_id(公共库user_id=0,cpid保持不变)
+        $store_uid = $is_public ? 0 : $uid;
+        
         $product_name = trim(getProp($data, 'product_name'));
         if (!$product_name) Utils::throwError('20003:名称不能为空');
         $product_name = preg_replace('/^[\s*\[\]【】[]{}{}\x{3000}]+|[\s*\[\]【】[]{}{}\x{3000}]+$/u', '', $product_name);
@@ -6202,6 +6241,7 @@ class AnimeService
             $parent = DB::table('mp_products')
                 ->where('id', $parent_id)
                 ->where('cpid', $cpid)
+                ->where('user_id', $store_uid)
                 ->where('type', 2)
                 ->where('is_deleted', 0)
                 ->first();
@@ -6214,7 +6254,7 @@ class AnimeService
         }
 
         $id = DB::table('mp_products')->insertGetId([
-            'user_id'       => $uid,
+            'user_id'       => $store_uid,
             'cpid'          => $cpid,
             'type'          => 1, // 1=角色图片
             'parent_id'     => $parent_id,
@@ -6249,11 +6289,16 @@ class AnimeService
         $id = getProp($data, 'id');
         if (!$id) Utils::throwError('20003:ID不能为空');
         $versions = getProp($data, 'versions');
+        $is_public = getProp($data, 'is_public', 0); // 0=个人资产库 1=公共资产库
         
-        // 检查是否存在且属于当前用户
+        // 根据is_public参数确定查询的user_id(公共库user_id=0,cpid保持不变)
+        $query_uid = $is_public ? 0 : $uid;
+        
+        // 检查是否存在且属于当前用户或公共库
         $role = DB::table('mp_products')
         ->where('id', $id)
         ->where('cpid', $cpid)
+        ->where('user_id', $query_uid)
         ->where('type', 1)->first();
         if (!$role) Utils::throwError('20003:记录不存在');
         
@@ -6467,16 +6512,22 @@ class AnimeService
         $id = getProp($data, 'id');
         if (!$id) Utils::throwError('20003:ID不能为空');
         $ids = explode(',', $id);
+        $is_public = getProp($data, 'is_public', 0); // 0=个人资产库 1=公共资产库
+        
+        // 根据is_public参数确定查询的user_id(公共库user_id=0,cpid保持不变)
+        $query_uid = $is_public ? 0 : $uid;
         
-        // 检查是否存在且属于当前用户
+        // 检查是否存在且属于当前用户或公共库
         $role = DB::table('mp_products')
         ->whereIn('id', $ids)
         ->where('cpid', $cpid)
+        ->where('user_id', $query_uid)
         ->get();
         if (!$role) Utils::throwError('20003:记录不存在');
         
         return DB::table('mp_products')
         ->where('cpid', $cpid)
+        ->where('user_id', $query_uid)
         ->whereIn('id', $ids)
         ->update([
             'is_deleted' => 1,
@@ -6489,11 +6540,16 @@ class AnimeService
         $cpid = Site::getCpid();
         $id = getProp($data, 'id');
         if (!$id) Utils::throwError('20003:ID不能为空');
+        $is_public = getProp($data, 'is_public', 0); // 0=个人资产库 1=公共资产库
         
-        // 检查是否存在且属于当前用户
+        // 根据is_public参数确定查询的user_id(公共库user_id=0,cpid保持不变)
+        $query_uid = $is_public ? 0 : $uid;
+        
+        // 检查是否存在且属于当前用户或公共库
         $product = DB::table('mp_products')
         ->where('id', $id)
         ->where('cpid', $cpid)
+        ->where('user_id', $query_uid)
         ->where('type', 1)->first();
         if (!$product) Utils::throwError('20003:资产不存在');
         
@@ -6679,6 +6735,67 @@ class AnimeService
         if (!$script) {
             Utils::throwError('20003:剧本不存在');
         }
+
+        // 处理图片模型
+        $model = getProp($data, 'model');
+        if (!$model) {
+            // 使用默认模型
+            $model = 'doubao-seedream-5-0-lite-260128';
+        }
+        // 验证模型是否在可用模型表中
+        if (!DB::table('mp_image_models')->where('model', $model)->where('is_enabled', 1)->exists()) {
+            Utils::throwError('20003:该模型已不可用,请更换!');
+        }
+        $ratio = getProp($data, 'ratio', '9:16');
+        $resolution = getProp($data, 'resolution', '2k');
+
+        // 定义分辨率和宽高比对应的尺寸映射表
+        $sizeMap = [
+            '2k' => [
+                '1:1' => ['width' => 2048, 'height' => 2048],
+                '4:3' => ['width' => 2304, 'height' => 1728],
+                '3:4' => ['width' => 1728, 'height' => 2304],
+                '16:9' => ['width' => 2848, 'height' => 1600],
+                '9:16' => ['width' => 1600, 'height' => 2848],
+                '3:2' => ['width' => 2496, 'height' => 1664],
+                '2:3' => ['width' => 1664, 'height' => 2496],
+                '21:9' => ['width' => 3136, 'height' => 1344],
+            ],
+            '3k' => [
+                '1:1' => ['width' => 3072, 'height' => 3072],
+                '4:3' => ['width' => 3456, 'height' => 2592],
+                '3:4' => ['width' => 2592, 'height' => 3456],
+                '16:9' => ['width' => 4096, 'height' => 2304],
+                '9:16' => ['width' => 2304, 'height' => 4096],
+                '2:3' => ['width' => 2496, 'height' => 3744],
+                '3:2' => ['width' => 3744, 'height' => 2496],
+                '21:9' => ['width' => 4704, 'height' => 2016],
+            ],
+            '4k' => [
+                '1:1' => ['width' => 4096, 'height' => 4096],
+                '3:4' => ['width' => 3520, 'height' => 4704],
+                '4:3' => ['width' => 4704, 'height' => 3520],
+                '16:9' => ['width' => 5504, 'height' => 3040],
+                '9:16' => ['width' => 3040, 'height' => 5504],
+                '2:3' => ['width' => 3328, 'height' => 4992],
+                '3:2' => ['width' => 4992, 'height' => 3328],
+                '21:9' => ['width' => 6240, 'height' => 2656],
+            ],
+        ];
+        
+        // 参数验证
+        $resolution = strtolower($resolution);
+        if (!isset($sizeMap[$resolution])) {
+            Utils::throwError('20003:分辨率参数错误,仅支持 2k、3k、4k');
+        }
+        
+        if (!isset($sizeMap[$resolution][$ratio])) {
+            Utils::throwError('20003:宽高比参数错误,该分辨率下不支持 ' . $ratio . ' 比例');
+        }
+        
+        // 根据 ratio 和 resolution 确定宽高
+        $width = $sizeMap[$resolution][$ratio]['width'];
+        $height = $sizeMap[$resolution][$ratio]['height'];
         
         $script_name = $script->script_name ?? 'script_' . $script_id;
         
@@ -6745,67 +6862,6 @@ class AnimeService
                     'script_name' => $script_name
                 ]);
 
-                // 处理图片模型
-                $model = getProp($data, 'model');
-                if (!$model) {
-                    // 使用默认模型
-                    $model = 'doubao-seedream-5-0-lite-260128';
-                }
-                // 验证模型是否在可用模型表中
-                if (!DB::table('mp_image_models')->where('model', $model)->where('is_enabled', 1)->exists()) {
-                    Utils::throwError('20003:该模型已不可用,请更换!');
-                }
-                $ratio = getProp($data, 'ratio', '16:9');
-                $resolution = getProp($data, 'resolution', '2k');
-
-                // 定义分辨率和宽高比对应的尺寸映射表
-                $sizeMap = [
-                    '2k' => [
-                        '1:1' => ['width' => 2048, 'height' => 2048],
-                        '4:3' => ['width' => 2304, 'height' => 1728],
-                        '3:4' => ['width' => 1728, 'height' => 2304],
-                        '16:9' => ['width' => 2848, 'height' => 1600],
-                        '9:16' => ['width' => 1600, 'height' => 2848],
-                        '3:2' => ['width' => 2496, 'height' => 1664],
-                        '2:3' => ['width' => 1664, 'height' => 2496],
-                        '21:9' => ['width' => 3136, 'height' => 1344],
-                    ],
-                    '3k' => [
-                        '1:1' => ['width' => 3072, 'height' => 3072],
-                        '4:3' => ['width' => 3456, 'height' => 2592],
-                        '3:4' => ['width' => 2592, 'height' => 3456],
-                        '16:9' => ['width' => 4096, 'height' => 2304],
-                        '9:16' => ['width' => 2304, 'height' => 4096],
-                        '2:3' => ['width' => 2496, 'height' => 3744],
-                        '3:2' => ['width' => 3744, 'height' => 2496],
-                        '21:9' => ['width' => 4704, 'height' => 2016],
-                    ],
-                    '4k' => [
-                        '1:1' => ['width' => 4096, 'height' => 4096],
-                        '3:4' => ['width' => 3520, 'height' => 4704],
-                        '4:3' => ['width' => 4704, 'height' => 3520],
-                        '16:9' => ['width' => 5504, 'height' => 3040],
-                        '9:16' => ['width' => 3040, 'height' => 5504],
-                        '2:3' => ['width' => 3328, 'height' => 4992],
-                        '3:2' => ['width' => 4992, 'height' => 3328],
-                        '21:9' => ['width' => 6240, 'height' => 2656],
-                    ],
-                ];
-                
-                // 参数验证
-                $resolution = strtolower($resolution);
-                if (!isset($sizeMap[$resolution])) {
-                    Utils::throwError('20003:分辨率参数错误,仅支持 2k、3k、4k');
-                }
-                
-                if (!isset($sizeMap[$resolution][$ratio])) {
-                    Utils::throwError('20003:宽高比参数错误,该分辨率下不支持 ' . $ratio . ' 比例');
-                }
-                
-                // 根据 ratio 和 resolution 确定宽高
-                $width = $sizeMap[$resolution][$ratio]['width'];
-                $height = $sizeMap[$resolution][$ratio]['height'];
-                
                 // 开启事务
                 DB::beginTransaction();
                 
@@ -6932,67 +6988,6 @@ class AnimeService
             // 存储每个类型的根文件夹ID
             $typeFolderIds = [];
             
-            // 处理图片模型
-            $model = getProp($data, 'model');
-            if (!$model) {
-                // 使用默认模型
-                $model = 'doubao-seedream-5-0-lite-260128';
-            }
-            // 验证模型是否在可用模型表中
-            if (!DB::table('mp_image_models')->where('model', $model)->where('is_enabled', 1)->exists()) {
-                Utils::throwError('20003:该模型已不可用,请更换!');
-            }
-            $ratio = getProp($data, 'ratio', '16:9');
-            $resolution = getProp($data, 'resolution', '2k');
-
-            // 定义分辨率和宽高比对应的尺寸映射表
-            $sizeMap = [
-                '2k' => [
-                    '1:1' => ['width' => 2048, 'height' => 2048],
-                    '4:3' => ['width' => 2304, 'height' => 1728],
-                    '3:4' => ['width' => 1728, 'height' => 2304],
-                    '16:9' => ['width' => 2848, 'height' => 1600],
-                    '9:16' => ['width' => 1600, 'height' => 2848],
-                    '3:2' => ['width' => 2496, 'height' => 1664],
-                    '2:3' => ['width' => 1664, 'height' => 2496],
-                    '21:9' => ['width' => 3136, 'height' => 1344],
-                ],
-                '3k' => [
-                    '1:1' => ['width' => 3072, 'height' => 3072],
-                    '4:3' => ['width' => 3456, 'height' => 2592],
-                    '3:4' => ['width' => 2592, 'height' => 3456],
-                    '16:9' => ['width' => 4096, 'height' => 2304],
-                    '9:16' => ['width' => 2304, 'height' => 4096],
-                    '2:3' => ['width' => 2496, 'height' => 3744],
-                    '3:2' => ['width' => 3744, 'height' => 2496],
-                    '21:9' => ['width' => 4704, 'height' => 2016],
-                ],
-                '4k' => [
-                    '1:1' => ['width' => 4096, 'height' => 4096],
-                    '3:4' => ['width' => 3520, 'height' => 4704],
-                    '4:3' => ['width' => 4704, 'height' => 3520],
-                    '16:9' => ['width' => 5504, 'height' => 3040],
-                    '9:16' => ['width' => 3040, 'height' => 5504],
-                    '2:3' => ['width' => 3328, 'height' => 4992],
-                    '3:2' => ['width' => 4992, 'height' => 3328],
-                    '21:9' => ['width' => 6240, 'height' => 2656],
-                ],
-            ];
-            
-            // 参数验证
-            $resolution = strtolower($resolution);
-            if (!isset($sizeMap[$resolution])) {
-                Utils::throwError('20003:分辨率参数错误,仅支持 2k、3k、4k');
-            }
-            
-            if (!isset($sizeMap[$resolution][$ratio])) {
-                Utils::throwError('20003:宽高比参数错误,该分辨率下不支持 ' . $ratio . ' 比例');
-            }
-            
-            // 根据 ratio 和 resolution 确定宽高
-            $width = $sizeMap[$resolution][$ratio]['width'];
-            $height = $sizeMap[$resolution][$ratio]['height'];
-            
             // 遍历每个产品类型(type: 1=角色, 2=场景, 3=道具)
             foreach ($products as $productGroup) {
                 $type = getProp($productGroup, 'type');