MarketingController.class.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Home\Controller;
  10. class MarketingController extends CommonController {
  11. public function get_special()
  12. {
  13. $_GPC = I('request.');
  14. $token = $_GPC['token'];
  15. $id = $_GPC['id'];
  16. $head_id = $_GPC['head_id'];
  17. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  18. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  19. {
  20. //echo json_encode( array('code' => 2,'msg' =>'请先登录') );
  21. //die();
  22. }
  23. $member_id = $weprogram_token['member_id'];
  24. $data = M('lionfish_comshop_special')->where( array('id' => $id ) )->find();
  25. $goodsids = $data['goodsids'];
  26. $list = array();
  27. if(!empty($data)) {
  28. if($data['enabled']==0){
  29. echo json_encode( array('code' => 1, 'msg' => '专题已关闭') );
  30. die();
  31. }
  32. if($data['begin_time'] > time()){
  33. echo json_encode( array('code' => 1, 'msg' => '活动未开始') );
  34. die();
  35. }
  36. if($data['end_time'] <= time()){
  37. echo json_encode( array('code' => 1, 'msg' => '活动已结束') );
  38. die();
  39. }
  40. if( !empty($data['cover']) ) $data['cover'] = tomedia($data['cover']);
  41. if( !empty($data['special_cover']) ) $data['special_cover'] = tomedia($data['special_cover']);
  42. // 满减
  43. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  44. $full_money = D('Home/Front')->get_config_by_name('full_money');
  45. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  46. if(empty($full_reducemoney) || $full_reducemoney <= 0) $is_open_fullreduction = 0;
  47. if($goodsids) {
  48. $goodsids = rtrim($goodsids, ",");
  49. $now_time = time();
  50. $where = ' g.grounding = 1 ';
  51. $where .= " and g.id in ({$goodsids})";
  52. //$where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  53. $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 ', $where, 0, 1000);
  54. foreach ($community_goods as $key => $value) {
  55. if($value['is_all_sale']==1){
  56. $list[] = $this->change_goods_form($value, $head_id, $token, $is_open_fullreduction);
  57. } else {
  58. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('head_id' => $head_id,'goods_id' => $value['id'] ) )->order('id desc')->select();
  59. if(!empty($is_head_shop)) $list[] = $this->change_goods_form($value, $head_id, $token , $is_open_fullreduction);
  60. }
  61. }
  62. }
  63. } else {
  64. echo json_encode( array('code' => 1, 'msg' => '无此专题') );
  65. die();
  66. }
  67. $ishow_special_share_btn = D('Home/Front')->get_config_by_name('ishow_special_share_btn');
  68. echo json_encode( array(
  69. 'code' => 0,
  70. 'data' => $data,
  71. 'list' => $list,
  72. 'ishow_special_share_btn' => $ishow_special_share_btn,
  73. 'full_reducemoney' => $full_reducemoney,
  74. 'full_money' => $full_money,
  75. 'is_open_fullreduction' => $is_open_fullreduction
  76. ));
  77. die();
  78. }
  79. private function change_goods_form ($val, $head_id='', $token='' , $is_open_fullreduction=0){
  80. $_GPC = I('request.');
  81. $tmp_data = array();
  82. $tmp_data['actId'] = $val['id'];
  83. $goodsname = htmlspecialchars_decode($val['goodsname']);
  84. $tmp_data['spuName'] = $goodsname;
  85. $tmp_data['spuCanBuyNum'] = $val['total'];
  86. $tmp_data['spuDescribe'] = $val['subtitle'];
  87. $tmp_data['end_time'] = $val['end_time'];
  88. $tmp_data['soldNum'] = $val['seller_count'] + $val['sales'];
  89. $productprice = $val['productprice'];
  90. $tmp_data['marketPrice'] = explode('.', $productprice);
  91. $time = time();
  92. $tmp_data['actEnd'] = time()>$val['end_time'] ? true : false;
  93. if( !empty($val['big_img']) )
  94. {
  95. $tmp_data['bigImg'] = tomedia($val['big_img']);
  96. }
  97. $good_image = D('Home/Pingoods')->get_goods_images($val['id']);
  98. if( !empty($good_image) )
  99. {
  100. $tmp_data['skuImage'] = tomedia($good_image['image']);
  101. }
  102. $token = $_GPC['token'];
  103. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  104. $member_id = $weprogram_token['member_id'];
  105. $price_arr = D('Home/Pingoods')->get_goods_price($val['id'], $member_id);
  106. $price = $price_arr['price'];
  107. $tmp_data['actPrice'] = explode('.', $price);
  108. $tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'],$member_id);
  109. if( !empty($tmp_data['skuList']) )
  110. {
  111. $tmp_data['car_count'] = 0;
  112. }else{
  113. $car_count = D('Home/Car')->get_wecart_goods($val['id'],"",$head_id ,$token);
  114. if( empty($car_count) )
  115. {
  116. $tmp_data['car_count'] = 0;
  117. }else{
  118. $tmp_data['car_count'] = $car_count;
  119. }
  120. }
  121. if($is_open_fullreduction == 0)
  122. {
  123. $tmp_data['is_take_fullreduction'] = 0;
  124. }else if($is_open_fullreduction == 1){
  125. $tmp_data['is_take_fullreduction'] = $val['is_take_fullreduction'];
  126. }
  127. // 商品角标
  128. $label_id = unserialize($val['labelname']);
  129. if($label_id){
  130. $label_info = D('Home/Pingoods')->get_goods_tags($label_id);
  131. if($label_info){
  132. if($label_info['type'] == 1){
  133. $label_info['tagcontent'] = tomedia($label_info['tagcontent']);
  134. } else {
  135. $label_info['len'] = mb_strlen($label_info['tagcontent'], 'utf-8');
  136. }
  137. }
  138. $tmp_data['label_info'] = $label_info;
  139. }
  140. return $tmp_data;
  141. }
  142. public function get_special_list()
  143. {
  144. $_GPC = I('request.');
  145. $head_id = $_GPC['head_id'];
  146. $token = $_GPC['token'];
  147. $id = $_GPC['id'];
  148. // $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  149. // if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  150. // {
  151. // //echo json_encode( array('code' => 2,'msg' =>'请先登录') );
  152. // //die();
  153. // }
  154. if($id) {
  155. $condition = " id=".$id;
  156. } else {
  157. $now_time = time();
  158. $condition = 'enabled = 1 and is_index = 1 and begin_time<='.$now_time.' and end_time>'.$now_time;
  159. }
  160. $special_list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special WHERE '.$condition.' order by displayorder desc ');
  161. if(!empty($special_list)) {
  162. foreach ($special_list as &$data) {
  163. $list = array();
  164. $goodsids = $data['goodsids'];
  165. if( !empty($data['cover']) ) $data['cover'] = tomedia($data['cover']);
  166. if( !empty($data['special_cover']) ) $data['special_cover'] = tomedia($data['special_cover']);
  167. if($goodsids && $data['type']==1) {
  168. $where = ' g.grounding = 1 ';
  169. $where .= " and g.id in ({$goodsids})";
  170. //$where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  171. $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 ', $where, 0, 1000);
  172. foreach ($community_goods as $key => $value) {
  173. if($value['is_all_sale']==1){
  174. $list[] = $this->change_goods_form($value);
  175. } else {
  176. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('goods_id' => $value['id'],'head_id' => $head_id ) )->order('id desc')->select();
  177. if(!empty($is_head_shop)) $list[] = $this->change_goods_form($value);
  178. }
  179. }
  180. }
  181. $data['list'] = $list;
  182. }
  183. } else {
  184. echo json_encode( array('code' => 1, 'msg' => '无专题') );
  185. die();
  186. }
  187. echo json_encode( array('code' => 0, 'data' => $special_list ) );
  188. die();
  189. }
  190. /**
  191. * 专题列表
  192. * @return @return [json] [list]
  193. */
  194. public function get_special_page_list()
  195. {
  196. $_GPC = I('request.');
  197. $head_id = $_GPC['head_id'];
  198. $page = isset($_GPC['page']) ? $_GPC['page']:'1';
  199. $pre_page = 10;
  200. $offset = ($page -1) * $pre_page;
  201. $token = $_GPC['token'];
  202. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  203. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  204. {
  205. //echo json_encode( array('code' => 2,'msg' =>'请先登录') );
  206. //die();
  207. }
  208. $now_time = time();
  209. $condition = 'enabled = 1 and begin_time<='.$now_time.' and end_time>'.$now_time;
  210. $special_list = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_special WHERE '.$condition." order by displayorder desc limit {$offset},{$pre_page} ");
  211. if(!empty($special_list)) {
  212. foreach ($special_list as &$data) {
  213. $list = array();
  214. $goodsids = $data['goodsids'];
  215. if( !empty($data['cover']) ) $data['cover'] = tomedia($data['cover']);
  216. if( !empty($data['special_cover']) ) $data['special_cover'] = tomedia($data['special_cover']);
  217. if($goodsids) {
  218. $where = ' g.grounding = 1 ';
  219. $where .= " and g.id in ({$goodsids})";
  220. //$where .= " and gc.begin_time <={$now_time} and gc.end_time > {$now_time} ";
  221. $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 ', $where, 0, 1000);
  222. foreach ($community_goods as $key => $value) {
  223. if($value['is_all_sale']==1){
  224. $list[] = $this->change_goods_form($value);
  225. } else {
  226. $is_head_shop = M('lionfish_community_head_goods')->field('id')->where( array('head_id' => $head_id, 'goods_id' => $value['id']) )->order('id desc')->select();
  227. if(!empty($is_head_shop)) $list[] = $this->change_goods_form($value);
  228. }
  229. }
  230. }
  231. $data['list'] = $list;
  232. }
  233. } else {
  234. echo json_encode( array('code' => 1, 'msg' => '无专题') );
  235. die();
  236. }
  237. echo json_encode( array('code' => 0, 'data' => $special_list ) );
  238. die();
  239. }
  240. }