Report.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 举报
  7. */
  8. class Report extends Api
  9. {
  10. protected $noNeedLogin = ['typelist'];
  11. protected $noNeedRight = ['*'];
  12. //类型列表
  13. public function typelist(){
  14. $list = Db::name('report_type')->order('id asc')->select();
  15. $this->success('success',$list);
  16. }
  17. //新增举报
  18. public function addone(){
  19. $user_id = input('user_id', 0, 'intval');
  20. $type_id = input('type_id', 0, 'intval');
  21. $content = input('content', '', 'trim');
  22. $images = input('images', '', 'trim');
  23. if (!$user_id) {
  24. $this->error('您的网络开小差啦~');
  25. }
  26. if ($this->auth->id == $user_id) {
  27. $this->error('您不能举报自己~');
  28. }
  29. $user_info = Db::name('user')->find($user_id);
  30. if (!$user_info) {
  31. $this->error('您的网络开小差啦~');
  32. }
  33. if (!$type_id) {
  34. $this->error('请选择举报类型');
  35. }
  36. $count = Db::name('report_type')->where(['id' => $type_id])->count('id');
  37. if (!$count) {
  38. $this->error('举报类型不存在');
  39. }
  40. if(empty($content)){
  41. $this->error('内容不能为空');
  42. }
  43. if (iconv_strlen($content, 'utf-8') > 500) {
  44. $this->error('内容最多500字');
  45. }
  46. if(!empty($images) && strpos($images,',')){
  47. if(count(explode(',',$images)) > 3){
  48. $this->error('一次最多只能上传3张图片');
  49. }
  50. }
  51. $data = [
  52. 'user_id' => $this->auth->id,
  53. 'type_id' => $type_id,
  54. 'other_id' => $user_id,
  55. 'content' => $content,
  56. 'images' => $images,
  57. 'createtime' => time(),
  58. 'updatetime' => time(),
  59. ];
  60. $id = Db::name('report')->insertGetId($data);
  61. if (!$id) {
  62. $this->error('您的网络开小差啦~');
  63. }
  64. $this->success('举报成功');
  65. }
  66. //举报列表
  67. public function reportlist() {
  68. $type = input('type', 0, 'intval'); //类型:0我举报的 1被人举报
  69. $where = [];
  70. if ($type == 1) {
  71. $where['other_id'] = $this->auth->id;
  72. } else {
  73. $where['user_id'] = $this->auth->id;
  74. }
  75. $list = Db::name('report')->where($where)->order('id desc')->autopage()->select();
  76. if (!$list) {
  77. $this->success('success', $list);
  78. }
  79. $list = list_domain_image($list,['images']);
  80. $mt_user = Db::name('user');
  81. $mt_report_type = Db::name('report_type');
  82. foreach ($list as &$v) {
  83. if ($type == 0) {
  84. $nickname = $mt_user->where(['id' => $v['other_id']])->value('nickname');
  85. $v['nickname'] = $nickname;
  86. } else {
  87. $nickname = $mt_user->where(['id' => $v['user_id']])->value('nickname');
  88. $v['nickname'] = str_replace(mb_substr($nickname, 1), '****', $nickname);
  89. }
  90. $v['type_name'] = $mt_report_type->where(['id' => $v['type_id']])->value('name');
  91. $v['createtime'] = date('Y.m.d H:i');
  92. }
  93. $this->success('success',$list);
  94. }
  95. }