['name' => 'username', 'title' => '员工工号', 'type' => 'varchar', 'is_must' => '1'], 'nickname' => ['name' => 'nickname', 'title' => '员工姓名', 'type' => 'varchar', 'is_must' => '1'], 'password' => ['name' => 'password', 'title' => 'password', 'type' => 'varchar', 'is_must' => '1'], 'company_id' => ['name' => 'company_id', 'title' => '公司ID', 'type' => 'int', 'is_must' => '0'], 'group_id' => ['name' => 'group_id', 'title' => '岗位ID', 'type' => 'int', 'is_must' => '0'], 'phone' => ['name' => 'phone', 'title' => '联系电话', 'type' => 'bigint', 'is_must' => '0'], 'monthly_working_days' => ['name' => 'monthly_working_days', 'title' => '月工作天数', 'type' => 'int', 'is_must' => '0'], 'entry_date' => ['name' => 'entry_date', 'title' => '入职日期', 'type' => 'date', 'is_must' => '0'], 'official_date' => ['name' => 'official_date', 'title' => '转正日期', 'type' => 'date', 'is_must' => '0'], 'resign_date' => ['name' => 'resign_date', 'title' => '离职日期', 'type' => 'date', 'is_must' => '0'], 'probation_salary' => ['name' => 'probation_salary', 'title' => '试用工资', 'type' => 'decimal', 'is_must' => '0'], 'official_salary' => ['name' => 'official_salary', 'title' => '转正工资', 'type' => 'decimal', 'is_must' => '0'], 'is_outer' => ['name' => 'is_outer', 'title' => '外网登录', 'type' => 'tinyint', 'is_must' => '0'], 'status' => ['name' => 'status', 'title' => '员工状态', 'type' => 'tinyint', 'is_must' => '0'], 'rules' => ['name' => 'rules', 'title' => '规则id,多个规则 , 隔开', 'type' => 'varchar', 'is_must' => '0'], ]; /** * @inheritDoc */ public function getJWTIdentifier() { // TODO: Implement getJWTIdentifier() method. return $this->getKey(); } /** * @inheritDoc */ public function getJWTCustomClaims() { // TODO: Implement getJWTCustomClaims() method. return ['auth_list' => $this->getAuthList()]; } public function getAuthList() { $config = config('auth.conf'); $user_auth_ids = DB::table($config['auth_group']) ->where('id', $this->group_id) ->value('rules'); $ids = array_unique(explode(',', $user_auth_ids . ',' . $this->rules)); if (empty($ids)) { return array(); } //读取用户组所有权限规则 $rules = DB::table($config['auth_rule']) ->whereIn('id',$ids) ->where('status',1)->select(['condition','name','module','method'])->get(); //循环规则,判断结果。 $authList = array(); // foreach ($rules as $rule) { if (!empty($rule->condition)) { //根据condition进行验证 $command = preg_replace('/\{(\w*?)\}/', '$user[\'\\1\']', $rule->condition); $condition = false; @(eval('$condition=(' . $command . ');')); if ($condition) { $authList[] = strtolower($rule->module .'_'. $rule->method .'_'. $rule->name); } } else { //只要存在就记录 $authList[] = strtolower($rule->module .'_'. $rule->method .'_'. $rule->name); } } return array_unique($authList); } }