Buyvirtual.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 控制器
  14. */
  15. class Buyvirtual extends BaseMember
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/buy.lang.php');
  21. //验证该会员是否禁止购买
  22. if (!session('is_buy')) {
  23. $this->error(lang('cart_buy_noallow'));
  24. }
  25. if (config('ds_config.member_auth') && $this->member_info['member_auth_state'] != 3) {
  26. $this->error(lang('cart_buy_noauth'), (string)url('MemberAuth/index'));
  27. }
  28. }
  29. /**
  30. * 虚拟商品购买第一步
  31. */
  32. public function buy_step1()
  33. {
  34. $logic_buyvirtual = model('buyvirtual', 'logic');
  35. $result = $logic_buyvirtual->getBuyStep1Data(input('goods_id'), input('quantity'), session('member_id'));
  36. if (!$result['code']) {
  37. $this->error($result['msg']);
  38. }
  39. View::assign('goods_info', $result['data']['goods_info']);
  40. View::assign('store_info', $result['data']['store_info']);
  41. return View::fetch($this->template_dir . 'buy_virtual_step1');
  42. }
  43. /**
  44. * 虚拟商品购买第二步
  45. */
  46. public function buy_step2()
  47. {
  48. $logic_buyvirtual = model('buyvirtual', 'logic');
  49. $result = $logic_buyvirtual->getBuyStep2Data(input('post.goods_id'), input('post.quantity'), session('member_id'));
  50. if (!$result['code']) {
  51. $this->error($result['msg']);
  52. }
  53. //处理会员信息
  54. $member_info = array_merge($this->member_info, $result['data']['member_info']);
  55. View::assign('goods_info', $result['data']['goods_info']);
  56. View::assign('store_info', $result['data']['store_info']);
  57. View::assign('member_info', $member_info);
  58. //返回店铺可用的代金券
  59. View::assign('store_voucher_list', $result['data']['store_voucher_list']);
  60. //返回平台可用的代金券
  61. View::assign('mall_voucher_list', $result['data']['mall_voucher_list']);
  62. return View::fetch($this->template_dir . 'buy_virtual_step2');
  63. }
  64. /**
  65. * 虚拟商品购买第三步
  66. */
  67. public function buy_step3()
  68. {
  69. $logic_buyvirtual = model('buyvirtual', 'logic');
  70. $post = input('post.');
  71. $post['order_from'] = 1;
  72. $result = $logic_buyvirtual->buyStep3($post, session('member_id'));
  73. if (!$result['code']) {
  74. $this->error($result['msg']);
  75. }
  76. //转向到商城支付页面
  77. $this->redirect('buyvirtual/pay', ['order_id' => $result['data']['order_id']]);
  78. }
  79. /**
  80. * 下单时支付页面
  81. */
  82. public function pay()
  83. {
  84. $order_id = intval(input('param.order_id'));
  85. if ($order_id <= 0) {
  86. $this->error(lang('cart_order_pay_not_exists'), 'membervrorder/index');
  87. }
  88. $vrorder_model = model('vrorder');
  89. //取订单信息
  90. $condition = array();
  91. $condition[] = array('order_id', '=', $order_id);
  92. $order_info = $vrorder_model->getVrorderInfo($condition, '*');
  93. if (empty($order_info) || !in_array($order_info['order_state'], array(ORDER_STATE_NEW, ORDER_STATE_PAY))) {
  94. $this->error(lang('no_order_paid_was_found'), 'memberorder/index');
  95. }
  96. //重新计算在线支付金额
  97. $pay_amount_online = 0;
  98. //订单总支付金额
  99. $pay_amount = 0;
  100. $payed_amount = floatval($order_info['rcb_amount']) + floatval($order_info['pd_amount']);
  101. //计算所需要支付金额
  102. $diff_pay_amount = ds_price_format(floatval($order_info['order_amount']) - $payed_amount);
  103. //显示支付方式与支付结果
  104. if ($payed_amount > 0) {
  105. $payed_tips = '';
  106. if (floatval($order_info['rcb_amount']) > 0) {
  107. $payed_tips = lang('card_has_been_paid') . ':¥' . $order_info['rcb_amount'];
  108. }
  109. if (floatval($order_info['pd_amount']) > 0) {
  110. $payed_tips .= lang('prepaid_deposits_beenpaid') . ':¥' . $order_info['pd_amount'];
  111. }
  112. $order_info['goods_price'] .= " ( {$payed_tips} )";
  113. }
  114. View::assign('order_info', $order_info);
  115. //如果所需支付金额为0,转到支付成功页
  116. if ($diff_pay_amount == 0) {
  117. $this->redirect('buyvirtual/pay_ok', ['order_sn' => $order_info['order_sn'], 'order_id' => $order_info['order_id'], 'order_amount' => ds_price_format($order_info['order_amount'])]);
  118. }
  119. View::assign('diff_pay_amount', ds_price_format($diff_pay_amount));
  120. //显示支付接口列表
  121. $payment_model = model('payment');
  122. $condition = array();
  123. $condition[] = array('payment_code', 'not in', array('offline', 'predeposit'));
  124. $condition[] = array('payment_platform', '=', 'pc');
  125. $payment_list = $payment_model->getPaymentOpenList($condition);
  126. if (empty($payment_list)) {
  127. $this->error(lang('appropriate_payment_method'), 'membervrorder/index');
  128. }
  129. View::assign('payment_list', $payment_list);
  130. //显示预存款、支付密码、充值卡
  131. $member_model = model('member');
  132. $buyer_info = $member_model->getMemberInfoByID($this->member_info['member_id']);
  133. View::assign('available_pd_amount', ($buyer_info['available_predeposit'] > 0) ? $buyer_info['available_predeposit'] : '');
  134. View::assign('member_paypwd', $buyer_info['member_paypwd']);
  135. View::assign('available_rcb_amount', ($buyer_info['available_rc_balance'] > 0) ? $buyer_info['available_rc_balance'] : '');
  136. return View::fetch($this->template_dir . 'buy_virtual_step3');
  137. }
  138. /**
  139. * 支付成功页面
  140. */
  141. public function pay_ok()
  142. {
  143. $order_sn = input('param.order_sn');
  144. if (!preg_match('/^\d{20}$/', $order_sn)) {
  145. $this->error(lang('cart_order_pay_not_exists'), 'membervrorder/index');
  146. }
  147. return View::fetch($this->template_dir . 'buy_virtual_step4');
  148. }
  149. }