Exemple #1
0
 public function actionOfficetop()
 {
     $rows = MOffice::getOfficeScoreTop(Yii::$app->user->getGhid());
     $filter = new \app\models\FiltersForm();
     $filter->unsetAttributes();
     if (isset($_GET['FiltersForm'])) {
         $filter->setAttributes($_GET['FiltersForm'], false);
     }
     $rows = $filter->filterArrayData($rows);
     $dataProvider = new ArrayDataProvider(['allModels' => $rows, 'sort' => ['attributes' => ['office_id', 'title', 'cnt_office', 'cnt_staffs', 'cnt_sum'], 'defaultOrder' => ['cnt_sum' => SORT_DESC]], 'pagination' => ['pageSize' => 50]]);
     if (isset($_GET['download'])) {
         $data = $rows;
         \yii\helpers\ArrayHelper::multisort($data, 'cnt_sum', SORT_DESC);
         $date = date('Y-m-d-His');
         $filename = Yii::$app->getRuntimePath() . "/Officetop-{$date}.csv";
         $csv = new \app\models\ECSVExport($data);
         $attributes = ['office_id', 'scene_id', 'title', 'is_jingxiaoshang', 'cnt_office', 'cnt_staffs', 'cnt_sum'];
         $csv->setInclude($attributes);
         $csv->setHeaders(['office_id' => '营业厅ID', 'scene_id' => '推广码ID', 'title' => '名称', 'is_jingxiaoshang' => '类别', 'cnt_office' => '部门推广人数', 'cnt_staffs' => '部门员工推广人数', 'cnt_sum' => '合计推广人数']);
         $csv->toCSV($filename);
         Yii::$app->response->sendFile($filename);
         return;
     }
     return $this->render('officetop', ['dataProvider' => $dataProvider, 'filter' => $filter]);
 }