Esempio n. 1
0
 public function actionInterkassaStatus1()
 {
     $data = $_POST;
     $data['ik_payment_desc'] = iconv('cp1251', 'utf-8', $data['ik_payment_desc']);
     if (!($transaction = Btransaction::model()->findByPk($data['ik_payment_id']))) {
         /** @var $transaction Btransaction */
         $transaction = new Btransaction();
         if (!preg_match('/(\\d+)-(\\d+)/', $data['ik_payment_id'], $matches)) {
             $data['alert'] = '!unhandled transaction';
             Yii::log('WARNING! IPN notification ' . print_r($data, true), 'info', 'payment');
             return;
         }
         $transaction->amount = $data['ik_payment_amount'];
         $transaction->id_user = $matches[1];
         $transaction->id_operation = 1;
         $transaction->time_start = time();
     }
     $transaction->amount_real = $data['ik_payment_amount'];
     $transaction->time_end = time();
     $transaction->status = 1;
     $transaction->info = serialize($data);
     $transaction->description = 'Пополнение счета';
     // прикрутить разбор "картой"
     $transaction->save(false);
     if ($user = $transaction->user) {
         $user->balance += $transaction->amount_real;
         $user->contact_count += floor($transaction->amount_real / 10);
         $user->saveAttributes(array('balance', 'contact_count'));
         //$user->con
     }
     Yii::log('IPN notification ' . print_r($data, true), 'info', 'payment');
 }
Esempio n. 2
0
    /**
     * Аццкий говнокод
     *
     */
    public function actionOrderService()
    {
        $service = Yii::app()->request->getPost('service');
        $model = Anketa::model()->findByPk(Yii::app()->user->id);
        $transaction = new Btransaction();
        $transaction->id_user = $model->id;
        $transaction->time_end = $transaction->time_start = time();
        $transaction->info = array('ip' => $_SERVER['REMOTE_ADDR']);
        $time_task = $time_top = $time_premium = 0;
        switch ($service) {
            case 1:
                // подъем анкеты
                if (Btransaction::model()->count('id_user = :id_user AND time_start > :delta AND description = :description', array(':id_user' => $transaction->id_user, ':delta' => time() - 60 * 5, ':description' => 'Поднятие анкеты'))) {
                    //Yii::app()->end();
                    $this->redirect(Yii::app()->request->getUrlReferrer());
                }
                // если чаще, чем в 5 минут - не списываем
                $transaction->amount = -100;
                $transaction->description = 'Поднятие анкеты';
                $transaction->status = 1;
                $model->setUp();
                break;
            case 2:
                $transaction->amount = -250;
                $transaction->description = 'ТОП на 2 недели';
                $transaction->status = 1;
                $time_top = 14 * 24 * 3600;
                break;
            case 3:
                $transaction->amount = -400;
                $transaction->description = 'ТОП на 30 дней ';
                $transaction->status = 1;
                $time_top = 30 * 24 * 3600;
                break;
            case 4:
                $transaction->amount = -ServiceManager::getPrice(4);
                $transaction->description = 'ПРЕМИУМ 2 недели';
                $transaction->status = 1;
                $time_premium = 14 * 24 * 3600;
                break;
            case 5:
                $transaction->amount = -ServiceManager::getPrice(5);
                $transaction->description = 'ПРЕМИУМ на 30 дней';
                $transaction->status = 1;
                $time_premium = 30 * 24 * 3600;
                break;
            case 6:
                $transaction->amount = -ServiceManager::getPrice(6);
                $transaction->description = 'ПРЕМИУМ на 3 дня';
                $transaction->status = 1;
                $time_premium = 3 * 24 * 3600;
                break;
            default:
                Yii::app()->user->setFlash('error', 'Неверная операция');
                $this->redirect(Yii::app()->request->getUrlReferrer());
        }
        if ($time_top) {
            $model->top = 1;
            $time_task = $time_top;
            $task = 'untop';
        }
        if ($time_premium) {
            /**
             * Если человек с пробным аккаунтом проплачивает прем – неизрасходованный пробник в двойном размере
             * прибавляется к прему. Т.е. человек, мгновенно оплативший прем после регистрации получит 72 часа к прему.
             */
            $bonus_time = 0;
            if ($model->getAccountType() == Anketa::ACCOUNT_TRIAL) {
                $bonus_time = ($model->trial_end - time()) * 2;
            }
            if ($bonus_time <= 0) {
                $bonus_time = 0;
            }
            $model->setPremium(1);
            $time_task = $time_premium + $bonus_time;
            $task = 'unpremium';
        }
        if ($model->balance + $transaction->amount < 0) {
            Yii::app()->user->setFlash('error', 'Недостаточно средств');
            $this->redirect(Yii::app()->request->getUrlReferrer());
        }
        if ($time_task) {
            $q = 'INSERT INTO `task` (id_user, `type`,time_task,`data`,status)
VALUES (:id_user,:type,:time_task+UNIX_TIMESTAMP(),:data,:status)
ON DUPLICATE KEY UPDATE
 time_task = GREATEST(time_task,UNIX_TIMESTAMP()) + :time_task,status=:status;';
            Yii::app()->db->createCommand($q)->execute(array(':id_user' => $transaction->id_user, ':type' => $task, ':time_task' => $time_task, ':data' => '', ':status' => 1));
        }
        $transaction->info = serialize($transaction->info);
        if ($transaction->save(false)) {
            // без валидации..
            $model->addBalance($transaction->amount);
            $model->savePriority();
        }
        Yii::app()->user->setFlash('success', 'Услуга &laquo;' . $transaction->description . '&raquo; успешно активирована');
        $this->checkUnBadStatus($model, $service);
        $this->redirect(Yii::app()->request->getUrlReferrer());
    }