|
|
@ -99,7 +99,7 @@ class Config extends AdminBaseController |
|
|
|
public function quoteList() |
|
|
|
{ |
|
|
|
$params = $this->request->param(); |
|
|
|
if (!isset($params['page']) || !isset($params['limit'])) { |
|
|
|
if (!isset($params['page']) || !isset($params['limit']) || !isset($params['market_type'])) { |
|
|
|
return json([ |
|
|
|
'code' => 400, |
|
|
|
'message' => '缺少参数', |
|
|
@ -107,6 +107,24 @@ class Config extends AdminBaseController |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
// 检查市场类型是否有效 |
|
|
|
if ($params['market_type'] < 0) { |
|
|
|
return json([ |
|
|
|
'code' => 400, |
|
|
|
'message' => '市场类型无效', |
|
|
|
'data' => [] |
|
|
|
]); |
|
|
|
} |
|
|
|
// 根据市场类型获取数据在mongo中对应的集合名称 |
|
|
|
if (!isset(MongoConnection::COLLECTION_ARR[$params['market_type']])) { |
|
|
|
return json([ |
|
|
|
'code' => 400, |
|
|
|
'message' => '没有找到对应的行情数据', |
|
|
|
'data' => [] |
|
|
|
]); |
|
|
|
} |
|
|
|
$collectionName = MongoConnection::COLLECTION_ARR[$params['market_type']]; |
|
|
|
|
|
|
|
// 分页计算 |
|
|
|
$page = (int)$params['page']; |
|
|
|
$pageSize = (int)$params['limit']; |
|
|
@ -125,10 +143,16 @@ class Config extends AdminBaseController |
|
|
|
'$options' => 'i' |
|
|
|
]; |
|
|
|
} |
|
|
|
if (!empty($params['code'])) { |
|
|
|
$filter['Code'] = trim($params['code']); |
|
|
|
} |
|
|
|
if (!empty($params['country'])) { |
|
|
|
$filter['Country'] = time($params['country']); |
|
|
|
} |
|
|
|
|
|
|
|
// 查询数据 |
|
|
|
$client = MongoConnection::getClient(); |
|
|
|
$collection = $client->selectCollection('bourse', 'stockListBak'); |
|
|
|
$collection = $client->selectCollection(MongoConnection::QUOTE_DATA_BASE_NAME, $collectionName); |
|
|
|
$cursor = $collection->find($filter, $options); |
|
|
|
$results = iterator_to_array($cursor); // 将 BSON 文档转换为数组 |
|
|
|
$total = $collection->countDocuments($filter); |
|
|
@ -157,38 +181,84 @@ class Config extends AdminBaseController |
|
|
|
public function quoteTopData() |
|
|
|
{ |
|
|
|
$params = $this->request->param(); |
|
|
|
if (empty($params['id']) || empty($params['sort'])) { |
|
|
|
if (empty($params['id']) || empty($params['sort']) || empty($params['market_type'])) { |
|
|
|
return json([ |
|
|
|
'code' => 400, |
|
|
|
'message' => '缺少参数', |
|
|
|
'data' => [] |
|
|
|
]); |
|
|
|
} |
|
|
|
// 根据市场类型获取数据在mongo中对应的集合名称 |
|
|
|
if (!isset(MongoConnection::COLLECTION_ARR[$params['market_type']])) { |
|
|
|
return json([ |
|
|
|
'code' => 400, |
|
|
|
'message' => '没有找到对应的行情数据', |
|
|
|
'data' => [] |
|
|
|
]); |
|
|
|
} |
|
|
|
$collectionName = MongoConnection::COLLECTION_ARR[$params['market_type']]; |
|
|
|
// 根据市场类型获取置顶数据将要存储的Redis Key |
|
|
|
if (!isset(MongoConnection::QUOTE_TOP_DATA_HASH_ARR[$params['market_type']])) { |
|
|
|
return json([ |
|
|
|
'code' => 400, |
|
|
|
'message' => '没有找到对应的行情数据存储KEY', |
|
|
|
'data' => [] |
|
|
|
]); |
|
|
|
} |
|
|
|
$quoteTopDataKey = MongoConnection::QUOTE_TOP_DATA_HASH_ARR[$params['market_type']]; |
|
|
|
|
|
|
|
// 获取行情数据 |
|
|
|
$client = MongoConnection::getClient(); |
|
|
|
$collection = $client->selectCollection('bourse', 'stockListBak'); |
|
|
|
$collection = $client->selectCollection(MongoConnection::QUOTE_DATA_BASE_NAME, $collectionName); |
|
|
|
$doc = $collection->find(['_id'=>new ObjectId($params['id'])]); |
|
|
|
$results = iterator_to_array($doc); |
|
|
|
if (!isset($results[0]['Code']) || !isset($results[0]['Type'])) { |
|
|
|
|
|
|
|
// 构建缓存数据 |
|
|
|
$buildArr = []; |
|
|
|
switch ($params['market_type']) { |
|
|
|
case 3: |
|
|
|
$buildArr = [ |
|
|
|
'Code' => $results[0]['Code'], |
|
|
|
'Type' => $results[0]['Country'], |
|
|
|
'Exchange' => $results[0]['Exchange'], |
|
|
|
'Sort' => $params['sort'], |
|
|
|
]; |
|
|
|
break; |
|
|
|
case 19: |
|
|
|
$buildArr = [ |
|
|
|
'Code' => $results[0]['symbol'], // 外汇行情用symbol字段值作为Code |
|
|
|
'Type' => $results[0]['category'], // 外汇行情用category作为标识 |
|
|
|
'Sort' => $params['sort'], |
|
|
|
]; |
|
|
|
break; |
|
|
|
default: |
|
|
|
return json([ |
|
|
|
'code' => 500, |
|
|
|
'message' => '构建数据失败', |
|
|
|
'data' => [] |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
// 检测构建数据 |
|
|
|
if (empty($buildArr)) { |
|
|
|
return json([ |
|
|
|
'code' => 400, |
|
|
|
'message' => '行情数据错误', |
|
|
|
'code' => 500, |
|
|
|
'message' => '构建数据为空', |
|
|
|
'data' => [] |
|
|
|
]); |
|
|
|
} |
|
|
|
$buildArr = [ |
|
|
|
'Code' => $results[0]['Code'], |
|
|
|
'Type' => $results[0]['Type'], |
|
|
|
'Sort' => $params['sort'], |
|
|
|
]; |
|
|
|
$jsonStr = json_encode($buildArr); |
|
|
|
|
|
|
|
|
|
|
|
$res = Cache::store('redis')->hSet(MongoConnection::QUOTE_TOP_DATA_HASH_KEY, $results[0]['Code'], $jsonStr); |
|
|
|
// 根据市场类型获取Redis Key |
|
|
|
$res = Cache::store('redis')->hSet($quoteTopDataKey, $buildArr['Code'], $jsonStr); |
|
|
|
return json([ |
|
|
|
'code' => 0, |
|
|
|
'message' => 'ok', |
|
|
|
'data' => [$res] |
|
|
|
'data' => [ |
|
|
|
'cache_key' => $quoteTopDataKey, |
|
|
|
'cache_val' => $buildArr, |
|
|
|
'isOk' => $res |
|
|
|
] |
|
|
|
]); |
|
|
|
} |
|
|
|
} |