Community.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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\admin\community;
  12. use crmeb\basic\BaseController;
  13. use think\App;
  14. use app\common\repositories\community\CommunityRepository as repository;
  15. class Community extends BaseController
  16. {
  17. /**
  18. * @var CommunityRepository
  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. public function title()
  32. {
  33. $where['is_del'] = 0;
  34. return app('json')->success($this->repository->title($where));
  35. }
  36. /**
  37. * @return mixed
  38. * @author Qinii
  39. */
  40. public function lst()
  41. {
  42. $where = $this->request->params(['keyword','status','username','category_id','topic_id','is_show','is_type']);
  43. $where['order'] = 'start';
  44. $where['is_del'] = 0;
  45. [$page, $limit] = $this->getPage();
  46. return app('json')->success($this->repository->getList($where, $page, $limit));
  47. }
  48. /**
  49. * @param $id
  50. * @return mixed
  51. * @author Qinii
  52. */
  53. public function detail($id)
  54. {
  55. if (!$this->repository->exists($id))
  56. return app('json')->fail('数据不存在');
  57. return app('json')->success($this->repository->detail($id));
  58. }
  59. public function updateForm($id)
  60. {
  61. return app('json')->success(formToData($this->repository->form($id)));
  62. }
  63. public function showForm($id)
  64. {
  65. return app('json')->success(formToData($this->repository->showForm($id)));
  66. }
  67. public function update($id)
  68. {
  69. $data['start'] = $this->request->param('start',1);
  70. if (!$this->repository->exists($id))
  71. return app('json')->fail('数据不存在');
  72. $this->repository->update($id,$data);
  73. return app('json')->success('修改成功');
  74. }
  75. /**
  76. * @param $id
  77. * @return mixed
  78. * @author Qinii
  79. */
  80. public function delete($id)
  81. {
  82. if (!$this->repository->exists($id))
  83. return app('json')->fail('数据不存在');
  84. $this->repository->destory($id);
  85. return app('json')->success('删除成功');
  86. }
  87. public function switchStatus($id)
  88. {
  89. $data = $this->request->params(['status', 'refusal']);
  90. if (!in_array($data['status'],[0,1,-1,-2]))
  91. return app('json')->fail('状态类型错误');
  92. $data['is_show'] = ($data['status'] == 1) ? : 0;
  93. if($data['status'] == -1 && empty($data['refusal']))
  94. return app('json')->fail('请填写拒绝理由');
  95. if($data['status'] == -2 && empty($data['refusal']))
  96. return app('json')->fail('请填写下架原因');
  97. if (!$this->repository->exists($id))
  98. return app('json')->fail('数据不存在');
  99. $this->repository->setStatus($id,$data);
  100. return app('json')->success('操作成功');
  101. }
  102. public function switchShow($id)
  103. {
  104. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  105. if (!$this->repository->exists($id))
  106. return app('json')->fail('数据不存在');
  107. $this->repository->update($id,['is_show' => $status]);
  108. return app('json')->success('修改成功');
  109. }
  110. }