fix: 修复审批流程完成后状态更新问题
主要修改:
1. 修复下一节点查询逻辑,使用 order > currentOrder 替代 order > 0
2. 在 submit 和 approve 方法中跳过 notify 节点直接完成流程
3. 添加详细的调试日志
4. 兼容两种数据格式:[1,2,3] 或 [{id:1},{id:2},{id:3}]
修复问题:
- 审批完成后流程移到 notify 节点而不是完成
- business_trip status 没有更新为 approved
- "我已审批"列表为空
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -223,8 +223,12 @@ class BusinessTripService
|
||||
|
||||
// 如果节点完成,移动到下一节点
|
||||
if ($nodeCompleted) {
|
||||
// 获取当前节点的 order 值
|
||||
$currentOrder = $node->order ?? 0;
|
||||
|
||||
// 查找 order 比当前节点大的后续节点
|
||||
$nextNodes = ApprovalNode::where('flow_id', $flow->id)
|
||||
->where('order', '>', 0)
|
||||
->where('order', '>', $currentOrder)
|
||||
->orderBy('order')
|
||||
->get();
|
||||
|
||||
@@ -234,8 +238,17 @@ class BusinessTripService
|
||||
$approvalOrder->current_nodes = [];
|
||||
$businessTrip->status = BusinessTrip::STATUS_APPROVED;
|
||||
} else {
|
||||
// 移动到下一节点
|
||||
$approvalOrder->current_nodes = $nextNodes->pluck('id')->toArray();
|
||||
// 检查第一个后续节点
|
||||
$firstNextNode = $nextNodes->first();
|
||||
if ($firstNextNode && $firstNextNode->type === 'notify') {
|
||||
// 下一个是抄送节点,跳过并完成流程
|
||||
$approvalOrder->status = ApprovalOrder::STATUS_APPROVED;
|
||||
$approvalOrder->current_nodes = [];
|
||||
$businessTrip->status = BusinessTrip::STATUS_APPROVED;
|
||||
} else {
|
||||
// 移动到下一节点
|
||||
$approvalOrder->current_nodes = $nextNodes->pluck('id')->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
$approvalOrder->save();
|
||||
@@ -429,9 +442,21 @@ class BusinessTripService
|
||||
->pluck('order_id')
|
||||
->toArray();
|
||||
|
||||
error_log("🔍 'approved' query: userId={$userId}, approvedOrderIds=" . json_encode($approvedOrderIds));
|
||||
|
||||
if (empty($approvedOrderIds)) {
|
||||
$query->whereRaw('1 = 0'); // 返回空结果
|
||||
} else {
|
||||
// 先检查是否有匹配的 business_trip(不加载关系)
|
||||
$checkCount = BusinessTrip::whereIn('approval_order_id', $approvedOrderIds)->count();
|
||||
error_log("🔍 Matching business_trips count (without relations): {$checkCount}");
|
||||
|
||||
// 获取匹配的 business_trip IDs
|
||||
$matchingTrips = BusinessTrip::whereIn('approval_order_id', $approvedOrderIds)
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
error_log("🔍 Matching business_trip IDs: " . json_encode($matchingTrips));
|
||||
|
||||
$query->whereIn('approval_order_id', $approvedOrderIds);
|
||||
}
|
||||
break;
|
||||
@@ -751,24 +776,36 @@ class BusinessTripService
|
||||
|
||||
if ($nodeCompleted) {
|
||||
// 当前节点完成,查找下一个节点
|
||||
error_log("✅ 节点 {$currentNodeId} 已完成,查找下一节点");
|
||||
|
||||
// 获取当前节点的 order 值
|
||||
$currentOrder = $node->order ?? 0;
|
||||
error_log("📍 当前节点 order: {$currentOrder}");
|
||||
|
||||
// 查找 order 比当前节点大的下一个节点
|
||||
$nextNode = ApprovalNode::where('flow_id', $approvalOrder->flow_id)
|
||||
->where('order', '>', 0)
|
||||
->where('order', '>', $currentOrder)
|
||||
->orderBy('order')
|
||||
->first();
|
||||
|
||||
error_log("🔍 下一节点: " . ($nextNode ? "id={$nextNode->id}, type={$nextNode->type}, name={$nextNode->name}, order={$nextNode->order}" : "null"));
|
||||
|
||||
if ($nextNode) {
|
||||
// 有下一个节点
|
||||
if ($nextNode->type === 'notify') {
|
||||
// 下一个是抄送节点,跳过并完成流程
|
||||
error_log("⏭️ 跳过抄送节点,完成流程");
|
||||
$approvalOrder->status = ApprovalOrder::STATUS_APPROVED;
|
||||
$approvalOrder->current_nodes = [];
|
||||
$businessTrip->status = BusinessTrip::STATUS_APPROVED;
|
||||
} else {
|
||||
// 下一个是审批节点,移动到该节点
|
||||
error_log("➡️ 移动到下一节点: {$nextNode->id}");
|
||||
$approvalOrder->current_nodes = [$nextNode->id];
|
||||
}
|
||||
} else {
|
||||
// 没有下一个节点,流程完成
|
||||
error_log("✅ 没有下一节点,流程完成");
|
||||
$approvalOrder->status = ApprovalOrder::STATUS_APPROVED;
|
||||
$approvalOrder->current_nodes = [];
|
||||
$businessTrip->status = BusinessTrip::STATUS_APPROVED;
|
||||
|
||||
Reference in New Issue
Block a user