|
|
@@ -34,6 +34,11 @@ class CallBackHandler
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ $sendStatus = $this->mapEventTypeToOrderSendStatus($eventType);
|
|
|
+ if ($sendStatus === null) {
|
|
|
+ Yii::warning(sprintf('货拉拉事件未配置状态映射: event_type=%s, order_display_id=%s', $eventType, $orderDisplayId), 'huolala-callback');
|
|
|
+ return true;
|
|
|
+ }
|
|
|
$orderStatus = $this->mapEventTypeToOrderStatus($eventType);
|
|
|
if ($orderStatus === null) {
|
|
|
Yii::warning(sprintf('货拉拉事件未配置状态映射: event_type=%s, order_display_id=%s', $eventType, $orderDisplayId), 'huolala-callback');
|
|
|
@@ -46,7 +51,7 @@ class CallBackHandler
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $deliveryOrder->orderStatus = $orderStatus;
|
|
|
+ $deliveryOrder->orderStatus = $sendStatus;
|
|
|
if (!$deliveryOrder->save()) {
|
|
|
Yii::error('更新配送订单状态失败: ' . json_encode($deliveryOrder->getErrors(), JSON_UNESCAPED_UNICODE), 'huolala-callback');
|
|
|
return false;
|
|
|
@@ -56,16 +61,17 @@ class CallBackHandler
|
|
|
if(property_exists($deliveryOrder, 'ghsOrderId')){ // 批发
|
|
|
$order = OrderClass::getById($deliveryOrder->ghsOrderId, true, 'id,sendStatus,deliveryId,purchaseId,customId,status');
|
|
|
if ($order) {
|
|
|
- $order->sendStatus = $orderStatus;
|
|
|
+ $order->sendStatus = $sendStatus;
|
|
|
+ $order->status = $orderStatus;
|
|
|
if (!$order->save()) {
|
|
|
Yii::warning('更新主订单配送状态失败: ' . json_encode($order->getErrors(), JSON_UNESCAPED_UNICODE), 'huolala-callback');
|
|
|
}
|
|
|
|
|
|
// 确认送达或取消订单,更新主订单状态
|
|
|
- if ($orderStatus == 5) {
|
|
|
+ if ($sendStatus == 5) {
|
|
|
OrderClass::confirmReach($order, ['staffId' => 0, 'staffName' => '']);
|
|
|
}
|
|
|
- if ($orderStatus == -1 || $orderStatus == -2) {
|
|
|
+ if ($sendStatus == -1 || $sendStatus == -2) {
|
|
|
OrderClass::cancelOrderSend($order, ['staffId' => 0, 'staffName' => '']);
|
|
|
}
|
|
|
} else {
|
|
|
@@ -74,7 +80,8 @@ class CallBackHandler
|
|
|
}elseif(property_exists($deliveryOrder, 'hdOrderId')){ // 零售
|
|
|
$order = HdOrderClass::getById($deliveryOrder->hdOrderId, true, 'id,sendType,sendStatus,deliveryId,customId,status');
|
|
|
if ($order) {
|
|
|
- $order->sendStatus = $orderStatus;
|
|
|
+ $order->sendStatus = $sendStatus;
|
|
|
+ $order->status = $orderStatus;
|
|
|
if (!$order->save()) {
|
|
|
Yii::warning('更新主订单配送状态失败: ' . json_encode($order->getErrors(), JSON_UNESCAPED_UNICODE), 'huolala-callback');
|
|
|
}
|
|
|
@@ -83,7 +90,7 @@ class CallBackHandler
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Yii::info(sprintf('货拉拉配送状态更新成功: order_display_id=%s, event_type=%s, orderStatus=%s', $orderDisplayId, $eventType, $orderStatus), 'huolala-callback');
|
|
|
+ Yii::info(sprintf('货拉拉配送状态更新成功: order_display_id=%s, event_type=%s, orderStatus=%s', $orderDisplayId, $eventType, $sendStatus), 'huolala-callback');
|
|
|
return true;
|
|
|
} catch (\Throwable $e) {
|
|
|
Yii::error('货拉拉回调处理异常: ' . $e->getMessage() . ' | Trace: ' . $e->getTraceAsString(), 'huolala-callback');
|
|
|
@@ -97,7 +104,7 @@ class CallBackHandler
|
|
|
* @param string $eventType
|
|
|
* @return int|null
|
|
|
*/
|
|
|
- protected function mapEventTypeToOrderStatus($eventType)
|
|
|
+ protected function mapEventTypeToOrderSendStatus($eventType)
|
|
|
{
|
|
|
$map = [
|
|
|
'order_cancel' => -1,
|
|
|
@@ -122,6 +129,44 @@ class CallBackHandler
|
|
|
return $map[$eventType] ?? null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 事件到系统订单状态的映射
|
|
|
+ *
|
|
|
+ * @param string $eventType
|
|
|
+ * @return int|null
|
|
|
+ */
|
|
|
+ protected function mapEventTypeToOrderStatus($eventType)
|
|
|
+ {
|
|
|
+ // 系统订单状态: 1待付款 2待配送 3配送中 4已完成 5已取消
|
|
|
+ $map = [
|
|
|
+ // 取消状态 (订单终态)
|
|
|
+ 'order_cancel' => 2, // 订单取消 -> 已取消 改为 待配送(配送的取消不等于订单的取消,由于 status 带有配送状态,所以改为:待配送)
|
|
|
+
|
|
|
+ // 回到待配送状态 (可重新派单)
|
|
|
+ 'no_load_cancel' => 2, // 未装货取消 -> 待配送
|
|
|
+ 'no_complete_cancel' => 2, // 未完成取消 -> 待配送
|
|
|
+ 'order_timeout' => 2, // 订单超时 -> 待配送
|
|
|
+ 'driver_reject' => 2, // 司机拒单 -> 待配送
|
|
|
+ 'set_order_abnormal' => 2, // 订单异常 -> 待配送
|
|
|
+ 'prepay_ok' => 2, // 预付成功 -> 待配送
|
|
|
+
|
|
|
+ // 配送中状态
|
|
|
+ 'pickup' => 3, // 已取货 -> 配送中
|
|
|
+ 'loading' => 3, // 装货中 -> 配送中
|
|
|
+ 'loaded' => 3, // 已装货 -> 配送中
|
|
|
+ 'unloading' => 3, // 卸货中 -> 配送中
|
|
|
+ 'unload_finish' => 3, // 卸货完成 -> 配送中
|
|
|
+
|
|
|
+ // 完成状态
|
|
|
+ 'order_complete' => 4, // 订单完成 -> 已完成
|
|
|
+ 'order_auto_complete' => 4, // 订单自动完成 -> 已完成
|
|
|
+ 'auto_confirm_bill_pay' => 4, // 自动确认支付 -> 已完成
|
|
|
+ 'rear_pay_ok' => 4, // 尾款支付成功 -> 已完成
|
|
|
+ 'cash_received' => 4, // 收到现金 -> 已完成
|
|
|
+ ];
|
|
|
+ return $map[$eventType] ?? null;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据订单号查找配送订单
|
|
|
*
|