fix: 完善审批流程错误处理和调试日志
主要修改: 1. 添加完整的 try-catch 错误处理 2. 添加 Transaction 开始/成功日志 3. 添加保存前后的状态日志 4. 捕获并记录任何异常 测试验证: - 审批流程正常执行 - 状态正确更新为 approved - 跳过 notify 节点直接完成 - "我已审批"列表正确返回数据 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -684,8 +684,10 @@ class BusinessTripService
|
|||||||
{
|
{
|
||||||
error_log("📝 approve() 开始: userId={$userId}, businessTripId={$businessTripId}, action={$action}");
|
error_log("📝 approve() 开始: userId={$userId}, businessTripId={$businessTripId}, action={$action}");
|
||||||
|
|
||||||
return $this->db->transaction(function () use ($userId, $businessTripId, $action, $comment) {
|
try {
|
||||||
$businessTrip = BusinessTrip::with(['itineraries', 'approvalOrder'])->findOrFail($businessTripId);
|
$result = $this->db->transaction(function () use ($userId, $businessTripId, $action, $comment) {
|
||||||
|
error_log("🔄 Transaction 开始");
|
||||||
|
$businessTrip = BusinessTrip::with(['itineraries', 'approvalOrder'])->findOrFail($businessTripId);
|
||||||
|
|
||||||
if (!$businessTrip->approval_order_id) {
|
if (!$businessTrip->approval_order_id) {
|
||||||
throw new \Exception('未找到审批单');
|
throw new \Exception('未找到审批单');
|
||||||
@@ -824,14 +826,27 @@ class BusinessTripService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_log("💾 准备保存: order_status={$approvalOrder->status}, trip_status={$businessTrip->status}");
|
||||||
|
|
||||||
$approvalOrder->save();
|
$approvalOrder->save();
|
||||||
$businessTrip->save();
|
$businessTrip->save();
|
||||||
|
|
||||||
|
error_log("✅ 保存完成: order_id={$approvalOrder->id}, trip_id={$businessTrip->id}");
|
||||||
|
|
||||||
// 发送审批结果通知
|
// 发送审批结果通知
|
||||||
$this->sendApprovalResultNotification($businessTrip, $action, $comment);
|
$this->sendApprovalResultNotification($businessTrip, $action, $comment);
|
||||||
|
|
||||||
|
error_log("✅ Transaction 成功,返回结果");
|
||||||
|
|
||||||
return $businessTrip->fresh(['itineraries', 'approvalOrder']);
|
return $businessTrip->fresh(['itineraries', 'approvalOrder']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
error_log("📝 approve() 完成: result_id=" . $result->id);
|
||||||
|
return $result;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
error_log("❌ approve() 异常: " . $e->getMessage() . " in " . $e->getFile() . ":" . $e->getLine());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user