浏览代码

给代理的权限

lizhen_gitee 1 年之前
父节点
当前提交
0cd9c2a265

+ 1 - 4
application/admin/controller/Banner.php

@@ -52,10 +52,7 @@ class Banner extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['banner.company_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('banner');
 
             $list = $this->model
                     ->with(['company'])

+ 1 - 4
application/admin/controller/Company.php

@@ -52,10 +52,7 @@ class Company extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['company.id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('company');
 
             $list = $this->model
                     ->with(['wallet'])

+ 1 - 4
application/admin/controller/CompanyBank.php

@@ -51,10 +51,7 @@ class CompanyBank extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['company_bank.company_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('company_bank');
 
             $list = $this->model
                     ->with(['company'])

+ 1 - 4
application/admin/controller/CompanyStaff.php

@@ -57,10 +57,7 @@ class CompanyStaff extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['company_staff.company_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('company_staff');
 
             $list = $this->model
                     ->with(['company'])

+ 1 - 4
application/admin/controller/CompanyTakeCash.php

@@ -51,10 +51,7 @@ class CompanyTakeCash extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['company_take_cash.user_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('company_take_cash');
 
             $list = $this->model
                     ->with(['company'])

+ 4 - 0
application/admin/controller/Companycomment.php

@@ -50,9 +50,13 @@ class Companycomment extends Backend
             }
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
+            //只能看自己的
+            $where_op = $this->whereop('companycomment');
+
             $list = $this->model
                     ->with(['user','company'])
                     ->where($where)
+                    ->where($where_op)
                     ->order($sort, $order)
                     ->paginate($limit);
 

+ 1 - 4
application/admin/controller/Companymoneylog.php

@@ -51,10 +51,7 @@ class Companymoneylog extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['companymoneylog.user_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('companymoneylog');
 
             $list = $this->model
                     ->with(['company'])

+ 2 - 4
application/admin/controller/Coupons.php

@@ -49,10 +49,8 @@ class Coupons extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['coupons.company_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('coupons');
+
 
             $list = $this->model->with(['company'])
                 ->where($where)

+ 1 - 4
application/admin/controller/Order.php

@@ -54,10 +54,7 @@ class Order extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['order.company_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('order');
 
             $list = $this->model
                     ->with(['company','staff','user','preorder','servicetype'])

+ 1 - 4
application/admin/controller/Package.php

@@ -57,10 +57,7 @@ class Package extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['package.company_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('package');
 
             $list = $this->model
                     ->with(['company','servicetype'])

+ 1 - 4
application/admin/controller/Preorder.php

@@ -52,10 +52,7 @@ class Preorder extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['preorder.company_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('preorder');
 
             $list = $this->model
                     ->with(['company','user','servicetype','order'])

+ 1 - 4
application/admin/controller/RechargeConfig.php

@@ -51,10 +51,7 @@ class RechargeConfig extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['recharge_config.company_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('recharge_config');
 
             $list = $this->model
                     ->with(['company'])

+ 1 - 4
application/admin/controller/UserCouponsLog.php

@@ -51,10 +51,7 @@ class UserCouponsLog extends Backend
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
 
             //只能看自己的
-            $where_op = [];
-            if($this->auth->company_id){
-                $where_op['user_coupons_log.company_id'] = $this->auth->company_id;
-            }
+            $where_op = $this->whereop('user_coupons_log');
 
             $list = $this->model
                     ->with(['company','user','coupons','staff'])

+ 21 - 0
application/common/controller/Backend.php

@@ -12,6 +12,7 @@ use think\Model;
 use think\Session;
 use fast\Tree;
 use think\Validate;
+use think\Db;
 
 /**
  * 后台控制器基类
@@ -230,6 +231,26 @@ class Backend extends Controller
         $this->assign('admin', Session::get('admin'));
     }
 
+    protected function whereop($alias = ''){
+
+        $where_op = [];
+
+        $group_id = Db::name('auth_group_access')->where('uid',$this->auth->id)->value('group_id');
+
+        if($group_id == 9){ //分公司
+            $company_ids = Db::name('company')->where('agent_id',$this->auth->id)->column('id');
+            if(!empty($company_ids)){
+                $where_op[$alias.'.id'] = ['IN',$company_ids];
+            }
+        }
+        if($group_id == 6 || $group_id == 7){ //老板或员工
+            if($this->auth->company_id){
+                $where_op[$alias.'.id'] = $this->auth->company_id;
+            }
+        }
+        return $where_op;
+    }
+
     /**
      * 加载语言文件
      * @param string $name