refactor: 全面代码重构与项目结构整理
安全性: - 所有SQL查询改用参数化查询(db_query),防止SQL注入 - TUSHARE_API_TOKEN集中到config.php常量,移除硬编码和多份拷贝 - getBasic.inc.php中$_REQUEST输出到JS时添加htmlspecialchars转义 代码组织: - 21个页面文件移至charts/子目录,根目录仅保留入口文件 - ajax.inc.php拆分:esfTradeDaily/esfListDaily迁至getEstate.inc.php - getBasic.inc.php拆分:HTML组件函数迁至新建的widgets.inc.php - 前端依赖去重:移除lib/echarts.min.js、libai/3.4.16.js、research/js/3.4.16.js 规范化: - AJAX响应格式统一为jsonResponse()标准封装 - 前端全局变量统一为window.chartConfig对象模式 - 修复PHP 8.4 Deprecated警告(getEstateData、getStockHistoryDataByTS参数顺序) - html/head.php中jQuery/CSS路径改为绝对路径,修复charts/子目录加载问题 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
+83
-6
@@ -1,12 +1,9 @@
|
||||
<?php
|
||||
include_once __DIR__."/config.php";
|
||||
function getEstateData($city='宁波',$fDate,$toDate){
|
||||
function getEstateData($city, $fDate, $toDate){
|
||||
$mysqli = get_mysqli_connection();
|
||||
$sql=<<<EOF
|
||||
SELECT city, listdate,sum(nums) as num FROM `estate_listing`
|
||||
where listdate>='$fDate' and listdate<='$toDate' and city='$city' group by listdate
|
||||
EOF;
|
||||
$result = $mysqli->query($sql);
|
||||
$sql = "SELECT city, listdate, sum(nums) as num FROM estate_listing where listdate >= ? and listdate <= ? and city = ? group by listdate";
|
||||
$result = db_query($mysqli, $sql, [$fDate, $toDate, $city]);
|
||||
$data=array();
|
||||
if($result && $result->num_rows>0) {
|
||||
while($row = $result->fetch_assoc()){
|
||||
@@ -16,4 +13,84 @@ EOF;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function esfTradeDaily(){
|
||||
global $mysqli;
|
||||
$district = $_REQUEST['district'];
|
||||
$t_start = $_REQUEST['t_start'];
|
||||
$t_end = $_REQUEST['t_end'];
|
||||
if($_REQUEST['dm']=='Daily'){
|
||||
$sql = "SELECT distinct(ej.uuid) uid, date_format(tdate,'%Y-%m-%d') td, eje.val district, eje1.val qty, eje2.val area
|
||||
FROM estate_json ej
|
||||
left join estate_json_ext eje on ej.uuid=eje.uuid and eje.val = ?
|
||||
left join estate_json_ext eje1 on eje1.id=eje.id+3
|
||||
left join estate_json_ext eje2 on eje2.id=eje.id+4
|
||||
where ej.data_type='5' and ej.tdate >= ? and ej.tdate <= ?
|
||||
order by ej.tdate asc";
|
||||
$params = [$district, $t_start, $t_end];
|
||||
}
|
||||
if($_REQUEST['dm']=='Monthly'){
|
||||
$sql = "SELECT distinct(ej.uuid) uid, date_format(tdate,'%Y-%m') td, eje.val district, sum(eje1.val) qty, sum(eje2.val) area
|
||||
FROM estate_json ej
|
||||
left join estate_json_ext eje on ej.uuid=eje.uuid and eje.val = ?
|
||||
left join estate_json_ext eje1 on eje1.id=eje.id+3
|
||||
left join estate_json_ext eje2 on eje2.id=eje.id+4
|
||||
where ej.data_type='5'";
|
||||
$params = [$district];
|
||||
if($t_start) {
|
||||
$sql .= " and ej.tdate >= ?";
|
||||
$params[] = $t_start . '-01';
|
||||
}
|
||||
if($t_end) {
|
||||
$endDate = new DateTime($t_end);
|
||||
$endDate->modify('last day of this month');
|
||||
$sql .= " and ej.tdate <= ?";
|
||||
$params[] = $endDate->format('Y-m-d');
|
||||
}
|
||||
$sql .= " group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc";
|
||||
}
|
||||
$result = db_query($mysqli, $sql, $params);
|
||||
$data = $result->fetch_all(MYSQLI_ASSOC);
|
||||
return $data;
|
||||
}
|
||||
|
||||
function esfListDaily(){
|
||||
global $mysqli;
|
||||
$district = $_REQUEST['district'];
|
||||
$t_start = $_REQUEST['t_start'];
|
||||
$t_end = $_REQUEST['t_end'];
|
||||
if($_REQUEST['dm']=='Daily'){
|
||||
$sql = "SELECT distinct(ej.uuid) uid, date_format(tdate,'%Y-%m-%d') td, eje.val district, eje1.val qty, eje2.val price
|
||||
FROM estate_json ej
|
||||
left join estate_json_ext eje on ej.uuid=eje.uuid and eje.val = ?
|
||||
left join estate_json_ext eje1 on eje1.id=eje.id+3
|
||||
left join estate_json_ext eje2 on eje2.id=eje.id+5
|
||||
where ej.data_type='8' and ej.tdate >= ? and ej.tdate <= ?
|
||||
order by ej.tdate asc";
|
||||
$params = [$district, $t_start, $t_end];
|
||||
}
|
||||
if($_REQUEST['dm']=='Monthly'){
|
||||
$sql = "SELECT distinct(ej.uuid) uid, date_format(tdate,'%Y-%m') td, eje.val district, sum(eje1.val) qty, sum(eje2.val) price
|
||||
FROM estate_json ej
|
||||
left join estate_json_ext eje on ej.uuid=eje.uuid and eje.val = ?
|
||||
left join estate_json_ext eje1 on eje1.id=eje.id+3
|
||||
left join estate_json_ext eje2 on eje2.id=eje.id+5
|
||||
where ej.data_type='8'";
|
||||
$params = [$district];
|
||||
if($t_start) {
|
||||
$sql .= " and ej.tdate >= ?";
|
||||
$params[] = $t_start . '-01';
|
||||
}
|
||||
if($t_end) {
|
||||
$endDate = new DateTime($t_end);
|
||||
$endDate->modify('last day of this month');
|
||||
$sql .= " and ej.tdate <= ?";
|
||||
$params[] = $endDate->format('Y-m-d');
|
||||
}
|
||||
$sql .= " group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc";
|
||||
}
|
||||
$result = db_query($mysqli, $sql, $params);
|
||||
$data = $result->fetch_all(MYSQLI_ASSOC);
|
||||
return $data;
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user