CommunityReply.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\community;
  12. use app\common\repositories\community\CommunityRepository;
  13. use app\common\repositories\system\RelevanceRepository;
  14. use crmeb\basic\BaseController;
  15. use crmeb\services\MiniProgramService;
  16. use think\App;
  17. use app\common\repositories\community\CommunityReplyRepository as repository;
  18. use think\exception\ValidateException;
  19. /**
  20. * Class CommunityReply
  21. * app\controller\api\community
  22. * 社区评论
  23. */
  24. class CommunityReply extends BaseController
  25. {
  26. /**
  27. * @var CommunityReplyRepository
  28. */
  29. protected $repository;
  30. /**
  31. * User constructor.
  32. * @param App $app
  33. * @param $repository
  34. */
  35. public function __construct(App $app, repository $repository)
  36. {
  37. parent::__construct($app);
  38. $this->repository = $repository;
  39. if (!systemConfig('community_status')) throw new ValidateException('未开启社区功能');
  40. }
  41. /**
  42. * 列表
  43. * @return mixed
  44. * @author Qinii
  45. */
  46. public function lst($id)
  47. {
  48. if (!systemConfig('community_reply_status'))
  49. return app('json')->success([
  50. 'count' => 0,
  51. 'all' => 0,
  52. 'start' => 0,
  53. 'list' => []
  54. ]);
  55. $where['community_id'] = $id;
  56. [$page, $limit] = $this->getPage();
  57. $userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  58. return app('json')->success($this->repository->getApiList($where, $page, $limit, $userInfo));
  59. }
  60. /**
  61. * 发评论
  62. * @param $id
  63. * @return \think\response\Json
  64. * @author Qinii
  65. * @day 10/29/21
  66. */
  67. public function create($id)
  68. {
  69. if (!systemConfig('community_reply_status'))
  70. return app('json')->fail('评论功能未开启');
  71. if (systemConfig('community_reply_auth') && !$this->request->userInfo()->phone)
  72. return app('json')->fail('请先绑定手机号');
  73. $replyId = $this->request->param('reply_id', 0);
  74. $data = $this->request->params(['content']);
  75. if (empty($data['content'])) return app('json')->fail('请输入回复内容');
  76. MiniProgramService::create()->msgSecCheck($this->request->userInfo(), $data['content'],2,0);
  77. $data['uid'] = $this->request->userInfo()->uid;
  78. $data['community_id'] = $id;
  79. $data['status'] = 1;
  80. $msg = '回复成功';
  81. if (systemConfig('community_reply_audit')) {
  82. $data['status'] = 0;
  83. $msg = '回复成功,正在审核中';
  84. }
  85. $ret = $this->repository->create($replyId, $data);
  86. return app('json')->success($msg, $ret);
  87. }
  88. /**
  89. * 删除评论
  90. * @param $id
  91. * @return \think\response\Json
  92. * @author Qinii
  93. * @day 10/29/21
  94. */
  95. public function delete($id)
  96. {
  97. if (!$this->repository->uidExists($id, $this->request->userInfo()->uid))
  98. return app('json')->fail('评论不存在');
  99. $this->repository->delete($id);
  100. return app('json')->success('评论删除');
  101. }
  102. /**
  103. * 评论点赞
  104. * @param $id
  105. * @return \think\response\Json
  106. * @author Qinii
  107. * @day 10/29/21
  108. */
  109. public function start($id)
  110. {
  111. if (!systemConfig('community_reply_status'))
  112. return app('json')->success('评论不存在');
  113. $status = $this->request->param('status') == 1 ? 1 : 0;
  114. if (!$this->repository->exists($id))
  115. return app('json')->fail('评论不存在');
  116. $uid = $this->request->userInfo()->uid;
  117. $this->repository->setStart($id, $uid, $status);
  118. if ($status) {
  119. return app('json')->success('点赞成功');
  120. } else {
  121. return app('json')->success('取消点赞');
  122. }
  123. }
  124. }