LiveclassController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-02-17
  10. // +—————————————————————————————————————————————————————————————————————
  11. /**
  12. * 直播分类
  13. */
  14. namespace app\admin\controller;
  15. use cmf\controller\AdminBaseController;
  16. use think\Db;
  17. class LiveclassController extends AdminbaseController {
  18. public function index(){
  19. $lists = Db::name("live_class")
  20. //->where()
  21. ->order("list_order asc, id desc")
  22. ->paginate(20);
  23. $page = $lists->render();
  24. $this->assign('lists', $lists);
  25. $this->assign("page", $page);
  26. return $this->fetch();
  27. }
  28. public function del(){
  29. $id = $this->request->param('id', 0, 'intval');
  30. $rs = DB::name('live_class')->where("id={$id}")->delete();
  31. if(!$rs){
  32. $this->error("删除失败!");
  33. }
  34. Db::name("live")->where(['liveclassid'=>$id])->update(['liveclassid'=>0]);
  35. Db::name("live_record")->where(['liveclassid'=>$id])->update(['liveclassid'=>0]);
  36. $this->resetcache();
  37. $this->success("删除成功!");
  38. }
  39. //排序
  40. public function listOrder() {
  41. $model = DB::name('live_class');
  42. parent::listOrders($model);
  43. $this->resetcache();
  44. $this->success("排序更新成功!");
  45. }
  46. public function add(){
  47. return $this->fetch();
  48. }
  49. public function addPost(){
  50. if ($this->request->isPost()) {
  51. $data = $this->request->param();
  52. $name=$data['name'];
  53. if($name==""){
  54. $this->error("请填写名称");
  55. }
  56. $thumb=$data['thumb'];
  57. if($thumb==""){
  58. $this->error("请上传图标");
  59. }
  60. $data['thumb']=set_upload_path($thumb);
  61. $des=$data['des'];
  62. if($des==''){
  63. $this->error("请填写直播分类描述");
  64. }
  65. if(mb_strlen($des)>200){
  66. $this->error("直播分类描述在200字以内");
  67. }
  68. $id = DB::name('live_class')->insertGetId($data);
  69. if(!$id){
  70. $this->error("添加失败!");
  71. }
  72. $this->resetcache();
  73. $this->success("添加成功!");
  74. }
  75. }
  76. public function edit(){
  77. $id = $this->request->param('id', 0, 'intval');
  78. $data=Db::name('live_class')
  79. ->where("id={$id}")
  80. ->find();
  81. if(!$data){
  82. $this->error("信息错误");
  83. }
  84. $this->assign('data', $data);
  85. return $this->fetch();
  86. }
  87. public function editPost(){
  88. if ($this->request->isPost()) {
  89. $data = $this->request->param();
  90. $name=$data['name'];
  91. if($name==""){
  92. $this->error("请填写名称");
  93. }
  94. $thumb=$data['thumb'];
  95. if($thumb==""){
  96. $this->error("请上传图标");
  97. }
  98. $des=$data['des'];
  99. if($des==''){
  100. $this->error("请填写直播分类描述");
  101. }
  102. if(mb_strlen($des)>200){
  103. $this->error("直播分类描述在200字以内");
  104. }
  105. $thumb_old=$data['thumb_old'];
  106. if($thumb_old!=$thumb){
  107. $data['thumb']=set_upload_path($thumb);
  108. }
  109. unset($data['thumb_old']);
  110. $id = DB::name('live_class')->update($data);
  111. if($id===false){
  112. $this->error("修改失败!");
  113. }
  114. $this->resetcache();
  115. $this->success("修改成功!");
  116. }
  117. }
  118. public function resetcache(){
  119. $key='getLiveClass';
  120. $rules= DB::name('live_class')
  121. ->order('list_order asc,id desc')
  122. ->select();
  123. if($rules){
  124. setcaches($key,$rules);
  125. }else{
  126. delcache($key);
  127. }
  128. return 1;
  129. }
  130. }