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