Community.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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\CommunityRepository as repository;
  15. /**
  16. * 社区图文
  17. */
  18. class Community extends BaseController
  19. {
  20. protected $repository;
  21. /**
  22. * User constructor.
  23. * @param App $app
  24. * @param $repository
  25. */
  26. public function __construct(App $app, repository $repository)
  27. {
  28. parent::__construct($app);
  29. $this->repository = $repository;
  30. }
  31. /**
  32. * 头部统计
  33. * @return mixed
  34. * @author Qinii
  35. */
  36. public function title()
  37. {
  38. $where['is_del'] = 0;
  39. return app('json')->success($this->repository->title($where));
  40. }
  41. /**
  42. * 列表
  43. * @return mixed
  44. * @author Qinii
  45. */
  46. public function lst()
  47. {
  48. $where = $this->request->params(['keyword', 'status', 'username', 'category_id', 'topic_id', 'is_show', 'is_type','uid','phone','real_name','nickname']);
  49. $where['order'] = 'start';
  50. $where['is_del'] = 0;
  51. [$page, $limit] = $this->getPage();
  52. return app('json')->success($this->repository->getList($where, $page, $limit));
  53. }
  54. /**
  55. * 详情
  56. * @param $id
  57. * @return mixed
  58. * @author Qinii
  59. */
  60. public function detail($id)
  61. {
  62. if (!$this->repository->exists($id))
  63. return app('json')->fail('数据不存在');
  64. return app('json')->success($this->repository->detail($id));
  65. }
  66. /**
  67. * 设置排序表单
  68. * @param $id
  69. * @return \think\response\Json
  70. * @author Qinii
  71. */
  72. public function updateForm($id)
  73. {
  74. return app('json')->success(formToData($this->repository->form($id)));
  75. }
  76. /**
  77. * 强制下架表单
  78. * @param $id
  79. * @return \think\response\Json
  80. * @author Qinii
  81. */
  82. public function showForm($id)
  83. {
  84. return app('json')->success(formToData($this->repository->showForm($id)));
  85. }
  86. /**
  87. * 设置星际
  88. * @param $id
  89. * @return \think\response\Json
  90. * @author Qinii
  91. */
  92. public function update($id)
  93. {
  94. $data['start'] = $this->request->param('start', 1);
  95. if (!$this->repository->exists($id))
  96. return app('json')->fail('数据不存在');
  97. $this->repository->update($id, $data);
  98. return app('json')->success('修改成功');
  99. }
  100. /**
  101. * 删除
  102. * @param $id
  103. * @return mixed
  104. * @author Qinii
  105. */
  106. public function delete($id)
  107. {
  108. if (!$this->repository->exists($id))
  109. return app('json')->fail('数据不存在');
  110. $this->repository->destory($id);
  111. return app('json')->success('删除成功');
  112. }
  113. /**
  114. * 商品审核
  115. * @param $id
  116. * @return \think\response\Json
  117. * FerryZhao 2024/4/18
  118. */
  119. public function switchStatus($id)
  120. {
  121. $data = $this->request->params(['status', 'refusal']);
  122. if (!in_array($data['status'], [0, 1, -1, -2]))
  123. return app('json')->fail('状态类型错误');
  124. $data['is_show'] = ($data['status'] == 1) ?: 0;
  125. if ($data['status'] == -1 && empty($data['refusal']))
  126. return app('json')->fail('请填写拒绝理由');
  127. if ($data['status'] == -2 && empty($data['refusal']))
  128. return app('json')->fail('请填写下架原因');
  129. if (!$this->repository->exists($id))
  130. return app('json')->fail('数据不存在');
  131. $this->repository->setStatus($id, $data);
  132. return app('json')->success('操作成功');
  133. }
  134. /**
  135. * 显示隐藏
  136. * @param $id
  137. * @return \think\response\Json
  138. * @author Qinii
  139. */
  140. public function switchShow($id)
  141. {
  142. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  143. if (!$this->repository->exists($id))
  144. return app('json')->fail('数据不存在');
  145. $this->repository->update($id, ['is_show' => $status]);
  146. return app('json')->success('修改成功');
  147. }
  148. }