Comment.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\api\controller;
  15. use app\api\BaseController;
  16. use think\facade\Db;
  17. use app\api\model\Comment as CommentModel;
  18. class Comment extends BaseController
  19. {
  20. /**
  21. * 构造函数
  22. */
  23. protected $model;
  24. public function __construct()
  25. {
  26. parent::__construct(); // 调用父类构造函数
  27. $this->model = new CommentModel();
  28. }
  29. //获取评论列表
  30. public function datalist()
  31. {
  32. $param = get_params();
  33. $param['admin_id'] = $this->uid;
  34. $where=[];
  35. if (!empty($param['module'])) {
  36. $where[] = ['module', '=', $param['module']];
  37. }
  38. if (!empty($param['topic_id'])) {
  39. $where['topic_id'] = $param['topic_id'];
  40. }
  41. $where[] = ['delete_time', '=', 0];
  42. $list = $this->model->datalist($param,$where);
  43. $total = Db::name('Comment')->where($where)->count();
  44. $totalRow['total'] = $total;
  45. return table_assign(0, '', $list,$totalRow);
  46. }
  47. //添加修改评论内容
  48. public function add()
  49. {
  50. $param = get_params();
  51. if (!empty($param['id']) && $param['id'] > 0) {
  52. $param['update_time'] = time();
  53. unset($param['pid']);
  54. unset($param['padmin_id']);
  55. $res = CommentModel::where(['admin_id' => $this->uid,'id'=>$param['id']])->strict(false)->field(true)->update($param);
  56. if ($res!==false) {
  57. add_log('edit', $param['id'], $param,'评论');
  58. return to_assign();
  59. }
  60. } else {
  61. $param['create_time'] = time();
  62. $param['admin_id'] = $this->uid;
  63. $insertId = CommentModel::strict(false)->field(true)->insertGetId($param);
  64. if ($insertId) {
  65. add_log('add', $insertId, $param,'评论');
  66. return to_assign();
  67. }
  68. }
  69. }
  70. //设为已读评论内容
  71. public function view()
  72. {
  73. if (request()->isPost()) {
  74. $id = get_params("id");
  75. $res = Db::name('CommentRead')->strict(false)->field(true)->insertGetId(['comment_id'=>$id,'admin_id'=>$this->uid,'create_time'=>time()]);
  76. if ($res!==false) {
  77. add_log('view', $id,[],'评论');
  78. return to_assign(0, "操作成功");
  79. } else {
  80. return to_assign(1, "操作失败");
  81. }
  82. }else{
  83. return to_assign(1, "错误的请求");
  84. }
  85. }
  86. //删除评论内容
  87. public function del()
  88. {
  89. if (request()->isDelete()) {
  90. $id = get_params("id");
  91. $res = CommentModel::where('id',$id)->strict(false)->field(true)->update(['delete_time'=>time()]);
  92. if ($res) {
  93. add_log('delete', $id,[],'评论');
  94. return to_assign(0, "删除成功");
  95. } else {
  96. return to_assign(1, "删除失败");
  97. }
  98. }else{
  99. return to_assign(1, "错误的请求");
  100. }
  101. }
  102. }