Files
hyperf_service/app/Service/Api/Order/RefundOrderService.php
2025-03-07 16:20:57 +08:00

52 lines
1.3 KiB
PHP

<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Api\Order;
use App\Constants\Common\OrderCode;
use App\Exception\ErrException;
use App\Model\Order;
use App\Service\Api\BaseService;
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class RefundOrderService extends BaseService
{
use OrderChangeStatusTrait;
/**
* @var Order
*/
#[Inject]
protected Order $orderModel;
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function handle(): array
{
//todo 考虑是否枷锁
$orderId = (int)$this->request->input('order_id');
$type = (int)$this->request->input('order_type');
$orderInfo = $this->orderModel->getInfoById($orderId);
if ($orderInfo->status != OrderCode::PAYED) throw new ErrException('该订单状态已变更,请勿重复操作,刷新后无法退款请联系客服');
//立即取消
$this->joinRefundQueue($orderId, $type, $orderInfo->actual_price, '用户主动取消订单');
return $this->return->success();
}
}