Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
racns committed Feb 13, 2023
1 parent 26b02c8 commit 71279b2
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 106 deletions.
2 changes: 1 addition & 1 deletion app/admin/controller/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function initialize()

// 开启了自动更新
$autoUpdate = Options::where(['keys'=>'config:system'])->value('opt');
$autoUpdate = json_decode($autoUpdate, true);
$autoUpdate = json_decode($autoUpdate ?? '', true);
$autoUpdate = $autoUpdate['system']['autoUpdate'] ?? false;
$autoUpdate = $autoUpdate == 'true' or $autoUpdate === true ? true : false;

Expand Down
6 changes: 3 additions & 3 deletions app/api/controller/default/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function ip($request)
$code = 400;
$msg = Lang::get('无数据!');

$ip = !empty($param['ip']) ? $param['ip'] : $this->helper->GetClientIP();
$ip = !empty($param['ip']) ? $param['ip'] : $this->utils->get->ip()['ip'];

// 设置缓存名称
$cache_name = json_encode(array_merge(['IAPI'=>'location'], $param));
Expand All @@ -118,12 +118,12 @@ public function ip($request)
else {

// 获取数据
$result = $this->helper->get($this->config['official']['api'] . 'gothe', ['ip'=>$ip], ['origin'=>$this->helper->domain()]);
$result = $this->utils->curl->get($this->config['official']['api'] . 'gothe', ['ip'=>$ip], ['origin'=>$this->helper->domain()]);

if ($result['code'] == 200) $data = $result['data'];
else $data = $result;

if ($this->ApiCache) Cache::tag(['gothe',$cache_name])->set($cache_name, json_encode($data));
if ($this->ApiCache) Cache::tag(['gothe', $cache_name])->set($cache_name, json_encode($data));

}

Expand Down
90 changes: 25 additions & 65 deletions app/install/controller/Handle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ class Handle extends BaseController
{
protected $File;
protected $helper;
protected $DBUPDATE;

public function __construct()
{
$this->File = new File;
$this->helper = new helper;
$this->DBUPDATE = Config::get('dbupdate');

$path = app()->getRootPath() . '/extend';
$dir = $this->File->getDir($path)['dir'];
Expand Down Expand Up @@ -164,91 +162,53 @@ public function fulfill()
$this->File->unlinkFile('install.env');
$this->File->writeFile($route, $text);
}
// 批量建表
public function createTables(Request $request)

// 批量导入数据
public function initDB(Request $request)
{
if ($request->isPost())
{

if ($request->isPost()) {

$data = [];
$code = 200;
$msg = 'ok';

$param = $request->param();
$db = !empty($param['db']) ? $param['db'] : 'mysql';

// 获取表信息
$tabs = $this->helper->get(config('inis.official.api') . $db . '/created');
// 获取数据信息
$array = config('inis_db.' . $db);

if ($tabs['code'] != 200) return $this->create([], $tabs['msg'], 400);
try {

// 数据库
$conn = Db::connect($db);
foreach ($array as $key => $val) {

// SQL 语句
$sqls = [];
if (!empty($tabs['data'])) {
// 数据库
$conn = Db::connect($db);

// mysql 驱动
if ($db == 'mysql') foreach ($tabs['data'] as $key => $val) {
// 如果表不存在,先创建该表
if (!in_array($key, $conn->getTables())) $conn->execute($val['sql']);

// 如果表已存在,先删除该表
if (in_array($key, $conn->getTables())) $conn->execute('DROP TABLE '. $key);
if (!empty($val['data'])) {

$sqls[] = $val;
// 重新设置自增起始值
$sqls[] = "ALTER TABLE " . $key . " AUTO_INCREMENT=1;";
}
// sqlite 驱动
else if ($db == 'sqlite') foreach ($tabs['data'] as $key => $val) {

// 如果表已存在,先删除该表
if (in_array($key, $conn->getTables())) $conn->execute('DROP TABLE '. $key);
// 重新设置自增起始值
$conn->execute("ALTER TABLE " . $key . " AUTO_INCREMENT=1;");

// 清空表数据
$conn->execute('TRUNCATE TABLE ' . $key);

$sqls[] = $val;
// 批量插入数据
$conn->table($key)->insertAll($val['data']);
}
}
}

try {

// 执行 SQL 语句
if (!empty($sqls)) foreach ($sqls as $val) $conn->execute($val);

} catch (\Exception $e) {

$code = 400;
$msg = $e->getMessage();
}

return $this->create($data, $msg, $code);
}
}

// 批量导入数据
public function insertAll(Request $request)
{
if ($request->isPost())
{
$data = [];
$code = 200;
$msg = 'ok';
$param = $request->param();

$db = !empty($param['db']) ? $param['db'] : 'mysql';

// 获取默认数据
$result= $this->helper->get(config('inis.official.api') . $db . '/data');

// 估计是没有权限 - 或者网络问题
if ($result['code'] != 200) return $this->create([], $result['msg'], (int)$result['code']);

// 先判断数据有没有
if (!empty($result['data'])) foreach ($result['data'] as $key => $val) {
// 批量插入数据
Db::connect($db)->table($key)->insertAll($val);
}

return $this->create($result, $msg, $code);
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"php": ">=7.1.0",
"php": ">=8.0.0",
"topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0",
"topthink/think-view": "^1.0",
Expand Down
4 changes: 2 additions & 2 deletions config/inis.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
'valid_time' => 5 * 60, // 验证码有效时间 - 单位秒
'jwt' => [
'key' => 'inis-api', // KEY - 用于校验 TOKEN 是否合法
'key' => 'inis-api-asd', // KEY - 用于校验 TOKEN 是否合法
'encrypt' => 'HS256', // 加密方式
'array' => ['HS256','HS384','HS512'], // 可用加密方式
],
Expand Down Expand Up @@ -65,5 +65,5 @@
]
],

'version' => '2.0.0', // inis 版本号 - 请不要自行更改,后果自负
'version' => '2.0.1', // inis 版本号 - 请不要自行更改,后果自负
];
Loading

0 comments on commit 71279b2

Please sign in to comment.