예제 #1
0
파일: Anketa.php 프로젝트: nellka/mebel
 public function addBonusBalance($balance)
 {
     $data = array('admin' => Yii::app()->user->id, 'ip' => $_SERVER['REMOTE_ADDR'], 'description' => 'Бонус от сервиса');
     $transaction = new Btransaction();
     $transaction->amount = $balance;
     $transaction->id_user = $this->id;
     $transaction->id_operation = 2;
     $transaction->time_end = $transaction->time_start = time();
     $transaction->amount_real = 0;
     $transaction->time_end = time();
     $transaction->status = 1;
     $transaction->info = serialize($data);
     $transaction->description = 'Бонус от сервиса';
     if ($transaction->save(false)) {
         $this->addBalance($transaction->amount);
     } else {
         return false;
     }
     return true;
 }
예제 #2
0
 /**
     * onpay status
     * @link http://wiki.onpay.ru/doku.php?id=api-notify
     * @link http://wiki.onpay.ru/doku.php?id=payment-links-specs
 2013/11/21 01:18:36 [info] [payment] IPN notification Array
 (
    [type] => check
    [amount] => 100.0
    [order_amount] => 100.0
    [order_currency] => TST
    [pay_for] => 4932797
    [md5] => B6C80B7F925CD99C1CC8B35AEE6F8630
 )
    2013/11/21 01:33:39 [info] [payment] IPN notification Array
    (
    [type] => check
    [amount] => 100.0
    [order_amount] => 100.0
    [order_currency] => TST
    [pay_for] => 4932797
    [md5] => B6C80B7F925CD99C1CC8B35AEE6F8630
    )
     *
    2013/11/21 01:39:59 [info] [payment] IPN notification Array
    (
    [type] => pay
    [onpay_id] => 7261069
    [amount] => 100.0
    [balance_amount] => 100.0
    [balance_currency] => TST
    [order_amount] => 100.0
    [order_currency] => TST
    [exchange_rate] => 1.0
    [pay_for] => 4932797
    [paymentDateTime] => 2013-11-21T01:39:59+04:00
    [user_email] => ivan5@iv-an.ru
    [user_phone] =>
    [paid_amount] => 100.0
    [md5] => 99C40DE7B5F231B7E54C59A06A8C0A1C
    )
     *
    2013/11/21 01:50:48 [info] [payment] IPN notification Array
    (
    [type] => check
    [amount] => 100.0
    [order_amount] => 100.0
    [order_currency] => TST
    [pay_for] => 4932797
    [md5] => B6C80B7F925CD99C1CC8B35AEE6F8630
    )
     *
    2013/11/21 01:51:54 [info] [payment] IPN notification Array
    (
    [type] => pay
    [onpay_id] => 7261103
    [amount] => 100.0
    [balance_amount] => 100.0
    [balance_currency] => TST
    [order_amount] => 100.0
    [order_currency] => TST
    [exchange_rate] => 1.0
    [pay_for] => 4932797
    [paymentDateTime] => 2013-11-21T01:51:54+04:00
    [user_email] => ivan5@iv-an.ru
    [user_phone] =>
    [paid_amount] => 100.0
    [md5] => E1532BFA5BB6CA8511F17ECA6B8A1871
    )
     *
    2013/11/21 02:22:17 [info] [payment] IPN notification Array
    (
    [type] => check
    [amount] => 100.0
    [order_amount] => 100.0
    [order_currency] => TST
    [pay_for] => 4932797
    [md5] => B6C80B7F925CD99C1CC8B35AEE6F8630
    [code] => 0
    [d_errors] =>
     *
    2013/11/21 02:22:25 [info] [payment] IPN notification Array
    (
    [type] => pay
    [onpay_id] => 7261193
    [amount] => 100.0
    [balance_amount] => 100.0
    [balance_currency] => TST
    [order_amount] => 100.0
    [order_currency] => TST
    [exchange_rate] => 1.0
    [pay_for] => 4932797
    [paymentDateTime] => 2013-11-21T02:22:25+04:00
    [user_email] => ivan5@iv-an.ru
    [user_phone] =>
    [paid_amount] => 100.0
    [md5] => 4A79BCEF6EC06764ACB973840ACAF863
     *
    2013/11/21 02:27:08 [info] [payment] IPN notification Array
    (
    [type] => check
    [amount] => 100.0
 
 
    [order_amount] => 100.0
    [order_currency] => TST
    [pay_for] => 4932797
    [md5] => B6C80B7F925CD99C1CC8B35AEE6F8630
    [code] => 0
    [d_errors] =>
    )
 
     *
    2013/11/21 02:30:23 [info] [payment] IPN notification Array
    (
    [type] => pay
    [onpay_id] => 7261210
    [amount] => 100.0
    [balance_amount] => 100.0
    [balance_currency] => TST
    [order_amount] => 100.0
    [order_currency] => TST
    [exchange_rate] => 1.0
    [pay_for] => 4932797
    [paymentDateTime] => 2013-11-21T02:30:22+04:00
    [user_email] => ivan5@iv-an.ru
    [user_phone] =>
    [paid_amount] => 100.0
    [md5] => A79B7830ACE5269F076A1E1585CB07F8
 */
 public function actionOnpayStatus1()
 {
     /** @var $transaction Btransaction */
     $data = $_POST;
     /*
             if (!$transaction = Btransaction::model()->findByPk($data['ik_payment_id'])) {
                 $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::import('ext.payment.*');
     $onpay = new Onpay('other_db', 'atolin_ru', '3dNXOO4lPAN');
     if ($onpay->check_errors($data)) {
         $data['code'] = 0;
     } else {
         if (empty($data['order_amount'])) {
             $data['code'] = 0;
         } else {
             $data['code'] = 2;
         }
     }
     $data['d_errors'] = $onpay->error;
     Yii::log('IPN notification ' . print_r($data, true), 'info', 'payment');
     if ($data['type'] == 'pay') {
         $transaction = new Btransaction();
         $transaction->amount = $data['order_amount'];
         $transaction->id_user = $data['pay_for'];
         $transaction->id_operation = 1;
         $transaction->time_start = time();
         $transaction->amount_real = $data['order_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'));
         }
     }
     echo $onpay->gen_xml_answer($data);
     /*
             $code = 0;
             $keys = array(
                 'type' => $data['type'] == 'pay' ? 'pay' : 'check', //
                 'pay_for'=>$data['pay_for'],
                 'order_amount'=>$data['order_amount'],
                 'order_ticker'=>$data['order_currency'],
                 'code'=>$code,
                 'secret_key_for_api_in'=>'3dNXOO4lPAN',
             );
             // md5 - проверка ответа
             // check “type;pay_for;order_amount;order_ticker;secret_key_for_api_in”
             // pay “type;pay_for;onpay_id;order_amount;order_ticker;secret_key_for_api_in”
     
             //      “type;pay_for;order_amount;order_ticker;code;secret_key_api_in” (без кавычек)
             //     “type;pay_for;onpay_id;order_id;order_amount;order_ticker;code;secret_key_api_in”
             $md5 = implode(';',$keys);
             $md5 = md5($md5);
     echo '<?xml version="1.0" encoding="UTF-8"?>
     	<result>
     		<code>'.$code.'</code>
     		<pay_for>'.$data['pay_for'].'</pay_for>
     		<comment>OK</comment>
     		<md5>'.$md5.'</md5>
     	</result>';*/
 }
예제 #3
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());
    }