예제 #1
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;
 }
예제 #2
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]);
 }