新增等待创建检测订单队列,修改im报告推送
This commit is contained in:
parent
3169cf4bfc
commit
9b675c1681
83
app/Amqp/Consumer/DetectionCompleteDelayDirectConsumer.php
Normal file
83
app/Amqp/Consumer/DetectionCompleteDelayDirectConsumer.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer;
|
||||
|
||||
use App\Amqp\Producer\DetectionCompleteDelayDirectProducer;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\OrderDetection;
|
||||
use App\Services\InquiryService;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\Amqp\Result;
|
||||
use Hyperf\Amqp\Annotation\Consumer;
|
||||
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
|
||||
#[Consumer(nums: 1)]
|
||||
class DetectionCompleteDelayDirectConsumer extends ConsumerMessage
|
||||
{
|
||||
use ProducerDelayedMessageTrait;
|
||||
use ConsumerDelayedMessageTrait;
|
||||
|
||||
protected string $exchange = 'amqp.delay.direct';
|
||||
|
||||
protected ?string $queue = 'detection.complete.delay.queue';
|
||||
|
||||
protected string $type = Type::DIRECT; //Type::FANOUT;
|
||||
|
||||
protected string|array $routingKey = 'DetectionComplete';
|
||||
|
||||
public function consumeMessage($data, AMQPMessage $message): string
|
||||
{
|
||||
Log::getInstance("queue-DetectionComplete")->info("开始:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
// 获取检测订单数据
|
||||
$params = array();
|
||||
$params['detection_no'] = $data['detection_no'];
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (empty($order_detection)){
|
||||
Log::getInstance("queue-DoctorNotYetInquiry")->error("非法订单");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
try {
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($order_detection['user_id'],$order_detection['doctor_id']);
|
||||
if (!empty($order_inquiry)){
|
||||
// 存在未完成订单
|
||||
// 获取现在时间距离订单结束时间的时间差
|
||||
$time_diff = $InquiryService->getInquiryFinishTimeDiff($order_inquiry);
|
||||
|
||||
// 计算时间并重新加入队列
|
||||
$queue_data = array();
|
||||
$queue_data['order_inquiry_id'] = $data['order_inquiry_id'];
|
||||
|
||||
$message = new DetectionCompleteDelayDirectProducer($queue_data);
|
||||
$message->setDelayMs(1000 * $time_diff);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("处理用户优惠卷过期队列 执行失败:未到过期时间,重新添加队列失败");
|
||||
return Result::REQUEUE;
|
||||
}
|
||||
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
}catch (\Throwable $e){
|
||||
Log::getInstance("queue-DoctorNotYetInquiry")->error($e->getMessage());
|
||||
return Result::DROP; // 重回队列
|
||||
}
|
||||
|
||||
|
||||
return Result::ACK;
|
||||
}
|
||||
}
|
||||
31
app/Amqp/Producer/DetectionCompleteDelayDirectProducer.php
Normal file
31
app/Amqp/Producer/DetectionCompleteDelayDirectProducer.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Producer;
|
||||
|
||||
use Hyperf\Amqp\Annotation\Producer;
|
||||
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\ProducerMessage;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
|
||||
/**
|
||||
* 检测订单自动完成延迟队列
|
||||
* 当接收到检测报告时,如当时患者-医生存在问诊中订单,则加入此延迟队列,等待问诊结束后,检测订单才会接收
|
||||
*/
|
||||
#[Producer]
|
||||
class DetectionCompleteDelayDirectProducer extends ProducerMessage
|
||||
{
|
||||
use ProducerDelayedMessageTrait;
|
||||
|
||||
protected string $exchange = 'amqp.delay.direct';
|
||||
|
||||
protected string $type = Type::DIRECT;
|
||||
|
||||
protected string|array $routingKey = 'DetectionComplete';
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->payload = $data;
|
||||
}
|
||||
}
|
||||
@ -1337,7 +1337,7 @@ class CallBackController extends AbstractController
|
||||
* 检测所结果回调
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function DetectionResultCallBack(): ResponseInterface
|
||||
public function DetectionResultCallBack1(): ResponseInterface
|
||||
{
|
||||
$request_params = $this->request->all();
|
||||
$auth = $this->request->header("Authorization");
|
||||
@ -1510,6 +1510,10 @@ class CallBackController extends AbstractController
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetection::editOrderDetection($params,$data);
|
||||
|
||||
// 回填检测结果字段
|
||||
$order_detection['detection_result_pdf'] = $detection_result_pdf;
|
||||
$order_detection['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
|
||||
// 添加自动完成队列
|
||||
$time = 1000 * 60 * 60 * 24 * 3;
|
||||
|
||||
@ -1577,6 +1581,109 @@ class CallBackController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测所结果回调
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function DetectionResultCallBack(): ResponseInterface
|
||||
{
|
||||
$request_params = $this->request->all();
|
||||
$auth = $this->request->header("Authorization");
|
||||
if (empty($auth)){
|
||||
return $this->detectionResultFailReturn("非法请求");
|
||||
}
|
||||
|
||||
Log::getInstance("CallBackController-DetectionResultCallBack")->info("处理检测所结果");
|
||||
|
||||
try {
|
||||
// 检测参数
|
||||
if (!isset($request_params['appId'])){
|
||||
return $this->detectionResultFailReturn("缺少appId参数");
|
||||
}
|
||||
|
||||
if (!isset($request_params['orderCode'])){
|
||||
return $this->detectionResultFailReturn("缺少orderCode参数");
|
||||
}
|
||||
|
||||
if (!isset($request_params['detectBarcode'])){
|
||||
return $this->detectionResultFailReturn("缺少detectBarcode参数");
|
||||
}
|
||||
|
||||
if (!isset($request_params['pdfReport'])){
|
||||
return $this->detectionResultFailReturn("缺少pdfReport参数");
|
||||
}
|
||||
|
||||
// 检测签名
|
||||
$params = array();
|
||||
$params['app_id'] = $request_params['appId'];
|
||||
$basic_detection_organ = BasicDetectionOrgan::getOne($params);
|
||||
if (empty($basic_detection_organ)){
|
||||
return $this->detectionResultFailReturn("非法appId");
|
||||
}
|
||||
|
||||
$time = date('Ymd');
|
||||
$sign = md5($basic_detection_organ['app_id'] . $basic_detection_organ['app_secret'] . $time);
|
||||
if ($auth != $sign){
|
||||
return $this->detectionResultFailReturn("签名错误");
|
||||
}
|
||||
|
||||
// 检测pdf文件
|
||||
$pdfData = base64_decode($request_params['pdfReport']);
|
||||
if (!$pdfData){
|
||||
return $this->detectionResultFailReturn("文件错误");
|
||||
}
|
||||
|
||||
// 获取检测订单数据
|
||||
$params = array();
|
||||
$params['detection_no'] = $request_params['orderCode'];
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (empty($order_detection)){
|
||||
return $this->detectionResultFailReturn("非法订单");
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_detection['detection_status'] != 3){
|
||||
return $this->detectionResultFailReturn("订单状态错误,无法处理");
|
||||
}
|
||||
|
||||
if (!empty($order_detection['detection_result_pdf'])){
|
||||
return $this->detectionResultSuccessReturn();
|
||||
}
|
||||
|
||||
if ($order_detection['detection_bar_code'] != $request_params['detectBarcode']){
|
||||
return $this->detectionResultFailReturn("检测条码无法对应");
|
||||
}
|
||||
|
||||
// 上传处方图片至oss
|
||||
$oss = new Oss();
|
||||
$detection_result_pdf_name = "applet/patient/detection/pdf/" . $order_detection['order_detection_id'] . '.' . 'pdf';
|
||||
$detection_result_pdf = $oss->putObject($detection_result_pdf_name, $pdfData);
|
||||
$detection_result_pdf = '/' . $detection_result_pdf;
|
||||
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
// 修改检测订单
|
||||
$data = array();
|
||||
$data['detection_result_pdf'] = $detection_result_pdf;
|
||||
$data['detection_result_date'] = date('Y-m-d H:i:s',time());
|
||||
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetection::editOrderDetection($params,$data);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollBack();
|
||||
return $this->detectionResultFailReturn($e->getMessage());
|
||||
}
|
||||
|
||||
return $this->detectionResultSuccessReturn();
|
||||
} catch (\Throwable $e) {
|
||||
return $this->detectionResultFailReturn("异常:" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测所结果回调失败
|
||||
* @param string $message
|
||||
|
||||
@ -694,6 +694,7 @@ class ImService extends BaseService
|
||||
$message_content_data['data']['order_no'] = (string)$order_detection['detection_no'];
|
||||
$message_content_data['data']['disease_class_names'] = $disease_class_names;
|
||||
$message_content_data['data']['detection_link'] = addAliyunOssWebsite($order_detection['detection_result_pdf']);// 检测结果链接(oss)
|
||||
$message_content_data['data']['message_path'] = "/pages/checkOrderDetail/checkOrderDetail?order_detection_id=" . $order_detection['detection_no']; // 跳转地址(小程序内页)
|
||||
$message_content = [
|
||||
'Data' => json_encode($message_content_data, JSON_UNESCAPED_UNICODE),
|
||||
];
|
||||
|
||||
@ -1319,7 +1319,7 @@ class InquiryService extends BaseService
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测当前医生是否和患者存在未完成问诊订单
|
||||
* 检测当前医生是否和患者进行中的问诊订单
|
||||
* @param string $patient_id
|
||||
* @param string $doctor_id
|
||||
* @return array
|
||||
@ -1472,4 +1472,87 @@ class InquiryService extends BaseService
|
||||
|
||||
return $is_time_pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取现在时间距离订单结束时间的时间差
|
||||
* @param array|object $order_inquiry
|
||||
* @return float|int
|
||||
*/
|
||||
public function getInquiryFinishTimeDiff(array|object $order_inquiry): float|int
|
||||
{
|
||||
if (!in_array($order_inquiry['inquiry_status'], [1, 2, 3, 4])) {
|
||||
throw new BusinessException("问诊订单状态错误");
|
||||
}
|
||||
|
||||
$time = 0;
|
||||
$wait_pay_time = 60 * 30;// 待支付时间
|
||||
$wait_assign_time = 60 * 5;// 待分配时间
|
||||
$wait_inquiry_time = 0; // 待接诊时间
|
||||
$wait_finish_time = 0;// 待结束时间
|
||||
|
||||
if ($order_inquiry['inquiry_type'] == 1) {
|
||||
// 专家问诊
|
||||
$wait_assign_time = 0;
|
||||
$wait_inquiry_time = 60 * 60 * 24;
|
||||
$wait_finish_time = 60 * 60 * 24;
|
||||
} elseif ($order_inquiry['inquiry_type'] == 2) {
|
||||
// 快速问诊
|
||||
$wait_assign_time = 60 * 5;
|
||||
$wait_inquiry_time = 60 * 10;
|
||||
$wait_finish_time = 60 * 60;
|
||||
} elseif ($order_inquiry['inquiry_type'] == 3) {
|
||||
// 公益问诊
|
||||
$wait_assign_time = 0;
|
||||
$wait_inquiry_time = 60 * 60 * 24;
|
||||
$wait_finish_time = 60 * 60 * 24;
|
||||
} elseif ($order_inquiry['inquiry_type'] == 4) {
|
||||
// 问诊购药
|
||||
$wait_assign_time = 60 * 5;
|
||||
$wait_inquiry_time = 60 * 10;
|
||||
$wait_finish_time = 60 * 30;
|
||||
}
|
||||
|
||||
switch ($order_inquiry['inquiry_status']) {
|
||||
case '1':
|
||||
// 待支付
|
||||
$wait_pay_time = $wait_pay_time - (time() - strtotime($order_inquiry['created_at']));
|
||||
if ($wait_pay_time < 0 ){
|
||||
$wait_pay_time = 0;
|
||||
}
|
||||
|
||||
$time = $wait_pay_time + $wait_assign_time + $wait_inquiry_time + $wait_finish_time;
|
||||
break;
|
||||
case '2':
|
||||
// 待分配
|
||||
$time = $wait_assign_time + $wait_inquiry_time + $wait_finish_time;
|
||||
break;
|
||||
case '3':
|
||||
// 待接诊
|
||||
$wait_inquiry_time = $wait_inquiry_time - (time() - strtotime($order_inquiry['pay_time']));
|
||||
if ($wait_inquiry_time < 0 ){
|
||||
$wait_inquiry_time = 0;
|
||||
}
|
||||
|
||||
$time = $wait_inquiry_time + $wait_finish_time;
|
||||
break;
|
||||
case '4':
|
||||
// 已接诊
|
||||
$wait_finish_time = $wait_finish_time - (time() - strtotime($order_inquiry['reception_time']));
|
||||
if ($wait_finish_time < 0 ){
|
||||
$wait_finish_time = 0;
|
||||
}
|
||||
|
||||
$time = $wait_finish_time;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ($time < 0){
|
||||
$time = 0;
|
||||
}
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1777,7 +1777,7 @@ class UserDoctorService extends BaseService
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
OrderInquiry::edit($params,$data);
|
||||
|
||||
// 添加自动完成队列
|
||||
// 添加自动结束队列
|
||||
if ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){
|
||||
// 专家问诊-公益问诊
|
||||
$time = 1000 * 60 * 60 * 24;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user