You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

167 rivejä
5.2 KiB

  1. <?php
  2. namespace backend\modules\motorcade\controllers;
  3. use backend\modules\motorcade\models\BusOrder;
  4. use common\models\User;
  5. use dosamigos\qrcode\QrCode;
  6. use Yii;
  7. use yii\filters\AccessControl;
  8. use backend\modules\motorcade\models\BusReport;
  9. /**
  10. * Default controller for the `Motorcade` module
  11. */
  12. class DefaultController extends BaseController
  13. {
  14. /**
  15. * @inheritdoc
  16. */
  17. public function behaviors()
  18. {
  19. return [
  20. 'access' => [
  21. 'class' => AccessControl::className(),
  22. 'rules' => [
  23. [
  24. 'actions' => ['login', 'error', 'qrcode'], //首页可能是从cs跳转过来,还没有登录信息,
  25. 'allow' => true,
  26. ],
  27. [
  28. 'actions' => ['logout', 'index'],
  29. 'allow' => true,
  30. 'roles' => ['@'],
  31. ],
  32. ],
  33. ]
  34. ];
  35. }
  36. /**
  37. * Renders the index view for the module
  38. * 业绩数据,公告数据
  39. * @return string
  40. */
  41. public function actionIndex()
  42. {
  43. $today = date('Y-m-d');
  44. //系统权限列表,车队系统 CS系统
  45. $user = Yii::$app->getUser()->getIdentity();
  46. /* @var $user User */
  47. $sysList = $user->getMainCorpArray();
  48. //昨日 省际
  49. $yesterday = date('Y-m-d', strtotime('-1 day'));
  50. $yesData = BusReport::getHomePageData($yesterday, $yesterday);
  51. if ($yesData['count'] == 0) {
  52. $yesData = [
  53. 'income' => 0,
  54. 'count' => 0,
  55. 'cost' => 0
  56. ];
  57. }
  58. //昨日 市内
  59. $yesDataCity = BusReport::getHomePageData($yesterday, $yesterday, false, BusOrder::LINE_TYPE_CITY);
  60. if ($yesDataCity['count'] == 0) {
  61. $yesDataCity = [
  62. 'income' => 0,
  63. 'count' => 0,
  64. 'cost' => 0
  65. ];
  66. }
  67. //一周 省际
  68. $lastWeek = date('Y-m-d', strtotime('-6 days'));
  69. $weekData = BusReport::getHomePageData($lastWeek, $today, true);
  70. $jsStr = 'var chartWeek = [';
  71. $jsDay = 'var chartDay = [';
  72. if (count($weekData) > 0) {
  73. foreach ($weekData as $key => $day) {
  74. $jsDay .= "date_tran('" . $day['run_date'] . "'),";
  75. $jsStr .= "{x: {$key}, y:{$day['income']}, j_name: '出车数', l_name: '利润',date: '{$day['run_date']}',income: {$day['income']}, count: {$day['count']}, profit: " . ($day['income'] - $day['cost']) . "},";
  76. }
  77. $jsDay = substr($jsDay, 0, -1);
  78. $jsStr = substr($jsStr, 0, -1);
  79. }
  80. $jsDay .= '];';
  81. $jsStr .= '];';
  82. //一周 市级
  83. $weekDataCity = BusReport::getHomePageData($lastWeek, $today, true, BusOrder::LINE_TYPE_CITY);
  84. $jsStrCity = 'var chartWeekCity = [';
  85. $jsDayCity = 'var chartDayCity = [';
  86. if (count($weekDataCity) > 0) {
  87. foreach ($weekDataCity as $key => $day) {
  88. $jsDayCity .= "date_tran('" . $day['run_date'] . "'),";
  89. $jsStrCity .= "{x: {$key}, y:{$day['income']}, j_name: '出车数', l_name: '利润',date: '{$day['run_date']}',income: {$day['income']}, count: {$day['count']}, profit: " . ($day['income'] - $day['cost']) . "},";
  90. }
  91. $jsDayCity = substr($jsDayCity, 0, -1);
  92. $jsStrCity = substr($jsStrCity, 0, -1);
  93. }
  94. $jsDayCity .= '];';
  95. $jsStrCity .= '];';
  96. $formatStr = '
  97. function date_tran(str){
  98. var month = str.split("-")[1];
  99. var day = str.split("-")[2];
  100. return month+\'月\'+day+\'日\';
  101. }';
  102. //本月
  103. $thisMonth = date('Y-m-01');
  104. $endMonth = date('Y-m-t');
  105. $monthData = BusReport::getHomePageData($thisMonth, $endMonth);
  106. if ($monthData['count'] == 0) {
  107. $monthData = [
  108. 'income' => 0,
  109. 'count' => 0,
  110. 'cost' => 0
  111. ];
  112. }
  113. //本月 市级
  114. $monthDataCity = BusReport::getHomePageData($thisMonth, $endMonth, false, BusOrder::LINE_TYPE_CITY);
  115. if ($monthDataCity['count'] == 0) {
  116. $monthDataCity = [
  117. 'income' => 0,
  118. 'count' => 0,
  119. 'cost' => 0
  120. ];
  121. }
  122. //公告
  123. $postData = BusReport::getSysPost();
  124. return $this->render('index',
  125. [
  126. 'sysList'=> $sysList,
  127. 'postData' => $postData,
  128. 'jsStr' => $formatStr . $jsDay . $jsStr,
  129. 'jsStrCity' => $jsDayCity . $jsStrCity,
  130. 'yesData' => $yesData,
  131. 'yesDataCity' => $yesDataCity,
  132. 'monthData' => $monthData,
  133. 'monthDataCity' => $monthDataCity,
  134. ]);
  135. }
  136. public function beforeAction($action)
  137. {
  138. if ($action->id === 'index' && Yii::$app->user->isGuest) {
  139. User::cs1Login();
  140. }
  141. return parent::beforeAction($action);
  142. }
  143. /**
  144. * User: wangxj
  145. *
  146. * 生成二维码
  147. *
  148. */
  149. public function actionQrcode()
  150. {
  151. QrCode::png('http://www.yii-china.com', false, 0, 6);
  152. }
  153. }