Buy.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. *
  11. * 控制器
  12. */
  13. class Buy extends BaseMember
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/buy.lang.php');
  19. //验证该会员是否禁止购买
  20. if (!session('is_buy')) {
  21. $this->error(lang('cart_buy_noallow'));
  22. }
  23. if (config('ds_config.member_auth') && $this->member_info['member_auth_state'] != 3) {
  24. $this->error(lang('cart_buy_noauth'), (string)url('MemberAuth/index'));
  25. }
  26. }
  27. public function buy_step1()
  28. {
  29. if (empty(input('post.'))) {
  30. $this->error(lang('param_error'));
  31. }
  32. //虚拟商品购买分流
  33. $this->_buy_branch(input('post.'));
  34. $ifcart = input('post.ifcart');
  35. $buy_logic = model('buy', 'logic');
  36. $result = $buy_logic->buyStep1(input('post.cart_id/a'), $ifcart, session('member_id'), session('store_id'));
  37. if ($result['code'] != 'SUCCESS') {
  38. $this->error($result['msg']);
  39. } else {
  40. $result = $result['data'];
  41. }
  42. View::assign('if_presell', $result['if_presell']);
  43. View::assign('presell_deposit_amount', $result['presell_deposit_amount']);
  44. //商品金额计算(分别对每个商品/优惠套装小计、每个店铺小计)
  45. View::assign('store_cart_list', $result['store_cart_list']);
  46. View::assign('store_goods_total', $result['store_goods_total']);
  47. View::assign('store_goods_original_total', $result['store_goods_original_total']);
  48. View::assign('store_goods_discount_total', $result['store_goods_discount_total']);
  49. //取得店铺优惠 - 满即送(赠品列表,店铺满送规则列表)
  50. View::assign('store_premiums_list', $result['store_premiums_list']);
  51. View::assign('store_mansong_rule_list', $result['store_mansong_rule_list']);
  52. //返回门店数据
  53. View::assign('chaingoods_list', $result['chaingoods_list']);
  54. //返回店铺可用的代金券
  55. View::assign('store_voucher_list', $result['store_voucher_list']);
  56. //返回平台可用的代金券
  57. View::assign('mall_voucher_list', $result['mall_voucher_list']);
  58. //返回需要计算运费的店铺ID数组 和 不需要计算运费(满免运费活动的)店铺ID及描述
  59. View::assign('need_calc_sid_list', $result['need_calc_sid_list']);
  60. View::assign('cancel_calc_sid_list', $result['cancel_calc_sid_list']);
  61. //将商品ID、数量、售卖区域、运费序列化,加密,输出到模板,选择地区AJAX计算运费时作为参数使用
  62. View::assign('freight_hash', $result['freight_list']);
  63. //输出用户默认收货地址
  64. View::assign('address_info', $result['address_info']);
  65. //输出有货到付款时,在线支付和货到付款及每种支付下商品数量和详细列表
  66. View::assign('pay_goods_list', $result['pay_goods_list']);
  67. View::assign('ifshow_offpay', $result['ifshow_offpay']);
  68. View::assign('deny_edit_payment', isset($result['deny_edit_payment']) ? $result['deny_edit_payment'] : 0);
  69. //不提供增值税发票时抛出true(模板使用)
  70. View::assign('vat_deny', $result['vat_deny']);
  71. //增值税发票哈希值(php验证使用)
  72. View::assign('vat_hash', $result['vat_hash']);
  73. //输出默认使用的发票信息
  74. View::assign('inv_info', $result['inv_info']);
  75. //显示预存款、支付密码、充值卡
  76. View::assign('available_pd_amount', isset($result['available_predeposit']) ? $result['available_predeposit'] : '');
  77. View::assign('member_paypwd', $result['member_paypwd']);
  78. View::assign('available_rcb_amount', isset($result['available_rc_balance']) ? $result['available_rc_balance'] : '');
  79. //标识购买流程执行步骤
  80. View::assign('buy_step', 'step2');
  81. View::assign('ifcart', $ifcart);
  82. //店铺信息
  83. $store_list = model('store')->getStoreMemberIDList(array_keys($result['store_cart_list']));
  84. View::assign('store_list', $store_list);
  85. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  86. return View::fetch($this->template_dir . 'buy_step1');
  87. }
  88. /**
  89. * 生成订单
  90. *
  91. */
  92. public function buy_step2()
  93. {
  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. {
  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. {
  215. $storejoinin_model = model('storejoinin');
  216. $joinin_detail = $storejoinin_model->getOneStorejoinin(array('member_id' => session('member_id')));
  217. if (!$joinin_detail) {
  218. $this->error('店铺入驻不存在');
  219. }
  220. if ($joinin_detail['joinin_state'] != STORE_JOIN_STATE_VERIFY_SUCCESS) {
  221. $this->error('店铺入驻状态不是待支付状态');
  222. }
  223. $pay_amount_online = round($joinin_detail['paying_amount'] - $joinin_detail['rcb_amount'] - $joinin_detail['pd_amount'], 2);
  224. View::assign('pay_amount_online', $pay_amount_online);
  225. View::assign('store_name', $joinin_detail['store_name']);
  226. //显示支付接口列表
  227. if ($pay_amount_online > 0) {
  228. //显示支付接口列表
  229. $payment_model = model('payment');
  230. $condition = array();
  231. $condition[] = array('payment_code', 'not in', array('offline', 'predeposit'));
  232. $condition[] = array('payment_state', '=', 1);
  233. $condition[] = array('payment_platform', '=', 'pc');
  234. $payment_list = $payment_model->getPaymentList($condition);
  235. if (empty($payment_list)) {
  236. $this->error(lang('appropriate_payment_method'));
  237. }
  238. View::assign('payment_list', $payment_list);
  239. }
  240. //显示预存款、支付密码、充值卡
  241. $member_model = model('member');
  242. $buyer_info = $member_model->getMemberInfoByID($this->member_info['member_id']);
  243. View::assign('available_pd_amount', ($buyer_info['available_predeposit'] > 0) ? $buyer_info['available_predeposit'] : '');
  244. View::assign('member_paypwd', $buyer_info['member_paypwd']);
  245. View::assign('available_rcb_amount', ($buyer_info['available_rc_balance'] > 0) ? $buyer_info['available_rc_balance'] : '');
  246. //标识 购买流程执行第几步
  247. View::assign('buy_step', 'step3');
  248. return View::fetch($this->template_dir . 'storejoinin_pay');
  249. }
  250. /**
  251. * 预存款充值下单时支付页面
  252. */
  253. public function pd_pay()
  254. {
  255. $pay_sn = input('param.pay_sn');
  256. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  257. $this->error(lang('param_error'), (string)url('Predeposit/index'));
  258. }
  259. //查询支付单信息
  260. $predeposit_model = model('predeposit');
  261. $pd_info = $predeposit_model->getPdRechargeInfo(array('pdr_sn' => $pay_sn, 'pdr_member_id' => session('member_id')));
  262. if (empty($pd_info)) {
  263. $this->error(lang('param_error'));
  264. }
  265. if (intval($pd_info['pdr_payment_state'])) {
  266. $this->error(lang('not_repeat_payment'), (string)url('Predeposit/index'));
  267. }
  268. View::assign('pdr_info', $pd_info);
  269. //显示支付接口列表
  270. $payment_model = model('payment');
  271. $condition = array();
  272. $condition[] = array('payment_code', 'not in', array('offline', 'predeposit'));
  273. $condition[] = array('payment_state', '=', 1);
  274. $condition[] = array('payment_platform', '=', 'pc');
  275. $payment_list = $payment_model->getPaymentList($condition);
  276. if (empty($payment_list)) {
  277. $this->error(lang('appropriate_payment_method'), (string)url('Predeposit/index'));
  278. }
  279. View::assign('payment_list', $payment_list);
  280. //标识 购买流程执行第几步
  281. View::assign('buy_step', 'step3');
  282. return View::fetch($this->template_dir . 'predeposit_pay');
  283. }
  284. /**
  285. * 支付成功页面
  286. */
  287. public function pay_ok()
  288. {
  289. $pay_sn = input('param.pay_sn');
  290. if (!preg_match('/^\d{20}$/', $pay_sn)) {
  291. $this->error(lang('cart_order_pay_not_exists'), 'memberorder/index');
  292. }
  293. //查询支付单信息
  294. $order_model = model('order');
  295. $pay_info = $order_model->getOrderpayInfo(array('pay_sn' => $pay_sn, 'buyer_id' => session('member_id')));
  296. if (empty($pay_info)) {
  297. $this->error(lang('cart_order_pay_not_exists'), 'home/Memberorder/index');
  298. }
  299. View::assign('pay_info', $pay_info);
  300. View::assign('buy_step', 'step4');
  301. return View::fetch($this->template_dir . 'buy_step3');
  302. }
  303. function load_addr()
  304. {
  305. $id = intval(input('param.id'));
  306. $address_model = model('address');
  307. $chain_model = model('chain');
  308. //如果传入ID 则删除再查询
  309. if ($id > 0) {
  310. $address_model->delAddress(array('address_id' => $id, 'member_id' => session('member_id')));
  311. }
  312. $address_list = $address_model->getAddressList(array('member_id' => session('member_id')));
  313. foreach ($address_list as $key => $val) {
  314. $address_list[$key]['cityerror'] = '';
  315. if ($val['chain_id'] > 0) {
  316. $condition = array();
  317. $condition[] = array('chain_id', '=', $val['chain_id']);
  318. $chain_info = $chain_model->getChainInfo($condition, 'chain_area_2,chain_area_3');
  319. if ($val['city_id'] !== $chain_info['chain_area_2'] || $val['area_id'] !== $chain_info['chain_area_3']) {
  320. $address_list[$key]['cityerror'] = lang('cart_step1_city_fail');
  321. }
  322. }
  323. }
  324. View::assign('address_list', $address_list);
  325. echo View::fetch($this->template_dir . 'buy_address_load');
  326. }
  327. /*
  328. * 新增收货地址
  329. */
  330. function add_addr()
  331. {
  332. if (!request()->isPost()) {
  333. //设置类型关联的分类
  334. $area_mod = model('area');
  335. $region_list = $area_mod->getAreaList(array('area_parent_id' => '0'));
  336. View::assign('region_list', $region_list);
  337. echo View::fetch($this->template_dir . 'buy_address_add');
  338. } else {
  339. $data = array(
  340. 'member_id' => session('member_id'),
  341. 'address_realname' => input('post.true_name'),
  342. 'area_id' => intval(input('post.area_id')),
  343. 'city_id' => intval(input('post.city_id')),
  344. 'area_info' => input('post.area_info'),
  345. 'address_detail' => input('post.address'),
  346. 'address_tel_phone' => input('post.tel_phone'),
  347. 'address_mob_phone' => input('post.mob_phone'),
  348. 'address_longitude' => input('post.longitude'),
  349. 'address_latitude' => input('post.latitude'),
  350. 'address_is_default' => 0,
  351. );
  352. $buy_validate = ds_validate('buy');
  353. if (!$buy_validate->scene('add_addr')->check($data)) {
  354. exit(json_encode(array('state' => false, 'msg' => $buy_validate->getError())));
  355. }
  356. $insert_id = model('address')->addAddress($data);
  357. if ($insert_id) {
  358. exit(json_encode(array('state' => true, 'addr_id' => $insert_id)));
  359. } else {
  360. exit(json_encode(array('state' => true, 'msg' => lang('add_cart_failed'))));
  361. }
  362. }
  363. }
  364. /**
  365. * 选择不同地区时,异步处理并返回每个店铺总运费以及本地区是否能使用货到付款
  366. * 如果店铺统一设置了满免运费规则,则售卖区域无效
  367. * 如果店铺未设置满免规则,且使用售卖区域,按售卖区域计算,如果其中有商品使用相同的售卖区域,则两种商品数量相加后再应用该售卖区域计算(即作为一种商品算运费)
  368. * 如果未找到售卖区域,按免运费处理
  369. * 如果没有使用售卖区域,商品运费按快递价格计算,运费不随购买数量增加
  370. */
  371. public function change_addr()
  372. {
  373. $buy_logic = model('buy', 'logic');
  374. $data = $buy_logic->changeAddr(input('post.freight_hash'), input('post.city_id'), input('post.area_id'), session('member_id'), input('post.goods'));
  375. if (!empty($data)) {
  376. exit(json_encode($data));
  377. } else {
  378. exit();
  379. }
  380. }
  381. function load_inv()
  382. {
  383. $id = intval(input('param.id'));
  384. $invoice_model = model('invoice');
  385. //如果传入ID 则删除再查询
  386. if ($id > 0) {
  387. $condition = array();
  388. $condition[] = array('invoice_id', '=', $id);
  389. $condition[] = array('member_id', '=', session('member_id'));
  390. $invoice_model->delInvoice($condition);
  391. }
  392. $inv_list = $invoice_model->getInvoiceList(array('member_id' => session('member_id')));
  393. if (!empty($inv_list)) {
  394. foreach ($inv_list as $key => $value) {
  395. if ($value['invoice_state'] == 1) {
  396. $inv_list[$key]['content'] = lang('commercial_invoice') . ' ' . $value['invoice_title'] . ' ' . $value['invoice_code'] . ' ' . $value['invoice_content'];
  397. } else {
  398. $inv_list[$key]['content'] = lang('vat_invoice') . ' ' . $value['invoice_company'] . ' ' . $value['invoice_company_code'] . ' ' . $value['invoice_reg_addr'];
  399. }
  400. }
  401. }
  402. View::assign('inv_list', $inv_list);
  403. echo View::fetch($this->template_dir . 'buy_invoice_load');
  404. }
  405. function add_inv()
  406. {
  407. if (!request()->isPost()) {
  408. echo View::fetch($this->template_dir . 'buy_address_add');
  409. } else {
  410. $invoice_type = input('post.invoice_type');
  411. //如果是增值税发票验证表单信息
  412. if ($invoice_type == 2) {
  413. if (empty(input('post.invoice_company')) || empty(input('post.invoice_company_code')) || empty(input('post.invoice_reg_addr'))) {
  414. exit(json_encode(array('state' => false, 'msg' => lang('save_information_failed'))));
  415. }
  416. }
  417. $data = array();
  418. if ($invoice_type == 1) {
  419. $data['invoice_state'] = 1;
  420. $data['invoice_title'] = input('post.invoice_title_select') == 'person' ? lang('individual') : input('post.invoice_title');
  421. $data['invoice_content'] = input('post.invoice_content');
  422. $data['invoice_code'] = input('post.invoice_code');
  423. } else {
  424. $data['invoice_state'] = 2;
  425. $data['invoice_company'] = input('post.invoice_company');
  426. $data['invoice_company_code'] = input('post.invoice_company_code');
  427. $data['invoice_reg_addr'] = input('post.invoice_reg_addr');
  428. $data['invoice_reg_phone'] = input('post.invoice_reg_phone');
  429. $data['invoice_reg_bname'] = input('post.invoice_reg_bname');
  430. $data['invoice_reg_baccount'] = input('post.invoice_reg_baccount');
  431. $data['invoice_rec_name'] = input('post.invoice_rec_name');
  432. $data['invoice_rec_mobphone'] = input('post.invoice_rec_mobphone');
  433. $data['invoice_rec_province'] = input('post.area_info');
  434. $data['invoice_goto_addr'] = input('post.invoice_goto_addr');
  435. }
  436. $data['member_id'] = session('member_id');
  437. $insert_id = model('invoice')->addInvoice($data);
  438. if ($insert_id) {
  439. exit(json_encode(array('state' => 'success', 'id' => $insert_id)));
  440. } else {
  441. exit(json_encode(array('state' => 'fail', 'msg' => lang('save_information_failed'))));
  442. }
  443. }
  444. }
  445. /**
  446. * AJAX验证支付密码
  447. */
  448. public function check_pd_pwd()
  449. {
  450. $password = input('param.password');
  451. if (empty($password))
  452. exit('0');
  453. $buyer_info = model('member')->getMemberInfoByID(session('member_id'));
  454. echo ($buyer_info['member_paypwd'] != '' && $buyer_info['member_paypwd'] === md5($password)) ? '1' : '0';
  455. }
  456. /**
  457. * F码验证
  458. */
  459. public function check_fcode()
  460. {
  461. $result = model('buy', 'logic')->checkFcode(input('goods_commonid'), input('fcode'));
  462. echo $result['code'] ? '1' : '0';
  463. exit;
  464. }
  465. /**
  466. * 得到所购买的id和数量
  467. *
  468. */
  469. private function _parseItems($cart_id)
  470. {
  471. //存放所购商品ID和数量组成的键值对
  472. $buy_items = array();
  473. if (is_array($cart_id)) {
  474. foreach ($cart_id as $value) {
  475. if (preg_match_all('/^(\d{1,10})\|(\d{1,6})$/', $value, $match)) {
  476. $buy_items[$match[1][0]] = $match[2][0];
  477. }
  478. }
  479. }
  480. return $buy_items;
  481. }
  482. /**
  483. * 购买分流
  484. */
  485. private function _buy_branch($post)
  486. {
  487. if (!isset($post['ifcart'])) {
  488. //取得购买商品信息
  489. $buy_items = $this->_parseItems($post['cart_id']);
  490. $goods_id = key($buy_items);
  491. $quantity = current($buy_items);
  492. $goods_info = model('goods')->getGoodsOnlineInfoAndPromotionById($goods_id);
  493. if ($goods_info['is_virtual']) {
  494. $this->redirect('Buyvirtual/buy_step1', ['goods_id' => $goods_id, 'quantity' => $quantity]);
  495. }
  496. }
  497. }
  498. public function change_chain()
  499. {
  500. $buy_logic = model('buy', 'logic');
  501. $chain_list = $buy_logic->changechain(input('post.goods'), input('post.area_id'), session('member_id'));
  502. if (!empty($chain_list)) {
  503. return ds_json_encode(10000, '', array('chain_list' => $chain_list));
  504. } else {
  505. exit();
  506. }
  507. }
  508. }