public function actionGive($id) { $node = Gift::findOne($id)->give(); if ($node) { return $this->redirect(['index', 'id' => $node->id]); } else { Yii::$app->session->addFlash('error', Yii::t('app', 'Something wrong happened')); return $this->redirect(['gift']); } }
public function open(Transaction $transaction) { try { $sum = (int) Node::find()->where(['user_name' => $this->user_name])->count(); $sum += (int) Income::find()->where(['user_name' => $this->user_name])->count(); if ($this->invest()) { do { $i = $this->rise(); } while ($i > 0); if (0 == $sum && $this->user->canChargeBonus()) { $referral = $this->user->referral; $referral->account += $this->type->bonus; $referral->update(true, ['account']); if (4 == $this->type->id) { $count = $referral->getSponsors()->select('user_name')->joinWith('nodes')->groupBy('user_name')->count(); if ($count > 0 && 0 == $count % 10) { $gift = new Gift(['user_name' => $referral->name]); $gift->save(); Yii::$app->session->setFlash('success', Yii::t('app', 'Your referral may receive a gift')); } } } $transaction->commit(); Yii::$app->session->setFlash('success', Yii::t('app', 'The plan is open')); return true; } else { Yii::$app->session->setFlash('error', $this->dump()); } } catch (\Exception $ex) { $transaction->rollBack(); Yii::$app->session->setFlash('error', $ex->getMessage()); } return false; }