0
0

Comment.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Comment extends Auth
  5. {
  6. public function index(){
  7. $type = input('type', 0);
  8. if(request()->isAjax()){
  9. //分页参数
  10. $length = input('rows',10,'intval'); //每页条数
  11. $page = input('page',1,'intval'); //第几页
  12. $start = ($page - 1) * $length; //分页开始位置
  13. //排序
  14. $sortRow = input('sidx','id','trim'); //排序列
  15. $sort = input('sord','desc','trim'); //排序方式
  16. $order = $sortRow.' '.$sort;
  17. $title = input('title','','trim');
  18. if($title){
  19. $map[] = ['content','like','%'.$title.'%'];
  20. }
  21. $map[] = ['org_id','=',$this->orgId];
  22. $map[] = ['type','=',$type];
  23. $map= empty($map) ? true: $map;
  24. //数据查询
  25. $lists = Db::name('comment')->limit($start,$length)->where($map)->order(['id'=>'desc'])->select();
  26. foreach ($lists as $k=>$v){
  27. $lists[$k]['userName'] = Db::name('user')
  28. ->where('id',$v['user_id'])->value('real_name');
  29. }
  30. //数据返回
  31. $totalCount = Db::name('comment')->where($map)->count();
  32. $totalPage = ceil($totalCount/$length);
  33. $result['page'] = $page;
  34. $result['total'] = $totalPage;
  35. $result['records'] = $totalCount;
  36. $result['rows'] = $lists;
  37. return json($result);
  38. }else{
  39. $this->assign('type',$type);
  40. return $this->fetch();
  41. }
  42. }
  43. }