diff --git a/app/Controller/CallBackController.php b/app/Controller/CallBackController.php index 5e3c80f..986d9dd 100644 --- a/app/Controller/CallBackController.php +++ b/app/Controller/CallBackController.php @@ -1354,18 +1354,18 @@ class CallBackController extends AbstractController } // 检测签名 -// $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("签名错误"); -// } + $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']); @@ -1392,9 +1392,9 @@ class CallBackController extends AbstractController return $this->detectionResultSuccessReturn(); } -// if ($order_detection['detection_bar_code'] != $request_params['detectBarcode']){ -// return $this->detectionResultFailReturn("检测条码无法对应"); -// } + if ($order_detection['detection_bar_code'] != $request_params['detectBarcode']){ + return $this->detectionResultFailReturn("检测条码无法对应"); + } // 获取医生数据 $params = array(); diff --git a/app/Services/DetectionService.php b/app/Services/DetectionService.php index 6f78ae5..6fd2aff 100644 --- a/app/Services/DetectionService.php +++ b/app/Services/DetectionService.php @@ -7,6 +7,7 @@ use App\Constants\HttpEnumCode; use App\Exception\BusinessException; use App\Model\Area; use App\Model\BasicCompany; +use App\Model\BasicDetectionOrgan; use App\Model\BasicNation; use App\Model\DetectionProject; use App\Model\DetectionProjectPurpose; @@ -537,6 +538,10 @@ class DetectionService extends BaseService $detection_pic = PcreMatch::pregRemoveOssWebsite($detection_pic); } + if (!isset($detection_pic)){ + return fail(HttpEnumCode::HTTP_ERROR,"上传图片失败"); + } + // 检测检测管编码是否已被使用 $params = array(); $params['detection_bar_code'] = $request_params['detection_bar_code']; @@ -545,21 +550,28 @@ class DetectionService extends BaseService return fail(HttpEnumCode::HTTP_ERROR,"检测管已被使用"); } - // 计算检测机构 - $detection_organ_id = 1; + // 获取检测码对应的检测所 + $detection_organ_code = substr($request_params['detection_bar_code'], 3, 1); + if (!$detection_organ_code){ + return fail(HttpEnumCode::HTTP_ERROR,"检测码错误"); + } + + // 获取检测所数据 + $params = array(); + $params['detection_organ_code'] = $detection_organ_code; + $basic_detection_organ = BasicDetectionOrgan::getOne($params); + if (empty($basic_detection_organ)){ + return fail(HttpEnumCode::HTTP_ERROR,"检测码错误"); + } Db::beginTransaction(); try { - // 上报数据 - $wy = new Wy($detection_organ_id); - $wy->report($order_detection); - // 修改检测订单 $data = array(); - $data['detection_pic'] = $detection_pic ?? ""; + $data['detection_pic'] = $detection_pic; $data['detection_bar_code'] = $request_params['detection_bar_code']; $data['detection_status'] = 3; - $data['detection_organ_id'] = $detection_organ_id;// 检测机构id + $data['detection_organ_id'] = $basic_detection_organ['detection_organ_id'];// 检测机构id $data['detection_time'] = date('Y-m-d H:i:s', time());// 上传检测时间 $params = array(); @@ -570,11 +582,15 @@ class DetectionService extends BaseService return fail(HttpEnumCode::HTTP_ERROR,"绑定失败"); } + // 上报数据 + $wy = new Wy($basic_detection_organ['detection_organ_id']); + $wy->report($order_detection_id); + Db::commit(); }catch (\Throwable $e){ Db::rollBack(); Log::getInstance("DetectionService-bindDetectionTube")->error($e->getMessage()); - return fail(HttpEnumCode::HTTP_ERROR, "绑定失败"); + return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage()); } return success(); diff --git a/extend/Detection/Base.php b/extend/Detection/Base.php index c2e5ade..70f417a 100644 --- a/extend/Detection/Base.php +++ b/extend/Detection/Base.php @@ -5,6 +5,7 @@ namespace Extend\Detection; use App\Constants\HttpEnumCode; use App\Exception\BusinessException; use App\Model\BasicDetectionOrgan; +use App\Utils\Log; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; use Hyperf\Di\Annotation\Inject; @@ -78,6 +79,12 @@ class Base $arg = array_merge($arg,$option); } + // 打印使用 + $l = $arg; + unset($l['json']['pictureOfDetectionTube']); + dump($l); + + Log::getInstance("请求参数")->info(json_encode($arg,JSON_UNESCAPED_UNICODE)); $response = $this->client->post($path, $arg); if ($response->getStatusCode() != '200'){ diff --git a/extend/Detection/Wy.php b/extend/Detection/Wy.php index a71febd..7a233cb 100644 --- a/extend/Detection/Wy.php +++ b/extend/Detection/Wy.php @@ -7,8 +7,10 @@ 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; @@ -30,7 +32,7 @@ class Wy extends Base throw new BusinessException("缺少签名数据"); } - $time = date('Y-m-d'); + $time = date('Ymd'); return md5($this->app_id . $this->secret . $time); } @@ -38,8 +40,15 @@ class Wy extends Base * 上报数据 * @param array|object $order_detection */ - public function report(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']; @@ -96,6 +105,14 @@ class Wy extends Base 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(); @@ -138,15 +155,17 @@ class Wy extends Base $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'] = $patient_family['mobile']; // 患者手机号 + $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']; // 支付时间 @@ -160,6 +179,7 @@ class Wy extends Base $path = $this->request_url . "api/sdInternet/v1/externalData/saveOrder"; try { $response = $this->httpRequest($sign,$path,$option); + dump($response); if (empty($response)){ // 返回值错误为空 throw new BusinessException("");