backend\controllers\UserController::actionView PHP Method

actionView() public method

public actionView ( $id )
    public function actionView($id)
    {
        $model = User::findOne($id);
        if (!$model) {
            throw new NotFoundHttpException('未找到该用户');
        }
        $last15days = [];
        $numDataOrder = [];
        $today = strtotime("00:00:00");
        $todayEnd = strtotime("23:59:59");
        for ($i = 0; $i < 15; $i++) {
            $timestrap = strtotime('-' . $i . ' days', $today);
            $timestrapEnd = strtotime('-' . $i . ' days', $todayEnd);
            $where = ['and', ['user_id' => $id], ['>=', 'created_at', $timestrap], ['<=', 'created_at', $timestrapEnd]];
            array_unshift($last15days, date('m/d', $timestrap));
            array_unshift($numDataOrder, Order::find()->where($where)->count('id'));
        }
        return $this->render('view', ['model' => $model, 'last15days' => $last15days, 'numDataOrder' => $numDataOrder]);
    }