fix: 完善审批流程调试日志
添加详细的调试日志来追踪审批流程: 1. approve() 方法开始时的参数日志 2. 节点类型和完成状态的日志 3. 下一节点查询和跳过逻辑的日志 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -682,6 +682,8 @@ class BusinessTripService
|
|||||||
*/
|
*/
|
||||||
public function approve(int $userId, int $businessTripId, string $action, string $comment = ''): BusinessTrip
|
public function approve(int $userId, int $businessTripId, string $action, string $comment = ''): BusinessTrip
|
||||||
{
|
{
|
||||||
|
error_log("📝 approve() 开始: userId={$userId}, businessTripId={$businessTripId}, action={$action}");
|
||||||
|
|
||||||
return $this->db->transaction(function () use ($userId, $businessTripId, $action, $comment) {
|
return $this->db->transaction(function () use ($userId, $businessTripId, $action, $comment) {
|
||||||
$businessTrip = BusinessTrip::with(['itineraries', 'approvalOrder'])->findOrFail($businessTripId);
|
$businessTrip = BusinessTrip::with(['itineraries', 'approvalOrder'])->findOrFail($businessTripId);
|
||||||
|
|
||||||
@@ -744,22 +746,28 @@ class BusinessTripService
|
|||||||
// 更新审批单状态
|
// 更新审批单状态
|
||||||
if ($action === 'reject') {
|
if ($action === 'reject') {
|
||||||
// 拒绝:直接结束流程
|
// 拒绝:直接结束流程
|
||||||
|
error_log("❌ 审批拒绝,结束流程");
|
||||||
$approvalOrder->status = ApprovalOrder::STATUS_REJECTED;
|
$approvalOrder->status = ApprovalOrder::STATUS_REJECTED;
|
||||||
$approvalOrder->current_nodes = [];
|
$approvalOrder->current_nodes = [];
|
||||||
$businessTrip->status = BusinessTrip::STATUS_REJECTED;
|
$businessTrip->status = BusinessTrip::STATUS_REJECTED;
|
||||||
} else {
|
} else {
|
||||||
|
error_log("✅ 审批同意,检查节点完成状态");
|
||||||
// 同意:检查当前节点是否完成,并处理流程流转
|
// 同意:检查当前节点是否完成,并处理流程流转
|
||||||
$nodeCompleted = false;
|
$nodeCompleted = false;
|
||||||
|
|
||||||
if ($currentNodeId) {
|
if ($currentNodeId) {
|
||||||
$node = ApprovalNode::find($currentNodeId);
|
$node = ApprovalNode::find($currentNodeId);
|
||||||
|
error_log("🔍 当前节点: id={$currentNodeId}, type=" . ($node ? $node->type : 'null'));
|
||||||
|
|
||||||
if ($node) {
|
if ($node) {
|
||||||
// 根据节点类型判断是否完成
|
// 根据节点类型判断是否完成
|
||||||
if ($node->type === 'approver') {
|
if ($node->type === 'approver') {
|
||||||
// 单人审批:一人通过即完成
|
// 单人审批:一人通过即完成
|
||||||
|
error_log("✅ 单人审批节点,一人通过即完成");
|
||||||
$nodeCompleted = true;
|
$nodeCompleted = true;
|
||||||
} elseif ($node->type === 'or_approve') {
|
} elseif ($node->type === 'or_approve') {
|
||||||
// 或签:一人通过即完成
|
// 或签:一人通过即完成
|
||||||
|
error_log("✅ 或签节点,一人通过即完成");
|
||||||
$nodeCompleted = true;
|
$nodeCompleted = true;
|
||||||
} elseif ($node->type === 'and_approve') {
|
} elseif ($node->type === 'and_approve') {
|
||||||
// 会签:需要所有人都通过
|
// 会签:需要所有人都通过
|
||||||
@@ -767,6 +775,7 @@ class BusinessTripService
|
|||||||
->where('node_id', $currentNodeId)
|
->where('node_id', $currentNodeId)
|
||||||
->where('action', 'approve')
|
->where('action', 'approve')
|
||||||
->count();
|
->count();
|
||||||
|
error_log("🔍 会签节点: approvedCount={$approvedCount}, totalApprovers=" . count($approverIds));
|
||||||
if ($approvedCount >= count($approverIds)) {
|
if ($approvedCount >= count($approverIds)) {
|
||||||
$nodeCompleted = true;
|
$nodeCompleted = true;
|
||||||
}
|
}
|
||||||
@@ -774,6 +783,8 @@ class BusinessTripService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_log("🔍 nodeCompleted: " . ($nodeCompleted ? 'true' : 'false'));
|
||||||
|
|
||||||
if ($nodeCompleted) {
|
if ($nodeCompleted) {
|
||||||
// 当前节点完成,查找下一个节点
|
// 当前节点完成,查找下一个节点
|
||||||
error_log("✅ 节点 {$currentNodeId} 已完成,查找下一节点");
|
error_log("✅ 节点 {$currentNodeId} 已完成,查找下一节点");
|
||||||
|
|||||||
Reference in New Issue
Block a user