fix: 修复会签场景下消息卡片更新问题

- 添加 updateMessageCardsForPartialApprove 方法处理会签部分通过
- 会签一人通过后,其他人的消息卡片显示进度并保留按钮
- 修复 Dockerfile 构建顺序问题
- 修复前端类型定义问题

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
root
2026-03-01 10:33:40 +08:00
parent 95375d9432
commit e13574f6f1
14 changed files with 1529 additions and 19 deletions
+37 -2
View File
@@ -110,8 +110,43 @@ class ApprovalService
]);
// 判断节点是否完成
if ($this->isNodeCompleted($order->id, $currentNode->id)) {
// 对于或签和单人审批,更新其他审批人的消息卡片
$nodeCompleted = $this->isNodeCompleted($order->id, $currentNode->id);
// 会签场景:即使节点未完成,也要更新其他审批人的消息卡片(显示进度)
if (!$nodeCompleted && $currentNode->type === ApprovalNode::TYPE_AND_APPROVE) {
$approver = User::find($approverId);
$approverName = $approver ? $approver->name : '未知';
// 获取已通过人数和总人数
$formData = $order->form_data ?? [];
$approvers = $formData['approvers'] ?? [];
if (!empty($approvers) && is_array($approvers[0] ?? null) && isset($approvers[0]['id'])) {
$approverIds = array_column($approvers, 'id');
} else {
$approverIds = $approvers;
}
$totalCount = count($approverIds);
$approvedRecords = ApprovalRecord::where('order_id', $order->id)
->where('node_id', $currentNode->id)
->where('action', 'approve')
->get();
$approvedCount = count($approvedRecords);
if ($this->notificationService) {
$this->notificationService->updateMessageCardsForPartialApprove(
$order->id,
$currentNode->id,
$approverId,
$approverName,
$approvedCount,
$totalCount
);
}
}
if ($nodeCompleted) {
// 节点完成:对于或签和单人审批,更新其他审批人的消息卡片
if ($currentNode->type === ApprovalNode::TYPE_OR_APPROVE || $currentNode->type === 'approver') {
$approver = User::find($approverId);
$approverName = $approver ? $approver->name : '未知';
@@ -789,6 +789,169 @@ class FeishuNotificationService
}
}
/**
* 更新会签节点的消息卡片(部分审批人已通过)
* 用于会签场景:一人通过后,更新其他人的消息卡片,显示等待其他人审批
*
* @param int $orderId 订单ID
* @param int $nodeId 节点ID
* @param int $excludeUserId 排除的用户ID(已经操作过的用户)
* @param string $operatorName 操作人姓名
* @param int $approvedCount 已通过人数
* @param int $totalCount 总审批人数
* @return bool
*/
public function updateMessageCardsForPartialApprove(int $orderId, int $nodeId, int $excludeUserId, string $operatorName, int $approvedCount, int $totalCount): bool
{
try {
// 获取该节点的所有消息(排除已操作的用户)
$messages = \app\model\FeishuMessage::where('order_id', $orderId)
->where('node_id', $nodeId)
->where('user_id', '!=', $excludeUserId)
->where('status', \app\model\FeishuMessage::STATUS_ACTIVE)
->get();
if ($messages->isEmpty()) {
error_log("📭 没有需要更新的消息: order_id={$orderId}, node_id={$nodeId}");
return true;
}
$token = $this->getAccessToken();
$remainingCount = $totalCount - $approvedCount;
foreach ($messages as $message) {
try {
// 构建更新后的卡片(保留操作按钮,但更新状态提示)
$updatedCard = [
'config' => [
'wide_screen_mode' => false,
],
'header' => [
'title' => [
'content' => '⏳ 会签进行中',
'tag' => 'plain_text',
],
'template' => 'blue',
],
'elements' => [
[
'tag' => 'div',
'text' => [
'content' => "**{$operatorName}** 已通过审批\n\n📊 进度: {$approvedCount}/{$totalCount} 人已通过,还剩 {$remainingCount} 人等待审批",
'tag' => 'lark_md',
],
],
[
'tag' => 'action',
'actions' => [
[
'tag' => 'button',
'text' => [
'content' => '通过',
'tag' => 'plain_text',
],
'type' => 'primary',
'size' => 'medium',
'value' => [
'action_type' => 'approve',
'order_id' => (int)$orderId,
],
],
[
'tag' => 'button',
'text' => [
'content' => '拒绝',
'tag' => 'plain_text',
],
'type' => 'danger',
'size' => 'medium',
'value' => [
'action_type' => 'reject',
'order_id' => (int)$orderId,
],
],
],
],
],
];
$requestData = [
'message_id' => $message->message_id,
'card' => $updatedCard,
'approved_count' => $approvedCount,
'total_count' => $totalCount,
];
$contentJson = json_encode($updatedCard, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$response = HttpClient::httpPostJson(
"https://open.feishu.cn/open-apis/im/v1/messages/{$message->message_id}/update",
[
'msg_type' => 'interactive',
'content' => $contentJson,
],
['content'],
[
'Authorization: Bearer ' . $token,
]
);
$code = $response['code'] ?? -1;
if ($code === 0) {
error_log("✅ 会签消息卡片更新成功: message_id={$message->message_id}, approved={$approvedCount}/{$totalCount}");
// 记录成功日志
\app\model\FeishuMessageLog::log(
\app\model\FeishuMessageLog::ACTION_UPDATE_CARD,
$orderId,
$nodeId,
$message->user_id,
$message->message_id,
\app\model\FeishuMessageLog::STATUS_SUCCESS,
$requestData,
$response
);
} else {
error_log("❌ 会签消息卡片更新失败: message_id={$message->message_id}, error=" . json_encode($response));
// 记录失败日志
\app\model\FeishuMessageLog::log(
\app\model\FeishuMessageLog::ACTION_UPDATE_CARD,
$orderId,
$nodeId,
$message->user_id,
$message->message_id,
\app\model\FeishuMessageLog::STATUS_FAILED,
$requestData,
$response,
$response['msg'] ?? 'Unknown error'
);
}
} catch (Exception $e) {
error_log("❌ 更新会签消息卡片异常: message_id={$message->message_id}, error=" . $e->getMessage());
// 记录异常日志
\app\model\FeishuMessageLog::log(
\app\model\FeishuMessageLog::ACTION_UPDATE_CARD,
$orderId,
$nodeId,
$message->user_id,
$message->message_id,
\app\model\FeishuMessageLog::STATUS_FAILED,
null,
null,
$e->getMessage()
);
}
}
return true;
} catch (Exception $e) {
error_log('❌ updateMessageCardsForPartialApprove 异常: ' . $e->getMessage());
return false;
}
}
/**
* 发送文本消息(用于自审批场景)
*/