fix: 修复审批功能和数据加载问题

- BusinessTripService 添加 ApprovalNode use 语句
- 修复 approve 方法中的字段引用错误(flow_id 替代 order_id)
- 修复 approve 方法中的类型引用错误(type 替代 node_type)
- getList 方法添加 approvalOrder 关联加载
- 完善审批逻辑:检查用户是否在当前节点审批人列表中
- 前后端联调测试通过

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-02-25 18:30:49 +08:00
parent 7c933bad16
commit e3e2843835
+9 -10
View File
@@ -6,6 +6,7 @@ use app\model\BusinessTrip;
use app\model\BusinessTripItinerary; use app\model\BusinessTripItinerary;
use app\model\ApprovalOrder; use app\model\ApprovalOrder;
use app\model\ApprovalFlow; use app\model\ApprovalFlow;
use app\model\ApprovalNode;
use app\model\ApprovalRecord; use app\model\ApprovalRecord;
use app\model\User; use app\model\User;
use support\Db; use support\Db;
@@ -160,7 +161,7 @@ class BusinessTripService
*/ */
public function getList(int $userId, string $type = 'my', int $page = 1, int $pageSize = 20): array public function getList(int $userId, string $type = 'my', int $page = 1, int $pageSize = 20): array
{ {
$query = BusinessTrip::with(['user', 'itineraries']); $query = BusinessTrip::with(['user', 'itineraries', 'approvalOrder']);
switch ($type) { switch ($type) {
case 'my': case 'my':
@@ -397,7 +398,7 @@ class BusinessTripService
$isApprover = false; $isApprover = false;
foreach ($currentNodes as $nodeId) { foreach ($currentNodes as $nodeId) {
$node = ApprovalNode::where('order_id', $approvalOrder->id) $node = ApprovalNode::where('flow_id', $approvalOrder->flow_id)
->where('id', $nodeId) ->where('id', $nodeId)
->first(); ->first();
@@ -405,13 +406,11 @@ class BusinessTripService
continue; continue;
} }
// 检查是否是单人审批节点 // 检查用户是否在审批人列表中
if ($node->node_type === 'single_approve') { $approvers = $node->approvers ?? [];
$approvers = $node->approvers ?? []; if (in_array($userId, $approvers)) {
if (in_array($userId, $approvers)) { $isApprover = true;
$isApprover = true; break;
break;
}
} }
} }
@@ -433,7 +432,7 @@ class BusinessTripService
ApprovalRecord::create([ ApprovalRecord::create([
'order_id' => $approvalOrder->id, 'order_id' => $approvalOrder->id,
'node_id' => $currentNodes[0] ?? 1, 'node_id' => $currentNodes[0] ?? 1,
'node_type' => 'single_approve', 'node_type' => 'approver',
'approver_id' => $userId, 'approver_id' => $userId,
'action' => $action, 'action' => $action,
'comment' => $comment, 'comment' => $comment,