feat : refund

This commit is contained in:
2025-02-24 15:06:26 +08:00
parent 6754d2969e
commit 27a6ad3e2e
15 changed files with 591 additions and 281 deletions

View File

@@ -9,6 +9,7 @@ use App\Lib\Log;
use App\Model\Order;
use App\Service\Amqp\Refund\GoodOrderAllRefundService;
use App\Service\Amqp\Refund\RefundFactory;
use App\Service\Amqp\Refund\RefundService;
use App\Service\ServiceTrait\Api\OrderTrait;
use Exception;
use Hyperf\Amqp\Message\Type;
@@ -41,11 +42,6 @@ class RefundOrderConsumer extends ConsumerMessage
#[Inject]
protected Order $orderModel;
/**
* @var RefundFactory
*/
#[Inject]
protected RefundFactory $refundFactory;
public function consumeMessage($data, AMQPMessage $message): Result
{
@@ -58,45 +54,10 @@ class RefundOrderConsumer extends ConsumerMessage
$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;
$service = new RefundService();
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) {