113 lines
2.3 KiB
PHP
113 lines
2.3 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\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();
|
|
});
|
|
|
|
if ($this->rollBackStockFlag) {
|
|
$this->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
|
|
}
|
|
|
|
$this->eventDispatcher->dispatch(new RefundGoodOrderFinishEvent($this->orderInfo->id, $this->payInfo->id, $this->refundInfo->id));
|
|
|
|
}
|
|
} |