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; }
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; }
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]); }
public function actionUpdateColumn() { // data: {'table_id': table_id, 'id': id, 'desc': desc, 'data_type': data_type, 'search_type': search_type, // 'select_id': select_id, 'order_type': order_type, 'chart_display': chart_display, 'table_display': table_display, // 'mark': mark, 'formatter': formatter} $table_id = 0 + \Yii::$app->request->post('table_id', ''); $column_id = \Yii::$app->request->post('id', ''); $table = TbTable::findOne($table_id); if (!$table) { echo json_encode(['code' => 1, 'msg' => '数据库中没有该表']); \Yii::$app->end(); } if (is_numeric($column_id)) { $column = TbColumn::findOne($column_id); } else { $column = new TbColumn(); } if (!$column) { echo json_encode(['code' => 1, 'msg' => '表中没有该字段']); \Yii::$app->end(); } $column->fdTableID = $table_id; $column->fdName = \Yii::$app->request->post('column_name', ''); $column->fdDesc = \Yii::$app->request->post('desc', ''); $column->fdTooltip = \Yii::$app->request->post('tip', ''); $column->fdDataType = 0 + \Yii::$app->request->post('data_type', ''); $column->fdSearchType = 0 + \Yii::$app->request->post('search_type', ''); $column->fdSelectID = 0 + \Yii::$app->request->post('select_id', ''); $column->fdOrderType = 0 + \Yii::$app->request->post('order_type', ''); $column->fdChartDisplay = 0 + \Yii::$app->request->post('chart_display', ''); $column->fdTableDisplay = 0 + \Yii::$app->request->post('table_display', ''); $column->fdMark = 0 + \Yii::$app->request->post('mark', ''); $column->fdFormatter = \Yii::$app->request->post('formatter', ''); if (!$column->save()) { echo json_encode(['code' => -1, 'msg' => json_encode($column->getErrors(), JSON_UNESCAPED_UNICODE)], JSON_UNESCAPED_UNICODE); \Yii::$app->end(); } echo json_encode(['code' => 0, 'msg' => '请求操作成功', 'result' => ['id' => $column->id]]); }