53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Amqp\Consumer;
|
|
|
|
use App\Model\OrderPrescription;
|
|
use App\Utils\Log;
|
|
use Hyperf\Amqp\Result;
|
|
use Hyperf\Amqp\Annotation\Consumer;
|
|
use Hyperf\Amqp\Message\ConsumerMessage;
|
|
use Hyperf\DbConnection\Db;
|
|
use PhpAmqpLib\Message\AMQPMessage;
|
|
|
|
/**
|
|
* 分配药师
|
|
*/
|
|
#[Consumer(exchange: 'amqp.direct', routingKey: 'AssignPharmacist', queue: 'assign.pharmacist.queue', nums: 1)]
|
|
class AssignPharmacistConsumer extends ConsumerMessage
|
|
{
|
|
public function consumeMessage($data, AMQPMessage $message): string
|
|
{
|
|
Log::getInstance()->error("开始执行 分配药师 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
|
|
|
Db::beginTransaction();
|
|
|
|
try {
|
|
// 获取订单-处方表数据
|
|
$params = array();
|
|
$params['order_prescription_id'] = $data['order_prescription_id'];
|
|
$order_prescription = OrderPrescription::getOne($params);
|
|
if (empty($order_prescription)){
|
|
Db::rollBack();
|
|
Log::getInstance()->error("分配药师队列执行失败:未查询到对应处方订单数据");
|
|
return Result::DROP;// 销毁
|
|
}
|
|
|
|
// 检测处方状态
|
|
if ($order_prescription['prescription_status'] != 1){
|
|
|
|
}
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
Db::rollBack();
|
|
Log::getInstance()->error("分配药师队列执行失败原因:" . $e->getMessage());
|
|
return Result::REQUEUE; // 重回队列
|
|
}
|
|
|
|
return Result::ACK;
|
|
}
|
|
}
|