Files
x-server-mobile/backend/app/model/FeishuMessage.php
T
root 1f72da9ec4 feat: 添加消息卡片更新功能,支持或签/单人审批场景
新增功能:
1. 创建 feishu_message 表,存储消息与审批订单/节点/用户的映射关系
2. 发送审批通知时保存 message_id
3. 审批完成后自动更新其他审批人的消息卡片

使用场景:
- 或签(or_approve):一人通过后,更新其他审批人的消息卡片
- 单人审批(approver):一人通过后,更新其他审批人的消息卡片
- 拒绝(reject):拒绝后更新所有其他审批人的消息卡片

技术细节:
- FeishuMessage 模型:管理消息映射
- FeishuNotificationService::updateMessageCards():更新消息卡片
- ApprovalService:审批完成后调用消息更新逻辑

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 18:06:40 +08:00

73 lines
1.6 KiB
PHP

<?php
namespace app\model;
use support\Model;
/**
* 飞书审批消息映射模型
*/
class FeishuMessage extends Model
{
protected $table = 'feishu_message';
protected $fillable = [
'order_id',
'node_id',
'user_id',
'message_id',
'msg_token',
'status',
];
const STATUS_ACTIVE = 'active';
const STATUS_UPDATED = 'updated';
const STATUS_DELETED = 'deleted';
/**
* 根据订单和节点获取消息列表
*/
public static function getMessagesByOrderAndNode(int $orderId, int $nodeId): array
{
return self::where('order_id', $orderId)
->where('node_id', $nodeId)
->where('status', self::STATUS_ACTIVE)
->get()
->toArray();
}
/**
* 保存消息映射
*/
public static function saveMessage(
int $orderId,
int $nodeId,
int $userId,
string $messageId,
?string $msgToken = null
): self {
return self::updateOrCreate(
[
'order_id' => $orderId,
'node_id' => $nodeId,
'user_id' => $userId,
],
[
'message_id' => $messageId,
'msg_token' => $msgToken,
'status' => self::STATUS_ACTIVE,
]
);
}
/**
* 标记消息为已更新
*/
public static function markAsUpdated(int $orderId, int $nodeId): bool
{
return self::where('order_id', $orderId)
->where('node_id', $nodeId)
->update(['status' => self::STATUS_UPDATED]) > 0;
}
}