ThemeModule.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 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\diy;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\diy\ThemeModuleServices;
  14. use crmeb\exceptions\AdminException;
  15. use think\facade\App;
  16. /**
  17. * 主题组件管理
  18. */
  19. class ThemeModule extends AuthController
  20. {
  21. /**
  22. * @var ThemeModuleServices
  23. */
  24. protected $services;
  25. /**
  26. * 构造方法
  27. * @param App $app
  28. * @param ThemeModuleServices $services
  29. */
  30. public function __construct(App $app, ThemeModuleServices $services)
  31. {
  32. parent::__construct($app);
  33. $this->services = $services;
  34. }
  35. /**
  36. * 组件列表
  37. * @return \think\Response
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\DbException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. */
  42. public function index()
  43. {
  44. $where = $this->request->getMore([
  45. ['type', ''],
  46. ]);
  47. $data = $this->services->getModuleList($where);
  48. return app('json')->success($data);
  49. }
  50. /**
  51. * 组件详情
  52. * @param int $id
  53. * @return \think\Response
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. */
  58. public function read(int $id)
  59. {
  60. if (!$id) {
  61. throw new AdminException('参数错误');
  62. }
  63. $info = $this->services->getModuleInfo($id);
  64. return app('json')->success($info);
  65. }
  66. /**
  67. * 新增组件
  68. * @return \think\Response
  69. */
  70. public function save()
  71. {
  72. $data = $this->request->postMore([
  73. ['type', ''],
  74. ['data', ''],
  75. ]);
  76. $id = $this->services->saveModule(0, $data);
  77. return app('json')->success('保存成功', ['id' => $id]);
  78. }
  79. /**
  80. * 编辑组件
  81. * @param int $id
  82. * @return \think\Response
  83. */
  84. public function update(int $id)
  85. {
  86. if (!$id) {
  87. throw new AdminException('参数错误');
  88. }
  89. $data = $this->request->postMore([
  90. ['type', ''],
  91. ['data', ''],
  92. ]);
  93. $this->services->saveModule($id, $data);
  94. return app('json')->success('保存成功', ['id' => $id]);
  95. }
  96. /**
  97. * 删除组件
  98. * @param int $id
  99. * @return \think\Response
  100. */
  101. public function delete(int $id)
  102. {
  103. if (!$id) {
  104. throw new AdminException('参数错误');
  105. }
  106. $this->services->deleteModule($id);
  107. return app('json')->success('删除成功');
  108. }
  109. }