feat : spu
This commit is contained in:
61
app/Amqp/Consumer/Pay/GoodOrderPayFinishConsumer.php
Normal file
61
app/Amqp/Consumer/Pay/GoodOrderPayFinishConsumer.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer\Pay;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Lib\Log;
|
||||
use App\Service\Amqp\Pay\PayGoodOrderFinishService;
|
||||
use Exception;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
use Hyperf\Amqp\Result;
|
||||
use Hyperf\Amqp\Annotation\Consumer;
|
||||
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
#[Consumer(exchange: 'GoodOrderPayFinish', routingKey: 'GoodOrderPayFinish', queue: 'GoodOrderPayFinish.pay', name: "GoodOrderPayFinishConsumer", nums: 1)]
|
||||
class GoodOrderPayFinishConsumer extends ConsumerMessage
|
||||
{
|
||||
/**
|
||||
* @var Type|string 消息类型
|
||||
*/
|
||||
protected Type|string $type = Type::DIRECT;
|
||||
|
||||
/**
|
||||
* @var Log
|
||||
*/
|
||||
protected Log $log;
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param AMQPMessage $message
|
||||
* @return Result
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function consumeMessage($data, AMQPMessage $message): Result
|
||||
{
|
||||
if (!$data['order_sno'] || !$data['pay_type']) {
|
||||
$this->log->error('GoodOrderPayFinishConsumer:error:NoData:'.json_encode($data));
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
$this->log->callbackLog('GoodOrderPayFinishConsumer:success:'.json_encode($data));
|
||||
|
||||
try {
|
||||
$service = new PayGoodOrderFinishService();
|
||||
|
||||
$service->orderSno = $data['order_sno'];
|
||||
$service->payType = (int)$data['pay_type'];
|
||||
|
||||
$service->handle();
|
||||
} catch (Exception|ErrException $e) {
|
||||
$this->log->error('GoodOrderPayFinishConsumer:error:'.$e->getMessage());
|
||||
}
|
||||
|
||||
return Result::ACK;
|
||||
}
|
||||
}
|
||||
62
app/Amqp/Consumer/Refund/GoodOrderRefundFinishConsumer.php
Normal file
62
app/Amqp/Consumer/Refund/GoodOrderRefundFinishConsumer.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer\Refund;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Lib\Log;
|
||||
use App\Service\Amqp\Refund\RefundGoodOrderFinishService;
|
||||
use Exception;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
use Hyperf\Amqp\Result;
|
||||
use Hyperf\Amqp\Annotation\Consumer;
|
||||
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
#[Consumer(exchange: 'GoodOrderRefundFinish', routingKey: 'GoodOrderRefundFinish', queue: 'GoodOrderRefundFinish.refund', name: "GoodOrderRefundFinishConsumer", nums: 1)]
|
||||
class GoodOrderRefundFinishConsumer extends ConsumerMessage
|
||||
{
|
||||
/**
|
||||
* @var Type|string 消息类型
|
||||
*/
|
||||
protected Type|string $type = Type::DIRECT;
|
||||
|
||||
|
||||
/**
|
||||
* @var Log
|
||||
*/
|
||||
protected Log $log;
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param AMQPMessage $message
|
||||
* @return Result
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function consumeMessage($data, AMQPMessage $message): Result
|
||||
{
|
||||
if (!$data['refund_order_sno'] || !$data['pay_type']) {
|
||||
$this->log->error('GoodOrderRefundFinishConsumer:error:NoData:'.json_encode($data));
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
$this->log->callbackLog('GoodOrderRefundFinishConsumer:success:'.json_encode($data));
|
||||
|
||||
try {
|
||||
$service = new RefundGoodOrderFinishService();
|
||||
|
||||
$service->orderSno = $data['order_sno'];
|
||||
$service->payType = (int)$data['pay_type'];
|
||||
|
||||
$service->handle();
|
||||
} catch (Exception|ErrException $e) {
|
||||
$this->log->error('GoodOrderRefundFinishConsumer:error:'.$e->getMessage());
|
||||
}
|
||||
|
||||
return Result::ACK;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user