SystemConfigTab.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\v1\system\config;
  12. use app\controller\admin\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\controller\admin\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. ['is_store', '']
  45. ]);
  46. return $this->success($this->services->getConfgTabList($where));
  47. }
  48. /**
  49. * 显示创建资源表单页.
  50. *
  51. * @return \think\Response
  52. */
  53. public function create()
  54. {
  55. return $this->success($this->services->createForm());
  56. }
  57. /**
  58. * 保存新建的资源
  59. *
  60. * @return \think\Response
  61. */
  62. public function save()
  63. {
  64. $data = $this->request->postMore([
  65. 'eng_title',
  66. 'status',
  67. 'title',
  68. 'icon',
  69. ['type', 0],
  70. ['sort', 0],
  71. ['pid', []],
  72. ['is_store', 0],
  73. ]);
  74. $data['pid'] = end($data['pid']);
  75. if (!$data['title']) return $this->fail('请输入按钮名称');
  76. $this->services->save($data);
  77. return $this->success('添加配置分类成功!');
  78. }
  79. /**
  80. * 显示指定的资源
  81. *
  82. * @param int $id
  83. * @return \think\Response
  84. */
  85. public function read($id)
  86. {
  87. //
  88. }
  89. /**
  90. * 显示编辑资源表单页.
  91. *
  92. * @param int $id
  93. * @return \think\Response
  94. */
  95. public function edit($id)
  96. {
  97. return $this->success($this->services->updateForm((int)$id));
  98. }
  99. /**
  100. * 保存更新的资源
  101. *
  102. * @param int $id
  103. * @return \think\Response
  104. */
  105. public function update($id)
  106. {
  107. $data = $this->request->postMore([
  108. 'title',
  109. 'status',
  110. 'eng_title',
  111. 'icon',
  112. ['type', 0],
  113. ['sort', 0],
  114. ['pid', []],
  115. ['is_store', 0],
  116. ]);
  117. $data['pid'] = end($data['pid']);
  118. if (!$data['title']) return $this->fail('请输入分类昵称');
  119. if (!$data['eng_title']) return $this->fail('请输入分类字段');
  120. $this->services->update($id, $data);
  121. return $this->success('修改成功!');
  122. }
  123. /**
  124. * 删除指定资源
  125. *
  126. * @param int $id
  127. * @return \think\Response
  128. */
  129. public function delete(SystemConfigServices $services, $id)
  130. {
  131. if ($services->count(['tab_id' => $id])) {
  132. return $this->fail('存在下级配置,无法删除!');
  133. }
  134. if (!$this->services->delete($id))
  135. return $this->fail('删除失败,请稍候再试!');
  136. else
  137. return $this->success('删除成功!');
  138. }
  139. /**
  140. * 修改状态
  141. * @param $id
  142. * @param $status
  143. * @return mixed
  144. */
  145. public function set_status($id, $status)
  146. {
  147. if ($status == '' || $id == 0) {
  148. return $this->fail('参数错误');
  149. }
  150. $this->services->update($id, ['status' => $status]);
  151. return $this->success($status == 0 ? '隐藏成功' : '显示成功');
  152. }
  153. }