'integer']; /** * @param array $param */ public static function list(array $param) { return (new self())->when(isset($param['table_name']) && $param['table_name'] != "", function ($query) use ($param) { $query->where('table_name', "like", "%{$param['table_name']}%"); })->when(isset($param['table_comment']) && $param['table_comment'] != "", function ($query) use ($param) { $query->where('table_comment', "like", "%{$param['table_comment']}%"); })->select(['table_id', 'table_name', 'table_comment', 'controller_name', 'module_name', 'remark', 'create_time', 'update_time']) ->orderByDesc('table_id')->paginate((int)$param['limit']); } public static function genTable(array $rows): bool { Db::beginTransaction(); foreach ($rows as $row) { // 添加主表 $id = self::add([ 'table_name' => $row->Name, 'table_comment' => $row->Comment, 'controller_name' => Str::snakeToCamel(str_replace("pi_", "", $row->Name), true), 'module_name' => 'App\Controller\Admin' ]); if (!$id) { Db::rollBack(); return false; } // 字段管理 $columns = Db::select("SHOW FULL COLUMNS FROM `{$row->Name}`"); $i = 1; foreach ($columns as $column) { $res = GenTableColumn::add([ 'table_id' => $id, 'column_name' => $column->Field, 'column_comment' => $column->Comment, 'column_type' => $column->Type, 'php_type' => Str::typeMysqlToPhp($column->Type), 'php_field' => $column->Field, 'is_insert' => Str::isInsert($column->Field, $column->Extra), 'is_edit' => Str::isEdit($column->Field, $column->Extra), 'is_list' => Str::isList($column->Field, $column->Extra), 'is_query' => Str::isQuery($column->Field, $column->Extra), 'is_required' => 0, 'query_type' => str_contains($column->Field, "name") ? "like" : "eq", 'html_type' => Str::htmlType($column->Field), 'rank' => $i ]); $i++; if (!$res) { Db::rollBack(); return false; } } } Db::commit(); return true; } }