Browse Source

fix: 日股价格

master
liyang 22 hours ago
parent
commit
6be9690037
  1. 18
      app/home/service/BlockStockService.php

18
app/home/service/BlockStockService.php

@ -26,12 +26,18 @@ class BlockStockService extends BaseHomeService
$list = StockBlockListModel::where('type', $param['type'])->page($param['page'], $param['limit'])->select();
$total = StockBlockListModel::where('type', $param['type'])->count();
$redisKeyArr = [3 => 'US', 4 => 'Indonesia', 5 => 'Malaysia', 6 => 'Thailand', 7 => 'India', 9 => 'Singapore', 12 => 'HongKong', 18=>'Japan'];
$redisKeyArr = [3 => 'US', 4 => 'Indonesia', 5 => 'Malaysia', 6 => 'Thailand', 7 => 'India', 9 => 'Singapore', 12 => 'HongKong', 18 => 'Japan'];
$redis = $this->getRedis();
foreach ($list as &$v) {
$key = "Stock:" . $redisKeyArr[$v->type];
$v->current_price = $redis->hget($key . ":ClosePrice", $v->stock_code) ?? $redis->hget($key . ":CloseNewPrice", $v->stock_code);
$closeNewPrice = $redis->hget($key . ":CloseNewPrice", $v->stock_code);
if (empty($closeNewPrice) || $closeNewPrice == 0) {
$v->current_price = $redis->hget($key . ":ClosePrice", $v->stock_code);
} else {
$v->current_price = $closeNewPrice;
}
}
return $this->toData('0', 'SUCCESS', ['list' => $list, 'total' => $total,]);
} catch (\Exception $exception) {
@ -51,9 +57,11 @@ class BlockStockService extends BaseHomeService
$where[] = ['user_id', '=', $userId];
// stock_type 3 美股 4 印尼 5 马股 6 泰股 9 新加坡股票
if (!empty($param['type']) && ($param['type'] >2 && $param['type']< 19)) {
if (!empty($param['type']) && ($param['type'] > 2 && $param['type'] < 19)) {
$where[] = [
'type', '=', $param['type']
'type',
'=',
$param['type']
];
}
@ -65,6 +73,4 @@ class BlockStockService extends BaseHomeService
return $this->toData('0', 'The system is busy. Please try again later.', [$exception->getMessage()]);
}
}
}
Loading…
Cancel
Save