PopadvController.class.php 3.5 KB

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