public function actionOpen($id) { if (!in_array($id, [1, 2, 3, 4])) { throw new InvalidParamException('id'); } /** @var \app\models\User $me */ $me = Yii::$app->user->identity; $type = $this->findModel($id); $node = new Node(['type' => $type, 'user' => $me]); if ($me->account >= $type->stake) { $me->account -= $type->stake; $transaction = Yii::$app->db->beginTransaction(); if ($me->update(true, ['account'])) { $node->open($transaction); } else { Yii::$app->session->setFlash('error', json_encode($me, JSON_UNESCAPED_UNICODE)); } } else { Yii::$app->session->setFlash('error', Yii::t('app', 'Insufficient funds')); return $this->redirect(['view', 'id' => $node->id]); } return $this->redirect(['view', 'id' => $id]); }