Commit 0de786d6 authored by wuxiaoli's avatar wuxiaoli

修复获取实时股票信息

parent 696012ee
...@@ -2047,21 +2047,34 @@ function curl($url){ ...@@ -2047,21 +2047,34 @@ function curl($url){
*/ */
if (!function_exists('toMarket')){ if (!function_exists('toMarket')){
function toMarket($code){ function toMarket($code){
if($code == '000001'){ if(strlen($code) === 5){//如果不符合上述简单规则,可能需要更复杂的逻辑或数据查询
return 'SZ'; return "HK";
} }else if (strlen($code) === 6){//A股暂时假设6位代码
if(in_array(substr($code, 0, 1),array('6', '9'))){ if($code == '000001'){
return 'SH'; return 'SZ';
} }
if(in_array(substr($code, 0, 1),array('0', '2', '3'))){ if(in_array(substr($code, 0, 1),array('6', '9'))){
return 'SZ'; return 'SH';
} }
if(in_array(substr($code, 0, 1),array('4', '8'))){ if(in_array(substr($code, 0, 1),array('0', '2', '3'))){
return 'BJ'; return 'SZ';
}
if(in_array(substr($code, 0, 1),array('4', '8'))){
return 'BJ';
}
} }
} }
} }
//腾讯数据解析
if(!function_exists('jsonQuotation')) {
function jsonQuotation($item) {
$item[0] = isset($item[0])?substr(str_replace('v_','', $item[0]), 0, 2):'';//交易所代号
$item[80] = isset($item[30]) ? strtotime($item[30]) : time();
return $item;
}
}
/******************************************************************************************/ /******************************************************************************************/
if(!function_exists('toPinyin')) { if(!function_exists('toPinyin')) {
function toPinyin($zh){ function toPinyin($zh){
......
...@@ -242,17 +242,10 @@ if (!function_exists('getEndDay')) { ...@@ -242,17 +242,10 @@ if (!function_exists('getEndDay')) {
} }
if (!function_exists('z_market')) { if (!function_exists('z_market')) {
function z_market($code,$market="HK") function z_market($code,$market="")
{ {
$res = \think\Db::name('admin_config')->where(array('name' => 'market_data_in'))->value('value'); $res = \think\Db::name('admin_config')->where(array('name' => 'market_data_in'))->value('value');
//判断股票前缀
/*if(toMarket($code)){
$market = toMarket($code);
};*/
$code=strtolower($market).$code;
//判断股票是否
switch ($res) { switch ($res) {
case 1: case 1:
$res = qq_market($code); $res = qq_market($code);
...@@ -296,7 +289,6 @@ if (!function_exists('getEndDay')) { ...@@ -296,7 +289,6 @@ if (!function_exists('getEndDay')) {
switch ($res) { switch ($res) {
case 1: case 1:
$res = explode(',', $code); $res = explode(',', $code);
$count = count($res);
foreach ($res as $v) { foreach ($res as $v) {
$d .= fenxi($v) . ','; $d .= fenxi($v) . ',';
...@@ -308,16 +300,9 @@ if (!function_exists('getEndDay')) { ...@@ -308,16 +300,9 @@ if (!function_exists('getEndDay')) {
break; break;
} }
for ($i = 0; $i < $count; $i++) { foreach ($tmd as $k=>$v){
$k = $i * 53; $data[$k][0] = '';
$data[$k] = qq_to_api($v);
for ($n = 1; $n <= 53; $n++) {
$num = $n + $k;
$data[$i][$n] = $tmd[$num];
}
$data[$i][0] = '';
$data[$i] = qq_to_api($data[$i]);
} }
break; break;
...@@ -377,7 +362,6 @@ if (!function_exists('getEndDay')) { ...@@ -377,7 +362,6 @@ if (!function_exists('getEndDay')) {
default: default:
$res = explode(',', $code); $res = explode(',', $code);
$count = count($res);
foreach ($res as $v) { foreach ($res as $v) {
$d .= fenxi($v) . ','; $d .= fenxi($v) . ',';
...@@ -385,16 +369,9 @@ if (!function_exists('getEndDay')) { ...@@ -385,16 +369,9 @@ if (!function_exists('getEndDay')) {
$tmd = qq_market_b($d); $tmd = qq_market_b($d);
for ($i = 0; $i < $count; $i++) { foreach ($tmd as $k=>$v){
$k = $i * 53; $data[$k][0] = '';
$data[$k] = qq_to_api($v);
for ($n = 1; $n <= 53; $n++) {
$num = $n + $k;
$data[$i][$n] = $tmd[$num];
}
$data[$i][0] = '';
$data[$i] = qq_to_api($data[$i]);
} }
break; break;
...@@ -976,40 +953,48 @@ if (!function_exists('getEndDay')) { ...@@ -976,40 +953,48 @@ if (!function_exists('getEndDay')) {
if (!function_exists('')) { if (!function_exists('')) {
function fenxi($code) function fenxi($code)
{ {
switch (substr($code, 0, 1)) {
case '0':
$d = 'sz' . $code;
break;
case '3': if(strlen($code) === 5){//港股
$d = 'sz' . $code;
break;
case '1': $d = 'hk' . $code;
$d = 'sz' . $code;
break;
case '2': }else if(strlen($code) === 6){//A股
$d = 'sz' . $code; switch (substr($code, 0, 1)) {
break; case '0':
$d = 'sz' . $code;
break;
case '6': case '3':
$d = 'sh' . $code; $d = 'sz' . $code;
break; break;
case '5': case '1':
$d = 'sh' . $code; $d = 'sz' . $code;
break; break;
case '9': case '2':
$d = 'sh' . $code; $d = 'sz' . $code;
break; break;
default: case '6':
$d = $code; $d = 'sh' . $code;
break; break;
case '5':
$d = 'sh' . $code;
break;
case '9':
$d = 'sh' . $code;
break;
default:
$d = $code;
break;
}
} }
return $d; return $d;
} }
} }
...@@ -1208,9 +1193,19 @@ if (!function_exists('getEndDay')) { ...@@ -1208,9 +1193,19 @@ if (!function_exists('getEndDay')) {
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch); $output = curl_exec($ch);
curl_close($ch); curl_close($ch);
$t2 = explode('~', mb_convert_encoding($output, 'utf-8', 'gbk')); $str = mb_convert_encoding($output, 'utf-8', 'gbk');
unset($t2[0]); $str = str_replace(array("\r\n", "\r", "\n"), "", $str);
return $t2; $t2 = explode('";', $str);
$json = [];
foreach ($t2 as $key => $val) {
$array = explode("~", $val);
if(isset($array[2])&&isset($array[3])&&isset($array[4])){
$json[] = jsonQuotation(explode("~", $val));
}else{
continue;
}
}
return $json;
} }
} }
......
...@@ -326,6 +326,7 @@ class Position extends Model{ ...@@ -326,6 +326,7 @@ class Position extends Model{
$data[0]['lid'] = $lid; $data[0]['lid'] = $lid;
$data[0]['soruce'] = $soure; $data[0]['soruce'] = $soure;
$data[0]['login_name'] = $user; $data[0]['login_name'] = $user;
$data[0]['market'] = toMarket($stockinfo["code"]);
$data[0]['gupiao_code'] = $stockinfo["code"]; $data[0]['gupiao_code'] = $stockinfo["code"];
$data[0]['gupiao_name'] = $stockinfo["name"]; $data[0]['gupiao_name'] = $stockinfo["name"];
$data[0]['count'] = $count; $data[0]['count'] = $count;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment