Files
x-server-mobile/backend/app/model/FeishuMessage.php
T

79 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace app\model;
use support\Model;
/**
* 飞书审批消息映射模型
*/
class FeishuMessage extends Model
{
protected $table = 'feishu_message';
protected $fillable = [
'order_id',
'node_id',
'user_id',
'company_id',
'feishu_app_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,
?int $companyId = null,
?int $feishuAppId = null
): self {
return self::updateOrCreate(
[
'order_id' => $orderId,
'node_id' => $nodeId,
'user_id' => $userId,
],
[
'message_id' => $messageId,
'msg_token' => $msgToken,
'company_id' => $companyId,
'feishu_app_id' => $feishuAppId,
'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;
}
}