SubService.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\common\service;
  3. use app\admin\model\Admin;
  4. use app\admin\model\AuthGroupAccess;
  5. use app\admin\model\AuthRule;
  6. use traits\think\Instance;
  7. class SubService{
  8. use Instance;
  9. /** @var Admin */
  10. protected $admin;
  11. protected $chanId;
  12. protected $rules=[];
  13. public function __construct($chanId)
  14. {
  15. $this->chanId=$chanId;
  16. $this->admin=Admin::get($chanId);
  17. $this->getRules();
  18. }
  19. protected function getRules(){
  20. if($this->getAdminId()){
  21. $groupRules=AuthGroupAccess::where((new AuthGroupAccess())->getTable().'.uid',$this->getAdminId())
  22. ->join('auth_group',(new AuthGroupAccess())->getTable().'.group_id=auth_group.id')
  23. ->group('auth_group.id')
  24. ->column('auth_group.rules');
  25. $rules=[];
  26. foreach ($groupRules as $rule){
  27. $rules=array_merge($rules,array_filter(explode(',',$rule)));
  28. }
  29. $this->rules=$rules;
  30. }
  31. }
  32. /**
  33. * @return Admin
  34. */
  35. public function getAdmin()
  36. {
  37. return $this->admin;
  38. }
  39. /**
  40. * @return mixed
  41. */
  42. public function getAdminId()
  43. {
  44. return $this->admin?$this->admin['id']:null;
  45. }
  46. /**
  47. * @param mixed $chanId
  48. */
  49. public function setChanId($chanId)
  50. {
  51. $this->chanId = $chanId;
  52. return $this;
  53. }
  54. public function getChanId(){
  55. return $this->chanId;
  56. }
  57. public function hasSortPower(){
  58. $id=$this->getRuleIdByName('mobile/mobile_sort');
  59. return in_array($id,$this->rules);
  60. }
  61. protected function getRuleIdByName($name){
  62. static $names=[];
  63. if(!isset($names[$name])){
  64. $names[$name]=AuthRule::where('name',$name)->value('id',false);
  65. }
  66. return $names[$name];
  67. }
  68. public function isFastHand(){
  69. return $this->chanId=='kuaishou';
  70. }
  71. }