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:
+56
-194
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
ini_set("display_errors","0");
|
||||
include_once __DIR__."/config.php";
|
||||
include_once __DIR__."/getEstate.inc.php";
|
||||
$mysqli = get_mysqli_connection();
|
||||
|
||||
//ajax: get stock list for select
|
||||
@@ -17,13 +18,9 @@ EOF;
|
||||
where tprice>0 and ts_code not like '7%' and length(0+ts_name)!=length(ts_name) order by ts_code
|
||||
EOF;
|
||||
}
|
||||
$result = $mysqli->query($sql);
|
||||
$result = db_query($mysqli, $sql);
|
||||
$data = $result->fetch_all(MYSQLI_ASSOC);
|
||||
echo json_encode(array(
|
||||
"status" => "1",
|
||||
'stocks'=> $data,
|
||||
"company"=>$_REQUEST['t_vendor'],
|
||||
),JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
jsonResponse(['stocks' => $data, 'company' => $_REQUEST['t_vendor']]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +63,7 @@ if($_REQUEST['t']=='financeData'){
|
||||
//strip key from array $data
|
||||
//dataTable must NOT have any key of json
|
||||
$data=array_values($data);
|
||||
echo json_encode(array("data"=>$data),JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
jsonResponse($data);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -75,11 +72,7 @@ if($_REQUEST['t']=='financeData'){
|
||||
if($_REQUEST['t']=='esfTBD'){
|
||||
$dataTrade=esfTradeDaily();
|
||||
$dataList=esfListDaily();
|
||||
echo json_encode(array(
|
||||
"status" => "1",
|
||||
'dataTrade'=> $dataTrade,
|
||||
'dataList'=>$dataList
|
||||
),JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
jsonResponse(['dataTrade' => $dataTrade, 'dataList' => $dataList]);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -88,204 +81,73 @@ if($_REQUEST['t']=='esfTBD'){
|
||||
if($_REQUEST['t']=='esfListDaily'){
|
||||
$data=esfListDaily();
|
||||
|
||||
echo json_encode(array(
|
||||
"status" => "1",
|
||||
'datas'=> $data
|
||||
),JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
jsonResponse(['datas' => $data]);
|
||||
}
|
||||
function esfTradeDaily(){
|
||||
global $mysqli;
|
||||
if($_REQUEST['dm']=='Daily'){
|
||||
$sql= <<<EOF
|
||||
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='{$_REQUEST['district']}'
|
||||
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>='{$_REQUEST['t_start']}' and ej.tdate<='{$_REQUEST['t_end']}')
|
||||
order by ej.tdate asc
|
||||
EOF;
|
||||
}
|
||||
if($_REQUEST['dm']=='Monthly'){
|
||||
$where="";
|
||||
if($_REQUEST['t_start']) $where .=" and ej.tdate>='{$_REQUEST['t_start']}-01'";
|
||||
if($_REQUEST['t_end']) {
|
||||
$endDate = new DateTime($_REQUEST['t_end']);
|
||||
$endDate->modify('last day of this month');
|
||||
$where .=" and ej.tdate<='{$endDate->format('Y-m-d')}'";
|
||||
}
|
||||
$sql= <<<EOF
|
||||
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='{$_REQUEST['district']}'
|
||||
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' {$where}
|
||||
group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc
|
||||
EOF;
|
||||
//echo $sql;
|
||||
}
|
||||
|
||||
$result = $mysqli->query($sql);
|
||||
$data = $result->fetch_all(MYSQLI_ASSOC);
|
||||
return $data;
|
||||
}
|
||||
|
||||
function esfListDaily(){
|
||||
global $mysqli;
|
||||
if($_REQUEST['dm']=='Daily'){
|
||||
$sql= <<<EOF
|
||||
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='{$_REQUEST['district']}'
|
||||
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>='{$_REQUEST['t_start']}' and ej.tdate<='{$_REQUEST['t_end']}')
|
||||
order by ej.tdate asc
|
||||
EOF;
|
||||
}
|
||||
if($_REQUEST['dm']=='Monthly'){
|
||||
$where="";
|
||||
if($_REQUEST['t_start']) $where .=" and ej.tdate>='{$_REQUEST['t_start']}-01'";
|
||||
if($_REQUEST['t_end']) {
|
||||
$endDate = new DateTime($_REQUEST['t_end']);
|
||||
$endDate->modify('last day of this month');
|
||||
$where .=" and ej.tdate<='{$endDate->format('Y-m-d')}'";
|
||||
}
|
||||
$sql= <<<EOF
|
||||
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='{$_REQUEST['district']}'
|
||||
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' {$where}
|
||||
group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc
|
||||
EOF;
|
||||
//echo $sql;
|
||||
}
|
||||
$result = $mysqli->query($sql);
|
||||
$data = $result->fetch_all(MYSQLI_ASSOC);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/*
|
||||
*newTBD: 新房Trade By Day
|
||||
*/
|
||||
if($_REQUEST['t']=='newTBD'){
|
||||
$district = $_REQUEST['district'];
|
||||
$t_start = $_REQUEST['t_start'];
|
||||
$t_end = $_REQUEST['t_end'];
|
||||
if($_REQUEST['dm']=='Daily'){
|
||||
$sql= <<<EOF
|
||||
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='{$_REQUEST['district']}'
|
||||
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='1' and (ej.tdate>='{$_REQUEST['t_start']}' and ej.tdate<='{$_REQUEST['t_end']}')
|
||||
order by date_format(tdate,'%Y-%m-%d') asc
|
||||
EOF;
|
||||
$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='1' and ej.tdate >= ? and ej.tdate <= ?
|
||||
order by date_format(tdate,'%Y-%m-%d') asc";
|
||||
$params = [$district, $t_start, $t_end];
|
||||
}
|
||||
if($_REQUEST['dm']=='Monthly'){
|
||||
$where="";
|
||||
if($_REQUEST['t_start']) $where .=" and ej.tdate>='{$_REQUEST['t_start']}-01'";
|
||||
if($_REQUEST['t_end']) {
|
||||
$endDate = new DateTime($_REQUEST['t_end']);
|
||||
$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='1'";
|
||||
$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');
|
||||
$where .=" and ej.tdate<='{$endDate->format('Y-m-d')}'";
|
||||
}
|
||||
$sql= <<<EOF
|
||||
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='{$_REQUEST['district']}'
|
||||
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='1' {$where}
|
||||
group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc
|
||||
EOF;
|
||||
$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 = $mysqli->query($sql);
|
||||
$result = db_query($mysqli, $sql, $params);
|
||||
$data = $result->fetch_all(MYSQLI_ASSOC);
|
||||
if($_REQUEST['dm']=='Daily'){
|
||||
$sql= <<<EOF
|
||||
SELECT
|
||||
distinct(ej.uuid) uid ,
|
||||
date_format(tdate,'%Y-%m-%d') td,
|
||||
eje.val district,
|
||||
eje1.val area,
|
||||
eje2.val qty
|
||||
FROM
|
||||
`estate_json` ej
|
||||
left join estate_json_ext eje on ej.uuid=eje.uuid and eje.val='{$_REQUEST['district']}'
|
||||
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='4' and (ej.tdate>='{$_REQUEST['t_start']}' and ej.tdate<='{$_REQUEST['t_end']}')
|
||||
order by date_format(tdate,'%Y-%m-%d') asc
|
||||
EOF;
|
||||
$sql2 = "SELECT distinct(ej.uuid) uid, date_format(tdate,'%Y-%m-%d') td, eje.val district, eje1.val area, eje2.val qty
|
||||
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='4' and ej.tdate >= ? and ej.tdate <= ?
|
||||
order by date_format(tdate,'%Y-%m-%d') asc";
|
||||
$params2 = [$district, $t_start, $t_end];
|
||||
}
|
||||
if($_REQUEST['dm']=='Monthly'){
|
||||
$where="";
|
||||
if($_REQUEST['t_start']) $where .=" and ej.tdate>='{$_REQUEST['t_start']}-01'";
|
||||
if($_REQUEST['t_end']) {
|
||||
$endDate = new DateTime($_REQUEST['t_end']);
|
||||
$sql2 = "SELECT distinct(ej.uuid) uid, date_format(tdate,'%Y-%m-%d') td, eje.val district, max(eje1.val) area, max(eje2.val) qty
|
||||
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='4'";
|
||||
$params2 = [$district];
|
||||
if($t_start) { $sql2 .= " and ej.tdate >= ?"; $params2[] = $t_start . '-01'; }
|
||||
if($t_end) {
|
||||
$endDate = new DateTime($t_end);
|
||||
$endDate->modify('last day of this month');
|
||||
$where .=" and ej.tdate<='{$endDate->format('Y-m-d')}'";
|
||||
$sql2 .= " and ej.tdate <= ?";
|
||||
$params2[] = $endDate->format('Y-m-d');
|
||||
}
|
||||
$sql= <<<EOF
|
||||
SELECT
|
||||
distinct(ej.uuid) uid ,
|
||||
date_format(tdate,'%Y-%m-%d') td,
|
||||
eje.val district,
|
||||
max(eje1.val) area,
|
||||
max(eje2.val) qty
|
||||
FROM
|
||||
`estate_json` ej
|
||||
left join estate_json_ext eje on ej.uuid=eje.uuid and eje.val='{$_REQUEST['district']}'
|
||||
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='4' $where
|
||||
group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc
|
||||
EOF;
|
||||
}
|
||||
$result = $mysqli->query($sql);
|
||||
$sql2 .= " group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc";
|
||||
}
|
||||
$result = db_query($mysqli, $sql2, $params2);
|
||||
$data2 = $result->fetch_all(MYSQLI_ASSOC);
|
||||
echo json_encode(array(
|
||||
"status" => "1",
|
||||
'datas'=> $data,
|
||||
'dataExt'=> $data2
|
||||
),JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
jsonResponse(['datas' => $data, 'dataExt' => $data2]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user