This commit is contained in:
molong
2022-05-24 16:10:50 +08:00
parent a37870c93b
commit d8e43f9e93
63 changed files with 2169 additions and 230 deletions

49
app/model/auth/Users.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\model\auth;
use app\model\BaseModel;
use think\facade\Config;
use xiaodi\JWTAuth\Facade\Jwt;
class Users extends BaseModel{
public $pk = 'uid';
public function getTokenAttr($value, $data){
$token = Jwt::store('api')->token($data)->__toString();
return $token;
}
public function scopeAuth($query, $where = []){
$auth = request()->auth();
$uid = request()->user['uid'];
$map = [];
// if(!in_array($uid, Config::get('auth.admin_root'))){
// if($auth['data_range'] == 2){
// $map[] = ['uid', '=', $uid];//只能看自己
// }elseif($auth['data_range'] == 3){
// $map[] = ['department_id', '=', $auth['department_id']]; //查自己所在部门
// }elseif($auth['data_range'] == 4){
// $map[] = ['department_id', 'IN', getDepartmentChild($auth['department_id'])]; //部门及以下数据
// }
// }
$query->where($query)->where($where);
}
public function roles(){
return $this->belongsToMany(Roles::class, RolesAccess::class, 'role_id', 'uid');
}
public function department(){
return $this->hasOne(Departments::class, 'id', 'department_id')->bind([
'department_name' => 'title'
]);
}
}