DashboardController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace backend\modules\ib\controllers;
  3. use Yii;
  4. use backend\models\DashboardApi;
  5. use yii\web\NotFoundHttpException;
  6. use yii\helpers\Url;
  7. use common\helpers\UserAgentHelper;
  8. use common\helpers\ExcelHelper;
  9. /**
  10. * 首页
  11. */
  12. class DashboardController extends BaseController
  13. {
  14. /**
  15. * @return string
  16. * @throws NotFoundHttpException
  17. */
  18. public function actionIndex()
  19. {
  20. $api = new DashboardApi();
  21. $result = $api->getData();
  22. if ($result['code'] == 0) {
  23. throw new NotFoundHttpException($result['message']);
  24. }
  25. $data = $result['data'];
  26. return $this->render('index', [
  27. 'mt4user' => Yii::$app->getUser()->getIdentity(false)->getMt4user(),
  28. 'fvSum' => $data['fvSum'] / 100,
  29. 'mvSum' => $data['mvSum'] / 100,
  30. 'cvSum' => $data['cvSum'] / 100,
  31. 'tvSum' => $data['tvSum'] / 100,
  32. 'endDate' => date('Y-m-d', strtotime($data['endDate'])),
  33. 'directlyUserCount' => $data['directlyUserCount'],
  34. 'depositSumByDay' => json_encode($data['depositSumByDay']),
  35. 'isHaveAdmin' => Yii::$app->user->identity->isHaveAdmin(),
  36. ]);
  37. }
  38. /**
  39. * 申请进度情况
  40. */
  41. public function actionApplyList()
  42. {
  43. $get = Yii::$app->request->get();
  44. $orderInt = isset($get['order'][0]['column']) ? (int) $get['order'][0]['column'] : 1;
  45. $order = isset($get['columns'][$orderInt]['data']) ? $get['columns'][$orderInt]['data'] : '';
  46. $orderBy = isset($get['order'][0]['dir']) ? $get['order'][0]['dir'] : 'desc';
  47. $search = isset($get['search']['value']) ? trim($get['search']['value']) : '';
  48. $start = isset($get['start']) ? (int) $get['start'] : 0;
  49. $length = isset($get['length']) ? (int) $get['length'] : 20;
  50. $draw = isset($get['draw']) ? $get['draw'] : 1;
  51. $params = [
  52. 'order' => $order,
  53. 'orderBy' => $orderBy,
  54. 'search' => $search,
  55. 'start' => $start,
  56. 'length' => $length,
  57. 'draw' => $draw,
  58. ];
  59. if ($params['length'] > 5000) {
  60. if (Yii::$app->getRequest()->getIsAjax()) {
  61. Yii::$app->getResponse()->redirect(Url::current(), UserAgentHelper::isIE() ? 200 : 302);
  62. } else {
  63. $this->exportXls($params);
  64. }
  65. Yii::$app->end();
  66. }
  67. $api = new DashboardApi();
  68. $result = $api->getApplyList($params);
  69. return json_encode($result['data']);
  70. }
  71. /**
  72. * @param array $params
  73. */
  74. protected function exportXls($params)
  75. {
  76. ExcelHelper::init();
  77. $attachmentName = Yii::$app->user->identity->name . "_工单申请进度情况_" . date('Y-m-d') . '.xlsx';
  78. $header = ['账户', '姓名', '业务', '申请时间', '处理状态', '完成时间'];
  79. $source = [];
  80. $api = new DashboardApi();
  81. $params['length'] = 5000;
  82. while (true) {
  83. $result = $api->getApplyList($params);
  84. if ($result['code'] == 1 && !empty($result['data']['data'])) {
  85. foreach ((array)$result['data']['data'] as $key => $row) {
  86. $arr = [];
  87. $arr[] = $row['login'];
  88. $arr[] = $row['name'];
  89. $arr[] = $row['business'];
  90. $arr[] = $row['in_time'];
  91. $arr[] = $row['type'];
  92. $arr[] = $row['complete_time'];
  93. $source[] = $arr;
  94. }
  95. } else {
  96. break;
  97. }
  98. $params['start'] += $params['length'];
  99. if ($params['start'] >= $result['data']['recordsTotal']) {
  100. break;
  101. }
  102. }
  103. ExcelHelper::output($source, $header, $attachmentName);
  104. }
  105. }