mirror of
https://gitee.com/technical-laohu/mpay.git
synced 2025-09-17 09:16:40 +08:00
修复首次安装程序报错问题
This commit is contained in:
parent
cd9d416bc1
commit
2cd6eafb02
@ -29,7 +29,21 @@ class InstallController
|
||||
$dbConfig = $request->post();
|
||||
|
||||
// 保存数据库配置信息到配置文件
|
||||
$this->saveDbConfig($dbConfig);
|
||||
if ($this->saveDbConfig($dbConfig) === false) {
|
||||
return json(backMsg(1, '配置保存失败'));
|
||||
} else {
|
||||
return json(backMsg(0, '配置保存成功'));
|
||||
};
|
||||
}
|
||||
// 初始化数据库
|
||||
public function init(Request $request)
|
||||
{
|
||||
// 检查是否已经安装过
|
||||
if ($this->checkLock()) {
|
||||
return backMsg(1, '已经安装');
|
||||
};
|
||||
// 获取表单提交的数据库配置信息
|
||||
$dbConfig = $request->post();
|
||||
|
||||
// 连接数据库并建表
|
||||
$is_succ_tb = $this->createTables();
|
||||
@ -66,7 +80,7 @@ DB_PREFIX = mpay_
|
||||
|
||||
DEFAULT_LANG = zh-cn
|
||||
EOT;
|
||||
file_put_contents($envPath, $envContent);
|
||||
return file_put_contents($envPath, $envContent);
|
||||
}
|
||||
|
||||
private function createTables()
|
||||
|
@ -6,9 +6,9 @@
|
||||
<title>程序安装</title>
|
||||
<link rel="stylesheet" href="/component/pear/css/pear.css" />
|
||||
<style>
|
||||
.logo1 {
|
||||
width: 180px !important;
|
||||
}
|
||||
.logo1 {
|
||||
width: 180px !important;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 30px !important;
|
||||
@ -124,32 +124,27 @@
|
||||
// 监听提交
|
||||
form.on('submit(formSubmit)', function (data) {
|
||||
const field = data.field;
|
||||
// 提交表单
|
||||
fetch('/install/install', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(field)
|
||||
}).then(res => {
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
}
|
||||
throw new Error('数据库配置错误');
|
||||
}).then(res => {
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, {
|
||||
time: 1000,
|
||||
end: () => {
|
||||
window.location.href = '/User/login';
|
||||
}
|
||||
});
|
||||
(async () => {
|
||||
const saveRes = await fetch('/install/install', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(field) });
|
||||
const saveJson = await saveRes.json();
|
||||
if (saveJson.code == 0) {
|
||||
const initRes = await fetch('/install/init', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(field) });
|
||||
if (initRes.status != 200) { layer.msg('初始化失败,请检查配置'); return; }
|
||||
const initJson = await initRes.json();
|
||||
if (initJson.code == 0) {
|
||||
layer.msg(initJson.msg, {
|
||||
time: 1000,
|
||||
end: () => {
|
||||
window.location.href = '/User/login';
|
||||
}
|
||||
});
|
||||
} else {
|
||||
layer.msg(initJson.msg);
|
||||
}
|
||||
} else {
|
||||
layer.msg(res.msg);
|
||||
layer.msg(json.msg);
|
||||
}
|
||||
}).catch(err => {
|
||||
layer.msg(err.message);
|
||||
})
|
||||
})()
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user