PageCategroy.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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\system\diy;
  12. use app\common\repositories\system\diy\PageCategoryRepository;
  13. use app\common\repositories\system\diy\PageLinkRepository;
  14. use crmeb\basic\BaseController;
  15. use think\App;
  16. /**
  17. * 页面链接分类
  18. */
  19. class PageCategroy extends BaseController
  20. {
  21. protected $repository;
  22. public function __construct(App $app, PageCategoryRepository $repository)
  23. {
  24. parent::__construct($app);
  25. $this->repository = $repository;
  26. }
  27. /**
  28. * 列表
  29. * @return mixed
  30. * @author Qinii
  31. */
  32. public function lst()
  33. {
  34. $where['is_mer'] = $this->request->param('type', 0);
  35. return app('json')->success($this->repository->getFormatList($where));
  36. }
  37. /**
  38. * 创建表单
  39. * @Author:Qinii
  40. * @Date: 2020/5/11
  41. * @return mixed
  42. */
  43. public function createForm()
  44. {
  45. $type = $this->request->param('type', 0);
  46. return app('json')->success(formToData($this->repository->form(0, $type)));
  47. }
  48. /**
  49. * 添加
  50. * @Author:Qinii
  51. * @Date: 2020/5/11
  52. * @return mixed
  53. */
  54. public function create()
  55. {
  56. $data = $this->request->params([
  57. 'pid',
  58. 'type',
  59. 'name',
  60. 'status',
  61. 'sort',
  62. 'is_mer',
  63. ['level', 3],
  64. ]);
  65. $this->repository->create($data);
  66. return app('json')->success('添加成功');
  67. }
  68. /**
  69. * 修改表单
  70. * @Author:Qinii
  71. * @Date: 2020/5/11
  72. * @param $id
  73. * @return mixed
  74. */
  75. public function updateForm($id)
  76. {
  77. return app('json')->success(formToData($this->repository->form($id)));
  78. }
  79. /**
  80. * 修改
  81. * @Author:Qinii
  82. * @Date: 2020/5/11
  83. * @param $id
  84. * @return mixed
  85. */
  86. public function update($id)
  87. {
  88. $data = $this->request->params([
  89. 'pid',
  90. 'type',
  91. 'name',
  92. 'status',
  93. 'sort',
  94. 'is_mer'
  95. ]);
  96. $this->repository->update($id, $data);
  97. return app('json')->success('编辑成功');
  98. }
  99. /**
  100. * 获取子分类
  101. * @Author:Qinii
  102. * @Date: 2020/5/11
  103. * @return mixed
  104. */
  105. public function options()
  106. {
  107. $type = $this->request->param('type', 0);
  108. return app('json')->success($this->repository->getSonCategoryList($type, 0));
  109. }
  110. /**
  111. * 修改表单
  112. * @param $id
  113. * @return \think\response\Json
  114. * @author Qinii
  115. */
  116. public function switchStatus($id)
  117. {
  118. $status = $this->request->param('status') == 1 ? 1 : 0;
  119. $this->repository->update($id, ['status' => $status]);
  120. return app('json')->success('修改成功');
  121. }
  122. /**
  123. * 删除
  124. * @param $id
  125. * @return \think\response\Json
  126. * @author Qinii
  127. */
  128. public function delete($id)
  129. {
  130. $this->repository->delete($id);
  131. return app('json')->success('删除成功');
  132. }
  133. }