2022-02-20 22:42:48 +00:00
|
|
|
<?php
|
2022-04-04 04:42:42 +00:00
|
|
|
|
2023-06-24 18:35:30 +00:00
|
|
|
use ba\Filesystem;
|
2022-04-04 04:42:42 +00:00
|
|
|
use think\facade\Db;
|
|
|
|
|
2022-04-03 04:38:25 +00:00
|
|
|
if (!function_exists('get_controller_list')) {
|
2022-11-05 17:20:24 +00:00
|
|
|
function get_controller_list($app = 'admin'): array
|
2022-04-03 04:38:25 +00:00
|
|
|
{
|
2022-11-05 17:20:24 +00:00
|
|
|
$controllerDir = root_path() . 'app' . DIRECTORY_SEPARATOR . $app . DIRECTORY_SEPARATOR . 'controller' . DIRECTORY_SEPARATOR;
|
2023-06-24 18:35:30 +00:00
|
|
|
return Filesystem::getDirFiles($controllerDir);
|
2022-04-03 04:38:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('get_table_list')) {
|
2022-10-07 12:35:48 +00:00
|
|
|
function get_table_list(): array
|
2022-04-03 04:38:25 +00:00
|
|
|
{
|
|
|
|
$tableList = [];
|
2022-10-07 12:35:48 +00:00
|
|
|
$database = config('database.connections.mysql.database');
|
|
|
|
$tables = Db::query("SELECT TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES WHERE table_schema = ? ", [$database]);
|
|
|
|
foreach ($tables as $row) {
|
2023-08-31 08:29:07 +00:00
|
|
|
$tableList[$row['TABLE_NAME']] = $row['TABLE_NAME'] . ($row['TABLE_COMMENT'] ? ' - ' . $row['TABLE_COMMENT'] : '');
|
2022-04-03 04:38:25 +00:00
|
|
|
}
|
|
|
|
return $tableList;
|
|
|
|
}
|
2022-04-04 04:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('get_table_fields')) {
|
2022-10-08 04:20:32 +00:00
|
|
|
function get_table_fields($table, $onlyCleanComment = false): array
|
2022-04-04 04:42:42 +00:00
|
|
|
{
|
|
|
|
if (!$table) return [];
|
|
|
|
|
|
|
|
$dbname = config('database.connections.mysql.database');
|
2022-07-18 06:57:18 +00:00
|
|
|
$prefix = config('database.connections.mysql.prefix');
|
2022-04-04 04:42:42 +00:00
|
|
|
|
|
|
|
// 从数据库中获取表字段信息
|
|
|
|
$sql = "SELECT * FROM `information_schema`.`columns` "
|
|
|
|
. "WHERE TABLE_SCHEMA = ? AND table_name = ? "
|
|
|
|
. "ORDER BY ORDINAL_POSITION";
|
|
|
|
$columnList = Db::query($sql, [$dbname, $table]);
|
2022-07-18 06:57:18 +00:00
|
|
|
if (!$columnList) {
|
|
|
|
$columnList = Db::query($sql, [$dbname, $prefix . $table]);
|
|
|
|
}
|
2022-04-04 04:42:42 +00:00
|
|
|
|
2022-10-08 04:20:32 +00:00
|
|
|
$fieldList = [];
|
2022-04-04 04:42:42 +00:00
|
|
|
foreach ($columnList as $item) {
|
2022-10-08 04:20:32 +00:00
|
|
|
if ($onlyCleanComment) {
|
|
|
|
$fieldList[$item['COLUMN_NAME']] = '';
|
|
|
|
if ($item['COLUMN_COMMENT']) {
|
|
|
|
$comment = explode(':', $item['COLUMN_COMMENT']);
|
|
|
|
$fieldList[$item['COLUMN_NAME']] = $comment[0];
|
|
|
|
}
|
|
|
|
continue;
|
2022-04-04 04:42:42 +00:00
|
|
|
}
|
2022-10-08 04:20:32 +00:00
|
|
|
$fieldList[$item['COLUMN_NAME']] = $item;
|
2022-04-04 04:42:42 +00:00
|
|
|
}
|
2022-10-08 04:20:32 +00:00
|
|
|
return $fieldList;
|
2022-04-04 04:42:42 +00:00
|
|
|
}
|
2022-04-23 09:57:29 +00:00
|
|
|
}
|