98 lines
3.1 KiB
PHP
98 lines
3.1 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Model;
|
||
|
||
|
||
|
||
use Hyperf\Database\Model\Collection;
|
||
use Hyperf\Snowflake\Concern\Snowflake;
|
||
|
||
/**
|
||
* @property int $message_id 主键id
|
||
* @property int $from_user_id 发送方user_id
|
||
* @property int $to_user_id 接收方user_id
|
||
* @property string $message_key 消息唯一标识(系统返回,撤回消息使用)
|
||
* @property string $message_send_time 消息发送时间戳
|
||
* @property int $message_seq 消息序列号(单聊消息优先使用 MsgTime 进行排序,同一秒发送的消息则按 MsgSeq 排序,MsgSeq 值越大消息越靠后)
|
||
* @property int $message_send_result 消息下发结果(0:失败 1:成功)
|
||
* @property string $send_error_info 消息下发失败原因
|
||
* @property string $message_type 消息类型(具体查看:https://cloud.tencent.com/document/product/269/2720)
|
||
* @property int $is_system 是否系统操作发送(0:否 1:是)
|
||
* @property int $order_inquiry_id 问诊id(自定义字段)
|
||
* @property string $message_content 消息内容(json形式)
|
||
* @property string $message_custom_content 自定义消息内容(json形式)
|
||
* @property \Carbon\Carbon $created_at 创建时间
|
||
* @property \Carbon\Carbon $updated_at 修改时间
|
||
*/
|
||
class MessageIm extends Model
|
||
{
|
||
use Snowflake;
|
||
|
||
/**
|
||
* The table associated with the model.
|
||
*/
|
||
protected ?string $table = 'message_im';
|
||
|
||
/**
|
||
* The attributes that are mass assignable.
|
||
*/
|
||
protected array $fillable = ['message_id', 'from_user_id', 'to_user_id', 'message_key', 'message_send_time', 'message_seq', 'message_send_result', 'send_error_info', 'message_type', 'is_system', 'order_inquiry_id', 'message_content', 'message_custom_content', 'created_at', 'updated_at'];
|
||
|
||
protected string $primaryKey = "message_id";
|
||
|
||
/**
|
||
* 获取是否存在
|
||
* @param array $params
|
||
* @return bool
|
||
*/
|
||
public static function getExists(array $params): bool
|
||
{
|
||
return self::where($params)->exists();
|
||
}
|
||
|
||
/**
|
||
* 获取信息-单条
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->first($fields);
|
||
}
|
||
|
||
/**
|
||
* 获取数据-多
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return Collection|array
|
||
*/
|
||
public static function getList(array $params = [], array $fields = ['*']): Collection|array
|
||
{
|
||
return self::where($params)->get($fields);
|
||
}
|
||
|
||
/**
|
||
* 新增
|
||
* @param array $data
|
||
* @return \Hyperf\Database\Model\Model|MessageIm
|
||
*/
|
||
public static function addMessage(array $data): \Hyperf\Database\Model\Model|MessageIm
|
||
{
|
||
return self::create($data);
|
||
}
|
||
|
||
/*
|
||
* 获取信息-最后一条
|
||
* @param array $params
|
||
* @param array $fields
|
||
* @return object|null
|
||
*/
|
||
public static function getLastOne(array $params, array $fields = ['*']): object|null
|
||
{
|
||
return self::where($params)->latest("created_at")->first($fields);
|
||
}
|
||
}
|