mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-30 22:40:48 +00:00
调增不在读取数据库默认信息
This commit is contained in:
parent
f0392ae7fd
commit
8db3c21a07
@ -79,6 +79,9 @@ class SystemCrudServices extends BaseServices
|
||||
'wechat_qrcode_cate', 'wechat_qrcode_record', 'wechat_reply', 'wechat_user'
|
||||
];
|
||||
|
||||
//表字符集
|
||||
const TABLR_COLLATION = 'utf8mb4_general_ci';
|
||||
|
||||
/**
|
||||
* SystemCrudServices constructor.
|
||||
* @param SystemCrudDao $dao
|
||||
@ -144,8 +147,8 @@ class SystemCrudServices extends BaseServices
|
||||
|
||||
'json',
|
||||
|
||||
'addTimestamps',
|
||||
'addSoftDelete',
|
||||
// 'addTimestamps',
|
||||
// 'addSoftDelete',
|
||||
],
|
||||
'form' => [
|
||||
[
|
||||
@ -430,7 +433,8 @@ class SystemCrudServices extends BaseServices
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
//默认字段没有在数据库中,需要添加字段
|
||||
//从数据库中新增的字段,并没有记录在表中做兼容处理;
|
||||
//默认字段没有在数据库中,需要添加字段;
|
||||
if (!in_array($item['default_field'], $fieldAll)) {
|
||||
$addAlter[] = [
|
||||
'prev_filed' => $prevFiled,
|
||||
@ -571,7 +575,7 @@ class SystemCrudServices extends BaseServices
|
||||
$crudInfo = $this->dao->get($id);
|
||||
}
|
||||
|
||||
$res = $this->transaction(function () use ($tableCreateInfo, $crudInfo, $tableInfo, $modelName, $filePath, $tableName, $routeName, $data, $dataMenu) {
|
||||
$res = $this->transaction(function () use ($tableComment, $tableCreateInfo, $crudInfo, $modelName, $filePath, $tableName, $routeName, $data, $dataMenu) {
|
||||
$routeService = app()->make(SystemRouteServices::class);
|
||||
$meunService = app()->make(SystemMenusServices::class);
|
||||
//修改菜单名称
|
||||
@ -683,7 +687,6 @@ class SystemCrudServices extends BaseServices
|
||||
if ($tableCreateInfo && isset($tableCreateInfo['table']) && $tableCreateInfo['table'] instanceof Table) {
|
||||
//创建数据库
|
||||
$tableCreateInfo['table']->create();
|
||||
$tableInfo = $this->getTableInfo($tableName);
|
||||
}
|
||||
|
||||
$crudDate = [
|
||||
@ -691,8 +694,8 @@ class SystemCrudServices extends BaseServices
|
||||
'name' => $data['menuName'],
|
||||
'model_name' => $data['modelName'],
|
||||
'table_name' => $tableName,
|
||||
'table_comment' => $tableInfo['TABLE_COMMENT'] ?? '',
|
||||
'table_collation' => $tableInfo['TABLE_COLLATION'] ?? '',
|
||||
'table_comment' => $tableComment,
|
||||
'table_collation' => self::TABLR_COLLATION,
|
||||
'field' => json_encode($data),//提交的数据
|
||||
'menu_ids' => json_encode($menuIds),//生成的菜单id
|
||||
'menu_id' => $menuInfo->id,//生成的菜单id
|
||||
@ -778,13 +781,14 @@ class SystemCrudServices extends BaseServices
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/4/7
|
||||
*/
|
||||
public function makeDatebase(string $tableName, string $tableComment, array $tableField = [])
|
||||
public function makeDatebase(string $tableName, string $tableComment, array $tableField = [], string $collation = self::TABLR_COLLATION)
|
||||
{
|
||||
$timestampsField = [];
|
||||
$softDelete = false;
|
||||
$timestamps = false;
|
||||
$indexField = [];
|
||||
//创建表
|
||||
$table = new Table($tableName, ['comment' => $tableComment], $this->getAdapter());
|
||||
$table = new Table($tableName, ['comment' => $tableComment, 'collation' => $collation], $this->getAdapter());
|
||||
//创建字段
|
||||
foreach ($tableField as $item) {
|
||||
if (isset($item['primaryKey']) && $item['primaryKey']) {
|
||||
@ -801,10 +805,9 @@ class SystemCrudServices extends BaseServices
|
||||
if ($item['field_type'] === 'addSoftDelete') {
|
||||
$table->addSoftDelete();
|
||||
$softDelete = true;
|
||||
} else if ($item['field_type'] === 'addTimestamps') {
|
||||
//创建修改和增加时间
|
||||
$table->addTimestamps();
|
||||
$timestamps = true;
|
||||
} else if ($item['field_type'] == 'timestamp' &&
|
||||
($item['field'] === 'create_time' || $item['field'] === 'update_time')) {
|
||||
$timestampsField[] = $item;
|
||||
} else {
|
||||
$option['comment'] = $item['comment'];
|
||||
$fieldType = $this->changeTabelRule($item['field_type']);
|
||||
@ -826,6 +829,19 @@ class SystemCrudServices extends BaseServices
|
||||
}
|
||||
}
|
||||
|
||||
//如果是成对出现的create_time和update_time就直接增加修改和添加时间
|
||||
if (count($timestampsField) == 2) {
|
||||
//创建修改和增加时间
|
||||
$table->addTimestamps();
|
||||
$timestamps = true;
|
||||
} else {
|
||||
//如果是一个数组,增加一列
|
||||
foreach ($timestampsField as $item) {
|
||||
$option['comment'] = $item['comment'];
|
||||
$table->addColumn($item['field'], $this->changeTabelRule($item['field_type']), $option);
|
||||
}
|
||||
}
|
||||
|
||||
return compact('indexField', 'softDelete', 'timestamps', 'table');
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user