ReportcatController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 ReportcatController extends AdminbaseController {
  10. //列表
  11. public function index(){
  12. $lists=Db::name("user_live_report_classify")
  13. ->where(function (Query $query) {
  14. $data = $this->request->param();
  15. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  16. if (!empty($keyword)) {
  17. $query->where('title', 'like', "%$keyword%");
  18. }
  19. })
  20. ->order("orderno asc")
  21. ->paginate(20);
  22. //分页-->筛选条件参数
  23. $data = $this->request->param();
  24. $lists->appends($data);
  25. // 获取分页显示
  26. $page = $lists->render();
  27. $this->assign('lists', $lists);
  28. $this->assign('page', $page);
  29. return $this->fetch();
  30. }
  31. /*分类添加*/
  32. public function add(){
  33. return $this->fetch();
  34. }
  35. /*分类添加提交*/
  36. public function add_post(){
  37. if($this->request->isPost()) {
  38. $data = $this->request->param();
  39. $title=trim($data['title']);
  40. $orderno=$data['orderno'];
  41. if($title==""){
  42. $this->error("请填写分类名称");
  43. }
  44. if(!is_numeric($orderno)){
  45. $this->error("排序号请填写数字");
  46. }
  47. if($orderno<0){
  48. $this->error("排序号必须大于0");
  49. }
  50. $isexit=Db::name("user_live_report_classify")
  51. ->where("title='{$title}'")
  52. ->find();
  53. if($isexit){
  54. $this->error('该分类已存在');
  55. }
  56. $data['title']=$title;
  57. $data['orderno']=$orderno;
  58. $data['addtime']=time();
  59. $result=Db::name("user_live_report_classify")->insert($data);
  60. if($result){
  61. $this->success('添加成功','admin/Reportcat/index',3);
  62. }else{
  63. $this->error('添加失败');
  64. }
  65. }
  66. }
  67. //分类排序
  68. public function listorderset() {
  69. $ids = $this->request->param('listorders');
  70. foreach ($ids as $key => $r) {
  71. $data['orderno'] = $r;
  72. Db::name("user_live_report_classify")
  73. ->where(array('id' => $key))
  74. ->update($data);
  75. }
  76. $status = true;
  77. if ($status) {
  78. $this->success("排序更新成功!");
  79. } else {
  80. $this->error("排序更新失败!");
  81. }
  82. }
  83. /*分类删除*/
  84. public function del(){
  85. $id = $this->request->param('id');
  86. if($id){
  87. $result=Db::name("user_live_report_classify")
  88. ->where("id={$id}")
  89. ->delete();
  90. if($result){
  91. $this->success('删除成功');
  92. }else{
  93. $this->error('删除失败');
  94. }
  95. }else{
  96. $this->error('数据传入失败!');
  97. }
  98. }
  99. /*分类编辑*/
  100. public function edit(){
  101. $id = $this->request->param('id');
  102. if($id){
  103. $info=Db::name("user_live_report_classify")
  104. ->where("id={$id}")
  105. ->find();
  106. $this->assign("info",$info);
  107. }else{
  108. $this->error('数据传入失败!');
  109. }
  110. return $this->fetch();
  111. }
  112. /*分类编辑提交*/
  113. public function edit_post(){
  114. if($this->request->isPost()) {
  115. $data = $this->request->param();
  116. $id=$data["id"];
  117. $title=$data["title"];
  118. $orderno=$data["orderno"];
  119. if(!trim($title)){
  120. $this->error('分类标题不能为空');
  121. }
  122. if(!is_numeric($orderno)){
  123. $this->error("排序号请填写数字");
  124. }
  125. if($orderno<0){
  126. $this->error("排序号必须大于0");
  127. }
  128. $isexit=Db::name("user_live_report_classify")
  129. ->where("id!={$id} and title='{$title}'")
  130. ->find();
  131. if($isexit){
  132. $this->error('该分类已存在');
  133. }
  134. $data["updatetime"]=time();
  135. unset($data['id']);
  136. $result=Db::name("user_live_report_classify")->where("id={$id}")->update($data);
  137. if($result!==false){
  138. $this->success('修改成功');
  139. }else{
  140. $this->error('修改失败');
  141. }
  142. }
  143. }
  144. }