public function actionRemoveHwid() { if (request()->isPostRequest) { try { $gs = Gs::model()->opened()->findByPk(user()->getGsId()); $l2 = l2('ls', $gs->login_id)->connect(); $res = $l2->removeHWID(user()->get('login')); if ($res > 0) { // Логирую действие юзера if (app()->params['user_actions_log']) { $log = new UserActionsLog(); $log->user_id = user()->getId(); $log->action_id = UserActionsLog::ACTION_SERVICES_REMOVE_HWID; $log->save(FALSE); } user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Привязка к HWID удалена.')); } else { user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Аккаунт не привязан к HWID.')); } } catch (Exception $e) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.')); Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, __METHOD__ . ' ' . __LINE__); } $this->refresh(); } $this->render('//cabinet/services/remove-hwid'); }
public function init() { if (($data = cache()->get(CacheNames::SERVER_STATUS)) === FALSE) { if (config('server_status.allow') == 1) { $data['content'] = array(); $data['totalOnline'] = 0; $criteria = new CDbCriteria(array('select' => 't.name, t.id, t.fake_online, t.ip, t.port', 'scopes' => array('opened'), 'with' => array('ls' => array('select' => 'ls.ip, ls.port, ls.name', 'scopes' => array('opened'))))); $gsList = Gs::model()->findAll($criteria); if ($gsList) { foreach ($gsList as $gs) { try { $l2 = l2('gs', $gs->id)->connect(); // Кол-во игроков $online = $l2->getDb()->createCommand("SELECT COUNT(0) FROM `characters` WHERE `online` = 1")->queryScalar(); // Fake online if (is_numeric($gs->fake_online) && $gs->fake_online > 0) { $online += Lineage::fakeOnline($online, $gs->fake_online); } $data['content'][$gs->id] = array('gs_status' => Lineage::getServerStatus($gs->ip, $gs->port), 'ls_status' => isset($gs->ls) ? Lineage::getServerStatus($gs->ls->ip, $gs->ls->port) : 'offline', 'online' => $online, 'gs' => $gs); $data['totalOnline'] += $online; } catch (Exception $e) { $data[$gs->id]['error'] = $e->getMessage(); } } } if (config('server_status.cache') > 0) { cache()->set(CacheNames::SERVER_STATUS, $data, config('server_status.cache') * 60); } } } app()->controller->renderPartial('//server-status', $data); }
protected function afterConstruct() { $this->gs_list = Gs::model()->getOpenServers(); if (count($this->gs_list) == 1) { $this->gs_id = key($this->gs_list); } parent::afterConstruct(); }
public function actionIndex() { $model = new Tickets(); if (isset($_GET['Tickets'])) { $model->setAttributes($_GET['Tickets']); } $dataProvider = $model->search(); $this->render('//tickets/index', array('dataProvider' => $dataProvider, 'gs' => CHtml::listData(Gs::model()->cache(60)->findAll(), 'id', 'name'), 'categories' => CHtml::listData(TicketsCategories::model()->cache(60)->findAll(), 'id', 'title'), 'model' => $model)); }
public function init() { parent::init(); $dependency = new CDbCacheDependency("SELECT MAX(UNIX_TIMESTAMP(updated_at)) FROM {{gs}} WHERE status = :status"); $dependency->params = array('status' => ActiveRecord::STATUS_ON); $dependency->reuseDependentData = TRUE; $gsList = Gs::model()->cache(3600 * 24, $dependency)->opened()->findAll(); foreach ($gsList as $row) { $this->_gs_list[$row->getPrimaryKey()] = $row; } require_once Yii::getPathOfAlias('application.helpers') . DIRECTORY_SEPARATOR . 'lineage.php'; }
public function actionIndex() { if (isset($_REQUEST)) { Yii::import('application.modules.deposit.extensions.Deposit.Deposit'); $deposit = new Deposit(); if (!$deposit->init()) { app()->end(); } try { /** * @var Transactions $transaction */ $transaction = $deposit->processed(); $percents = (double) config('referral_program.percent'); Yii::log("Deposit::log\n" . print_r($_REQUEST, TRUE), CLogger::LEVEL_INFO, 'application.modules.deposit.controllers.DefaultController::' . __LINE__); // Начисляю партнёрку if ($percents > 0 && $transaction) { // Смотрю есть ли реферер $referer = Referals::model()->find('referal = :referal', array(':referal' => $transaction->user_id)); if ($referer !== NULL) { $refererProfile = UserProfiles::model()->with('user')->find('t.user_id = :user_id', array(':user_id' => $referer->referer)); if ($refererProfile) { $gsModel = Gs::model()->findByPk($transaction->getGsId()); // Кол-во предметов которые были куплены, от них будет считаться % рефералу $countItems = $transaction->getSum() / $gsModel->deposit_course_payments; $profit = $countItems / 100 * $percents; $refererProfile->balance += $profit; $refererProfile->save(FALSE, array('balance', 'updated_at')); // Логирую $dataDb = array('referer_id' => $refererProfile->user_id, 'referal_id' => $transaction->getUserId(), 'profit' => $profit, 'sum' => $transaction->getSum(), 'percent' => $percents, 'transaction_id' => $transaction->getPrimaryKey(), 'created_at' => date('Y-m-d H:i:s')); db()->createCommand()->insert('{{referals_profit}}', $dataDb); // Отправляю письмо что баланс реферера был пополнен notify()->rechargeBalanceByReferal($refererProfile->user->email, array('profit' => $profit)); // Логирую действие юзера if (app()->params['user_actions_log']) { $log = new UserActionsLog(); $log->user_id = $transaction->getUserId(); $log->action_id = UserActionsLog::ACTION_DEPOSIT_SUCCESS; $log->params = json_encode($dataDb); $log->save(); } } } } echo $deposit->success(Yii::t('main', 'Ваш баланс успешно пополнен.')); } catch (Exception $e) { echo $deposit->error($e->getMessage()); } } else { $this->redirect(array('/index/default/index')); } }
public function afterConstruct() { $dependency = new CDbCacheDependency("SELECT COUNT(0), MAX(UNIX_TIMESTAMP(updated_at)) FROM {{gs}} WHERE status = :status"); $dependency->params = array('status' => ActiveRecord::STATUS_ON); $dependency->reuseDependentData = TRUE; $res = Gs::model()->cache(3600 * 24, $dependency)->opened()->findAll(); if ($res) { foreach ($res as $gs) { $this->gs_list[$gs['id']] = $gs; } } unset($res); if (count($this->gs_list) == 1) { $this->gs_id = key($this->gs_list); } parent::afterConstruct(); }
/** * @param string $type gs|ls * @param int $id * * @throws Exception * * @return void */ private function init($type, $id) { if ($type == 'gs') { $dependency = new CDbCacheDependency("SELECT COUNT(0), MAX(UNIX_TIMESTAMP(updated_at)) FROM {{gs}} WHERE status = :status AND id = :id"); $dependency->params = array('status' => ActiveRecord::STATUS_ON, 'id' => $id); $dependency->reuseDependentData = TRUE; $this->_config = Gs::model()->cache(3600 * 24, $dependency)->opened()->findByPk($id); } elseif ($type == 'ls') { $dependency = new CDbCacheDependency("SELECT COUNT(0), MAX(UNIX_TIMESTAMP(updated_at)) FROM {{ls}} WHERE status = :status AND id = :id"); $dependency->params = array('status' => ActiveRecord::STATUS_ON, 'id' => $id); $dependency->reuseDependentData = TRUE; $this->_config = Ls::model()->cache(3600 * 24, $dependency)->opened()->findByPk($id); } if (!$this->_config) { Yii::log('Настройки в БД для ' . $type . ' с ID ' . $id . ' не найдены', CLogger::LEVEL_ERROR, 'Lineage::init'); throw new Exception('Настройки в БД для ' . $type . ' с ID ' . $id . ' не найдены'); } }
/** * Список GS * * @return array */ public function getGs() { return HTML::listData(Gs::model()->findAll(), 'id', 'name'); }
/** * Добавление предмета в набор * * @param int $gs_id * @param int $category_id * @param int $pack_id * @param int $item_id */ public function actionShopCategoryPackEditItem($gs_id, $category_id, $pack_id, $item_id) { $model = ShopItems::model()->with('itemInfo')->findByPk($item_id); if ($model === NULL) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('backend', 'Предмет не найден.')); $this->redirect(array('/backend/gameServers/shopCategoryPackItems', 'gs_id' => $gs_id, 'category_id' => $category_id, 'pack_id' => $pack_id)); } $model->item_name = $model->itemInfo->name . ($model->itemInfo->add_name ? ' (' . $model->itemInfo->add_name . ')' : ''); if (isset($_POST[CHtml::modelName($model)])) { $model->setAttributes($_POST[CHtml::modelName($model)]); $model->pack_id = $pack_id; if ($model->save()) { user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('backend', 'Изменения сохранены.')); $this->refresh(); } } $this->render('//gs/shop/category/packs/itemForm', array('gs' => Gs::model()->findByPk($gs_id), 'category' => $this->loadShopCategoriesModel($category_id), 'pack' => $this->loadShopItemsPacksModel($pack_id), 'model' => $model)); }
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; }