Files
fdesk/app/common/model/User.php
T
2025-07-11 18:01:23 +08:00

95 lines
2.0 KiB
PHP

<?php
namespace app\common\model;
use support\Model;
/**
* users 用户表
* @property integer $id 用户ID(主键)
* @property string $sn 编号
* @property string $name 姓名
* @property string $avatar 头像
* @property string $password 密码
* @property string $phone 手机
* @property string $email 邮箱
* @property integer $status 状态
* @property string $system_code 系统码
* @property string $created_at
* @property string $updated_at
*/
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 = [
'sn',
'name',
'avatar',
'password',
'phone',
'email',
'status',
'corp_id',
'user_type',
'union_id',
'user_id',
'open_id',
'tenant_key'
];
// 用户所有角色
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');
}
// 用户可访问的系统
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('phone', $account)
->orWhere('email', $account);
}
}