Buy.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * ============================================================================
  8. *
  9. * ============================================================================
  10. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Buy extends BaseMember {
  18. public function initialize() {
  19. parent::initialize();
  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. public function buy_step1() {
  30. if(empty(input('post.'))){
  31. $this->error(lang('param_error'));
  32. }
  33. //虚拟商品购买分流
  34. $this->_buy_branch(input('post.'));
  35. $ifcart = input('post.ifcart');
  36. $buy_logic = model('buy','logic');
  37. $result = $buy_logic->buyStep1(input('post.cart_id/a'), $ifcart, session('member_id'), session('store_id'));
  38. if ($result['code'] != 'SUCCESS') {
  39. $this->error($result['msg']);
  40. } else {
  41. $result = $result['data'];
  42. }
  43. View::assign('if_presell', $result['if_presell']);
  44. View::assign('presell_deposit_amount', $result['presell_deposit_amount']);
  45. //商品金额计算(分别对每个商品/优惠套装小计、每个店铺小计)
  46. View::assign('store_cart_list', $result['store_cart_list']);
  47. View::assign('store_goods_total', $result['store_goods_total']);
  48. View::assign('store_goods_original_total', $result['store_goods_original_total']);
  49. View::assign('store_goods_discount_total', $result['store_goods_discount_total']);
  50. //取得店铺优惠 - 满即送(赠品列表,店铺满送规则列表)
  51. View::assign('store_premiums_list', $result['store_premiums_list']);
  52. View::assign('store_mansong_rule_list', $result['store_mansong_rule_list']);
  53. //返回门店数据
  54. View::assign('chaingoods_list', $result['chaingoods_list']);
  55. //返回店铺可用的代金券
  56. View::assign('store_voucher_list', $result['store_voucher_list']);
  57. //返回平台可用的代金券
  58. View::assign('mall_voucher_list', $result['mall_voucher_list']);
  59. //返回需要计算运费的店铺ID数组 和 不需要计算运费(满免运费活动的)店铺ID及描述
  60. View::assign('need_calc_sid_list', $result['need_calc_sid_list']);
  61. View::assign('cancel_calc_sid_list', $result['cancel_calc_sid_list']);
  62. //将商品ID、数量、售卖区域、运费序列化,加密,输出到模板,选择地区AJAX计算运费时作为参数使用
  63. View::assign('freight_hash', $result['freight_list']);
  64. //输出用户默认收货地址
  65. View::assign('address_info', $result['address_info']);
  66. //输出有货到付款时,在线支付和货到付款及每种支付下商品数量和详细列表
  67. View::assign('pay_goods_list', $result['pay_goods_list']);
  68. View::assign('ifshow_offpay', $result['ifshow_offpay']);
  69. View::assign('deny_edit_payment', isset($result['deny_edit_payment'])?$result['deny_edit_payment']:0);
  70. //不提供增值税发票时抛出true(模板使用)
  71. View::assign('vat_deny', $result['vat_deny']);
  72. //增值税发票哈希值(php验证使用)
  73. View::assign('vat_hash', $result['vat_hash']);
  74. //输出默认使用的发票信息
  75. View::assign('inv_info', $result['inv_info']);
  76. //显示预存款、支付密码、充值卡
  77. View::assign('available_pd_amount', isset($result['available_predeposit'])?$result['available_predeposit']:'');
  78. View::assign('member_paypwd', $result['member_paypwd']);
  79. View::assign('available_rcb_amount', isset($result['available_rc_balance'])?$result['available_rc_balance']:'');
  80. //标识购买流程执行步骤
  81. View::assign('buy_step', 'step2');
  82. View::assign('ifcart', $ifcart);
  83. //店铺信息
  84. $store_list = model('store')->getStoreMemberIDList(array_keys($result['store_cart_list']));
  85. View::assign('store_list', $store_list);
  86. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  87. return View::fetch($this->template_dir.'buy_step1');
  88. }
  89. /**
  90. * 生成订单
  91. *
  92. */
  93. public function buy_step2() {
  94. $buy_logic = model('buy','logic');
  95. $post = input('post.');
  96. //处理自提门店
  97. foreach($post['chain_goods'] as $key => $val){
  98. if($val == 0){
  99. unset($post['chain_goods'][$key]);
  100. }
  101. }
  102. $result = $buy_logic->buyStep2($post, session('member_id'), session('member_name'), session('member_email'));
  103. if (!$result['code']) {
  104. $this->error($result['msg']);
  105. }
  106. //转向到商城支付页面
  107. $this->redirect('Buy/pay', ['pay_sn' => $result['data']['pay_sn']]);
  108. }
  109. /**
  110. * 下单时支付页面
  111. */
  112. public function pay() {
  113. $pay_sn = input('param.pay_sn');
  114. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  115. $this->error(lang('cart_order_pay_not_exists'), 'home/Memberorder/index');
  116. }
  117. //查询支付单信息
  118. $order_model = model('order');
  119. $pay_info = $order_model->getOrderpayInfo(array('pay_sn' => $pay_sn, 'buyer_id' => session('member_id')));
  120. if (empty($pay_info)) {
  121. $this->error(lang('cart_order_pay_not_exists'), 'home/Memberorder/index');
  122. }
  123. View::assign('pay_info', $pay_info);
  124. //取子订单列表
  125. $condition = array();
  126. $condition[]=array('pay_sn','=',$pay_sn);
  127. $condition[] = array('order_state','in', array_values(array(ORDER_STATE_NEW, ORDER_STATE_DEPOSIT, ORDER_STATE_REST, ORDER_STATE_PAY, ORDER_STATE_PICKUP)));
  128. $order_list = $order_model->getOrderList($condition, '', 'order_id,order_state,payment_code,order_amount,rcb_amount,pd_amount,order_sn,presell_deposit_amount,presell_rcb_amount,presell_pd_amount');
  129. if (empty($order_list)) {
  130. $this->error(lang('no_order_paid_was_found'), 'home/Memberorder/index');
  131. }
  132. //重新计算在线支付金额
  133. $pay_amount_online = 0;
  134. $pay_amount_offline = 0;
  135. //订单总支付金额(不包含货到付款)
  136. $pay_amount = 0;
  137. foreach ($order_list as $key => $order_info) {
  138. $payed_amount = floatval($order_info['rcb_amount']) + floatval($order_info['pd_amount']);
  139. //计算相关支付金额
  140. if ($order_info['payment_code'] != 'offline') {
  141. if ($order_info['order_state'] == ORDER_STATE_NEW || $order_info['order_state'] == ORDER_STATE_REST) {
  142. $pay_amount_online += ds_price_format(floatval($order_info['order_amount']) - floatval($order_info['presell_deposit_amount']) + floatval($order_info['presell_rcb_amount']) + floatval($order_info['presell_pd_amount']) - $payed_amount);
  143. }else if($order_info['order_state'] == ORDER_STATE_DEPOSIT){
  144. $pay_amount_online += ds_price_format(floatval($order_info['presell_deposit_amount']) - $payed_amount);
  145. }
  146. $pay_amount += floatval($order_info['order_amount']);
  147. } else {
  148. $pay_amount_offline += floatval($order_info['order_amount']);
  149. }
  150. //显示支付方式与支付结果
  151. if ($order_info['payment_code'] == 'offline') {
  152. $order_list[$key]['payment_state'] = lang('cart_step2_arrival_pay');
  153. } else {
  154. $order_list[$key]['payment_state'] = lang('cart_step2_online_pay');
  155. if ($payed_amount > 0) {
  156. $payed_tips = '';
  157. if (floatval($order_info['rcb_amount']) > 0) {
  158. $payed_tips = lang('card_has_been_paid').':¥' . $order_info['rcb_amount'];
  159. }
  160. if (floatval($order_info['pd_amount']) > 0) {
  161. $payed_tips .= lang('prepaid_deposits_beenpaid').':¥' . $order_info['pd_amount'];
  162. }
  163. $order_list[$key]['order_amount'] .= " ( {$payed_tips} )";
  164. }
  165. }
  166. }
  167. View::assign('order_list', $order_list);
  168. //如果线上线下支付金额都为0,转到支付成功页
  169. if (empty($pay_amount_online) && empty($pay_amount_offline)) {
  170. $this->redirect('Buy/pay_ok', ['pay_sn' => $pay_sn, 'pay_amount' => ds_price_format($pay_amount)]);
  171. }
  172. //输出订单描述
  173. if (empty($pay_amount_online)) {
  174. $order_remind = lang('successful_ordering_delivery');
  175. } elseif (empty($pay_amount_offline)) {
  176. $order_remind = lang('timely_payment');
  177. } else {
  178. $order_remind = lang('payment_soon_possible');
  179. }
  180. View::assign('order_remind', $order_remind);
  181. View::assign('pay_amount_online', ds_price_format($pay_amount_online));
  182. // View::assign('pd_amount', ds_price_format($pd_amount));
  183. //显示支付接口列表
  184. if ($pay_amount_online > 0) {
  185. $payment_model = model('payment');
  186. $condition = array();
  187. $condition[] = array('payment_platform','=','pc');
  188. $payment_list = $payment_model->getPaymentOpenList($condition);
  189. if(empty($payment_list)){
  190. $this->error(lang('appropriate_payment_method'),'home/Memberorder/index');
  191. }
  192. foreach ($payment_list as $key => $payment) {
  193. if(in_array($payment['payment_code'], array('predeposit','offline'))){
  194. unset($payment_list[$key]);
  195. }
  196. }
  197. View::assign('payment_list', $payment_list);
  198. }
  199. //显示预存款、支付密码、充值卡
  200. $member_model=model('member');
  201. $buyer_info=$member_model->getMemberInfoByID($this->member_info['member_id']);
  202. View::assign('available_pd_amount', ($buyer_info['available_predeposit']>0)?$buyer_info['available_predeposit']:'');
  203. View::assign('member_paypwd', $buyer_info['member_paypwd']);
  204. View::assign('available_rcb_amount', ($buyer_info['available_rc_balance']>0)?$buyer_info['available_rc_balance']:'');
  205. //标识 购买流程执行第几步
  206. View::assign('buy_step', 'step3');
  207. return View::fetch($this->template_dir.'buy_step2');
  208. }
  209. /**
  210. * 店铺入驻支付页面
  211. */
  212. public function sj_pay(){
  213. $storejoinin_model = model('storejoinin');
  214. $joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => session('member_id')));
  215. if(!$joinin_detail){
  216. $this->error('店铺入驻不存在');
  217. }
  218. if($joinin_detail['joinin_state']!=STORE_JOIN_STATE_VERIFY_SUCCESS){
  219. $this->error('店铺入驻状态不是待支付状态');
  220. }
  221. $pay_amount_online=round($joinin_detail['paying_amount']-$joinin_detail['rcb_amount']-$joinin_detail['pd_amount'],2);
  222. View::assign('pay_amount_online', $pay_amount_online);
  223. View::assign('store_name', $joinin_detail['store_name']);
  224. //显示支付接口列表
  225. if ($pay_amount_online > 0) {
  226. //显示支付接口列表
  227. $payment_model = model('payment');
  228. $condition = array();
  229. $condition[] = array('payment_code','not in',array('offline', 'predeposit'));
  230. $condition[] = array('payment_state','=',1);
  231. $condition[] = array('payment_platform','=','pc');
  232. $payment_list = $payment_model->getPaymentList($condition);
  233. if (empty($payment_list)) {
  234. $this->error(lang('appropriate_payment_method'));
  235. }
  236. View::assign('payment_list', $payment_list);
  237. }
  238. //显示预存款、支付密码、充值卡
  239. $member_model=model('member');
  240. $buyer_info=$member_model->getMemberInfoByID($this->member_info['member_id']);
  241. View::assign('available_pd_amount', ($buyer_info['available_predeposit']>0)?$buyer_info['available_predeposit']:'');
  242. View::assign('member_paypwd', $buyer_info['member_paypwd']);
  243. View::assign('available_rcb_amount', ($buyer_info['available_rc_balance']>0)?$buyer_info['available_rc_balance']:'');
  244. //标识 购买流程执行第几步
  245. View::assign('buy_step', 'step3');
  246. return View::fetch($this->template_dir.'storejoinin_pay');
  247. }
  248. /**
  249. * 预存款充值下单时支付页面
  250. */
  251. public function pd_pay() {
  252. $pay_sn = input('param.pay_sn');
  253. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  254. $this->error(lang('param_error'), (string)url('Predeposit/index'));
  255. }
  256. //查询支付单信息
  257. $predeposit_model = model('predeposit');
  258. $pd_info = $predeposit_model->getPdRechargeInfo(array('pdr_sn' => $pay_sn, 'pdr_member_id' => session('member_id')));
  259. if (empty($pd_info)) {
  260. $this->error(lang('param_error'));
  261. }
  262. if (intval($pd_info['pdr_payment_state'])) {
  263. $this->error(lang('not_repeat_payment'), (string)url('Predeposit/index'));
  264. }
  265. View::assign('pdr_info', $pd_info);
  266. //显示支付接口列表
  267. $payment_model = model('payment');
  268. $condition = array();
  269. $condition[] = array('payment_code','not in',array('offline', 'predeposit'));
  270. $condition[] = array('payment_state','=',1);
  271. $condition[] = array('payment_platform','=','pc');
  272. $payment_list = $payment_model->getPaymentList($condition);
  273. if (empty($payment_list)) {
  274. $this->error(lang('appropriate_payment_method'), (string)url('Predeposit/index'));
  275. }
  276. View::assign('payment_list', $payment_list);
  277. //标识 购买流程执行第几步
  278. View::assign('buy_step', 'step3');
  279. return View::fetch($this->template_dir.'predeposit_pay');
  280. }
  281. /**
  282. * 支付成功页面
  283. */
  284. public function pay_ok() {
  285. $pay_sn = input('param.pay_sn');
  286. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  287. $this->error(lang('cart_order_pay_not_exists'), 'memberorder/index');
  288. }
  289. //查询支付单信息
  290. $order_model = model('order');
  291. $pay_info = $order_model->getOrderpayInfo(array('pay_sn' => $pay_sn, 'buyer_id' => session('member_id')));
  292. if (empty($pay_info)) {
  293. $this->error(lang('cart_order_pay_not_exists'), 'home/Memberorder/index');
  294. }
  295. View::assign('pay_info', $pay_info);
  296. View::assign('buy_step', 'step4');
  297. return View::fetch($this->template_dir.'buy_step3');
  298. }
  299. function load_addr() {
  300. $id = intval(input('param.id'));
  301. $address_model=model('address');
  302. $chain_model = model('chain');
  303. //如果传入ID 则删除再查询
  304. if ($id > 0) {
  305. $address_model->delAddress(array('address_id'=>$id,'member_id'=> session('member_id')));
  306. }
  307. $address_list = $address_model->getAddressList(array('member_id'=>session('member_id')));
  308. foreach($address_list as $key => $val){
  309. $address_list[$key]['cityerror'] = '';
  310. if($val['chain_id'] > 0){
  311. $condition = array();
  312. $condition[] = array('chain_id','=',$val['chain_id']);
  313. $chain_info = $chain_model->getChainInfo($condition,'chain_area_2,chain_area_3');
  314. if($val['city_id'] !== $chain_info['chain_area_2'] || $val['area_id'] !== $chain_info['chain_area_3']){
  315. $address_list[$key]['cityerror'] = lang('cart_step1_city_fail');
  316. }
  317. }
  318. }
  319. View::assign('address_list', $address_list);
  320. echo View::fetch($this->template_dir.'buy_address_load');
  321. }
  322. /*
  323. * 新增收货地址
  324. */
  325. function add_addr() {
  326. if (!request()->isPost()) {
  327. //设置类型关联的分类
  328. $area_mod=model('area');
  329. $region_list = $area_mod->getAreaList(array('area_parent_id'=>'0'));
  330. View::assign('region_list', $region_list);
  331. echo View::fetch($this->template_dir.'buy_address_add');
  332. } else {
  333. $data = array(
  334. 'member_id' => session('member_id'),
  335. 'address_realname' => input('post.true_name'),
  336. 'area_id' => intval(input('post.area_id')),
  337. 'city_id' => intval(input('post.city_id')),
  338. 'area_info'=>input('post.area_info'),
  339. 'address_detail' => input('post.address'),
  340. 'address_tel_phone' => input('post.tel_phone'),
  341. 'address_mob_phone' => input('post.mob_phone'),
  342. 'address_longitude' => input('post.longitude'),
  343. 'address_latitude' => input('post.latitude'),
  344. 'address_is_default' => 0,
  345. );
  346. $buy_validate = ds_validate('buy');
  347. if (!$buy_validate->scene('add_addr')->check($data)) {
  348. exit(json_encode(array('state' => false, 'msg' => $buy_validate->getError())));
  349. }
  350. $insert_id = model('address')->addAddress($data);
  351. if ($insert_id) {
  352. exit(json_encode(array('state' => true, 'addr_id' => $insert_id)));
  353. } else {
  354. exit(json_encode(array('state' => true, 'msg' => lang('add_cart_failed'))));
  355. }
  356. }
  357. }
  358. /**
  359. * 选择不同地区时,异步处理并返回每个店铺总运费以及本地区是否能使用货到付款
  360. * 如果店铺统一设置了满免运费规则,则售卖区域无效
  361. * 如果店铺未设置满免规则,且使用售卖区域,按售卖区域计算,如果其中有商品使用相同的售卖区域,则两种商品数量相加后再应用该售卖区域计算(即作为一种商品算运费)
  362. * 如果未找到售卖区域,按免运费处理
  363. * 如果没有使用售卖区域,商品运费按快递价格计算,运费不随购买数量增加
  364. */
  365. public function change_addr() {
  366. $buy_logic = model('buy','logic');
  367. $data = $buy_logic->changeAddr(input('post.freight_hash'), input('post.city_id'), input('post.area_id'), session('member_id'),input('post.goods'));
  368. if (!empty($data)) {
  369. exit(json_encode($data));
  370. } else {
  371. exit();
  372. }
  373. }
  374. function load_inv() {
  375. $id = intval(input('param.id'));
  376. $invoice_model = model('invoice');
  377. //如果传入ID 则删除再查询
  378. if ($id > 0) {
  379. $condition = array();
  380. $condition[] = array('invoice_id','=',$id);
  381. $condition[] = array('member_id','=',session('member_id'));
  382. $invoice_model->delInvoice($condition);
  383. }
  384. $inv_list = $invoice_model->getInvoiceList(array('member_id'=> session('member_id')));
  385. if (!empty($inv_list)) {
  386. foreach ($inv_list as $key => $value) {
  387. if ($value['invoice_state'] == 1) {
  388. $inv_list[$key]['content'] = lang('commercial_invoice') . ' ' . $value['invoice_title'] . ' ' . $value['invoice_code']. ' ' . $value['invoice_content'];
  389. } else {
  390. $inv_list[$key]['content'] = lang('vat_invoice') . ' ' . $value['invoice_company'] . ' ' . $value['invoice_company_code'] . ' ' . $value['invoice_reg_addr'];
  391. }
  392. }
  393. }
  394. View::assign('inv_list', $inv_list);
  395. echo View::fetch($this->template_dir.'buy_invoice_load');
  396. }
  397. function add_inv() {
  398. if (!request()->isPost()) {
  399. echo View::fetch($this->template_dir.'buy_address_add');
  400. } else {
  401. $invoice_type = input('post.invoice_type');
  402. //如果是增值税发票验证表单信息
  403. if ($invoice_type == 2) {
  404. if (empty(input('post.invoice_company')) || empty(input('post.invoice_company_code')) || empty(input('post.invoice_reg_addr'))) {
  405. exit(json_encode(array('state' => false, 'msg' => lang('save_information_failed'))));
  406. }
  407. }
  408. $data = array();
  409. if ($invoice_type == 1) {
  410. $data['invoice_state'] = 1;
  411. $data['invoice_title'] = input('post.invoice_title_select') == 'person' ? lang('individual') : input('post.invoice_title');
  412. $data['invoice_content'] = input('post.invoice_content');
  413. $data['invoice_code'] = input('post.invoice_code');
  414. } else {
  415. $data['invoice_state'] = 2;
  416. $data['invoice_company'] = input('post.invoice_company');
  417. $data['invoice_company_code'] = input('post.invoice_company_code');
  418. $data['invoice_reg_addr'] = input('post.invoice_reg_addr');
  419. $data['invoice_reg_phone'] = input('post.invoice_reg_phone');
  420. $data['invoice_reg_bname'] = input('post.invoice_reg_bname');
  421. $data['invoice_reg_baccount'] = input('post.invoice_reg_baccount');
  422. $data['invoice_rec_name'] = input('post.invoice_rec_name');
  423. $data['invoice_rec_mobphone'] = input('post.invoice_rec_mobphone');
  424. $data['invoice_rec_province'] = input('post.area_info');
  425. $data['invoice_goto_addr'] = input('post.invoice_goto_addr');
  426. }
  427. $data['member_id'] = session('member_id');
  428. $insert_id = model('invoice')->addInvoice($data);
  429. if ($insert_id) {
  430. exit(json_encode(array('state' => 'success', 'id' => $insert_id)));
  431. } else {
  432. exit(json_encode(array('state' => 'fail', 'msg' => lang('save_information_failed'))));
  433. }
  434. }
  435. }
  436. /**
  437. * AJAX验证支付密码
  438. */
  439. public function check_pd_pwd() {
  440. $password = input('param.password');
  441. if (empty($password))
  442. exit('0');
  443. $buyer_info = model('member')->getMemberInfoByID(session('member_id'));
  444. echo ($buyer_info['member_paypwd'] != '' && $buyer_info['member_paypwd'] === md5($password)) ? '1' : '0';
  445. }
  446. /**
  447. * F码验证
  448. */
  449. public function check_fcode() {
  450. $result = model('buy','logic')->checkFcode(input('goods_commonid'), input('fcode'));
  451. echo $result['code'] ? '1' : '0';
  452. exit;
  453. }
  454. /**
  455. * 得到所购买的id和数量
  456. *
  457. */
  458. private function _parseItems($cart_id) {
  459. //存放所购商品ID和数量组成的键值对
  460. $buy_items = array();
  461. if (is_array($cart_id)) {
  462. foreach ($cart_id as $value) {
  463. if (preg_match_all('/^(\d{1,10})\|(\d{1,6})$/', $value, $match)) {
  464. $buy_items[$match[1][0]] = $match[2][0];
  465. }
  466. }
  467. }
  468. return $buy_items;
  469. }
  470. /**
  471. * 购买分流
  472. */
  473. private function _buy_branch($post) {
  474. if (!isset($post['ifcart'])) {
  475. //取得购买商品信息
  476. $buy_items = $this->_parseItems($post['cart_id']);
  477. $goods_id = key($buy_items);
  478. $quantity = current($buy_items);
  479. $goods_info = model('goods')->getGoodsOnlineInfoAndPromotionById($goods_id);
  480. if ($goods_info['is_virtual']) {
  481. $this->redirect('Buyvirtual/buy_step1',['goods_id'=>$goods_id,'quantity'=>$quantity]);
  482. }
  483. }
  484. }
  485. public function change_chain() {
  486. $buy_logic = model('buy','logic');
  487. $chain_list = $buy_logic->changechain(input('post.goods'),input('post.area_id'), session('member_id'));
  488. if (!empty($chain_list)) {
  489. return ds_json_encode(10000, '',array('chain_list'=>$chain_list));
  490. } else {
  491. exit();
  492. }
  493. }
  494. }