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