|
@@ -0,0 +1,78 @@
|
|
|
+<?php
|
|
|
+namespace app\common\service;
|
|
|
+
|
|
|
+use app\admin\model\Admin;
|
|
|
+use app\admin\model\AuthGroupAccess;
|
|
|
+use app\admin\model\AuthRule;
|
|
|
+use traits\think\Instance;
|
|
|
+
|
|
|
+class SubService{
|
|
|
+ use Instance;
|
|
|
+ /** @var Admin */
|
|
|
+ protected $admin;
|
|
|
+ protected $chanId;
|
|
|
+ protected $rules=[];
|
|
|
+
|
|
|
+ public function __construct($chanId)
|
|
|
+ {
|
|
|
+ $this->chanId=$chanId;
|
|
|
+ $this->admin=Admin::get($chanId);
|
|
|
+ $this->getRules();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getRules(){
|
|
|
+ if($this->getAdminId()){
|
|
|
+ $groupRules=AuthGroupAccess::where((new AuthGroupAccess())->getTable().'.uid',$this->getAdminId())
|
|
|
+ ->join('auth_group',(new AuthGroupAccess())->getTable().'.group_id=auth_group.id')
|
|
|
+ ->group('auth_group.id')
|
|
|
+ ->column('auth_group.rules');
|
|
|
+ $rules=[];
|
|
|
+ foreach ($groupRules as $rule){
|
|
|
+ $rules=array_merge($rules,array_filter(explode(',',$rule)));
|
|
|
+ }
|
|
|
+ $this->rules=$rules;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return Admin
|
|
|
+ */
|
|
|
+ public function getAdmin()
|
|
|
+ {
|
|
|
+ return $this->admin;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getAdminId()
|
|
|
+ {
|
|
|
+ return $this->admin?$this->admin['id']:null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param mixed $chanId
|
|
|
+ */
|
|
|
+ public function setChanId($chanId)
|
|
|
+ {
|
|
|
+ $this->chanId = $chanId;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getChanId(){
|
|
|
+ return $this->chanId;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function hasSortPower(){
|
|
|
+ $id=$this->getRuleIdByName('mobile/mobile_sort');
|
|
|
+ return in_array($id,$this->rules);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getRuleIdByName($name){
|
|
|
+ static $names=[];
|
|
|
+ if(!isset($names[$name])){
|
|
|
+ $names[$name]=AuthRule::where('name',$name)->value('id',false);
|
|
|
+ }
|
|
|
+ return $names[$name];
|
|
|
+ }
|
|
|
+}
|