Files
hyperf_service/app/Service/ServiceTrait/Common/OrderChangeStatusTrait.php
2025-03-27 10:58:00 +08:00

69 lines
1.9 KiB
PHP

<?php
namespace App\Service\ServiceTrait\Common;
use App\Amqp\Producer\CancelOrderProducer;
use App\Amqp\Producer\RefundOrderProducer;
use App\Cache\Redis\Common\ConfigCache;
use App\Constants\Common\OrderCode;
use App\Constants\ConfigCode;
use App\Extend\DateUtil;
use Hyperf\Amqp\Producer;
use Hyperf\Context\ApplicationContext;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
trait OrderChangeStatusTrait
{
/**
* @var ConfigCache $configCache
*/
#[Inject]
protected ConfigCache $configCache;
/**
* @var Producer
*/
#[Inject]
protected Producer $producer;
/**
* 加入取消队列
* @param int $orderId
* @param int $type
* @param int $millisecond
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function joinCancelDelayQueue(int $orderId,int $type,int $millisecond): void
{
$message = new CancelOrderProducer([
'order_id' => $orderId,
'type' => $type
]);
$message->setDelayMs($millisecond);
// $producer = ApplicationContext::getContainer()->get(Producer::class);
$this->producer->produce($message);
}
/**
* @param int $orderId
* @param int $type refundCode
* @param string $reason
* @param int $adminId
* @return void
*/
protected function joinRefundQueue(int $orderId, int $type, string $reason = '系统自动',int $adminId = 0): void
{
$message = new RefundOrderProducer([
'order_id' => $orderId,
'type' => $type,
'reason' => $reason,
'admin_id' => $adminId
]);
// $producer = ApplicationContext::getContainer()->get(Producer::class);
$this->producer->produce($message);
}
}