Exemplo n.º 1
0
 /**
  * Отображает новые заказы
  * @return array|\yii\db\ActiveRecord[]
  * @throws ForbiddenHttpException
  * @throws NotFoundHttpException
  */
 public function actionNew()
 {
     $searchModel = new Order();
     if (!Yii::$app->user->can('listModels', array("model" => $searchModel))) {
         throw new ForbiddenHttpException('Forbidden');
     }
     $searchModel->setScenario(ActiveRecord::SCENARIO_SEARCH);
     $perm = $searchModel->getPermission();
     $status = Status::findOne(["default" => true]);
     if (!$status) {
         throw new NotFoundHttpException();
     }
     $query = Order::find()->published()->andWhere(["status_id" => $status->id]);
     if ($perm) {
         $perm->applyConstraint($query);
     }
     return $query->all();
 }
 /**
  * @return string
  */
 public function actionList()
 {
     $orders = [];
     $dataProvider = null;
     $currentOrderId = null;
     if (\Yii::$app->user->isGuest) {
         $orders = \Yii::$app->session->get('orders', []);
         $currentOrderId = \Yii::$app->session->get('orderId');
         $orders = Order::find()->where(['id' => $orders, 'user_id' => 0]);
     } else {
         $orders = Order::find()->where(['user_id' => \Yii::$app->user->id]);
         $currentOrderId = \Yii::$app->session->get('orderId');
     }
     if (!is_array($orders)) {
         $orders = $orders->orderBy(['update_date' => SORT_DESC]);
         $dataProvider = new ActiveDataProvider(['query' => $orders, 'pagination' => ['pageSize' => 10]]);
     }
     return $this->render('list', ['orders' => $orders, 'currentOrder' => $currentOrderId, 'dataProvider' => $dataProvider]);
 }
Exemplo n.º 3
0
 /**
  * @param Connection $db
  * @return array
  */
 protected function getUserStatistics(Connection $db)
 {
     $usersIds = User::find()->select('id')->column($db);
     $activeUsers = Order::find()->select('user_id')->innerJoin(OrderTransaction::tableName(), Order::tableName() . '.id = ' . OrderTransaction::tableName() . '.order_id')->where(['status' => 5, 'user_id' => $usersIds])->count('*', $db);
     $lastRegistered = User::find()->where(['>=', 'create_time', $this->getPeriodTs($this->userDate)])->count('*', $db);
     $userData = [Yii::t('app', 'Registered customers') => count($usersIds), Yii::t('app', 'Active registered customers') => $activeUsers, Yii::t('app', 'New registered customers for last {period}', ['period' => Yii::t('app', $this->userDate)]) => $lastRegistered];
     return $userData;
 }