[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['login', 'error', 'qrcode'], //首页可能是从cs跳转过来,还没有登录信息, 'allow' => true, ], [ 'actions' => ['logout', 'index'], 'allow' => true, 'roles' => ['@'], ], ], ] ]; } /** * Renders the index view for the module * 业绩数据,公告数据 * @return string */ public function actionIndex() { $today = date('Y-m-d'); //系统权限列表,车队系统 CS系统 $user = Yii::$app->getUser()->getIdentity(); /* @var $user User */ $sysList = $user->getMainCorpArray(); //昨日 省际 $yesterday = date('Y-m-d', strtotime('-1 day')); $yesData = BusReport::getHomePageData($yesterday, $yesterday); if ($yesData['count'] == 0) { $yesData = [ 'income' => 0, 'count' => 0, 'cost' => 0 ]; } //昨日 市内 $yesDataCity = BusReport::getHomePageData($yesterday, $yesterday, false, BusOrder::LINE_TYPE_CITY); if ($yesDataCity['count'] == 0) { $yesDataCity = [ 'income' => 0, 'count' => 0, 'cost' => 0 ]; } //一周 省际 $lastWeek = date('Y-m-d', strtotime('-6 days')); $weekData = BusReport::getHomePageData($lastWeek, $today, true); $jsStr = 'var chartWeek = ['; $jsDay = 'var chartDay = ['; if (count($weekData) > 0) { foreach ($weekData as $key => $day) { $jsDay .= "date_tran('" . $day['run_date'] . "'),"; $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']) . "},"; } $jsDay = substr($jsDay, 0, -1); $jsStr = substr($jsStr, 0, -1); } $jsDay .= '];'; $jsStr .= '];'; //一周 市级 $weekDataCity = BusReport::getHomePageData($lastWeek, $today, true, BusOrder::LINE_TYPE_CITY); $jsStrCity = 'var chartWeekCity = ['; $jsDayCity = 'var chartDayCity = ['; if (count($weekDataCity) > 0) { foreach ($weekDataCity as $key => $day) { $jsDayCity .= "date_tran('" . $day['run_date'] . "'),"; $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']) . "},"; } $jsDayCity = substr($jsDayCity, 0, -1); $jsStrCity = substr($jsStrCity, 0, -1); } $jsDayCity .= '];'; $jsStrCity .= '];'; $formatStr = ' function date_tran(str){ var month = str.split("-")[1]; var day = str.split("-")[2]; return month+\'月\'+day+\'日\'; }'; //本月 $thisMonth = date('Y-m-01'); $endMonth = date('Y-m-t'); $monthData = BusReport::getHomePageData($thisMonth, $endMonth); if ($monthData['count'] == 0) { $monthData = [ 'income' => 0, 'count' => 0, 'cost' => 0 ]; } //本月 市级 $monthDataCity = BusReport::getHomePageData($thisMonth, $endMonth, false, BusOrder::LINE_TYPE_CITY); if ($monthDataCity['count'] == 0) { $monthDataCity = [ 'income' => 0, 'count' => 0, 'cost' => 0 ]; } //公告 $postData = BusReport::getSysPost(); return $this->render('index', [ 'sysList'=> $sysList, 'postData' => $postData, 'jsStr' => $formatStr . $jsDay . $jsStr, 'jsStrCity' => $jsDayCity . $jsStrCity, 'yesData' => $yesData, 'yesDataCity' => $yesDataCity, 'monthData' => $monthData, 'monthDataCity' => $monthDataCity, ]); } public function beforeAction($action) { if ($action->id === 'index' && Yii::$app->user->isGuest) { User::cs1Login(); } return parent::beforeAction($action); } /** * User: wangxj * * 生成二维码 * */ public function actionQrcode() { QrCode::png('http://www.yii-china.com', false, 0, 6); } }