Exemple #1
0
 /**
  * @brief 【重要】进行支付支付方法
  */
 public function doPay()
 {
     //获得相关参数
     $order_id = IFilter::act(IReq::get('order_id'), 'int');
     $recharge = IReq::get('recharge');
     $payment_id = IFilter::act(IReq::get('payment_id'), 'int');
     if ($order_id) {
         //获取订单信息
         $orderDB = new IModel('order');
         $orderRow = $orderDB->getObj('id = ' . $order_id);
         if (empty($orderRow)) {
             IError::show(403, '要支付的订单信息不存在');
         }
         $payment_id = $orderRow['pay_type'];
     }
     //获取支付方式类库
     $paymentInstance = Payment::createPaymentInstance($payment_id);
     //在线充值
     if ($recharge !== null) {
         $recharge = IFilter::act($recharge, 'float');
         $paymentRow = Payment::getPaymentById($payment_id);
         //account:充值金额; paymentName:支付方式名字
         $reData = array('account' => $recharge, 'paymentName' => $paymentRow['name']);
         $sendData = $paymentInstance->getSendData(Payment::getPaymentInfo($payment_id, 'recharge', $reData));
     } else {
         if ($order_id != 0) {
             $sendData = $paymentInstance->getSendData(Payment::getPaymentInfo($payment_id, 'order', $order_id));
         } else {
             IError::show(403, '发生支付错误');
         }
     }
     $this->paymentInstance = $paymentInstance;
     $this->sendData = $sendData;
     $this->redirect('hidden_form', false);
 }
Exemple #2
0
 /**
  * @brief 支付方法
  */
 public static function doPay()
 {
     //获得payment_id 获得相关参数
     $payment_id = intval(IReq::get('id'));
     $order_id = intval(IReq::get('order_id'));
     $recharge = IReq::get('recharge');
     //检查支付方式可用性
     $paymentObj = new Payment();
     $paymentRow = $paymentObj->getPaymentById($payment_id);
     if (empty($paymentRow)) {
         IError::show(403, '支付方式不存在');
     }
     //载入支付接口文件
     $payObj = $paymentObj->loadMethod($paymentRow['file_path']);
     if (isset($payObj->head_charset)) {
         header("Content-Type: text/html;charset=" . $payObj->head_charset);
     }
     $html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n                <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-US\" lang=\"en-US\" dir=\"ltr\">\n                <head>\n</header><body><div>Redirecting...</div>";
     //在线充值
     if ($recharge !== null) {
         $reData = array('account' => $recharge, 'payment_type' => $paymentRow['name']);
         $toSubmit = $payObj->toSubmit($paymentObj->getPaymentInfo($payment_id, 'recharge', $reData));
     } else {
         if ($order_id != 0) {
             $toSubmit = $payObj->toSubmit($paymentObj->getPaymentInfo($payment_id, 'order', $order_id));
         } else {
             IError::show(403, '发生支付错误');
         }
     }
     //兼容站外站内的支付方式
     if (strtolower(substr($payObj->submitUrl, 0, 4)) != 'http') {
         $payObj->submitUrl = IUrl::creatUrl($payObj->submitUrl);
     }
     $html .= "<form id=\"payment\" action=\"" . $payObj->submitUrl . "\" method=\"" . $payObj->method . "\">";
     $buffer = "";
     foreach ($toSubmit as $k => $v) {
         if ($k != "ikey") {
             $html .= "<input  type=\"hidden\" name=\"" . urldecode($k) . "\" value=\"" . htmlspecialchars($v) . "\" />";
             $buffer .= $k . "=" . urlencode($v) . "&";
         }
     }
     $html .= "\n</form>\n<script language=\"javascript\">\ndocument.getElementById('payment').submit();\n</script>\n</html>";
     echo $html;
     exit;
 }
Exemple #3
0
 public function doPay()
 {
     // 获得payment_id 获得相关参数
     $payment_id = Filter::int(Req::args('payment_id'));
     $order_id = Filter::int(Req::args('order_id'));
     $recharge = Req::args('recharge');
     $extendDatas = Req::args();
     if ($payment_id) {
         $payment = new Payment($payment_id);
         $paymentPlugin = $payment->getPaymentPlugin();
         //充值处理
         if ($recharge != null) {
             $recharge = Filter::float($recharge);
             $paymentInfo = $payment->getPayment();
             $data = array('account' => $recharge, 'paymentName' => $paymentInfo['name']);
             $packData = $payment->getPaymentInfo('recharge', $data);
             $packData = array_merge($extendDatas, $packData);
             $sendData = $paymentPlugin->packData($packData);
         } else {
             if ($order_id != null) {
                 $order = Order::getOrder($order_id);
                 $model = new Model("order_goods");
                 if ($order) {
                     //获取订单可能延时时长,0不限制
                     $config = Config::getInstance();
                     $config_other = $config->get('other');
                     // todo 修改方法  order type 去掉  详情表中记录 order type
                     switch ($order['type']) {
                         case '1':
                             $order_delay = isset($config_other['other_order_delay_group']) ? intval($config_other['other_order_delay_group']) : 120;
                             break;
                         case '2':
                             $order_delay = isset($config_other['other_order_delay_flash']) ? intval($config_other['other_order_delay_flash']) : 120;
                             break;
                         case '3':
                             $order_delay = isset($config_other['other_order_delay_bund']) ? intval($config_other['other_order_delay_bund']) : 0;
                             break;
                         default:
                             $order_delay = isset($config_other['other_order_delay']) ? intval($config_other['other_order_delay']) : 0;
                             break;
                     }
                     $time = strtotime("-" . $order_delay . " Minute");
                     $create_time = strtotime($order['create_time']);
                     if ($create_time >= $time || $order_delay == 0) {
                         //取得所有订单商品
                         //$order_goods = $model->table('order_goods')->fields("product_id,goods_nums, prom_type")->where('order_id='.$order_id)->findAll();
                         $order_goods_inst = new OrderGoods();
                         $order_goods = $order_goods_inst->getOrderGoods($order_id);
                         $product_ids = array();
                         $order_products = array();
                         // todo 这里判断 prom_type 类型
                         foreach ($order_goods as $value) {
                             // 套餐不在这里检查商品库存  考虑在别的地方检查
                             // 如果订单详细表中行是由于捆绑促销
                             if ($value['prom_type'] == 'bundling') {
                                 continue;
                             } else {
                                 $product_ids[] = $value['product_id'];
                                 $order_products[$value['product_id']] = $value['goods_nums'];
                             }
                         }
                         $packData = $payment->getPaymentInfo('order', $order_id);
                         $packData = array_merge($extendDatas, $packData);
                         $sendData = $paymentPlugin->packData($packData);
                         /* 这里不需要验证库存量  提交订单时已经验证
                                                 if (!empty($product_ids)) {
                         
                                                     $product_ids = implode(',', $product_ids);
                                                     $products = $model->table('products')->fields("id,store_nums")->where("id in ($product_ids)")->findAll();
                                                     $products_list = array();
                                                     foreach ($products as $value) {
                                                         $products_list[$value['id']] = $value['store_nums'];
                                                     }
                                                     $flag = true;
                                                     foreach ($order_goods as $value) {
                                                         if ($order_products[$value['product_id']] > $products_list[$value['product_id']]) {
                                                             $flag = false;
                                                             break;
                                                         }
                                                     }
                                                     //检测库存是否还能满足订单
                                                     if ($flag) {
                                                         //团购订单
                                                         if ($order['type'] == 1 || $order['type'] == 2) {
                                                             if ($order['type'] == 1) {
                                                                 $prom_name = '团购';
                                                                 $prom_table = "groupbuy";
                                                             } else {
                                                                 $prom_name = '抢购';
                                                                 $prom_table = "flash_sale";
                                                             }
                                                             $prom = $model->table($prom_table)->where("id=" . $order['prom_id'])->find();
                                                             if ($prom) {
                                                                 if (time() > strtotime($prom['end_time']) || $prom['max_num'] <= $prom["goods_num"]) {
                                                                     $model->table("order")->data(array('status' => 6))->where('id=' . $order_id)->update();
                                                                     $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '支付晚了,' . $prom_name . "活动已结束。"));
                                                                     exit;
                                                                 }
                                                             }
                                                         }
                         
                                                         $packData = $payment->getPaymentInfo('order', $order_id);
                                                         $packData = array_merge($extendDatas, $packData);
                                                         $sendData = $paymentPlugin->packData($packData);
                         
                                                     } else {
                                                         $model->table("order")->data(array('status' => 6))->where('id=' . $order_id)->update();
                                                         $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '支付晚了,库存已不足。'));
                                                         exit;
                         
                                                     }
                                                 }
                                                 */
                     } else {
                         $model->data(array('status' => 6))->where('id=' . $order_id)->update();
                         $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '订单超出了规定时间内付款,已作废.'));
                         exit;
                     }
                 }
             }
         }
         if (!empty($sendData)) {
             $this->assign("paymentPlugin", $paymentPlugin);
             $this->assign("sendData", $sendData);
             $this->redirect('pay_form', false);
         } else {
             $this->redirect("/index/msg", false, array('type' => 'fail', 'msg' => '需要支付的订单已经不存在。'));
         }
     } else {
         echo "fail";
     }
 }