GroupController.class.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. * 拼团模块
  11. * @author fish
  12. *
  13. */
  14. namespace Home\Controller;
  15. class GroupController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. public function pintuan_slides()
  21. {
  22. $_GPC = I('request.');
  23. // 活动商品展示方式 pintuan_show_type 0横向布局 1左右布局
  24. $pintuan_show_type_info= D('Home/Front')->get_config_by_name('pintuan_show_type');
  25. if( empty($pintuan_show_type_info) )
  26. {
  27. $pintuan_show_type_info = 0;
  28. }
  29. //拼团页面浮窗 hide_pintuan_page_windows 0开启 1关闭
  30. $hide_pintuan_page_windows_info= D('Home/Front')->get_config_by_name('hide_pintuan_page_windows' );
  31. if( empty($hide_pintuan_page_windows_info) )
  32. {
  33. $hide_pintuan_page_windows_info = 0;
  34. }
  35. //拼团规则介绍 pintuan_publish
  36. $pintuan_publish_info= D('Home/Front')->get_config_by_name('pintuan_publish');
  37. $category_list = D('Home/GoodsCategory')->get_index_goods_category(0,'pintuan');
  38. $params = array();
  39. $params[':uniacid'] = $uniacid;
  40. $params[':type'] = 'pintuan';
  41. $params[':enabled'] = 1;
  42. //拼团幻灯片
  43. $slider_list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_adv
  44. WHERE type='pintuan' and enabled=1 " . ' order by displayorder desc, id desc ');
  45. if(!empty($slider_list))
  46. {
  47. foreach($slider_list as $key => $val)
  48. {
  49. $val['image'] = tomedia($val['thumb']);
  50. $slider_list[$key] = $val;
  51. }
  52. }else{
  53. $slider_list = array();
  54. }
  55. //tabbar开关
  56. //$open_tabbar_out_weapp = D('Home/Front')->get_config_by_name('open_tabbar_out_weapp');
  57. //$tabbar_out_type = D('Home/Front')->get_config_by_name('tabbar_out_type');
  58. //分享信息
  59. $pintuan_index_share_title = D('Home/Front')->get_config_by_name('pintuan_index_share_title');
  60. $pintuan_index_share_img = D('Home/Front')->get_config_by_name('pintuan_index_share_img');
  61. if(!empty($pintuan_index_share_img)){
  62. $pintuan_index_share_img = tomedia($pintuan_index_share_img);
  63. }
  64. echo json_encode(
  65. array(
  66. 'code'=>0,
  67. 'pintuan_show_type' => $pintuan_show_type_info,
  68. 'category_list' => $category_list,
  69. 'hide_pintuan_page_windows' => $hide_pintuan_page_windows_info,
  70. 'pintuan_publish' => htmlspecialchars_decode($pintuan_publish_info),
  71. 'slider_list' => $slider_list,
  72. // 'open_tabbar_out_weapp' => $open_tabbar_out_weapp,
  73. // 'tabbar_out_type' => $tabbar_out_type,
  74. 'pintuan_index_share_title' => $pintuan_index_share_title,
  75. 'pintuan_index_share_img' => $pintuan_index_share_img
  76. )
  77. );
  78. die();
  79. }
  80. //拼团商品首页
  81. public function get_pintuan_list()
  82. {
  83. $_GPC = I('request.');
  84. $head_id = $_GPC['head_id'];
  85. if($head_id == 'undefined') $head_id = '';
  86. $pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
  87. if( empty($pintuan_model_buy) || $pintuan_model_buy ==0 )
  88. {
  89. $pintuan_model_buy = 0;
  90. $head_id = '';
  91. }
  92. $pageNum = isset($_GPC['pageNum']) ? intval($_GPC['pageNum']) : 1;
  93. $gid = $_GPC['gid'];
  94. $keyword = $_GPC['keyword'];
  95. $is_random = isset($_GPC['is_random']) ? $_GPC['is_random'] : 0;
  96. $is_index = isset($_GPC['is_index']) ? $_GPC['is_index'] : 0;
  97. $per_page = isset($_GPC['per_page']) ? $_GPC['per_page'] : 10;
  98. if($gid == 'undefined' || $gid =='')
  99. {
  100. $gid = 0;
  101. }
  102. if(!$keyword){
  103. $gids = D('Home/GoodsCategory')->get_index_goods_category($gid);
  104. $gidArr = array();
  105. $gidArr[] = $gid;
  106. foreach ($gids as $key => $val) {
  107. $gidArr[] = $val['id'];
  108. }
  109. $gid = implode(',', $gidArr);
  110. }
  111. $offset = ($pageNum - 1) * $per_page;
  112. $limit = "{$offset},{$per_page}";
  113. $token = $_GPC['token'];
  114. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token ) )->find();
  115. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  116. {
  117. }else{
  118. $member_id = $weprogram_token['member_id'];
  119. }
  120. $now_time = time();
  121. $where = " g.grounding =1 and g.type ='pin' ";
  122. if( isset($is_index) && $is_index == 1 )
  123. {
  124. $where .= " and g.is_index_show = 1 ";
  125. $per_page = 20;
  126. }
  127. if( !empty($head_id) && $head_id >0 )
  128. {
  129. $params = array();
  130. $params['uniacid'] = $_W['uniacid'];
  131. $params['head_id'] = $head_id;
  132. if($gid == 0){
  133. $goods_ids_arr = M()->query('SELECT goods_id FROM ' .C('DB_PREFIX'). "lionfish_community_head_goods
  134. WHERE head_id={$head_id} order by id desc ");
  135. } else {
  136. $sql_goods_ids = "select pg.goods_id from ".C('DB_PREFIX')."lionfish_community_head_goods as pg, "
  137. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g
  138. where pg.goods_id = g.goods_id and g.cate_id in ({$gid}) and pg.head_id = {$head_id} order by pg.id desc ";
  139. $goods_ids_arr = M()->query($sql_goods_ids);
  140. }
  141. $ids_arr = array();
  142. foreach($goods_ids_arr as $val){
  143. $ids_arr[] = $val['goods_id'];
  144. }
  145. if(!empty($keyword)) {
  146. $goods_ids_nolimit_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX') . "lionfish_comshop_goods
  147. WHERE is_all_sale=1 and goodsname like '%{$keyword}%' " );
  148. } else {
  149. if($gid == 0){
  150. $goods_ids_nolimit_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods
  151. WHERE is_all_sale=1 " );
  152. } else {
  153. $goods_ids_nolimit_sql = "select pg.id from ".C('DB_PREFIX')."lionfish_comshop_goods as pg,"
  154. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g
  155. where pg.id = g.goods_id and g.cate_id in ({$gid}) and pg.is_all_sale=1 ";
  156. $goods_ids_nolimit_arr = M()->query($goods_ids_nolimit_sql);
  157. }
  158. }
  159. if( !empty($goods_ids_nolimit_arr) )
  160. {
  161. foreach($goods_ids_nolimit_arr as $val){
  162. $ids_arr[] = $val['id'];
  163. }
  164. }
  165. $ids_str = implode(',',$ids_arr);
  166. if( !empty($ids_str) )
  167. {
  168. $where .= " and g.id in ({$ids_str})";
  169. } else{
  170. $where .= " and 0 ";
  171. }
  172. }else{
  173. if($gid > 0){
  174. $goods_ids_nohead_sql = "select pg.id from ".C('DB_PREFIX')."lionfish_comshop_goods as pg,"
  175. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g where pg.id = g.goods_id and g.cate_id in ({$gid}) ";
  176. $goods_ids_nohead_arr = M()->query($goods_ids_nohead_sql);
  177. }
  178. $ids_arr = array();
  179. if( !empty($goods_ids_nohead_arr) )
  180. {
  181. foreach($goods_ids_nohead_arr as $val){
  182. $ids_arr[] = $val['id'];
  183. }
  184. }
  185. $ids_str = implode(',',$ids_arr);
  186. if( !empty($ids_str) )
  187. {
  188. $where .= " and g.id in ({$ids_str})";
  189. }
  190. }
  191. if($gid == 0 && $keyword == ''){
  192. $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  193. } else {
  194. $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  195. }
  196. $where .= " and gc.is_new_buy=0 and gc.is_spike_buy = 0 ";
  197. if($is_random == 1)
  198. {
  199. $community_goods = D('Home/Pingoods')->get_community_index_goods('g.*,gc.begin_time,gc.end_time,gc.big_img,gc.is_take_fullreduction,gc.labelname,gc.video ', $where,$offset,$per_page,' rand() ');
  200. }else{
  201. $community_goods = D('Home/Pingoods')->get_community_index_goods('g.*,gc.begin_time,gc.end_time,gc.big_img,gc.is_take_fullreduction,gc.labelname,gc.video ', $where,$offset,$per_page);
  202. }
  203. if( !empty($community_goods) )
  204. {
  205. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  206. $full_money = D('Home/Front')->get_config_by_name('full_money');
  207. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  208. $is_open_fullreduction = 0;
  209. $cart= D('Home/Car');
  210. $list = array();
  211. $copy_text_arr = array();
  212. foreach($community_goods as $val)
  213. {
  214. $tmp_data = array();
  215. $tmp_data['actId'] = $val['id'];
  216. $tmp_data['spuName'] = $val['goodsname'];
  217. $tmp_data['spuCanBuyNum'] = $val['total'];
  218. $tmp_data['spuDescribe'] = $val['subtitle'];
  219. $tmp_data['end_time'] = $val['end_time'];
  220. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  221. $productprice = $val['productprice'];
  222. $tmp_data['marketPrice'] = explode('.', $productprice);
  223. if( !empty($val['big_img']) )
  224. {
  225. $tmp_data['bigImg'] = tomedia($val['big_img']);
  226. }
  227. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  228. if( !empty($good_image) )
  229. {
  230. $tmp_data['skuImage'] = tomedia($good_image['image']);
  231. }
  232. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'], $member_id);
  233. $price = $price_arr['price'];
  234. if( $pageNum == 1 )
  235. {
  236. $copy_text_arr[] = array('goods_name' => $val['goodsname'], 'price' => $price);
  237. }
  238. $tmp_data['actPrice'] = explode('.', $price);
  239. $tmp_data['danPrice'] = $price_arr['danprice'];
  240. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  241. if( !empty($tmp_data['skuList']) )
  242. {
  243. $tmp_data['car_count'] = 0;
  244. }else{
  245. $car_count = 0;
  246. if( empty($car_count) )
  247. {
  248. $tmp_data['car_count'] = 0;
  249. }else{
  250. $tmp_data['car_count'] = $car_count;
  251. }
  252. }
  253. if($is_open_fullreduction == 0)
  254. {
  255. $tmp_data['is_take_fullreduction'] = 0;
  256. }else if($is_open_fullreduction == 1){
  257. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  258. }
  259. // 商品角标
  260. $label_id = unserialize($val['labelname']);
  261. if($label_id){
  262. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  263. if($label_info){
  264. if($label_info['type'] == 1){
  265. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  266. } else {
  267. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  268. }
  269. }
  270. $tmp_data['label_info'] = $label_info;
  271. }
  272. $tmp_data['is_video'] = empty($val['video']) ? false : true;
  273. //根据商品信息查询拼团信息 $val['id'];
  274. $good_pin_list = M('lionfish_comshop_good_pin')->where( array('goods_id' => $val['id'] ) )->find();
  275. //拼团价格
  276. //$tmp_data['pinprice'] = $price ;
  277. //拼团人数
  278. $tmp_data['pin_count'] =$good_pin_list['pin_count'];
  279. //拼团时间
  280. $tmp_data['pin_hour'] =$good_pin_list['pin_hour'];
  281. //拼团开始时间
  282. $tmp_data['pin_begin_time'] =$good_pin_list['begin_time'];
  283. //拼团结束时间
  284. $tmp_data['pin_end_time'] =$good_pin_list['end_time'];
  285. $list[] = $tmp_data;
  286. }
  287. $is_show_list_timer = D('Home/Front')->get_config_by_name('is_show_list_timer');
  288. $pintuan_index_coming_img = D('Home/Front')->get_config_by_name('pintuan_index_coming_img');
  289. $pintuan_index_show = D('Home/Front')->get_config_by_name('pintuan_index_show');
  290. if( !isset($pintuan_index_show) )
  291. {
  292. $pintuan_index_show = 0;
  293. }
  294. $pintuan_index_show_listtop = D('Home/Front')->get_config_by_name('pintuan_index_show_listtop');
  295. if( !isset($pintuan_index_show_listtop) )
  296. {
  297. $pintuan_index_show_listtop = 0;
  298. }
  299. if( isset($pintuan_index_coming_img) && !empty($pintuan_index_coming_img) )
  300. {
  301. $pintuan_index_coming_img = tomedia($pintuan_index_coming_img);
  302. }
  303. $pintuan_show_type = D('Home/Front')->get_config_by_name('pintuan_show_type');
  304. //pintuan_index_coming_img
  305. echo json_encode(array('code' => 0,'pintuan_model_buy' => $pintuan_model_buy,'pintuan_index_show' => $pintuan_index_show,'pintuan_index_coming_img' => $pintuan_index_coming_img, 'list' => $list ,'copy_text_arr' => $copy_text_arr, 'cur_time' => time() ,'full_reducemoney' => $full_reducemoney,'full_money' => $full_money,'is_open_fullreduction' => $is_open_fullreduction,'is_show_list_timer'=>$is_show_list_timer , 'pintuan_index_show_listtop'=>$pintuan_index_show_listtop, 'pintuan_show_type'=>$pintuan_show_type ));
  306. die();
  307. }else{
  308. echo json_encode( array('code' => 1) );
  309. die();
  310. }
  311. }
  312. //猜你喜欢
  313. public function pintuan_like_list()
  314. {
  315. $_GPC = I('request.');
  316. //猜你喜欢开关
  317. $is_show_order_guess_like= D('Home/Front')->get_config_by_name('is_open_pipntuan_like' );
  318. if( empty($is_show_order_guess_like) )
  319. {
  320. $is_show_order_guess_like = 0;
  321. }
  322. $community_id = $_GPC['community_id'];
  323. //community_id
  324. //购买的商品id
  325. $order_list = M('lionfish_comshop_order_goods')->field('goods_id')->where( array('order_id' =>$_GPC["order_id"] ) )->find();
  326. $now_time = time();
  327. $pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
  328. if( empty($pintuan_model_buy) )
  329. {
  330. $pintuan_model_buy = 1;
  331. }
  332. if(!empty($community_id) && $pintuan_model_buy == 1){
  333. //有社区
  334. $head_info = M('lionfish_community_head')->field('id')->where( array('id' => $community_id ) )->find();
  335. //团长商品和全部可售
  336. //lionfish_community_head_goods
  337. $head_goods = M('lionfish_community_head_goods')->field('goods_id')->where( array('head_id' => $head_info['id'] ) )->select();
  338. foreach ($head_goods as $hg) {
  339. $hg = join(",",$hg);
  340. $temp_array[] = $hg;
  341. }
  342. $all_goods = M('lionfish_comshop_goods')->field('id')->where( array('type' => 'pin', 'is_all_sale' => 1) )->select();
  343. if( !empty($all_goods) )
  344. {
  345. foreach( $all_goods as $vv )
  346. {
  347. $temp_array[] = $vv['id'];
  348. }
  349. }
  350. //团长商品id
  351. $goods_id_list = implode(",", $temp_array);
  352. $sql_likegoods = "select g.*,gc.end_time,gc.begin_time from ".C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc
  353. where g.id = gc.goods_id and gc.begin_time <={$now_time} and gc.end_time > {$now_time} and g.grounding =1 and ( g.id in (".$goods_id_list.") and g.id <> ".$order_list['goods_id']." ) and g.type = 'pin' order by rand() limit 6";
  354. }else{
  355. //猜你喜欢 随机6条数据
  356. $sql_likegoods = "select g.*,gc.end_time,gc.begin_time from ".C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc
  357. where gc.begin_time <={$now_time} and gc.end_time > {$now_time} and g.id=gc.goods_id and g.id <> ".$order_list['goods_id']." and g.grounding =1 and g.type = 'pin' order by rand() limit 6";
  358. }
  359. $likegoods_list = M()->query($sql_likegoods);
  360. $list = array();
  361. if( !empty($likegoods_list) )
  362. {
  363. foreach($likegoods_list as $val)
  364. {
  365. $tmp_data = array();
  366. $tmp_data['actId'] = $val['id'];
  367. $tmp_data['spuName'] = $val['goodsname'];
  368. $tmp_data['spuCanBuyNum'] = $val['total'];
  369. $tmp_data['spuDescribe'] = $val['subtitle'];
  370. $tmp_data['end_time'] = $val['end_time'];
  371. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  372. $productprice = $val['productprice'];
  373. $tmp_data['marketPrice'] = explode('.', $productprice);
  374. if( !empty($val['big_img']) )
  375. {
  376. $tmp_data['bigImg'] = tomedia($val['big_img']);
  377. }
  378. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  379. if( !empty($good_image) )
  380. {
  381. $tmp_data['skuImage'] = tomedia($good_image['image']);
  382. }
  383. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'], $member_id);
  384. $price = $price_arr['price'];
  385. if( $pageNum == 1 )
  386. {
  387. $copy_text_arr[] = array('goods_name' => $val['goodsname'], 'price' => $price);
  388. }
  389. $tmp_data['actPrice'] = explode('.', $price);
  390. $tmp_data['danPrice'] = $price_arr['danprice'];
  391. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  392. if( !empty($tmp_data['skuList']) )
  393. {
  394. $tmp_data['car_count'] = 0;
  395. }else{
  396. $car_count = 0;
  397. if( empty($car_count) )
  398. {
  399. $tmp_data['car_count'] = 0;
  400. }else{
  401. $tmp_data['car_count'] = $car_count;
  402. }
  403. }
  404. if($is_open_fullreduction == 0)
  405. {
  406. $tmp_data['is_take_fullreduction'] = 0;
  407. }else if($is_open_fullreduction == 1){
  408. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  409. }
  410. // 商品角标
  411. $label_id = unserialize($val['labelname']);
  412. if($label_id){
  413. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  414. if($label_info){
  415. if($label_info['type'] == 1){
  416. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  417. } else {
  418. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  419. }
  420. }
  421. $tmp_data['label_info'] = $label_info;
  422. }
  423. $tmp_data['is_video'] = empty($val['video']) ? false : true;
  424. //根据商品信息查询拼团信息
  425. $good_pin_list = M('lionfish_comshop_good_pin')->where( array('goods_id' => $val['id'] ) )->find();
  426. //拼团价格
  427. //拼团人数
  428. $tmp_data['pin_count'] =$good_pin_list['pin_count'];
  429. //拼团时间
  430. $tmp_data['pin_hour'] =$good_pin_list['pin_hour'];
  431. //拼团开始时间
  432. $tmp_data['pin_begin_time'] =$good_pin_list['begin_time'];
  433. //拼团结束时间
  434. $tmp_data['pin_end_time'] =$good_pin_list['end_time'];
  435. $list[] = $tmp_data;
  436. }
  437. }
  438. echo json_encode(array('code'=>0,
  439. 'is_show_order_guess_like' => $is_show_order_guess_like,
  440. 'list' => $list,
  441. )
  442. );
  443. die();
  444. }
  445. }