Ver código fonte

前端改版

lh 2 dias atrás
pai
commit
1a8f898a66

+ 45 - 18
app/Services/Anime/AnimeService.php

@@ -1195,9 +1195,10 @@ class AnimeService
 
                 // 如果有关联的script_id,则同步到mp_products表
                 if ($script_id) {
-                    // 查询剧本信息
+                    // 查询剧本信息(仅同步属于当前用户的剧本,不属于则跳过后续资产同步)
                     $script = DB::table('mp_scripts')
                         ->where('id', $script_id)
+                        ->where('user_id', $uid)
                         ->where('is_deleted', 0)
                         ->first();
                     
@@ -1206,6 +1207,15 @@ class AnimeService
                         $product_name = getProp($target_roles, 'role');
                         $pic_prompt = getProp($target_roles, 'pic_prompt', '');
                         $url = getProp($target_roles, 'url', '');
+                        $three_view_image_url = trim(getProp($target_roles, 'three_view_image_url', ''));
+                        // 兼容 versions 传入数组或 JSON 字符串
+                        $versions = getProp($target_roles, 'versions', null);
+                        if (is_string($versions) && $versions !== '') {
+                            $decoded_versions = json_decode($versions, true);
+                            if (is_array($decoded_versions)) {
+                                $versions = $decoded_versions;
+                            }
+                        }
                         $product_type = 1; // 1=角色
                         
                         // 查找或创建以script_name命名的文件夹
@@ -1254,10 +1264,10 @@ class AnimeService
                             ];
                             if ($pic_prompt) $updateData['pic_prompt'] = $pic_prompt;
                             if ($url) $updateData['url'] = $url;
+                            if ($three_view_image_url) $updateData['three_view_image_url'] = $three_view_image_url;
                             
-                            // 处理versions字段
-                            $versions = getProp($target_roles, 'versions', []);
-                            if ($versions && is_array($versions)) {
+                            // 处理versions字段,显式传入数组(含空数组)时覆盖
+                            if (is_array($versions)) {
                                 $updateData['versions'] = json_encode($versions, 256);
                             }
                             
@@ -1270,8 +1280,6 @@ class AnimeService
                             $product_id = $existing_product->id;
                         } else {
                             // 创建新资产
-                            $versions = getProp($target_roles, 'versions', []);
-                            
                             $product_id = DB::table('mp_products')->insertGetId([
                                 'user_id' => $uid,
                                 'cpid' => $cpid,
@@ -1281,6 +1289,7 @@ class AnimeService
                                 'level' => 2,
                                 'product_name' => $product_name,
                                 'url' => $url,
+                                'three_view_image_url' => $three_view_image_url,
                                 'pic_prompt' => $pic_prompt,
                                 'versions' => is_array($versions) ? json_encode($versions, 256) : '[]',
                                 'sort_order' => time(),
@@ -1417,9 +1426,10 @@ class AnimeService
 
                 // 如果有关联的script_id,则同步到mp_products表
                 if ($script_id) {
-                    // 查询剧本信息
+                    // 查询剧本信息(仅同步属于当前用户的剧本,不属于则跳过后续资产同步)
                     $script = DB::table('mp_scripts')
                         ->where('id', $script_id)
+                        ->where('user_id', $uid)
                         ->where('is_deleted', 0)
                         ->first();
                     
@@ -1428,6 +1438,15 @@ class AnimeService
                         $product_name = getProp($target_scenes, 'scene');
                         $pic_prompt = getProp($target_scenes, 'pic_prompt', '');
                         $url = getProp($target_scenes, 'url', '');
+                        $three_view_image_url = trim(getProp($target_scenes, 'three_view_image_url', ''));
+                        // 兼容 versions 传入数组或 JSON 字符串
+                        $versions = getProp($target_scenes, 'versions', null);
+                        if (is_string($versions) && $versions !== '') {
+                            $decoded_versions = json_decode($versions, true);
+                            if (is_array($decoded_versions)) {
+                                $versions = $decoded_versions;
+                            }
+                        }
                         $product_type = 2; // 2=场景
                         
                         // 查找或创建以script_name命名的文件夹
@@ -1476,10 +1495,10 @@ class AnimeService
                             ];
                             if ($pic_prompt) $updateData['pic_prompt'] = $pic_prompt;
                             if ($url) $updateData['url'] = $url;
+                            if ($three_view_image_url) $updateData['three_view_image_url'] = $three_view_image_url;
                             
-                            // 处理versions字段
-                            $versions = getProp($target_scenes, 'versions', []);
-                            if ($versions && is_array($versions)) {
+                            // 处理versions字段,显式传入数组(含空数组)时覆盖
+                            if (is_array($versions)) {
                                 $updateData['versions'] = json_encode($versions, 256);
                             }
                             
@@ -1492,8 +1511,6 @@ class AnimeService
                             $product_id = $existing_product->id;
                         } else {
                             // 创建新资产
-                            $versions = getProp($target_scenes, 'versions', []);
-                            
                             $product_id = DB::table('mp_products')->insertGetId([
                                 'user_id' => $uid,
                                 'cpid' => $cpid,
@@ -1503,6 +1520,7 @@ class AnimeService
                                 'level' => 2,
                                 'product_name' => $product_name,
                                 'url' => $url,
+                                'three_view_image_url' => $three_view_image_url,
                                 'pic_prompt' => $pic_prompt,
                                 'versions' => is_array($versions) ? json_encode($versions, 256) : '[]',
                                 'sort_order' => time(),
@@ -1639,9 +1657,10 @@ class AnimeService
 
                 // 如果有关联的script_id,则同步到mp_products表
                 if ($script_id) {
-                    // 查询剧本信息
+                    // 查询剧本信息(仅同步属于当前用户的剧本,不属于则跳过后续资产同步)
                     $script = DB::table('mp_scripts')
                         ->where('id', $script_id)
+                        ->where('user_id', $uid)
                         ->where('is_deleted', 0)
                         ->first();
                     
@@ -1650,6 +1669,15 @@ class AnimeService
                         $product_name = getProp($target_props, 'prop');
                         $pic_prompt = getProp($target_props, 'pic_prompt', '');
                         $url = getProp($target_props, 'url', '');
+                        $three_view_image_url = trim(getProp($target_props, 'three_view_image_url', ''));
+                        // 兼容 versions 传入数组或 JSON 字符串
+                        $versions = getProp($target_props, 'versions', null);
+                        if (is_string($versions) && $versions !== '') {
+                            $decoded_versions = json_decode($versions, true);
+                            if (is_array($decoded_versions)) {
+                                $versions = $decoded_versions;
+                            }
+                        }
                         $product_type = 3; // 3=道具
                         
                         // 查找或创建以script_name命名的文件夹
@@ -1698,10 +1726,10 @@ class AnimeService
                             ];
                             if ($pic_prompt) $updateData['pic_prompt'] = $pic_prompt;
                             if ($url) $updateData['url'] = $url;
+                            if ($three_view_image_url) $updateData['three_view_image_url'] = $three_view_image_url;
                             
-                            // 处理versions字段
-                            $versions = getProp($target_props, 'versions', []);
-                            if ($versions && is_array($versions)) {
+                            // 处理versions字段,显式传入数组(含空数组)时覆盖
+                            if (is_array($versions)) {
                                 $updateData['versions'] = json_encode($versions, 256);
                             }
                             
@@ -1714,8 +1742,6 @@ class AnimeService
                             $product_id = $existing_product->id;
                         } else {
                             // 创建新资产
-                            $versions = getProp($target_props, 'versions', []);
-                            
                             $product_id = DB::table('mp_products')->insertGetId([
                                 'user_id' => $uid,
                                 'cpid' => $cpid,
@@ -1725,6 +1751,7 @@ class AnimeService
                                 'level' => 2,
                                 'product_name' => $product_name,
                                 'url' => $url,
+                                'three_view_image_url' => $three_view_image_url,
                                 'pic_prompt' => $pic_prompt,
                                 'versions' => is_array($versions) ? json_encode($versions, 256) : '[]',
                                 'sort_order' => time(),

Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 1
resources/views/animeIndex.blade.php