feat : check
This commit is contained in:
50
app/Amqp/Consumer/Order/GoodOrderFinishSuccessorConsumer.php
Normal file
50
app/Amqp/Consumer/Order/GoodOrderFinishSuccessorConsumer.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Amqp\Consumer\Order;
|
||||||
|
|
||||||
|
use App\Lib\Log;
|
||||||
|
use App\Service\Amqp\Order\GoodOrderFinishSuccessorService;
|
||||||
|
use Exception;
|
||||||
|
use Hyperf\Amqp\Message\Type;
|
||||||
|
use Hyperf\Amqp\Result;
|
||||||
|
use Hyperf\Amqp\Annotation\Consumer;
|
||||||
|
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
use PhpAmqpLib\Message\AMQPMessage;
|
||||||
|
|
||||||
|
#[Consumer(exchange: 'GoodOrderFinish', routingKey: 'GoodOrderFinish', queue: 'GoodOrderFinish.successor', name: "GoodOrderFinishSuccessorConsumer", nums: 1)]
|
||||||
|
class GoodOrderFinishSuccessorConsumer extends ConsumerMessage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Type|string 消息类型
|
||||||
|
*/
|
||||||
|
protected Type|string $type = Type::DIRECT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Log
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Log $log;
|
||||||
|
|
||||||
|
public function consumeMessage($data, AMQPMessage $message): Result
|
||||||
|
{
|
||||||
|
if (!$data['order_id']) {
|
||||||
|
$this->log->error('GoodOrderFinishSuccessorConsumer:error:NoData:'.json_encode($data));
|
||||||
|
return Result::ACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$service = new GoodOrderFinishSuccessorService();
|
||||||
|
|
||||||
|
$service->orderId = (int)$data['order_id'];
|
||||||
|
|
||||||
|
$service->handle();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->log->error('GoodOrderFinishSuccessorConsumer:error:'.$e->getMessage().':data:'.json_encode($data));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result::ACK;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
app/Amqp/Producer/Order/GoodOrderFinishSuccessorProducer.php
Normal file
26
app/Amqp/Producer/Order/GoodOrderFinishSuccessorProducer.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Amqp\Producer\Order;
|
||||||
|
|
||||||
|
use Hyperf\Amqp\Annotation\Producer;
|
||||||
|
use Hyperf\Amqp\Message\ProducerMessage;
|
||||||
|
use Hyperf\Amqp\Message\Type;
|
||||||
|
|
||||||
|
#[Producer(exchange: 'GoodOrderFinish', routingKey: 'GoodOrderFinish')]
|
||||||
|
class GoodOrderFinishSuccessorProducer extends ProducerMessage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Type|string 消息类型
|
||||||
|
*/
|
||||||
|
protected Type|string $type = Type::DIRECT;
|
||||||
|
|
||||||
|
public function __construct($data)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* $data string array => {"order_id":"orderId"}
|
||||||
|
*/
|
||||||
|
$this->payload = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
58
app/Service/Amqp/Order/GoodOrderFinishSuccessorService.php
Normal file
58
app/Service/Amqp/Order/GoodOrderFinishSuccessorService.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This service file is part of item.
|
||||||
|
*
|
||||||
|
* @author ctexthuang
|
||||||
|
* @contact ctexthuang@qq.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service\Amqp\Order;
|
||||||
|
|
||||||
|
use App\Constants\Common\OrderCode;
|
||||||
|
use App\Model\Order;
|
||||||
|
use Exception;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
|
||||||
|
class GoodOrderFinishSuccessorService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public int $orderId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Order
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected Order $orderModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Order
|
||||||
|
*/
|
||||||
|
protected Order $orderInfo;
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$this->orderInfo = $this->orderModel->find($this->orderId);
|
||||||
|
|
||||||
|
if (empty($this->orderInfo)) throw new Exception('订单不存在');
|
||||||
|
|
||||||
|
if ($this->orderInfo->status != OrderCode::FINISH) throw new Exception('订单状态错误');
|
||||||
|
|
||||||
|
$this->addOrderPoint();
|
||||||
|
|
||||||
|
$this->addInvite();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addOrderPoint()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function addInvite()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user