PopadvController.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 fld
  12. *
  13. */
  14. namespace Home\Controller;
  15. class PopadvController extends CommonController{
  16. /**
  17. * 弹窗广告数据
  18. * 需要参数:
  19. * 1、token 会员token,
  20. * 2、pop_page 投放页面类型:0、商城首页,1、商品分类,2、商城购物车,3、商城个人中心
  21. *
  22. * 1、时间判断,2、投放对象判断,3、
  23. */
  24. public function popadv_list()
  25. {
  26. $popadvs = array();
  27. $_GPC = I('request.');
  28. //获取用户编号信息
  29. $token = $_GPC['token'];
  30. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  31. $member_id = $weprogram_token['member_id'];
  32. //投放页面
  33. $pop_page = $_GPC['pop_page'];
  34. $pop_list = D('Seller/Redisorder')->get_popadv_list();
  35. $now = time();
  36. if(empty($pop_list)){
  37. $pop_info = M('lionfish_comshop_pop_adv')->where(" begin_time <= ".$now." and end_time >= ".$now." and status = 1 and pop_page=".$pop_page)->find();
  38. if($pop_info['send_person'] == 1){//指定用户发送
  39. if(strpos($pop_info['member_id'],$member_id.',') !== false){
  40. $popadvs = $pop_info;
  41. }
  42. }else if($pop_info['send_person'] == 2){//用户组发送
  43. if(!empty($pop_info['member_group_id'])){
  44. $member_info = M('lionfish_comshop_member')->where(array('groupid'=>$pop_info['member_group_id'],'member_id'=>$member_id))->find();
  45. if(!empty($member_info)){
  46. $popadvs = $pop_info;
  47. }
  48. }else{
  49. $popadvs = $pop_info;
  50. }
  51. }else{//全部发送
  52. $popadvs = $pop_info;
  53. }
  54. if(!empty($popadvs)){
  55. $adv_list = M('lionfish_comshop_pop_adv_list')->where(array('ad_id'=>$popadvs['id']))->select();
  56. if(!empty($adv_list)) {
  57. foreach($adv_list as $k=>$v){
  58. if($v['thumb']){
  59. $v['thumb'] = tomedia($v['thumb']);
  60. }
  61. $adv_list[$k] = $v;
  62. }
  63. }
  64. $popadvs['adv_list'] = $adv_list;
  65. }
  66. }else{
  67. foreach($pop_list as $k=>$v){
  68. //启用,投放页面,时间
  69. if($v['status'] == 1 && $v['pop_page'] == $pop_page && $v['begin_time'] <= $now && $now <= $v['end_time']){
  70. if($v['send_person'] == 1){//指定用户发送
  71. if(strpos($v['member_id'].',',$member_id.',') !== false){
  72. $popadvs = $v;
  73. }
  74. }else if($v['send_person'] == 2){//用户组发送
  75. if(!empty($v['member_group_id'])){
  76. $member_info = M('lionfish_comshop_member')->where(array('groupid'=>$v['member_group_id'],'member_id'=>$member_id))->find();
  77. if(!empty($member_info)){
  78. $popadvs = $v;
  79. }
  80. }
  81. }else{//全部发送
  82. $popadvs = $v;
  83. }
  84. }
  85. }
  86. }
  87. if(!empty($popadvs)){
  88. //判断弹窗广告是否还要再出现
  89. $is_show = D('Seller/Redisorder')->check_pop_advs($popadvs,$member_id,$pop_page);
  90. if($is_show == 0){
  91. $popadvs = array();
  92. }
  93. }
  94. if(!empty($popadvs)){
  95. $view_num = $popadvs['view_num']+1;
  96. M('lionfish_comshop_pop_adv')->where(array('id'=>$popadvs['id']))->save(array('view_num'=>$view_num));
  97. }
  98. $result = array('popadvs' =>$popadvs);
  99. echo json_encode($result);
  100. die();
  101. }
  102. //弹窗广告次数累加
  103. /**
  104. * 参数 弹窗广告编号 id
  105. */
  106. public function popadv_click(){
  107. $_GPC = I('request.');
  108. $id = $_GPC['id'];
  109. if(!empty($id)){
  110. $pop_info = M('lionfish_comshop_pop_adv')->where(array('id'=>$id))->field('open_num')->find();
  111. $open_num = $pop_info['open_num']+1;
  112. M('lionfish_comshop_pop_adv')->where(array('id'=>$id))->save(array('open_num'=>$open_num));
  113. }
  114. echo json_encode(array('code'=>0));
  115. die();
  116. }
  117. }