VideoCateAction.class.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 VideoCateAction extends CommonAction{
  10. public function index()
  11. {
  12. $now=get_gmtime();
  13. $map['is_delete'] = 0;
  14. if(strim($_REQUEST['title'])!=''){
  15. $map['title'] = array('like','%'.strim($_REQUEST['title']).'%');
  16. }
  17. $create_time_2=empty($_REQUEST['create_time_2'])?to_date($now,'Y-m-d'):strim($_REQUEST['create_time_2']);
  18. $create_time_2=to_timespan($create_time_2)+24*3600;
  19. if(trim($_REQUEST['create_time_1'])!='')
  20. {
  21. $map['create_time'] = array('between',array(to_timespan($_REQUEST['create_time_1']),$create_time_2));
  22. }
  23. if (method_exists ( $this, '_filter' )) {
  24. $this->_filter ( $map );
  25. }
  26. $name=$this->getActionName();
  27. $model = D ($name);
  28. if (! empty ( $model )) {
  29. $this->_list ( $model, $map );
  30. }
  31. $list = $this->get("list");
  32. $result = array();
  33. $row = 0;
  34. foreach($list as $k=>$v)
  35. {
  36. $v['level'] = -1;
  37. $v['title'] = $v['title'];
  38. $video_count = M('Video')->where('cate_id ='.$v['id'])->count();
  39. $v['video_num'] = $video_count;
  40. $result[$row] = $v;
  41. $row++;
  42. }
  43. $this->assign("list",$result);
  44. $this->display ();
  45. return;
  46. }
  47. public function add()
  48. {
  49. $cate_tree = M(MODULE_NAME)->where('is_delete = 0')->findAll();
  50. $this->assign("cate_tree",$cate_tree);
  51. $this->assign("new_sort", M("VideoCate")->max("sort")+1);
  52. $this->display();
  53. }
  54. public function edit() {
  55. $id = intval($_REQUEST ['id']);
  56. $cate_tree = M(MODULE_NAME)->where('is_delete = 0')->findAll();
  57. $this->assign("cate_tree",$cate_tree);
  58. $condition['id'] = $id;
  59. $vo = M(MODULE_NAME)->where($condition)->find();
  60. $this->assign ( 'vo', $vo );
  61. $this->display ();
  62. }
  63. public function foreverdelete() {
  64. //彻底删除指定记录
  65. $ajax = intval($_REQUEST['ajax']);
  66. $id = $_REQUEST ['id'];
  67. if (isset ( $id )) {
  68. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  69. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  70. foreach($rel_data as $data)
  71. {
  72. $info[] = $data['title'];
  73. }
  74. if($info) $info = implode(",",$info);
  75. $list = M(MODULE_NAME)->where ( $condition )->delete();
  76. if ($list!==false) {
  77. //redis同步
  78. require_once APP_ROOT_PATH."/admin/Lib/Action/RedisCommon.class.php";
  79. $redisCommon = new Ridescommon();
  80. foreach($rel_data as $data){
  81. $redisCommon->video_cate_list($data['title'],$data,'delete');
  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. $data['title'] = strim($data['title']);
  100. if(!check_empty($data['title']))
  101. {
  102. $this->error("请输入话题名称");
  103. }
  104. $cate_id = $GLOBALS['db']->getOne("select id from ".DB_PREFIX."video_cate where title = '".$data['title']."'");
  105. if($cate_id){
  106. $this->error("话题名称已存在");
  107. }
  108. $data['create_time'] = get_gmtime();
  109. $data['is_delete'] = 0;
  110. $user_count = $GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."user where id = ".intval($data['user_id']));
  111. if(strim($data['user_id'])!='' && $user_count<=0){
  112. $this->error("关联用户ID不存在");
  113. }
  114. // 更新数据
  115. $log_info = $data['title'];
  116. $list=M(MODULE_NAME)->add($data);
  117. if (false !== $list) {
  118. //redis同步
  119. require_once APP_ROOT_PATH."/admin/Lib/Action/RedisCommon.class.php";
  120. $redisCommon = new Ridescommon();
  121. $redisData = $data;
  122. $redisData['id'] = intval(M(MODULE_NAME)->getLastInsID());
  123. $redisCommon->video_cate_list($data['title'],$redisData,'insert');
  124. //成功提示
  125. save_log($log_info.L("INSERT_SUCCESS"),1);
  126. $this->success(L("INSERT_SUCCESS"));
  127. } else {
  128. //错误提示
  129. save_log($log_info.L("INSERT_FAILED"),0);
  130. $this->error(L("INSERT_FAILED"));
  131. }
  132. }
  133. public function update() {
  134. B('FilterString');
  135. $data = M(MODULE_NAME)->create ();
  136. $log_info = M(MODULE_NAME)->where("id=".intval($data['id']))->getField("title");
  137. //开始验证有效性
  138. $this->assign("jumpUrl",u(MODULE_NAME."/edit",array("id"=>$data['id'])));
  139. if(!check_empty($data['title']))
  140. {
  141. $this->error("请输入分类名称");
  142. }
  143. $user_count = $GLOBALS['db']->getOne("select count(*) from ".DB_PREFIX."user where id = ".intval($data['user_id']));
  144. if(strim($data['user_id'])!='' && $user_count<=0){
  145. $this->error("关联用户ID不存在");
  146. }
  147. $list=M(MODULE_NAME)->save ($data);
  148. if (false !== $list) {
  149. //redis同步
  150. require_once APP_ROOT_PATH."/admin/Lib/Action/RedisCommon.class.php";
  151. $redisCommon = new Ridescommon();
  152. $redisCommon->video_cate_list($data['title'],$data,'update');
  153. //成功提示
  154. save_log($log_info.L("UPDATE_SUCCESS"),1);
  155. $this->success(L("UPDATE_SUCCESS"));
  156. } else {
  157. //错误提示
  158. save_log($log_info.L("UPDATE_FAILED"),0);
  159. $this->error(L("UPDATE_FAILED"),0,$log_info.L("UPDATE_FAILED"));
  160. }
  161. }
  162. /*public function set_effect()
  163. {
  164. $id = intval($_REQUEST['id']);
  165. $ajax = intval($_REQUEST['ajax']);
  166. $info = M(MODULE_NAME)->where("id=".$id)->getField("title");
  167. $c_is_effect = M(MODULE_NAME)->where("id=".$id)->getField("is_effect"); //当前状态
  168. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  169. M(MODULE_NAME)->where("id=".$id)->setField("is_effect",$n_is_effect);
  170. save_log($info.l("SET_EFFECT_".$n_is_effect),1);
  171. //redis同步
  172. require_once APP_ROOT_PATH."/admin/Lib/Action/RedisCommon.class.php";
  173. $data = M(MODULE_NAME)->where("id=".$id)->find();
  174. $redisCommon = new Ridescommon();
  175. $redisCommon->video_cate_list($data['title'],$data,'update');
  176. clear_auto_cache("get_help_cache");
  177. $this->ajaxReturn($n_is_effect,l("SET_EFFECT_".$n_is_effect),1) ;
  178. }*/
  179. public function set_sort()
  180. {
  181. $id = intval($_REQUEST['id']);
  182. $sort = intval($_REQUEST['sort']);
  183. $log_info = M("VideoCate")->where("id=".$id)->getField("title");
  184. if(!check_sort($sort))
  185. {
  186. $this->error(l("SORT_FAILED"),1);
  187. }
  188. M("VideoCate")->where("id=".$id)->setField("sort",$sort);
  189. //redis同步
  190. require_once APP_ROOT_PATH."/admin/Lib/Action/RedisCommon.class.php";
  191. $data = M(MODULE_NAME)->where("id=".$id)->find();
  192. $redisCommon = new Ridescommon();
  193. $redisCommon->video_cate_list($data['title'],$data,'update');
  194. save_log($log_info.l("SORT_SUCCESS"),1);
  195. $this->success(l("SORT_SUCCESS"),1);
  196. }
  197. }
  198. ?>