コード例 #1
0
ファイル: pscb.php プロジェクト: Nikitian/fl-ru-damp
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/stdf.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/pskb.php";
require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/log.php";
$src = __paramValue('int', $get['res']);
$state = __paramValue('int', $post['state']);
$lc_id = __paramValue('int', $post['account']);
$log_data = array('GET' => $get, 'POST' => $post);
if (!pskb::validateCardRequest($post)) {
    $src = 2;
    $state = -999;
    $log_data['err'] = array('src' => $src, 'state' => $state);
}
$log = new log("pskb_cards/income-" . SERVER . '-%d%m%Y.log', 'a', '%d.%m.%Y %H:%M:%S : ' . $_SERVER['REMOTE_ADDR'] . ' : ');
$log->writevar($log_data);
$pskb = new pskb();
$_lc = $pskb->getLCbyLCId($lc_id);
$err_msg = "Неизвестная ошибка";
if ($src == 2) {
    if ($state && in_array($state, array_keys(pskb::$card_messages))) {
        $err_msg = pskb::$card_messages[$state];
    }
    if (!in_array($state, array(2, -999))) {
        $pskb->upLC(array('state' => 'err', 'stateReason' => $err_msg), $_lc['lc_id']);
    }
}
if ($src === 1 && defined('PSKB_TEST_MODE')) {
    $lc = new pskb_lc(json_encode($_lc));
    $lc->id = $_lc['lc_id'];
    $lc->state = 'cover';
    $test = new pskb_server();
    $test->set($lc);
コード例 #2
0
ファイル: pskb.php プロジェクト: uadev/fl-ru-damp
 public function serve($method, $params = array())
 {
     switch ($method) {
         case 'checkOrCreateWallet':
             $num = $params['num'];
             //имитация
             $test['+71234567890'] = array("state" => "EXIST", "message" => "Уже создан +71234567890", "fio" => "Власов Павел Владимирович", "verified" => TRUE, "identified" => false);
             $test['+79272540217'] = array("state" => "EXIST", "message" => "Cоздан +79272540217", "fio" => "Власов Павел Владимирович", "verified" => TRUE, "identified" => TRUE);
             $test['+380664848120'] = array("state" => "EXIST", "message" => "Уже создан +380664848120", "fio" => "Власов Павел Владимирович", "verified" => FALSE, "identified" => TRUE);
             $test['+79034731235'] = array("state" => "EXIST", "message" => "Уже создан +79034731235", "fio" => "Власов Павел Владимирович", "verified" => TRUE, "identified" => TRUE);
             /*
             $test['+380664848120'] = array(
                 "state" => "EXIST",
                 "message" => "Уже создан +380664848120",
                 "fio" => "Власов Павел Владимирович",
                 "verified" => TRUE,
                 "identified" => false
             );                 
             */
             if (isset($test[$num])) {
                 $lc = $test[$num];
             } else {
                 $lc = array();
             }
             break;
         case 'superCheck':
             //$params = json_decode(file_get_contents('php://input'), 1);
             $ids = explode(",", $params['id']);
             /*if(is_array($params['id'])) {
                   $ids = array_map('intval', $params['id']);
               } else {
                   $ids = array(intval($params['id']));
               }*/
             $ids = array_map('intval', $ids);
             $lcs = $this->getRows($ids);
             if (!$lc) {
                 $lc = $this->_err('Ошибка. Счет не найден.');
             }
             $pskb = new pskb();
             foreach ($lcs as $k => $lc) {
                 if ($lc->state == 'trans') {
                     $lc->state = pskb::PAYOUT_END;
                     $this->set($lc);
                 }
                 $pskb_lc = $pskb->getLCbyLCId($lc->id);
                 $lc->sum = $pskb_lc['sum'];
                 $lc->sumOpen = $pskb_lc['sumOpen'];
                 $lc->numDog = $pskb_lc['sbr_id'];
                 $lc->cover = date('d.m.Y H:i', strtotime($pskb_lc['dateCoverLC']));
                 $payouts = sbr_meta::getStatePayout(array($pskb_lc['sbr_id'], 0), true);
                 if ($payouts) {
                     foreach ($payouts as $payout) {
                         if ($lc->state != pskb::PAYOUT_END) {
                             continue;
                         }
                         $history = array('id' => $lc->id, 'state' => $lc->state, 'date' => date('d.m.Y H:i'), 'uid' => $pskb_lc['sbr_id'] . '-' . ($payout['num'] + 1), 'target' => $payout['user_id'] == $payout['emp_id'] ? false : true, 'sum' => $payout['credit_sum'], 'account' => $payout['user_id'] == $payout['emp_id'] ? $pskb_lc['accCust'] : $pskb_lc['accPerf'], 'ps' => $payout['user_id'] == $payout['emp_id'] ? $pskb_lc['ps_emp'] : $pskb_lc['ps_frl']);
                         $lc->history[] = new pskb_lc(json_encode($history));
                     }
                 }
                 $lcs[$k] = $lc;
             }
             $post = json_encode($lcs);
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $params['urlRejoin']);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
             curl_setopt($ch, CURLOPT_TIMEOUT, 30);
             if (defined('BASIC_AUTH')) {
                 curl_setopt($ch, CURLOPT_USERPWD, BASIC_AUTH);
             }
             $res = curl_exec($ch);
             return;
             break;
         case 'historyLC':
             $id = intval($params['id']);
             $lc = $this->get($id);
             if (!$lc) {
                 $lc = $this->_err('Ошибка. Счет не найден.');
             }
             if ($lc->state == 'trans') {
                 $lc->state = pskb::PAYOUT_END;
                 $this->set($lc);
             }
             $lc->sum = 1000;
             $lc->account = '79210000000';
             $lc->uid = $params['uid'];
             $lc->target = $params['target'] ? $params['target'] : true;
             $lc->date = date('d.m.Y H:i');
             break;
         case 'addLC':
             $lc = new pskb_lc();
             $lc->state = 'form';
             $lc->stateReason = 'test';
             foreach ($params as $k => $v) {
                 $lc->{$k} = $v;
             }
             $lc = $this->set($lc);
             break;
         case 'checkLC':
             $id = intval($params['id']);
             $lc = $this->get($id);
             if (!$lc) {
                 $lc = $this->_err('Ошибка. Счет не найден.');
             }
             //                $m = new memBuff();
             //                $cntr = intval($m->get('___lc_cntr__' . $lc->id));
             //
             //                if ($lc->state == 'form' && $cntr == 3) {
             //                    $lc->state = 'err';
             //                    $lc->stateReason = '500';
             //                    $this->set($lc);
             //                }
             //
             //                if ($lc->state == 'form' && $cntr > 5) {
             //                    $lc->state = 'new';
             //                    $this->set($lc);
             //                }
             //
             //                $m->set('___lc_cntr__' . $lc->id, ($cntr+1));
             //
             if ($lc->state == 'form') {
                 $lc->state = 'new';
                 $this->set($lc);
             }
             break;
         case 'checks':
             $this->expStatusUpdate();
             $id = json_decode(file_get_contents('php://input'), 1);
             $ids = $id['id'];
             $lc = $this->getRows($ids);
             if (!$lc) {
                 $lc[] = $this->_err('Ошибка. Счет не найден.');
             }
             break;
         case 'changeDateLC':
             $id = intval($params['id']);
             $lc = $this->get($id);
             if (!$lc) {
                 $lc = $this->_err('Ошибка. Счет не найден.');
                 break;
             }
             if ($lc->status == 'end') {
                 $lc = $this->_err('Ошибка. Счет не найден.');
                 break;
             }
             foreach ($params as $k => $v) {
                 $lc->{$k} = $v;
             }
             $this->set($lc);
             break;
         case 'openLC':
             $id = intval($params['id']);
             $lc = $this->get($id);
             if (!$lc) {
                 $lc = $this->_err('Ошибка. Счет не найден.');
                 break;
             }
             if ($lc->status == 'end') {
                 $lc = $this->_err('Ошибка. Счет не найден.');
                 break;
             }
             $lc->state = 'passed';
             $lc->sms = strtoupper(substr(md5(time()), 3, 4));
             $this->set($lc);
             break;
         case 'subOpenLC':
             $id = intval($params['id']);
             $lc = $this->get($id);
             $code = $params['asp'];
             if (!$lc) {
                 $lc = $this->_err('Ошибка. Счет не найден.');
                 break;
             }
             if ($lc->status == 'end') {
                 $lc = $this->_err('Ошибка. Счет не найден.');
                 break;
             }
             if ($code != $lc->sms) {
                 $lc = $this->_err('Неверный код подтверждения.');
                 break;
             }
             foreach ($params as $k => $v) {
                 $lc->{$k} = $v;
             }
             $lc->state = 'trans';
             $this->set($lc);
             break;
         case 'transLC':
             $id = intval($params['id']);
             $lc = $this->get($id);
             if (!$lc) {
                 $lc = $this->_err('Ошибка. Счет не найден.');
                 break;
             }
             if ($lc->state != 'err') {
                 $lc = $this->_err('Ошибка. Приемлемо только для LC в статусе err.');
                 break;
             }
             $lc->state = 'end';
             $this->set($lc);
             break;
         case 'reqCode':
             $id = intval($params['id']);
             $lc = $this->get($id);
             if (!$lc) {
                 $lc = $this->_err('Ошибка. Счет не найден.');
                 break;
             }
             if ($lc->state != 'passed') {
                 $lc = $this->_err('Ошибка. Приемлемо только для LC в статусе passed.');
                 break;
             }
             $lc->sms = strtoupper(substr(md5(time()), 3, 4));
             $this->set($lc);
             break;
         default:
             $lc = $this->_err('Ошибка запроса.');
     }
     echo json_encode($lc);
     exit;
 }