log->error('CancelOrderConsumer:error:NoData:'.json_encode($data)); return Result::ACK; } $orderId = (int)$data['order_id']; $orderType = (int)$data['type']; $amount = $data['amount']; $orderInfo = match ($orderType) { OrderCode::ORDER_TYPE_GOOD => $this->orderModel->getInfoById($orderId), default => null, }; if (empty($orderInfo)) { $this->log->debug('RefundOrderConsumer:error:NoOrderData:'.json_encode($data)); return Result::ACK; } if (!in_array($orderInfo->status,OrderCode::CAN_REFUND_STATUS)) { $this->log->debug('CancelOrderConsumer:error:orderStatusError:'.json_encode($orderInfo->toArray())); return Result::ACK; } //余额订单必须退款全部金额 if ($orderType == OrderCode::ORDER_TYPE_BALANCE && $amount != 0) { $this->log->debug('CancelOrderConsumer:error:orderStatusError:'.json_encode($orderInfo->toArray())); return Result::ACK; } try { $service = null; switch ($orderType) { case OrderCode::ORDER_TYPE_GOOD: if ($amount == 0) { $service = $this->refundFactory->newGoodOrderRefundAll(); } else { $service = $this->refundFactory->newGoodOrderRefundPart(); } break; case OrderCode::ORDER_TYPE_BALANCE: $service = $this->refundFactory->newBalanceOrderRefund(); break; default: throw new Exception('service not found or orderType error'); } } catch (Exception $e) { $this->log->error('RefundOrderConsumer:error:'.$e->getMessage().':data:'.json_encode($data)); } return Result::ACK; } }