PopadvController.class.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. *
  6. * @author fld
  7. *
  8. */
  9. namespace Seller\Controller;
  10. class PopadvController extends CommonController{
  11. protected function _initialize(){
  12. parent::_initialize();
  13. $this->breadcrumb1='弹窗广告';
  14. $this->breadcrumb2='广告列表';
  15. $this->sellerid = SELLERUID;
  16. }
  17. /**
  18. * 弹窗广告列表
  19. */
  20. public function index()
  21. {
  22. $_GPC = I('request.');
  23. $this->gpc = $_GPC;
  24. $condition = ' 1 ';
  25. $pindex = max(1, intval($_GPC['page']));
  26. $psize = 20;
  27. $time = $_GPC['time'];
  28. if (!empty($_GPC['keyword'])) {
  29. $_GPC['keyword'] = trim($_GPC['keyword']);
  30. $condition .= ' and adv_name like "%'.$_GPC['keyword'].'%" ';
  31. }
  32. if (isset($_GPC['status']) && trim($_GPC['status']) != '') {
  33. $_GPC['status'] = trim($_GPC['status']);
  34. $condition .= ' and status = ' . $_GPC['status'];
  35. }
  36. if(!empty($time['start'])){
  37. /*$condition .= ' and ((begin_time <= ' . strtotime($time['start']). " and end_time >= ".strtotime($time['start'])." ) ";
  38. $condition .= ' or (begin_time <= ' . strtotime($time['end']). " and end_time >= ".strtotime($time['end'])." )) ";*/
  39. $condition .= " and begin_time <= ".strtotime($time['end'])." and end_time >=".strtotime($time['start'])." ";
  40. $this->starttime = strtotime($time['start']);
  41. $this->endtime = strtotime($time['end']);
  42. }else{
  43. $this->starttime = strtotime(date('Y-m-d').' 00:00');
  44. $this->endtime = strtotime(date('Y-m-d').' 23:59');
  45. }
  46. $label = M('lionfish_comshop_pop_adv')->where( $condition )->order(' sort_order desc ')->limit( (($pindex - 1) * $psize) . ',' . $psize )->select();
  47. $total = M('lionfish_comshop_pop_adv')->where( $condition )->count();
  48. $pager = pagination2($total, $pindex, $psize);
  49. $time = time();
  50. foreach($label as $k=>$v){
  51. if($v['begin_time'] >= $time){
  52. $label[$k]['adv_status'] = '未开始';
  53. }else if($v['begin_time'] < $time && $v['end_time'] >= $time){
  54. $label[$k]['adv_status'] = '正在进行中';
  55. }else if($v['end_time'] < $time){
  56. $label[$k]['adv_status'] = '已结束';
  57. }
  58. }
  59. $this->label = $label;
  60. $this->pager = $pager;
  61. $this->display("popadv_index");
  62. }
  63. /**
  64. * 添加弹窗广告
  65. */
  66. public function add_popadv(){
  67. $_GPC = I('request.');
  68. if (IS_POST) {
  69. $data = $_GPC['data'];
  70. $time = $_GPC['time'];
  71. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  72. if($open_redis_server != 1){
  73. show_json(0, array('message' => '请开启redis服务'));
  74. }
  75. if (empty($data['adv_name'])) {
  76. show_json(0, array('message' => '活动名称不能为空'));
  77. }
  78. $aid = $_GPC['aid'];
  79. $thumb = $_GPC['thumb'];
  80. for($i = 0;$i < count($aid);$i++){
  81. if(empty($thumb[$i])){
  82. show_json(0, array('message' => '广告'.$aid[$i].'图片不能为空'));
  83. }
  84. if(empty($data['link_'.$aid[$i]])){
  85. show_json(0, array('message' => '广告'.$aid[$i].'链接不能为空'));
  86. }
  87. }
  88. $begin_time = strtotime($time['start']);
  89. $end_time = strtotime($time['end']);
  90. $count = M('lionfish_comshop_pop_adv')->where(" begin_time <= ".$end_time." and end_time >=".$begin_time)->count();
  91. if($count > 0){
  92. show_json(0, array('message' => '广告时间与其他广告重叠'));
  93. }
  94. if($data['is_index_show'] == 1){
  95. $time = $end_time-$begin_time;
  96. $show_hour = floatval($data['show_hour'])*60*60;
  97. if($show_hour > $time){
  98. show_json(0, array('message' => '出现频次时间间隔不能大于投放时间'));
  99. }
  100. }
  101. D('Seller/Popadv')->update($_GPC);
  102. D('Seller/Redisorder')->sysnc_popadv_list();
  103. show_json(1, array('url' => U('popadv/index')));
  104. }
  105. $item = array();
  106. $item['begin_time'] = time();
  107. $item['end_time'] = time() + 24*60*60;
  108. $this->item = $item;
  109. $membercount = M('lionfish_comshop_member')->where( array('groupid' => 0 ) )->count();
  110. $list = array(
  111. array('id' => 'default', 'groupname' => '默认分组', 'membercount' => $membercount )
  112. );
  113. $condition = ' ';
  114. $alllist = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_member_group WHERE 1 ' . $condition . ' ORDER BY id asc' );
  115. foreach ($alllist as &$row ) {
  116. $row['membercount'] = M('lionfish_comshop_member')->where("find_in_set(".$row['id'].",groupid)")->count();
  117. }
  118. $list = array_merge($list, $alllist);
  119. $this->list = $list;
  120. $this->membercount = $membercount;
  121. $this->display("popadv_add");
  122. }
  123. public function add_adv(){
  124. $_GPC = I('request.');
  125. $this->num = $_GPC['num'];
  126. $html = $this->fetch('Popadv/popadv_one');
  127. echo json_encode(array(
  128. 'code' => 0,
  129. 'html' => $html
  130. ));
  131. die();
  132. }
  133. /**
  134. * 更新弹窗广告状态
  135. */
  136. public function change_status(){
  137. $_GPC = I('request.');
  138. $id = intval($_GPC['id']);
  139. if (empty($id)) {
  140. $id = $_GPC['ids'];
  141. }
  142. if( is_array($id) )
  143. {
  144. $items = M('lionfish_comshop_pop_adv')->field('id')->where( array('id' => array('in', $id)) )->select();
  145. }else{
  146. $items = M('lionfish_comshop_pop_adv')->field('id')->where( array('id' =>$id ) )->select();
  147. }
  148. if (empty($items)) {
  149. $items = array();
  150. }
  151. foreach ($items as $item) {
  152. M('lionfish_comshop_pop_adv')->where( array('id' => $item['id']) )->save( array('status' => intval($_GPC['status'])) );
  153. }
  154. D('Seller/Redisorder')->sysnc_popadv_list();
  155. show_json(1, array('url' => U('popadv/index')));
  156. }
  157. /**
  158. * 删除弹窗广告
  159. */
  160. public function delete_popadv(){
  161. $_GPC = I('request.');
  162. $id = intval($_GPC['id']);
  163. if (empty($id)) {
  164. $id = $_GPC['ids'];
  165. }
  166. if( is_array($id) )
  167. {
  168. $items = M('lionfish_comshop_pop_adv')->field('id')->where( array('id' => array('in', $id)) )->select();
  169. }else{
  170. $items = M('lionfish_comshop_pop_adv')->field('id')->where( array('id' =>$id ) )->select();
  171. }
  172. if (empty($item)) {
  173. $item = array();
  174. }
  175. foreach ($items as $item) {
  176. M('lionfish_comshop_pop_adv')->where( array('id' => $item['id']) )->delete();
  177. M('lionfish_comshop_pop_adv_list')->where( array('ad_id' => $item['id']) )->delete();
  178. }
  179. D('Seller/Redisorder')->sysnc_popadv_list();
  180. show_json(1, array('url' => U('popadv/index')));
  181. }
  182. /**
  183. * 编辑弹窗广告
  184. */
  185. public function edit_popadv(){
  186. $_GPC = I('request.');
  187. $id = intval($_GPC['id']);
  188. if (!empty($id)) {
  189. $item = M('lionfish_comshop_pop_adv')->where( array('id' =>$id ) )->find();
  190. $adv_list = M('lionfish_comshop_pop_adv_list')->where( array('ad_id' => $id) )->select();
  191. $this->item = $item;
  192. $this->adv_list = $adv_list;
  193. $membercount = M('lionfish_comshop_member')->where( array('groupid' => 0 ) )->count();
  194. $list = array(
  195. array('id' => 'default', 'groupname' => '默认分组', 'membercount' => $membercount )
  196. );
  197. $condition = ' ';
  198. $alllist = M()->query('SELECT * FROM ' . C('DB_PREFIX'). 'lionfish_comshop_member_group WHERE 1 ' . $condition . ' ORDER BY id asc' );
  199. foreach ($alllist as &$row ) {
  200. $row['membercount'] = M('lionfish_comshop_member')->where("find_in_set(".$row['id'].",groupid)")->count();
  201. }
  202. $list = array_merge($list, $alllist);
  203. $this->list = $list;
  204. $this->membercount = $membercount;
  205. if(!empty($item['member_id'])){
  206. $user_list = M('lionfish_comshop_member')->where("member_id in (".$item['member_id'].")")->select();
  207. $this->user_list = $user_list;
  208. }
  209. }
  210. if (IS_POST) {
  211. $data = $_GPC['data'];
  212. $time = $_GPC['time'];
  213. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  214. if($open_redis_server != 1){
  215. show_json(0, array('message' => '请开启redis服务'));
  216. }
  217. if (empty($data['adv_name'])) {
  218. show_json(0, array('message' => '活动名称不能为空'));
  219. }
  220. $aid = $_GPC['aid'];
  221. $thumb = $_GPC['thumb'];
  222. for($i = 0;$i < count($aid);$i++){
  223. if(empty($thumb[$i])){
  224. show_json(0, array('message' => '广告'.$aid[$i].'图片不能为空'));
  225. }
  226. if(empty($data['link_'.$aid[$i]])){
  227. show_json(0, array('message' => '广告'.$aid[$i].'链接不能为空'));
  228. }
  229. }
  230. $begin_time = strtotime($time['start']);
  231. $end_time = strtotime($time['end']);
  232. $count = M('lionfish_comshop_pop_adv')->where(" begin_time <= ".$end_time." and end_time >=".$begin_time." and id <> ".$data['id'])->count();
  233. if($count > 0){
  234. show_json(0, array('message' => '广告时间与其他广告重叠'));
  235. }
  236. if($data['is_index_show'] == 1){
  237. $time = $end_time-$begin_time;
  238. $show_hour = floatval($data['show_hour'])*60*60;
  239. if($show_hour > $time){
  240. show_json(0, array('message' => '出现频次时间间隔不能大于投放时间'));
  241. }
  242. }
  243. D('Seller/Popadv')->update($_GPC);
  244. D('Seller/Redisorder')->sysnc_popadv_list();
  245. show_json(1, array('url' => U('popadv/index')));
  246. }
  247. $this->display("popadv_edit");
  248. }
  249. //查看活动统计
  250. public function popadv_click(){
  251. $_GPC = I('request.');
  252. $id = intval($_GPC['id']);
  253. $item = M('lionfish_comshop_pop_adv')->where( array('id' =>$id ) )->find();
  254. $this->item = $item;
  255. $this->display("popadv_click");
  256. }
  257. }
  258. ?>