Files
echart/inc/ajax.inc.php
T
simonandClaude Code 7e57cae242 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>
2026-05-26 08:20:33 +08:00

154 lines
5.8 KiB
PHP

<?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
if($_REQUEST['t']=='stockList'){
if($_REQUEST['t_vendor']=='方正证券'){
$sql= <<< EOF
select distinct(ts_code) ts_code,ts_name from trade_record
where tprice>0 and (ts_code not like '7%' and ts_code not like '1%') and length(trade_id)=5 order by ts_code
EOF;
}elseif($_REQUEST['t_vendor']=='长江证券'){
//length(0+ts_name)!=length(ts_name) 判断ts_name 不能为纯数字
$sql= <<< EOF
select distinct(ts_code) ts_code,ts_name from trade_record_cj
where tprice>0 and ts_code not like '7%' and length(0+ts_name)!=length(ts_name) order by ts_code
EOF;
}
$result = db_query($mysqli, $sql);
$data = $result->fetch_all(MYSQLI_ASSOC);
jsonResponse(['stocks' => $data, 'company' => $_REQUEST['t_vendor']]);
}
/**
* AJAX get finance Data from getFianceData class
*/
if($_REQUEST['t']=='financeData'){
include_once __DIR__."/getFinanceData.class.php";
include_once __DIR__."/getBasic.inc.php";
$years=yearList($_REQUEST['yst'],$_REQUEST['yed']);
$fina = new getFinance();
$fina->ts_code=$_REQUEST['ts_code'];
$dataAll=array();
foreach($years as $year){
$fina->finDate=$year;
$dataAll[] =$fina->getFinanceData();
}
for($i=0;$i<count($dataAll);$i++){
$n=0;
foreach ($dataAll[$i] as $key=>$val){
$n++;
if(strlen($n)<2) $n='0'.$n;
if($key=='ts_code') {
$key=$n.'.股票代码';
$val=tscodeToName($val);
$n--;
continue; //不显示股票代码
}elseif($key=='period') {
$key=$n.'.报告期';
$val=yearToname($val);
$n--;
continue; //不显示报告期
}else $key=$n.'.'.$key;
if($i==0) $data[$n][]=$key; //首列加
$data[$n][]=$val;
}
}
//strip key from array $data
//dataTable must NOT have any key of json
$data=array_values($data);
jsonResponse($data);
}
/*
*esfTBD: 二手房Trade By Day
*/
if($_REQUEST['t']=='esfTBD'){
$dataTrade=esfTradeDaily();
$dataList=esfListDaily();
jsonResponse(['dataTrade' => $dataTrade, 'dataList' => $dataList]);
}
/*
*esfListDaily: 二手房每日挂牌数量
*/
if($_REQUEST['t']=='esfListDaily'){
$data=esfListDaily();
jsonResponse(['datas' => $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 = "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'){
$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');
$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);
if($_REQUEST['dm']=='Daily'){
$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'){
$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');
$sql2 .= " and ej.tdate <= ?";
$params2[] = $endDate->format('Y-m-d');
}
$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);
jsonResponse(['datas' => $data, 'dataExt' => $data2]);
}