server/app/Model/GenTable.php

68 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\DbConnection\Db;
/**
* @property int $table_id
* @property string $table_name
* @property string $table_comment
* @property string $controller_name
* @property string $module_name
* @property string $remark
* @property string $deleted_at
* @property string $create_time
* @property string $update_time
*/
class GenTable extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'gen_table';
protected string $primaryKey = 'table_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['table_id' => '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)
{
Db::beginTransaction();
foreach ($rows as $row) {
var_dump($row);
// 添加主表
// $res = self::insert([
// 'table_name' => $row,
// ]);
// $columns = Db::select("SHOW FULL COLUMNS FROM `{$row}`");
// var_dump($columns);
}
Db::commit();
return true;
}
}