|
@@ -5936,30 +5936,49 @@ class AnimeService
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取角色库列表(支持文件夹递归查询)
|
|
* 获取角色库列表(支持文件夹递归查询)
|
|
|
- * @param array $data 包含 parent_id(父文件夹ID,默认0表示最外层)、role(搜索关键词)
|
|
|
|
|
|
|
+ * @param array $data 包含 parent_id(父文件夹ID,默认0表示最外层)、role(搜索关键词)、is_public(筛选类型)
|
|
|
* @return array 返回当前目录下的所有子目录和角色列表(递归)
|
|
* @return array 返回当前目录下的所有子目录和角色列表(递归)
|
|
|
*/
|
|
*/
|
|
|
public function globalProducts($data) {
|
|
public function globalProducts($data) {
|
|
|
$uid = Site::getUid();
|
|
$uid = Site::getUid();
|
|
|
$cpid = Site::getCpid();
|
|
$cpid = Site::getCpid();
|
|
|
|
|
+ $role = Site::getRole();
|
|
|
$id = getProp($data, 'id', 0);
|
|
$id = getProp($data, 'id', 0);
|
|
|
$parent_id = getProp($data, 'parent_id', 0);
|
|
$parent_id = getProp($data, 'parent_id', 0);
|
|
|
$product_name = getProp($data, 'product_name');
|
|
$product_name = getProp($data, 'product_name');
|
|
|
$product = getProp($data, 'product'); // 1.角色 2.场景 3.道具
|
|
$product = getProp($data, 'product'); // 1.角色 2.场景 3.道具
|
|
|
- $is_public = getProp($data, 'is_public', 0); // 0=个人资产库 1=公共资产库
|
|
|
|
|
|
|
+ $is_public = getProp($data, 'public_type', 2); // 0=仅个人库 1=仅公共库 2=个人库+公共库
|
|
|
|
|
|
|
|
if (!$product) {
|
|
if (!$product) {
|
|
|
Utils::throwError('20003:请选择产品类型');
|
|
Utils::throwError('20003:请选择产品类型');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 根据is_public参数确定查询的user_id(公共库user_id=0,cpid保持不变)
|
|
|
|
|
- $query_uid = $is_public ? 0 : $uid;
|
|
|
|
|
|
|
+ // 根据角色和is_public参数确定查询范围
|
|
|
|
|
+ // admin角色:获取所有个人库+公共库(忽略is_public参数)
|
|
|
|
|
+ // user角色:根据is_public参数筛选
|
|
|
|
|
+ $query_user_ids = [];
|
|
|
|
|
+ if ($role === 'admin') {
|
|
|
|
|
+ // admin获取所有个人库和公共库
|
|
|
|
|
+ $query_user_ids = [$uid, 0];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // user角色根据is_public参数筛选
|
|
|
|
|
+ if ($is_public == 2) {
|
|
|
|
|
+ // 个人库+公共库
|
|
|
|
|
+ $query_user_ids = [$uid, 0];
|
|
|
|
|
+ } elseif ($is_public == 0) {
|
|
|
|
|
+ // 仅个人库
|
|
|
|
|
+ $query_user_ids = [$uid];
|
|
|
|
|
+ } elseif ($is_public == 1) {
|
|
|
|
|
+ // 仅公共库
|
|
|
|
|
+ $query_user_ids = [0];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 如果有搜索条件(product_name 或 id),按条件搜索文件夹和产品
|
|
// 如果有搜索条件(product_name 或 id),按条件搜索文件夹和产品
|
|
|
if ($id || $product_name) {
|
|
if ($id || $product_name) {
|
|
|
$query = DB::table('mp_products')
|
|
$query = DB::table('mp_products')
|
|
|
->where('cpid', $cpid)
|
|
->where('cpid', $cpid)
|
|
|
- ->where('user_id', $query_uid)
|
|
|
|
|
|
|
+ ->whereIn('user_id', $query_user_ids)
|
|
|
->where('is_deleted', 0);
|
|
->where('is_deleted', 0);
|
|
|
|
|
|
|
|
// 如果指定了 id,按 id 精确查询
|
|
// 如果指定了 id,按 id 精确查询
|
|
@@ -5977,8 +5996,8 @@ class AnimeService
|
|
|
$query->where('product', $product);
|
|
$query->where('product', $product);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $result = $query->select('id', 'type', 'parent_id', 'level', 'product_name', 'url', 'pic_prompt', 'three_view_image_url', 'versions', 'product', 'created_at')
|
|
|
|
|
- ->orderByRaw('sort_order DESC, created_at DESC')
|
|
|
|
|
|
|
+ $result = $query->select('id', 'type', 'parent_id', 'level', 'product_name', 'url', 'pic_prompt', 'three_view_image_url', 'versions', 'product', 'user_id', 'created_at')
|
|
|
|
|
+ ->orderByRaw('type DESC, CASE WHEN user_id = '.$uid.' THEN 0 ELSE 1 END ASC, sort_order DESC, created_at DESC')
|
|
|
->get()
|
|
->get()
|
|
|
->map(function($value) {
|
|
->map(function($value) {
|
|
|
$value = (array)$value;
|
|
$value = (array)$value;
|
|
@@ -5987,7 +6006,9 @@ class AnimeService
|
|
|
$value['parent_id'] = (int)$value['parent_id'];
|
|
$value['parent_id'] = (int)$value['parent_id'];
|
|
|
$value['level'] = (int)$value['level'];
|
|
$value['level'] = (int)$value['level'];
|
|
|
$value['product'] = (int)($value['product'] ?? 1);
|
|
$value['product'] = (int)($value['product'] ?? 1);
|
|
|
|
|
+ $value['is_public'] = (int)$value['user_id'] === 0 ? 1 : 0;
|
|
|
$value['versions'] = json_decode($value['versions'], true) ?: [];
|
|
$value['versions'] = json_decode($value['versions'], true) ?: [];
|
|
|
|
|
+ unset($value['user_id']);
|
|
|
return $value;
|
|
return $value;
|
|
|
})
|
|
})
|
|
|
->toArray();
|
|
->toArray();
|
|
@@ -5996,7 +6017,7 @@ class AnimeService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 递归获取所有子目录和角色
|
|
// 递归获取所有子目录和角色
|
|
|
- return $this->getChildrenRecursive($cpid, $parent_id, $product, $query_uid);
|
|
|
|
|
|
|
+ return $this->getChildrenRecursive($cpid, $parent_id, $product, $query_user_ids, $uid);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -6004,19 +6025,20 @@ class AnimeService
|
|
|
* @param int $cpid 公司ID
|
|
* @param int $cpid 公司ID
|
|
|
* @param int $parent_id 父目录ID
|
|
* @param int $parent_id 父目录ID
|
|
|
* @param int|null $product 产品类型筛选 1.角色 2.场景 3.道具
|
|
* @param int|null $product 产品类型筛选 1.角色 2.场景 3.道具
|
|
|
- * @param int $uid 用户ID
|
|
|
|
|
|
|
+ * @param array $query_user_ids 用户ID数组(支持多个)
|
|
|
|
|
+ * @param int $current_uid 当前用户ID(用于排序)
|
|
|
* @return array
|
|
* @return array
|
|
|
*/
|
|
*/
|
|
|
- private function getChildrenRecursive($cpid, $parent_id, $product = null, $uid = null) {
|
|
|
|
|
|
|
+ private function getChildrenRecursive($cpid, $parent_id, $product = null, $query_user_ids = [], $current_uid = 0) {
|
|
|
// 查询当前层级的所有项(文件夹和角色)
|
|
// 查询当前层级的所有项(文件夹和角色)
|
|
|
$query = DB::table('mp_products')
|
|
$query = DB::table('mp_products')
|
|
|
->where('cpid', $cpid)
|
|
->where('cpid', $cpid)
|
|
|
->where('is_deleted', 0)
|
|
->where('is_deleted', 0)
|
|
|
->where('parent_id', $parent_id);
|
|
->where('parent_id', $parent_id);
|
|
|
|
|
|
|
|
- // 添加用户ID验证
|
|
|
|
|
- if ($uid !== '') {
|
|
|
|
|
- $query->where('user_id', $uid);
|
|
|
|
|
|
|
+ // 添加用户ID验证(支持多个user_id)
|
|
|
|
|
+ if (!empty($query_user_ids)) {
|
|
|
|
|
+ $query->whereIn('user_id', $query_user_ids);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 如果指定了 product,添加筛选条件(文件夹和角色都需要筛选)
|
|
// 如果指定了 product,添加筛选条件(文件夹和角色都需要筛选)
|
|
@@ -6024,8 +6046,12 @@ class AnimeService
|
|
|
$query->where('product', $product);
|
|
$query->where('product', $product);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $items = $query->select('id', 'type', 'parent_id', 'level', 'product_name', 'url', 'pic_prompt', 'three_view_image_url', 'versions', 'product', 'created_at')
|
|
|
|
|
- ->orderByRaw('type DESC, sort_order DESC, created_at DESC')
|
|
|
|
|
|
|
+ // 排序规则:
|
|
|
|
|
+ // 1. 文件夹在前(type DESC)
|
|
|
|
|
+ // 2. 个人库在前,公共库在后(CASE WHEN user_id = current_uid)
|
|
|
|
|
+ // 3. 其他排序规则
|
|
|
|
|
+ $items = $query->select('id', 'type', 'parent_id', 'level', 'product_name', 'url', 'pic_prompt', 'three_view_image_url', 'versions', 'product', 'user_id', 'created_at')
|
|
|
|
|
+ ->orderByRaw('type DESC, CASE WHEN user_id = '.$current_uid.' THEN 0 ELSE 1 END ASC, sort_order DESC, created_at DESC')
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
$result = [];
|
|
$result = [];
|
|
@@ -6041,13 +6067,14 @@ class AnimeService
|
|
|
'pic_prompt' => $item->pic_prompt ?? '',
|
|
'pic_prompt' => $item->pic_prompt ?? '',
|
|
|
'three_view_image_url' => $item->three_view_image_url,
|
|
'three_view_image_url' => $item->three_view_image_url,
|
|
|
'product' => (int)($item->product ?? 1),
|
|
'product' => (int)($item->product ?? 1),
|
|
|
|
|
+ 'is_public' => (int)$item->user_id === 0 ? 1 : 0,
|
|
|
'created_at' => transDate($item->created_at, 'Y-m-d')
|
|
'created_at' => transDate($item->created_at, 'Y-m-d')
|
|
|
];
|
|
];
|
|
|
$itemArray['versions'] = json_decode($item->versions, true) ?: [];
|
|
$itemArray['versions'] = json_decode($item->versions, true) ?: [];
|
|
|
|
|
|
|
|
// 如果是文件夹,递归获取其子项
|
|
// 如果是文件夹,递归获取其子项
|
|
|
if ($item->type == 2) {
|
|
if ($item->type == 2) {
|
|
|
- $children = $this->getChildrenRecursive($cpid, $item->id, $product, $uid);
|
|
|
|
|
|
|
+ $children = $this->getChildrenRecursive($cpid, $item->id, $product, $query_user_ids, $current_uid);
|
|
|
if (!empty($children)) {
|
|
if (!empty($children)) {
|
|
|
$itemArray['children'] = $children;
|
|
$itemArray['children'] = $children;
|
|
|
}
|
|
}
|