public function save() { //create Match $match = new IntCorrelation(); $match->account_id = $this->account_id; $match->owner = Yii::app()->user->id; $match->save(); //bankbooks foreach ($this->in as $transaction => $true) { $transaction = Transactions::model()->findByPk($transaction); if ($transaction !== null) { $transaction->intCorrelation = $match->id; $transaction->intType = true; $transaction->save(); } } //transaction foreach ($this->out as $transaction => $true) { $transaction = Transactions::model()->findByPk($transaction); if ($transaction !== null) { $transaction->intCorrelation = $match->id; $transaction->intType = false; $transaction->save(); } } return $match->id; }
public function save() { //create Match $match = new ExtCorrelation(); $match->account_id = $this->account_id; $match->owner = Yii::app()->user->id; $match->save(); //bankbooks //print_r($this->Bankbooks); //print_r($this->Transactions); foreach ($this->Bankbooks['match'] as $bankbook => $true) { Yii::log("bank:" . $bankbook, 'info', 'app'); $bankbook = Bankbook::model()->findByPk($bankbook); if ($bankbook !== null) { $bankbook->extCorrelation = $match->id; $bankbook->save(); } } //transaction foreach ($this->Transactions['match'] as $transaction => $true) { Yii::log("trans:" . $transaction, 'info', 'app'); $transaction = Transactions::model()->findByPk($transaction); if ($transaction !== null) { $transaction->extCorrelation = $match->id; $transaction->save(); } } return $match->id; }
public function actionIndex() { $dependency = new CDbCacheDependency('SELECT COUNT(0) FROM {{transactions}} WHERE user_id = :user_id'); $dependency->params = array('user_id' => user()->getId()); $model = Transactions::model()->cache(3600 * 24, $dependency, 2); $dataProvider = new CActiveDataProvider($model, array('criteria' => array('condition' => 'user_id = :user_id', 'params' => array('user_id' => user()->getId()), 'order' => 'created_at DESC'), 'pagination' => array('pageSize' => config('cabinet.transaction_history.limit'), 'pageVar' => 'page'))); $this->render('//cabinet/transaction-history', array('dataProvider' => $dataProvider)); }
public function actionProcessed() { $transactionId = app()->session['transaction_id']; $model = Transactions::model()->findByPk($transactionId); // Транзакция не найдена if ($model === NULL) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Транзакция не найдена.')); $this->redirect(array('index')); } if ($model->isPaid()) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Транзакция уже обработана.')); $this->redirect(array('index')); } $deposit = new Deposit(); $deposit->init($model->payment_system); $this->render('//cabinet/deposit/processed', array('model' => $model, 'fields' => $deposit->getFields($model), 'formAction' => $deposit->getFormAction(), 'deposit' => $deposit)); }
private function calc($accounts = array(), $types = array()) { $sum = 0; $yiidatetimesec = Yii::app()->locale->getDateFormat('yiidatetimesec'); $phpdbdatetime = Yii::app()->locale->getDateFormat('phpdbdatetime'); $from_date = date($phpdbdatetime, CDateTimeParser::parse($this->from_date, $yiidatetimesec)); $to_date = date($phpdbdatetime, CDateTimeParser::parse($this->to_date, $yiidatetimesec)); $criteria = new CDbCriteria(); $criteria->condition = "date BETWEEN :from_date AND :to_date"; $criteria->params = array(':from_date' => $from_date, ':to_date' => $to_date); $criteria->compare('type', $types); $criteria->compare('account_id', $accounts); $trans = Transactions::model()->findAll($criteria); $sum = 0; $data = array(); foreach ($trans as $tran) { $sum = $tran->sum; if ($sum != 0) { $data[] = array('id' => $tran->id, 'name' => $tran->account_id, 'sum' => $sum, 'id6111' => $tran->id); } } return $data; }
public function getTotal($from_date, $to_date) { $sum = 0; $yiidatetimesec = Yii::app()->locale->getDateFormat('yiidatetimesec'); $phpdbdatetime = Yii::app()->locale->getDateFormat('phpdbdatetime'); $from_date = date($phpdbdatetime, CDateTimeParser::parse($from_date, $yiidatetimesec)); $to_date = date($phpdbdatetime, CDateTimeParser::parse($to_date, $yiidatetimesec)); $criteria = new CDbCriteria(); $criteria->condition = "account_id = :id"; $criteria->addCondition("valuedate BETWEEN :from_date AND :to_date"); $criteria->params = array(':id' => $this->id, ':from_date' => $from_date, ':to_date' => $to_date); $transactions = Transactions::model()->findAll($criteria); foreach ($transactions as $transaction) { $sum += $transaction->sum; } return $sum; }
public function make() { $this->id = rand(0, 999999); //$this->iniArr=array('b110'=>0,'b100'=>0,'m100'=>0,'c100'=>0,'d100'=>0,'d110'=>0,'d120'=>0,); //$this->docArr=array(0=>0,305=>0,300=>0,); $bkmv = ''; //$this->line=1; $yiidatetimesec = Yii::app()->locale->getDateFormat('yiidatetimesec'); $phpdbdatetime = Yii::app()->locale->getDateFormat('phpdbdatetime'); $from_date = date($phpdbdatetime, CDateTimeParser::parse($this->from_date . ":00", $yiidatetimesec)); $to_date = date($phpdbdatetime, CDateTimeParser::parse($this->to_date . ":00", $yiidatetimesec)); //$types=array(3,4,9,11,13,14); //accounts $criteria = new CDbCriteria(); $accounts = Accounts::model()->findAll($criteria); $record = array('id' => 'B110', 'name' => OpenFormatType::model()->getDesc('B110'), 'count' => 0); foreach ($accounts as $account) { $this->line++; $bkmv .= $account->openfrmt($this->line, $from_date, $to_date); $record['count']++; } $this->iniArr[] = $record; //items $criteria = new CDbCriteria(); $items = Item::model()->findAll($criteria); $record = array('id' => 'M100', 'name' => OpenFormatType::model()->getDesc('M100'), 'count' => 0); foreach ($items as $item) { $this->line++; $bkmv .= $item->openfrmt($this->line, $from_date, $to_date); $record['count']++; } $this->iniArr[] = $record; // //transactions $criteria = new CDbCriteria(); $criteria->condition = "valuedate BETWEEN :from_date AND :to_date"; $criteria->params = array(':from_date' => $from_date, ':to_date' => $to_date); $transactions = Transactions::model()->findAll($criteria); $record = array('id' => 'B100', 'name' => OpenFormatType::model()->getDesc('B100'), 'count' => 0); foreach ($transactions as $transaction) { $this->line++; $bkmv .= $transaction->openfrmt($this->line, $from_date, $to_date); $record['count']++; } $this->iniArr[] = $record; //docs $criteria = new CDbCriteria(); $criteria->condition = "due_date BETWEEN :from_date AND :to_date"; $criteria->params = array(':from_date' => $from_date, ':to_date' => $to_date); $docs = Docs::model()->findAll($criteria); //OpenFormatType::model()->getDesc('C100') $record = array('id' => 'C100', 'name' => OpenFormatType::model()->getDesc('C100'), 'count' => 0); $d110 = array('id' => 'D110', 'name' => OpenFormatType::model()->getDesc('D110'), 'count' => 0); $d120 = array('id' => 'D120', 'name' => OpenFormatType::model()->getDesc('D120'), 'count' => 0); foreach ($docs as $doc) { if ($doc->docType->openformat != '0') { $this->line++; $bkmv .= $doc->openfrmt($this->line, $from_date, $to_date); foreach ($doc->docDetailes as $detial) { $this->line++; $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date); $d110['count']++; } foreach ($doc->docCheques as $detial) { $this->line++; $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date); $d120['count']++; } $type = $doc->getType(); $this->docArr[$type] = isset($this->docArr[$type]) ? $this->docArr[$type] + 1 : 0; $this->docSumArr[$type] = isset($this->docSumArr[$type]) ? $this->docSumArr[$type] + $doc->total : $doc->total; $record['count']++; } } $this->iniArr[] = $record; $this->iniArr[] = $d110; $this->iniArr[] = $d120; $company = Settings::model()->findByPk('company.name'); //A100 $bkmv = $company->a100(1, $this->id) . $bkmv; //Z900 $bkmv = $bkmv . $company->z900($this->line + 1, $this->id, $this->line + 1); $bkmvFile = new Files(); $bkmvFile->name = 'bkmvdata.txt'; $bkmvFile->path = 'openformat/'; // $bkmvFile->expire = 360; $bkmvFile->save(); $bkmvFile->writeFile($bkmv); $this->bkmvId = $bkmvFile->id; //A000 $ini = $company->a000(1, $this->id, $this->line + 1); foreach ($this->iniArr as $line) { $ini .= $line['id'] . sprintf("%015d", $line['count']) . "\r\n"; } //Z $iniFile = new Files(); $iniFile->name = 'ini.txt'; $iniFile->path = 'openformat/'; // $iniFile->expire = 360; $iniFile->save(); $iniFile->writeFile($ini); $this->iniId = $iniFile->id; return $this->id; }
public static function getMax() { $model = new Transactions(); $criteria = new CDbCriteria(); $criteria->select = 'max(num) AS maxNum'; $row = $model->model()->find($criteria); return $row['maxNum']; }
public function processed() { $aggregator = $this->_aggregator; // Проверка необходимых параметров $aggregator->checkParams(); // Проверка подписи $aggregator->checkSignature(); if ($aggregator->isSms()) { $paymentSystem = $this->_aggregator_id == self::PAYMENT_SYSTEM_UNITPAY ? self::PAYMENT_SYSTEM_UNITPAY_SMS : self::PAYMENT_SYSTEM_WAYTOPAY_SMS; if ($paymentSystem == self::PAYMENT_SYSTEM_UNITPAY_SMS) { $transactionId = $aggregator->getId(); /** @var Transactions $transaction */ $transaction = Transactions::model()->findByPk($transactionId); if (!$transaction) { throw new Exception('Транзакция не найдена.'); } elseif ($transaction->isPaid()) { throw new Exception('Транзакция уже обработана.'); } elseif ($transaction->getSum() != $aggregator->getSum()) { throw new Exception('Сумма не совпадает.'); } $gsModel = Gs::model()->findByPk($transaction->gs_id); if (!$gsModel) { throw new Exception('Сервер не найден.'); } $tr = db()->beginTransaction(); try { $transaction->status = Transactions::STATUS_SUCCESS; $transaction->save(FALSE, array('status', 'updated_at')); $this->recharge($transaction->user_id, $aggregator->getSum(), $gsModel->deposit_course_payments); $tr->commit(); } catch (Exception $e) { $tr->rollback(); Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, 'modules.deposit.extensions.Deposit.' . __LINE__); throw new Exception('Ошибка'); } } elseif ($paymentSystem == self::PAYMENT_SYSTEM_WAYTOPAY_SMS) { $userId = $aggregator->getId(); $gsId = $aggregator->getGsId(); $userModel = Users::model()->findByPk($userId); if (!$userModel) { throw new Exception('Аккаунт не найден.'); } $gsModel = Gs::model()->findByPk($gsId); if (!$gsModel) { throw new Exception('Сервер не найден.'); } $count = floor($aggregator->getProfit() / $gsModel->deposit_course_payments); $tr = db()->beginTransaction(); try { $transaction = new Transactions(); $transaction->payment_system = $paymentSystem; $transaction->user_id = $userId; $transaction->sum = (double) $aggregator->getProfit(); $transaction->count = $count; $transaction->status = Transactions::STATUS_SUCCESS; $transaction->params = serialize($_REQUEST); $transaction->gs_id = $gsId; $transaction->save(FALSE); $gsModel = Gs::model()->findByPk($gsId); if (!$gsModel) { throw new Exception('Сервер не найден.'); } $this->recharge($userId, $aggregator->getSum(), $gsModel->deposit_course_payments); $tr->commit(); } catch (Exception $e) { $tr->rollback(); Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, 'modules.deposit.extensions.Deposit.' . __LINE__); throw new Exception('Ошибка'); } } } else { $transactionId = $aggregator->getId(); $transaction = Transactions::model()->findByPk($transactionId); if (!$transaction) { throw new Exception('Транзакция не найдена.'); } if ($transaction->isPaid()) { throw new Exception('Транзакция уже обработана.'); } elseif ($transaction->getSum() != $aggregator->getSum()) { throw new Exception('Сумма не совпадает.'); } $transaction->status = Transactions::STATUS_SUCCESS; $gsModel = Gs::model()->findByPk($transaction->gs_id); if (!$gsModel) { throw new Exception('Сервер не найден.'); } $tr = db()->beginTransaction(); try { $transaction->save(FALSE, array('status', 'updated_at')); $this->recharge($transaction->user_id, $aggregator->getSum(), $gsModel->deposit_course_payments); $tr->commit(); } catch (Exception $e) { $tr->rollback(); throw new Exception($e->getMessage()); } } return $transaction; }