Exemple #1
0
 public function scenarios()
 {
     $scenarios = parent::scenarios();
     $scenarios['create'] = ['tabId', 'fieldText', 'fieldName', 'dataType', 'menuId', 'gridNumber', 'isQuery', 'reName', 'makeTbName'];
     $scenarios['update'] = ['tabId', 'fieldText', 'fieldName', 'dataType', 'menuId', 'gridNumber', 'isQuery', 'reName', 'makeTbName'];
     $scenarios['search'] = ['tabId', 'fieldText', 'fieldName', 'dataType', 'menuId', 'gridNumber', 'isQuery', 'reName', 'makeTbName'];
     return $scenarios;
 }
 public function actionIndex()
 {
     $request = Yii::$app->request;
     $menuId = 31;
     $theadArray = QueryField::find()->where(['menuId' => $menuId])->asArray()->with('queryTable')->all();
     $tables = QueryTable::find()->where(['menuId' => $menuId])->asArray()->all();
     $masterTable = $this->getMasterTable($tables);
     if (!$masterTable) {
         $NullPages = new Pagination(['pageParam' => 'pageCurrent', 'pageSizeParam' => 'pageSize', 'totalCount' => 0, 'defaultPageSize' => 20]);
         return $this->render('index', ['models' => [], 'pages' => $NullPages, 'theadArray' => []]);
     }
     $query = new Query();
     $query->from($masterTable['tabName']);
     $query->select($masterTable['tabName'] . '.' . 'id');
     foreach ($tables as $table) {
         if ($table['isMain'] != '1') {
             $query->leftJoin($table['tabName'], $table['condition']);
         }
     }
     //排序字段
     $attributes = [];
     //查询条件
     $where = [];
     foreach ($theadArray as $thead) {
         if ($thead['queryTable']['reName']) {
             $addSelect = $thead['queryTable']['reName'];
         } else {
             $addSelect = $thead['queryTable']['tabName'];
         }
         $addSelect = $addSelect . '.' . $thead['fieldName'];
         if ($thead['makeTbName'] != 1) {
             $addSelect = $thead['fieldName'];
         }
         if ($thead['reName']) {
             //组装排序字段
             array_push($attributes, $thead['reName']);
             //查询字段
             $addSelect = $addSelect . ' ' . 'as' . ' ' . $thead['reName'];
         } else {
             array_push($attributes, $thead['fieldName']);
         }
         $query->addSelect($addSelect);
         //组装查询条件
         if ($thead['isQuery'] == '1' && $thead['reName']) {
             $where[$thead['reName']] = $request->get($thead['reName']);
         } elseif ($thead['isQuery'] == '1') {
             $where[$thead['fieldName']] = $request->get($thead['fieldName']);
         }
     }
     $query->where($where);
     $pages = new Pagination(['pageParam' => 'pageCurrent', 'pageSizeParam' => 'pageSize', 'defaultPageSize' => 20]);
     $sort = new WetSort(['attributes' => $attributes]);
     $provider = new ActiveDataProvider(['query' => $query, 'pagination' => $pages, 'sort' => $sort]);
     $models = $provider->getModels();
     return $this->render('index', ['models' => $models, 'pages' => $pages, 'theadArray' => $theadArray]);
 }
Exemple #3
0
<?php

use common\models\QueryField;
$searchUrl = "index";
$menuId = 41;
$theadArray = QueryField::find()->where(['menuId' => $menuId])->asArray()->all();
include dirname(dirname(__FILE__)) . "/TplSearch.php";
 public function actionDeletefield($menuId)
 {
     $jsonData = Yii::$app->request->post()['json'];
     $attributes = json_decode($jsonData, true);
     $fields = QueryField::find()->where(['menuId' => $menuId, 'gridNumber' => $attributes[0]['gridNumber']])->one();
     if ($fields->delete()) {
         return $this->ok('删除成功');
     } else {
         return $this->error('删除失败');
     }
 }