安全性: - 所有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>
118 lines
3.4 KiB
PHP
118 lines
3.4 KiB
PHP
<?php
|
|
include_once __DIR__."/config.php";
|
|
|
|
/**
|
|
* 显示股票代码选择列表 (datalist widget)
|
|
* @param string $email: default null
|
|
* @return bool true
|
|
*/
|
|
function tradeStocksList($email=null){
|
|
$mysqli = get_mysqli_connection();
|
|
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 = $mysqli->query($sql);
|
|
$data = $result->fetch_all(MYSQLI_ASSOC);
|
|
$option='';
|
|
foreach ( $data as $item){
|
|
$option .= "<option label='{$item['ts_name']}' value='{$item['ts_code']}'></option>\n";
|
|
}
|
|
$ts_code_val = htmlspecialchars($_REQUEST['ts_code'] ?? '', ENT_QUOTES);
|
|
$html = <<< EOF
|
|
<input id="ts_code" name= "ts_code" list="codeList" autocomplete="off"/>
|
|
<datalist id="codeList">
|
|
$option
|
|
</datalist>
|
|
<script>
|
|
$("#ts_code").val('$ts_code_val');
|
|
</script>
|
|
|
|
EOF;
|
|
echo $html;
|
|
return true;
|
|
}
|
|
|
|
function vendorList($id='t_vendor'){
|
|
$val = htmlspecialchars($_REQUEST[$id] ?? '', ENT_QUOTES);
|
|
$html = <<<EOF
|
|
<select id="{$id}" name= "{$id}" autocomplete="off" >
|
|
<option value="方正证券">方正证券</option>
|
|
<option value="长江证券">长江证券</option>
|
|
</select>
|
|
<script>
|
|
$("#{$id}").val('{$val}');
|
|
</script>
|
|
EOF;
|
|
echo $html;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 根据年份区间,获取财报日期清单
|
|
* @param $yst
|
|
* @param $yed
|
|
*/
|
|
function yearList($yst,$yed){
|
|
$n = $yed-$yst+1;
|
|
$thisYear=date('Y'); //yyyy,eg.2022
|
|
$thisMonDay=date('md'); //mmdd,eg.0331
|
|
$years=array();
|
|
for($i=0;$i<$n;$i++){
|
|
if(($yst+$i)<($thisYear-1) ) $years[]=($yst+$i)."1231"; //前年及以前
|
|
|
|
//去年
|
|
if(($yst+$i)==($thisYear-1)and $thisMonDay<='0430') $years[]=($yst+$i)."0930";
|
|
if(($yst+$i)==($thisYear-1)and $thisMonDay >'0430') $years[]=($yst+$i)."1231";
|
|
//今年
|
|
if(($yst+$i)==$thisYear){
|
|
switch ($thisMonDay){
|
|
case $thisMonDay<='0430':
|
|
//一季报未公布do nothing
|
|
break;
|
|
case $thisMonDay>'0430' && $thisMonDay<= '0831':
|
|
//公布一季报
|
|
$years[]=($yst+$i)."0331";
|
|
break;
|
|
case $thisMonDay>'0831' && $thisMonDay<= '1031':
|
|
//公布一季报
|
|
$years[]=($yst+$i)."0630";
|
|
break;
|
|
case $thisMonDay>'1031':
|
|
//公布一季报
|
|
$years[]=($yst+$i)."0930";
|
|
break;
|
|
default: break;
|
|
}
|
|
}
|
|
}
|
|
return $years;
|
|
}
|
|
|
|
/**
|
|
* $year 20201231 转为2020年报
|
|
* @param $year
|
|
*/
|
|
function yearToname($year){
|
|
switch (substr($year,4,4)){
|
|
case '1231':
|
|
return substr($year,0,4).'年报';
|
|
case '0930':
|
|
return substr($year,0,4).'三季';
|
|
case '0630':
|
|
return substr($year,0,4).'半年';
|
|
case '0331':
|
|
return substr($year,0,4).'一季';
|
|
default:
|
|
return substr($year,4,4);
|
|
}
|
|
}
|