public function actionOfficetopbymonth($month) { $rows = MOffice::getOfficeScoreTopByMonth(Yii::$app->user->getGhid(), $month); $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() . "/Officetopbymonth-{$month}.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('officetopbymonth', ['dataProvider' => $dataProvider, 'month' => $month, 'filter' => $filter]); }