Merge branch 'v5.0.0dev' of https://gitee.com/ZhongBangKeJi/CRMEB into v5.0.0dev

This commit is contained in:
From-wh 2023-05-12 11:05:37 +08:00
commit 130decee2f
2 changed files with 58 additions and 15 deletions

View File

@ -0,0 +1,27 @@
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
HOSTPORT = 3306
USERNAME = crmeb
PASSWORD = '123456'
DATABASE = crmeb
PREFIX = eb_
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
[REDIS]
REDIS_HOSTNAME = 127.0.0.1
PORT = 6379
REDIS_PASSWORD = '123456'
SELECT = 0
[QUEUE]
QUEUE_NAME = 638f005e37b38

View File

@ -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' => [
[
@ -311,7 +314,7 @@ class SystemCrudServices extends BaseServices
$type = addslashes($type);
$default = addslashes($default);
if (in_array(strtolower($type), ['text', 'longtext', 'tinytext'])) {
$sql = "ALTER TABLE `$tableName` CHANGE `$field` `$changeFiled` $type CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '$comment';";
$sql = "ALTER TABLE `$tableName` CHANGE `$field` `$changeFiled` $type CHARACTER SET utf8mb4 COLLATE " . self::TABLR_COLLATION . " NULL COMMENT '$comment';";
} else {
$sql = "ALTER TABLE `$tableName` CHANGE `$field` `$changeFiled` $type($limit) NOT NULL DEFAULT '$default' COMMENT '$comment';";
}
@ -430,7 +433,8 @@ class SystemCrudServices extends BaseServices
}
continue;
} else {
//默认字段没有在数据库中,需要添加字段
//从数据库中新增的字段,并没有记录在表中做兼容处理;
//默认字段没有在数据库中,需要添加字段;
if (!in_array($item['default_field'], $fieldAll)) {
$addAlter[] = [
'prev_filed' => $prevFiled,
@ -506,7 +510,7 @@ class SystemCrudServices extends BaseServices
//先检查表存在则
if ($id) {
$this->updateFromCommon($tableName, $tableComment);
//删除数据库表
//读取数据库表
$tableInfo = $this->getTableInfo($tableName);
if ($tableInfo) {
//对比字段进行更新/删除字段
@ -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');
}