新增对接检测所,新增医生短信推送

This commit is contained in:
wucongxing 2023-08-15 15:23:24 +08:00
parent a13b55d90b
commit 19ae7e6bff
9 changed files with 416 additions and 27 deletions

View File

@ -7,6 +7,7 @@ use App\Amqp\Producer\AutoCompleteInquiryDelayDirectProducer;
use App\Constants\DoctorTitleCode;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Model\BasicDetectionOrgan;
use App\Model\BasicLogisticsCompany;
use App\Model\DetectionProject;
use App\Model\Hospital;
@ -35,6 +36,7 @@ use App\Services\InquiryService;
use App\Services\MessagePush;
use App\Services\OrderPrescriptionService;
use App\Utils\Log;
use Extend\Alibaba\Oss;
use Extend\TencentIm\Account;
use Extend\TencentIm\Message;
use Extend\TencentIm\Profile;
@ -1328,12 +1330,54 @@ class CallBackController extends AbstractController
public function DetectionResultCallBack(): ResponseInterface
{
$request_params = $this->request->all();
$auth = $this->request->getHeader("Authorization");
if (empty($auth)){
return $this->detectionResultFailReturn("非法请求");
}
try {
Log::getInstance("detectionResult")->info(json_encode($request_params, JSON_UNESCAPED_UNICODE));
// 检测参数
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('Y-m-d');
// $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("文件错误");
}
Log::getInstance("CallBackController-DetectionResultCallBack")->info(json_encode($request_params, JSON_UNESCAPED_UNICODE));
// 获取检测订单数据
$params = array();
$params['detection_no'] = "D549534850211602432";
$params['detection_no'] = $request_params['orderCode'];
$order_detection = OrderDetection::getOne($params);
if (empty($order_detection)){
return $this->detectionResultFailReturn("非法订单");
@ -1344,6 +1388,14 @@ class CallBackController extends AbstractController
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("检测条码无法对应");
// }
// 获取医生数据
$params = array();
$params['doctor_id'] = $order_detection['doctor_id'];
@ -1377,6 +1429,12 @@ class CallBackController extends AbstractController
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 {
@ -1431,10 +1489,11 @@ class CallBackController extends AbstractController
return $this->detectionResultFailReturn("问诊订单病例创建失败");
}
// 修改检测状态
// 修改检测订单
$data = array();
$data['detection_status'] = 4;
$data['detection_time'] = date('Y-m-d H:i:s',time());
$data['detection_result_pdf'] = $detection_result_pdf;
$data['detection_result_date'] = date('Y-m-d H:i:s',time());
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];// 订单-问诊id
$params = array();
@ -1494,7 +1553,9 @@ class CallBackController extends AbstractController
$MessagePush = new MessagePush($order_detection['user_id']);
$MessagePush->patientDetectionResultNotice($order_detection['order_detection_id']);
// 医生-发送检测报告短信
// 医生-通知医生患者检测报告已生成
$MessagePush = new MessagePush($user_doctor['user_id']);
$MessagePush->doctorDetectionResultNotice($order_detection['order_detection_id']);
}catch (\Throwable $e){
Log::getInstance("detectionResult")->error($e->getMessage());
}
@ -1518,9 +1579,8 @@ class CallBackController extends AbstractController
new SwooleStream(
strval(
json_encode([
'result' => false,
'returnCode' => "500",
'message' => $message,
'code' => 0,
'msg' => $message,
], JSON_UNESCAPED_UNICODE)
)
)
@ -1540,9 +1600,8 @@ class CallBackController extends AbstractController
new SwooleStream(
strval(
json_encode([
'result' => true,
'returnCode' => "200",
'message' => $message,
'code' => 1,
'msg' => $message,
], JSON_UNESCAPED_UNICODE)
)
)

View File

@ -39,7 +39,9 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property int $patient_age 患者年龄-就诊人
* @property string $detection_bar_code 检测条码
* @property string $detection_pic 检测管图片(逗号分隔)
* @property string $detection_time 检测时间
* @property string $detection_time 上传检测时间
* @property string $detection_result_pdf 检测结果
* @property string $detection_result_date 检测结果时间
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
*/
@ -55,7 +57,7 @@ class OrderDetection extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['order_detection_id', 'user_id', 'patient_id', 'doctor_id', 'family_id', 'detection_project_id', 'purpose_id', 'detection_organ_id', 'order_inquiry_id', 'detection_status', 'is_delete', 'detection_refund_status', 'detection_pay_channel', 'detection_pay_status', 'detection_no', 'escrow_trade_no', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'pay_time', 'cancel_time', 'cancel_reason', 'cancel_remarks', 'patient_name', 'patient_name_mask', 'patient_sex', 'patient_age', 'detection_bar_code', 'detection_pic', 'detection_time', 'created_at', 'updated_at'];
protected array $fillable = ['order_detection_id', 'user_id', 'patient_id', 'doctor_id', 'family_id', 'detection_project_id', 'purpose_id', 'detection_organ_id', 'order_inquiry_id', 'detection_status', 'is_delete', 'detection_refund_status', 'detection_pay_channel', 'detection_pay_status', 'detection_no', 'escrow_trade_no', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'pay_time', 'cancel_time', 'cancel_reason', 'cancel_remarks', 'patient_name', 'patient_name_mask', 'patient_sex', 'patient_age', 'detection_bar_code', 'detection_pic', 'detection_time', 'detection_result_pdf', 'detection_result_date', 'created_at', 'updated_at'];
protected string $primaryKey = "order_detection_id";

View File

@ -20,6 +20,7 @@ use App\Model\UserDoctor;
use App\Model\UserLocation;
use App\Utils\Log;
use App\Utils\PcreMatch;
use Extend\Detection\Wy;
use Extend\Wechat\WechatPay;
use Hyperf\Amqp\Producer;
use Hyperf\DbConnection\Db;
@ -537,16 +538,27 @@ class DetectionService extends BaseService
$detection_pic = PcreMatch::pregRemoveOssWebsite($detection_pic);
}
// 获取检测所
// 检测检测管编码是否已被使用
$params = array();
$params['detection_bar_code'] = $request_params['detection_bar_code'];
$result = OrderDetection::getOne($params);
if (!empty($result)){
return fail(HttpEnumCode::HTTP_ERROR,"检测管已被使用");
}
Db::beginTransaction();
try {
// 上报数据
$wy = new Wy($order_detection['detection_organ_id']);
$wy->report($order_detection);
// 修改检测订单
$data = array();
$data['detection_pic'] = $detection_pic ?? "";
$data['detection_bar_code'] = $request_params['detection_bar_code'];
$data['detection_status'] = 3;
$data['detection_organ_id'] = 1;// 检测机构id
$data['detection_time'] = date('Y-m-d H:i:s', time());// 上传检测时间
$params = array();
$params['order_detection_id'] = $order_detection_id;
@ -556,12 +568,11 @@ class DetectionService extends BaseService
return fail(HttpEnumCode::HTTP_ERROR,"绑定失败");
}
// 上报数据
Db::commit();
}catch (\Exception $e){
}catch (\Throwable $e){
Db::rollBack();
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
Log::getInstance("DetectionService-bindDetectionTube")->error($e->getMessage());
return fail(HttpEnumCode::HTTP_ERROR, "绑定失败");
}
return success();

View File

@ -729,7 +729,7 @@ class ImService extends BaseService
$cloud_custom_data['patient_family_data']['patient_age'] = $order_detection['patient_age'];
$message_content = [
'Text' => $doctor_name . "医生您好,我在您那里开具的【" . $detection_project_name . "服务,报告单已出,请您查看报告并详细的做一下解读,谢谢医生",
'Text' => $doctor_name . "医生您好,您给我开具的【" . $detection_project_name . "检测项目报告已经出来啦,请您抽空查看报告并做一下解读,谢谢",
];
$this->sendMessage($patient_user_id,$doctor_user_id, $message_content, "TIMTextElem", $cloud_custom_data);

View File

@ -2338,7 +2338,7 @@ class MessagePush extends BaseService
// 短信
$sms_data = array();
$sms_data['template_code'] = "SMS_462035956";
$sms_data['scene_desc'] = "您的{$detection_project['detection_project_name']}报告单已出请联系医生做报告解读。平台已赠送您和医生5个沟通回合请珍惜沟通机会请前往肝胆相照互联网医院微信小程序“个人中心”-“检测订单”-“订单详情”查看报告。";
$sms_data['scene_desc'] = "新报告生成通知";
$sms_data['phone'] = $this->user['mobile'];
$sms_data['user_id'] = $this->user['user_id'];
@ -2360,4 +2360,52 @@ class MessagePush extends BaseService
Log::getInstance("MessagePush-patientDetectionResultNotice")->error($e->getMessage());
}
}
/**
* 医生-通知医生患者检测报告已生成
* 短信
* @param string $order_detection_id
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function doctorDetectionResultNotice(string $order_detection_id): void
{
// 获取检测订单
$params = array();
$params['order_detection_id'] = $order_detection_id;
$order_detection = OrderDetection::getOne($params);
if (empty($order_detection)) {
Log::getInstance("MessagePush-patientDetectionResultNotice")->error("无检测订单数据");
return;
}
// 获取检测项目
$params = array();
$params['detection_project_id'] = $order_detection['detection_project_id'];
$detection_project = DetectionProject::getOne($params);
if (empty($detection_project)) {
Log::getInstance("MessagePush-patientDetectionResultNotice")->error("检测项目错误");
return;
}
// 获取系统接诊配置
$data = array();
$data['template_code'] = "SMS_461980700";
$data['scene_desc'] = "通知医生患者检测报告已生成";
$data['phone'] = $this->user['mobile'];
$data['user_id'] = $this->user['user_id'];
$template_param = array();
$template_param['name'] = $order_detection['patient_name'];
$template_param['report'] = $detection_project['detection_project_name'];
$data['template_param'] = $template_param;
$message = new SendSmsMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
throw new BusinessException("加入推送队列失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
}
}

View File

@ -28,17 +28,17 @@ class Auth
"/callback/wxpay/inquiry/refund" => "post", // 微信问诊退款回调
"/callback/wxpay/product/success" => "post", // 微信药品支付回调
"/callback/wxpay/product/refund" => "post", // 微信药品退款回调
"/callback/wxpay/detection/success" => "post", // 微信药品支付回调
"/callback/wxpay/detection/refund" => "post", // 微信药品退款回调
"/callback/wxpay/detection/success" => "post", // 微信检测订单支付回调
"/callback/wxpay/detection/refund" => "post", // 微信检测订单退款回调
"/callback/im" => "post", // im回调
"/callback/platform/logistics" => "post", // 处方平台物流回调
"/callback/logistics" => "post", // 快递100订阅回调
"/popup" => "get", // 获取弹窗数据
"/basic/keyword/search" => "get", // 获取热门搜索关键词
"/test/uninquiry" => "get", // 获取未接诊的医生
"/test/refund" => "get", // 测试退款
"/test" => "get", // 测试
"/callback/detection" => "post", // 检测所结果回调
];
}

View File

@ -110,13 +110,9 @@ class Oss
public function getCusTomObjectToRAM(string $filename,string $style = "image/resize"): string
{
try {
// $download_file = "./runtime/aaa.jpg";
$ossClient = $this->createClient();
$options = array(
OssClient::OSS_PROCESS => $style,
// OssClient::OSS_FILE_DOWNLOAD => $download_file,
);
$object = $filename;

96
extend/Detection/Base.php Normal file
View File

@ -0,0 +1,96 @@
<?php
namespace Extend\Detection;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Model\BasicDetectionOrgan;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Context\ApplicationContext;
use Psr\Container\ContainerInterface;
use \Hyperf\Config\config;
/**
* 对接检测所
*/
class Base
{
#[Inject]
protected ContainerInterface $container;
#[Inject]
protected Client $client;
protected string $app_id;
protected string $secret; // 秘钥
protected string $request_url; // 请求地址
public function __construct(string $detection_organ_id)
{
$this->container = ApplicationContext::getContainer();
$this->client = $this->container->get(Client::class);
// 获取检测机构数据
$params = array();
$params['detection_organ_id'] = $detection_organ_id;
$basic_detection_organ = BasicDetectionOrgan::getOne($params);
if (!empty($basic_detection_organ)){
if (!empty($basic_detection_organ['app_id'])){
$this->app_id = $basic_detection_organ['app_id'];
}
if (!empty($basic_detection_organ['app_secret'])){
$this->secret = $basic_detection_organ['app_secret'];
}
$app_env = config("app_env","dev");
if ($app_env == "dev"){
if (!empty($basic_detection_organ['request_dev_url'])){
$this->request_url = $basic_detection_organ['request_dev_url'];
}
}else{
if (!empty($basic_detection_organ['request_prod_url'])){
$this->request_url = $basic_detection_organ['request_prod_url'];
}
}
}
}
/**
* 请求封装
* @param string $sign
* @param array $arg 请求参数
* @return array
* @throws GuzzleException
*/
protected function httpRequest(string $sign,array $arg = []): array
{
$option = [
"headers" => [
"source" => $sign
]
];
if (!empty($option)){
$arg = array_merge($arg,$option);
}
$response = $this->client->post($this->request_url, $arg);
if ($response->getStatusCode() != '200'){
// 请求失败
throw new BusinessException($response->getBody()->getContents());
}
$body = json_decode($response->getBody(),true);
if (empty($body)){
// 返回值为空
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
}
return $body;
}
}

177
extend/Detection/Wy.php Normal file
View File

@ -0,0 +1,177 @@
<?php
namespace Extend\Detection;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Model\DetectionProject;
use App\Model\DetectionProjectPurpose;
use App\Model\Hospital;
use App\Model\OrderDetectionCase;
use App\Model\PatientFamily;
use App\Model\UserDoctor;
use App\Model\UserLocation;
use App\Utils\Log;
use Extend\Alibaba\Oss;
use GuzzleHttp\Exception\GuzzleException;
/**
* 微远检测所
*/
class Wy extends Base
{
/**
* 获取签名
* @return string
*/
public function getSign(): string
{
if (empty($this->app_id) || empty($this->secret) || empty($this->request_url)){
throw new BusinessException("缺少签名数据");
}
$time = date('Y-m-d');
return md5($this->app_id . $this->secret . $time);
}
/**
* 上报数据
* @param array|object $order_detection
*/
public function report(array|object $order_detection)
{
// 获取检测订单病例数据
$params = array();
$params['order_detection_id'] = $order_detection['order_detection_id'];
$order_detection_case = OrderDetectionCase::getOne($params);
if (empty($order_detection_case)){
throw new BusinessException("病例数据错误");
}
// 获取家庭成员数据
$params = array();
$params['family_id'] = $order_detection['family_id'];
$patient_family = PatientFamily::getOne($params);
if (empty($patient_family)){
throw new BusinessException("患者家庭成员数据错误");
}
// 获取患者地址
$params = array();
$params['user_id'] = $order_detection['user_id'];
$user_location = UserLocation::getOne($params);
if (!empty($user_location)){
$address = $user_location['province'] . $user_location['city'] . $user_location['county'] . $user_location['address'];
}
// 获取医生数据
$params = array();
$params['doctor_id'] = $order_detection['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)){
throw new BusinessException("医生数据错误");
}
// 获取医院数据
$params = array();
$params['hospital_id'] = $user_doctor['hospital_id'];
$hospital = Hospital::getOne($params);
if (empty($hospital)){
throw new BusinessException("医院数据错误");
}
// 获取检测项目数据
$params = array();
$params['detection_project_id'] = $order_detection['detection_project_id'];
$detection_project = DetectionProject::getOne($params);
if (empty($detection_project)){
throw new BusinessException("检测数据错误");
}
// 获取检测用途数据
$params = array();
$params['purpose_id'] = $order_detection['purpose_id'];
$detection_project_purpose = DetectionProjectPurpose::getOne($params);
if (empty($detection_project_purpose)){
throw new BusinessException("检测数据错误");
}
// 处理检测管图片
$oss = new Oss();
$pics = [];
$detection_pics = explode(',',$order_detection['detection_pic']);
foreach ($detection_pics as $key => $value){
// 去除用户签名图片第一个/ oss不识别
$value = substr($value, 1, strlen($value) - 1);
$pic = $oss->getObjectToRAM($value);
if (empty($pic)){
throw new BusinessException("检测管图片错误");
}
$pic = base64_encode($pic);
if (!$pic) {
throw new BusinessException("检测管图片下载失败");
}
$pics[$key]['pictureNo'] = $key + 1; // 图片序号
$pics[$key]['pictureName'] = "检测管图片"; // 图片名称
$pics[$key]['pictureInfo'] = $pic; // 对图片进行base64后的编码
}
// 获取签名
$sign = $this->getSign();
$arg = array();
$arg['appId'] = $this->app_id;
$arg['orderCode'] = $order_detection['detection_no']; // 订单编号
$arg['orderTime'] = date('Y-m-d H:i:s',strtotime($order_detection['created_at'])); // 订单时间
$arg['userPatientRelationships'] = $patient_family['relation']; // 操作用户与患者关系1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他
$arg['patientName'] = $order_detection['patient_name']; // 患者姓名
$arg['patientSex'] = $order_detection['patient_sex']; // 患者性别(0未知 1男 2女)
$arg['patientNationality'] = $order_detection_case['nation_name']; // 患者民族
$arg['patientPastMedicalHistory'] = $order_detection_case['detection_disease_class_names']; // 患者既往病史
$arg['patientCardNo'] = $patient_family['id_number']; // 患者身份证号
$arg['patientPhone'] = $patient_family['mobile']; // 患者手机号
$arg['patientAddress'] = $address ?? ""; // 患者住址(非必填)
$arg['detectBarCode'] = $order_detection['detection_bar_code']; // 检测条形码
$arg['pictureOfDetectionTube'] = $pics; // 检测管图片数组
$arg['hospitalName'] = $hospital['hospital_name']; // 医院名称(送检单位)
$arg['doctorName'] = $user_doctor['user_name']; // 医生名称
$arg['projectName'] = $detection_project['detection_project_name']; // 检测项目名称
$arg['projectPurpose'] = $detection_project_purpose['purpose_name']; // 检测项目用途名称
$arg['payTime'] = $order_detection['pay_time']; // 支付时间
$arg['payAmount'] = $order_detection['payment_amount_total']; // 支付金额
$arg['reportUrl'] = $this->request_url; // 推送报告的回调地址
$option = [
"json" => $arg
];
try {
$response = $this->httpRequest($sign,$option);
if (empty($response)){
// 返回值错误为空
throw new BusinessException("");
}
if (!isset($response['code'])){
throw new BusinessException("上报数据返回值错误");
}
if ($response['code'] != 1){
if (!isset($response['msg'])){
throw new BusinessException("上报数据返回值错误");
}
if (empty($response['msg'])){
throw new BusinessException("上报数据返回值错误");
}
throw new BusinessException($response['msg']);
}
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
}
}
}