feat: 优化飞书审批通知卡片,改用卡片回调机制
主要改动: - 去掉卡片中的备注输入框和表单元素 - 改为三个按钮(通过、拒绝、查看详情)横向排列在一行 - 通过/拒绝按钮使用卡片回调(value)而不是跳转 URL - 新增 FeishuCardController 处理飞书卡片回调 - 添加提示文字告知用户如需备注可去详情页操作 技术细节: - 按钮点击触发 card.action.trigger 事件 - 后端通过 FeishuCardController 处理回调 - 支持 url_verification 和 card.callback 两种事件类型 - 查看详情 URL 添加公司参数支持多租户 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -143,7 +143,7 @@ class FeishuNotificationService
|
||||
return false;
|
||||
}
|
||||
|
||||
$card = $this->buildApprovalCard($params);
|
||||
$card = $this->buildApprovalCard($params, $user->company_id);
|
||||
return $this->sendMessage($feishuUserId, $card);
|
||||
} catch (Exception $e) {
|
||||
error_log('❌ sendApprovalNotification 失败: ' . $e->getMessage());
|
||||
@@ -185,7 +185,7 @@ class FeishuNotificationService
|
||||
continue;
|
||||
}
|
||||
|
||||
$card = $this->buildSystemCard($params);
|
||||
$card = $this->buildSystemCard($params, $user->company_id);
|
||||
$results[$userId] = $this->sendMessage($feishuUserId, $card);
|
||||
} catch (Exception $e) {
|
||||
error_log("❌ sendSystemNotification 失败: user_id={$userId}, error=" . $e->getMessage());
|
||||
@@ -229,7 +229,7 @@ class FeishuNotificationService
|
||||
return false;
|
||||
}
|
||||
|
||||
$card = $this->buildReminderCard($params);
|
||||
$card = $this->buildReminderCard($params, $user->company_id);
|
||||
return $this->sendMessage($feishuUserId, $card);
|
||||
} catch (Exception $e) {
|
||||
error_log('❌ sendReminderNotification 失败: ' . $e->getMessage());
|
||||
@@ -276,7 +276,7 @@ class FeishuNotificationService
|
||||
/**
|
||||
* 构建审批通知卡片
|
||||
*/
|
||||
private function buildApprovalCard(array $params): array
|
||||
private function buildApprovalCard(array $params, int $recipientCompanyId): array
|
||||
{
|
||||
$title = $params['title'] ?? '新的审批申请';
|
||||
$applicant = $params['applicant'] ?? '未知';
|
||||
@@ -307,39 +307,58 @@ class FeishuNotificationService
|
||||
];
|
||||
}
|
||||
|
||||
// 操作按钮区域
|
||||
$actions = [];
|
||||
|
||||
// 如果有审批单ID,添加审批操作按钮(使用快速审批页面,无感操作)
|
||||
// 提示信息(如需备注请去详情页)
|
||||
if ($orderId) {
|
||||
// 通过按钮(绿色)- 快速审批页面
|
||||
$actions[] = [
|
||||
$elements[] = [
|
||||
'tag' => 'div',
|
||||
'text' => [
|
||||
'content' => "_如需添加备注,请点击「查看详情」进入详情页操作_",
|
||||
'tag' => 'lark_md',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// 按钮区域:三个按钮在一行
|
||||
$buttonActions = [];
|
||||
|
||||
// 通过按钮
|
||||
if ($orderId) {
|
||||
$buttonActions[] = [
|
||||
'tag' => 'button',
|
||||
'text' => [
|
||||
'content' => '✓ 通过',
|
||||
'content' => '通过',
|
||||
'tag' => 'plain_text',
|
||||
],
|
||||
'type' => 'primary',
|
||||
'size' => 'medium',
|
||||
'url' => "https://xsm.dev.hnxinyouhe.com/approval/quick-action?action=approve&order_id={$orderId}",
|
||||
'value' => [
|
||||
'action_type' => 'approve',
|
||||
'order_id' => $orderId,
|
||||
],
|
||||
];
|
||||
|
||||
// 拒绝按钮(红色)- 快速审批页面
|
||||
$actions[] = [
|
||||
// 拒绝按钮
|
||||
$buttonActions[] = [
|
||||
'tag' => 'button',
|
||||
'text' => [
|
||||
'content' => '✗ 拒绝',
|
||||
'content' => '拒绝',
|
||||
'tag' => 'plain_text',
|
||||
],
|
||||
'type' => 'danger',
|
||||
'size' => 'medium',
|
||||
'url' => "https://xsm.dev.hnxinyouhe.com/approval/quick-action?action=reject&order_id={$orderId}",
|
||||
'value' => [
|
||||
'action_type' => 'reject',
|
||||
'order_id' => $orderId,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// 查看详情按钮
|
||||
// 查看详情按钮(跳转链接)
|
||||
if ($url) {
|
||||
$actions[] = [
|
||||
$separator = strpos($url, '?') !== false ? '&' : '?';
|
||||
$urlWithCompany = $url . $separator . 'company=' . $recipientCompanyId;
|
||||
|
||||
$buttonActions[] = [
|
||||
'tag' => 'button',
|
||||
'text' => [
|
||||
'content' => '查看详情',
|
||||
@@ -347,14 +366,15 @@ class FeishuNotificationService
|
||||
],
|
||||
'type' => 'default',
|
||||
'size' => 'medium',
|
||||
'url' => $url,
|
||||
'url' => $urlWithCompany,
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($actions)) {
|
||||
// 将所有按钮放在一个 action 元素中(会横向排列)
|
||||
if (!empty($buttonActions)) {
|
||||
$elements[] = [
|
||||
'tag' => 'action',
|
||||
'actions' => $actions,
|
||||
'actions' => $buttonActions,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -376,7 +396,7 @@ class FeishuNotificationService
|
||||
/**
|
||||
* 构建系统通知卡片
|
||||
*/
|
||||
private function buildSystemCard(array $params): array
|
||||
private function buildSystemCard(array $params, int $recipientCompanyId): array
|
||||
{
|
||||
$title = $params['title'] ?? '系统通知';
|
||||
$content = $params['content'] ?? '';
|
||||
@@ -395,6 +415,10 @@ class FeishuNotificationService
|
||||
}
|
||||
|
||||
if ($url) {
|
||||
// 在 URL 后面添加公司参数
|
||||
$separator = strpos($url, '?') !== false ? '&' : '?';
|
||||
$urlWithCompany = $url . $separator . 'company=' . $recipientCompanyId;
|
||||
|
||||
$elements[] = [
|
||||
'tag' => 'action',
|
||||
'actions' => [
|
||||
@@ -405,7 +429,7 @@ class FeishuNotificationService
|
||||
'tag' => 'plain_text',
|
||||
],
|
||||
'type' => 'default',
|
||||
'url' => $url,
|
||||
'url' => $urlWithCompany,
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -429,7 +453,7 @@ class FeishuNotificationService
|
||||
/**
|
||||
* 构建提醒通知卡片
|
||||
*/
|
||||
private function buildReminderCard(array $params): array
|
||||
private function buildReminderCard(array $params, int $recipientCompanyId): array
|
||||
{
|
||||
$title = $params['title'] ?? '提醒';
|
||||
$content = $params['content'] ?? '';
|
||||
@@ -465,6 +489,10 @@ class FeishuNotificationService
|
||||
}
|
||||
|
||||
if ($url) {
|
||||
// 在 URL 后面添加公司参数
|
||||
$separator = strpos($url, '?') !== false ? '&' : '?';
|
||||
$urlWithCompany = $url . $separator . 'company=' . $recipientCompanyId;
|
||||
|
||||
$elements[] = [
|
||||
'tag' => 'action',
|
||||
'actions' => [
|
||||
@@ -475,7 +503,7 @@ class FeishuNotificationService
|
||||
'tag' => 'plain_text',
|
||||
],
|
||||
'type' => 'primary',
|
||||
'url' => $url,
|
||||
'url' => $urlWithCompany,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user