CommunityReply.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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. class CommunityReply extends BaseController
  20. {
  21. /**
  22. * @var CommunityReplyRepository
  23. */
  24. protected $repository;
  25. /**
  26. * User constructor.
  27. * @param App $app
  28. * @param $repository
  29. */
  30. public function __construct(App $app, repository $repository)
  31. {
  32. parent::__construct($app);
  33. $this->repository = $repository;
  34. if (!systemConfig('community_status')) throw new ValidateException('未开启社区功能');
  35. }
  36. /**
  37. * @return mixed
  38. * @author Qinii
  39. */
  40. public function lst($id)
  41. {
  42. if (!systemConfig('community_reply_status'))
  43. return app('json')->success([
  44. 'count' => 0,
  45. 'all' => 0,
  46. 'start' => 0,
  47. 'list' => []
  48. ]);
  49. $where['community_id'] = $id;
  50. [$page, $limit] = $this->getPage();
  51. $userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  52. return app('json')->success($this->repository->getApiList($where, $page, $limit, $userInfo));
  53. }
  54. /**
  55. * TODO 发评论
  56. * @param $id
  57. * @return \think\response\Json
  58. * @author Qinii
  59. * @day 10/29/21
  60. */
  61. public function create($id)
  62. {
  63. if (!systemConfig('community_reply_status'))
  64. return app('json')->fail('评论功能未开启');
  65. if (systemConfig('community_reply_auth') && !$this->request->userInfo()->phone)
  66. return app('json')->fail('请先绑定手机号');
  67. $replyId = $this->request->param('reply_id', 0);
  68. $data = $this->request->params(['content']);
  69. if (empty($data['content'])) return app('json')->fail('请输入回复内容');
  70. MiniProgramService::create()->msgSecCheck($this->request->userInfo(), $data['content'],2,0);
  71. $data['uid'] = $this->request->userInfo()->uid;
  72. $data['community_id'] = $id;
  73. $data['status'] = 1;
  74. $msg = '回复成功';
  75. if (systemConfig('community_reply_audit')) {
  76. $data['status'] = 0;
  77. $msg = '回复成功,正在审核中';
  78. }
  79. $ret = $this->repository->create($replyId, $data);
  80. return app('json')->success($msg, $ret);
  81. }
  82. public function delete($id)
  83. {
  84. if (!$this->repository->uidExists($id, $this->request->userInfo()->uid))
  85. return app('json')->fail('评论不存在');
  86. $this->repository->delete($id);
  87. return app('json')->success('评论删除');
  88. }
  89. /**
  90. * TODO 评论点赞
  91. * @param $id
  92. * @return \think\response\Json
  93. * @author Qinii
  94. * @day 10/29/21
  95. */
  96. public function start($id)
  97. {
  98. if (!systemConfig('community_reply_status'))
  99. return app('json')->success('评论不存在');
  100. $status = $this->request->param('status') == 1 ? 1 : 0;
  101. if (!$this->repository->exists($id))
  102. return app('json')->fail('评论不存在');
  103. $uid = $this->request->userInfo()->uid;
  104. $this->repository->setStart($id, $uid, $status);
  105. if ($status) {
  106. return app('json')->success('点赞成功');
  107. } else {
  108. return app('json')->success('取消点赞');
  109. }
  110. }
  111. }