Пример #1
0
 /**
  * вывод с депозита пользователя
  *
  * @param $user_id integer
  * @return string
  */
 public static function withDrawFunds($withdraw_value, $user_id, $payment_system = 1)
 {
     $withdraw_value = 0 - $withdraw_value;
     $deposit_before = self::getDepositValue($user_id);
     $res = self::updateUserDeposit($withdraw_value, $user_id);
     if ($res == 1) {
         $data = ['payment_system' => $payment_system];
         $res = Transaction::addNewTransaction(Transaction::TR_TYPE_WITHDRAW, $data, $user_id, $deposit_before, $withdraw_value);
     }
     return $res;
 }
Пример #2
0
 /**
  *
  */
 public function createNewTransaction()
 {
     //echo'<pre>';print_r($this);echo'</pre>';die;
     $result = 0;
     $err_msg = '';
     $deposit_before = $this->user->deposit;
     $created_by = Yii::$app->user->id;
     switch ($this->trans_type) {
         case Transaction::TR_TYPE_DEPOSIT:
             //echo'<pre>';print_r($this->user);echo'</pre>';die;
             $res = User::updateUserDeposit($this->value, $this->user->id);
             //echo'<pre>';var_dump($res);echo'</pre>';die;
             if ($res == 1) {
                 $data = ['payment_system' => $this->payment_type, 'payment_status' => PaymentSystem::PAYMENT_STATUS_OK];
                 $result = Transaction::addNewTransaction(Transaction::TR_TYPE_DEPOSIT, $data, $this->user->id, $deposit_before, $this->value, $created_by, $this->comment);
                 if ($result != 1) {
                     $err_msg = 'При создании транзакции возникла ошибка.';
                 }
             } else {
                 $err_msg = 'При обновлении депозита пользователя возникла ошибка.';
             }
             //echo'<pre>';var_dump($result);echo'</pre>';die;
             //$result = true;
             break;
         case Transaction::TR_TYPE_FANTASY_PAYMENT:
             if (($fantasy_model = DotaFantasy::findOne($this->fantasy_id)) !== null) {
                 if ($this->user->deposit >= $fantasy_model->deposit + $fantasy_model->fee) {
                     //$this->value = 0 - ($fantasy_model->deposit + $fantasy_model->fee);
                     $this->value = 0 - $this->value;
                     $res = User::updateUserDeposit($this->value, $this->user->id);
                     if ($res == 1) {
                         $data = ['fantasy_id' => $fantasy_model->id, 'game' => $this->game_id];
                         $result = Transaction::addNewTransaction(Transaction::TR_TYPE_FANTASY_PAYMENT, $data, $this->user->id, $deposit_before, $this->value, $created_by, $this->comment);
                         //echo'<pre>';var_dump($result);echo'</pre>';die;
                     } else {
                         $err_msg = 'При обновлении депозита пользователя возникла ошибка';
                     }
                 } else {
                     $err_msg = 'Недостаточно средств.';
                 }
             } else {
                 $err_msg = 'Ошибка загрузки фантазии.';
             }
             //$result = true;
             break;
         case Transaction::TR_TYPE_FANTASY_CANCEL:
             if (($fantasy_model = DotaFantasy::findOne($this->fantasy_id)) !== null) {
                 $res = User::updateUserDeposit($this->value, $this->user->id);
                 if ($res == 1) {
                     $data = ['fantasy_id' => $fantasy_model->id, 'game' => $this->game_id];
                     $result = Transaction::addNewTransaction(Transaction::TR_TYPE_FANTASY_CANCEL, $data, $this->user->id, $deposit_before, $this->value, $created_by, $this->comment);
                     //echo'<pre>';var_dump($result);echo'</pre>';die;
                 } else {
                     $err_msg = 'При обновлении депозита пользователя возникла ошибка';
                 }
             } else {
                 $err_msg = 'Ошибка загрузки фантазии.';
             }
             //$result = true;
             break;
         case Transaction::TR_TYPE_PAYOUT_PRIZES:
             if (($fantasy_model = DotaFantasy::findOne($this->fantasy_id)) !== null) {
                 $res = User::updateUserDeposit($this->value, $this->user->id);
                 if ($res == 1) {
                     $data = ['fantasy_id' => $fantasy_model->id, 'prize' => $this->value, 'game' => $this->game_id];
                     $result = Transaction::addNewTransaction(Transaction::TR_TYPE_PAYOUT_PRIZES, $data, $this->user->id, $deposit_before, $this->value, $created_by, $this->comment);
                     //echo'<pre>';var_dump($result);echo'</pre>';die;
                 } else {
                     $err_msg = 'При обновлении депозита пользователя возникла ошибка';
                 }
             } else {
                 $err_msg = 'Ошибка загрузки фантазии.';
             }
             //$result = true;
             break;
         case Transaction::TR_TYPE_WITHDRAW:
             //echo'<pre>';print_r($this);echo'</pre>';die;
             if ($this->user->deposit > $this->value) {
                 $this->value = 0 - $this->value;
                 $res = User::updateUserDeposit($this->value, $this->user->id);
                 if ($res == 1) {
                     $data = ['payment_system' => $this->payment_type];
                     $result = Transaction::addNewTransaction(Transaction::TR_TYPE_WITHDRAW, $data, $this->user->id, $deposit_before, $this->value, $created_by, $this->comment);
                 } else {
                     $err_msg = 'При обновлении депозита пользователя возникла ошибка';
                 }
             } else {
                 $err_msg = 'Депозит пользователя меньше выводимой суммы';
             }
             //$result = true;
             break;
         default:
             $result = 0;
             break;
     }
     if ($result != 1 && $err_msg != '') {
         Yii::$app->session->setFlash('error', $err_msg);
     }
     return $result;
 }