server/app/Model/Post.php

59 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $post_id
* @property int $account_type
* @property int $belong_id
* @property string $post_name
* @property int $status
* @property int $rank
* @property string $create_time
* @property string $update_time
* @property string $deleted_at
*/
class Post extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'post';
protected string $primaryKey = 'post_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['post_id' => 'integer', 'account_type' => 'integer', 'belong_id' => 'integer', 'rank' => 'integer', 'status' => 'integer'];
public static function list(int $belong_id, int $account_type, string $post_name)
{
$model = self::where('belong_id', $belong_id)
->where('account_type', $account_type);
if ($post_name != '') {
$model = $model->where('post_name', "like", "%$post_name%");
}
return $model->orderByDesc("rank")->orderByDesc("post_id")
->select(["post_id", "post_name", "rank", "status", "create_time"])
->get()->toArray();
}
public static function options(int $belong_id, int $account_type)
{
return self::where('belong_id', $belong_id)
->where('account_type', $account_type)
->where("status",1)
->orderByDesc("rank")->orderByDesc("post_id")
->select(["post_id", "post_name"])
->get()->toArray();
}
}