| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?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();
- }
- /**
- * @param int $group_id
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- 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 [];
- }
- /**
- * @param int $adminId
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- 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 [];
- }
- }
|