From 6e1f2e9d394df0d634182e66278ba023a19cdbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=98=8A=E5=A4=A9?= <442384644@qq.com> Date: Thu, 8 Oct 2026 14:24:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=AE=A2=E5=8D=95):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=84=E4=BB=B7=E6=8F=90=E4=BA=A4=E4=B8=A4?= =?UTF-8?q?=E5=A4=84=20PHP=20=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CenterOrderController 评价入口把 User 模型实例直接传入要求 array 的 StoreProductReplyServices::comment(),先 toArray - comment() 声明返回 int 但 save() 返回模型实例,取 id 返回, OrderComment 事件的 reply_id 参数同步统一为 int --- .../app/api/controller/v1/order/CenterOrderController.php | 5 ++++- .../services/product/product/StoreProductReplyServices.php | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/app/api/controller/v1/order/CenterOrderController.php b/backend/app/api/controller/v1/order/CenterOrderController.php index 9e42fff98..2d0a26292 100644 --- a/backend/app/api/controller/v1/order/CenterOrderController.php +++ b/backend/app/api/controller/v1/order/CenterOrderController.php @@ -2763,7 +2763,10 @@ class CenterOrderController // ==================== 3. 获取用户信息 ==================== $uid = (int)request()->uid(); $user_info = request()->user(); - // 用户信息在 Service 中处理 + // StoreProductReplyServices::comment() 要求数组(取 nickname/avatar) + if (is_object($user_info)) { + $user_info = $user_info->toArray(); + } // ==================== 4. 从中台订单快照定位商品(unique 为 SKU 唯一码,限定本人订单防越权) ==================== $item = $this->findOrderItemBySkuUnique((string)$unique, $uid); diff --git a/backend/app/services/product/product/StoreProductReplyServices.php b/backend/app/services/product/product/StoreProductReplyServices.php index fe4bf5354..bab33a03c 100644 --- a/backend/app/services/product/product/StoreProductReplyServices.php +++ b/backend/app/services/product/product/StoreProductReplyServices.php @@ -158,6 +158,7 @@ class StoreProductReplyServices extends BaseService if (!$res) { throw new AdminException('评价失败'); } + $replyId = (int)($res->id ?? 0); // ==================== 触发评价事件 ==================== // 订单评价事件(通知管理员、缓存抽奖次数等) @@ -168,7 +169,7 @@ class StoreProductReplyServices extends BaseService 'uid' => $uid, 'product_id'=> $productId, 'order_id' => $cartInfo['oid'], - 'reply_id' => $res, + 'reply_id' => $replyId, 'star' => $data['star'] ?? 5, 'content' => $data['comment'] ?? '', ]]); @@ -176,7 +177,8 @@ class StoreProductReplyServices extends BaseService // 检查订单是否全部评价完成,若是则更新订单状态为已完成 $this->checkOrderOverAfterComment($cartInfo['oid']); - return $res; + // save() 返回模型实例,签名声明返回 int(评价ID) + return $replyId; } /**