更新:添加每日和每月数据选项,修改相关URL参数,更新JavaScript文件,增加股票指数历史数据获取功能
This commit is contained in:
+111
-8
@@ -94,8 +94,8 @@ if($_REQUEST['t']=='esfListDaily'){
|
||||
}
|
||||
function esfTradeDaily(){
|
||||
global $mysqli;
|
||||
|
||||
$sql= <<<EOF
|
||||
if($_REQUEST['dm']=='Daily'){
|
||||
$sql= <<<EOF
|
||||
SELECT
|
||||
distinct(ej.uuid) uid ,
|
||||
date_format(tdate,'%Y-%m-%d') td,
|
||||
@@ -110,7 +110,33 @@ function esfTradeDaily(){
|
||||
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;
|
||||
@@ -118,8 +144,8 @@ EOF;
|
||||
|
||||
function esfListDaily(){
|
||||
global $mysqli;
|
||||
|
||||
$sql= <<<EOF
|
||||
if($_REQUEST['dm']=='Daily'){
|
||||
$sql= <<<EOF
|
||||
SELECT
|
||||
distinct(ej.uuid) uid ,
|
||||
date_format(tdate,'%Y-%m-%d') td,
|
||||
@@ -134,7 +160,32 @@ function esfListDaily(){
|
||||
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;
|
||||
@@ -144,7 +195,7 @@ EOF;
|
||||
*newTBD: 新房Trade By Day
|
||||
*/
|
||||
if($_REQUEST['t']=='newTBD'){
|
||||
|
||||
if($_REQUEST['dm']=='Daily'){
|
||||
$sql= <<<EOF
|
||||
SELECT
|
||||
distinct(ej.uuid) uid ,
|
||||
@@ -158,11 +209,37 @@ if($_REQUEST['t']=='newTBD'){
|
||||
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;
|
||||
}
|
||||
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='1' {$where}
|
||||
group by date_format(tdate,'%Y-%m') order by date_format(tdate,'%Y-%m') asc
|
||||
EOF;
|
||||
}
|
||||
|
||||
$result = $mysqli->query($sql);
|
||||
$data = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
if($_REQUEST['dm']=='Daily'){
|
||||
$sql= <<<EOF
|
||||
SELECT
|
||||
distinct(ej.uuid) uid ,
|
||||
@@ -176,7 +253,33 @@ EOF;
|
||||
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;
|
||||
}
|
||||
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-%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);
|
||||
$data2 = $result->fetch_all(MYSQLI_ASSOC);
|
||||
echo json_encode(array(
|
||||
|
||||
Binary file not shown.
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
include_once __DIR__."/functions.inc.php";
|
||||
/**
|
||||
* 获取PE_TTM,PB,PS等历史数据
|
||||
* @param $ts_code ts code
|
||||
@@ -312,4 +313,101 @@ function yearToname($year){
|
||||
return substr($year,4,4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 函数一:获取股票代码ts_code对应的历史pe_ttm、pb或ps
|
||||
function getStockHistoryDataByTS($ts_code, $day_st, $day_end = null, $item){
|
||||
//global $token;
|
||||
|
||||
// 参数校验
|
||||
if (empty($ts_code) || empty($day_st) || !in_array(strtolower($item), ['pe_ttm', 'pb', 'ps'])) {
|
||||
return "参数错误:股票代码、起始日期不能为空,查询项目必须为pe_ttm、pb或ps。";
|
||||
}
|
||||
|
||||
// 处理日期参数
|
||||
$params = [
|
||||
"ts_code" => $ts_code,
|
||||
"start_date" => $day_st,
|
||||
"end_date" => $day_end ?? date("Y-m-d") // 如果为空,默认为今天
|
||||
];
|
||||
|
||||
// 调用TuShare API获取数据
|
||||
$data = callTushareApi('daily_basic', $params);
|
||||
return true ;
|
||||
if (empty($data)) {
|
||||
return "未获取到数据,请检查参数或网络连接。";
|
||||
}
|
||||
|
||||
// 提取指定项目的数据
|
||||
$result = [];
|
||||
$tDate = [];
|
||||
$itemValues = [];
|
||||
foreach ($data as $row) {
|
||||
$tDate[] = $row['trade_date'];
|
||||
$itemValues[] = $row[$item];
|
||||
}
|
||||
|
||||
// 按日期排序(从远到近,默认已经是按日期排序的)
|
||||
$tDate = array_reverse($tDate); // 默认TuShare按日期顺序是近到远,所以反转得到远到近
|
||||
$itemValues = array_reverse($itemValues);
|
||||
|
||||
// 计算统计值
|
||||
$dataMax = max($itemValues);
|
||||
$dataMin = min($itemValues);
|
||||
$dataAvg = array_sum($itemValues) / count($itemValues);
|
||||
$dataLast = end($itemValues);
|
||||
|
||||
// 返回结果
|
||||
return [
|
||||
'tDate' => $tDate,
|
||||
'data' => $itemValues,
|
||||
'data_max' => $dataMax,
|
||||
'data_min' => $dataMin,
|
||||
'data_avg' => $dataAvg,
|
||||
'data_last' => $dataLast
|
||||
];
|
||||
}
|
||||
|
||||
// 函数二:获取指数趋势历史数据
|
||||
function getIndexHistoryDataByTS($ts_code, $day_st, $day_end = null)
|
||||
{
|
||||
global $token;
|
||||
|
||||
// 参数校验
|
||||
if (empty($ts_code) || empty($day_st)) {
|
||||
return "参数错误:股票代码和起始日期不能为空。";
|
||||
}
|
||||
|
||||
// 处理日期参数
|
||||
$params = [
|
||||
"ts_code" => $ts_code,
|
||||
"start_date" => $day_st,
|
||||
"end_date" => $day_end ?? date("Y-m-d") // 如果为空,默认为今天
|
||||
];
|
||||
|
||||
// 调用TuShare API获取数据
|
||||
$data = callTushareApi('index_dailybasic', $params);
|
||||
return true ;
|
||||
if (empty($data)) {
|
||||
return "未获取到数据,请检查参数或网络连接。";
|
||||
}
|
||||
|
||||
// 提取指数点数值
|
||||
$tDate = [];
|
||||
$closeValues = [];
|
||||
foreach ($data as $row) {
|
||||
$tDate[] = $row['trade_date'];
|
||||
$closeValues[] = $row['close']; // 假设close字段是指数点数值
|
||||
}
|
||||
|
||||
// 按日期排序
|
||||
$tDate = array_reverse($tDate);
|
||||
$closeValues = array_reverse($closeValues);
|
||||
|
||||
// 返回结果
|
||||
return [
|
||||
'tDate' => $tDate,
|
||||
'data' => $closeValues
|
||||
];
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user