feat : refund

This commit is contained in:
2025-03-27 10:47:31 +08:00
parent 1265bdcce9
commit f9d3511ed6
7 changed files with 128 additions and 23 deletions

View File

@@ -97,7 +97,6 @@ class PlaceOrderService extends BaseOrderService
foreach ($this->cartFirstData as $goodId => $stock) {
$this->rollbackStockCache[$goodId] = $stock;
if (!($this->redis->zIncrBy($this->stockKey,-$stock,$goodId))) {
echo '123';
throw new Exception('cache error');
}
}

View File

@@ -15,8 +15,10 @@ use App\Constants\Common\RefundCode;
use App\Exception\ErrException;
use App\Model\Order;
use App\Model\PayOrder;
use App\Service\Amqp\Refund\FullRefundOrderService;
use App\Service\Api\BaseService;
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
use Exception;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@@ -46,18 +48,26 @@ class RefundOrderService extends BaseService
{
//todo 考虑是否枷锁
$orderId = (int)$this->request->input('order_id');
$type = (int)$this->request->input('order_type');
$orderInfo = $this->orderModel->getInfoById($orderId);
if ($orderInfo->user_id != $this->userId) throw new ErrException('该订单不是您的订单,请勿操作');
if ($orderInfo->status != OrderCode::PAYED) throw new ErrException('该订单状态已变更,请勿重复操作,刷新后无法退款请联系客服');
$payInfo = $this->payOrderModel->getInfoByOrderIdAndType($orderInfo->id,OrderCode::ORDER_TYPE_GOOD);
if (empty($payInfo)) throw new ErrException('订单支付信息不存在');
try {
$orderId = (int)$this->request->input('order_id');
//立即取消
$this->joinRefundQueue($orderId, RefundCode::FULL_GOOD_REFUND, '用户主动取消订单');
$service = new FullRefundOrderService();
$service->orderId = $orderId;
$service->reason = '用户主动退款订单';
$service->type = RefundCode::FULL_GOOD_REFUND;
return $this->return->success();
$service->handle();
return $this->return->success();
}catch (Exception $e) {
throw new ErrException($e->getMessage());
}
}
}