Files
hyperf_service/app/Service/Amqp/Refund/RefundGoodOrderFinishService.php
2025-03-27 10:47:31 +08:00

126 lines
2.6 KiB
PHP

<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Amqp\Refund;
use App\Constants\Common\RefundCode;
use App\Event\RefundGoodOrderFinishEvent;
use App\Lib\Log;
use App\Model\Order;
use App\Model\PayOrder;
use App\Model\RefundOrder;
use App\Service\ServiceTrait\Api\CateringTrait;
use App\Service\ServiceTrait\Api\CouponTrait;
use App\Service\ServiceTrait\Api\OrderTrait;
use App\Service\ServiceTrait\Api\RefundOrderTrait;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
class RefundGoodOrderFinishService
{
use RefundOrderTrait;
use CateringTrait;
use CouponTrait;
use OrderTrait;
/**
* @var string
*/
public string $orderSno;
/**
* @var int
*/
public int $payType;
/**
* @var int
*/
public int $orderType;
/**
* @var array
*/
public array $callbackData;
/**
* @var Order
*/
protected Order $orderInfo;
/**
* @var PayOrder
*/
protected PayOrder $payInfo;
/**
* @var RefundOrder
*/
protected RefundOrder $refundInfo;
/**
* @var EventDispatcherInterface
*/
#[Inject]
private EventDispatcherInterface $eventDispatcher;
/**
* @var Log
*/
#[Inject]
protected Log $log;
/**
* @var bool
*/
protected bool $rollBackStockFlag;
/**
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function handle(): void
{
$this->checkRefundOrder();
$this->rollBackStockFlag = $this->orderInfo->cycle_id == $this->initTodayCycleId();
Db::transaction(function (){
$this->manageRefundOrder();
$this->manageOrderByRefund();
$this->manageSubCateringLog();
});
$this->eventDispatcher->dispatch(new RefundGoodOrderFinishEvent($this->orderInfo->id, $this->payInfo->id, $this->refundInfo->id));
}
/**
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
private function rollBackStock(): void
{
if (!$this->rollBackStockFlag) return;
//判断是不是用户行为才退库存
if ($this->refundInfo->action_admin_id != 0) return;
$this->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
}
}