Buyvirtual.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Buyvirtual extends BaseMember
  18. {
  19. public function initialize()
  20. {
  21. parent::initialize(); // TODO: Change the autogenerated stub
  22. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/buy.lang.php');
  23. //验证该会员是否禁止购买
  24. if(!session('is_buy')){
  25. $this->error(lang('cart_buy_noallow'));
  26. }
  27. if(config('ds_config.member_auth') && $this->member_info['member_auth_state']!=3){
  28. $this->error(lang('cart_buy_noauth'),(string)url('MemberAuth/index'));
  29. }
  30. }
  31. /**
  32. * 虚拟商品购买第一步
  33. */
  34. public function buy_step1() {
  35. $logic_buyvirtual = model('buyvirtual', 'logic');
  36. $result = $logic_buyvirtual->getBuyStep1Data(input('goods_id'), input('quantity'), session('member_id'));
  37. if (!$result['code']) {
  38. $this->error($result['msg']);
  39. }
  40. View::assign('goods_info', $result['data']['goods_info']);
  41. View::assign('store_info', $result['data']['store_info']);
  42. return View::fetch($this->template_dir . 'buy_virtual_step1');
  43. }
  44. /**
  45. * 虚拟商品购买第二步
  46. */
  47. public function buy_step2() {
  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. $logic_buyvirtual = model('buyvirtual','logic');
  69. $post = input('post.');
  70. $post['order_from'] = 1;
  71. $result = $logic_buyvirtual->buyStep3($post,session('member_id'));
  72. if (!$result['code']) {
  73. $this->error($result['msg']);
  74. }
  75. //转向到商城支付页面
  76. $this->redirect('buyvirtual/pay',['order_id'=>$result['data']['order_id']]);
  77. }
  78. /**
  79. * 下单时支付页面
  80. */
  81. public function pay() {
  82. $order_id = intval(input('param.order_id'));
  83. if ($order_id <= 0){
  84. $this->error(lang('cart_order_pay_not_exists'),'membervrorder/index');
  85. }
  86. $vrorder_model = model('vrorder');
  87. //取订单信息
  88. $condition = array();
  89. $condition[] = array('order_id','=',$order_id);
  90. $order_info = $vrorder_model->getVrorderInfo($condition,'*');
  91. if (empty($order_info) || !in_array($order_info['order_state'],array(ORDER_STATE_NEW,ORDER_STATE_PAY))) {
  92. $this->error(lang('no_order_paid_was_found'),'memberorder/index');
  93. }
  94. //重新计算在线支付金额
  95. $pay_amount_online = 0;
  96. //订单总支付金额
  97. $pay_amount = 0;
  98. $payed_amount = floatval($order_info['rcb_amount']) + floatval($order_info['pd_amount']);
  99. //计算所需要支付金额
  100. $diff_pay_amount = ds_price_format(floatval($order_info['order_amount'])-$payed_amount);
  101. //显示支付方式与支付结果
  102. if ($payed_amount > 0) {
  103. $payed_tips = '';
  104. if (floatval($order_info['rcb_amount']) > 0) {
  105. $payed_tips = lang('card_has_been_paid').':¥'.$order_info['rcb_amount'];
  106. }
  107. if (floatval($order_info['pd_amount']) > 0) {
  108. $payed_tips .= lang('prepaid_deposits_beenpaid').':¥'.$order_info['pd_amount'];
  109. }
  110. $order_info['goods_price'] .= " ( {$payed_tips} )";
  111. }
  112. View::assign('order_info',$order_info);
  113. //如果所需支付金额为0,转到支付成功页
  114. if ($diff_pay_amount == 0) {
  115. $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'])]);
  116. }
  117. View::assign('diff_pay_amount',ds_price_format($diff_pay_amount));
  118. //显示支付接口列表
  119. $payment_model = model('payment');
  120. $condition = array();
  121. $condition[] = array('payment_code','not in',array('offline', 'predeposit'));
  122. $condition[] = array('payment_platform','=','pc');
  123. $payment_list = $payment_model->getPaymentOpenList($condition);
  124. if (empty($payment_list)) {
  125. $this->error(lang('appropriate_payment_method'),'membervrorder/index');
  126. }
  127. View::assign('payment_list',$payment_list);
  128. //显示预存款、支付密码、充值卡
  129. $member_model=model('member');
  130. $buyer_info=$member_model->getMemberInfoByID($this->member_info['member_id']);
  131. View::assign('available_pd_amount', ($buyer_info['available_predeposit']>0)?$buyer_info['available_predeposit']:'');
  132. View::assign('member_paypwd', $buyer_info['member_paypwd']);
  133. View::assign('available_rcb_amount', ($buyer_info['available_rc_balance']>0)?$buyer_info['available_rc_balance']:'');
  134. return View::fetch($this->template_dir.'buy_virtual_step3');
  135. }
  136. /**
  137. * 支付成功页面
  138. */
  139. public function pay_ok() {
  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. }