SystemCrud.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * +----------------------------------------------------------------------
  4. * | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  5. * +----------------------------------------------------------------------
  6. * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  7. * +----------------------------------------------------------------------
  8. * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  9. * +----------------------------------------------------------------------
  10. * | Author: CRMEB Team <admin@crmeb.com>
  11. * +----------------------------------------------------------------------
  12. */
  13. namespace app\adminapi\controller\v1\setting;
  14. use app\adminapi\controller\AuthController;
  15. use app\services\system\SystemCrudServices;
  16. use app\services\system\SystemMenusServices;
  17. use think\facade\App;
  18. use think\helper\Str;
  19. /**
  20. * Class SystemCrud
  21. * @author 等风来
  22. * @email 136327134@qq.com
  23. * @date 2023/4/6
  24. * @package app\adminapi\controller\v1\setting
  25. */
  26. class SystemCrud extends AuthController
  27. {
  28. /**
  29. * SystemCrud constructor.
  30. * @param App $app
  31. * @param SystemCrudServices $services
  32. */
  33. public function __construct(App $app, SystemCrudServices $services)
  34. {
  35. parent::__construct($app);
  36. $this->services = $services;
  37. }
  38. /**
  39. * @return \think\Response
  40. * @author 等风来
  41. * @email 136327134@qq.com
  42. * @date 2023/4/11
  43. */
  44. public function index()
  45. {
  46. return app('json')->success($this->services->getList());
  47. }
  48. /**
  49. * @return \think\Response
  50. * @author 等风来
  51. * @email 136327134@qq.com
  52. * @date 2023/4/11
  53. */
  54. public function save()
  55. {
  56. $data = $this->request->postMore([
  57. ['pid', 0],
  58. ['menuName', ''],
  59. ['tableName', ''],
  60. ['tableComment', ''],//表备注
  61. ['tableField', []],//表字段
  62. ['tableIndex', []],//索引
  63. ['tableTime', 0],//表是否增加修改和添加时间
  64. ['tableDelete', 0],//表是否增加伪删除
  65. ['fromField', []],
  66. ['columnField', []],
  67. ['filePath', []],
  68. ]);
  69. $this->services->createCrud($data);
  70. return app('json')->success('创建成功');
  71. }
  72. /**
  73. * 获取创建文件的目录存放位置
  74. * @return \think\Response
  75. * @author 等风来
  76. * @email 136327134@qq.com
  77. * @date 2023/4/11
  78. */
  79. public function getFilePath()
  80. {
  81. [$menuName, $tableName, $fromField, $columnField] = $this->request->postMore([
  82. ['menuName', ''],
  83. ['tableName', ''],
  84. ['fromField', []],
  85. ['columnField', []],
  86. ], true);
  87. $routeName = 'crud/' . Str::snake($tableName);
  88. $make = $this->services->makeFile($tableName, $routeName, false, [
  89. 'menuName' => $menuName,
  90. 'fromField' => $fromField,
  91. 'columnField' => $columnField,
  92. ]);
  93. $makePath = [];
  94. foreach ($make as $key => $item) {
  95. $makePath[$key] = $item['path'];
  96. }
  97. return app('json')->success($makePath);
  98. }
  99. /**
  100. * 获取tree菜单
  101. * @return \think\Response
  102. * @author 等风来
  103. * @email 136327134@qq.com
  104. * @date 2023/4/11
  105. */
  106. public function getMenus()
  107. {
  108. return app('json')->success(app()->make(SystemMenusServices::class)
  109. ->getList(['auth_type' => 1], ['pid', 'id', 'menu_name as label', 'id as value']));
  110. }
  111. /**
  112. * 获取创建表数据类型
  113. * @return \think\Response
  114. * @author 等风来
  115. * @email 136327134@qq.com
  116. * @date 2023/4/11
  117. */
  118. public function columnType()
  119. {
  120. return app('json')->success($this->services->getTabelRule());
  121. }
  122. /**
  123. * @param $id
  124. * @return \think\Response
  125. * @author 等风来
  126. * @email 136327134@qq.com
  127. * @date 2023/4/11
  128. */
  129. public function delete($id)
  130. {
  131. if (!$id) {
  132. return app('json')->fail('缺少参数');
  133. }
  134. $this->services->delete($id);
  135. return app('json')->success('删除成功');
  136. }
  137. }