Buyvirtual.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Buyvirtual extends BaseMember
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize(); // TODO: Change the autogenerated stub
  21. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/buy.lang.php');
  22. //验证该会员是否禁止购买
  23. if(!session('is_buy')){
  24. $this->error(lang('cart_buy_noallow'));
  25. }
  26. if(config('ds_config.member_auth') && $this->member_info['member_auth_state']!=3){
  27. $this->error(lang('cart_buy_noauth'),(string)url('MemberAuth/index'));
  28. }
  29. }
  30. /**
  31. * 虚拟商品购买第一步
  32. */
  33. public function buy_step1() {
  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. $logic_buyvirtual = model('buyvirtual','logic');
  48. $result = $logic_buyvirtual->getBuyStep2Data(input('post.goods_id'), input('post.quantity'), session('member_id'));
  49. if (!$result['code']) {
  50. $this->error($result['msg']);
  51. }
  52. //处理会员信息
  53. $member_info = array_merge($this->member_info,$result['data']['member_info']);
  54. View::assign('goods_info',$result['data']['goods_info']);
  55. View::assign('store_info',$result['data']['store_info']);
  56. View::assign('member_info',$member_info);
  57. //返回店铺可用的代金券
  58. View::assign('store_voucher_list', $result['data']['store_voucher_list']);
  59. //返回平台可用的代金券
  60. View::assign('mall_voucher_list', $result['data']['mall_voucher_list']);
  61. return View::fetch($this->template_dir.'buy_virtual_step2');
  62. }
  63. /**
  64. * 虚拟商品购买第三步
  65. */
  66. public function buy_step3() {
  67. $logic_buyvirtual = model('buyvirtual','logic');
  68. $post = input('post.');
  69. $post['order_from'] = 1;
  70. $result = $logic_buyvirtual->buyStep3($post,session('member_id'));
  71. if (!$result['code']) {
  72. $this->error($result['msg']);
  73. }
  74. //转向到商城支付页面
  75. $this->redirect('buyvirtual/pay',['order_id'=>$result['data']['order_id']]);
  76. }
  77. /**
  78. * 下单时支付页面
  79. */
  80. public function pay() {
  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. $order_sn = input('param.order_sn');
  140. if (!preg_match('/^\d{20}$/',$order_sn)){
  141. $this->error(lang('cart_order_pay_not_exists'),'membervrorder/index');
  142. }
  143. return View::fetch($this->template_dir.'buy_virtual_step4');
  144. }
  145. }