Files
fdesk/app/common/model/User.php
T

101 lines
2.2 KiB
PHP
Raw Normal View History

2025-07-01 19:39:13 +08:00
<?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 系统码
2025-08-14 20:08:57 +08:00
* @property string $report_to 上级用户ID
* @property string $created_at
2025-07-01 19:39:13 +08:00
* @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',
2025-07-18 10:04:54 +08:00
'sex',
2025-07-01 19:39:13 +08:00
'password',
'phone',
'email',
'status',
2025-07-11 15:21:00 +08:00
'corp_id',
'user_type',
'union_id',
'user_id',
'open_id',
2025-07-18 10:04:54 +08:00
'tenant_key',
'country_id',
'position',
'socialize',
'socialize_pic',
2025-08-14 20:08:57 +08:00
'report_to',
2025-07-01 19:39:13 +08:00
];
// 用户所有角色
public function roles()
{
return $this->belongsToMany(Role::class, 'user_roles', 'user_id', 'role_id');
}
// 用户直接拥有的资源(用于特殊补权)
public function resources()
{
2025-07-13 22:07:55 +08:00
return $this->belongsToMany(Resource::class, 'user_resources', 'user_id', 'resource_id')->orderBy('sort', 'asc');
2025-07-01 19:39:13 +08:00
}
// 用户可访问的系统
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);
}
2025-07-23 18:41:47 +08:00
}