ScekillController.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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 ScekillController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. public function get_scekill_info()
  21. {
  22. //秒杀设置begin
  23. $seckill_is_open = D('Home/Front')->get_config_by_name('seckill_is_open');
  24. $seckill_is_show_index = D('Home/Front')->get_config_by_name('seckill_is_show_index');
  25. $scekill_show_time = D('Home/Front')->get_config_by_name('scekill_show_time');
  26. if( empty($seckill_is_open) )
  27. {
  28. $seckill_is_open = 0;
  29. }
  30. if( empty($seckill_is_show_index) )
  31. {
  32. $seckill_is_show_index = 0;
  33. }
  34. $scekill_time_arr = array();
  35. if( isset($scekill_show_time) && !empty($scekill_show_time) )
  36. {
  37. $scekill_show_time_arr = unserialize($scekill_show_time);
  38. foreach($scekill_show_time_arr as $vv)
  39. {
  40. if( $vv != 25 )
  41. {
  42. $scekill_time_arr[] = $vv;
  43. }
  44. }
  45. }
  46. //秒杀主页标题
  47. $seckill_page_title = D('Home/Front')->get_config_by_name('seckill_page_title');
  48. if( empty($seckill_page_title) )
  49. {
  50. $seckill_page_title = '商品秒杀';
  51. }
  52. //首页秒杀活动背景色
  53. $seckill_bg_color = D('Home/Front')->get_config_by_name('seckill_bg_color');
  54. //秒杀活动分享标题
  55. $seckill_share_title = D('Home/Front')->get_config_by_name('seckill_share_title');
  56. $seckill_share_image = D('Home/Front')->get_config_by_name('seckill_share_image');
  57. if( !empty($seckill_share_image) )
  58. {
  59. $seckill_share_image = tomedia( $seckill_share_image );
  60. }
  61. //是否显示tabbar
  62. $showTabbar = false;
  63. $tabbar_out_type = D('Home/Front')->get_config_by_name('tabbar_out_type');
  64. $tabbar_out_link = D('Home/Front')->get_config_by_name('tabbar_out_link');
  65. if($tabbar_out_type==1 && $tabbar_out_link == '/lionfish_comshop/moduleA/seckill/list') $showTabbar = true;
  66. //整点秒杀结束
  67. $need_data = array();
  68. $need_data['seckill_is_open'] = $seckill_is_open;
  69. $need_data['seckill_is_show_index'] = $seckill_is_show_index;
  70. $need_data['scekill_time_arr'] = $scekill_time_arr;
  71. $need_data['seckill_page_title'] = $seckill_page_title;
  72. $need_data['seckill_bg_color'] = $seckill_bg_color;
  73. $need_data['seckill_share_title'] = $seckill_share_title;
  74. $need_data['seckill_share_image'] = $seckill_share_image;
  75. $need_data['showTabbar'] = $showTabbar;
  76. echo json_encode( array('code' => 0 ,'data' => $need_data ) );
  77. die();
  78. }
  79. public function load_gps_goodslist()
  80. {
  81. $_GPC = I('request.');
  82. $head_id = $_GPC['head_id'];
  83. if($head_id == 'undefined') $head_id = '';
  84. $pageNum = $_GPC['pageNum'];
  85. $gid = $_GPC['gid'];
  86. $keyword = $_GPC['keyword'];
  87. $is_random = isset($_GPC['is_random']) ? $_GPC['is_random'] : 0;
  88. $per_page = isset($_GPC['per_page']) ? $_GPC['per_page'] : 10;
  89. $cate_info = '';
  90. if($gid == 'undefined' || $gid =='')
  91. {
  92. $gid = 0;
  93. } else {
  94. $cate_info = M('lionfish_comshop_goods_category')->field('banner,name')->where( array('id' => $gid ) )->find();
  95. if(!empty($cate_info['banner'])) $cate_info['banner'] = tomedia($cate_info['banner']);
  96. }
  97. if(!$keyword){
  98. $gids = D('Home/GoodsCategory')->get_index_goods_category($gid);
  99. $gidArr = array();
  100. $gidArr[] = $gid;
  101. foreach ($gids as $key => $val) {
  102. $gidArr[] = $val['id'];
  103. }
  104. $gid = implode(',', $gidArr);
  105. }
  106. $offset = ($pageNum - 1) * $per_page;
  107. $limit = "{$offset},{$per_page}";
  108. $token = $_GPC['token'];
  109. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token ) )->find();
  110. $is_member_level_buy = 0;
  111. $is_vip_card_member = 0;
  112. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  113. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
  114. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  115. {
  116. // echo json_encode( array('code' => 2) );
  117. // die();
  118. }else{
  119. $member_id = $weprogram_token['member_id'];
  120. //member_id
  121. if( $member_id > 0 )
  122. {
  123. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  124. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  125. {
  126. $now_time = time();
  127. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  128. {
  129. $is_vip_card_member = 1;//还是会员
  130. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  131. $is_vip_card_member = 2;//已过期
  132. }
  133. }
  134. if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
  135. {
  136. $is_member_level_buy = 1;
  137. }
  138. }
  139. }
  140. $now_time = time();
  141. $where = " g.grounding =1 and g.type ='normal' ";
  142. //head_id
  143. if( !empty($head_id) && $head_id >0 )
  144. {
  145. if(!empty($keyword)) {
  146. $sql_goods_ids = "select pg.goods_id from ".C('DB_PREFIX')."lionfish_community_head_goods as pg,"
  147. .C('DB_PREFIX')."lionfish_comshop_goods as g
  148. where pg.goods_id = g.id and g.goodsname like '%{$keyword}%' and pg.head_id = {$head_id} order by pg.id desc ";
  149. $goods_ids_arr = M()->query($sql_goods_ids);
  150. } else {
  151. if($gid == 0){
  152. $goods_ids_arr = M()->query('SELECT goods_id FROM ' . C('DB_PREFIX'). "lionfish_community_head_goods
  153. WHERE head_id=".$head_id." order by id desc " );
  154. } else {
  155. $sql_goods_ids = "select pg.goods_id from ".C('DB_PREFIX')."lionfish_community_head_goods as pg,"
  156. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g
  157. where pg.goods_id = g.goods_id and g.cate_id in ({$gid}) and pg.head_id = {$head_id} order by pg.id desc ";
  158. $goods_ids_arr = M()->query($sql_goods_ids);
  159. }
  160. }
  161. $ids_arr = array();
  162. foreach($goods_ids_arr as $val){
  163. $ids_arr[] = $val['goods_id'];
  164. }
  165. if(!empty($keyword)) {
  166. $goods_ids_nolimit_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods
  167. WHERE is_all_sale=1 and goodsname like '%{$keyword}%' " );
  168. } else {
  169. if($gid == 0){
  170. $goods_ids_nolimit_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX') . "lionfish_comshop_goods
  171. WHERE is_all_sale=1 " );
  172. } else {
  173. $goods_ids_nolimit_sql = "select pg.id from ".C('DB_PREFIX')."lionfish_comshop_goods as pg,"
  174. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g
  175. where pg.id = g.goods_id and g.cate_id in ({$gid}) and pg.is_all_sale=1 ";
  176. $goods_ids_nolimit_arr = M()->query($goods_ids_nolimit_sql);
  177. }
  178. }
  179. if( !empty($goods_ids_nolimit_arr) )
  180. {
  181. foreach($goods_ids_nolimit_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. } else{
  190. $where .= " and 0 ";
  191. }
  192. }else{
  193. //echo json_encode( array('code' => 1) );
  194. // die();
  195. if(!empty($keyword)) {
  196. $goods_ids_nolimit_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods
  197. WHERE goodsname like '%{$keyword}%' and type='normal' " );
  198. } else {
  199. if($gid == 0){
  200. $goods_ids_nohead_arr = M()->query('SELECT id FROM ' . C('DB_PREFIX'). "lionfish_comshop_goods
  201. WHERE type='normal' " );
  202. } else {
  203. $goods_ids_nohead_sql = "select pg.id from ".C('DB_PREFIX')."lionfish_comshop_goods as pg,"
  204. .C('DB_PREFIX')."lionfish_comshop_goods_to_category as g where pg.id = g.goods_id and g.cate_id in ({$gid}) and type='normal' ";
  205. $goods_ids_nohead_arr = M()->query($goods_ids_nohead_sql);
  206. }
  207. }
  208. $ids_arr = array();
  209. if( !empty($goods_ids_nohead_arr) )
  210. {
  211. foreach($goods_ids_nohead_arr as $val){
  212. $ids_arr[] = $val['id'];
  213. }
  214. }
  215. $ids_str = implode(',',$ids_arr);
  216. if( !empty($ids_str) )
  217. {
  218. $where .= " and g.id in ({$ids_str})";
  219. } else{
  220. $where .= " and 0 ";
  221. }
  222. }
  223. if($gid == 0 && $keyword == ''){
  224. $where .= " and g.is_index_show = 1 and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  225. // $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  226. } else {
  227. $where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  228. }
  229. $where .= " and gc.is_new_buy=0 and gc.is_spike_buy = 0 ";
  230. //$is_random $order='g.istop DESC, g.settoptime DESC,g.index_sort desc,g.id desc '
  231. if($is_random == 1)
  232. {
  233. $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() ');
  234. }else{
  235. $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);
  236. }
  237. if( !empty($community_goods) )
  238. {
  239. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  240. $full_money = D('Home/Front')->get_config_by_name('full_money');
  241. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  242. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  243. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 ? 1:0;
  244. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  245. {
  246. $is_open_fullreduction = 0;
  247. }
  248. $cart= D('Home/Car');
  249. $list = array();
  250. $copy_text_arr = array();
  251. foreach($community_goods as $val)
  252. {
  253. $tmp_data = array();
  254. $tmp_data['actId'] = $val['id'];
  255. $tmp_data['spuName'] = $val['goodsname'];
  256. $tmp_data['spuCanBuyNum'] = $val['total'];
  257. $tmp_data['spuDescribe'] = $val['subtitle'];
  258. $tmp_data['end_time'] = $val['end_time'];
  259. $tmp_data['is_take_vipcard'] = $val['is_take_vipcard'];
  260. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  261. $productprice = $val['productprice'];
  262. $tmp_data['marketPrice'] = explode('.', $productprice);
  263. if( !empty($val['big_img']) )
  264. {
  265. $tmp_data['bigImg'] = tomedia($val['big_img']);
  266. }
  267. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  268. if( !empty($good_image) )
  269. {
  270. $tmp_data['skuImage'] = tomedia($good_image['image']);
  271. }
  272. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'], $member_id);
  273. $price = $price_arr['price'];
  274. if( $pageNum == 1 )
  275. {
  276. $copy_text_arr[] = array('goods_name' => $val['goodsname'], 'price' => $price);
  277. }
  278. $tmp_data['actPrice'] = explode('.', $price);
  279. $tmp_data['card_price'] = $price_arr['card_price'];
  280. $tmp_data['levelprice'] = $price_arr['levelprice']; // 会员等级价格
  281. $tmp_data['is_mb_level_buy'] = $price_arr['is_mb_level_buy']; //是否 会员等级 可享受
  282. //card_price
  283. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  284. if( !empty($tmp_data['skuList']) )
  285. {
  286. $tmp_data['car_count'] = 0;
  287. }else{
  288. $car_count = $cart->get_wecart_goods($val['id'],"",$head_id ,$token);
  289. if( empty($car_count) )
  290. {
  291. $tmp_data['car_count'] = 0;
  292. }else{
  293. $tmp_data['car_count'] = $car_count;
  294. }
  295. }
  296. if($is_open_fullreduction == 0)
  297. {
  298. $tmp_data['is_take_fullreduction'] = 0;
  299. }else if($is_open_fullreduction == 1){
  300. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  301. }
  302. // 商品角标
  303. $label_id = unserialize($val['labelname']);
  304. if($label_id){
  305. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  306. if($label_info){
  307. if($label_info['type'] == 1){
  308. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  309. } else {
  310. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  311. }
  312. }
  313. $tmp_data['label_info'] = $label_info;
  314. }
  315. $tmp_data['is_video'] = empty($val['video']) ? false : true;
  316. $list[] = $tmp_data;
  317. }
  318. $is_show_list_timer = D('Home/Front')->get_config_by_name('is_show_list_timer');
  319. $is_show_cate_tabbar = D('Home/Front')->get_config_by_name('is_show_cate_tabbar');
  320. echo json_encode(array('code' => 0, 'list' => $list ,'is_vip_card_member' => $is_vip_card_member,'is_member_level_buy' => $is_member_level_buy ,'copy_text_arr' => $copy_text_arr, 'cur_time' => time() ,'full_reducemoney' => $full_reducemoney,'full_money' => $full_money,'is_open_vipcard_buy' => $is_open_vipcard_buy,'is_open_fullreduction' => $is_open_fullreduction,'is_show_list_timer'=>$is_show_list_timer, 'cate_info' => $cate_info, 'is_show_cate_tabbar'=>$is_show_cate_tabbar ));
  321. die();
  322. }else{
  323. $is_show_cate_tabbar = D('Home/Front')->get_config_by_name('is_show_cate_tabbar');
  324. echo json_encode( array('code' => 1, 'cate_info' => $cate_info, 'is_show_cate_tabbar'=>$is_show_cate_tabbar) );
  325. die();
  326. }
  327. }
  328. }