CommunityReply.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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\admin\community;
  12. use crmeb\basic\BaseController;
  13. use think\App;
  14. use app\common\repositories\community\CommunityReplyRepository as repository;
  15. /**
  16. * 社区评论
  17. */
  18. class CommunityReply extends BaseController
  19. {
  20. /**
  21. * @var CommunityReplyRepository
  22. */
  23. protected $repository;
  24. /**
  25. * CommunityReplyRepository
  26. * @param App $app
  27. * @param $repository
  28. */
  29. public function __construct(App $app, repository $repository)
  30. {
  31. parent::__construct($app);
  32. $this->repository = $repository;
  33. }
  34. /**
  35. * 列表
  36. * @return mixed
  37. * @author Qinii
  38. */
  39. public function lst()
  40. {
  41. $where = $this->request->params(['keyword', 'date', 'username', 'community_id', 'pid']);
  42. [$page, $limit] = $this->getPage();
  43. return app('json')->success($this->repository->getList($where, $page, $limit));
  44. }
  45. public function reply($id)
  46. {
  47. $where['community_id'] = $id;
  48. [$page, $limit] = $this->getPage();
  49. return app('json')->success($this->repository->getList($where, $page, $limit));
  50. }
  51. /**
  52. * 删除
  53. * @param $id
  54. * @return mixed
  55. * @author Qinii
  56. */
  57. public function delete($id)
  58. {
  59. if (!$this->repository->exists($id))
  60. return app('json')->fail('数据不存在');
  61. $this->repository->update($id, ['is_del' => 1]);
  62. return app('json')->success('删除成功');
  63. }
  64. /**
  65. * 审核表单
  66. * @param $id
  67. * @return \think\response\Json
  68. * @author Qinii
  69. */
  70. public function statusForm($id)
  71. {
  72. if (!$this->repository->exists($id))
  73. return app('json')->fail('数据不存在');
  74. return app('json')->success(formToData($this->repository->statusForm($id)));
  75. }
  76. /**
  77. * 审核
  78. * @param $id
  79. * @return \think\response\Json
  80. * @author Qinii
  81. */
  82. public function switchStatus($id)
  83. {
  84. $data = $this->request->params(['status', 'refusal']);
  85. if (!in_array($data['status'], [1, -1]))
  86. return app('json')->fail('审核类型错误');
  87. if ($data['status'] == -1 && empty($data['refusal']))
  88. return app('json')->fail('请填写拒绝理由');
  89. if (!$this->repository->exists($id))
  90. return app('json')->fail('数据不存在');
  91. $this->repository->update($id, $data);
  92. return app('json')->success('审核成功');
  93. }
  94. }