SystemCrudServices.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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\services\system;
  14. use app\dao\system\SystemCrudDao;
  15. use app\services\BaseServices;
  16. use crmeb\exceptions\AdminException;
  17. use crmeb\services\crud\Controller;
  18. use crmeb\services\crud\Dao;
  19. use crmeb\services\crud\Make;
  20. use crmeb\services\crud\Model;
  21. use crmeb\services\crud\Route;
  22. use crmeb\services\crud\Service;
  23. use crmeb\services\crud\Validate;
  24. use crmeb\services\crud\ViewApi;
  25. use crmeb\services\crud\ViewPages;
  26. use crmeb\services\crud\ViewRouter;
  27. use crmeb\services\FileService;
  28. use Phinx\Db\Adapter\AdapterFactory;
  29. use think\facade\Db;
  30. use think\helper\Str;
  31. use think\migration\db\Table;
  32. /**
  33. * Class SystemCrudServices
  34. * @author 等风来
  35. * @email 136327134@qq.com
  36. * @date 2023/4/6
  37. * @package app\services\system
  38. */
  39. class SystemCrudServices extends BaseServices
  40. {
  41. //不能生成的系统自带表
  42. const NOT_CRUD_TABANAME = [
  43. 'system_config', 'system_attachment', 'system_attachment_category', 'system_config_tab',
  44. 'system_admin', 'eb_system_city', 'system_log', 'system_menus', 'system_notice',
  45. 'system_notice_admin', 'system_notification', 'system_role', 'system_route',
  46. 'system_route_cate', 'system_storage', 'system_timer', 'system_user_level',
  47. 'system_crud', 'wechat_key', 'user_label_relation', 'user_brokerage_frozen',
  48. 'user_brokerage', 'store_product_cate', 'store_bargain_user_help', 'shipping_templates_region',
  49. 'shipping_templates_no_delivery', 'shipping_templates_free', 'other_order_status', 'lang_code',
  50. 'lang_country', 'app_version', 'user', 'wechat_user', 'template_message', 'store_order', 'other_order',
  51. 'store_order_cart_info', 'store_order_economize', 'store_order_invoice', 'store_order_refund',
  52. 'store_order_status', 'store_pink'
  53. ];
  54. /**
  55. * SystemCrudServices constructor.
  56. * @param SystemCrudDao $dao
  57. */
  58. public function __construct(SystemCrudDao $dao)
  59. {
  60. $this->dao = $dao;
  61. }
  62. /**
  63. * @return array
  64. * @author 等风来
  65. * @email 136327134@qq.com
  66. * @date 2023/4/11
  67. */
  68. public function getList()
  69. {
  70. [$page, $limit] = $this->getPageValue();
  71. $list = $this->dao->selectList([], 'add_time,id,name,table_name,table_comment,table_collation', $page, $limit, 'id desc');
  72. $count = $this->dao->count();
  73. return compact('list', 'count');
  74. }
  75. /**
  76. * 数据库字段类型
  77. * @return \string[][]
  78. * @author 等风来
  79. * @email 136327134@qq.com
  80. * @date 2023/4/11
  81. */
  82. public function getTabelRule()
  83. {
  84. $rule = [
  85. 'varchar' => 'string',
  86. 'int' => 'integer',
  87. 'biginteger' => 'bigint',
  88. 'tinyint' => 'boolean',
  89. ];
  90. return [
  91. 'types' => [
  92. 'varchar',
  93. 'char',
  94. 'text',
  95. 'longtext',
  96. 'tinytext',
  97. 'enum',
  98. 'blob',
  99. 'binary',
  100. 'varbinary',
  101. 'datetime',
  102. 'timestamp',
  103. 'time',
  104. 'date',
  105. 'year',
  106. 'boolean',
  107. 'tinyint',
  108. 'int',
  109. 'decimal',
  110. 'float',
  111. 'json',
  112. 'addTimestamps',
  113. 'addSoftDelete',
  114. ],
  115. 'rule' => $rule
  116. ];
  117. }
  118. /**
  119. * 改变数据库类型
  120. * @param string $type
  121. * @return string
  122. * @author 等风来
  123. * @email 136327134@qq.com
  124. * @date 2023/4/13
  125. */
  126. public function changeTabelRule(string $type)
  127. {
  128. if (!in_array($type, $this->getTabelRule()['types'])) {
  129. throw new AdminException(500047);
  130. }
  131. return $this->getTabelRule()['rule'][$type] ?? $type;
  132. }
  133. /**
  134. * @param string $tableName
  135. * @return mixed
  136. * @author 等风来
  137. * @email 136327134@qq.com
  138. * @date 2023/4/14
  139. */
  140. public function getTableInfo(string $tableName)
  141. {
  142. $sql = 'SELECT * FROM `information_schema`.`TABLES` WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?';
  143. $tableInfo = Db::query($sql, [config('database.connections.mysql.database'), $this->getTableName($tableName)]);
  144. return $tableInfo[0] ?? [];
  145. }
  146. /**
  147. * 获取表字段
  148. * @param string $tableName
  149. * @return mixed
  150. * @author 等风来
  151. * @email 136327134@qq.com
  152. * @date 2023/4/7
  153. */
  154. public function getColumnNamesList(string $tableName)
  155. {
  156. $sql = 'SELECT * FROM `information_schema`.`columns` WHERE TABLE_SCHEMA = ? AND table_name = ? ORDER BY ORDINAL_POSITION';
  157. $column = Db::query($sql, [config('database.connections.mysql.database'), $this->getTableName($tableName)]);
  158. $columns = [];
  159. foreach ($column as $item) {
  160. $column = [
  161. 'name' => $item['COLUMN_NAME'],
  162. 'type' => $item['DATA_TYPE'],
  163. 'dataType' => stripos($item['COLUMN_TYPE'], '(') !== false ? substr_replace($item['COLUMN_TYPE'], '', stripos($item['COLUMN_TYPE'], ')') + 1) : $item['COLUMN_TYPE'],
  164. 'default' => $item['COLUMN_DEFAULT'],
  165. 'null' => $item['IS_NULLABLE'] == 'YES',
  166. 'primaryKey' => $item['COLUMN_KEY'] == 'PRI',
  167. 'unsigned' => (bool)stripos($item['COLUMN_TYPE'], 'unsigned'),
  168. 'autoIncrement' => stripos($item['EXTRA'], 'auto_increment') !== false,
  169. 'comment' => $item['COLUMN_COMMENT'],
  170. 'limit' => $item['CHARACTER_MAXIMUM_LENGTH'] ?: $item['NUMERIC_PRECISION'],
  171. ];
  172. $columns[$item['COLUMN_NAME']] = $column;
  173. }
  174. return $columns;
  175. }
  176. /**
  177. * @param array $data
  178. * @return array
  179. * @author 等风来
  180. * @email 136327134@qq.com
  181. * @date 2023/4/12
  182. */
  183. public function valueReplace(array $data)
  184. {
  185. $replace = ['phar://'];
  186. $newData = [];
  187. foreach ($data as $key => $item) {
  188. if (is_array($item)) {
  189. $item = $this->valueReplace($item);
  190. } else {
  191. $item = str_replace($replace, '', $item);
  192. }
  193. $newData[str_replace($replace, '', $key)] = $item;
  194. }
  195. return $newData;
  196. }
  197. /**
  198. * 创建
  199. * @param array $data
  200. * @return mixed
  201. * @author 等风来
  202. * @email 136327134@qq.com
  203. * @date 2023/4/11
  204. */
  205. public function createCrud(array $data)
  206. {
  207. $tableName = $data['tableName'];
  208. $tableComment = $data['tableComment'] ?? $data['menuName'];
  209. $tableField = $this->valueReplace($data['tableField']);
  210. $filePath = $this->valueReplace($data['filePath']);
  211. $modelName = $data['modelName'] ?? $data['menuName'] ?? $tableName;
  212. if ($this->dao->value(['table_name' => $tableName])) {
  213. throw new AdminException(500048);
  214. }
  215. $data['softDelete'] = false;
  216. //创建数据库
  217. if ($tableField && !$data['isTable']) {
  218. $tableCreateInfo = $this->makeDatebase($tableName, $tableComment, $tableField);
  219. if ($tableCreateInfo['softDelete']) {
  220. $data['softDelete'] = true;
  221. }
  222. }
  223. if (in_array($tableName, self::NOT_CRUD_TABANAME)) {
  224. throw new AdminException(500044);
  225. }
  226. //读取表结构
  227. $column = $this->getColumnNamesList($tableName);
  228. if (!$column) {
  229. throw new AdminException(500049, ['_name' => $tableName]);
  230. }
  231. $tableInfo = $this->getTableInfo($tableName);
  232. //获取主键
  233. foreach ($column as $value) {
  234. if ($value['primaryKey']) {
  235. $data['key'] = $value['name'];
  236. break;
  237. }
  238. }
  239. $routeName = 'crud/' . Str::snake($tableName);
  240. $uniqueAuth = Str::snake($tableName) . '-crud-list-index';
  241. //增加保存的绝对路径
  242. foreach ($filePath as $k => $i) {
  243. if (in_array($k, ['pages', 'router', 'api'])) {
  244. $filePath[$k] = Make::adminTemplatePath() . $i;
  245. } else {
  246. $filePath[$k] = app()->getRootPath() . $i;
  247. }
  248. }
  249. //创建菜单
  250. if (!$data['menuName']) {
  251. $data['menuName'] = $tableName;
  252. }
  253. $dataMenu = [
  254. 'pid' => $data['pid'],
  255. 'menu_name' => $data['menuName'],
  256. 'menu_path' => '/' . $routeName,
  257. 'auth_type' => 1,
  258. 'is_show' => 1,
  259. 'is_del' => 0,
  260. 'unique_auth' => $uniqueAuth,
  261. 'is_header' => $data['pid'] ? 0 : 1,
  262. ];
  263. $res = $this->transaction(function () use ($tableInfo, $modelName, $filePath, $tableName, $routeName, $data, $dataMenu) {
  264. $menuInfo = app()->make(SystemMenusServices::class)->save($dataMenu);
  265. //写入路由权限
  266. $cateId = app()->make(SystemRouteServices::class)->topCateId('adminapi');
  267. $ruleData = [
  268. [
  269. 'path' => $routeName,
  270. 'method' => 'GET',
  271. 'name' => $modelName . '列表接口',
  272. 'app_name' => 'adminapi',
  273. 'cate_id' => $cateId,
  274. 'unique_auth' => '',
  275. 'add_time' => date('Y-m-d H:i:s')
  276. ],
  277. [
  278. 'path' => $routeName . '/create',
  279. 'method' => 'GET',
  280. 'name' => $modelName . '获取创建表单接口',
  281. 'app_name' => 'adminapi',
  282. 'cate_id' => $cateId,
  283. 'unique_auth' => Str::snake($tableName) . '-add',
  284. 'add_time' => date('Y-m-d H:i:s')
  285. ],
  286. [
  287. 'path' => $routeName,
  288. 'method' => 'POST',
  289. 'name' => $modelName . '保存数据接口',
  290. 'app_name' => 'adminapi',
  291. 'cate_id' => $cateId,
  292. 'unique_auth' => '',
  293. 'add_time' => date('Y-m-d H:i:s')
  294. ],
  295. [
  296. 'path' => $routeName . '/<id>/edit',
  297. 'method' => 'GET',
  298. 'name' => $modelName . '获取修改表单接口',
  299. 'app_name' => 'adminapi',
  300. 'cate_id' => $cateId,
  301. 'unique_auth' => '',
  302. 'add_time' => date('Y-m-d H:i:s')
  303. ],
  304. [
  305. 'path' => $routeName . '/<id>',
  306. 'method' => 'PUT',
  307. 'name' => $modelName . '修改数据接口',
  308. 'app_name' => 'adminapi',
  309. 'cate_id' => $cateId,
  310. 'unique_auth' => '',
  311. 'add_time' => date('Y-m-d H:i:s')
  312. ],
  313. [
  314. 'path' => $routeName . '/<id>',
  315. 'method' => 'DELETE',
  316. 'name' => $modelName . '删除数据接口',
  317. 'app_name' => 'adminapi',
  318. 'cate_id' => $cateId,
  319. 'unique_auth' => '',
  320. 'add_time' => date('Y-m-d H:i:s')
  321. ],
  322. ];
  323. $routeService = app()->make(SystemRouteServices::class);
  324. foreach ($ruleData as $key => $item) {
  325. if ($routeService->count(['method' => $item['method'], 'path' => $item['path']])) {
  326. unset($ruleData[$key]);
  327. }
  328. }
  329. app()->make(SystemRouteServices::class)->saveAll($ruleData);
  330. //记录权限加入菜单表
  331. $menuData = [];
  332. foreach ($ruleData as $item) {
  333. $menuData[] = [
  334. 'pid' => $menuInfo->id,
  335. 'methods' => $item['method'],
  336. 'api_url' => $item['path'],
  337. 'unique_auth' => $item['unique_auth'],
  338. 'menu_name' => $item['name'],
  339. 'is_del' => 0,
  340. 'auth_type' => 2,
  341. ];
  342. }
  343. $menus = app()->make(SystemMenusServices::class)->saveAll($menuData);
  344. $menuIds = array_column($menus->toArray(), 'id');
  345. array_push($menuIds, $menuInfo->id);
  346. //生成文件
  347. $make = $this->makeFile($tableName, $routeName, config('app.crud_make', false), $data, $filePath);
  348. $makePath = [];
  349. foreach ($make as $key => $item) {
  350. $makePath[$key] = $item['path'];
  351. }
  352. //记录crud生成
  353. $res = $this->dao->save([
  354. 'pid' => $data['pid'],
  355. 'name' => $data['menuName'],
  356. 'model_name' => $data['modelName'],
  357. 'table_name' => $tableName,
  358. 'table_comment' => $tableInfo['TABLE_COMMENT'] ?? '',
  359. 'table_collation' => $tableInfo['TABLE_COLLATION'] ?? '',
  360. 'field' => json_encode($data),//提交的数据
  361. 'menu_ids' => json_encode($menuIds),//生成的菜单id
  362. 'make_path' => json_encode($makePath),
  363. 'add_time' => time()
  364. ]);
  365. return $res;
  366. });
  367. return $res->toArray();
  368. }
  369. /**
  370. * 获取数据库配置
  371. * @return array
  372. */
  373. protected function getDbConfig(): array
  374. {
  375. $default = app()->config->get('database.default');
  376. $config = app()->config->get("database.connections.{$default}");
  377. if (0 == $config['deploy']) {
  378. $dbConfig = [
  379. 'adapter' => $config['type'],
  380. 'host' => $config['hostname'],
  381. 'name' => $config['database'],
  382. 'user' => $config['username'],
  383. 'pass' => $config['password'],
  384. 'port' => $config['hostport'],
  385. 'charset' => $config['charset'],
  386. 'table_prefix' => $config['prefix'],
  387. ];
  388. } else {
  389. $dbConfig = [
  390. 'adapter' => explode(',', $config['type'])[0],
  391. 'host' => explode(',', $config['hostname'])[0],
  392. 'name' => explode(',', $config['database'])[0],
  393. 'user' => explode(',', $config['username'])[0],
  394. 'pass' => explode(',', $config['password'])[0],
  395. 'port' => explode(',', $config['hostport'])[0],
  396. 'charset' => explode(',', $config['charset'])[0],
  397. 'table_prefix' => explode(',', $config['prefix'])[0],
  398. ];
  399. }
  400. $table = app()->config->get('database.migration_table', 'migrations');
  401. $dbConfig['default_migration_table'] = $dbConfig['table_prefix'] . $table;
  402. return $dbConfig;
  403. }
  404. public function getAdapter()
  405. {
  406. $options = $this->getDbConfig();
  407. $adapter = AdapterFactory::instance()->getAdapter($options['adapter'], $options);
  408. if ($adapter->hasOption('table_prefix') || $adapter->hasOption('table_suffix')) {
  409. $adapter = AdapterFactory::instance()->getWrapper('prefix', $adapter);
  410. }
  411. return $adapter;
  412. }
  413. /**
  414. * 创建数据库
  415. * @param string $tableName
  416. * @param string $tableComment
  417. * @param array $tableField
  418. * @return array
  419. * @author 等风来
  420. * @email 136327134@qq.com
  421. * @date 2023/4/7
  422. */
  423. public function makeDatebase(string $tableName, string $tableComment, array $tableField = [])
  424. {
  425. $softDelete = false;
  426. $timestamps = false;
  427. $indexField = [];
  428. //创建表
  429. $table = new Table($tableName, ['comment' => $tableComment], $this->getAdapter());
  430. //创建字段
  431. foreach ($tableField as $item) {
  432. $option = [];
  433. if (isset($item['limit'])) {
  434. $option['limit'] = (int)$item['limit'];
  435. }
  436. if (isset($item['default'])) {
  437. $option['default'] = $item['default'];
  438. }
  439. //创建伪删除
  440. if ($item['field_type'] === 'addSoftDelete') {
  441. $table->addSoftDelete();
  442. $softDelete = true;
  443. } else if ($item['field_type'] === 'addTimestamps') {
  444. //创建修改和增加时间
  445. $table->addTimestamps();
  446. $timestamps = true;
  447. } else {
  448. $option['comment'] = $item['comment'];
  449. $table->addColumn($item['field'], $this->changeTabelRule($item['field_type']), $option);
  450. }
  451. }
  452. //创建索引
  453. if (!empty($data['tableIndex'])) {
  454. $indexField = $data['tableIndex'];
  455. foreach ($data['tableIndex'] as $item) {
  456. $table->addIndex($item);
  457. }
  458. }
  459. //执行创建
  460. $table->create();
  461. return compact('indexField', 'softDelete', 'timestamps');
  462. }
  463. /**
  464. * 创建文件返回文件路径和内容
  465. * @param string $tableName
  466. * @param string $routeName
  467. * @param bool $isMake
  468. * @param array $options
  469. * @param array $filePath
  470. * @param string $basePath
  471. * @return array[]
  472. * @author 等风来
  473. * @email 136327134@qq.com
  474. * @date 2023/4/7
  475. */
  476. public function makeFile(string $tableName, string $routeName, bool $isMake = false, array $options = [], array $filePath = [], string $basePath = '')
  477. {
  478. $options['fromField'] = is_array($options['fromField']) ? $options['fromField'] : [];
  479. $options['columnField'] = is_array($options['columnField']) ? $options['columnField'] : [];
  480. //生成模型
  481. $model = app()->make(Model::class);
  482. $model->setFilePathName($filePath['model'] ?? '')->setbasePath($basePath)->handle($tableName, $options);
  483. //生成dao
  484. $dao = app()->make(Dao::class);
  485. $dao->setFilePathName($filePath['dao'] ?? '')->setbasePath($basePath)->handle($tableName, [
  486. 'usePath' => $model->getUsePath(),
  487. ]);
  488. //生成service
  489. $service = app()->make(Service::class);
  490. $service->setFilePathName($filePath['service'] ?? '')->setbasePath($basePath)->handle($tableName, [
  491. 'field' => $options['fromField'],
  492. 'key' => $options['key'],
  493. 'usePath' => $dao->getUsePath(),
  494. 'modelName' => $options['modelName'] ?? '',
  495. ]);
  496. //生成验证器
  497. $validate = app()->make(Validate::class);
  498. $validate->setFilePathName($filePath['validate'] ?? '')->setbasePath($basePath)->handle($tableName, [
  499. 'field' => $options['fromField'],
  500. ]);
  501. //生成控制器
  502. $controller = app()->make(Controller::class);
  503. $controller->setFilePathName($filePath['controller'] ?? '')->setbasePath($basePath)->handle($tableName, [
  504. 'usePath' => $service->getUsePath(),
  505. 'validateName' => '\\' . str_replace('/', '\\', $validate->getUsePath()) . 'Validate::class',
  506. 'field' => array_column($options['fromField'], 'field'),
  507. ]);
  508. //生成路由
  509. $route = app()->make(Route::class);
  510. $route->setFilePathName($filePath['route'] ?? '')->setbasePath($basePath)->handle($tableName, [
  511. 'menus' => $options['modelName'] ?? $options['menuName'],
  512. 'route' => $routeName
  513. ]);
  514. //生成前台路由
  515. $viewRouter = app()->make(ViewRouter::class);
  516. $viewRouter->setFilePathName($filePath['router'] ?? '')->setbasePath($basePath)->handle($tableName, [
  517. 'route' => $routeName,
  518. 'menuName' => $options['menuName'],
  519. ]);
  520. //生成前台接口
  521. $viewApi = app()->make(ViewApi::class);
  522. $viewApi->setFilePathName($filePath['api'] ?? '')->setbasePath($basePath)->handle($tableName, [
  523. 'route' => $routeName,
  524. ]);
  525. //生成前台页面
  526. $viewPages = app()->make(ViewPages::class);
  527. $viewPages->setFilePathName($filePath['pages'] ?? '')->setbasePath($basePath)->handle($tableName, [
  528. 'field' => $options['columnField'],
  529. 'route' => $routeName,
  530. 'key' => $options['key'],
  531. 'pathApiJs' => '@/' . str_replace('\\', '/', str_replace([Make::adminTemplatePath(), '.js'], '', $viewApi->getPath())),
  532. ]);
  533. //创建文件
  534. if ($isMake) {
  535. FileService::batchMakeFiles([$model, $validate, $dao, $service, $controller, $route, $viewApi, $viewPages, $viewRouter]);
  536. }
  537. return [
  538. 'controller' => [
  539. 'path' => $this->replace($controller->getPath()),
  540. 'content' => $controller->getContent()
  541. ],
  542. 'model' => [
  543. 'path' => $this->replace($model->getPath()),
  544. 'content' => $model->getContent()
  545. ],
  546. 'dao' => [
  547. 'path' => $this->replace($dao->getPath()),
  548. 'content' => $dao->getContent()
  549. ],
  550. 'route' => [
  551. 'path' => $this->replace($route->getPath()),
  552. 'content' => $route->getContent()
  553. ],
  554. 'service' => [
  555. 'path' => $this->replace($service->getPath()),
  556. 'content' => $service->getContent()
  557. ],
  558. 'validate' => [
  559. 'path' => $this->replace($validate->getPath()),
  560. 'content' => $validate->getContent()
  561. ],
  562. 'router' => [
  563. 'path' => $this->replace($viewRouter->getPath()),
  564. 'content' => $viewRouter->getContent()
  565. ],
  566. 'api' => [
  567. 'path' => $this->replace($viewApi->getPath()),
  568. 'content' => $viewApi->getContent()
  569. ],
  570. 'pages' => [
  571. 'path' => $this->replace($viewPages->getPath()),
  572. 'content' => $viewPages->getContent()
  573. ],
  574. ];
  575. }
  576. protected function replace(string $path)
  577. {
  578. return str_replace([app()->getRootPath(), Make::adminTemplatePath()], '', $path);
  579. }
  580. /**
  581. * @param string $tableName
  582. * @param bool $fullName
  583. * @return string
  584. * @author 等风来
  585. * @email 136327134@qq.com
  586. * @date 2023/4/7
  587. */
  588. public function getTableName(string $tableName, bool $fullName = true)
  589. {
  590. $tablePrefix = config('database.connections.mysql.prefix');
  591. $pattern = '/^' . $tablePrefix . '/i';
  592. return ($fullName ? $tablePrefix : '') . (preg_replace($pattern, '', $tableName));
  593. }
  594. }