コード例 #1
0
ファイル: TableForm.php プロジェクト: mademingshiwo/todolist
 public function save()
 {
     if (is_numeric($this->id)) {
         $table = TbTable::findOne($this->id);
     } else {
         $table = new TbTable();
     }
     $table->fdName = $this->name;
     $table->fdText = $this->text;
     $table->fdSubText = $this->sub_text;
     $table->fdClass = $this->class;
     $table->fdDirection = $this->direction;
     $table->fdCondition = $this->condition;
     $table->fdLimit = 0 + $this->limit;
     $table->fdSummary = $this->summary;
     $table->fdSummaryGroup = $this->summary_group;
     $table->fdSummaryOrder = $this->summary_order;
     $table->fdSummaryLimit = $this->summary_limit;
     if (!$table->save()) {
         echo json_encode(['code' => -1, 'msg' => json_encode($table->errors, JSON_UNESCAPED_UNICODE)]);
         return false;
     }
     echo json_encode(['code' => 0, 'msg' => '请求操作成功', 'result' => ['id' => $table->id]]);
     return true;
 }
コード例 #2
0
 public function run()
 {
     //将get数组导入到post数组
     \Yii::$app->request->setBodyParams(\Yii::$app->request->getQueryParams());
     $table = TbTable::findOne(\Yii::$app->request->post('table_id'));
     $model = new StatsForm($table);
     $data = $model->search('table', true);
     $filename = $table->fdText . '_' . date('Y-m-d');
     header("Content-Type: application/vnd.ms-excel; charset=utf-8");
     header("Content-Disposition: inline; filename=\"" . $filename . ".csv\"");
     foreach ($data['table_datas'] as $row) {
         $key = 0;
         foreach ($row as $td_data) {
             if ($data['format'][$key] > '') {
                 $td_data_format = sprintf($data['format'][$key], $td_data);
             } else {
                 $td_data_format = $td_data;
             }
             $key++;
             echo iconv("UTF-8", "GBK", $td_data_format) . ',';
         }
         echo "\r\n";
     }
     exit;
 }
コード例 #3
0
 public function search()
 {
     $search = TbTable::find();
     if ($this->name > '') {
         $search->andWhere("fdName like :name", [":name" => "%" . $this->name . "%"]);
     }
     $pages = new Pagination(['totalCount' => $search->count(), 'pageSize' => 10]);
     $datas = $search->offset($pages->offset)->limit($pages->limit)->all();
     return ['datas' => $datas, 'pages' => $pages];
 }
コード例 #4
0
 public function run()
 {
     //异步访问支持
     if (\Yii::$app->request->isAjax) {
         $table = TbTable::findOne(\Yii::$app->request->post('table_id'));
         $model = new StatsForm($table);
         if (\Yii::$app->request->get('page') > 0) {
             $data = $model->search('table');
         } else {
             $data = $model->search();
         }
         //根据是还是翻页来生成全部页面还是部分页面
         $table_content = \Yii::$app->controller->renderPartial('_stats_table', ['table' => $table, 'data' => $data]);
         if ($data['sum_datas'] != null) {
             $sum_content = \Yii::$app->controller->renderPartial('_stats_sum', ['table' => $table, 'data' => $data]);
         } else {
             $sum_content = '';
         }
         if (\Yii::$app->request->get('page') > 0) {
             echo $table_content;
         } else {
             echo \Yii::$app->controller->renderPartial('_stats', ['table' => $table, 'data' => $data, 'sum_content' => $sum_content, 'table_content' => $table_content]);
         }
         \Yii::$app->end();
     }
     $action = \Yii::$app->controller->action->id;
     $menu = TbMenu::find()->where('fdAction = :action', [':action' => $action])->one();
     $content = [];
     foreach ($menu->tables as $table) {
         $model = new StatsForm($table);
         $data = $model->search();
         if ($data['sum_datas'] != null) {
             $sum_content = \Yii::$app->controller->renderPartial('_stats_sum', ['table' => $table, 'data' => $data]);
         } else {
             $sum_content = '';
         }
         $table_content = \Yii::$app->controller->renderPartial('_stats_table', ['table' => $table, 'data' => $data]);
         $content[$table->id] = \Yii::$app->controller->renderPartial('_stats', ['table' => $table, 'data' => $data, 'sum_content' => $sum_content, 'table_content' => $table_content]);
     }
     return \Yii::$app->controller->render('stats', ['menu' => $menu, 'content' => $content]);
 }
コード例 #5
0
ファイル: TbMenu.php プロジェクト: mademingshiwo/todolist
 public function getTables()
 {
     return $this->hasMany(TbTable::className(), ['id' => 'fdTableID'])->via('menuTables');
 }
コード例 #6
0
 public function actionSearch()
 {
     $keyword = trim(Yii::$app->request->post('keyword'));
     $model = TbTable::find();
     if ($keyword > '') {
         $model->andWhere("fdName like :name", [":name" => "%" . $keyword . "%"]);
     }
     $count = $model->count();
     $ret['total'] = $count;
     $model->select = ["id", "fdText as name"];
     $model->limit = 30;
     $model->asArray = true;
     $ret['entity'] = $model->all();
     echo json_encode($ret);
 }