SystemConfigTab.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\setting;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\system\config\SystemConfigServices;
  14. use app\services\system\config\SystemConfigTabServices;
  15. use think\facade\App;
  16. /**
  17. * 配置分类
  18. * Class SystemConfigTab
  19. * @package app\adminapi\controller\v1\setting
  20. */
  21. class SystemConfigTab extends AuthController
  22. {
  23. /**
  24. * g构造方法
  25. * SystemConfigTab constructor.
  26. * @param App $app
  27. * @param SystemConfigTabServices $services
  28. */
  29. public function __construct(App $app, SystemConfigTabServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**
  35. * 显示资源列表
  36. *
  37. * @return \think\Response
  38. */
  39. public function index()
  40. {
  41. $where = $this->request->getMore([
  42. ['status', ''],
  43. ['title', '']
  44. ]);
  45. return app('json')->success($this->services->getConfgTabList($where));
  46. }
  47. /**
  48. * 显示创建资源表单页.
  49. *
  50. * @return \think\Response
  51. */
  52. public function create()
  53. {
  54. return app('json')->success($this->services->createForm());
  55. }
  56. /**
  57. * 保存新建的资源
  58. *
  59. * @return \think\Response
  60. */
  61. public function save()
  62. {
  63. $data = $this->request->postMore([
  64. 'eng_title',
  65. 'status',
  66. 'title',
  67. 'icon',
  68. ['type', 0],
  69. ['sort', 0],
  70. ['pid', 0],
  71. ['menus_id', 0],
  72. ]);
  73. if (is_array($data['pid'])) $data['pid'] = end($data['pid']);
  74. if (!$data['title']) return app('json')->fail(400291);
  75. $this->services->save($data);
  76. return app('json')->success(400292);
  77. }
  78. /**
  79. * 显示指定的资源
  80. *
  81. * @param int $id
  82. * @return \think\Response
  83. */
  84. public function read($id)
  85. {
  86. //
  87. }
  88. /**
  89. * 显示编辑资源表单页.
  90. *
  91. * @param int $id
  92. * @return \think\Response
  93. */
  94. public function edit($id)
  95. {
  96. return app('json')->success($this->services->updateForm((int)$id));
  97. }
  98. /**
  99. * 保存更新的资源
  100. *
  101. * @param int $id
  102. * @return \think\Response
  103. */
  104. public function update($id)
  105. {
  106. $data = $this->request->postMore([
  107. 'title',
  108. 'status',
  109. 'eng_title',
  110. 'icon',
  111. ['type', 0],
  112. ['sort', 0],
  113. ['pid', 0],
  114. ['menus_id', 0],
  115. ]);
  116. if (is_array($data['pid'])) $data['pid'] = end($data['pid']);
  117. if (!$data['title']) return app('json')->fail(400291);
  118. if (!$data['eng_title']) return app('json')->fail(400275);
  119. $this->services->update($id, $data);
  120. return app('json')->success(100001);
  121. }
  122. /**
  123. * 删除指定资源
  124. *
  125. * @param int $id
  126. * @return \think\Response
  127. */
  128. public function delete(SystemConfigServices $services, $id)
  129. {
  130. if ($services->count(['tab_id' => $id])) {
  131. return app('json')->fail(400293);
  132. }
  133. if (!$this->services->delete($id))
  134. return app('json')->fail(100008);
  135. else
  136. return app('json')->success(100002);
  137. }
  138. /**
  139. * 修改状态
  140. * @param $id
  141. * @param $status
  142. * @return mixed
  143. */
  144. public function set_status($id, $status)
  145. {
  146. if ($status == '' || $id == 0) {
  147. return app('json')->fail(100100);
  148. }
  149. $this->services->update($id, ['status' => $status]);
  150. return app('json')->success(100014);
  151. }
  152. }