FeedBackCategory.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-06-08
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\user;
  11. use crmeb\basic\BaseController;
  12. use think\App;
  13. use app\common\repositories\user\FeedBackCategoryRepository as repository;
  14. class FeedBackCategory extends BaseController
  15. {
  16. /**
  17. * @var repository
  18. */
  19. protected $repository;
  20. /**
  21. * User constructor.
  22. * @param App $app
  23. * @param $repository
  24. */
  25. public function __construct(App $app, repository $repository)
  26. {
  27. parent::__construct($app);
  28. $this->repository = $repository;
  29. }
  30. /**
  31. * @return mixed
  32. * @author Qinii
  33. */
  34. public function lst()
  35. {
  36. return app('json')->success($this->repository->getFormatList(0));
  37. }
  38. public function createForm()
  39. {
  40. return app('json')->success(formToData($this->repository->form(0)));
  41. }
  42. public function updateForm($id)
  43. {
  44. if (!$this->repository->merExists(0, $id))
  45. return app('json')->fail('数据不存在');
  46. return app('json')->success(formToData($this->repository->updateForm(0,$id)));
  47. }
  48. public function create()
  49. {
  50. $data = $this->request->params(['pid','cate_name','sort','pic','is_show']);
  51. if(empty($data['cate_name']))
  52. return app('json')->fail('分类名不可为空');
  53. if ($data['pid'] && !$this->repository->merExists(0, $data['pid']))
  54. return app('json')->fail('上级分类不存在');
  55. if ($data['pid'] && !$this->repository->checkLevel($data['pid']))
  56. return app('json')->fail('不可添加更低阶分类');
  57. $this->repository->create($data);
  58. return app('json')->success('添加成功');
  59. }
  60. public function update($id)
  61. {
  62. $data = $this->request->params(['pid','cate_name','sort','pic','is_show']);
  63. if (!$this->repository->merExists(0, $id))
  64. return app('json')->fail('数据不存在');
  65. if ($data['pid'] && !$this->repository->merExists(0, $data['pid']))
  66. return app('json')->fail('上级分类不存在');
  67. if ($data['pid'] && !$this->repository->checkLevel($data['pid']))
  68. return app('json')->fail('不可添加更低阶分类');
  69. if (!$this->repository->checkChangeToChild($id,$data['pid']))
  70. return app('json')->fail('无法修改到当前分类到子集,请先修改子类');
  71. /*if (!$this->repository->checkChildLevel($id,$data['pid']))
  72. return app('json')->fail('子类超过最低限制,请先修改子类');*/
  73. $this->repository->update($id,$data);
  74. return app('json')->success('编辑成功');
  75. }
  76. public function switchStatus($id)
  77. {
  78. $status = $this->request->param('status', 0) == 1 ? 1 : 0;
  79. if (!$this->repository->merExists(0, $id))
  80. return app('json')->fail('数据不存在');
  81. $this->repository->switchStatus($id, $status);
  82. return app('json')->success('修改成功');
  83. }
  84. public function delete($id)
  85. {
  86. if (!$this->repository->merExists(0, $id))
  87. return app('json')->fail('数据不存在');
  88. if ($this->repository->hasChild($id))
  89. return app('json')->fail('该分类存在子集,请先处理子集');
  90. $this->repository->delete($id);
  91. return app('json')->success('删除成功');
  92. }
  93. public function detail($id)
  94. {
  95. if (!$this->repository->merExists(0, $id))
  96. return app('json')->fail('数据不存在');
  97. return app('json')->success($this->repository->get($id));
  98. }
  99. }