AdminIndexController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | d_comment [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 DaliyCode All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: DaliyCode <3471677985@qq.com> <author_url:dalicode.com>
  8. // +----------------------------------------------------------------------
  9. namespace plugins\d_comment\controller;
  10. use app\admin\model\PluginModel;
  11. use app\portal\model\PortalPostModel;
  12. use cmf\controller\PluginBaseController;
  13. use think\Db;
  14. class AdminIndexController extends PluginBaseController {
  15. public function _initialize() {
  16. $where = ['status' => 1, 'name' => $this->getPlugin()->info['name']];
  17. $vo = PluginModel::where($where)->cache(60, true)->find();
  18. if (!$vo) {
  19. $this->error('评论插件未启用!');
  20. }
  21. $adminId = cmf_get_current_admin_id();
  22. if (!empty($adminId)) {
  23. $this->assign("admin_id", $adminId);
  24. } else {
  25. $this->error('请登录!');
  26. }
  27. }
  28. public function index() {
  29. $param = $this->request->param();
  30. $where['c.delete_time'] = 0;
  31. $where['c.status'] = array(0,1);
  32. $where['c.table_name'] = 'portal_post';
  33. $startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
  34. $endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
  35. if (!empty($startTime) && !empty($endTime)) {
  36. $where['c.create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
  37. } else {
  38. if (!empty($startTime)) {
  39. $where['c.create_time'] = ['>= time', $startTime];
  40. }
  41. if (!empty($endTime)) {
  42. $where['c.create_time'] = ['<= time', $endTime];
  43. }
  44. }
  45. $keyword = empty($param['keyword']) ? '' : $param['keyword'];
  46. if (!empty($keyword)) {
  47. $where['c.content|c.more'] = ['like', "%$keyword%"];
  48. }
  49. $status = isset($param['status']) ? $param['status'] : -1;
  50. if ($status > -1) {
  51. $where['c.status'] = (int) $status;
  52. }
  53. $username = empty($param['username']) ? '' : $param['username'];
  54. if (!empty($username)) {
  55. $where['u.user_nickname'] = trim($username);
  56. }
  57. $comments = Db::name('comment')->alias('c')
  58. ->join('__USER__ u', 'c.user_id = u.id', 'left')
  59. ->join('__USER__ ut', 'c.to_user_id = ut.id', 'left')
  60. ->field('c.*,u.user_nickname as username,ut.user_nickname as to_username')
  61. ->where($where)
  62. ->order('c.create_time DESC')
  63. ->paginate(10);
  64. $comments->appends($param);
  65. $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
  66. $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
  67. $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
  68. $this->assign('username', isset($param['username']) ? $param['username'] : '');
  69. $this->assign('status', isset($param['status']) ? $param['status'] : '');
  70. $this->assign('list', $comments);
  71. $this->assign('page', $comments->render());
  72. return $this->fetch('/admin_index');
  73. }
  74. public function del($id = 0, $oid = 0) {
  75. $param = $this->request->param();
  76. $id = $param['id'];
  77. $oid = $param['oid'];
  78. if (Db::name('comment')->where(['id' => (int) $id])->update(['delete_time' => time(), 'status' => 2])) {
  79. PortalPostModel::where('id=' . (int) $oid)->setDec('comment_count');
  80. $this->success('删除成功');
  81. }
  82. $this->error('删除失败');
  83. }
  84. public function pass() {
  85. $param = $this->request->param();
  86. $where['id'] = $param['ids'];
  87. if (Db::name('comment')->where($where)->update(['status' => 1]) !== false) {
  88. $this->success('审核成功');
  89. }
  90. $this->error('审核失败');
  91. }
  92. public function delall() {
  93. $ids = $this->request->param('ids/a');
  94. if (is_array($ids)) {
  95. $d = Db::name('comment')->field('id,object_id')->where('id','in', $ids)->select()->toArray();
  96. Db::name('comment')->where('id','in', array_map('reset', $d))->update(['delete_time' => time(), 'status' => 2]);
  97. $r = array_count_values(array_map('end', $d));
  98. foreach ($r as $key => $v) {
  99. PortalPostModel::where('id=' . $key)->setDec('comment_count', $v);
  100. }
  101. $this->success('删除成功!');
  102. }
  103. $this->success('删除失败!');
  104. }
  105. }