Buyvirtual.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. return View::fetch($this->template_dir.'buy_virtual_step2');
  61. }
  62. /**
  63. * 虚拟商品购买第三步
  64. */
  65. public function buy_step3() {
  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. $order_id = intval(input('param.order_id'));
  81. if ($order_id <= 0){
  82. $this->error(lang('cart_order_pay_not_exists'),'membervrorder/index');
  83. }
  84. $vrorder_model = model('vrorder');
  85. //取订单信息
  86. $condition = array();
  87. $condition[] = array('order_id','=',$order_id);
  88. $order_info = $vrorder_model->getVrorderInfo($condition,'*');
  89. if (empty($order_info) || !in_array($order_info['order_state'],array(ORDER_STATE_NEW,ORDER_STATE_PAY))) {
  90. $this->error(lang('no_order_paid_was_found'),'memberorder/index');
  91. }
  92. //重新计算在线支付金额
  93. $pay_amount_online = 0;
  94. //订单总支付金额
  95. $pay_amount = 0;
  96. $payed_amount = floatval($order_info['rcb_amount']) + floatval($order_info['pd_amount']);
  97. //计算所需要支付金额
  98. $diff_pay_amount = ds_price_format(floatval($order_info['order_amount'])-$payed_amount);
  99. //显示支付方式与支付结果
  100. if ($payed_amount > 0) {
  101. $payed_tips = '';
  102. if (floatval($order_info['rcb_amount']) > 0) {
  103. $payed_tips = lang('card_has_been_paid').':¥'.$order_info['rcb_amount'];
  104. }
  105. if (floatval($order_info['pd_amount']) > 0) {
  106. $payed_tips .= lang('prepaid_deposits_beenpaid').':¥'.$order_info['pd_amount'];
  107. }
  108. $order_info['goods_price'] .= " ( {$payed_tips} )";
  109. }
  110. View::assign('order_info',$order_info);
  111. //如果所需支付金额为0,转到支付成功页
  112. if ($diff_pay_amount == 0) {
  113. $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'])]);
  114. }
  115. View::assign('diff_pay_amount',ds_price_format($diff_pay_amount));
  116. //显示支付接口列表
  117. $payment_model = model('payment');
  118. $condition = array();
  119. $condition[] = array('payment_code','not in',array('offline', 'predeposit'));
  120. $condition[] = array('payment_platform','=','pc');
  121. $payment_list = $payment_model->getPaymentOpenList($condition);
  122. if (empty($payment_list)) {
  123. $this->error(lang('appropriate_payment_method'),'membervrorder/index');
  124. }
  125. View::assign('payment_list',$payment_list);
  126. //显示预存款、支付密码、充值卡
  127. $member_model=model('member');
  128. $buyer_info=$member_model->getMemberInfoByID($this->member_info['member_id']);
  129. View::assign('available_pd_amount', ($buyer_info['available_predeposit']>0)?$buyer_info['available_predeposit']:'');
  130. View::assign('member_paypwd', $buyer_info['member_paypwd']);
  131. View::assign('available_rcb_amount', ($buyer_info['available_rc_balance']>0)?$buyer_info['available_rc_balance']:'');
  132. return View::fetch($this->template_dir.'buy_virtual_step3');
  133. }
  134. /**
  135. * 支付成功页面
  136. */
  137. public function pay_ok() {
  138. $order_sn = input('param.order_sn');
  139. if (!preg_match('/^\d{20}$/',$order_sn)){
  140. $this->error(lang('cart_order_pay_not_exists'),'membervrorder/index');
  141. }
  142. return View::fetch($this->template_dir.'buy_virtual_step4');
  143. }
  144. }