Files
hyperf_service/app/Service/ServiceTrait/Common/OrderChangeStatusTrait.php
2025-02-24 15:30:58 +08:00

65 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;
/**
* 加入取消队列
* @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);
$producer->produce($message);
}
/**
* @param int $orderId
* @param int $type
* @param float|int $amount amount = 0 全部 amount > 0 部分
* @param string $reason
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function joinRefundQueue(int $orderId, int $type, float|int $amount = 0, string $reason = '系统自动'): void
{
$message = new RefundOrderProducer([
'order_id' => $orderId,
'type' => $type,
'amount' => $amount,
'reason' => $reason
]);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$producer->produce($message);
}
}