SystemCrud.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 think\facade\App;
  17. use think\helper\Str;
  18. /**
  19. * Class SystemCrud
  20. * @author 等风来
  21. * @email 136327134@qq.com
  22. * @date 2023/4/6
  23. * @package app\adminapi\controller\v1\setting
  24. */
  25. class SystemCrud extends AuthController
  26. {
  27. /**
  28. * SystemCrud constructor.
  29. * @param App $app
  30. * @param SystemCrudServices $services
  31. */
  32. public function __construct(App $app, SystemCrudServices $services)
  33. {
  34. parent::__construct($app);
  35. $this->services = $services;
  36. }
  37. /**
  38. * @return \think\Response
  39. * @author 等风来
  40. * @email 136327134@qq.com
  41. * @date 2023/4/11
  42. */
  43. public function index()
  44. {
  45. return app('json')->success($this->services->getList());
  46. }
  47. /**
  48. * @return \think\Response
  49. * @author 等风来
  50. * @email 136327134@qq.com
  51. * @date 2023/4/11
  52. */
  53. public function save()
  54. {
  55. $data = $this->request->postMore([
  56. ['pid', 0],
  57. ['menuName', ''],
  58. ['tableName', ''],
  59. ['tableComment', ''],//表备注
  60. ['tableField', []],//表字段
  61. ['tableIndex', []],//索引
  62. ['tableTime', 0],//表是否增加修改和添加时间
  63. ['tableDelete', 0],//表是否增加伪删除
  64. ['fromField', []],
  65. ['columnField', []],
  66. ['filePath', []],
  67. ]);
  68. $this->services->createCrud($data);
  69. return app('json')->success('创建成功');
  70. }
  71. /**
  72. * 获取创建文件的目录存放位置
  73. * @return \think\Response
  74. * @author 等风来
  75. * @email 136327134@qq.com
  76. * @date 2023/4/11
  77. */
  78. public function getFilePath()
  79. {
  80. [$menuName, $tableName, $fromField, $columnField] = $this->request->postMore([
  81. ['menuName', ''],
  82. ['tableName', ''],
  83. ['fromField', []],
  84. ['columnField', []],
  85. ], true);
  86. $routeName = 'crud/' . Str::snake($tableName);
  87. $make = $this->services->makeFile($tableName, $routeName, false, [
  88. 'menuName' => $menuName,
  89. 'fromField' => $fromField,
  90. 'columnField' => $columnField,
  91. ]);
  92. $makePath = [];
  93. foreach ($make as $key => $item) {
  94. $makePath[$key] = $item['path'];
  95. }
  96. return app('json')->success($makePath);
  97. }
  98. /**
  99. * 获取创建表数据类型
  100. * @return \think\Response
  101. * @author 等风来
  102. * @email 136327134@qq.com
  103. * @date 2023/4/11
  104. */
  105. public function columnType()
  106. {
  107. return app('json')->success($this->services->getTabelRule());
  108. }
  109. /**
  110. * @param $id
  111. * @return \think\Response
  112. * @author 等风来
  113. * @email 136327134@qq.com
  114. * @date 2023/4/11
  115. */
  116. public function delete($id)
  117. {
  118. if (!$id) {
  119. return app('json')->fail('缺少参数');
  120. }
  121. $this->services->delete($id);
  122. return app('json')->success('删除成功');
  123. }
  124. }