xxxrrrdddd 2 年之前
父节点
当前提交
ad48085340
共有 2 个文件被更改,包括 84 次插入11 次删除
  1. 6 11
      application/common.php
  2. 78 0
      application/common/service/SubService.php

+ 6 - 11
application/common.php

@@ -4,6 +4,7 @@
 
 use app\admin\model\Admin;
 use app\common\model\User;
+use app\common\service\SubService;
 use EasyWeChat\Factory;
 use Symfony\Component\VarExporter\VarExporter;
 use think\exception\HttpResponseException;
@@ -606,16 +607,10 @@ function buildUrl($url){
 }
 #分站ID
 function getChanId(){
+    return getSub()->getAdminId();
+}
+#分站
+function getSub(){
     $id=input('chanId/d');
-    if($id=='kuaishou'){
-        return false;
-    }
-    if(!$id){
-        return false;
-    }
-    $admin= Admin::get($id);
-    if(!$admin||!$admin['sub']){
-        return false;
-    }
-    return $admin['id'];
+    return SubService::instance($id);
 }

+ 78 - 0
application/common/service/SubService.php

@@ -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];
+    }
+}