IndexImageAction.class.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class IndexImageAction extends CommonAction{
  10. private $type_list;
  11. private $position;
  12. public function __construct(){
  13. parent::__construct();
  14. $type_list =array('0'=>'网页url链接');
  15. $position = array('0'=>'轮播图');
  16. if(defined("OPEN_RANKING_LIST")&&OPEN_RANKING_LIST){
  17. $type_list[2] = '排行榜APP跳转';
  18. }
  19. if(defined("OPEN_PC")&&OPEN_PC){
  20. $position[3] = 'PC首页';
  21. }
  22. //教育直播
  23. if(defined("OPEN_EDU_MODULE") && OPEN_EDU_MODULE){
  24. $position[5] = '首页直播推荐';
  25. $position[9] = '首页预约课程推荐';
  26. $position[6] = '课堂首页轮播图';
  27. $position[7] = '约课首页轮播图';
  28. $position[8] = '线下约课轮播图';
  29. $type_list[8] = '跳转到直播间';
  30. $type_list[6] = '跳转线下约课详情';
  31. $type_list[7] = '跳转一对一约课';
  32. $type_list[9] = '跳转课程详情';
  33. }
  34. /*$type_list[3] = 'PC首页';
  35. $type_list[4] = '启动广告';*/
  36. $position[4] = '启动广告';
  37. $this->type_list = $type_list;
  38. $this->position = $position;
  39. }
  40. public function index()
  41. {
  42. parent::index();
  43. }
  44. public function add()
  45. {
  46. $this->assign("position",$this->position);
  47. $this->assign("type_list",$this->type_list);
  48. $this->assign("new_sort", M("IndexImage")->max("sort")+1);
  49. $this->display();
  50. }
  51. public function edit() {
  52. $this->assign("position",$this->position);
  53. $this->assign("type_list",$this->type_list);
  54. $id = intval($_REQUEST ['id']);
  55. $condition['id'] = $id;
  56. $vo = M(MODULE_NAME)->where($condition)->find();
  57. $this->assign ( 'vo', $vo );
  58. $this->display ();
  59. }
  60. public function foreverdelete() {
  61. //彻底删除指定记录
  62. $ajax = intval($_REQUEST['ajax']);
  63. $id = $_REQUEST ['id'];
  64. if (isset ( $id )) {
  65. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  66. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  67. $delete_show_position=array();
  68. foreach($rel_data as $data)
  69. {
  70. $info[] = $data['title'];
  71. $delete_show_position[$data['show_position']]=$data['show_position'];
  72. }
  73. if($info) $info = implode(",",$info);
  74. $list = M(MODULE_NAME)->where ( $condition )->delete();
  75. if ($list!==false) {
  76. clear_auto_cache("banner_list");
  77. load_auto_cache("banner_list");
  78. if(defined("OPEN_EDU_MODULE") && OPEN_EDU_MODULE) {
  79. foreach ($delete_show_position as $v) {
  80. load_auto_cache("banner_edu_list", array('show_position' => $v), false);
  81. }
  82. }
  83. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  84. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  85. } else {
  86. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  87. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  88. }
  89. } else {
  90. $this->error (l("INVALID_OPERATION"),$ajax);
  91. }
  92. }
  93. public function insert() {
  94. B('FilterString');
  95. $ajax = intval($_REQUEST['ajax']);
  96. $data = M(MODULE_NAME)->create ();
  97. //开始验证有效性
  98. $this->assign("jumpUrl",u(MODULE_NAME."/add"));
  99. if($data['show_position']==4){
  100. $index_image = M(MODULE_NAME)->where("show_position = 4")->find();
  101. if($index_image){
  102. $this->error("启动广告只能添加一个,已添加可编辑!");
  103. }
  104. }
  105. if(!check_empty($data['image']))
  106. {
  107. $this->error("请上传广告图");
  108. }
  109. if(!check_empty($data['title']))
  110. {
  111. $this->error("请输入标题");
  112. }
  113. if($data['type']==1|| $data['type']==6 || $data['type']==7 || $data['type']==8 || $data['type']==9){
  114. if($data['type']==8)
  115. $error_title="请输入房间号";
  116. elseif($data['type']==6)
  117. $error_title="请输入机构id";
  118. elseif($data['type']==7)
  119. $error_title="请输入会员id";
  120. elseif($data['type']==9)
  121. $error_title="请输入课程id";
  122. if(!$data['show_id']){
  123. $this->error($error_title);
  124. }
  125. }else{
  126. $data['show_id'] = '';
  127. }
  128. // 更新数据
  129. $log_info = $data['title'];
  130. $list=M(MODULE_NAME)->add($data);
  131. if (false !== $list) {
  132. //load_auto_cache("index_image",'',false);
  133. //redis缓存
  134. clear_auto_cache("banner_list");
  135. load_auto_cache("banner_list");
  136. if(defined("OPEN_EDU_MODULE") && OPEN_EDU_MODULE) {
  137. load_auto_cache("banner_edu_list", array('show_position' => $data['show_position']), false);
  138. }
  139. //成功提示
  140. save_log($log_info.L("INSERT_SUCCESS"),1);
  141. $this->success(L("INSERT_SUCCESS"));
  142. } else {
  143. //错误提示
  144. save_log($log_info.L("INSERT_FAILED"),0);
  145. $this->error(L("INSERT_FAILED"));
  146. }
  147. }
  148. public function update() {
  149. B('FilterString');
  150. $data = M(MODULE_NAME)->create ();
  151. $before_info = M("IndexImage")->where("id=" . $data['id'])->find();
  152. $log_info = $before_info['title'];
  153. //开始验证有效性
  154. $this->assign("jumpUrl",u(MODULE_NAME."/edit",array("id"=>$data['id'])));
  155. if($data['show_position']==4){
  156. $index_image = M(MODULE_NAME)->where("show_position = 4")->find();
  157. if(isset($index_image['id']) && $index_image['id']!=$data['id']){
  158. $this->error("启动广告只能添加一个,已添加可编辑!");
  159. }
  160. }
  161. if(!check_empty($data['image']))
  162. {
  163. $this->error("请上传广告图");
  164. }
  165. if(!check_empty($data['title']))
  166. {
  167. $this->error("请输入标题");
  168. }
  169. if($data['type']==1|| $data['type']==6 || $data['type']==7 || $data['type']==8 || $data['type']==9){
  170. if($data['type']==8)
  171. $error_title="请输入房间号";
  172. elseif($data['type']==6)
  173. $error_title="请输入机构id";
  174. elseif($data['type']==7)
  175. $error_title="请输入会员id";
  176. elseif($data['type']==9)
  177. $error_title="请输入课程id";
  178. if(!$data['show_id']){
  179. $this->error($error_title);
  180. }
  181. }else{
  182. $data['show_id'] = '';
  183. }
  184. $list=M(MODULE_NAME)->save ($data);
  185. if (false !== $list) {
  186. //成功提示
  187. //load_auto_cache("index_image",'',false);
  188. //redis缓存
  189. clear_auto_cache("banner_list");
  190. load_auto_cache("banner_list");
  191. if(defined("OPEN_EDU_MODULE") && OPEN_EDU_MODULE)
  192. {
  193. if($before_info['show_position'] != $data['show_position']){
  194. load_auto_cache("banner_edu_list",array('show_position'=>$before_info['show_position']),false);
  195. }
  196. load_auto_cache("banner_edu_list",array('show_position'=>$data['show_position']),false);
  197. }
  198. save_log($log_info.L("UPDATE_SUCCESS"),1);
  199. $this->success(L("UPDATE_SUCCESS"));
  200. } else {
  201. //错误提示
  202. save_log($log_info.L("UPDATE_FAILED"),0);
  203. $this->error(L("UPDATE_FAILED"),0,$log_info.L("UPDATE_FAILED"));
  204. }
  205. }
  206. public function set_sort()
  207. {
  208. $id = intval($_REQUEST['id']);
  209. $sort = intval($_REQUEST['sort']);
  210. $image_info = M("IndexImage")->where("id=" . $id)->find();
  211. $log_info = $image_info['title'];
  212. if(!check_sort($sort))
  213. {
  214. $this->error(l("SORT_FAILED"),1);
  215. }
  216. M("IndexImage")->where("id=".$id)->setField("sort",$sort);
  217. save_log($log_info.l("SORT_SUCCESS"),1);
  218. clear_auto_cache("banner_list");
  219. if(defined("OPEN_EDU_MODULE") && OPEN_EDU_MODULE) {
  220. load_auto_cache("banner_edu_list", array('show_position' => $image_info['show_position']), false);
  221. }
  222. $this->success(l("SORT_SUCCESS"),1);
  223. }
  224. }
  225. ?>