GeneratorController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\controller\tools;
  15. use app\adminapi\controller\BaseAdminController;
  16. use app\adminapi\lists\tools\DataTableLists;
  17. use app\adminapi\lists\tools\GenerateTableLists;
  18. use app\adminapi\logic\tools\GeneratorLogic;
  19. use app\adminapi\validate\tools\EditTableValidate;
  20. use app\adminapi\validate\tools\GenerateTableValidate;
  21. /**
  22. * 代码生成器控制器
  23. * Class GeneratorController
  24. * @package app\adminapi\controller\article
  25. */
  26. class GeneratorController extends BaseAdminController
  27. {
  28. public array $notNeedLogin = ['download'];
  29. /**
  30. * @notes 获取数据库中所有数据表信息
  31. * @return \think\response\Json
  32. * @author 段誉
  33. * @date 2022/6/14 10:57
  34. */
  35. public function dataTable()
  36. {
  37. return $this->dataLists(new DataTableLists());
  38. }
  39. /**
  40. * @notes 获取已选择的数据表
  41. * @return \think\response\Json
  42. * @author 段誉
  43. * @date 2022/6/14 10:57
  44. */
  45. public function generateTable()
  46. {
  47. return $this->dataLists(new GenerateTableLists());
  48. }
  49. /**
  50. * @notes 选择数据表
  51. * @return \think\response\Json
  52. * @author 段誉
  53. * @date 2022/6/15 10:09
  54. */
  55. public function selectTable()
  56. {
  57. $params = (new GenerateTableValidate())->post()->goCheck('select');
  58. $result = GeneratorLogic::selectTable($params, $this->adminId);
  59. if (true === $result) {
  60. return $this->success('操作成功', [], 1, 1);
  61. }
  62. return $this->fail(GeneratorLogic::getError());
  63. }
  64. /**
  65. * @notes 生成代码
  66. * @return \think\response\Json
  67. * @author 段誉
  68. * @date 2022/6/23 19:08
  69. */
  70. public function generate()
  71. {
  72. $params = (new GenerateTableValidate())->post()->goCheck('id');
  73. $result = GeneratorLogic::generate($params);
  74. if (false === $result) {
  75. return $this->fail(GeneratorLogic::getError());
  76. }
  77. return $this->success('操作成功', $result, 1, 1);
  78. }
  79. /**
  80. * @notes 下载文件
  81. * @return \think\response\File|\think\response\Json
  82. * @author 段誉
  83. * @date 2022/6/24 9:51
  84. */
  85. public function download()
  86. {
  87. $params = (new GenerateTableValidate())->goCheck('download');
  88. $result = GeneratorLogic::download($params['file']);
  89. if (false === $result) {
  90. return $this->fail(GeneratorLogic::getError() ?: '下载失败');
  91. }
  92. return download($result, 'likeadmin-curd.zip');
  93. }
  94. /**
  95. * @notes 预览代码
  96. * @return \think\response\Json
  97. * @author 段誉
  98. * @date 2022/6/23 19:07
  99. */
  100. public function preview()
  101. {
  102. $params = (new GenerateTableValidate())->post()->goCheck('id');
  103. $result = GeneratorLogic::preview($params);
  104. if (false === $result) {
  105. return $this->fail(GeneratorLogic::getError());
  106. }
  107. return $this->data($result);
  108. }
  109. /**
  110. * @notes 同步字段
  111. * @return \think\response\Json
  112. * @author 段誉
  113. * @date 2022/6/17 15:22
  114. */
  115. public function syncColumn()
  116. {
  117. $params = (new GenerateTableValidate())->post()->goCheck('id');
  118. $result = GeneratorLogic::syncColumn($params);
  119. if (true === $result) {
  120. return $this->success('操作成功', [], 1, 1);
  121. }
  122. return $this->fail(GeneratorLogic::getError());
  123. }
  124. /**
  125. * @notes 编辑表信息
  126. * @return \think\response\Json
  127. * @author 段誉
  128. * @date 2022/6/20 10:44
  129. */
  130. public function edit()
  131. {
  132. $params = (new EditTableValidate())->post()->goCheck();
  133. $result = GeneratorLogic::editTable($params);
  134. if (true === $result) {
  135. return $this->success('操作成功', [], 1, 1);
  136. }
  137. return $this->fail(GeneratorLogic::getError());
  138. }
  139. /**
  140. * @notes 获取已选择的数据表详情
  141. * @return \think\response\Json
  142. * @author 段誉
  143. * @date 2022/6/15 19:00
  144. */
  145. public function detail()
  146. {
  147. $params = (new GenerateTableValidate())->goCheck('id');
  148. $result = GeneratorLogic::getTableDetail($params);
  149. return $this->success('', $result);
  150. }
  151. /**
  152. * @notes 删除已选择的数据表信息
  153. * @return \think\response\Json
  154. * @author 段誉
  155. * @date 2022/6/15 19:00
  156. */
  157. public function delete()
  158. {
  159. $params = (new GenerateTableValidate())->post()->goCheck('id');
  160. $result = GeneratorLogic::deleteTable($params);
  161. if (true === $result) {
  162. return $this->success('操作成功', [], 1, 1);
  163. }
  164. return $this->fail(GeneratorLogic::getError());
  165. }
  166. /**
  167. * @notes 获取模型
  168. * @return \think\response\Json
  169. * @author 段誉
  170. * @date 2022/12/14 11:07
  171. */
  172. public function getModels()
  173. {
  174. $result = GeneratorLogic::getAllModels();
  175. return $this->success('', $result, 1, 1);
  176. }
  177. }