AuthService.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\admin\service;
  3. use app\common\model\AuthGroupAccessModel;
  4. use app\common\model\AuthGroupModel;
  5. use app\common\model\AuthRuleModel;
  6. class AuthService
  7. {
  8. public $authGroupModel;
  9. public $authGroupAccessModel;
  10. public $authRuleModel;
  11. public function __construct()
  12. {
  13. $this->authGroupModel = new AuthGroupModel();
  14. $this->authGroupAccessModel = new AuthGroupAccessModel();
  15. $this->authRuleModel = new AuthRuleModel();
  16. }
  17. public function loadRuleByGroupId(int $group_id) {
  18. $group = $this->authGroupModel->findById($group_id);
  19. if ($group) {
  20. $rules_str = $group->rules;
  21. return $this->authRuleModel->findByIds($rules_str == "*" ? ["*"] : explode(',', $rules_str));
  22. }
  23. return [];
  24. }
  25. public function loadRuleByAdminId(int $adminId) {
  26. $access = $this->authGroupAccessModel->findByAdminId($adminId);
  27. if ($access && $access->group_id > 0) {
  28. $group = $this->authGroupModel->findById($access->group_id);
  29. if ($group) {
  30. $rules_str = $group->rules;
  31. return $this->authRuleModel->findByIds($rules_str == "*" ? ["*"] : explode(',', $rules_str));
  32. }
  33. }
  34. return [];
  35. }
  36. }