新增等待创建检测订单队列,修改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),
|
||||
];
|
||||
|
||||
@ -81,7 +81,7 @@ class InquiryService extends BaseService
|
||||
|
||||
// 检测是否存在同类型未完成的问诊订单
|
||||
$PatientOrderService = new PatientOrderService();
|
||||
$order_inquiry_id = $PatientOrderService->getNotFinishedOrderInquiry($request_params['inquiry_type'],$user_info['client_user_id']);
|
||||
$order_inquiry_id = $PatientOrderService->getNotFinishedOrderInquiry($request_params['inquiry_type'], $user_info['client_user_id']);
|
||||
if (!empty($order_inquiry_id)) {
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "当前患者存在进行中的问诊订单";
|
||||
@ -95,7 +95,7 @@ class InquiryService extends BaseService
|
||||
}
|
||||
|
||||
// 是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在
|
||||
if (isset($request_params['is_taboo'])){
|
||||
if (isset($request_params['is_taboo'])) {
|
||||
if ($request_params['is_taboo'] == 0) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "无法为您开具药物");
|
||||
}
|
||||
@ -134,8 +134,8 @@ class InquiryService extends BaseService
|
||||
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($user_info['client_user_id'],$request_params['doctor_id']);
|
||||
if (!empty($order_inquiry)){
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($user_info['client_user_id'], $request_params['doctor_id']);
|
||||
if (!empty($order_inquiry)) {
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "您和当前医生存在问诊中订单,无法再次发起问诊";
|
||||
$result['data']['order_inquiry_id'] = $order_inquiry_id;
|
||||
@ -146,7 +146,7 @@ class InquiryService extends BaseService
|
||||
// 检测当前是否符合系统问诊时间
|
||||
$inquiryService = new InquiryService();
|
||||
$is_system_time_pass = $inquiryService->checkSystemInquiryTime($request_params['inquiry_type']);
|
||||
if (!$is_system_time_pass && $request_params['inquiry_type'] == 4){
|
||||
if (!$is_system_time_pass && $request_params['inquiry_type'] == 4) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "当前非医生接诊时间");
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ class InquiryService extends BaseService
|
||||
$DoctorInquiryService = new DoctorInquiryService();
|
||||
$inquiry_price = $DoctorInquiryService->getDoctorInquiryPrice($request_params['inquiry_type'], $request_params['inquiry_mode'], $request_params['doctor_id'] ?: "");
|
||||
|
||||
if ($inquiry_price > 0){
|
||||
if ($inquiry_price > 0) {
|
||||
// 获取可用优惠卷
|
||||
$CouponService = new CouponService();
|
||||
$user_coupon = $CouponService->getUserUsableCouponOne($user_info['user_id'], $request_params['inquiry_type']);
|
||||
@ -184,8 +184,8 @@ class InquiryService extends BaseService
|
||||
$data = array();
|
||||
$data['user_id'] = $user_info['user_id'];
|
||||
$data['patient_id'] = $user_info['client_user_id'];
|
||||
if (isset($request_params['doctor_id'])){
|
||||
if (!empty($request_params['doctor_id'])){
|
||||
if (isset($request_params['doctor_id'])) {
|
||||
if (!empty($request_params['doctor_id'])) {
|
||||
$data['doctor_id'] = $request_params['doctor_id'];
|
||||
}
|
||||
}
|
||||
@ -233,25 +233,25 @@ class InquiryService extends BaseService
|
||||
$data['diagnosis_date'] = $request_params['diagnosis_date'] ?: null; // 确诊日期
|
||||
$data['disease_desc'] = $request_params['disease_desc'] ?: null; // 病情描述(主诉)
|
||||
$data['diagnose_images'] = $diagnose_images ?? ""; // 复诊凭证(多个使用逗号分隔)
|
||||
if (isset($request_params['is_allergy_history'])){
|
||||
if ($request_params['is_allergy_history'] !== null){
|
||||
if (isset($request_params['is_allergy_history'])) {
|
||||
if ($request_params['is_allergy_history'] !== null) {
|
||||
$data['is_allergy_history'] = $request_params['is_allergy_history']; // 是否存在过敏史(0:否 1:是)
|
||||
}
|
||||
}
|
||||
$data['allergy_history'] = $request_params['allergy_history'] ?? null; // 过敏史描述
|
||||
if (isset($request_params['is_family_history'])){
|
||||
if ($request_params['is_family_history'] !== null){
|
||||
if (isset($request_params['is_family_history'])) {
|
||||
if ($request_params['is_family_history'] !== null) {
|
||||
$data['is_family_history'] = $request_params['is_family_history']; // 是否存在家族病史(0:否 1:是)
|
||||
}
|
||||
}
|
||||
$data['family_history'] = $request_params['family_history'] ?? null; // 家族病史描述
|
||||
if (isset($request_params['is_pregnant'])){
|
||||
if ($request_params['is_pregnant'] !== null){
|
||||
if (isset($request_params['is_pregnant'])) {
|
||||
if ($request_params['is_pregnant'] !== null) {
|
||||
$data['is_pregnant'] = $request_params['is_pregnant']; // 是否备孕、妊娠、哺乳期(0:否 1:是)
|
||||
}
|
||||
}
|
||||
if (isset($request_params['is_taboo'])){
|
||||
if ($request_params['is_taboo'] !== null){
|
||||
if (isset($request_params['is_taboo'])) {
|
||||
if ($request_params['is_taboo'] !== null) {
|
||||
$data['is_taboo'] = $request_params['is_taboo']; // 是否存在禁忌药物(0:否 1:是)问诊购药时存在
|
||||
}
|
||||
}
|
||||
@ -335,7 +335,7 @@ class InquiryService extends BaseService
|
||||
|
||||
// 加入未接诊取消订单延迟队列
|
||||
// 专家问诊-公益问诊
|
||||
if (!empty($request_params['doctor_id']) && ($request_params['inquiry_type'] == 1 || $request_params['inquiry_type'] == 3)){
|
||||
if (!empty($request_params['doctor_id']) && ($request_params['inquiry_type'] == 1 || $request_params['inquiry_type'] == 3)) {
|
||||
$data = array();
|
||||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$message = new CancelUnInquiryOrdersDelayDirectProducer($data);
|
||||
@ -418,11 +418,11 @@ class InquiryService extends BaseService
|
||||
$params = array();
|
||||
$params['family_id'] = $order_inquiry_case['family_id'];
|
||||
$patient_family_health = PatientFamilyHealth::getOne($params);
|
||||
if (empty($patient_family_health)){
|
||||
if (empty($patient_family_health)) {
|
||||
$order_inquiry_case['diagnosis_hospital'] = "";
|
||||
$order_inquiry_case['is_take_medicine'] = null;
|
||||
$order_inquiry_case['drugs_name'] = "";
|
||||
}else{
|
||||
} else {
|
||||
$order_inquiry_case['diagnosis_hospital'] = $patient_family_health['diagnosis_hospital'];
|
||||
$order_inquiry_case['is_take_medicine'] = $patient_family_health['is_take_medicine'];
|
||||
$order_inquiry_case['drugs_name'] = $patient_family_health['drugs_name'];
|
||||
@ -432,14 +432,14 @@ class InquiryService extends BaseService
|
||||
$params = array();
|
||||
$params['family_id'] = $order_inquiry_case['family_id'];
|
||||
$patient_family_personal = PatientFamilyPersonal::getOne($params);
|
||||
if (empty($patient_family_personal)){
|
||||
if (empty($patient_family_personal)) {
|
||||
$order_inquiry_case['drink_wine_status'] = null;
|
||||
$order_inquiry_case['smoke_status'] = null;
|
||||
$order_inquiry_case['chemical_compound_status'] = null;
|
||||
$order_inquiry_case['chemical_compound_describe'] = "";
|
||||
$order_inquiry_case['is_operation'] = null;
|
||||
$order_inquiry_case['operation'] = "";
|
||||
}else{
|
||||
} else {
|
||||
$order_inquiry_case['drink_wine_status'] = $patient_family_personal['drink_wine_status'];
|
||||
$order_inquiry_case['smoke_status'] = $patient_family_personal['smoke_status'];
|
||||
$order_inquiry_case['chemical_compound_status'] = $patient_family_personal['chemical_compound_status'];
|
||||
@ -481,17 +481,17 @@ class InquiryService extends BaseService
|
||||
|
||||
// 检测项目
|
||||
$order_inquiry_case['detection_project'] = null;
|
||||
if ($order_inquiry['inquiry_type'] == 5){
|
||||
if ($order_inquiry['inquiry_type'] == 5) {
|
||||
// 获取检测订单
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (!empty($order_detection)){
|
||||
if (!empty($order_detection)) {
|
||||
// 获取检测项目
|
||||
$params = array();
|
||||
$params['detection_project_id'] = $order_detection['detection_project_id'];
|
||||
$detection_project = DetectionProject::getOne($params);
|
||||
if (!empty($detection_project)){
|
||||
if (!empty($detection_project)) {
|
||||
$order_inquiry_case['detection_project']['detection_project_name'] = $detection_project['detection_project_name']; // 检测项目名称
|
||||
$order_inquiry_case['detection_project']['detection_time'] = $order_detection['detection_time']; // 检测时间
|
||||
$order_inquiry_case['detection_project']['detection_link'] = addAliyunOssWebsite($order_detection['detection_result_pdf']); // 检测结果链接
|
||||
@ -605,7 +605,7 @@ class InquiryService extends BaseService
|
||||
$data['doctor_id'] = $doctor_id;
|
||||
$data['patient_id'] = $user_info['client_user_id'];
|
||||
$data['order_inquiry_id'] = $order_inquiry_id;
|
||||
$data['name_mask'] = Mask::maskNameStr($order_inquiry['patient_name'],2);
|
||||
$data['name_mask'] = Mask::maskNameStr($order_inquiry['patient_name'], 2);
|
||||
$data['reply_quality'] = $reply_quality;
|
||||
$data['service_attitude'] = $service_attitude;
|
||||
$data['reply_progress'] = $reply_progress;
|
||||
@ -721,7 +721,7 @@ class InquiryService extends BaseService
|
||||
$result['quick_inquiry_price'] = $quick_inquiry_price;
|
||||
$result['medicine_inquiry_price'] = $medicine_inquiry_price;
|
||||
$result['expert_inquiry_price'] = $expert_inquiry_price ?: 0;
|
||||
$result['welfare_inquiry_price'] = $welfare_inquiry_price ?: 0 ;
|
||||
$result['welfare_inquiry_price'] = $welfare_inquiry_price ?: 0;
|
||||
|
||||
return success($result);
|
||||
}
|
||||
@ -739,17 +739,17 @@ class InquiryService extends BaseService
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单错误");
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单错误");
|
||||
}
|
||||
|
||||
if ($user_info['user_type'] == 1){
|
||||
if ($order_inquiry['patient_id'] != $user_info['client_user_id']){
|
||||
if ($user_info['user_type'] == 1) {
|
||||
if ($order_inquiry['patient_id'] != $user_info['client_user_id']) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if ($user_info['user_type'] == 2){
|
||||
if ($order_inquiry['doctor_id'] != $user_info['client_user_id']){
|
||||
if ($user_info['user_type'] == 2) {
|
||||
if ($order_inquiry['doctor_id'] != $user_info['client_user_id']) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
@ -771,12 +771,12 @@ class InquiryService extends BaseService
|
||||
$params['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||||
$params['inquiry_mode'] = $order_inquiry['inquiry_mode'];
|
||||
$system_inquiry_config = SystemInquiryConfig::getOne($params);
|
||||
if (!empty($system_inquiry_config)){
|
||||
if (!empty($system_inquiry_config)) {
|
||||
$times_number = $system_inquiry_config['times_number'];
|
||||
$duration = $system_inquiry_config['duration'];
|
||||
}
|
||||
|
||||
if ($user_info['user_type'] == 1){
|
||||
if ($user_info['user_type'] == 1) {
|
||||
// 关注状态
|
||||
$params = array();
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
@ -825,7 +825,7 @@ class InquiryService extends BaseService
|
||||
$params = array();
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
|
||||
$inquiry_status_params = ["5","6"];
|
||||
$inquiry_status_params = ["5", "6"];
|
||||
|
||||
$fields = [
|
||||
'order_inquiry_id',
|
||||
@ -849,10 +849,10 @@ class InquiryService extends BaseService
|
||||
'created_at',
|
||||
];
|
||||
|
||||
$result = OrderInquiry::getInquiryStatusWithDoctorPage($params,$inquiry_status_params,$fields,$page,$per_page);
|
||||
$result = OrderInquiry::getInquiryStatusWithDoctorPage($params, $inquiry_status_params, $fields, $page, $per_page);
|
||||
|
||||
if (!empty($result['data'])){
|
||||
foreach ($result['data'] as &$item){
|
||||
if (!empty($result['data'])) {
|
||||
foreach ($result['data'] as &$item) {
|
||||
$params = array();
|
||||
$params['message_send_result'] = 1;
|
||||
$params['order_inquiry_id'] = $item['order_inquiry_id'];
|
||||
@ -873,7 +873,7 @@ class InquiryService extends BaseService
|
||||
|
||||
$order_inquiry_id = $this->request->route('order_inquiry_id');
|
||||
|
||||
if (empty($user_info)){
|
||||
if (empty($user_info)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "操作失败");
|
||||
}
|
||||
// 获取问诊订单数据
|
||||
@ -886,7 +886,7 @@ class InquiryService extends BaseService
|
||||
|
||||
$order_inquiry = $order_inquiry->toArray();
|
||||
|
||||
if ($order_inquiry['doctor_id'] != $user_info['client_user_id'] && $order_inquiry['patient_id'] != $user_info['client_user_id']){
|
||||
if ($order_inquiry['doctor_id'] != $user_info['client_user_id'] && $order_inquiry['patient_id'] != $user_info['client_user_id']) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "操作失败");
|
||||
}
|
||||
|
||||
@ -896,13 +896,13 @@ class InquiryService extends BaseService
|
||||
}
|
||||
|
||||
// 订单退款状态
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'],[0,4,5])){
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'], [0, 4, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单正在退款,无法结束");
|
||||
}
|
||||
|
||||
// 订单支付状态
|
||||
if ($order_inquiry['inquiry_pay_status'] != 2){
|
||||
if ($order_inquiry['inquiry_pay_status'] != 2) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单未支付,无法结束");
|
||||
}
|
||||
|
||||
@ -910,7 +910,7 @@ class InquiryService extends BaseService
|
||||
$params = array();
|
||||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)){
|
||||
if (empty($user_doctor)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "操作失败");
|
||||
}
|
||||
|
||||
@ -920,24 +920,24 @@ class InquiryService extends BaseService
|
||||
// 修改问诊订单表
|
||||
$data = array();
|
||||
$data['inquiry_status'] = 5;// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$data['complete_time'] = date('Y-m-d H:i:s',time());// 订单完成时间(问诊完成时间)
|
||||
$data['complete_time'] = date('Y-m-d H:i:s', time());// 订单完成时间(问诊完成时间)
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
OrderInquiry::edit($params,$data);
|
||||
OrderInquiry::edit($params, $data);
|
||||
|
||||
// 新增患者历史问诊表-问诊完成后添加
|
||||
$data = array();
|
||||
$data['patient_id'] = $order_inquiry['patient_id'];
|
||||
$data['doctor_id'] = $order_inquiry['doctor_id'];
|
||||
if (!empty($order_inquiry['pharmacist_id'])){
|
||||
if (!empty($order_inquiry['pharmacist_id'])) {
|
||||
$data['pharmacist_id'] = $order_inquiry['pharmacist_id'];
|
||||
}
|
||||
|
||||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$data['history_status'] = 1;
|
||||
$patient_history_inquiry = PatientHistoryInquiry::addPatientHistoryInquiry($data);
|
||||
if (empty($patient_history_inquiry)){
|
||||
if (empty($patient_history_inquiry)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "添加患者历史问诊表失败");
|
||||
}
|
||||
@ -964,20 +964,20 @@ class InquiryService extends BaseService
|
||||
try {
|
||||
// 发送IM消息-问诊已完成
|
||||
$imService = new ImService();
|
||||
$imService->inquiryComplete($order_inquiry,$user_doctor['user_id'],$order_inquiry['user_id']);
|
||||
$imService->inquiryComplete($order_inquiry, $user_doctor['user_id'], $order_inquiry['user_id']);
|
||||
|
||||
// 发送IM消息-问诊结束评价通知
|
||||
$imService->inquiryEndEvaluation($order_inquiry,$user_doctor['user_id'],$order_inquiry['user_id']);
|
||||
$imService->inquiryEndEvaluation($order_inquiry, $user_doctor['user_id'], $order_inquiry['user_id']);
|
||||
|
||||
// 医生-发送通知消息-问诊结束
|
||||
$MessagePush = new MessagePush($user_doctor['user_id'],$order_inquiry['order_inquiry_id']);
|
||||
$MessagePush = new MessagePush($user_doctor['user_id'], $order_inquiry['order_inquiry_id']);
|
||||
$MessagePush->finishInquiryToDoctor();
|
||||
|
||||
// 患者-发送通知消息-患者的问诊服务结束
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id'],$order_inquiry['order_inquiry_id']);
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id'], $order_inquiry['order_inquiry_id']);
|
||||
$MessagePush->patientInquiryFinish();
|
||||
}catch(\Exception $e){
|
||||
return success([],HttpEnumCode::HTTP_SUCCESS,"消息发送失败");
|
||||
} catch (\Exception $e) {
|
||||
return success([], HttpEnumCode::HTTP_SUCCESS, "消息发送失败");
|
||||
}
|
||||
|
||||
return success();
|
||||
@ -1079,7 +1079,7 @@ class InquiryService extends BaseService
|
||||
$params['inquiry_status'] = 6; // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
|
||||
$order_inquiry = OrderInquiry::getList($params);
|
||||
if (empty($order_inquiry)){
|
||||
if (empty($order_inquiry)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -1141,7 +1141,7 @@ class InquiryService extends BaseService
|
||||
$inquiry_refund_no = $generator->generate();
|
||||
|
||||
// 检测订单金额
|
||||
if ($order_inquiry['payment_amount_total'] > 0){
|
||||
if ($order_inquiry['payment_amount_total'] > 0) {
|
||||
// 发起退款
|
||||
$WechatPay = new WechatPay(1, 1);
|
||||
|
||||
@ -1179,7 +1179,7 @@ class InquiryService extends BaseService
|
||||
|
||||
$refund_id = $result['refund_id'];
|
||||
|
||||
}else{
|
||||
} else {
|
||||
// 模拟退款
|
||||
$inquiry_refund_status = 3;
|
||||
$refund_id = "模拟退款:" . $generator->generate();
|
||||
@ -1286,7 +1286,7 @@ class InquiryService extends BaseService
|
||||
// 取消问诊订单
|
||||
$data = array();
|
||||
$data['inquiry_status'] = 7;
|
||||
if ($cancel_reason == 5){
|
||||
if ($cancel_reason == 5) {
|
||||
$data['inquiry_pay_status'] = 5; // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
}
|
||||
|
||||
@ -1308,7 +1308,7 @@ class InquiryService extends BaseService
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_inquiry_coupon = OrderInquiryCoupon::getOne($params);
|
||||
if (!empty($order_inquiry_coupon)){
|
||||
if (!empty($order_inquiry_coupon)) {
|
||||
// 发送站内消息-优惠卷退还
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id'], $order_inquiry['order_inquiry_id']);
|
||||
$MessagePush->patientRefundCoupon($order_inquiry_coupon['coupon_name']);
|
||||
@ -1319,7 +1319,7 @@ class InquiryService extends BaseService
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测当前医生是否和患者存在未完成问诊订单
|
||||
* 检测当前医生是否和患者进行中的问诊订单
|
||||
* @param string $patient_id
|
||||
* @param string $doctor_id
|
||||
* @return array
|
||||
@ -1362,8 +1362,8 @@ class InquiryService extends BaseService
|
||||
|
||||
$redis_key = "inquiryRefund" . $order_inquiry_id;
|
||||
$redis_value = $redis->get($redis_key);
|
||||
if(empty($redis_value)){
|
||||
$redis->set($redis_key, 1,60 * 60 * 24 * 5);
|
||||
if (empty($redis_value)) {
|
||||
$redis->set($redis_key, 1, 60 * 60 * 24 * 5);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1391,14 +1391,14 @@ class InquiryService extends BaseService
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function returnInquiryCoupon(string $order_inquiry_id,string $patient_user_id): bool
|
||||
public function returnInquiryCoupon(string $order_inquiry_id, string $patient_user_id): bool
|
||||
{
|
||||
try {
|
||||
// 获取用户优惠卷信息
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$order_inquiry_coupon = OrderInquiryCoupon::getOne($params);
|
||||
if (empty($order_inquiry_coupon)){
|
||||
if (empty($order_inquiry_coupon)) {
|
||||
// 订单未使用优惠卷,无需退还
|
||||
return true;
|
||||
}
|
||||
@ -1407,7 +1407,7 @@ class InquiryService extends BaseService
|
||||
$params = array();
|
||||
$params['user_coupon_id'] = $order_inquiry_coupon['user_coupon_id'];
|
||||
$user_coupon = UserCoupon::getOne($params);
|
||||
if (empty($user_coupon)){
|
||||
if (empty($user_coupon)) {
|
||||
// 无该优惠卷数据,无需处理
|
||||
return true;
|
||||
}
|
||||
@ -1416,10 +1416,10 @@ class InquiryService extends BaseService
|
||||
$data = array();
|
||||
|
||||
// 检测优惠卷过期时间。判断是否需要退还
|
||||
if (strtotime($user_coupon['valid_end_time']) <= time()){
|
||||
if (strtotime($user_coupon['valid_end_time']) <= time()) {
|
||||
// 超出过期时间,置为已过期
|
||||
$data['user_coupon_status'] = 3;
|
||||
}else{
|
||||
} else {
|
||||
$data['user_coupon_status'] = 0;
|
||||
$data['coupon_use_date'] = null;
|
||||
}
|
||||
@ -1429,7 +1429,7 @@ class InquiryService extends BaseService
|
||||
UserCoupon::edit($params, $data);
|
||||
|
||||
return true;
|
||||
} catch(\Exception $e){
|
||||
} catch (\Exception $e) {
|
||||
Log::getInstance()->error("退还用户优惠卷失败" . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
@ -1447,7 +1447,7 @@ class InquiryService extends BaseService
|
||||
$params['inquiry_type'] = $inquiry_type;
|
||||
$params['inquiry_mode'] = 1;
|
||||
$system_inquiry_config = SystemInquiryConfig::getOne($params);
|
||||
if (empty($system_inquiry_config)){
|
||||
if (empty($system_inquiry_config)) {
|
||||
throw new BusinessException("系统问诊配置错误");
|
||||
}
|
||||
|
||||
@ -1455,16 +1455,16 @@ class InquiryService extends BaseService
|
||||
$params = array();
|
||||
$params['system_inquiry_config_id'] = $system_inquiry_config['system_inquiry_config_id'];
|
||||
$system_inquiry_time = SystemInquiryTime::getList($params);
|
||||
if (empty($system_inquiry_time)){
|
||||
if (empty($system_inquiry_time)) {
|
||||
throw new BusinessException("系统问诊时间配置错误");
|
||||
}
|
||||
|
||||
// 检测当前是否坐班时间
|
||||
$is_time_pass = false; // 非坐班时间
|
||||
|
||||
foreach ($system_inquiry_time as $item){
|
||||
$now_time = date('H',time()) . date('i',time());
|
||||
if ($item['start_time'] < $now_time && $item['end_time'] > $now_time){
|
||||
foreach ($system_inquiry_time as $item) {
|
||||
$now_time = date('H', time()) . date('i', time());
|
||||
if ($item['start_time'] < $now_time && $item['end_time'] > $now_time) {
|
||||
// 符合当前时间区间
|
||||
$is_time_pass = true;
|
||||
}
|
||||
@ -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