You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.0 KiB
90 lines
2.0 KiB
|
1 week ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||
|
|
use Laravel\Sanctum\HasApiTokens;
|
||
|
|
|
||
|
|
class AdminUser extends Authenticatable
|
||
|
|
{
|
||
|
|
use HasApiTokens;
|
||
|
|
use HasFactory;
|
||
|
|
use SoftDeletes;
|
||
|
|
|
||
|
|
protected $table = 'admin_users';
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'username',
|
||
|
|
'password_hash',
|
||
|
|
'real_name',
|
||
|
|
'mobile',
|
||
|
|
'email',
|
||
|
|
'avatar_url',
|
||
|
|
'status',
|
||
|
|
'last_login_at',
|
||
|
|
'last_login_ip',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $hidden = [
|
||
|
|
'password_hash',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'last_login_at' => 'datetime',
|
||
|
|
'status' => 'integer',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function getAuthPassword(): string
|
||
|
|
{
|
||
|
|
return $this->password_hash;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function roles(): BelongsToMany
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(Role::class, 'admin_user_roles', 'admin_user_id', 'role_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function universities(): BelongsToMany
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(
|
||
|
|
University::class,
|
||
|
|
'admin_user_universities',
|
||
|
|
'admin_user_id',
|
||
|
|
'university_id'
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function researchDirections(): BelongsToMany
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(
|
||
|
|
ResearchDirection::class,
|
||
|
|
'admin_user_research_directions',
|
||
|
|
'admin_user_id',
|
||
|
|
'research_direction_id'
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isGridMember(): bool
|
||
|
|
{
|
||
|
|
return $this->roles()->where('code', 'grid_member')->exists();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isSuperAdmin(): bool
|
||
|
|
{
|
||
|
|
return $this->roles()->where('code', 'super_admin')->exists();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 首期不在接口层使用权限码;返回空数组。后续启用 `permissions` 时再实现聚合逻辑。
|
||
|
|
*
|
||
|
|
* @return array<int, string>
|
||
|
|
*/
|
||
|
|
public function permissionCodes(): array
|
||
|
|
{
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
}
|