refactor: 前端库清理、页面废弃、DB→API 数据源替换
- 删除重复库文件:lib/DataTables-2/、lib/echarts/、libai/、css/fontawesome/ 等 179 个冗余文件 - 下载外部 CDN 到本地:Mermaid、AOS、Google Fonts(Inter/Noto Serif SC/Noto Sans SC) - 所有第三方库统一到 lib/,按库名-版本号命名 - 更新 8 个 research HTML 文件引用路径 - stock_his_pro → /api/stockbasic/(getStockHist、recentPrice) - stock_all_pro → /api/stockinfo/(tscodeToName) - index_hist_pro → /api/indexDatas/(getIndexData) - 新增 callDoorcomeApi() 共享函数 - 被替换表的 DB 查询代码完全删除,无回退 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -113,6 +113,31 @@ function callTushareApi($method, $params){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用 api.doorcome.cn 获取实时数据
|
||||
*/
|
||||
function callDoorcomeApi($endpoint, $params = []) {
|
||||
$url = 'https://api.doorcome.cn/api/' . $endpoint;
|
||||
if ($params) {
|
||||
$url .= '?' . http_build_query($params);
|
||||
}
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
]);
|
||||
$resp = curl_exec($ch);
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
if ($err) {
|
||||
error_log("Doorcome API error [$endpoint]: " . $err);
|
||||
return null;
|
||||
}
|
||||
return json_decode($resp, true);
|
||||
}
|
||||
|
||||
// 假设的调试模式开关函数
|
||||
function debug_enabled()
|
||||
{
|
||||
|
||||
+20
-31
@@ -75,42 +75,31 @@ function ts_code_conv($ts_code){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getStockHist($ts_code,$day_st,$day_end){
|
||||
$mysqli = get_mysqli_connection();
|
||||
$sql = "select trade_date, close from stock_his_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();
|
||||
|
||||
if($result && $result->num_rows>0) {
|
||||
#$data = $result->fetch_all();
|
||||
while($row = $result->fetch_assoc()){
|
||||
//$trade_date=substr($row['trade_date'],0,4).'-'.substr($row['trade_date'],4,2).'-'.substr($row['trade_date'],6,2);
|
||||
//$trade_date1=strtotime($row['trade_date']);
|
||||
array_push($tDate,$row['trade_date']);
|
||||
array_push($idx,$row['close']);
|
||||
array_push($data,array("value"=>array($row['trade_date'],$row['close'])));
|
||||
$tDate=$idx=$data=array();
|
||||
$ds = preg_replace('/\D/', '', $day_st);
|
||||
$de = $day_end ? preg_replace('/\D/', '', $day_end) : date('Ymd');
|
||||
$resp = callDoorcomeApi('stockbasic', ['tscode' => $ts_code, 'start_date' => $ds, 'end_date' => $de]);
|
||||
if ($resp && is_array($resp)) {
|
||||
foreach ($resp as $row) {
|
||||
$d = $row['trade_date'];
|
||||
array_push($tDate, $d);
|
||||
array_push($idx, $row['close']);
|
||||
array_push($data, ["value" => [$d, $row['close']]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#Free result and close connection.
|
||||
$result->free();
|
||||
$mysqli->close();
|
||||
return array('tDate'=>$tDate,'idx'=>$idx,'data'=>$data);
|
||||
return array('tDate'=>$tDate,'idx'=>$idx,'data'=>$data);
|
||||
}
|
||||
|
||||
function tscodeToName($ts_code){
|
||||
$mysqli = get_mysqli_connection();
|
||||
$result = db_query($mysqli, "select name from stock_all_pro where ts_code = ?", [$ts_code]);
|
||||
if($result && $result->num_rows >0) $row = $result->fetch_assoc();
|
||||
$result->free();
|
||||
$mysqli->close();
|
||||
return $row['name'];
|
||||
$resp = callDoorcomeApi('stockinfo', ['tscode' => $ts_code]);
|
||||
if ($resp && isset($resp[0]['name'])) {
|
||||
return $resp[0]['name'];
|
||||
}
|
||||
return $ts_code;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getBasicExtData($ts_code,$item,$day_st,$day_end){
|
||||
|
||||
+13
-26
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
include_once __DIR__."/config.php";
|
||||
include_once __DIR__."/functions.inc.php";
|
||||
/*
|
||||
上证指数:000001.SH
|
||||
深证成指:399001.SZ
|
||||
@@ -7,35 +8,21 @@ include_once __DIR__."/config.php";
|
||||
创业板指:399006.SZ
|
||||
*/
|
||||
function getIndexData($ts_code,$day_st,$day_end){
|
||||
$mysqli = get_mysqli_connection();
|
||||
|
||||
$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();
|
||||
|
||||
if($result && $result->num_rows>0) {
|
||||
#$data = $result->fetch_all();
|
||||
while($row=$result->fetch_assoc()){
|
||||
$trade_date=substr($row['trade_date'],0,4).'-'.substr($row['trade_date'],4,2).'-'.substr($row['trade_date'],6,2);
|
||||
$trade_date1=strtotime($row['trade_date']);
|
||||
array_push($tDate,$trade_date);
|
||||
array_push($idx,$row['close']);
|
||||
array_push($data,array("value"=>array($trade_date,round($row['close'],2))));
|
||||
$tDate=$idx=$data=array();
|
||||
$ds = preg_replace('/\D/', '', $day_st);
|
||||
$de = $day_end ? preg_replace('/\D/', '', $day_end) : date('Ymd');
|
||||
$resp = callDoorcomeApi('indexDatas', ['tscode' => $ts_code, 'start_date' => $ds, 'end_date' => $de]);
|
||||
if ($resp && is_array($resp)) {
|
||||
foreach ($resp as $row) {
|
||||
$d = substr($row['trade_date'],0,4).'-'.substr($row['trade_date'],4,2).'-'.substr($row['trade_date'],6,2);
|
||||
array_push($tDate, $d);
|
||||
array_push($idx, $row['close']);
|
||||
array_push($data, ["value" => [$d, round($row['close'], 2)]]);
|
||||
}
|
||||
}
|
||||
return array('tDate'=>$tDate,'idx'=>$idx,'data'=>$data);
|
||||
}
|
||||
#Free result and close connection.
|
||||
|
||||
$result->free();
|
||||
$mysqli->close();
|
||||
return array('tDate'=>$tDate,'idx'=>$idx,'data'=>$data);
|
||||
}
|
||||
/*
|
||||
#LX: 序号 1-6,分别代表基金,QFII, 社保,券商,保险,信托
|
||||
#share: vposition 市值 f10, sahreHDnum 股数 f9
|
||||
|
||||
@@ -129,11 +129,14 @@ function tradeSummary($dataBuy,$dataSell,$dataAll):array{
|
||||
}
|
||||
|
||||
function recentPrice($ts_code){
|
||||
global $mysqli;
|
||||
$sql = "SELECT close FROM stock_his_pro where ts_code = ? and trade_date=(select max(trade_date) from stock_his_pro)";
|
||||
$result = db_query($mysqli, $sql, [ts_code_conv($ts_code)]);
|
||||
$rt = $result->fetch_all(MYSQLI_ASSOC);
|
||||
return $rt[0];
|
||||
$today = date('Ymd');
|
||||
$start = date('Ymd', strtotime('-20 days'));
|
||||
$resp = callDoorcomeApi('stockparam', ['tscode' => ts_code_conv($ts_code), 'start_date' => $start, 'end_date' => $today]);
|
||||
if ($resp && is_array($resp) && count($resp) > 0) {
|
||||
$last = end($resp);
|
||||
return ['close' => $last['close']];
|
||||
}
|
||||
return ['close' => 0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user