Comment.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Comment extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function data()
  11. {
  12. $param = input();
  13. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  14. $param['limit'] = intval($param['limit']) <1 ? $this->_pagesize : $param['limit'];
  15. $where=[];
  16. if(in_array($param['status'],['0','1'],true)){
  17. $where['comment_status'] = ['eq',$param['status']];
  18. }
  19. if(in_array($param['mid'],['1','2','3'])){
  20. $where['comment_mid'] = ['eq',$param['mid']];
  21. }
  22. if(!empty($param['uid'])){
  23. $where['user_id'] = ['eq',$param['uid'] ];
  24. }
  25. if(!empty($param['report'])){
  26. if($param['report'] == 1){
  27. $where['comment_report'] = ['eq',0];
  28. }
  29. else{
  30. $where['comment_report'] = ['gt',0];
  31. }
  32. }
  33. if(!empty($param['wd'])){
  34. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  35. $where['comment_name|comment_content'] = ['like','%'.$param['wd'].'%'];
  36. }
  37. $order='comment_id desc';
  38. $res = model('Comment')->listData($where,$order,$param['page'],$param['limit']);
  39. $this->assign('list',$res['list']);
  40. $this->assign('total',$res['total']);
  41. $this->assign('page',$res['page']);
  42. $this->assign('limit',$res['limit']);
  43. $param['page'] = '{page}';
  44. $param['limit'] = '{limit}';
  45. $this->assign('param',$param);
  46. $this->assign('title',lang('admin/comment/title'));
  47. return $this->fetch('admin@comment/index');
  48. }
  49. public function info()
  50. {
  51. if (Request()->isPost()) {
  52. $param = input();
  53. $res = model('Comment')->saveData($param);
  54. if($res['code']>1){
  55. return $this->error($res['msg']);
  56. }
  57. return $this->success($res['msg']);
  58. }
  59. $id = input('id');
  60. $where=[];
  61. $where['comment_id'] = ['eq',$id];
  62. $res = model('Comment')->infoData($where);
  63. $this->assign('info',$res['info']);
  64. $this->assign('title',lang('admin/comment/title'));
  65. return $this->fetch('admin@comment/info');
  66. }
  67. public function del()
  68. {
  69. $param = input();
  70. $ids = $param['ids'];
  71. $all = $param['all'];
  72. if(!empty($ids) || !empty($all)){
  73. $where=[];
  74. $where['comment_id'] = ['in',$ids];
  75. if($all==1){
  76. $where['comment_id'] = ['gt',0];
  77. }
  78. $res = model('Comment')->delData($where);
  79. if($res['code']>1){
  80. return $this->error($res['msg']);
  81. }
  82. return $this->success($res['msg']);
  83. }
  84. return $this->error(lang('param_err'));
  85. }
  86. public function field()
  87. {
  88. $param = input();
  89. $ids = $param['ids'];
  90. $col = $param['col'];
  91. $val = $param['val'];
  92. if(!empty($ids) && in_array($col,['comment_status']) ){
  93. $where=[];
  94. $where['comment_id'] = ['in',$ids];
  95. $res = model('Comment')->fieldData($where,$col,$val);
  96. if($res['code']>1){
  97. return $this->error($res['msg']);
  98. }
  99. return $this->success($res['msg']);
  100. }
  101. return $this->error(lang('param_err'));
  102. }
  103. }