LiveclassController.php 3.7 KB

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