server/app/Model/Message.php

62 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $message_id
* @property string $title
* @property string $content
* @property string $type
* @property string $extra
* @property int $recalled_flag
* @property int $create_id
* @property string $deleted_at
* @property string $create_time
* @property string $update_time
*/
class Message extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'message';
protected string $primaryKey = 'message_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['message_id' => 'integer', 'recalled_flag' => 'integer', 'create_id' => 'integer'];
/**
* 仅管理系统消息
* @param array $param
* @return \Hyperf\Contract\LengthAwarePaginatorInterface
*/
public static function list(array $param)
{
$model = self::query()->with(["account" => function ($query) {
$query->select(['account_id', 'username']);
}]);
if (isset($param['title']) && $param['title'] != '') {
$model = $model->where('title', "like", "%{$param['title']}%");
}
return $model->where("type", "system")
->orderByDesc("message_id")
->select(["message_id", "title", "content", "recalled_flag", "create_id", "create_time", "update_time"])
->paginate((int)$param['limit']);
}
public function account()
{
return $this->hasOne(Account::class, 'account_id', 'create_id');
}
}