Exemplo n.º 1
0
 public function behaviors()
 {
     return ['verbs' => ['class' => VerbFilter::class, 'actions' => ['delete' => ['post']]], 'cache' => ['class' => 'yii\\filters\\HttpCache', 'cacheControlHeader' => 'must-revalidate, private', 'only' => ['index'], 'enabled' => false, 'lastModified' => function ($action, $params) {
         $query = Income::find();
         if (isset($params['user'])) {
             $query->where(['user_name' => $params['user']]);
         }
         return (int) $query->max('time');
     }]];
 }
Exemplo n.º 2
0
 public function canChargeBonus()
 {
     //@todo decouple
     return $this->ref_name && (Node::find()->where(['user_name' => $this->ref_name])->count() > 0 || Income::find()->where(['user_name' => $this->ref_name])->count() > 0);
 }
Exemplo n.º 3
-1
 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;
 }