server/app/Model/Online.php

58 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $online_id
* @property string $session_id
* @property int $account_type
* @property int $belong_id
* @property int $account_id
* @property int $fd
* @property int $status
* @property string $ip
* @property string $ua
* @property string $online_time
* @property string $offline_time
*/
class Online extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'online';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['online_id' => 'integer', 'account_type' => 'integer', 'belong_id' => 'integer', 'account_id' => 'integer', 'fd' => 'integer', 'status' => 'integer'];
public static function list(array $param)
{
return self::where("status", 1)
->with(["account" => function ($query) {
$query->select(["account_id", "username", 'dept_id']);
}, "account.dept" => function ($query) {
$query->select(["dept_id", "dept_name"]);
}])
->when(isset($param['username']) && $param['username'] != '', function ($q) use ($param) {
$q->where('username', 'like', "%{$param['username']}%");
})
->orderByDesc("online_id")
->select(['session_id', 'username', 'ip', 'ua', 'online_time', 'account_id'])
->paginate((int)$param['limit']);
}
public function account()
{
return $this->hasOne(Account::class, 'account_id', 'account_id');
}
}