|
|
@ -155,10 +155,9 @@ class ResourceSharingService extends BaseApiService |
|
|
return $model; |
|
|
return $model; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//查询资源共享详情 |
|
|
//查询资源共享详情 - 修改为使用 ResourceAssignment 表 |
|
|
public function info(array $where, string $field = '*') |
|
|
public function info(array $where, string $field = '*') |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
$res = [ |
|
|
$res = [ |
|
|
'code' => 0, |
|
|
'code' => 0, |
|
|
'msg' => '操作失败', |
|
|
'msg' => '操作失败', |
|
|
@ -169,7 +168,8 @@ class ResourceSharingService extends BaseApiService |
|
|
return $res; |
|
|
return $res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$model = $this->model; |
|
|
// 使用 ResourceAssignment 表查询,resource_sharing_id 现在是 assignment 表的 id |
|
|
|
|
|
$model = $this->assignmentModel; |
|
|
|
|
|
|
|
|
if (!empty($where['id'])) { |
|
|
if (!empty($where['id'])) { |
|
|
$model = $model->where('id', $where['id']); |
|
|
$model = $model->where('id', $where['id']); |
|
|
@ -197,9 +197,11 @@ class ResourceSharingService extends BaseApiService |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
])->field($field)->find(); |
|
|
])->field($field)->find(); |
|
|
|
|
|
|
|
|
if ($data) { |
|
|
if ($data) { |
|
|
$data = $data->toArray(); |
|
|
$data = $data->toArray(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!empty($data['customerResource'])) { |
|
|
if (!empty($data['customerResource'])) { |
|
|
$data['customerResource']['cj_count'] = OrderTable::where('resource_id', $data['customerResource']['id']) |
|
|
$data['customerResource']['cj_count'] = OrderTable::where('resource_id', $data['customerResource']['id']) |
|
|
->where('order_status', 'paid') |
|
|
->where('order_status', 'paid') |
|
|
@ -207,6 +209,13 @@ class ResourceSharingService extends BaseApiService |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($data) { |
|
|
if ($data) { |
|
|
|
|
|
// 添加兼容字段 |
|
|
|
|
|
$data['resource_sharing_id'] = $data['id']; // assignment 表的 id |
|
|
|
|
|
$data['user_id'] = ($data['assignee_type'] ?? '') === 'user' ? (int) $data['assignee_id'] : 0; |
|
|
|
|
|
$data['role_id'] = ($data['assignee_type'] ?? '') === 'role' ? (int) $data['assignee_id'] : 0; |
|
|
|
|
|
$data['shared_by'] = (int) ($data['assigned_by'] ?? 0); |
|
|
|
|
|
$data['shared_at'] = $data['assigned_at'] ?? null; |
|
|
|
|
|
|
|
|
$res['code'] = 1; |
|
|
$res['code'] = 1; |
|
|
$res['msg'] = '操作成功'; |
|
|
$res['msg'] = '操作成功'; |
|
|
$res['data'] = $data; |
|
|
$res['data'] = $data; |
|
|
@ -339,6 +348,16 @@ class ResourceSharingService extends BaseApiService |
|
|
$resource_conditions[] = ['source_channel', 'like', '%' . $where['source_channel'] . '%']; |
|
|
$resource_conditions[] = ['source_channel', 'like', '%' . $where['source_channel'] . '%']; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 年龄查询 |
|
|
|
|
|
if (isset($where['age']) && $where['age'] !== '' && $where['age'] !== null) { |
|
|
|
|
|
$resource_conditions[] = ['age', '=', $where['age']]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 黑名单状态查询 |
|
|
|
|
|
if (isset($where['blacklist']) && $where['blacklist'] !== '' && $where['blacklist'] !== null) { |
|
|
|
|
|
$resource_conditions[] = ['blacklist', '=', $where['blacklist']]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 查询符合条件的资源ID |
|
|
// 查询符合条件的资源ID |
|
|
$resource_ids = []; |
|
|
$resource_ids = []; |
|
|
if (!empty($resource_conditions)) { |
|
|
if (!empty($resource_conditions)) { |
|
|
@ -353,7 +372,7 @@ class ResourceSharingService extends BaseApiService |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
$model = $model->whereIn('ra.resource_id', $resource_ids); |
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 共享时间查询 |
|
|
// 共享时间查询 |
|
|
@ -387,7 +406,7 @@ class ResourceSharingService extends BaseApiService |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
$model = $model->whereIn('ra.resource_id', $resource_ids); |
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -424,7 +443,7 @@ class ResourceSharingService extends BaseApiService |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
$model = $model->whereIn('ra.resource_id', $resource_ids); |
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -455,7 +474,7 @@ class ResourceSharingService extends BaseApiService |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
$model = $model->whereIn('ra.resource_id', $resource_ids); |
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -497,7 +516,63 @@ class ResourceSharingService extends BaseApiService |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
$model = $model->whereIn('ra.resource_id', $resource_ids); |
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 处理课程搜索查询 - 通过订单表关联课程表查询 |
|
|
|
|
|
if (!empty($where['course_search'])) { |
|
|
|
|
|
// 通过订单表关联查询包含指定课程的资源ID |
|
|
|
|
|
$order_model = new OrderTable(); |
|
|
|
|
|
|
|
|
|
|
|
// 先查询课程表中匹配的课程ID |
|
|
|
|
|
$course_ids = \app\model\school\Course::where('course_name', 'like', '%' . $where['course_search'] . '%') |
|
|
|
|
|
->column('course_id'); |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($course_ids)) { |
|
|
|
|
|
// 查询订单表中包含这些课程的订单 |
|
|
|
|
|
$course_resource_ids = $order_model->whereIn('course_id', $course_ids) |
|
|
|
|
|
->distinct(true) |
|
|
|
|
|
->column('resource_id'); |
|
|
|
|
|
|
|
|
|
|
|
if (empty($course_resource_ids)) { |
|
|
|
|
|
// 没有匹配的资源,返回空结果 |
|
|
|
|
|
return [ |
|
|
|
|
|
'count' => 0, |
|
|
|
|
|
'total' => 0, |
|
|
|
|
|
'current_page' => $page, |
|
|
|
|
|
'last_page' => 0, |
|
|
|
|
|
'data' => [] |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 没有匹配的课程,返回空结果 |
|
|
|
|
|
return [ |
|
|
|
|
|
'count' => 0, |
|
|
|
|
|
'total' => 0, |
|
|
|
|
|
'current_page' => $page, |
|
|
|
|
|
'last_page' => 0, |
|
|
|
|
|
'data' => [] |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($course_resource_ids)) { |
|
|
|
|
|
if (empty($resource_ids)) { |
|
|
|
|
|
$resource_ids = $course_resource_ids; |
|
|
|
|
|
} else { |
|
|
|
|
|
$resource_ids = array_intersect($resource_ids, $course_resource_ids); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (empty($resource_ids)) { |
|
|
|
|
|
return [ |
|
|
|
|
|
'count' => 0, |
|
|
|
|
|
'total' => 0, |
|
|
|
|
|
'current_page' => $page, |
|
|
|
|
|
'last_page' => 0, |
|
|
|
|
|
'data' => [] |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -531,28 +606,7 @@ class ResourceSharingService extends BaseApiService |
|
|
$resource_ids = array_column($list['data'], 'resource_id'); |
|
|
$resource_ids = array_column($list['data'], 'resource_id'); |
|
|
$resource_ids = array_unique(array_filter($resource_ids)); |
|
|
$resource_ids = array_unique(array_filter($resource_ids)); |
|
|
|
|
|
|
|
|
// 映射 legacy 表中的资源共享记录 ID,兼容旧接口依赖 |
|
|
// resource_sharing_id 现在直接使用 ResourceAssignment 表的 id,不需要映射 |
|
|
$resource_sharing_map = []; |
|
|
|
|
|
if (!empty($resource_ids)) { |
|
|
|
|
|
$legacy_records = $this->model |
|
|
|
|
|
->whereIn('resource_id', $resource_ids) |
|
|
|
|
|
->order('id', 'desc') |
|
|
|
|
|
->field('resource_id, id') |
|
|
|
|
|
->select() |
|
|
|
|
|
->toArray(); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($legacy_records as $record) { |
|
|
|
|
|
$resourceId = (int) ($record['resource_id'] ?? 0); |
|
|
|
|
|
$recordId = (int) ($record['id'] ?? 0); |
|
|
|
|
|
if ($resourceId === 0 || $recordId === 0) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (!isset($resource_sharing_map[$resourceId])) { |
|
|
|
|
|
$resource_sharing_map[$resourceId] = $recordId; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取分配人员ID列表 |
|
|
// 获取分配人员ID列表 |
|
|
$shared_by_ids = array_column($list['data'], 'assigned_by'); |
|
|
$shared_by_ids = array_column($list['data'], 'assigned_by'); |
|
|
$shared_by_ids = array_unique(array_filter($shared_by_ids)); |
|
|
$shared_by_ids = array_unique(array_filter($shared_by_ids)); |
|
|
@ -745,9 +799,8 @@ class ResourceSharingService extends BaseApiService |
|
|
|
|
|
|
|
|
// 处理每条数据 |
|
|
// 处理每条数据 |
|
|
foreach ($list['data'] as &$item) { |
|
|
foreach ($list['data'] as &$item) { |
|
|
$resourceId = (int) ($item['resource_id'] ?? 0); |
|
|
// resource_sharing_id 现在直接使用 ResourceAssignment 表的 id |
|
|
$legacyResourceSharingId = $resource_sharing_map[$resourceId] ?? null; |
|
|
$item['resource_sharing_id'] = (int) ($item['id'] ?? 0); |
|
|
$item['resource_sharing_id'] = $legacyResourceSharingId; |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($item['customerResource'])) { |
|
|
if (!empty($item['customerResource'])) { |
|
|
// 确保数据类型转换:数据库中的数值需要转换为字符串 |
|
|
// 确保数据类型转换:数据库中的数值需要转换为字符串 |
|
|
@ -759,9 +812,8 @@ class ResourceSharingService extends BaseApiService |
|
|
$item['customerResource']['source_channel'] = get_dict_value('SourceChannel', $source_channel_value); |
|
|
$item['customerResource']['source_channel'] = get_dict_value('SourceChannel', $source_channel_value); |
|
|
$item['customerResource']['campus_name'] = $campus_names[$item['customerResource']['campus']] ?? ''; |
|
|
$item['customerResource']['campus_name'] = $campus_names[$item['customerResource']['campus']] ?? ''; |
|
|
|
|
|
|
|
|
if ($legacyResourceSharingId !== null) { |
|
|
// customerResource 中的 resource_sharing_id 也使用 assignment 表的 id |
|
|
$item['customerResource']['resource_sharing_id'] = $legacyResourceSharingId; |
|
|
$item['customerResource']['resource_sharing_id'] = (int) ($item['id'] ?? 0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($item['customerResource']['consultant'])) { |
|
|
if (!empty($item['customerResource']['consultant'])) { |
|
|
$item['customerResource']['consultant_name'] = $consultant_names[$item['customerResource']['consultant']] ?? ''; |
|
|
$item['customerResource']['consultant_name'] = $consultant_names[$item['customerResource']['consultant']] ?? ''; |
|
|
@ -940,6 +992,16 @@ class ResourceSharingService extends BaseApiService |
|
|
$resource_conditions[] = ['source_channel', 'like', '%' . $where['source_channel'] . '%']; |
|
|
$resource_conditions[] = ['source_channel', 'like', '%' . $where['source_channel'] . '%']; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 年龄查询 |
|
|
|
|
|
if (isset($where['age']) && $where['age'] !== '' && $where['age'] !== null) { |
|
|
|
|
|
$resource_conditions[] = ['age', '=', $where['age']]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 黑名单状态查询 |
|
|
|
|
|
if (isset($where['blacklist']) && $where['blacklist'] !== '' && $where['blacklist'] !== null) { |
|
|
|
|
|
$resource_conditions[] = ['blacklist', '=', $where['blacklist']]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 查询符合条件的资源ID |
|
|
// 查询符合条件的资源ID |
|
|
$resource_ids = []; |
|
|
$resource_ids = []; |
|
|
if (!empty($resource_conditions)) { |
|
|
if (!empty($resource_conditions)) { |
|
|
@ -954,7 +1016,7 @@ class ResourceSharingService extends BaseApiService |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
$model = $model->whereIn('ra.resource_id', $resource_ids); |
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 共享时间查询 |
|
|
// 共享时间查询 |
|
|
@ -988,7 +1050,7 @@ class ResourceSharingService extends BaseApiService |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
$model = $model->whereIn('ra.resource_id', $resource_ids); |
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1025,7 +1087,7 @@ class ResourceSharingService extends BaseApiService |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
$model = $model->whereIn('ra.resource_id', $resource_ids); |
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1056,7 +1118,63 @@ class ResourceSharingService extends BaseApiService |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
$model = $model->whereIn('ra.resource_id', $resource_ids); |
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 处理课程搜索查询 - 通过订单表关联课程表查询 |
|
|
|
|
|
if (!empty($where['course_search'])) { |
|
|
|
|
|
// 通过订单表关联查询包含指定课程的资源ID |
|
|
|
|
|
$order_model = new OrderTable(); |
|
|
|
|
|
|
|
|
|
|
|
// 先查询课程表中匹配的课程ID |
|
|
|
|
|
$course_ids = \app\model\school\Course::where('course_name', 'like', '%' . $where['course_search'] . '%') |
|
|
|
|
|
->column('course_id'); |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($course_ids)) { |
|
|
|
|
|
// 查询订单表中包含这些课程的订单 |
|
|
|
|
|
$course_resource_ids = $order_model->whereIn('course_id', $course_ids) |
|
|
|
|
|
->distinct(true) |
|
|
|
|
|
->column('resource_id'); |
|
|
|
|
|
|
|
|
|
|
|
if (empty($course_resource_ids)) { |
|
|
|
|
|
// 没有匹配的资源,返回空结果 |
|
|
|
|
|
return [ |
|
|
|
|
|
'count' => 0, |
|
|
|
|
|
'total' => 0, |
|
|
|
|
|
'current_page' => $page, |
|
|
|
|
|
'last_page' => 0, |
|
|
|
|
|
'data' => [] |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 没有匹配的课程,返回空结果 |
|
|
|
|
|
return [ |
|
|
|
|
|
'count' => 0, |
|
|
|
|
|
'total' => 0, |
|
|
|
|
|
'current_page' => $page, |
|
|
|
|
|
'last_page' => 0, |
|
|
|
|
|
'data' => [] |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($course_resource_ids)) { |
|
|
|
|
|
if (empty($resource_ids)) { |
|
|
|
|
|
$resource_ids = $course_resource_ids; |
|
|
|
|
|
} else { |
|
|
|
|
|
$resource_ids = array_intersect($resource_ids, $course_resource_ids); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (empty($resource_ids)) { |
|
|
|
|
|
return [ |
|
|
|
|
|
'count' => 0, |
|
|
|
|
|
'total' => 0, |
|
|
|
|
|
'current_page' => $page, |
|
|
|
|
|
'last_page' => 0, |
|
|
|
|
|
'data' => [] |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
$model = $model->whereIn('resource_id', $resource_ids); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1102,6 +1220,7 @@ class ResourceSharingService extends BaseApiService |
|
|
$resource_ids = array_column($list['data'], 'resource_id'); |
|
|
$resource_ids = array_column($list['data'], 'resource_id'); |
|
|
$resource_ids = array_unique(array_filter($resource_ids)); |
|
|
$resource_ids = array_unique(array_filter($resource_ids)); |
|
|
|
|
|
|
|
|
|
|
|
// resource_sharing_id 现在直接使用 ResourceAssignment 表的 id,不需要映射 |
|
|
// 获取分配人员ID列表 |
|
|
// 获取分配人员ID列表 |
|
|
$shared_by_ids = array_column($list['data'], 'shared_by'); |
|
|
$shared_by_ids = array_column($list['data'], 'shared_by'); |
|
|
$shared_by_ids = array_unique(array_filter($shared_by_ids)); |
|
|
$shared_by_ids = array_unique(array_filter($shared_by_ids)); |
|
|
@ -1294,7 +1413,12 @@ class ResourceSharingService extends BaseApiService |
|
|
|
|
|
|
|
|
// 处理每条数据 |
|
|
// 处理每条数据 |
|
|
foreach ($list['data'] as &$item) { |
|
|
foreach ($list['data'] as &$item) { |
|
|
|
|
|
// resource_sharing_id 现在直接使用 ResourceAssignment 表的 id |
|
|
|
|
|
$item['resource_sharing_id'] = (int) ($item['id'] ?? 0); |
|
|
|
|
|
|
|
|
if (!empty($item['customerResource'])) { |
|
|
if (!empty($item['customerResource'])) { |
|
|
|
|
|
// customerResource 中的 resource_sharing_id 也使用 assignment 表的 id |
|
|
|
|
|
$item['customerResource']['resource_sharing_id'] = (int) ($item['id'] ?? 0); |
|
|
// 确保数据类型转换:数据库中的数值需要转换为字符串 |
|
|
// 确保数据类型转换:数据库中的数值需要转换为字符串 |
|
|
$source_value = (string) $item['customerResource']['source']; |
|
|
$source_value = (string) $item['customerResource']['source']; |
|
|
$source_channel_value = (string) $item['customerResource']['source_channel']; |
|
|
$source_channel_value = (string) $item['customerResource']['source_channel']; |
|
|
@ -1442,27 +1566,88 @@ class ResourceSharingService extends BaseApiService |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 兼容旧接口的资源分配方法 |
|
|
* 兼容旧接口的资源分配方法 |
|
|
* @param int $resource_sharing_id 旧表记录ID(实际为resource_id) |
|
|
* @param int $resource_sharing_id 现在是 ResourceAssignment 表的 ID |
|
|
* @param int $shared_by 分配给的用户ID |
|
|
* @param int $shared_by 分配给的用户ID |
|
|
* @return array |
|
|
* @return array |
|
|
*/ |
|
|
*/ |
|
|
public function assignResourceLegacy(int $resource_sharing_id, int $shared_by): array |
|
|
public function assignResourceLegacy(int $resource_sharing_id, int $shared_by): array |
|
|
{ |
|
|
{ |
|
|
// 首先检查旧表中的记录,获取resource_id |
|
|
// 检查 ResourceAssignment 表中是否存在该记录 |
|
|
$old_record = $this->model->where('id', $resource_sharing_id)->find(); |
|
|
$assignment_record = $this->assignmentModel->where('id', $resource_sharing_id)->find(); |
|
|
|
|
|
|
|
|
if (!$old_record) { |
|
|
if (!$assignment_record) { |
|
|
return [ |
|
|
return [ |
|
|
'code' => 0, |
|
|
'code' => 0, |
|
|
'msg' => '资源记录不存在', |
|
|
'msg' => '资源分配记录不存在', |
|
|
'data' => [] |
|
|
'data' => [] |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$resource_id = $old_record['resource_id']; |
|
|
$resource_id = $assignment_record['resource_id']; |
|
|
|
|
|
$campus_id = $assignment_record['campus_id']; |
|
|
|
|
|
|
|
|
// 使用新的分配方法 |
|
|
// 使用新的分配方法 |
|
|
return $this->assignResource($resource_id, 'user', $shared_by, true, $old_record['campus_id']); |
|
|
return $this->assignResource($resource_id, 'user', $shared_by, true, $campus_id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 确保资源的 resource_sharing_id 映射存在 |
|
|
|
|
|
* @param array $resource_ids 资源ID数组 |
|
|
|
|
|
* @return array resource_id => resource_sharing_id 的映射 |
|
|
|
|
|
*/ |
|
|
|
|
|
protected function ensureResourceSharingIdMap(array $resource_ids): array |
|
|
|
|
|
{ |
|
|
|
|
|
$resource_sharing_map = []; |
|
|
|
|
|
if (empty($resource_ids)) { |
|
|
|
|
|
return $resource_sharing_map; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 查询现有的 legacy 记录 |
|
|
|
|
|
$legacy_records = $this->model |
|
|
|
|
|
->whereIn('resource_id', $resource_ids) |
|
|
|
|
|
->order('id', 'desc') |
|
|
|
|
|
->field('resource_id, id') |
|
|
|
|
|
->select() |
|
|
|
|
|
->toArray(); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($legacy_records as $record) { |
|
|
|
|
|
$resourceId = (int) ($record['resource_id'] ?? 0); |
|
|
|
|
|
$recordId = (int) ($record['id'] ?? 0); |
|
|
|
|
|
if ($resourceId === 0 || $recordId === 0) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (!isset($resource_sharing_map[$resourceId])) { |
|
|
|
|
|
$resource_sharing_map[$resourceId] = $recordId; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 对于没有 legacy 记录的资源,自动创建或使用兜底方案 |
|
|
|
|
|
foreach ($resource_ids as $resource_id) { |
|
|
|
|
|
$resource_id = (int) $resource_id; |
|
|
|
|
|
if (!isset($resource_sharing_map[$resource_id])) { |
|
|
|
|
|
// 尝试创建一条新的 legacy 记录以确保兼容性 |
|
|
|
|
|
try { |
|
|
|
|
|
$new_legacy_record = [ |
|
|
|
|
|
'resource_id' => $resource_id, |
|
|
|
|
|
'user_id' => 0, |
|
|
|
|
|
'role_id' => 0, |
|
|
|
|
|
'shared_by' => 0, |
|
|
|
|
|
'shared_at' => date('Y-m-d H:i:s'), |
|
|
|
|
|
'created_at' => date('Y-m-d H:i:s'), |
|
|
|
|
|
'updated_at' => date('Y-m-d H:i:s') |
|
|
|
|
|
]; |
|
|
|
|
|
$inserted_id = $this->model->insertGetId($new_legacy_record); |
|
|
|
|
|
if ($inserted_id) { |
|
|
|
|
|
$resource_sharing_map[$resource_id] = (int) $inserted_id; |
|
|
|
|
|
} |
|
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
// 如果创建失败,使用 resource_id 作为兜底(确保总有值返回) |
|
|
|
|
|
$resource_sharing_map[$resource_id] = $resource_id; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $resource_sharing_map; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -1502,4 +1687,5 @@ class ResourceSharingService extends BaseApiService |
|
|
|
|
|
|
|
|
return $assignments; |
|
|
return $assignments; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|