Report.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use Think\Db;
  5. /**
  6. * 用户举报管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Report extends Backend
  11. {
  12. /**
  13. * Report模型对象
  14. * @var \app\admin\model\user\Report
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\user\Report;
  21. }
  22. public function import()
  23. {
  24. parent::import();
  25. }
  26. /**
  27. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  28. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  29. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  30. */
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //当前是否为关联查询
  37. $this->relationSearch = true;
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. //如果发送的来源是Selectpage,则转发到Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  46. $list = $this->model
  47. ->with(['user','ruser','reporttype'])
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->paginate($limit);
  51. foreach ($list as $row) {
  52. $row->getRelation('user')->visible(['nickname']);
  53. $row->getRelation('ruser')->visible(['nickname']);
  54. $row->getRelation('reporttype')->visible(['name']);
  55. }
  56. $result = array("total" => $list->total(), "rows" => $list->items());
  57. return json($result);
  58. }
  59. return $this->view->fetch();
  60. }
  61. /**
  62. * 编辑
  63. */
  64. public function edit($ids = null)
  65. {
  66. $row = $this->model->get($ids);
  67. if (!$row) {
  68. $this->error(__('No Results were found'));
  69. }
  70. $adminIds = $this->getDataLimitAdminIds();
  71. if (is_array($adminIds)) {
  72. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  73. $this->error(__('You have no permission'));
  74. }
  75. }
  76. if ($this->request->isPost()) {
  77. $params = $this->request->post("row/a");
  78. if ($params) {
  79. $params = $this->preExcludeFields($params);
  80. $result = false;
  81. Db::startTrans();
  82. if ($params['status'] == 1) {
  83. //发送通知
  84. $title = '举报处理结果';
  85. $content = '您的举报后台已经处理,备注:' . $params['remarks'];
  86. \app\common\model\SysMsg::sendSysMsg($row['user_id'],9,$title,$content);
  87. }
  88. try {
  89. //是否采用模型验证
  90. if ($this->modelValidate) {
  91. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  92. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  93. $row->validateFailException(true)->validate($validate);
  94. }
  95. $result = $row->allowField(true)->save($params);
  96. Db::commit();
  97. } catch (ValidateException $e) {
  98. Db::rollback();
  99. $this->error($e->getMessage());
  100. } catch (PDOException $e) {
  101. Db::rollback();
  102. $this->error($e->getMessage());
  103. } catch (Exception $e) {
  104. Db::rollback();
  105. $this->error($e->getMessage());
  106. }
  107. if ($result !== false) {
  108. $this->success();
  109. } else {
  110. $this->error(__('No rows were updated'));
  111. }
  112. }
  113. $this->error(__('Parameter %s can not be empty', ''));
  114. }
  115. $this->view->assign("row", $row);
  116. return $this->view->fetch();
  117. }
  118. }