|
|
@@ -249,64 +249,139 @@ class DingService extends Service
|
|
|
}
|
|
|
|
|
|
//待审核
|
|
|
+ public function getTodoProcessList1($data, $user)
|
|
|
+ {
|
|
|
+ // 1. 获取 AccessToken
|
|
|
+ [$success, $tokenData] = $this->getAccessToken($user['login_type']);
|
|
|
+ if (!$success) return [false, $tokenData];
|
|
|
+ $accessToken = $tokenData['access_token'];
|
|
|
+
|
|
|
+ // 2. 请求 URL (使用 TOP 接口)
|
|
|
+ $url = "https://oapi.dingtalk.com/topapi/processinstance/listids?access_token={$accessToken}";
|
|
|
+
|
|
|
+ // 3. 准备参数
|
|
|
+ // 注意:TOP 接口的分页叫 cursor (偏移量),从 0 开始
|
|
|
+ if(empty($data['page_index'])) {
|
|
|
+ $cursor = 0;
|
|
|
+ }else{
|
|
|
+ $cursor = ($data['page_index'] - 1) * $data['page_size'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $payload = [
|
|
|
+ 'userid' => $user['userid'],
|
|
|
+ 'cursor' => $cursor,
|
|
|
+ 'size' => (int)($data['page_size'] ?? 20),
|
|
|
+ 'process_code' => 'PROC-B31B268E-6B7E-417D-A103-8765D8AE9090'
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 4. 发送请求
|
|
|
+ $resp = $this->curlOpen1($url, [
|
|
|
+ 'request' => 'post',
|
|
|
+ 'json' => $payload
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $res = json_decode($resp, true);
|
|
|
+dd($res);
|
|
|
+ // 5. 错误处理 (TOP 接口 errcode 为 0 表示成功)
|
|
|
+ if (($res['errcode'] ?? -1) !== 0) {
|
|
|
+ return [false, "获取待审批列表失败: " . ($res['errmsg'] ?? '未知错误')];
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = $res['result'] ?? [];
|
|
|
+ $instanceIds = $result['list'] ?? [];
|
|
|
+ $nextCursor = $result['next_cursor'] ?? null;
|
|
|
+ $hasMore = !is_null($nextCursor);
|
|
|
+
|
|
|
+ if (empty($instanceIds)) {
|
|
|
+ return [true, ['list' => [], 'has_more' => false]];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 关联本地业务记录
|
|
|
+ // 因为 TOP 接口只给实例 ID,不给 TaskID,如果你本地需要 TaskID,
|
|
|
+ // 通常需要再通过单据详情接口获取,或者本地生成。
|
|
|
+ $records = Record::where('del_time', 0)
|
|
|
+ ->whereIn('process_instance_id', $instanceIds)
|
|
|
+ ->where('login_type', $user['login_type'])
|
|
|
+ ->select('type', 'order_number', 'process_instance_id')
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ $finalList = [];
|
|
|
+ foreach ($records as $item) {
|
|
|
+ $finalList[] = [
|
|
|
+ 'type' => $item->type,
|
|
|
+ 'type_title' => U8State::type_name[$item->type] ?? '未知',
|
|
|
+ 'order_number' => $item->order_number,
|
|
|
+ 'process_instance_id' => $item->process_instance_id,
|
|
|
+ 'task_id' => '' // TOP 列表接口不直接返回 taskId
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, [
|
|
|
+ 'list' => $finalList,
|
|
|
+ 'has_more' => $hasMore
|
|
|
+ ]];
|
|
|
+ }
|
|
|
+
|
|
|
public function getTodoProcessList($data, $user)
|
|
|
{
|
|
|
- // 获取 AccessToken
|
|
|
[$success, $tokenData] = $this->getAccessToken($user['login_type']);
|
|
|
if (!$success) return [false, $tokenData];
|
|
|
$accessToken = $tokenData['access_token'];
|
|
|
|
|
|
- // 新版接口分页参数(pageNumber 从 1 开始)
|
|
|
$pageNumber = $data['page_index'] ?? 1;
|
|
|
$pageSize = $data['page_size'] ?? 20;
|
|
|
|
|
|
- // 1. 请求 URL
|
|
|
- $url = "https://api.dingtalk.com/v1.0/workflow/processCentres/todoTasks?userId={$user['userid']}&pageNumber={$pageNumber}&pageSize={$pageSize}";
|
|
|
+ // 重点:加上 viewId=all
|
|
|
+ $url = "https://api.dingtalk.com/v1.0/workflow/processCentres/todoTasks?userId={$user['userid']}&pageNumber=1&pageSize=20";
|
|
|
+ $url = "https://api.dingtalk.com/v1.0/workflow/processes/todoTasks/numbers?userId={$user['userid']}";
|
|
|
|
|
|
- // 2. 发送请求
|
|
|
$resp = $this->curlOpen1($url, [
|
|
|
- 'request' => 'get', // 这个接口是 GET 请求
|
|
|
+ 'request' => 'get',
|
|
|
'header' => [
|
|
|
"Content-Type: application/json",
|
|
|
- "x-acs-dingtalk-access-token: {$accessToken}" // 新版标准的 Header 鉴权
|
|
|
+ "x-acs-dingtalk-access-token: {$accessToken}"
|
|
|
]
|
|
|
]);
|
|
|
|
|
|
$res = json_decode($resp, true);
|
|
|
|
|
|
- // 3. 错误处理
|
|
|
- if (isset($res['code']) && $res['code'] !== 'success') return [false, "获取新版待办列表失败: " . ($res['message'] ?? '未知错误')];
|
|
|
+ if (isset($res['code']) && $res['code'] !== 'success') {
|
|
|
+ return [false, "钉钉接口报错: " . ($res['message'] ?? '未知错误')];
|
|
|
+ }
|
|
|
|
|
|
- // 4. 提取实例 ID
|
|
|
- $result = $res['result'];
|
|
|
- $hasMore = $result['hasMore'];
|
|
|
- $tasks = $result['list'];
|
|
|
- $instanceIds = array_column($tasks, 'processInstanceId');
|
|
|
+ $result = $res['result'] ?? [];
|
|
|
+ $tasks = $result['list'] ?? [];
|
|
|
+ $hasMore = $result['hasMore'] ?? false;
|
|
|
|
|
|
- if (empty($instanceIds)) {
|
|
|
- return [true, [
|
|
|
- 'list' => [],
|
|
|
- 'has_more' => $hasMore,
|
|
|
- ]];
|
|
|
+ if (empty($tasks)) {
|
|
|
+ return [true, ['list' => [], 'has_more' => $hasMore]];
|
|
|
}
|
|
|
|
|
|
- $map = array_column($tasks,'taskId','processInstanceId');
|
|
|
+ // 提取实例ID
|
|
|
+ $instanceIds = array_column($tasks, 'processInstanceId');
|
|
|
+ // 建立 实例ID -> 任务ID 的映射
|
|
|
+ $taskMap = array_column($tasks, 'taskId', 'processInstanceId');
|
|
|
|
|
|
- // 5. 关联本地
|
|
|
- $record = Record::where('del_time',0)
|
|
|
+ // 关联本地业务表记录
|
|
|
+ $records = Record::where('del_time', 0)
|
|
|
->whereIn('process_instance_id', $instanceIds)
|
|
|
->where('login_type', $user['login_type'])
|
|
|
->select('type', 'order_number', 'process_instance_id')
|
|
|
- ->get()
|
|
|
- ->toArray();
|
|
|
-
|
|
|
- foreach ($record as $key => $item) {
|
|
|
- $record[$key]['type_title'] = U8State::type_name[$item['type']];
|
|
|
- $record[$key]['task_id'] = $map[$item['process_instance_id']];
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ $finalList = [];
|
|
|
+ foreach ($records as $item) {
|
|
|
+ $finalList[] = [
|
|
|
+ 'type' => $item->type,
|
|
|
+ 'type_title' => U8State::type_name[$item->type],
|
|
|
+ 'order_number' => $item->order_number,
|
|
|
+ 'process_instance_id' => $item->process_instance_id,
|
|
|
+ 'task_id' => $taskMap[$item->process_instance_id] ?? ''
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
return [true, [
|
|
|
- 'list' => $record,
|
|
|
+ 'list' => $finalList,
|
|
|
'has_more' => $hasMore
|
|
|
]];
|
|
|
}
|