VideoclassController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * 短视频分类
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. use think\db\Query;
  9. class VideoclassController extends AdminbaseController {
  10. /*视频分类列表*/
  11. public function index(){
  12. $video_model=Db::name("user_video_class");
  13. $lists = $video_model
  14. ->where(function(Query $query){
  15. $data = $this->request->param();
  16. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  17. if(!empty($keyword)){
  18. $query->where('title', 'like', "%$keyword%");
  19. }
  20. })
  21. ->order("orderno asc")
  22. ->paginate(20);
  23. //分页-->筛选条件参数
  24. $data = $this->request->param();
  25. $lists->appends($data);
  26. // 获取分页显示
  27. $page = $lists->render();
  28. $this->assign('lists', $lists);
  29. $this->assign("page", $page);
  30. return $this->fetch();
  31. }
  32. //排序
  33. public function listordersset() {
  34. $ids=$this->request->param('listorders');
  35. foreach ($ids as $key => $r) {
  36. $data['orderno'] = $r;
  37. Db::name("user_video_class")->where(array('id' => $key))->update($data);
  38. }
  39. $status = true;
  40. if ($status) {
  41. $this->resetCache();
  42. $this->success("排序更新成功!");
  43. } else {
  44. $this->error("排序更新失败!");
  45. }
  46. }
  47. public function resetCache(){
  48. $key='getVideoClass';
  49. $rules= Db::name("user_video_class")
  50. ->field('id,title')
  51. ->where("status=1")
  52. ->order('orderno asc')
  53. ->select();
  54. setcaches($key,$rules);
  55. return 1;
  56. }
  57. public function del(){
  58. $id=$this->request->param('id',0,'intval');
  59. if($id){
  60. $result=Db::name("user_video_class")->where(["id"=>$id])->delete();
  61. if($result){
  62. $this->resetCache();
  63. //将视频列表属于该分类下的视频分类取消
  64. Db::name("user_video")->where("classid={$id}")->update(array("classid"=>0));
  65. $this->success('删除成功');
  66. }else{
  67. $this->error('删除失败');
  68. }
  69. }else{
  70. $this->error('数据传入失败!');
  71. }
  72. return $this->fetch();
  73. }
  74. public function add(){
  75. return $this->fetch();
  76. }
  77. public function add_post(){
  78. if($this->request->isPost()){
  79. $data=$this->request->param();
  80. $data['addtime']=time();
  81. $title=$data['title'];
  82. if($title==""){
  83. $this->error("请填写分类标题");
  84. }
  85. //判断标题是否存在
  86. $info=Db::name("user_video_class")->where("title='{$title}'")->find();
  87. if($info){
  88. $this->error("分类标题已经存在");
  89. }
  90. $result=Db::name("user_video_class")->insert($data);
  91. if($result){
  92. $this->resetCache();
  93. $this->success('添加成功','admin/videoclass/index');
  94. }else{
  95. $this->error('添加失败');
  96. }
  97. }
  98. }
  99. public function edit(){
  100. $id=$this->request->param('id',0,'intval');
  101. if($id){
  102. $info=Db::name("user_video_class")->where("id={$id}")->find();
  103. $this->assign('info', $info);
  104. }else{
  105. $this->error('数据传入失败!');
  106. }
  107. return $this->fetch();
  108. }
  109. public function edit_post(){
  110. if($this->request->isPost()){
  111. $data=$this->request->param();
  112. $id=$data['id'];
  113. $title=trim($data['title']);
  114. if($title==""){
  115. $this->error("请填写视频标题");
  116. }
  117. $data['title']=$title;
  118. //判断名称是否存在
  119. $info=Db::name("user_video_class")->where("id !={$id} and title='{$title}'")->find();
  120. if($info){
  121. $this->error("视频分类标题已经存在");
  122. }
  123. $result=Db::name("user_video_class")->update($data);
  124. if($result!==false){
  125. $this->resetCache();
  126. $this->success('修改成功');
  127. }else{
  128. $this->error('修改失败');
  129. }
  130. }
  131. }
  132. }