Comment.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\admin\controller\cms;
  3. use app\common\controller\Backend;
  4. use app\common\model\User;
  5. use think\Db;
  6. use think\exception\PDOException;
  7. /**
  8. * 评论管理
  9. *
  10. * @icon fa fa-comment
  11. */
  12. class Comment extends Backend
  13. {
  14. /**
  15. * Comment模型对象
  16. */
  17. protected $model = null;
  18. protected $searchFields = 'id,aid,content';
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\cms\Comment;
  23. $this->view->assign("typeList", $this->model->getTypeList());
  24. $this->view->assign("statusList", $this->model->getStatusList());
  25. }
  26. /**
  27. * 查看
  28. */
  29. public function index()
  30. {
  31. $this->relationSearch = true;
  32. //设置过滤方法
  33. $this->request->filter(['strip_tags']);
  34. if ($this->request->isAjax()) {
  35. //如果发送的来源是Selectpage,则转发到Selectpage
  36. if ($this->request->request('keyField')) {
  37. return $this->selectpage();
  38. }
  39. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  40. $total = $this->model
  41. ->where($where)
  42. ->order($sort, $order)
  43. ->count();
  44. $list = $this->model
  45. ->where($where)
  46. ->order($sort, $order)
  47. ->limit($offset, $limit)
  48. ->select();
  49. foreach ($list as $index => $item) {
  50. $item->user->visible(['id', 'username', 'nickname', 'avatar']);
  51. $item->source = $item->source;
  52. }
  53. $list = collection($list)->toArray();
  54. $result = array("total" => $total, "rows" => $list);
  55. return json($result);
  56. }
  57. $this->assignconfig("typeList", $this->model->getTypeList());
  58. return $this->view->fetch();
  59. }
  60. public function recyclebin()
  61. {
  62. //设置过滤方法
  63. $this->request->filter(['strip_tags']);
  64. if ($this->request->isAjax()) {
  65. $this->relationSearch = true;
  66. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  67. $total = $this->model
  68. ->onlyTrashed()
  69. ->with(['archives', 'spage', 'user'])
  70. ->where($where)
  71. ->order($sort, $order)
  72. ->count();
  73. $list = $this->model
  74. ->onlyTrashed()
  75. ->with(['archives', 'spage', 'user'])
  76. ->where($where)
  77. ->order($sort, $order)
  78. ->limit($offset, $limit)
  79. ->select();
  80. foreach ($list as $index => $item) {
  81. $item->user->visible(['id', 'username', 'nickname', 'avatar']);
  82. $type = $item['type'] == 'page' ? 'spage' : $item['type'];
  83. $item->url = $item->{$type} ? $item->{$type}->url : 'javascript:';
  84. }
  85. $list = collection($list)->toArray();
  86. $result = array("total" => $total, "rows" => $list);
  87. return json($result);
  88. }
  89. return $this->view->fetch();
  90. }
  91. public function restore($ids = "")
  92. {
  93. if (!$this->request->isPost()) {
  94. $this->error(__("Invalid parameters"));
  95. }
  96. $pk = $this->model->getPk();
  97. $adminIds = $this->getDataLimitAdminIds();
  98. if (is_array($adminIds)) {
  99. $this->model->where($this->dataLimitField, 'in', $adminIds);
  100. }
  101. if ($ids) {
  102. $this->model->where($pk, 'in', $ids);
  103. }
  104. $config = get_addon_config('cms');
  105. $list = $this->model->onlyTrashed()->select();
  106. if ($list) {
  107. $ids = [];
  108. foreach ($list as $index => $item) {
  109. if ($item['status'] == 'normal') {
  110. User::score($config['score']['postcomment'], $item['user_id'], '发表评论');
  111. }
  112. $ids[] = $item['id'];
  113. }
  114. $this->model->where('id', 'in', $ids);
  115. $this->model->restore('1=1');
  116. foreach ($list as $index => $item) {
  117. \app\admin\model\cms\Comment::refreshSourceComments($item['id']);
  118. }
  119. $this->success();
  120. }
  121. $this->error(__('No rows were updated'));
  122. }
  123. }