|
|
@@ -242,6 +242,97 @@ class WorkFlowService extends Service
|
|
|
return [true, $instance->id];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取当前用户的已办(已处理)审核列表
|
|
|
+ */
|
|
|
+ public function getMyHandledApprovals($data, $user)
|
|
|
+ {
|
|
|
+ $userId = $user['id'];
|
|
|
+ $topDepartId = $user['top_depart_id'];
|
|
|
+
|
|
|
+ // 1. 构造查询对象
|
|
|
+ $model = WorkFlowInstancesNodes::where('del_time', 0)
|
|
|
+ ->where('top_depart_id', $topDepartId)
|
|
|
+ // 核心条件变更:
|
|
|
+ // 条件A:我是审批人之一
|
|
|
+ ->whereRaw('JSON_CONTAINS(assignees, JSON_OBJECT("id", ?))', [$userId])
|
|
|
+ // 条件B:包含我已经审批通过(1)或审批驳回(2)的情况
|
|
|
+ ->whereRaw('(JSON_CONTAINS(assignees, JSON_OBJECT("id", ?, "is_pass", 1)) OR JSON_CONTAINS(assignees, JSON_OBJECT("id", ?, "is_pass", 2)))', [$userId, $userId])
|
|
|
+ ->select('*')
|
|
|
+ ->orderBy('id', 'desc');
|
|
|
+
|
|
|
+ $pageData = $this->limit($model, '', $data);
|
|
|
+
|
|
|
+ if (empty($pageData['data'])) return [true, $pageData];
|
|
|
+
|
|
|
+ // 2. 提取当前页的所有流程实例 ID
|
|
|
+ $instanceIds = array_unique(array_column($pageData['data'], 'instance_id'));
|
|
|
+
|
|
|
+ // 3. 获取流程实例及其关联的模板
|
|
|
+ $instances = WorkFlowInstances::with(['template'])
|
|
|
+ ->whereIn('id', $instanceIds)
|
|
|
+ ->get()
|
|
|
+ ->keyBy('id');
|
|
|
+
|
|
|
+ // --- 处理动态业务单据数据 ---
|
|
|
+ // 4. 按业务类型分组,批量查出单据的 code 和 title
|
|
|
+ $documentGroups = [];
|
|
|
+ foreach ($instances as $ins) {
|
|
|
+ $documentGroups[$ins->document_type][] = $ins->document_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ $documentDataMap = []; // 存储结构: [type][id] => ['code' => ..., 'title' => ...]
|
|
|
+ foreach ($documentGroups as $type => $ids) {
|
|
|
+ $docs = DB::table($type)
|
|
|
+ ->whereIn('id', array_unique($ids))
|
|
|
+ ->select('id', 'code', 'title')
|
|
|
+ ->get()
|
|
|
+ ->keyBy('id')
|
|
|
+ ->toArray();
|
|
|
+ $documentDataMap[$type] = $docs;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 组装最终返回数据
|
|
|
+ foreach ($pageData['data'] as $key => $node) {
|
|
|
+ $instance = $instances[$node['instance_id']] ?? null;
|
|
|
+
|
|
|
+ // 获取关联业务表的具体数据
|
|
|
+ $docDetail = null;
|
|
|
+ if ($instance) {
|
|
|
+ $docDetail = $documentDataMap[$instance->document_type][$instance->document_id] ?? null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析出我个人的审批意见和审批时间
|
|
|
+ $assignees = is_string($node['assignees']) ? json_decode($node['assignees'], true) : $node['assignees'];
|
|
|
+ $mySnapshot = collect($assignees)->firstWhere('id', $userId);
|
|
|
+
|
|
|
+ $pageData['data'][$key] = [
|
|
|
+ 'node_instance_id' => $node['id'],
|
|
|
+ 'instance_id' => $node['instance_id'],
|
|
|
+ 'node_label' => $node['label'],
|
|
|
+ 'document_id' => $instance->document_id ?? 0,
|
|
|
+ 'document_type' => $instance->document_type ?? '',
|
|
|
+ 'document_code' => $docDetail->code ?? '', // 业务单据编号
|
|
|
+ 'document_title' => $docDetail->title ?? '', // 业务单据标题
|
|
|
+ 'workflow_title' => $instance->template->title ?? '', // 审批模板名
|
|
|
+ 'crt_time' => !empty($instance->crt_time->timestamp) ? date('Y-m-d H:i:s', $instance->crt_time->timestamp) : '',
|
|
|
+ 'approval_type' => $node['approval_type'],
|
|
|
+ 'approval_type_title'=> WorkFlowInstancesNodes::approval_type[$node['approval_type']] ?? '',
|
|
|
+
|
|
|
+ // --- 已办列表额外返回:我当时的处理结果 ---
|
|
|
+ 'my_handle_status' => $mySnapshot['is_pass'] ?? 0, // 我个人的处理状态:1-通过,2-驳回
|
|
|
+ 'my_handle_status_title' => WorkFlowInstancesNodes::is_pass_title[$mySnapshot['is_pass']] ?? '', // 我个人的处理状态:1-通过,2-驳回
|
|
|
+ 'my_handle_remark' => $mySnapshot['mark'] ?? '', // 我写下的审批意见
|
|
|
+ 'my_handle_time_fmt' => !empty($mySnapshot['pass_time']) ? date('Y-m-d H:i:s', $mySnapshot['pass_time']) : '', // 我的审批时间
|
|
|
+
|
|
|
+ // 整个流程目前的整体状态(方便前端展示:审批中、已通过、已驳回)
|
|
|
+ 'instance_status' => $instance->status ?? 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $pageData];
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取当前用户的待办审核列表
|
|
|
*/
|