| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace backend\modules\ib\controllers;
- use Yii;
- use backend\models\DashboardApi;
- use yii\web\NotFoundHttpException;
- use yii\helpers\Url;
- use common\helpers\UserAgentHelper;
- use common\helpers\ExcelHelper;
- /**
- * 首页
- */
- class DashboardController extends BaseController
- {
- /**
- * @return string
- * @throws NotFoundHttpException
- */
- public function actionIndex()
- {
- $api = new DashboardApi();
- $result = $api->getData();
- if ($result['code'] == 0) {
- throw new NotFoundHttpException($result['message']);
- }
- $data = $result['data'];
- return $this->render('index', [
- 'mt4user' => Yii::$app->getUser()->getIdentity(false)->getMt4user(),
- 'fvSum' => $data['fvSum'] / 100,
- 'mvSum' => $data['mvSum'] / 100,
- 'cvSum' => $data['cvSum'] / 100,
- 'tvSum' => $data['tvSum'] / 100,
- 'endDate' => date('Y-m-d', strtotime($data['endDate'])),
- 'directlyUserCount' => $data['directlyUserCount'],
- 'depositSumByDay' => json_encode($data['depositSumByDay']),
- 'isHaveAdmin' => Yii::$app->user->identity->isHaveAdmin(),
- ]);
- }
- /**
- * 申请进度情况
- */
- public function actionApplyList()
- {
- $get = Yii::$app->request->get();
- $orderInt = isset($get['order'][0]['column']) ? (int) $get['order'][0]['column'] : 1;
- $order = isset($get['columns'][$orderInt]['data']) ? $get['columns'][$orderInt]['data'] : '';
- $orderBy = isset($get['order'][0]['dir']) ? $get['order'][0]['dir'] : 'desc';
- $search = isset($get['search']['value']) ? trim($get['search']['value']) : '';
- $start = isset($get['start']) ? (int) $get['start'] : 0;
- $length = isset($get['length']) ? (int) $get['length'] : 20;
- $draw = isset($get['draw']) ? $get['draw'] : 1;
- $params = [
- 'order' => $order,
- 'orderBy' => $orderBy,
- 'search' => $search,
- 'start' => $start,
- 'length' => $length,
- 'draw' => $draw,
- ];
- if ($params['length'] > 5000) {
- if (Yii::$app->getRequest()->getIsAjax()) {
- Yii::$app->getResponse()->redirect(Url::current(), UserAgentHelper::isIE() ? 200 : 302);
- } else {
- $this->exportXls($params);
- }
- Yii::$app->end();
- }
- $api = new DashboardApi();
- $result = $api->getApplyList($params);
- return json_encode($result['data']);
- }
- /**
- * @param array $params
- */
- protected function exportXls($params)
- {
- ExcelHelper::init();
- $attachmentName = Yii::$app->user->identity->name . "_工单申请进度情况_" . date('Y-m-d') . '.xlsx';
- $header = ['账户', '姓名', '业务', '申请时间', '处理状态', '完成时间'];
- $source = [];
- $api = new DashboardApi();
- $params['length'] = 5000;
- while (true) {
- $result = $api->getApplyList($params);
- if ($result['code'] == 1 && !empty($result['data']['data'])) {
- foreach ((array)$result['data']['data'] as $key => $row) {
- $arr = [];
- $arr[] = $row['login'];
- $arr[] = $row['name'];
- $arr[] = $row['business'];
- $arr[] = $row['in_time'];
- $arr[] = $row['type'];
- $arr[] = $row['complete_time'];
- $source[] = $arr;
- }
- } else {
- break;
- }
- $params['start'] += $params['length'];
- if ($params['start'] >= $result['data']['recordsTotal']) {
- break;
- }
- }
- ExcelHelper::output($source, $header, $attachmentName);
- }
- }
|