Ejemplo n.º 1
0
 public function actionOfficetopbyrange()
 {
     $cur_date = Yii::$app->request->get('cur_date');
     if (empty($cur_date)) {
         $date_start = Yii::$app->request->get('date_start', date("Y-m-d", strtotime("-1 day")));
         $date_end = Yii::$app->request->get('date_end', date("Y-m-d", strtotime("-1 day")));
     } else {
         $date_start = $cur_date;
         $date_end = $cur_date;
     }
     $rows = MOffice::getOfficeScoreTopByRange(Yii::$app->user->getGhid(), $date_start, $date_end);
     $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() . "/Officetopbyrange-{$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('officetopbyrange', ['dataProvider' => $dataProvider, 'cur_date' => $cur_date, 'date_start' => $date_start, 'date_end' => $date_end, 'filter' => $filter]);
 }