75 lines
1.7 KiB
PHP
75 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace app\common\model;
|
|
|
|
use support\Model;
|
|
|
|
class User extends Model
|
|
{
|
|
/**
|
|
* The connection name for the model.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
protected $connection = 'mysql';
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'user';
|
|
|
|
/**
|
|
* The primary key associated with the table.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $primaryKey = 'id';
|
|
|
|
/**
|
|
* Indicates if the model should be timestamped.
|
|
*
|
|
* @var bool
|
|
*/
|
|
public $timestamps = true;
|
|
|
|
|
|
protected $dateFormat = 'U';
|
|
|
|
/**
|
|
* 允许自动填充模型字段
|
|
*/
|
|
protected $fillable = ['id', 'password', 'name', 'email', 'mobile', 'avatar', 'sn', 'status', 'is_release', 'nickname', 'openid', 'unionid', 'created_at', 'updated_at'];
|
|
|
|
/**
|
|
* 不允许自动填充模型字段
|
|
*/
|
|
protected $guarded = [];
|
|
|
|
// 用户所有角色
|
|
public function roles()
|
|
{
|
|
return $this->belongsToMany(Role::class, 'user_roles', 'user_id', 'role_id');
|
|
}
|
|
|
|
// 用户直接拥有的资源(用于特殊补权)
|
|
public function resources()
|
|
{
|
|
return $this->belongsToMany(Resource::class, 'user_resources', 'user_id', 'resource_id')->orderBy('sort', 'asc');
|
|
}
|
|
|
|
// 用户可访问的系统
|
|
public function systems()
|
|
{
|
|
return $this->belongsToMany(Systems::class, 'user_systems', 'user_id', 'system_id');
|
|
}
|
|
|
|
// 账号查询的作用域
|
|
public function scopeByAccount($query, $account)
|
|
{
|
|
return $query->where('sn', $account)
|
|
->orWhere('mobile', $account)
|
|
->orWhere('email', $account);
|
|
}
|
|
} |