0
0

NewsReply.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class NewsReply extends Auth
  5. {
  6. public function index(){
  7. if(request()->isAjax()){
  8. //分页参数
  9. $length = input('rows',10,'intval'); //每页条数
  10. $page = input('page',1,'intval'); //第几页
  11. $start = ($page - 1) * $length; //分页开始位置
  12. //排序
  13. $sortRow = input('sidx','id','trim'); //排序列
  14. $sort = input('sord','desc','trim'); //排序方式
  15. $order = $sortRow.' '.$sort;
  16. $title = input('title','','trim');
  17. if($title){
  18. $map[] = ['content','like','%'.$title.'%'];
  19. }
  20. $cate_id = input('cate_id','','trim');
  21. if($cate_id){
  22. $map[] = ['cate_id','=',$cate_id];
  23. }
  24. $enable = input('enable','','trim');
  25. if($enable != ''){
  26. $map[] = ['enable','=',$enable];
  27. }
  28. $ids = Db::name('news')
  29. ->where('org_id',$this->orgId)
  30. ->column('id');
  31. if($ids){
  32. $map[] = ['news_id','in',$ids];
  33. }else{
  34. $map[] = ['id','=',-1];
  35. }
  36. $map[] = ['del','=',0];
  37. $map= empty($map) ? true: $map;
  38. //数据查询
  39. $lists = Db::name('news_reply')->limit($start,$length)->where($map)->order(['id'=>'desc'])->select();
  40. foreach ($lists as $k=>$v){
  41. $lists[$k]['userName'] = Db::name('user')
  42. ->where('id',$v['user_id'])->value('real_name');
  43. $lists[$k]['title'] = Db::name('news')
  44. ->where('id',$v['news_id'])->value('title');
  45. }
  46. //数据返回
  47. $totalCount = Db::name('news_reply')->where($map)->count();
  48. $totalPage = ceil($totalCount/$length);
  49. $result['page'] = $page;
  50. $result['total'] = $totalPage;
  51. $result['records'] = $totalCount;
  52. $result['rows'] = $lists;
  53. return json($result);
  54. }else{
  55. return $this->fetch();
  56. }
  57. }
  58. /**
  59. * 删除记录
  60. * @param int $id
  61. */
  62. public function del($id=0){
  63. if(!$id){
  64. $this->error('参数错误');
  65. }
  66. $res = Db::name('news_reply')->where('id',$id)
  67. ->setField('del',1);
  68. if($res){
  69. $this->success('删除成功');
  70. }else{
  71. $this->error('删除失败');
  72. }
  73. }
  74. /**
  75. * 改变字段值
  76. * @param int $fv
  77. * @param string $fn
  78. * @param int $fv
  79. */
  80. public function changeField($id=0,$fn='',$fv=0){
  81. if(!$fn||!$id){
  82. $this->error('参数错误');
  83. }
  84. $res = Db::name('news_reply')->where('id',$id)->setField($fn,$fv);
  85. if($res){
  86. $this->success('操作成功');
  87. }else{
  88. $this->error('操作失败');
  89. }
  90. }
  91. /**
  92. * 排序
  93. * @param int $id
  94. * @param int $sort
  95. */
  96. public function changeSort($id=0,$sort=0){
  97. if($id<0||$sort<0){
  98. $this->error('参数错误');
  99. }
  100. $res = db('news')->where('id',$id)->update(['sort'=>$sort]);
  101. if($res){
  102. $this->success('操作成功');
  103. }else{
  104. $this->error('操作失败');
  105. }
  106. }
  107. }