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