Files
echart/inc/ajax.inc.php
T
2023-10-16 12:58:41 +08:00

186 lines
5.4 KiB
PHP

<?php
ini_set("display_errors","1");
$mysqli = new mysqli('localhost','root','nancysimon','myquant');
//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 = $mysqli->query($sql);
$data = $result->fetch_all(MYSQLI_ASSOC);
echo json_encode(array(
"status" => "1",
'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);
echo json_encode(array("data"=>$data));
}
/*
*esfTBD: 二手房Trade By Day
*/
if($_REQUEST['t']=='esfTBD'){
$dataTrade=esfTradeDaily();
$dataList=esfListDaily();
echo json_encode(array(
"status" => "1",
'dataTrade'=> $dataTrade,
'dataList'=>$dataList
));
}
/*
*esfListDaily: 二手房每日挂牌数量
*/
if($_REQUEST['t']=='esfListDaily'){
$data=esfListDaily();
echo json_encode(array(
"status" => "1",
'datas'=> $data
));
}
function esfTradeDaily(){
global $mysqli;
$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']}')
EOF;
$result = $mysqli->query($sql);
$data = $result->fetch_all(MYSQLI_ASSOC);
return $data;
}
function esfListDaily(){
global $mysqli;
$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']}')
EOF;
$result = $mysqli->query($sql);
$data = $result->fetch_all(MYSQLI_ASSOC);
return $data;
}
/*
*newTBD: 新房Trade By Day
*/
if($_REQUEST['t']=='newTBD'){
$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']}')
EOF;
$result = $mysqli->query($sql);
$data = $result->fetch_all(MYSQLI_ASSOC);
$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']}')
EOF;
$result = $mysqli->query($sql);
$data2 = $result->fetch_all(MYSQLI_ASSOC);
echo json_encode(array(
"status" => "1",
'datas'=> $data,
'dataExt'=> $data2
));
}