Report.php 4.9 KB

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