From 6be9690037416649827748b9421933714809f72f Mon Sep 17 00:00:00 2001 From: liyang <2154243450@qq.com> Date: Thu, 7 Aug 2025 11:27:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=A5=E8=82=A1=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/home/service/BlockStockService.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/home/service/BlockStockService.php b/app/home/service/BlockStockService.php index 12af1498..6c5753e5 100644 --- a/app/home/service/BlockStockService.php +++ b/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()]); } } - - -} \ No newline at end of file +}