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:
2026-05-26 08:20:33 +08:00
co-authored by Claude Code
parent 07da6a2ad4
commit 7e57cae242
49 changed files with 848 additions and 733 deletions
+42 -42
View File
@@ -9,16 +9,14 @@ include_once __DIR__."/config.php";
function getIndexData($ts_code,$day_st,$day_end){
$mysqli = get_mysqli_connection();
#$ts_code = '000001.SH';
#$day_st = '20000101';
#$day_end = '20190701';
$where = " and trade_date>='".$day_st."'";
if($day_end) $where .= " and trade_date <='".$day_end."'";
$sql= <<<EOF
select trade_date, close from index_hist_pro where ts_code = '$ts_code' $where order by trade_date asc
EOF;
#echo $sql;
$result = $mysqli->query($sql);
$sql = "select trade_date, close from index_hist_pro where ts_code = ? and trade_date >= ?";
$params = [$ts_code, $day_st];
if($day_end) {
$sql .= " and trade_date <= ?";
$params[] = $day_end;
}
$sql .= " order by trade_date asc";
$result = db_query($mysqli, $sql, $params);
$tDate=$idx=$data=array();
@@ -44,24 +42,17 @@ return array('tDate'=>$tDate,'idx'=>$idx,'data'=>$data);
*/
function getIhData($lx,$share,$day_st,$day_end){
$mysqli = get_mysqli_connection();
/*
$where = " and rdate>='".$day_st."'";
if($day_end) $where .= " and rdate<='".$day_end."'";
if($share=='ShareHDNum' or $share=='vPosition') $shareSel='sum('.$share.')/100000000';
elseif($share=='VSRatio') $shareSel='vPosition/ShareHDNum';
$sql= <<<EOF
select rdate,$shareSel as ttl from ih_data where lx='$lx' $where group by rdate order by rdate
EOF;
*/
$where = " and ih_date>='".$day_st."'";
if($day_end) $where .= " and ih_date<='".$day_end."'";
if($share=='ShareHDNum' ) $shareSel="sum(f9)/100000000"; //持股数
elseif($share=='vPosition') $shareSel="sum(f10)/100000000"; //持股额
elseif($share=='VSRatio') $shareSel='f10/f9'; //每股价格
$sql= <<<EOF
select ih_date,$shareSel as ttl from ih_by_ts_code_ext where tp='$lx' $where group by ih_date order by ih_date
EOF;
$result = $mysqli->query($sql);
$sql = "select ih_date,$shareSel as ttl from ih_by_ts_code_ext where tp = ? and ih_date >= ?";
$params = [$lx, $day_st];
if($day_end) {
$sql .= " and ih_date <= ?";
$params[] = $day_end;
}
$sql .= " group by ih_date order by ih_date";
$result = db_query($mysqli, $sql, $params);
//echo $sql;
$tDate=$idx=$data=array();
@@ -177,25 +168,30 @@ function hkholdConv($code){
*/
function getIhDataByStock($ts_code,$item,$lx,$day_st,$day_end){
$mysqli = get_mysqli_connection();
$where = " and ih_date>'".$day_st."'";
if($day_end) $where .= " and ih_date<'".$day_end."'";
if($lx) $where .= " and tp='".$lx."'";
switch(strtoupper($item)){
case 'F9':
$item_sel = 'sum('.$item.')/10000'; #单位万股
$item_sel = 'sum(f9)/10000';
break;
case 'F10':
$item_sel = 'sum('.$item.')/10000'; #单位万元
$item_sel = 'sum(f10)/10000';
break;
case 'F11':
case 'F12':
$item_sel = 'sum('.$item.')'; #单位%
$item_sel = "sum($item)";
break;
}
$sql= <<<EOF
select ts_code,ih_date,$item_sel as ttl from ih_by_ts_code_ext where ts_code='$ts_code' $where group by ih_date order by ih_date asc
EOF;
$result = $mysqli->query($sql);
$sql = "select ts_code,ih_date,$item_sel as ttl from ih_by_ts_code_ext where ts_code = ? and ih_date > ?";
$params = [$ts_code, $day_st];
if($day_end) {
$sql .= " and ih_date < ?";
$params[] = $day_end;
}
if($lx) {
$sql .= " and tp = ?";
$params[] = $lx;
}
$sql .= " group by ih_date order by ih_date asc";
$result = db_query($mysqli, $sql, $params);
#echo $sql;
$tDate=$idx=$data=array();
@@ -221,15 +217,19 @@ EOF;
function getMoneyFlowData($itm, $day_st,$day_end, $stacked){
$mysqli = get_mysqli_connection();
$allowed_cols = ['ggt_ss','ggt_sz','hgt','sgt','north_money','south_money'];
if(!in_array($itm, $allowed_cols)) return array('tDate'=>[],'data'=>[],'data_max'=>0,'data_min'=>0,'data_avg'=>0,'data_last'=>0);
if($stacked==1) $tb = 'moneyflow_hsgt_pro_ext';
else $tb = 'moneyflow_hsgt_pro';
$where = " trade_date>='".$day_st."'";
if($day_end) $where .= " and trade_date <='".$day_end."'";
$sql= <<<EOF
select trade_date, $itm as itm from $tb where $where order by trade_date asc
EOF;
#echo $sql;
$result = $mysqli->query($sql);
$sql = "select trade_date, $itm as itm from $tb where trade_date >= ?";
$params = [$day_st];
if($day_end) {
$sql .= " and trade_date <= ?";
$params[] = $day_end;
}
$sql .= " order by trade_date asc";
$result = db_query($mysqli, $sql, $params);
$tDate=$data=array();