From c4aa873bea9695c65d4a88d8737630052d10693c Mon Sep 17 00:00:00 2001 From: liufumingren Date: Thu, 22 Oct 2026 14:19:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(chat):=20=E4=BF=AE=E5=A4=8D=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E4=BA=8B=E5=8A=A1=E4=B8=AD=E7=9A=84=20null=20?= =?UTF-8?q?=E5=8F=96=E4=B8=8B=E6=A0=87=EF=BC=88PHP=207.4=20=E6=8A=9B?= =?UTF-8?q?=E5=87=BA=20ErrorException=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 企微入口 processMessages 在事务中捕获到 Trying to access array offset on value of type null:消息"打包视频+单号"走 dabaoVideo -> getOrderInfoByPostnum 时,Express 表查不到该单号,find() 返回 null,随后直接取 ["TRADEORDER"]。 PHP 7.4 起该 notice 被抛成异常,导致整条消息事务回滚、无回复。 - getOrderInfoByPostnum:先取 TRADEORDER 到变量并用 ?? 兜底,4 处引用统一 - fastruku:仓库未取到时 ["operatorID"] 加 ?? 0 - createOrder:群未登记时 ['isOrder'] 用 ?? 0 兜底 - createPostnum:3 处 Wsdl::webservice 的仓库参数补 ?? 兜底 - grabnum(): 为空时改用 empty() 判断,避免 notice - qiwe processMessages 事务失败日志补充出错文件与行号,便于定位 以上均为等价语义,仅消除 PHP 7.4 下的 notice/异常。 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- application/index/controller/qiwe/Index.php | 2 +- application/index/controller/wms/Chat.php | 19 ++++++++++--------- application/index/controller/wms/Order.php | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/application/index/controller/qiwe/Index.php b/application/index/controller/qiwe/Index.php index a7ef7a9..23af098 100644 --- a/application/index/controller/qiwe/Index.php +++ b/application/index/controller/qiwe/Index.php @@ -115,7 +115,7 @@ class Index extends Frontend Db::commit(); } catch (\Exception $e) { Db::rollback(); - \think\Log::error('消息处理事务失败: ' . $e->getMessage()); + \think\Log::error('消息处理事务失败: ' . $e->getMessage() . ' @ ' . $e->getFile() . ':' . $e->getLine()); } } diff --git a/application/index/controller/wms/Chat.php b/application/index/controller/wms/Chat.php index d83e9eb..760c1d4 100644 --- a/application/index/controller/wms/Chat.php +++ b/application/index/controller/wms/Chat.php @@ -756,7 +756,7 @@ class Chat extends Frontend $this->redis->set("kdksjdksaj1",json_encode($results)); $WAREHOUSE = $WarehouseModel->field("kjrkSpaceId,operatorID")->where(["WAREHOUSEID"=>$WAREHOUSEID])->find(); $kjrkSpaceId = $WAREHOUSE['kjrkSpaceId']??0; - $userid = $WAREHOUSE["operatorID"]; + $userid = $WAREHOUSE["operatorID"] ?? 0; if(!$kjrkSpaceId){ $backMsg = $this->backMsg($from,"仓库未设置快捷入库库位"); $msgs = array_merge($msgs,$backMsg); @@ -984,7 +984,7 @@ _________________________________________________________ $addr_info = $this->getAddress($result['address']); $RoomsModel = $this->SOURCE == "wx" ? $this->RoomsModel : $this->qiweRoomsModel; $roominfo = $RoomsModel->where(["room_id"=>$from['fromid']])->find();//货主群聊 - if(!$roominfo['isOrder']){ + if(!($roominfo['isOrder'] ?? 0)){ $text = "群未开启自动抓取建单,如有需要,联系客服开启\n"; }else{ if(!isset($addr_info->result->address)){ @@ -2636,7 +2636,7 @@ _________________________________________________________ }else{ $text.="执行回传任务...\n"; try { - $data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],intval($WAREHOUSE["operatorID"]),$ids],'synOrder'); + $data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"] ?? null,intval($WAREHOUSE["operatorID"] ?? 0),$ids],'synOrder'); $text.="回传任务结束,正在检查...\n"; $order = $this->getOrderInfoBySourceOrderCode($postnum,$from); if($order["SYNFLAG"]){ @@ -2651,7 +2651,7 @@ _________________________________________________________ }else{ $text.="平台单号:".$postnum." 未分配快递单号,开始分配...\n"; try { - $data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],intval($WAREHOUSE["operatorID"]),$ids],'createPostNum'); + $data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"] ?? null,intval($WAREHOUSE["operatorID"] ?? 0),$ids],'createPostNum'); } catch (Exception $e ) { } $text.="分配任务结束,正在检查单号...\n"; @@ -2659,7 +2659,7 @@ _________________________________________________________ if($order["POSTNUM"] && $order["POSTFLAG"]){ $text.="分配运单号成功,运单号:{$order["POSTNUM"]},执行回传任务...\n"; try { - $data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"],intval($WAREHOUSE["operatorID"]),$ids],'synOrder'); + $data = Wsdl::webservice([$WAREHOUSE["WAREHOUSEID"] ?? null,intval($WAREHOUSE["operatorID"] ?? 0),$ids],'synOrder'); $text.="回传任务结束,正在检查...\n"; $order = $this->getOrderInfoBySourceOrderCode($postnum,$from); if($order["SYNFLAG"]){ @@ -3022,17 +3022,18 @@ _________________________________________________________ private function getOrderInfoByPostnum($postnum,$from){ $status = 0; $expressRow = $this->ExpressModel->where(["POSTNUM"=>$postnum])->find(); + $tradeOrder = $expressRow['TRADEORDER'] ?? ''; if(isset($from["isMe"])){ - if(!$expressRow["TRADEORDER"]){ + if(!$tradeOrder){ $where = '(POSTNUM = "'.$postnum.'")'; }else{ - $where = '(SOURCEID="'.$expressRow["TRADEORDER"].'" or POSTNUM = "'.$postnum.'")'; + $where = '(SOURCEID="'.$tradeOrder.'" or POSTNUM = "'.$postnum.'")'; } }else{ - if(!$expressRow["TRADEORDER"]){ + if(!$tradeOrder){ $where = '(POSTNUM = "'.$postnum.'") and STOREID='.$from["storeid"]; }else{ - $where = '(SOURCEID="'.$expressRow["TRADEORDER"].'" or POSTNUM = "'.$postnum.'") and STOREID='.$from["storeid"]; + $where = '(SOURCEID="'.$tradeOrder.'" or POSTNUM = "'.$postnum.'") and STOREID='.$from["storeid"]; } } diff --git a/application/index/controller/wms/Order.php b/application/index/controller/wms/Order.php index 6856281..b2c76a4 100644 --- a/application/index/controller/wms/Order.php +++ b/application/index/controller/wms/Order.php @@ -242,7 +242,7 @@ class Order extends Frontend } } - return json(["grabnum"=>$last['grabnum']?$last['grabnum']:null,"count"=>$count,"hour_sum"=>$hour_sum]); + return json(["grabnum"=>!empty($last['grabnum'])?$last['grabnum']:null,"count"=>$count,"hour_sum"=>$hour_sum]); } public function closeall(){ $first = $Gongzuomodel->where(["endtime"=>0])->select();