|
|
@@ -219,4 +219,48 @@ class WorkFLowService extends Service
|
|
|
|
|
|
return [true, $instance->id];
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前用户的待办审核列表
|
|
|
+ */
|
|
|
+ public function getMyPendingApprovals($userId, $topDepartId)
|
|
|
+ {
|
|
|
+ // 1. 在节点实例表中查询
|
|
|
+ // 条件:公司隔离 + 状态为审批中(1) + 审批人JSON中包含当前用户ID
|
|
|
+ $pendingNodes = WorkFlowInstancesNodes::where('top_depart_id', $topDepartId)
|
|
|
+ ->where('status', 1) // 1 = 审批中
|
|
|
+ ->whereRaw('JSON_CONTAINS(assignees, JSON_OBJECT("id", ?))', [$userId])
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ if ($pendingNodes->isEmpty()) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 获取关联的实例信息和业务单据信息
|
|
|
+ // 建议在 Model 中定义好 belongsTo 关系
|
|
|
+ $instanceIds = $pendingNodes->pluck('instance_id')->unique();
|
|
|
+
|
|
|
+ $instances = WorkFlowInstances::with(['template']) // 关联查出模板名称等信息
|
|
|
+ ->whereIn('id', $instanceIds)
|
|
|
+ ->get()
|
|
|
+ ->keyBy('id');
|
|
|
+
|
|
|
+ // 3. 组装返回数据
|
|
|
+ $result = $pendingNodes->map(function ($node) use ($instances) {
|
|
|
+ $instance = $instances[$node->instance_id] ?? null;
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'node_instance_id' => $node->id, // 节点实例ID(审批接口要用)
|
|
|
+ 'instance_id' => $node->instance_id, // 流程实例ID
|
|
|
+ 'node_label' => $node->label, // 当前环节名称(如:财务审批)
|
|
|
+ 'document_id' => $instance->document_id ?? 0, // 业务单据ID
|
|
|
+ 'document_type' => $instance->document_type ?? '', // 业务模型
|
|
|
+ 'flow_title' => $instance->template->title ?? '未知流程',
|
|
|
+ 'apply_time' => $instance->crt_time ?? 0, // 发起时间
|
|
|
+ 'approval_type' => $node->approval_type, // 1会签/2或签
|
|
|
+ ];
|
|
|
+ });
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
}
|