|
|
@ -15,14 +15,15 @@ class Api { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* name:创建分类目录 |
|
|
|
* name:创建分类目录 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function add_category($token,$name,$property = 0,$weight = 0,$description = ''){ |
|
|
|
public function add_category($token,$name,$property = 0,$weight = 0,$description = '',$font_icon = ''){ |
|
|
|
$this->auth($token); |
|
|
|
$this->auth($token); |
|
|
|
$data = [ |
|
|
|
$data = [ |
|
|
|
'name' => htmlspecialchars($name,ENT_QUOTES), |
|
|
|
'name' => htmlspecialchars($name,ENT_QUOTES), |
|
|
|
'add_time' => time(), |
|
|
|
'add_time' => time(), |
|
|
|
'weight' => $weight, |
|
|
|
'weight' => $weight, |
|
|
|
'property' => $property, |
|
|
|
'property' => $property, |
|
|
|
'description' => htmlspecialchars($description,ENT_QUOTES) |
|
|
|
'description' => htmlspecialchars($description,ENT_QUOTES), |
|
|
|
|
|
|
|
'font_icon' => $font_icon |
|
|
|
]; |
|
|
|
]; |
|
|
|
//插入分类目录 |
|
|
|
//插入分类目录 |
|
|
|
$this->db->insert("on_categorys",$data); |
|
|
|
$this->db->insert("on_categorys",$data); |
|
|
@ -46,7 +47,7 @@ class Api { |
|
|
|
* 修改分类目录 |
|
|
|
* 修改分类目录 |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function edit_category($token,$id,$name,$property = 0,$weight = 0,$description = ''){ |
|
|
|
public function edit_category($token,$id,$name,$property = 0,$weight = 0,$description = '',$font_icon = ''){ |
|
|
|
$this->auth($token); |
|
|
|
$this->auth($token); |
|
|
|
//如果id为空 |
|
|
|
//如果id为空 |
|
|
|
if( empty($id) ){ |
|
|
|
if( empty($id) ){ |
|
|
@ -63,7 +64,8 @@ class Api { |
|
|
|
'up_time' => time(), |
|
|
|
'up_time' => time(), |
|
|
|
'weight' => $weight, |
|
|
|
'weight' => $weight, |
|
|
|
'property' => $property, |
|
|
|
'property' => $property, |
|
|
|
'description' => htmlspecialchars($description,ENT_QUOTES) |
|
|
|
'description' => htmlspecialchars($description,ENT_QUOTES), |
|
|
|
|
|
|
|
'font_icon' => $font_icon |
|
|
|
]; |
|
|
|
]; |
|
|
|
$re = $this->db->update('on_categorys',$data,[ 'id' => $id]); |
|
|
|
$re = $this->db->update('on_categorys',$data,[ 'id' => $id]); |
|
|
|
//var_dump( $this->db->log() ); |
|
|
|
//var_dump( $this->db->log() ); |
|
|
@ -636,9 +638,13 @@ class Api { |
|
|
|
* 循环读取db/sql/目录下的.sql文件 |
|
|
|
* 循环读取db/sql/目录下的.sql文件 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function get_sql_update_list($data) { |
|
|
|
public function get_sql_update_list($data) { |
|
|
|
//待升级的数据库文件目录 |
|
|
|
//鉴权 |
|
|
|
|
|
|
|
if( !$this->is_login() ) { |
|
|
|
|
|
|
|
$this->err_msg(-1002,'Authorization failure!'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//待更新的数据库文件目录 |
|
|
|
$sql_dir = 'db/sql/'; |
|
|
|
$sql_dir = 'db/sql/'; |
|
|
|
//sql文件列表,默认为空 |
|
|
|
//待更新的sql文件列表,默认为空 |
|
|
|
$sql_files_all = []; |
|
|
|
$sql_files_all = []; |
|
|
|
//打开一个目录,读取里面的文件列表 |
|
|
|
//打开一个目录,读取里面的文件列表 |
|
|
|
if (is_dir($sql_dir)){ |
|
|
|
if (is_dir($sql_dir)){ |
|
|
@ -663,23 +669,28 @@ class Api { |
|
|
|
if ( $num === 0 ) { |
|
|
|
if ( $num === 0 ) { |
|
|
|
$data = [ |
|
|
|
$data = [ |
|
|
|
"code" => 0, |
|
|
|
"code" => 0, |
|
|
|
"data" => ['on_db_logs'] |
|
|
|
"data" => ['on_db_logs.sql'] |
|
|
|
]; |
|
|
|
]; |
|
|
|
exit(json_encode($data)); |
|
|
|
exit(json_encode($data)); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
//如果不为0,则需要进行比对 |
|
|
|
//如果不为0,则需要查询数据库更新表里面的数据进行差集比对 |
|
|
|
$get_on_db_logs = $this->db->select("on_db_logs",[ |
|
|
|
$get_on_db_logs = $this->db->select("on_db_logs",[ |
|
|
|
"sql_name" |
|
|
|
"sql_name" |
|
|
|
],[ |
|
|
|
],[ |
|
|
|
"status" => "TRUE" |
|
|
|
"status" => "TRUE" |
|
|
|
]); |
|
|
|
]); |
|
|
|
//声明一个空数组,存储已更新的数据库 |
|
|
|
//声明一个空数组,存储已更新的数据库列表 |
|
|
|
$already_dbs = []; |
|
|
|
$already_dbs = []; |
|
|
|
foreach ($get_on_db_logs as $key => $value) { |
|
|
|
foreach ($get_on_db_logs as $value) { |
|
|
|
array_push($already_dbs,$value['sql_name']); |
|
|
|
array_push($already_dbs,$value['sql_name']); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//array_diff() 函数返回两个数组的差集数组 |
|
|
|
//array_diff() 函数返回两个数组的差集数组 |
|
|
|
$diff_result = array_diff($sql_files_all,$already_dbs); |
|
|
|
$diff_result = array_diff($sql_files_all,$already_dbs); |
|
|
|
|
|
|
|
//去掉键 |
|
|
|
|
|
|
|
$diff_result = array_values($diff_result); |
|
|
|
|
|
|
|
sort($diff_result); |
|
|
|
|
|
|
|
|
|
|
|
$data = [ |
|
|
|
$data = [ |
|
|
|
"code" => 0, |
|
|
|
"code" => 0, |
|
|
|
"data" => $diff_result |
|
|
|
"data" => $diff_result |
|
|
@ -692,13 +703,17 @@ class Api { |
|
|
|
* 执行SQL更新语句,只执行单条更新 |
|
|
|
* 执行SQL更新语句,只执行单条更新 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function exe_sql($data) { |
|
|
|
public function exe_sql($data) { |
|
|
|
|
|
|
|
//鉴权 |
|
|
|
|
|
|
|
if( !$this->is_login() ) { |
|
|
|
|
|
|
|
$this->err_msg(-1002,'Authorization failure!'); |
|
|
|
|
|
|
|
} |
|
|
|
//数据库sql目录 |
|
|
|
//数据库sql目录 |
|
|
|
$sql_dir = 'db/sql/'; |
|
|
|
$sql_dir = 'db/sql/'; |
|
|
|
$name = $data['name']; |
|
|
|
$name = $data['name']; |
|
|
|
$sql_name = $sql_dir.$name.'.sql'; |
|
|
|
$sql_name = $sql_dir.$name; |
|
|
|
//如果文件不存在,直接返回错误 |
|
|
|
//如果文件不存在,直接返回错误 |
|
|
|
if ( !file_exists($sql_name) ) { |
|
|
|
if ( !file_exists($sql_name) ) { |
|
|
|
$this->err_msg(-2000,$name.'.sql不存在!'); |
|
|
|
$this->err_msg(-2000,$name.'不存在!'); |
|
|
|
} |
|
|
|
} |
|
|
|
//读取需要更新的SQL内容 |
|
|
|
//读取需要更新的SQL内容 |
|
|
|
try { |
|
|
|
try { |
|
|
@ -708,24 +723,24 @@ class Api { |
|
|
|
if( $result ) { |
|
|
|
if( $result ) { |
|
|
|
//将更新信息写入数据库 |
|
|
|
//将更新信息写入数据库 |
|
|
|
$insert_re = $this->db->insert("on_db_logs",[ |
|
|
|
$insert_re = $this->db->insert("on_db_logs",[ |
|
|
|
"sql_name" => $name.'.sql', |
|
|
|
"sql_name" => $name, |
|
|
|
"update_time" => time() |
|
|
|
"update_time" => time() |
|
|
|
]); |
|
|
|
]); |
|
|
|
if( $insert_re ) { |
|
|
|
if( $insert_re ) { |
|
|
|
$data = [ |
|
|
|
$data = [ |
|
|
|
"code" => 0, |
|
|
|
"code" => 0, |
|
|
|
"data" => $name.".sql更新完成!" |
|
|
|
"data" => $name."更新完成!" |
|
|
|
]; |
|
|
|
]; |
|
|
|
exit(json_encode($data)); |
|
|
|
exit(json_encode($data)); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
$this->err_msg(-2000,$name.".sql更新失败,请人工检查!"); |
|
|
|
$this->err_msg(-2000,$name."更新失败,请人工检查!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
else{ |
|
|
|
//如果执行失败 |
|
|
|
//如果执行失败 |
|
|
|
$this->err_msg(-2000,$name.".sql更新失败,请人工检查!"); |
|
|
|
$this->err_msg(-2000,$name."更新失败,请人工检查!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch(Exception $e){ |
|
|
|
} catch(Exception $e){ |
|
|
|
$this->err_msg(-2000,$e->getMessage()); |
|
|
|
$this->err_msg(-2000,$e->getMessage()); |
|
|
|