Эх сурвалжийг харах

feat: 优化订单指派逻辑以增强支付处理和状态更新

在OrderService中,修改了assignCoach方法,更新了支付类型的检查逻辑,确保在处理余额和微信支付时的类型转换。同时,删除了冗余的Redis记录删除操作,并在成功指派后更新订单状态为已接单。这一改进旨在提升订单指派的准确性和系统的健壮性。
刘学玺 3 сар өмнө
parent
commit
7b7bdb2058

+ 7 - 5
app/Services/Client/OrderService.php

@@ -2474,17 +2474,16 @@ readonly class OrderService
                 ];
 
                 // 6. 处理支付
-                if ($order->payment_type === PaymentMethod::BALANCE->value) {
+                if ((int)$order->payment_type === PaymentMethod::BALANCE->value) {
                     $this->handleBalancePaymentForAssign($order, $userId, $coachId);
-                } else if ($order->payment_type === PaymentMethod::WECHAT->value) {
+                    // 7. 删除订单位置的Redis记录
+                    Redis::zrem('order_locations', 'order_' . $order->id);
+                } else if ((int)$order->payment_type === PaymentMethod::WECHAT->value) {
                     // 获取微信支付配置
                     $paymentService = app(PaymentService::class);
                     $result['wx_payment'] = $paymentService->getPaymentConfig($order->id);
                 }
 
-                // 7. 删除订单位置的Redis记录
-                Redis::zrem('order_locations', 'order_' . $order->id);
-
                 // 8. 发送通知
                 $this->notifyAssignment($order, $coach);
 
@@ -2596,6 +2595,9 @@ readonly class OrderService
 
             // 更新抢单记录
             $this->updateGrabRecords($order->id, $coachId);
+
+            // 更新订单状态为已接单
+            $order->update(['state' => OrderStatus::ACCEPTED->value]);
         });
     }