Buy.php 25 KB

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