ReportController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 ReportController extends AdminbaseController {
  10. //列表
  11. public function classify(){
  12. $lists=Db::name("user_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 classify_add(){
  33. return $this->fetch();
  34. }
  35. /*分类添加提交*/
  36. public function classify_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_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_report_classify")->insert($data);
  60. if($result){
  61. $this->success('添加成功','admin/Report/classify',3);
  62. }else{
  63. $this->error('添加失败');
  64. }
  65. }
  66. }
  67. //分类排序
  68. public function classify_listorders() {
  69. $ids = $this->request->param('listorders');
  70. foreach ($ids as $key => $r) {
  71. $data['orderno'] = $r;
  72. Db::name("user_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 classify_del(){
  85. $id = $this->request->param('id');
  86. if($id){
  87. $result=Db::name("user_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 classify_edit(){
  101. $id = $this->request->param('id');
  102. if($id){
  103. $info=Db::name("user_report_classify")
  104. ->where("id={$id}")
  105. ->find();
  106. $this->assign("classify_info",$info);
  107. }else{
  108. $this->error('数据传入失败!');
  109. }
  110. return $this->fetch();
  111. }
  112. /*分类编辑提交*/
  113. public function classify_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_report_classify")
  129. ->where("id!={$id} and title='{$title}'")
  130. ->find();
  131. if($isexit){
  132. $this->error('该分类已存在');
  133. }
  134. $data["updatetime"]=time();
  135. $result=Db::name("user_report_classify")
  136. ->update($data);
  137. if($result!==false){
  138. $this->success('修改成功');
  139. }else{
  140. $this->error('修改失败');
  141. }
  142. }
  143. }
  144. public function index(){
  145. $lists = Db::name('user_report')
  146. ->where(function (Query $query) {
  147. $data = $this->request->param();
  148. $status=isset($data['status']) ? $data['status']: '';
  149. $start_time=isset($data['start_time']) ? $data['start_time']: '';
  150. $end_time=isset($data['end_time']) ? $data['end_time']: '';
  151. if ($status!='') {
  152. $query->where('status','=', intval($status));
  153. }
  154. if (!empty($start_time)) {
  155. $query->where('addtime', '>=' , strtotime($start_time));
  156. }
  157. if (!empty($end_time)) {
  158. $query->where('addtime', '<=' ,strtotime($end_time));
  159. }
  160. if (!empty($start_time) && !empty($end_time)) {
  161. $query->where('addtime', 'between' , [strtotime($start_time),strtotime($end_time)]);
  162. }
  163. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  164. if (!empty($keyword)) {
  165. $query->where('uid', 'like', "%$keyword%");
  166. }
  167. })
  168. ->order("addtime DESC")
  169. ->paginate(20);
  170. $lists->each(function($v,$k){
  171. $userinfo=Db::name("user")
  172. ->field("user_nickname")
  173. ->where("id='$v[uid]'")
  174. ->find();
  175. $v['userinfo']= $userinfo;
  176. $userinfo=Db::name("user")
  177. ->field("user_nickname,user_status")
  178. ->where("id='$v[touid]'")
  179. ->find();
  180. $v['touserinfo']= $userinfo;
  181. return $v;
  182. });
  183. //分页-->筛选条件参数
  184. $data = $this->request->param();
  185. $lists->appends($data);
  186. // 获取分页显示
  187. $page = $lists->render();
  188. $this->assign('lists', $lists);
  189. $this->assign('page', $page);
  190. return $this->fetch();
  191. }
  192. //标记处理
  193. public function setstatus(){
  194. $id = $this->request->param('id');
  195. if($id){
  196. $data['status']=1;
  197. $data['uptime']=time();
  198. $result=Db::name("user_report")
  199. ->where("id='{$id}'")
  200. ->update($data);
  201. if($result){
  202. $reportInfo=Db::name("user_report")
  203. ->where("id={$id}")
  204. ->find();
  205. $reportedUserInfo=Db::name("user")
  206. ->where("id={$reportInfo['touid']}")
  207. ->field("id,user_nickname")
  208. ->find();
  209. $uid=$reportInfo['uid'];
  210. $baseMsg='您于'.date("Y-m-d H:i:s",$reportInfo['addtime']).'对'.$reportedUserInfo['user_nickname'].'的举报已被管理员于'.date("Y-m-d H:i:s",time()).'进行处理';
  211. $text="用户举报处理提醒";
  212. $result1=addSysytemInfo($uid,$text,$baseMsg);
  213. if($result1!==false){
  214. //发送腾讯云IM
  215. txMessageIM($text,$uid);
  216. }
  217. $this->success('标记成功');
  218. }else{
  219. $this->error('标记失败');
  220. }
  221. }else{
  222. $this->error('数据传入失败!');
  223. }
  224. }
  225. //拉黑用户
  226. public function ban(){
  227. $id = $this->request->param('id');
  228. if ($id) {
  229. $rst = Db::name("user")
  230. ->where(array("id"=>$id,"user_type"=>2))
  231. ->update(['user_status'=>'0']);
  232. if ($rst!==false) {
  233. $this->success("会员拉黑成功!");
  234. } else {
  235. $this->error('会员拉黑失败!');
  236. }
  237. } else {
  238. $this->error('数据传入失败!');
  239. }
  240. }
  241. //下架视频
  242. public function ban_video(){
  243. $id = $this->request->param('id');
  244. if($id){
  245. $rst = Db::name("user_video")
  246. ->where(array("uid"=>$id))
  247. ->update(['isdel'=>'1']);
  248. if ($rst!==false) {
  249. $this->success("被举报用户所有视频下架成功!");
  250. } else {
  251. $this->error('视频下架失败!');
  252. }
  253. }else {
  254. $this->error('数据传入失败!');
  255. }
  256. }
  257. //标记处理+禁用用户+下架视频
  258. public function ban_all(){
  259. $id = $this->request->param('id');
  260. if($id){
  261. $data['status']=1;
  262. $data['uptime']=time();
  263. //标记处理
  264. $result=Db::name("user_report")
  265. ->where("id='{$id}'")
  266. ->update($data);
  267. //获取该举报信息对应的用户
  268. $info=Db::name("user_report")
  269. ->where("id='{$id}'")
  270. ->find();
  271. //用户禁用
  272. Db::name("user")
  273. ->where(array("id"=>$info['touid'],"user_type"=>2))
  274. ->update(['user_status'=>'0']);
  275. //下架视频
  276. Db::name("user_video")
  277. ->where(array("uid"=>$info['touid']))
  278. ->update(['isdel'=>'1']);
  279. $this->success("操作成功!");
  280. }else {
  281. $this->error('数据传入失败!');
  282. }
  283. }
  284. /*删除举报*/
  285. public function del(){
  286. $id = $this->request->param('id');
  287. if($id){
  288. $result=Db::name("user_report")
  289. ->where("id={$id}")
  290. ->delete();
  291. if($result){
  292. $this->success('删除成功');
  293. }else{
  294. $this->error('删除失败');
  295. }
  296. }else{
  297. $this->error('数据传入失败!');
  298. }
  299. }
  300. }