208 lines
8.0 KiB
PHP
208 lines
8.0 KiB
PHP
<?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\OrderDetection;
|
||
use App\Model\OrderDetectionCase;
|
||
use App\Model\PatientFamily;
|
||
use App\Model\User;
|
||
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('Ymd');
|
||
return md5($this->app_id . $this->secret . $time);
|
||
}
|
||
|
||
/**
|
||
* 上报数据
|
||
* @param array|object $order_detection
|
||
*/
|
||
public function report(string $order_detection_id)
|
||
{
|
||
$params = array();
|
||
$params['order_detection_id'] = $order_detection_id;
|
||
$order_detection = OrderDetection::getOne($params);
|
||
if (empty($order_detection)){
|
||
throw new BusinessException("检测订单数据错误");
|
||
}
|
||
|
||
// 获取检测订单病例数据
|
||
$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("检测数据错误");
|
||
}
|
||
|
||
// 获取用户数据
|
||
$params = array();
|
||
$params['user_id'] = $order_detection['user_id'];
|
||
$user = User::getOne($params);
|
||
if (empty($user)){
|
||
throw new BusinessException("用户数据错误");
|
||
}
|
||
|
||
// 处理检测管图片
|
||
$oss = new Oss();
|
||
|
||
$pics = [];
|
||
if (!empty($order_detection['detection_pic'])){
|
||
$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();
|
||
|
||
// 获取回调地址
|
||
$app_env = \Hyperf\Config\config("app_env",'dev');
|
||
if ($app_env == "prod"){
|
||
$callback_url = env('DOMAIN_NAME_PROD','https://prod.hospital.applets.igandanyiyuan.com/');
|
||
}else{
|
||
$callback_url = env('DOMAIN_NAME_DEV','https://dev.hospital.applets.igandanyiyuan.com/');
|
||
}
|
||
|
||
$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['patientAge'] = $order_detection['patient_age']; // 患者年龄
|
||
$arg['patientNationality'] = $order_detection_case['nation_name']; // 患者民族
|
||
$arg['patientPastMedicalHistory'] = $order_detection_case['detection_disease_class_names']; // 患者既往病史
|
||
$arg['patientCardNo'] = $patient_family['id_number']; // 患者身份证号
|
||
$arg['patientPhone'] = $user['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['sendSampleDate'] = date('Y-m-d'); // 送检日期(yyyy-MM-dd)
|
||
$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'] = $callback_url . "callback/detection"; // 推送报告的回调地址
|
||
|
||
$option = [
|
||
"json" => $arg
|
||
];
|
||
|
||
$path = $this->request_url . "api/sdInternet/v1/externalData/saveOrder";
|
||
try {
|
||
$response = $this->httpRequest($sign,$path,$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());
|
||
}
|
||
}
|
||
} |