Ejemplo n.º 1
0
 /**
  * добавляет в базу новую ставку
  * @param Model $fantasy
  */
 public function addRate($fantasy)
 {
     $draftModel = new PokerDraft();
     $PokerDraftPlayer = new PokerDraftPlayer();
     $draftModel->attributes = $this->attributes;
     $draftModel->save();
     //echo'<pre>'; print_r($draftModel);echo'</pre>';die;
     $PokerDraftPlayer->addPlayersRows($this->players, $draftModel->id);
     //снимаем взнос+комиссия у игрока
     $user = User::findOne(Yii::$app->user->id);
     $deposit_before = $user->deposit;
     $user->deposit = $user->deposit - $fantasy->deposit - $fantasy->fee;
     if ($user->save()) {
         //заносим в лог
         $data = ['fantasy_id' => $fantasy->id, 'game' => Transaction::TR_GAME_POKER];
         $trans_descr = Transaction::buildTransactionDescrForSave(Transaction::TR_TYPE_FANTASY_PAYMENT, $data);
         Transaction::saveTransaction($user->id, $deposit_before, -($fantasy->deposit + $fantasy->fee), $trans_descr);
     }
     //если нужно - увеличиваем призовой фонд
     //$total_sum_rates = PokerDraft::getCountFantasyDrafts($fantasy->id) * $fantasy->deposit;
     $total_sum_rates = $draftModel->getCountFantasyDrafts($fantasy->id) * $fantasy->deposit;
     if ($total_sum_rates > $fantasy->prize_pool_real) {
         PokerFantasy::upateRealPrizePool($fantasy->id, $total_sum_rates);
     }
 }
Ejemplo n.º 2
0
 /**
  * Displays homepage.
  *
  * @return mixed
  */
 public function actionIndex()
 {
     if (Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = $this->loadProfile();
     $transactions = Transaction::getLastUserTransactions(Yii::$app->user->id);
     $rates = User::getLastUserRates(Yii::$app->user->id);
     //echo'<pre>';print_r($drafts);echo'</pre>';die;
     $data = ['model' => $model, 'transactions' => $transactions, 'rates' => $rates];
     return $this->render('main', ['subTmpl' => 'index', 'data' => $data]);
 }
Ejemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Transaction::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'code' => $this->code, 'status' => $this->status, 'created' => $this->created, 'ttl' => $this->ttl]);
     $query->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Ejemplo n.º 4
0
 public function searchForUser($params, $pagesize = 20)
 {
     $query = Transaction::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]], 'pagination' => ['pageSize' => $pagesize, 'pageSizeParam' => false]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'deposit_before' => $this->deposit_before, 'value' => $this->value, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'descr', $this->descr]);
     return $dataProvider;
 }
Ejemplo n.º 5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Transaction::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['class' => 'yii\\data\\Sort', 'attributes' => ['id', 'ttl', 'status', 'user_id' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]], 'description', 'resp_status', 'resp_code', 'resp_description']]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'ttl' => $this->ttl, 'status' => $this->status, 'resp_code' => $this->resp_code, 'user_id' => $this->user_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'resp_status', $this->resp_status])->andFilterWhere(['like', 'resp_description', $this->resp_description]);
     return $dataProvider;
 }
Ejemplo n.º 6
0
 public function actionCheck()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $request = Yii::$app->request;
     if ($request->isAjax) {
         $post = $request->post();
         $id = $post['id'];
         $app = $post['app'];
         $xml = simplexml_load_string($this->createxml($app, $id), "SimpleXMLElement", LIBXML_NOCDATA);
         $json = json_encode($xml);
         $model = \common\models\Transaction::findOne($id);
         $model->code = $xml->transaction['code'];
         $model->status = $xml->transaction['status'];
         $model->save();
         return $json;
     }
 }
Ejemplo n.º 7
0
 public function actionTransaction($id)
 {
     $result = Yii::$app->request->post();
     $json_data = base64_decode($result['data']);
     $data = json_decode($json_data, true);
     if ($data) {
         Transaction::saveTransaction($data, $id);
     }
     if ($data['status'] === 'success') {
         $this->send();
         if ($model = Searched::updateAll(['plan_id' => $data['description']], ['id' => $id])) {
             return $this->redirect('/user/profile');
         } else {
             return $this->goHome();
         }
     } else {
         return $this->goHome();
     }
 }
Ejemplo n.º 8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Transaction::find()->joinWith('user');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     //echo'<pre>';var_dump($this->trans_type);echo'</pre>';die;
     $query->andFilterWhere(['{{%transaction}}.id' => $this->id, '{{%user}}.id' => $this->user_id, '{{%user}}.nickname' => $this->nickname, 'deposit_before' => $this->deposit_before, 'value' => $this->value, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'descr', $this->descr]);
     if (floatval($this->value_from) < floatval($this->value_to) && floatval($this->value_to) != 0) {
         $query->andFilterWhere(['between', 'value', floatval($this->value_from), floatval($this->value_to)]);
     } elseif (floatval($this->value_from) != 0 && floatval($this->value_to) == 0) {
         $query->andFilterWhere(['>=', 'value', floatval($this->value_from)]);
     } elseif (floatval($this->value_from) == 0 && floatval($this->value_to) != 0) {
         $query->andFilterWhere(['<=', 'value', floatval($this->value_to)]);
     }
     if ($this->trans_user_type != self::TR_USER_TYPE_ALL) {
         $admins = User::getAdministratorsIds();
         if ($this->trans_user_type == self::TR_USER_TYPE_ADM) {
             $query->andFilterWhere(['in', 'user_id', $admins]);
         } else {
             $query->andFilterWhere(['not in', 'user_id', $admins]);
         }
     }
     if (is_array($this->trans_type)) {
         if (count($this->trans_type)) {
             $trans_type_arr = ['or'];
             foreach ($this->trans_type as $trans_type) {
                 $trans_type_arr[] = '(`descr` like "' . $trans_type . ',%")';
             }
             //echo'<pre>';print_r($trans_type_arr);echo'</pre>';//die;
             if (count($trans_type_arr)) {
                 $query->andFilterWhere($trans_type_arr);
             }
         }
     }
     return $dataProvider;
 }
Ejemplo n.º 9
0
<?php

use common\models\Transaction;
?>


<div class="col col15"><?php 
echo Yii::$app->formatter->asDate($model->created_at, 'php:H:i / d.m.yy');
?>
</div>
<div class="col col15 t-right"><?php 
echo Yii::$app->formatter->asDecimal($model->deposit_before, 2);
?>
$</div>
<div class="col col15 t-right"><?php 
echo Transaction::showTransactionValue($model->value);
?>
</div>
<div class="col col15 t-right"><b class="blue"><?php 
echo Yii::$app->formatter->asDecimal($model->deposit_before + $model->value, 2);
?>
$</b></div>
<div class="col col-text col40"><?php 
echo Transaction::buildTransactionDescr($model->descr);
?>
</div>
<?/*<div class="clr"></div>*/?>

Ejemplo n.º 10
0
 public static function find()
 {
     return parent::find()->andWhere(['user_id' => Yii::$app->getUser()->id]);
 }
Ejemplo n.º 11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTransactions()
 {
     return $this->hasMany(Transaction::className(), ['user_id' => 'id']);
 }
Ejemplo n.º 12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTransactions()
 {
     return $this->hasMany(Transaction::className(), ['id' => 'transaction_id'])->viaTable('transaction_product', ['product_id' => 'id']);
 }
Ejemplo n.º 13
0
 /**
  * добавляет в базу новую ставку
  *
  * @param $fantasy
  * @return bool
  */
 public function addRate($fantasy)
 {
     $draftModel = new DotaDraft();
     $draftModel->attributes = $this->attributes;
     if ($draftModel->save() === false) {
         return false;
     }
     //echo'<pre>'; print_r($draftModel);echo'</pre>';die;
     switch ($this->scenario) {
         case self::SCENARIO_MIXED_DRAFT:
             $DotaDraftPlayer = new DotaDraftPlayer();
             $DotaDraftHero = new DotaDraftHero();
             $DotaDraftPlayer->addPlayersRows($this->players, $draftModel->id, $this->draft_slots);
             $DotaDraftHero->addHeroesRows($this->heroes, $draftModel->id);
             break;
         case self::SCENARIO_PLAYERS_DRAFT:
             $DotaDraftPlayer = new DotaDraftPlayer();
             $DotaDraftPlayer->addPlayersRows($this->players, $draftModel->id, $this->draft_slots);
             break;
         case self::SCENARIO_HEROES_DRAFT:
             $DotaDraftHero = new DotaDraftHero();
             $DotaDraftHero->addHeroesRows($this->heroes, $draftModel->id);
             break;
     }
     //снимаем взнос+комиссия у игрока
     $user = User::findOne(Yii::$app->user->id);
     $deposit_before = $user->deposit;
     $user->deposit = $user->deposit - $fantasy->deposit - $fantasy->fee;
     if ($user->save() === false) {
         $draftModel->delete();
         //если возникла ошибка - удаляем из базы ставку пользователя
         return false;
     }
     //заносим в лог
     $data = ['fantasy_id' => $fantasy->id, 'game' => Transaction::TR_GAME_DOTA];
     $trans_descr = Transaction::buildTransactionDescrForSave(Transaction::TR_TYPE_FANTASY_PAYMENT, $data);
     Transaction::saveTransaction($user->id, $deposit_before, -($fantasy->deposit + $fantasy->fee), $trans_descr);
     //если нужно - увеличиваем призовой фонд
     $total_sum_rates = $draftModel->getCountFantasyDrafts($fantasy->id) * $fantasy->deposit;
     if ($total_sum_rates > $fantasy->prize_pool_real) {
         DotaFantasy::upateRealPrizePool($fantasy->id, $total_sum_rates);
     }
     return true;
 }
Ejemplo n.º 14
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;
 }
Ejemplo n.º 15
0
</div>
				<div class="col col25 t-right"><?php 
    echo Yii::$app->formatter->asDecimal($trans['deposit_before'], 2);
    ?>
$</div>
				<div class="col col20 t-right"><?php 
    echo Transaction::showTransactionValue($trans['value']);
    ?>
</div>
				<div class="col col25 t-right"><b class="blue"><?php 
    echo Yii::$app->formatter->asDecimal($trans['deposit_before'] + $trans['value'], 2);
    ?>
$</b></div>
				<div class="clr"></div>
				<div class="col-text"><?php 
    echo Transaction::buildTransactionDescr($trans['descr']);
    ?>
</div>
			</div>
		<?php 
}
?>
	</div>
	<a href="<?php 
echo Url::to('cabinet/transactions');
?>
" class="view-all"><?php 
echo Yii::t('app', 'CABINET_SHOW_ALL');
?>
</a>
</div>
Ejemplo n.º 16
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;
 }
Ejemplo n.º 17
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTransaction()
 {
     return $this->hasOne(Transaction::className(), ['id' => 'transaction_id']);
 }
Ejemplo n.º 18
0
/* @var $model common\models\Books */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="books-form">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

    <?php 
echo $form->field($model, 'ttl')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'status')->dropDownList(\common\models\Transaction::getRequestStatuses(), ['prompt' => '--Ожидаемый статус--']);
?>

    <?php 
echo $form->field($model, 'description')->textarea(['cols' => 80, 'rows' => 5]);
?>


    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Добавить' : 'Редактировать', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
Ejemplo n.º 19
0
 /**
  * Finds the Transaction model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Transaction the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Transaction::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 20
0
 public function actionTransactions()
 {
     echo '<pre>';
     print_r('actionTransactions');
     echo '</pre>';
     //die;
     $user_id = 19;
     $data = ['fantasy_id' => 7];
     $trans_descr = Transaction::buildTransactionDescrForSave(Transaction::TR_TYPE_FANTASY_PAYMENT, $data);
     echo '<pre>$trans_descr ';
     print_r($trans_descr);
     echo '</pre>';
     //die;
     $deposit_before = User::getDepositValue($user_id);
     $value = 10.9;
     echo '<pre>$deposit_before ';
     print_r($deposit_before);
     echo '</pre>';
     //die;
     //Transaction::saveTransaction($user_id, $deposit_before, $value, $trans_descr);
     $trans_txt = Transaction::buildTransactionDescr($trans_descr);
     echo '<pre>$trans_txt ';
     print_r($trans_txt);
     echo '</pre>';
     //die;
     die;
 }