Example #1
0
 public function callbackGateway()
 {
     global $db, $get;
     $Status = $_POST['status'];
     $Refnumber = $_POST['refnumber'];
     $Resnumber = $_POST['resnumber'];
     if ($Status == 100) {
         $ParspalPin = trim($this->merchant);
         $pass = $this->pass;
         $payment = Cshop::app()->getDb()->prepare(QueryBuilder::getInstance()->select()->from('payment')->where('reference = ?'));
         $payment->execute(array($Resnumber));
         $payment = $payment->fetch();
         $amount = round($payment['amount'] / 10);
         $soapclient = new nusoap_client('http://merchant.parspal.com/WebService.asmx?wsdl', 'wsdl');
         $params = array('MerchantID' => $ParspalPin, 'Password' => $pass, 'Price' => $amount, 'RefNum' => $Refnumber);
         $res = $soapclient->call('verifyPayment', $params);
         $Status = $res['verifyPaymentResult']['ResultStatus'];
         if (strtolower($Status) == 'success') {
             return $payment;
         } else {
             $message = 'پرداخت ناموفق است. خطا';
         }
     } else {
         $message = 'پرداخت ناموفق است. خطا';
     }
     throw new Exception($message);
 }
Example #2
0
 public function callbackGateway()
 {
     $merchantID = $this->merchantID;
     $au = preg_replace('/[^a-z0-9]/', '', $_GET['au']);
     $ref_id = $_GET['order_id'];
     if (strlen($au) > 4) {
         $payment = Cshop::app()->getDb()->prepare(QueryBuilder::getInstance()->select()->from('payment')->where('id = ?'));
         $payment->execute(array($au));
         $payment = $payment->fetch();
         $amount = round($payment['amount'] / 10);
         $client = new nusoap_client('https://www.sibapal.com/payment/wsdl?wsdl', 'wsdl');
         $res = $client->call("verify", array($merchantID, $amount, $au));
         if ($payment['status'] == Application::STATUS_PENDING) {
             if (!empty($res) and $res == 1) {
                 return $payment;
             } else {
                 $message = 'پرداخت توسط سیباپال انجام نشده است .';
             }
         } else {
             $message = 'سفارش قبلا پرداخت شده است.';
         }
     } else {
         $message = 'شماره یکتا اشتباه است.';
     }
     throw new Exception($message);
 }
Example #3
0
 public function callbackGateway()
 {
     $result = $_POST['Result'];
     $requestId = $_POST['RequestId'];
     $followCode = $_POST['FollowCode'];
     $payment = Cshop::app()->getDb()->prepare(QueryBuilder::getInstance()->select()->from('payment')->where('reference = ?'));
     $payment->execute(array($requestId));
     $amount = round($payment['amout']);
     if ($payment['status'] == Application::STATUS_PENDING) {
         if ($result == 0) {
             if ($_POST[Amount] != $payment['amout']) {
                 $message = 'در اطلاعات پرداختي مغايرت وجود دارد';
             } else {
                 $backResult = file("http://www.sharjiran.net/asan_pardakht/CheckPay2.php?FollowCode={$followCode}&RequestId={$requestId}");
                 if ($backResult[0] == 0 && (int) $backResult[1] == (int) $payment['amout'] && $backResult[2] == trim($this->AccountNumber)) {
                     return $payment;
                 } else {
                     $message = 'تراكنش موفقيت آميز نبود';
                 }
             }
         } else {
             if ($result == -1) {
                 $message = 'در اتصال به درگاه بانك مشكلي پيش آمده يا اينكه اطلاعات پرداختي شما نامعتبر بوده است. ';
             }
         }
     } else {
         $message = 'سفارش قبلا پرداخت شده است.';
     }
     throw new Exception($message);
 }
Example #4
0
 public function callbackGateway()
 {
     $au = $_GET['au'];
     $ref_id = $_GET['order_id'];
     if (strlen($au) > 4) {
         $payment = Cshop::app()->getDb()->prepare(QueryBuilder::getInstance()->select()->from('payment')->where('reference = ?'));
         $payment->execute(array($au));
         $payment = $payment->fetch();
         $merchantID = $this->merchant;
         $amount = round($payment['amount'] / 10);
         $client = new nusoap_client('http://jahanpay.com/webservice?wsdl', 'wsdl');
         $res = $client->call("verification", array($merchantID, $amount, $au));
         if ($payment['status'] == Application::STATUS_PENDING) {
             if (!empty($res) and $res == 1) {
                 return $payment;
             } else {
                 $message = 'پرداخت توسط جهان پی انجام نشده است .';
             }
         } else {
             $message = 'سفارش قبلا پرداخت شده است.';
         }
     } else {
         $message = 'شماره یکتا اشتباه است.';
     }
     throw new Exception($message);
 }
Example #5
0
 public function callbackGateway()
 {
     if ($_POST['status'] != '1') {
         $message = 'پرداخت با موفقيت انجام نشده است.';
         throw new Exception($message);
     }
     $refID = $_POST['refnum'];
     $resCode = $_POST['resnum'];
     $id = $this->merchantID;
     $payment = Cshop::app()->getDb()->prepare(QueryBuilder::getInstance()->select()->from('payment')->where('id = ?'));
     $payment->execute(array($resCode));
     $payment = $payment->fetch();
     if ($payment['status'] == Application::STATUS_PENDING) {
         $amount = $payment['amount'];
         $url = 'http://bazpardakht.com/webservice/verify.php';
         $fields = array('id' => urlencode($id), 'resnum' => urlencode($resCode), 'refnum' => urlencode($refID), 'amount' => urlencode($amount / 10));
         //url-ify the data for the POST
         $fields_string = "";
         foreach ($fields as $key => $value) {
             $fields_string .= $key . '=' . $value . '&';
         }
         rtrim($fields_string, '&');
         //open connection
         $ch = curl_init($url);
         //set the url, number of POST vars, POST data
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_POST, count($fields));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         //execute post
         $result = curl_exec($ch);
         curl_close($ch);
         $result = intval($result);
         $pay = false;
         if ($result <= 0) {
             $pay = false;
         } elseif ($result == '1') {
             $pay = true;
         }
         ///////////////////
         if ($pay) {
             return $payment;
         } else {
             $message = 'خطا در پرداخت';
         }
     } else {
         $message = 'این سفارش قبلا پرداخت شده است.';
     }
     throw new Exception($message);
 }
Example #6
0
 public function callbackGateway()
 {
     $api = $this->pin;
     $url = 'http://payline.ir/payment-test/gateway-result-second';
     $trans_id = $_POST['trans_id'];
     $id_get = $_POST['id_get'];
     $result = $this->get($url, $api, $trans_id, $id_get);
     if ($result == 1) {
         $payment = Cshop::app()->getDb()->prepare(QueryBuilder::getInstance()->select()->from('payment')->where('reference = ?'));
         $payment->execute(array($id_get));
         $payment = $payment->fetch();
         if ($payment) {
             return $payment;
         } else {
             $message = 'اطلاعات پرداخت کامل نیست.';
         }
     } else {
         $message = 'پرداخت موفقيت آميز نبود';
     }
     throw new Exception($message);
 }
Example #7
0
 public function callbackGateway()
 {
     $Authority = $_GET['Authority'];
     $ref_id = $_GET['refID'];
     if ($_GET['Status'] == 'OK') {
         $payment = Cshop::app()->getDb()->prepare(QueryBuilder::getInstance()->select()->from('payment')->where('reference = ?'));
         $payment->execute(array($Authority));
         $amount = round($payment['amout'] / 10);
         $client = new nusoap_client('https://de.zarinpal.com/pg/services/WebGate/wsdl', 'wsdl');
         $res = $client->call("PaymentVerification", array(array('MerchantID' => $this->merchant, 'Authority' => $Authority, 'Amount' => $amount)));
         if ($payment[payment_status] == Application::STATUS_PENDING) {
             if ($res['Status'] == 100) {
                 return $payment;
             } else {
                 $message = 'پرداخت توسط زرین‌پال تایید نشد‌.' . $res['Status'];
             }
         } else {
             $message = 'سفارش قبلا پرداخت شده است.';
         }
     } else {
         $message = 'شماره یکتا اشتباه است.';
     }
     throw new Exception($message);
 }
Example #8
0
 public function callbackGateway()
 {
     $au = $_SESSION['siba_au'];
     $order_id = $_SESSION['invoice_id'];
     $pin = $this->merchantID;
     $payment = Cshop::app()->getDb()->prepare(QueryBuilder::getInstance()->select()->from('payment')->where('reference = ?'));
     $payment->execute(array($au));
     $payment = $payment->fetch();
     $amount = round($payment['amount'] / 10);
     $bank_return = $_POST + $_GET;
     $res = $this->verify($pin, $amount, $au, $order_id, $bank_return);
     if ($payment['status'] == Application::STATUS_PENDING) {
         if (empty($res)) {
             $message = 'خطا در اتصال به سرور !';
         } elseif ($res['result'] == 1) {
             return $payment;
         } else {
             $message = 'پرداخت  انجام نشده است . <br /> شرح خطا : ' . urldecode($res['msg']);
         }
     } else {
         $message = 'سفارش قبلا پرداخت شده است.';
     }
     throw new Exception($message);
 }
Example #9
0
    /**
     * 
     * @param Controller $controller
     */
    public function actionEditVoucher($controller)
    {
        $message = $controller->getUser()->message();
        if (!isset($_GET['vid'])) {
            Cshop::app()->redirect(self::getActionLink('voucher', $this->id));
        }
        $vouchers = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->select()->from('voucher')->where('id = ?'));
        $vouchers->execute(array($_GET['vid']));
        $vouchers = $vouchers->fetch();
        if (!$vouchers) {
            Cshop::app()->redirect(self::getActionLink('voucher', $this->id));
        }
        CShop::app()->getEventHandler()->attach(Application::EVENT_MENU, function (&$menu) {
            $menu['کد تخفیف']['ویرایش کد تخفیف'] = $_SERVER['REQUEST_URI'];
        });
        if (isset($_POST['save'])) {
            $voucher = $_POST['voucher'];
            //validate
            try {
                if (empty($voucher['code'])) {
                    throw new Exception('لطفا یک کد انتخاب کنید');
                }
                if ($voucher['time'] != -1) {
                    $time = time() + 24 * 60 * 60 * $voucher['time'];
                } else {
                    $time = $voucher['time'];
                }
                $sql = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->update('voucher')->set('code=?,time=?,maxuse=?,value=?,productid=?')->where('id=?'));
                $sql->execute(array($voucher['code'], $time, $voucher['maxuse'], $voucher['value'], $voucher['productid'], $_GET['vid']));
                $message['content'] = 'تغییرات با موفقیت ذخیره شد';
                $message['type'] = 'success';
                $controller->getUser()->message($message);
                CShop::app()->redirect($_SERVER['REQUEST_URI']);
            } catch (Exception $e) {
                $message['content'] = $e->getMessage();
            }
        } else {
            $voucher = $vouchers;
            if ($voucher['time'] != -1) {
                $voucher['time'] = round(($voucher['time'] - time()) / (60 * 60 * 24), 2);
                $voucher['time'] = $voucher['time'] > 0 ? $voucher['time'] : 0;
            }
        }
        $content = '<div class="title">ویرایش کد تخفیف</div>
			<div class="content">
			<form action="" method="post">
				<div class="formrow">
					<div class="label"><label for="code">کد</label></div>
					<div class="input"><input type="text" name="voucher[code]" id="code" value="' . $voucher['code'] . '"></div>
				</div>
				<div class="formrow">
					<div class="label"><label for="time">تعداد روز استفاده ( -1 برای بینهایت )</label></div>
					<div class="input"><input type="text" name="voucher[time]" id="time" value="' . $voucher['time'] . '"></div>
				</div>
				<div class="formrow">
					<div class="label"><label for="maxuse">تعداد استفاده( -1 برای بینهایت )</label></div>
					<div class="input"><input type="text" name="voucher[maxuse]" id="maxuse" value="' . $voucher['maxuse'] . '"></div>
				</div>
				<div class="formrow">
					<div class="label"><label for="value">ارزش ( بدون % )</label></div>
					<div class="input"><input type="text" name="voucher[value]" id="value" value="' . $voucher['value'] . '"></div>
				</div>
				<div class="formrow wide">
					<div class="label"><label for="productid">محصول (-1 برای همه)</label></div>
					<div class="input"><input type="text" name="voucher[productid]" id="productid" value="' . $voucher['productid'] . '"></div>
				</div>
				<div class="formrow">
					<input type="submit" value="ذخیره" name="save">
				</div>
			</form>
			</div>';
        $controller->renderWithContent($content, array('message' => $message));
    }
Example #10
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include 'config.php');
require 'core/CShop.php';
Cshop::create($config)->run('payment');
Example #11
0
 public function init()
 {
     $this->_templatepath = Cshop::$templatepath;
     $this->db = Cshop::app()->getDb();
     $this->user = new User();
 }
Example #12
0
 public function actionViewPayment()
 {
     $message = $this->user->message();
     if (!isset($_GET['id'])) {
         Cshop::app()->redirect('payment.php');
     }
     $sql = $this->db->prepare(QueryBuilder::getInstance()->select()->from('payment')->where('payment.id=?'));
     $sql->execute(array($_GET['id']));
     $payment = $sql->fetch();
     if (!$payment) {
         Cshop::app()->redirect('payment.php');
     }
     $sql = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->select('input.*,value')->from('payment_meta')->leftJoin('input')->on('inputid = input.id')->where('paymentid = ?'));
     $sql->execute(array($payment['id']));
     $payment['input'] = array();
     while ($row = $sql->fetch()) {
         $row['data'] = unserialize($row['data']);
         $payment['input'][$row['id']] = $row;
     }
     $sql = $this->db->prepare(QueryBuilder::getInstance()->select('item.*,value.fieldid,value,field.name AS fieldname,field.type,product.name,product.description')->from('item')->leftJoin('product')->on('product.id = item.productid')->leftJoin('value')->on('item.id = itemid')->leftJoin('field')->on('fieldid = field.id')->where('paymentid = ?'));
     $sql->execute(array($_GET['id']));
     $items = array();
     while ($item = $sql->fetch()) {
         $items[$item['id']][] = $item;
     }
     CShop::app()->getEventHandler()->attach(Application::EVENT_MENU, function (&$menu) {
         $menu['خرید ها']['مشاهده خرید'] = CShop::$baseurl . '/admin/' . 'viewpayment.php?id=' . $_GET['id'];
     });
     $this->render('admin/paymentview', array('message' => $message, 'payment' => $payment, 'items' => $items));
 }
Example #13
0
    /**
     * 
     * @param Controller $controller
     */
    public function actionEditPage($controller)
    {
        $message = $controller->getUser()->message();
        if (!isset($_GET['pid'])) {
            Cshop::app()->redirect(self::getActionLink('page', $this->id));
        }
        $pages = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->select()->from('page')->where('id = ?'));
        $pages->execute(array($_GET['pid']));
        $pages = $pages->fetch();
        if (!$pages) {
            Cshop::app()->redirect(self::getActionLink('page', $this->id));
        }
        CShop::app()->getEventHandler()->attach(Application::EVENT_MENU, function (&$menu) {
            $menu['مدیریت صفحه ها']['ویرایش صفحه'] = $_SERVER['REQUEST_URI'];
        });
        if (isset($_POST['save'])) {
            $page = $_POST['page'];
            //validate
            try {
                if (empty($page['name'])) {
                    throw new Exception('لطفا یک عنوان مناسب انتخاب کنید');
                }
                $sql = CShop::app()->getDb()->prepare(QueryBuilder::getInstance()->update('page')->set('name=?,type=?,content=?')->where('id=?'));
                $sql->execute(array($page['name'], $page['type'], $page['content'], $pages['id']));
                $message['content'] = 'تغییرات با موفقیت ذخیره شد';
                $message['type'] = 'success';
                $controller->getUser()->message($message);
                CShop::app()->redirect($_SERVER['REQUEST_URI']);
            } catch (Exception $e) {
                $message['content'] = $e->getMessage();
            }
        } else {
            $page = $pages;
        }
        $content = '<div class="title">ویراش صفحه</div> مقادیر نوع می تواند به صورت زیر باشد <br> 0:مقدار محتوی به صورت لینک خواهد شد <br> 1:مقدار محتوی با قالب فروشگاه نمایش داده خواهد شد <br> 2:مقدار محتوی بدون قالب فروشگاه نمایش داده خواهد شد
			<div class="content">
			<form action="" method="post">
				<div class="formrow">
					<div class="label"><label for="name">نام</label></div>
					<div class="input"><input type="text" name="page[name]" id="name" value="' . $page['name'] . '"></div>
				</div>
				<div class="formrow">
					<div class="label"><label for="name">نوع</label></div>
					<div class="input"><input type="text" name="page[type]" id="name" value="' . $page['type'] . '"></div>
				</div>
				<div class="formrow wide">
					<div class="label"><label for="content">محتوی</label></div>
					<div class="input"><textarea name="page[content]" id="content">' . $page['content'] . '</textarea></div>
				</div>
				<div class="formrow">
					<input type="submit" value="ذخیره" name="save">
				</div>
			</form>
			</div>';
        $controller->renderWithContent($content, array('message' => $message));
    }
Example #14
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include '../config.php');
require '../core/CShop.php';
Cshop::create($config)->run(array('admin', 'input'));
Example #15
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include '../config.php');
require '../core/CShop.php';
Cshop::create($config)->run(array('admin', 'gateway'));
Example #16
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include '../config.php');
require '../core/CShop.php';
Cshop::create($config)->run(array('admin', 'statistic'));
Example #17
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include 'config.php');
if (empty($config)) {
    header("location: install/");
    exit;
}
require 'core/CShop.php';
Cshop::create($config)->run('index');
Example #18
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include '../config.php');
require '../core/CShop.php';
Cshop::create($config)->run(array('admin', 'edititem'));
Example #19
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include '../config.php');
require '../core/CShop.php';
Cshop::create($config)->run(array('admin', 'plugin'));
Example #20
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include '../config.php');
require '../core/CShop.php';
Cshop::create($config)->run(array('admin', 'category'));
Example #21
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include '../config.php');
require '../core/CShop.php';
Cshop::create($config)->run(array('admin', 'setting'));
Example #22
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include '../config.php');
require '../core/CShop.php';
Cshop::create($config)->run(array('admin', 'product'));
Example #23
0
<?php

/**
 * @author Ali Akbar Azizi <*****@*****.**>
 * @link http://cshop.irprog.com
 * @copyright 2014 CShop
 * @license http://cshop.irprog.com/licence.txt
 */
$config = (include '../config.php');
require '../core/CShop.php';
Cshop::create($config)->run(array('admin', 'payment'));
Example #24
0
 public function actionIndex()
 {
     $message['content'] = '';
     $save = false;
     if (isset($_POST['submit'])) {
         try {
             $inputs = array();
             foreach (new Model($this->db->query(QueryBuilder::getInstance()->select()->from('input'))) as $key => $value) {
                 $value['data'] = unserialize($value['data']);
                 $messages = Input::validate($value, $_POST['input'][$key]);
                 if ($messages !== true) {
                     throw new Exception(implode('<br>', $messages));
                 }
                 $inputs[$key] = $value;
                 $inputs[$key]['value'] = $_POST['input'][$key];
             }
             if (!is_array($_POST['product'])) {
                 throw new Exception("لطفا یک محصول انتخاب کنید");
             }
             if (empty($_POST['product'])) {
                 throw new Exception("لطفا یک محصول انتخاب کنید");
             }
             $product = array_keys($_POST['product']);
             $products = array();
             $sql = $this->db->prepare(QueryBuilder::getInstance()->select()->from('product')->where('product.id IN (' . implode(',', array_fill(0, count($product), '?')) . ')'));
             $sql->execute($product);
             while ($row = $sql->fetch()) {
                 $products[$row['id']] = $row;
             }
             $items = $this->db->prepare(QueryBuilder::getInstance()->select('item.*,price')->from('item')->leftJoin('product')->on('product.id = productid')->where('productid IN (' . implode(',', array_fill(0, count($product), '?')) . ')')->andWith('reservetime < ' . time())->andWith('status =' . Application::STATUS_PENDING));
             $items->execute($product);
             $itemids = array();
             while ($item = $items->fetch()) {
                 if ($item['id']) {
                     $itemids[$item['productid']][] = $item;
                 }
             }
             $buyids = array();
             $additems = array();
             $price = 0;
             foreach ($products as $key => $p) {
                 $value = $_POST['product'][$key];
                 if (!$value) {
                     $value = 1;
                 }
                 if ($p['skipitem'] == 1) {
                     $price = $p['price'] * $value + $price;
                     $additems[$key] = $value;
                     continue;
                 }
                 if ($value > count($itemids[$key])) {
                     throw new Exception("محصول انتخاب شده موجود نیست");
                 } else {
                     for ($i = 0; $i < $value; $i++) {
                         $item = array_shift($itemids[$key]);
                         $price = $item['price'] + $price;
                         $buyids[] = $item['id'];
                     }
                 }
             }
             $gateway = $this->db->prepare(QueryBuilder::getInstance()->select()->from('gateway')->leftJoin('option')->on('`class` = category')->where('gateway.id = ?'));
             $gateway->execute(array($_POST['gatewayid']));
             $gateway = $gateway->fetchAll();
             if (!$gateway) {
                 throw new Exception("درگاه وارد شده معتبر نیست");
             }
             $sql = $this->db->prepare(QueryBuilder::getInstance()->insert('payment')->into('`requesttime`, `status`, `clientip`, `gatewayid`, `amount`', true));
             $param = array('requesttime' => time(), 'status' => Application::STATUS_PENDING, 'clientip' => $_SERVER['REMOTE_ADDR'], 'gatewayid' => $_POST['gatewayid'], 'amount' => $price);
             $sql->execute($param);
             $param['id'] = $this->db->lastInsertId();
             foreach ($inputs as $key => $value) {
                 $sql = $this->db->prepare(QueryBuilder::getInstance()->insert('payment_meta')->into(array('paymentid', 'inputid', 'value'), true, false));
                 $sql->execute(array($param['id'], $key, $value['value']));
             }
             if (!empty($buyids)) {
                 $this->db->exec(QueryBuilder::getInstance()->update('item')->set('paymentid=' . $param['id'] . ',reservetime=' . (time() + CShop::app()->systemConfig()->reservetime * 60 * 60))->where('id IN (' . implode(',', $buyids) . ')'));
             }
             $additemids = array();
             if (!empty($additems)) {
                 foreach ($additems as $key => $value) {
                     for ($i = 0; $i < $value; $i++) {
                         $sql = $this->db->prepare(QueryBuilder::getInstance()->insert('item')->into(array('productid', 'status', 'createtime', 'paymentid', 'reservetime'), true, false));
                         $sql->execute(array($key, Application::STATUS_SYSTEM_ADDED, time(), $param['id'], time() + CShop::app()->systemConfig()->reservetime * 60 * 60));
                         $additemids[] = $this->db->lastInsertId();
                     }
                 }
             }
             $save = true;
             $param['input'] = $inputs;
             CShop::app()->raise(Application::EVENT_BEFORE_PAYMENT, array(&$param, &$products));
             CShop::import(Cshop::$gatewaypath . DIRECTORY_SEPARATOR . $gateway[0]['class'] . '.php');
             /* @var $plugin GatewayBase */
             $plugin = new $gateway[0]['class']($gateway[0]['id'], $gateway);
             $message = $plugin->sendToGateway($param, Cshop::siteURL() . Cshop::$baseurl . '/payment.php?gateway=' . $_POST['gatewayid']);
         } catch (Exception $e) {
             $message['content'] = $e->getMessage();
         }
         if (isset($message) && $save) {
             if (!empty($buyids)) {
                 $this->db->exec(QueryBuilder::getInstance()->update('item')->set('reservetime=0')->where('id IN (' . implode(',', $buyids) . ')'));
             }
             if (!empty($additemids)) {
                 $this->db->exec(QueryBuilder::getInstance()->delete('item')->where('id IN (' . implode(',', $additemids) . ')'));
             }
         }
     }
     $product = new Model($this->db->query(QueryBuilder::getInstance()->select()->from('product')->order('`order`')));
     $category = new Model($this->db->query(QueryBuilder::getInstance()->select()->from('category')->order('`order`')));
     $gateway = new Model($this->db->query(QueryBuilder::getInstance()->select()->from('plugin')->where('type=' . Application::PLUGIN_TYPE_GATEWAY)->order('`order`')));
     $input = new Model($this->db->query(QueryBuilder::getInstance()->select()->from('input')->order('`order`')));
     $this->render('site/index', array('input' => $input, 'product' => $product, 'category' => $category, 'gateway' => $gateway, 'message' => $message));
 }