| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace app\admin\service;
- use app\common\model\AuthGroupAccessModel;
- use app\common\model\AuthGroupModel;
- use app\common\model\AuthRuleModel;
- class AuthService
- {
- public $authGroupModel;
- public $authGroupAccessModel;
- public $authRuleModel;
- public function __construct()
- {
- $this->authGroupModel = new AuthGroupModel();
- $this->authGroupAccessModel = new AuthGroupAccessModel();
- $this->authRuleModel = new AuthRuleModel();
- }
- public function loadRuleByGroupId(int $group_id) {
- $group = $this->authGroupModel->findById($group_id);
- if ($group) {
- $rules_str = $group->rules;
- return $this->authRuleModel->findByIds($rules_str == "*" ? ["*"] : explode(',', $rules_str));
- }
- return [];
- }
- public function loadRuleByAdminId(int $adminId) {
- $access = $this->authGroupAccessModel->findByAdminId($adminId);
- if ($access && $access->group_id > 0) {
- $group = $this->authGroupModel->findById($access->group_id);
- if ($group) {
- $rules_str = $group->rules;
- return $this->authRuleModel->findByIds($rules_str == "*" ? ["*"] : explode(',', $rules_str));
- }
- }
- return [];
- }
- }
|