コード例 #1
0
ファイル: PowerCheck.php プロジェクト: smartgirl001/Test
 /**
  * 检查权限
  */
 public function power_check()
 {
     /**
      * var_dump(request()->method());
      *      string 'GET' (length=3)
      * var_dump(Route::currentRouteAction());
      *      string 'App\Http\Controllers\Admin\GroupController@get_list' (length=51)
      */
     // route
     $route = Route::currentRouteAction();
     $temp_r = explode('@', $route);
     $temp_ctl = explode('\\', $temp_r[0]);
     // controller acction method
     $controller = end($temp_ctl);
     // controller
     $action = end($temp_r);
     // action
     $method = request()->method();
     // method
     // delete temp var
     unset($temp_r);
     unset($temp_ctl);
     $oAdmin = Admin::findOrFail(session('admin_id'));
     $oGroups = AdminGroup::whereIn('id', json_decode($oAdmin->groups))->get();
     $oPowers = Power::where('controller', $controller)->where('action', $action)->get();
     $aPowers = array_column($oPowers->toArray(), 'method', 'id');
     /**
      * 选出继续操作需要的权限ID
      */
     $iNeedPower = null;
     // id
     foreach ($aPowers as $key => $value) {
         if ($value === $method || $value === '') {
             $iNeedPower = $key;
             break;
         }
     }
     if ($iNeedPower === null) {
         // 没有此权限记录
         return False;
     }
     /**
      * 检查用户所属的组中有没有拥有这种权限的组
      */
     $flag = False;
     foreach ($oGroups as $oGroup) {
         $powers = json_decode($oGroup->power);
         $powers = empty($powers) ? array() : $powers;
         if (in_array($iNeedPower, $powers)) {
             $flag = True;
             break;
         }
     }
     return $flag;
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AdminGroup::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'create_time' => $this->create_time, 'update_time' => $this->update_time]);
     $query->andFilterWhere(['like', 'group_name', $this->group_name])->andFilterWhere(['like', 'model', $this->model])->andFilterWhere(['like', 'create_user', $this->create_user])->andFilterWhere(['like', 'update_user', $this->update_user]);
     return $dataProvider;
 }
コード例 #3
0
 /**
  * Finds the AdminGroup model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return AdminGroup the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = AdminGroup::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #4
0
ファイル: Admin.php プロジェクト: smartgirl001/Test
 public static function get_groups_info($adminid = null)
 {
     $adminid = $adminid ? $adminid : session('admin_id');
     $aGroups = self::get_groups($adminid);
     return AdminGroup::whereIn('id', $aGroups)->get()->toArray();
 }