buy_virtual.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * 虚拟商品购买
  4. ***/
  5. defined('InShopNC') or exit('Access Invalid!');
  6. class buy_virtualControl extends BaseBuyControl {
  7. public function __construct() {
  8. parent::__construct();
  9. if (!$_SESSION['member_id']){
  10. redirect('index.php?act=login&ref_url='.urlencode(request_uri()));
  11. }
  12. //验证该会员是否禁止购买
  13. if(!$_SESSION['is_buy']){
  14. showMessage(Language::get('cart_buy_noallow'),'','html','error');
  15. }
  16. Tpl::output('hidden_rtoolbar_cart', 1);
  17. }
  18. /**
  19. * 虚拟商品购买第一步
  20. */
  21. public function buy_step1Op() {
  22. $logic_buy_virtual = Logic('buy_virtual');
  23. $result = $logic_buy_virtual->getBuyStep1Data($_GET['goods_id'], $_GET['quantity'], $_SESSION['member_id']);
  24. if (!$result['state']) {
  25. showMessage($result['msg'], '', 'html', 'error');
  26. }
  27. Tpl::output('goods_info',$result['data']['goods_info']);
  28. Tpl::output('store_info',$result['data']['store_info']);
  29. Tpl::showpage('buy_virtual_step1');
  30. }
  31. /**
  32. * 虚拟商品购买第二步
  33. */
  34. public function buy_step2Op() {
  35. $logic_buy_virtual = Logic('buy_virtual');
  36. $result = $logic_buy_virtual->getBuyStep2Data($_POST['goods_id'], $_POST['quantity'], $_SESSION['member_id']);
  37. if (!$result['state']) {
  38. showMessage($result['msg'], '', 'html', 'error');
  39. }
  40. //处理会员信息
  41. $member_info = array_merge($this->member_info,$result['data']['member_info']);
  42. Tpl::output('goods_info',$result['data']['goods_info']);
  43. Tpl::output('store_info',$result['data']['store_info']);
  44. Tpl::output('member_info',$member_info);
  45. Tpl::showpage('buy_virtual_step2');
  46. }
  47. /**
  48. * 虚拟商品购买第三步
  49. */
  50. public function buy_step3Op() {
  51. $logic_buy_virtual = Logic('buy_virtual');
  52. $_POST['order_from'] = 1;
  53. $result = $logic_buy_virtual->buyStep3($_POST,$_SESSION['member_id']);
  54. if (!$result['state']) {
  55. showMessage($result['msg'], 'index.php', 'html', 'error');
  56. }
  57. //转向到商城支付页面
  58. redirect('index.php?act=buy_virtual&op=pay&order_id='.$result['data']['order_id']);
  59. }
  60. /**
  61. * 下单时支付页面
  62. */
  63. public function payOp() {
  64. $order_id = intval($_GET['order_id']);
  65. if ($order_id <= 0){
  66. showMessage('该订单不存在','index.php?act=member_vr_order','html','error');
  67. }
  68. $model_vr_order = Model('vr_order');
  69. //取订单信息
  70. $condition = array();
  71. $condition['order_id'] = $order_id;
  72. $order_info = $model_vr_order->getOrderInfo($condition,'*',true);
  73. if (empty($order_info) || !in_array($order_info['order_state'],array(ORDER_STATE_NEW,ORDER_STATE_PAY))) {
  74. showMessage('未找到需要支付的订单','index.php?act=member_order','html','error');
  75. }
  76. //重新计算在线支付金额
  77. $pay_amount_online = 0;
  78. //订单总支付金额
  79. $pay_amount = 0;
  80. $payed_amount = floatval($order_info['rcb_amount']) + floatval($order_info['pd_amount']);
  81. //计算所需要支付金额
  82. $diff_pay_amount = ncPriceFormat(floatval($order_info['order_amount'])-$payed_amount);
  83. //显示支付方式与支付结果
  84. if ($payed_amount > 0) {
  85. $payed_tips = '';
  86. if (floatval($order_info['rcb_amount']) > 0) {
  87. $payed_tips = '充值卡已支付:¥'.$order_info['rcb_amount'];
  88. }
  89. if (floatval($order_info['pd_amount']) > 0) {
  90. $payed_tips .= ' 预存款已支付:¥'.$order_info['pd_amount'];
  91. }
  92. $order_info['goods_price'] .= " ( {$payed_tips} )";
  93. }
  94. Tpl::output('order_info',$order_info);
  95. //如果所需支付金额为0,转到支付成功页
  96. if ($diff_pay_amount == 0) {
  97. redirect('index.php?act=buy_virtual&op=pay_ok&order_sn='.$order_info['order_sn'].'&order_id='.$order_info['order_id'].'&order_amount='.ncPriceFormat($order_info['order_amount']));
  98. }
  99. Tpl::output('diff_pay_amount',ncPriceFormat($diff_pay_amount));
  100. //显示支付接口列表
  101. $model_payment = Model('payment');
  102. $condition = array();
  103. $payment_list = $model_payment->getPaymentOpenList($condition);
  104. if (!empty($payment_list)) {
  105. unset($payment_list['predeposit']);
  106. unset($payment_list['offline']);
  107. }
  108. if (empty($payment_list)) {
  109. showMessage('暂未找到合适的支付方式','index.php?act=member_vr_order','html','error');
  110. }
  111. Tpl::output('payment_list',$payment_list);
  112. Tpl::showpage('buy_virtual_step3');
  113. }
  114. /**
  115. * 支付成功页面
  116. */
  117. public function pay_okOp() {
  118. $order_sn = $_GET['order_sn'];
  119. if (!preg_match('/^\d{18}$/',$order_sn)){
  120. showMessage('该订单不存在','index.php?act=member_vr_order','html','error');
  121. }
  122. Tpl::showpage('buy_virtual_step4');
  123. }
  124. }