PopadvController.class.php 9.4 KB

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