|
@@ -7007,6 +7007,7 @@ class AnimeService
|
|
|
$role = Site::getRole();
|
|
$role = Site::getRole();
|
|
|
$product_id = getProp($data, 'product_id');
|
|
$product_id = getProp($data, 'product_id');
|
|
|
$target_parent_id = getProp($data, 'target_parent_id', 0);
|
|
$target_parent_id = getProp($data, 'target_parent_id', 0);
|
|
|
|
|
+ $target_product = getProp($data, 'product'); // 目标 product 类型,用于跨类型推送
|
|
|
|
|
|
|
|
if (!$product_id) {
|
|
if (!$product_id) {
|
|
|
Utils::throwError('20003:请选择要推送的项目');
|
|
Utils::throwError('20003:请选择要推送的项目');
|
|
@@ -7031,6 +7032,7 @@ class AnimeService
|
|
|
$target_level = 0;
|
|
$target_level = 0;
|
|
|
$target_uid = $uid; // 默认推送到个人库
|
|
$target_uid = $uid; // 默认推送到个人库
|
|
|
$target_is_public = 0;
|
|
$target_is_public = 0;
|
|
|
|
|
+ $final_product_type = $sourceItem->product; // 默认使用源的 product 类型
|
|
|
|
|
|
|
|
if ($target_parent_id > 0) {
|
|
if ($target_parent_id > 0) {
|
|
|
// 查询目标文件夹(只通过cpid查询,不限制user_id)
|
|
// 查询目标文件夹(只通过cpid查询,不限制user_id)
|
|
@@ -7045,24 +7047,30 @@ class AnimeService
|
|
|
Utils::throwError('20003:目标文件夹不存在');
|
|
Utils::throwError('20003:目标文件夹不存在');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 检查 product 类型是否一致
|
|
|
|
|
- if ($targetParent->product != $sourceItem->product) {
|
|
|
|
|
- Utils::throwError('20003:不能推送到不同类型的文件夹下');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// 通过user_id判断目标是公共库还是个人库
|
|
// 通过user_id判断目标是公共库还是个人库
|
|
|
$target_level = $targetParent->level;
|
|
$target_level = $targetParent->level;
|
|
|
$target_uid = $targetParent->user_id;
|
|
$target_uid = $targetParent->user_id;
|
|
|
$target_is_public = ($target_uid == 0) ? 1 : 0;
|
|
$target_is_public = ($target_uid == 0) ? 1 : 0;
|
|
|
|
|
+
|
|
|
|
|
+ // 使用目标文件夹的 product 类型
|
|
|
|
|
+ $final_product_type = $targetParent->product;
|
|
|
}
|
|
}
|
|
|
// 如果 target_parent_id = 0(推送到根目录),需要通过参数判断推送到个人库还是公共库
|
|
// 如果 target_parent_id = 0(推送到根目录),需要通过参数判断推送到个人库还是公共库
|
|
|
else {
|
|
else {
|
|
|
$push_to_public = getProp($data, 'push_to_public');
|
|
$push_to_public = getProp($data, 'push_to_public');
|
|
|
- if ($push_to_public === '') Utils::throwError('20003:请选择是否推送到公共库');
|
|
|
|
|
|
|
+ if ($push_to_public === '') {
|
|
|
|
|
+ Utils::throwError('20003:请选择是否推送到公共库');
|
|
|
|
|
+ }
|
|
|
if ($push_to_public) {
|
|
if ($push_to_public) {
|
|
|
$target_uid = 0;
|
|
$target_uid = 0;
|
|
|
$target_is_public = 1;
|
|
$target_is_public = 1;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 推送到根目录时,必须指定 product 类型
|
|
|
|
|
+ if ($target_product === null || $target_product === '') {
|
|
|
|
|
+ Utils::throwError('20003:推送到根目录时必须指定目标类型(product)');
|
|
|
|
|
+ }
|
|
|
|
|
+ $final_product_type = $target_product;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 如果目标是公共库,需要admin权限
|
|
// 如果目标是公共库,需要admin权限
|
|
@@ -7076,17 +7084,17 @@ class AnimeService
|
|
|
try {
|
|
try {
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
- // 如果是资产,直接复制
|
|
|
|
|
|
|
+ // 如果是资产,直接复制(支持跨类型推送,更新 product 字段)
|
|
|
if ($sourceItem->type == 1) {
|
|
if ($sourceItem->type == 1) {
|
|
|
- $newId = $this->copyProduct($sourceItem, $target_parent_id, $target_level + 1, $cpid, $target_uid);
|
|
|
|
|
|
|
+ $newId = $this->copyProduct($sourceItem, $target_parent_id, $target_level + 1, $cpid, $target_uid, $final_product_type);
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
return [
|
|
return [
|
|
|
'product_id' => $newId,
|
|
'product_id' => $newId,
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 如果是文件夹,递归复制
|
|
|
|
|
- $newFolderId = $this->copyFolderRecursive($sourceItem, $target_parent_id, $target_level + 1, $cpid, $target_uid, $source_uid);
|
|
|
|
|
|
|
+ // 如果是文件夹,递归复制(支持跨类型推送)
|
|
|
|
|
+ $newFolderId = $this->copyFolderRecursive($sourceItem, $target_parent_id, $target_level + 1, $cpid, $target_uid, $source_uid, $final_product_type);
|
|
|
|
|
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
return [
|
|
return [
|
|
@@ -7156,7 +7164,10 @@ class AnimeService
|
|
|
* @param int $targetUid 目标用户ID
|
|
* @param int $targetUid 目标用户ID
|
|
|
* @return int 返回新资产ID
|
|
* @return int 返回新资产ID
|
|
|
*/
|
|
*/
|
|
|
- private function copyProduct($sourceProduct, $targetParentId, $targetLevel, $cpid, $targetUid) {
|
|
|
|
|
|
|
+ private function copyProduct($sourceProduct, $targetParentId, $targetLevel, $cpid, $targetUid, $productType = null) {
|
|
|
|
|
+ // 如果指定了 productType,使用指定的;否则使用源的 product 类型
|
|
|
|
|
+ $finalProductType = ($productType !== null) ? $productType : $sourceProduct->product;
|
|
|
|
|
+
|
|
|
$newProductData = [
|
|
$newProductData = [
|
|
|
'user_id' => $targetUid,
|
|
'user_id' => $targetUid,
|
|
|
'cpid' => $cpid,
|
|
'cpid' => $cpid,
|
|
@@ -7167,7 +7178,7 @@ class AnimeService
|
|
|
'url' => $sourceProduct->url,
|
|
'url' => $sourceProduct->url,
|
|
|
'pic_prompt' => $sourceProduct->pic_prompt ?? '',
|
|
'pic_prompt' => $sourceProduct->pic_prompt ?? '',
|
|
|
'three_view_image_url' => $sourceProduct->three_view_image_url ?? '',
|
|
'three_view_image_url' => $sourceProduct->three_view_image_url ?? '',
|
|
|
- 'product' => $sourceProduct->product,
|
|
|
|
|
|
|
+ 'product' => $finalProductType,
|
|
|
'versions' => $sourceProduct->versions ?? '',
|
|
'versions' => $sourceProduct->versions ?? '',
|
|
|
'sort_order' => time(),
|
|
'sort_order' => time(),
|
|
|
'is_deleted' => 0,
|
|
'is_deleted' => 0,
|
|
@@ -7188,7 +7199,10 @@ class AnimeService
|
|
|
* @param int $sourceUid 源用户ID
|
|
* @param int $sourceUid 源用户ID
|
|
|
* @return int 返回新文件夹ID
|
|
* @return int 返回新文件夹ID
|
|
|
*/
|
|
*/
|
|
|
- private function copyFolderRecursive($sourceFolder, $targetParentId, $targetLevel, $cpid, $targetUid, $sourceUid) {
|
|
|
|
|
|
|
+ private function copyFolderRecursive($sourceFolder, $targetParentId, $targetLevel, $cpid, $targetUid, $sourceUid, $productType = null) {
|
|
|
|
|
+ // 如果指定了 productType,使用指定的;否则使用源的 product 类型
|
|
|
|
|
+ $finalProductType = ($productType !== null) ? $productType : $sourceFolder->product;
|
|
|
|
|
+
|
|
|
// 创建新文件夹
|
|
// 创建新文件夹
|
|
|
$newFolderData = [
|
|
$newFolderData = [
|
|
|
'user_id' => $targetUid,
|
|
'user_id' => $targetUid,
|
|
@@ -7197,7 +7211,7 @@ class AnimeService
|
|
|
'parent_id' => $targetParentId,
|
|
'parent_id' => $targetParentId,
|
|
|
'level' => $targetLevel,
|
|
'level' => $targetLevel,
|
|
|
'product_name' => $sourceFolder->product_name,
|
|
'product_name' => $sourceFolder->product_name,
|
|
|
- 'product' => $sourceFolder->product,
|
|
|
|
|
|
|
+ 'product' => $finalProductType,
|
|
|
'sort_order' => time(),
|
|
'sort_order' => time(),
|
|
|
'is_deleted' => 0,
|
|
'is_deleted' => 0,
|
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
@@ -7215,14 +7229,14 @@ class AnimeService
|
|
|
->orderByRaw('type DESC, sort_order DESC, created_at DESC')
|
|
->orderByRaw('type DESC, sort_order DESC, created_at DESC')
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
- // 递归复制子项
|
|
|
|
|
|
|
+ // 递归复制子项(子项继承目标文件夹的 product 类型)
|
|
|
foreach ($children as $child) {
|
|
foreach ($children as $child) {
|
|
|
if ($child->type == 1) {
|
|
if ($child->type == 1) {
|
|
|
// 资产
|
|
// 资产
|
|
|
- $this->copyProduct($child, $newFolderId, $targetLevel + 1, $cpid, $targetUid);
|
|
|
|
|
|
|
+ $this->copyProduct($child, $newFolderId, $targetLevel + 1, $cpid, $targetUid, $finalProductType);
|
|
|
} else {
|
|
} else {
|
|
|
// 文件夹
|
|
// 文件夹
|
|
|
- $this->copyFolderRecursive($child, $newFolderId, $targetLevel + 1, $cpid, $targetUid, $sourceUid);
|
|
|
|
|
|
|
+ $this->copyFolderRecursive($child, $newFolderId, $targetLevel + 1, $cpid, $targetUid, $sourceUid, $finalProductType);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|