diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php index 5d4f4b9..0441d54 100644 --- a/app/Controller/TestController.php +++ b/app/Controller/TestController.php @@ -7,6 +7,7 @@ use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer; use App\Constants\HttpEnumCode; use App\Exception\BusinessException; use App\Model\DoctorInquiryTime; +use App\Model\OrderPrescriptionProduct; use App\Model\UserCaCert; use App\Model\OrderInquiry; use App\Model\OrderPrescription; @@ -575,134 +576,30 @@ class TestController extends AbstractController } public function test_11(){ - $oss = new Oss(); - $prescription_pdf = $oss->getObjectToLocal("applet/prescription/500341310934036481.pdf","./runtime/test.pdf"); - dump($prescription_pdf); + $order_prescription_id = ""; + + // 获取处方数据 + $params = array(); + $params['order_prescription_id'] = $order_prescription_id; + $order_prescription = OrderPrescription::getOne($params); + if (empty($order_prescription)) { + throw new BusinessException("处方数据错误"); + } + + // 获取处方关联商品数据 + $params = array(); + $params['order_prescription_id'] = $order_prescription_id; + $order_prescription_product = OrderPrescriptionProduct::getList($params); + if (empty($order_prescription_product)) { + throw new BusinessException("处方药品数据错误"); + } + + + + + $OrderPrescriptionService = new OrderPrescriptionService(); + $result = $OrderPrescriptionService->reportPrescription(); } - // pdf进行签章 - public function test_12(){ - $ca = new Ca(); - - $pdf_file = fopen("./runtime/prescription.pdf",'r'); - - $oss = new Oss(); - - $filename = "basic/file/hospital_signature.png"; - - $style = "image/resize,w_300,h_300"; - - $sign_image = $oss->getCusTomObjectToRAM($filename,$style); - $sign_image = base64_encode($sign_image); - if (!$sign_image){ - return fail(HttpEnumCode::SERVER_ERROR); - } - - $sign_param = [ - [ // 医院签章 - "llx"=>"1550", // 左边底部X坐标 - "lly"=>"1350", // 左边底部Y坐标 - "urx"=>"2250", // 右边上部x坐标 - "ury"=>"650", // 右边上部y坐标 - "pageList"=>[1], - "sealImg"=>$sign_image - ], -// [ // 药师端 -// "llx"=>"350", // 左边底部X坐标 -// "lly"=>"190", // 左边底部Y坐标 -// "urx"=>"440", // 右边上部x坐标 -// "ury"=>"140", // 右边上部y坐标 -// "pageList"=>[1], -// "sealImg"=>$sign_image -// ] - ]; - $data = array(); - $data['sign_param'] = json_encode($sign_param); - $data['pdf_file'] = $pdf_file; - - - $result = $ca->addSignPdf("5345345461",$data); - - $file_id = $result[0]['fileId']; - - $result = $ca->getSignedFile("5345345461",$file_id); - if (empty($result)){ - return fail(); - } - - $file = fopen("./runtime/test.pdf", "w") or die("Unable to open file!"); - fwrite($file, $result); - fclose($file); - - // 上传阿里云oss - -// $oss = new Oss(); -// -// $filename = "applet/doctor/prescription/test.pdf"; -// -// $result = $oss->putObject($filename, $result); -// dump($result); - } - - public function test_13(){ - $oss = new Oss(); - $hospital_sign_image_path = "basic/file/hospital_signature.png"; - - // 下载医院签名图片 - $style = "image/resize,w_300,h_300"; - $sign_image = $oss->getCusTomObjectToRAM($hospital_sign_image_path,$style); - $sign_image = base64_encode($sign_image); - if (!$sign_image){ - throw new BusinessException("医院签名图片下载失败"); - } - - $sign_param = [ - [ // 医院签章 - "llx"=>"370", // 左边底部X坐标 控制左右(越小越左) - "lly"=>"210", // 左边底部Y坐标 控制上下(越小越下) - "urx"=>"520", // 右边上部x坐标 - "ury"=>"360", // 右边上部y坐标 - "pageList"=>[1], - "sealImg"=>$sign_image - ], - ]; - - // 打开处方pdf文件 - unset($pdf_file); - $pdf_file = fopen("./runtime/" . "501402833412673536" . ".pdf",'r'); - - $ca = new Ca(); - - // 处方pdf进行签章 - $data = array(); - $data['sign_param'] = json_encode($sign_param); - $data['pdf_file'] = $pdf_file; - $hospital_sign_pdf_result = $ca->addSignPdf("5345345461",$data); - if (empty($hospital_sign_pdf_result[0]['fileId'])){ - throw new BusinessException("处方签章失败"); - } - - dump($hospital_sign_pdf_result); - - dump("处方pdf进行医院签章成功"); - - - - // 下载处方签章文件 - unset($prescription_pdf_result); - $file_id = $hospital_sign_pdf_result[0]['fileId']; - $prescription_pdf_result = $ca->getSignedFile("5345345461",$file_id); - - if (empty($prescription_pdf_result)){ - throw new BusinessException("下载处方签章文件失败"); - } - - dump("下载医院处方签章文件成功"); - - $file = fopen("./runtime/test.pdf", "w") or die("Unable to open file!"); - fwrite($file, $prescription_pdf_result); - fclose($file); - - } } \ No newline at end of file diff --git a/app/Model/OrderPrescription.php b/app/Model/OrderPrescription.php index 3fd8723..1608064 100644 --- a/app/Model/OrderPrescription.php +++ b/app/Model/OrderPrescription.php @@ -207,7 +207,9 @@ class OrderPrescription extends Model "OrderPrescriptionIcd:prescription_icd_id,order_prescription_id,icd_name", "OrderPrescriptionProduct:prescription_product_id,order_prescription_id,product_name,product_spec" ]) - ->where($params)->paginate($per_page, $fields, "page", $page); + ->where($params) + ->orderBy("created_at",'desc') + ->paginate($per_page, $fields, "page", $page); $data = array(); $data['current_page'] = $raw->currentPage();// 当前页码 diff --git a/app/Services/OrderPrescriptionService.php b/app/Services/OrderPrescriptionService.php index e212cdb..71fb3c2 100644 --- a/app/Services/OrderPrescriptionService.php +++ b/app/Services/OrderPrescriptionService.php @@ -4,6 +4,8 @@ namespace App\Services; use App\Constants\HttpEnumCode; use App\Exception\BusinessException; +use App\Model\PatientFamily; +use App\Model\Product; use App\Model\UserCaCert; use App\Model\HospitalDepartmentCustom; use App\Model\OrderInquiryCase; @@ -14,6 +16,7 @@ use App\Model\OrderProductItem; use App\Model\User; use App\Model\UserDoctor; use App\Model\UserDoctorInfo; +use App\Model\UserPharmacist; use App\Model\UserPharmacistInfo; use Extend\Alibaba\Oss; use Extend\Ca\Ca; @@ -108,7 +111,6 @@ class OrderPrescriptionService extends BaseService return OrderPrescription::getCount($params); } - /** * 开具处方 * 医生-正常开具 @@ -117,35 +119,35 @@ class OrderPrescriptionService extends BaseService * @param string $user_id * @return array */ - public function openPrescription(string $order_prescription_id,string $user_id): array + public function openPrescription(string $order_prescription_id, string $user_id): array { try { // 获取用户数据 $params = array(); $params['user_id'] = $user_id; $user = User::getOne($params); - if (empty($user)){ + if (empty($user)) { throw new BusinessException("用户数据错误"); } - if ($user['user_type'] != 2 && $user['user_type'] != 3){ + if ($user['user_type'] != 2 && $user['user_type'] != 3) { throw new BusinessException("用户类型错误"); } // 获取用户info数据 $params = array(); $params['user_id'] = $user['user_id']; - if ($user['user_type'] == 2){ + if ($user['user_type'] == 2) { $user_doctor_info = UserDoctorInfo::getOne($params); - if (empty($user_doctor_info)){ + if (empty($user_doctor_info)) { throw new BusinessException("用户数据错误"); } $user_sign_image_path = $user_doctor_info['sign_image']; $user_entity_id = "491925054435950592"; - } else{ + } else { $user_pharmacist_info = UserPharmacistInfo::getOne($params); - if (empty($user_pharmacist_info)){ + if (empty($user_pharmacist_info)) { throw new BusinessException("用户数据错误"); } @@ -156,7 +158,7 @@ class OrderPrescriptionService extends BaseService $hospital_entity_id = "5345345461"; } - if (empty($user_sign_image_path) || empty($user_entity_id)){ + if (empty($user_sign_image_path) || empty($user_entity_id)) { throw new BusinessException("无签名图片/用户唯一标识"); } @@ -167,16 +169,16 @@ class OrderPrescriptionService extends BaseService $params = array(); $params['order_prescription_id'] = $order_prescription_id; $order_prescription = OrderPrescription::getOne($params); - if (empty($order_prescription)){ + if (empty($order_prescription)) { throw new BusinessException("处方数据错误"); } - if (empty($order_prescription['doctor_created_time'])){ + if (empty($order_prescription['doctor_created_time'])) { throw new BusinessException("医生开方日期错误"); } // 检测处方图片 - if ($user['user_type'] == 3 && empty($order_prescription['prescription_img'])){ + if ($user['user_type'] == 3 && empty($order_prescription['prescription_img'])) { throw new BusinessException("处方图片错误"); } @@ -184,7 +186,7 @@ class OrderPrescriptionService extends BaseService $params = array(); $params['order_prescription_id'] = $order_prescription_id; $order_prescription_icd = OrderPrescriptionIcd::getList($params); - if (empty($order_prescription_icd)){ + if (empty($order_prescription_icd)) { throw new BusinessException("处方疾病数据错误"); } @@ -192,7 +194,7 @@ class OrderPrescriptionService extends BaseService $params = array(); $params['order_prescription_id'] = $order_prescription_id; $order_prescription_product = OrderPrescriptionProduct::getList($params); - if (empty($order_prescription_product)){ + if (empty($order_prescription_product)) { throw new BusinessException("处方药品数据错误"); } @@ -200,7 +202,7 @@ class OrderPrescriptionService extends BaseService $params = array(); $params['doctor_id'] = $order_prescription['doctor_id']; $user_doctor = UserDoctor::getOne($params); - if (empty($user_doctor)){ + if (empty($user_doctor)) { throw new BusinessException("医生数据错误"); } @@ -208,7 +210,7 @@ class OrderPrescriptionService extends BaseService $params = array(); $params['department_custom_id'] = $user_doctor['department_custom_id']; $hospital_department_custom = HospitalDepartmentCustom::getOne($params); - if (empty($hospital_department_custom)){ + if (empty($hospital_department_custom)) { throw new BusinessException("医生自定义数据错误"); } @@ -216,15 +218,19 @@ class OrderPrescriptionService extends BaseService $params = array(); $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; $order_inquiry_case = OrderInquiryCase::getOne($params); - if (empty($order_inquiry_case)){ + if (empty($order_inquiry_case)) { throw new BusinessException("处方病例数据错误"); } // 处理疾病数据 - $icd_name = array_column($order_prescription_icd->toArray(),'icd_name'); - if (!empty($icd_name)){ - $icd_name = implode(';',$icd_name); - }else{ + $icd_name = array_column($order_prescription_icd->toArray(), 'icd_name'); + if (!empty($icd_name)) { + if (count($icd_name > 1)){ + $icd_name = implode(';', $icd_name); + }else{ + $icd_name = $icd_name[0]; + } + } else { $icd_name = ""; } @@ -243,7 +249,7 @@ class OrderPrescriptionService extends BaseService // 商品数据 $data['product'] = array(); - foreach ($order_prescription_product as $item){ + foreach ($order_prescription_product as $item) { $product = array(); $product['product_name'] = $item['product_name'] . "(" . $item['product_spec'] . ")"; // 商品名称+商品规格 $product['single_unit'] = $item['single_unit'] ?: ""; // 单次剂量(例:1次1包) @@ -256,21 +262,21 @@ class OrderPrescriptionService extends BaseService $cert_sign_result = $ca->getCertSign($user_entity_id, $user_entity_id, $data); // 验证云证书签名-验证无需处理,只要不返回错误即可 - $ca->verifyPkcs7($cert_sign_result['signP7'],$data); + $ca->verifyPkcs7($cert_sign_result['signP7'], $data); dump("云证书签名验证成功"); - if ($user['user_type'] == 3){ + if ($user['user_type'] == 3) { $cert_sign_result = $ca->getCertSign($hospital_entity_id, $hospital_entity_id, $data); // 验证云证书签名-验证无需处理,只要不返回错误即可 - $ca->verifyPkcs7($cert_sign_result['signP7'],$data); + $ca->verifyPkcs7($cert_sign_result['signP7'], $data); dump("医院云证书签名获取成功"); } $oss = new Oss(); // 医生 - if ($user['user_type'] == 2){ + if ($user['user_type'] == 2) { // 下载基础处方图片 $prescription_basic_filename = "basic/file/prescription.jpg"; $prescription_image = $oss->getObjectToRAM($prescription_basic_filename); @@ -284,96 +290,96 @@ class OrderPrescriptionService extends BaseService $fontPath = './extend/Ca/msyh.ttf'; // 处方号 - $image->text($order_prescription['prescription_code'], 1480, 540, function ($font) use($fontPath) { + $image->text($order_prescription['prescription_code'], 1480, 540, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(60); $font->align('left'); }); // 日期 - $image->text(date('Y-m-d',strtotime($order_prescription['doctor_created_time'])), 354, 675, function ($font) use($fontPath) { + $image->text(date('Y-m-d', strtotime($order_prescription['doctor_created_time'])), 354, 675, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(60); $font->align('left'); }); // 科室 - $image->text($hospital_department_custom['department_name'] ?: "", 1385, 675, function ($font) use($fontPath) { + $image->text($hospital_department_custom['department_name'] ?: "", 1385, 675, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(60); $font->align('left'); }); // 姓名 - $image->text($order_prescription['patient_name'], 354, 795, function ($font) use($fontPath) { + $image->text($order_prescription['patient_name'], 354, 795, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(60); $font->align('left'); }); // 性别 - $image->text(sexToStringSex($order_prescription['patient_sex']), 1385, 790, function ($font) use($fontPath) { + $image->text(sexToStringSex($order_prescription['patient_sex']), 1385, 790, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(60); $font->align('left'); }); // 年龄 - $image->text($order_prescription['patient_age'], 354, 900, function ($font) use($fontPath) { + $image->text($order_prescription['patient_age'], 354, 900, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(60); $font->align('left'); }); // 过敏史 - $image->text($order_inquiry_case['allergy_history'] ?: "无", 405, 1030, function ($font) use($fontPath) { + $image->text($order_inquiry_case['allergy_history'] ?: "无", 405, 1030, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(60); $font->align('left'); }); // 初步诊断 - $image->text($icd_name, 445, 1145, function ($font) use($fontPath) { + $image->text($icd_name, 445, 1145, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(60); $font->align('left'); }); // 医生建议 - $image->text($order_prescription['doctor_advice'] ?: "无", 445, 1252, function ($font) use($fontPath) { + $image->text($order_prescription['doctor_advice'] ?: "无", 445, 1252, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(60); $font->align('left'); }); // 商品数据 - foreach ($order_prescription_product as $key => $item){ + foreach ($order_prescription_product as $key => $item) { $x_axis = 229; $y_axis = 1600 + $key * 250; $x_axis_num = 1900;// 数量使用 // 商品名称 - $image->text($item['product_name'], $x_axis, $y_axis, function ($font) use($fontPath) { + $image->text($item['product_name'], $x_axis, $y_axis, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(50); $font->align('left'); }); - $image->text("X" . $item['prescription_product_num'] . $item['packaging_unit'], $x_axis_num, $y_axis, function ($font) use($fontPath) { + $image->text("X" . $item['prescription_product_num'] . $item['packaging_unit'], $x_axis_num, $y_axis, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(50); $font->align('left'); }); // 用量 - $image->text("用量:" . $item['single_unit'] . " " . $item['frequency_use'], $x_axis, $y_axis+70, function ($font) use($fontPath) { + $image->text("用量:" . $item['single_unit'] . " " . $item['frequency_use'], $x_axis, $y_axis + 70, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(50); $font->align('left'); }); // 用法 - $image->text("用法:" . $item['single_use'], $x_axis, $y_axis+140, function ($font) use($fontPath) { + $image->text("用法:" . $item['single_use'], $x_axis, $y_axis + 140, function ($font) use ($fontPath) { $font->file($fontPath); $font->size(50); $font->align('left'); @@ -381,7 +387,7 @@ class OrderPrescriptionService extends BaseService } // 生成图片 - $img_result = (string) $image->encode('png', 75); + $img_result = (string)$image->encode('png', 75); dump("处方图片生成成功"); // 上传处方图片至oss @@ -399,60 +405,60 @@ class OrderPrescriptionService extends BaseService $prescription_pdf_local_filename = $order_prescription['order_prescription_id'] . '.' . 'pdf'; // 图片生成的处方pdf存储为本地文件 - $pdf->Output(dirname(__DIR__, 2) . "/" . $prescription_pdf_local_filename ,"F"); + $pdf->Output(dirname(__DIR__, 2) . "/" . $prescription_pdf_local_filename, "F"); dump("处方图片生成pdf成功"); } // 药师 - if ($user['user_type'] == 3){ + if ($user['user_type'] == 3) { // 下载医生开具的处方pdf // 去除第一个/ oss不识别 $prescription_pdf_path = substr($order_prescription['prescription_pdf'], 1, strlen($order_prescription['prescription_pdf']) - 1); $local = "./runtime/" . $order_prescription['order_prescription_id'] . '.' . 'pdf'; - $oss->getObjectToLocal($prescription_pdf_path,$local); + $oss->getObjectToLocal($prescription_pdf_path, $local); dump("下载医生开具的处方pdf成功"); } // 下载签名图片 $style = "image/resize,m_lfit,w_100,h_350"; - $sign_image = $oss->getCusTomObjectToRAM($sign_image_path,$style); + $sign_image = $oss->getCusTomObjectToRAM($sign_image_path, $style); $sign_image = base64_encode($sign_image); - if (!$sign_image){ + if (!$sign_image) { throw new BusinessException("签名图片下载失败"); } dump("下载签名图片成功"); - if ($user['user_type'] == 2){ + if ($user['user_type'] == 2) { $sign_param = [ [ // 医生端 - "llx"=>"120", // 左边底部X坐标 - "lly"=>"190", // 左边底部Y坐标 - "urx"=>"190", // 右边上部x坐标 - "ury"=>"140", // 右边上部y坐标 - "pageList"=>[1], - "sealImg"=>$sign_image + "llx" => "120", // 左边底部X坐标 + "lly" => "190", // 左边底部Y坐标 + "urx" => "190", // 右边上部x坐标 + "ury" => "140", // 右边上部y坐标 + "pageList" => [1], + "sealImg" => $sign_image ], ]; - }else{ + } else { $sign_param = [ [ // 药师端 - "llx"=>"350", // 左边底部X坐标 - "lly"=>"190", // 左边底部Y坐标 - "urx"=>"440", // 右边上部x坐标 - "ury"=>"140", // 右边上部y坐标 - "pageList"=>[1], - "sealImg"=>$sign_image + "llx" => "350", // 左边底部X坐标 + "lly" => "190", // 左边底部Y坐标 + "urx" => "440", // 右边上部x坐标 + "ury" => "140", // 右边上部y坐标 + "pageList" => [1], + "sealImg" => $sign_image ] ]; } // 打开处方pdf文件 - $pdf_file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . ".pdf",'r'); - if (!$pdf_file){ + $pdf_file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . ".pdf", 'r'); + if (!$pdf_file) { throw new BusinessException("处方图片打开失败"); } @@ -461,8 +467,8 @@ class OrderPrescriptionService extends BaseService $data = array(); $data['sign_param'] = json_encode($sign_param); $data['pdf_file'] = $pdf_file; - $sign_pdf_result = $ca->addSignPdf($user_entity_id,$data); - if (empty($sign_pdf_result[0]['fileId'])){ + $sign_pdf_result = $ca->addSignPdf($user_entity_id, $data); + if (empty($sign_pdf_result[0]['fileId'])) { throw new BusinessException("处方签章失败"); } @@ -470,9 +476,9 @@ class OrderPrescriptionService extends BaseService // 下载处方签章文件 $file_id = $sign_pdf_result[0]['fileId']; - $prescription_pdf_result = $ca->getSignedFile($user_entity_id,$file_id); + $prescription_pdf_result = $ca->getSignedFile($user_entity_id, $file_id); - if (empty($prescription_pdf_result)){ + if (empty($prescription_pdf_result)) { throw new BusinessException("下载处方签章文件失败"); } @@ -483,7 +489,7 @@ class OrderPrescriptionService extends BaseService $prescription_pdf_url = $oss->putObject($filename, $prescription_pdf_result); dump("处方pdf上传pss成功"); - if ($user['user_type'] == 3){ + if ($user['user_type'] == 3) { // 药师端时,需要进行系统签章 // 把药师签章的pdf存储至本地文件 $file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . '.' . 'pdf', "w"); @@ -492,33 +498,33 @@ class OrderPrescriptionService extends BaseService // 下载医院签名图片 $style = "image/resize,w_300,h_300"; - $sign_image = $oss->getCusTomObjectToRAM($hospital_sign_image_path,$style); + $sign_image = $oss->getCusTomObjectToRAM($hospital_sign_image_path, $style); $sign_image = base64_encode($sign_image); - if (!$sign_image){ + if (!$sign_image) { throw new BusinessException("医院签名图片下载失败"); } $sign_param = [ [ // 医院签章 - "llx"=>"370", // 左边底部X坐标 控制左右(越小越左) - "lly"=>"210", // 左边底部Y坐标 控制上下(越小越下) - "urx"=>"520", // 右边上部x坐标 - "ury"=>"360", // 右边上部y坐标 - "pageList"=>[1], - "sealImg"=>$sign_image + "llx" => "370", // 左边底部X坐标 控制左右(越小越左) + "lly" => "210", // 左边底部Y坐标 控制上下(越小越下) + "urx" => "520", // 右边上部x坐标 + "ury" => "360", // 右边上部y坐标 + "pageList" => [1], + "sealImg" => $sign_image ], ]; // 打开处方pdf文件 unset($pdf_file); - $pdf_file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . ".pdf",'r'); + $pdf_file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . ".pdf", 'r'); // 处方pdf进行签章 $data = array(); $data['sign_param'] = json_encode($sign_param); $data['pdf_file'] = $pdf_file; - $hospital_sign_pdf_result = $ca->addSignPdf($hospital_entity_id,$data); - if (empty($hospital_sign_pdf_result[0]['fileId'])){ + $hospital_sign_pdf_result = $ca->addSignPdf($hospital_entity_id, $data); + if (empty($hospital_sign_pdf_result[0]['fileId'])) { throw new BusinessException("处方签章失败"); } @@ -527,9 +533,9 @@ class OrderPrescriptionService extends BaseService // 下载处方签章文件 unset($prescription_pdf_result); $file_id = $hospital_sign_pdf_result[0]['fileId']; - $prescription_pdf_result = $ca->getSignedFile($hospital_entity_id,$file_id); + $prescription_pdf_result = $ca->getSignedFile($hospital_entity_id, $file_id); - if (empty($prescription_pdf_result)){ + if (empty($prescription_pdf_result)) { throw new BusinessException("下载处方签章文件失败"); } @@ -550,4 +556,171 @@ class OrderPrescriptionService extends BaseService throw new BusinessException($e->getMessage()); } } + + // 上报处方平台 + public function reportPrescription(array $order_inquiry, array $order_prescription, array $order_prescription_product, array $order_product) + { + // 获取就诊患者用户数据 + $params = array(); + $params['user_id'] = $order_inquiry['user_id']; + $user = User::getOne($params); + if (empty($user)){ + throw new BusinessException("用户数据错误"); + } + + // 获取家庭成员-基本信息 + $params = array(); + $params['family_id'] = $order_inquiry['family_id']; + $patient_family = PatientFamily::getOne($params); + if (empty($patient_family)){ + throw new BusinessException("用户家庭成员错误"); + } + + // 获取处方关联疾病数据 + $params = array(); + $params['order_prescription_id'] = $order_prescription['order_prescription_id']; + $order_prescription_icd = OrderPrescriptionIcd::getList($params); + if (empty($order_prescription_icd)) { + throw new BusinessException("处方疾病数据错误"); + } + + // 处理疾病数据 + $icd_name = array_column($order_prescription_icd->toArray(), 'icd_name'); + if (!empty($icd_name)) { + if (count($icd_name > 1)){ + $icd_name = implode(';', $icd_name); + }else{ + $icd_name = $icd_name[0]; + } + } else { + $icd_name = ""; + } + + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $order_prescription['doctor_id']; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + throw new BusinessException("医生数据错误"); + } + + // 获取医生科室 + $params = array(); + $params['department_custom_id'] = $user_doctor['department_custom_id']; + $hospital_department_custom = HospitalDepartmentCustom::getOne($params); + if (empty($hospital_department_custom)) { + throw new BusinessException("医生科室数据错误"); + } + + // 获取医生详情数据 + $params = array(); + $params['doctor_id'] = $order_prescription['doctor_id']; + $user_doctor_info = UserDoctorInfo::getOne($params); + if (empty($user_doctor_info)){ + throw new BusinessException("医生详情数据错误"); + } + + // 获取药师数据 + $params = array(); + $params['pharmacist_id'] = $order_prescription['pharmacist_id']; + $user_pharmacist = UserPharmacist::getOne($params); + if (empty($user_pharmacist)){ + throw new BusinessException("药师数据错误"); + } + + // 获取药师详情数据 + $params = array(); + $params['pharmacist_id'] = $order_prescription['pharmacist_id']; + $user_pharmacist_info = UserPharmacistInfo::getOne($params); + if (empty($user_pharmacist_info)){ + throw new BusinessException("药师详情数据错误"); + } + + // 获取病例数据 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $params['status'] = 1; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)){ + throw new BusinessException("病例数据错误"); + } + + $arg = array(); + $arg['terminalCode'] = "JG-10009"; + $arg['orderNo'] = $order_product['order_product_no']; // 支付流水号 + $arg['transactNo'] = $order_product['escrow_trade_no']; // 支付流水号 + $arg['payDate'] = $order_product['pay_time']; // 支付时间 + $arg['money'] = $order_product['payment_amount_total']; // 订单金额 + $arg['takeTypeCode'] = 2; // 取货方式 1 自提 2 快递,目 前只支持快递,传 固定值 2 + $arg['buyerName'] = $order_product['consignee_name'];// 收货人姓名 + $arg['buyerPhone'] = $order_product['consignee_tel'];// 收货人联系方式 + $arg['buyerAddress'] = $order_product['address'];// 收货人地址 + $arg['provinceCode'] = $order_product['province_id']; // 收货地址(省) 编码 + $arg['provinceName'] = $order_product['province']; // 收货地址(省) 名称 + $arg['cityCode'] = $order_product['city_id']; // 收货地址(市) 编码 + $arg['cityName'] = $order_product['city']; // 收货地址(市) 名称 + $arg['districtCode'] = $order_product['county_id']; // 收货地址(区 县)编码 + $arg['districtName'] = $order_product['county']; // 收货地址(区 县)名称 + $arg['freight'] = $order_product['logistics_fee']; // 运费(单位:元) + $arg['prescriptionNo'] = $order_prescription['prescription_code']; // 处方编号 + $arg['prescriptionSubType'] = 1; // 处方类型 0:无类型 1:普 通处方 2:儿科处 方 + $arg['patientName'] = $order_prescription['patient_name']; // 就诊人姓名 + $arg['patientPhone'] = $user['mobile']; // 就诊人联系方式 + $arg['idCard'] = $patient_family['id_number']; // 身份证号 + $arg['advice'] = $order_prescription['doctor_advice'] ?: ""; // 医嘱 + $arg['diagnosisName'] = $icd_name ?: ""; // 诊断 + $arg['thirdDoctorName'] = $user_doctor['user_name']; // 开方医生姓名 + $arg['thirdDeptName'] = $hospital_department_custom['department_name'] ?: ""; // 开方科室名称 + $arg['thirdDoctorNameImg'] = addAliyunOssWebsite($user_doctor_info['sign_image']); // 开方医生签名链接 + $arg['prescriptionTime'] = $order_prescription['doctor_created_time']; // 开方时间 + $arg['thirdFirstPharmacist'] = $user_pharmacist['user_name']; // 初审药师姓名 + $arg['thirdFirstPharmacistImg'] = addAliyunOssWebsite($user_pharmacist_info['sign_image']); // 初审药师签名链接 + $arg['thirdFirstTime'] = $order_prescription['pharmacist_verify_time']; // 初审时间 + $arg['thirdLastPharmacist'] = $user_pharmacist['user_name']; // 终审药师姓名 + $arg['thirdLastPharmacistImg'] = addAliyunOssWebsite($user_pharmacist_info['sign_image']); // 终审药师签名 链接 + $arg['ThirdLastTime'] = $order_prescription['pharmacist_verify_time']; // 终审时间 + $arg['thirdSignImg'] = addAliyunOssWebsite("/basic/file/hospital_signature.png"); // 处方签章链接 + $arg['referenceCharge'] = $order_product['amount_total']; // 处方费用 + $arg['chiefComplaint'] = $order_inquiry_case['disease_desc'] ?: ""; // 主诉 + $arg['historyPresent'] = $order_inquiry_case['disease_class_name'] ?: ""; // 现病史 + $arg['pastHistory'] = $order_inquiry_case['family_history'] ?: "无"; // 既往史 + $arg['physicalExamination'] = "无"; // 体格检查 + $arg['supplementaryExamination'] = "无"; // 辅助检查 + $arg['allergicHistory'] = $order_inquiry_case['allergy_history'] ?: "无"; // 过敏史 + + // 药品数据 + foreach ($order_prescription_product as $key => $item){ + // 获取商品数据 + $pamras = array(); + $pamras['product_id'] = $item['product_id']; + $product = Product::getOne($pamras); + if (empty($product)){ + throw new BusinessException("药品数据错误"); + } + + $arg['drugList'][$key]['drugCode'] = $product['product_pharmacy_code']; // 药品编码 + $arg['drugList'][$key]['approvalNumber'] = $product['license_number']; // 批准文号 + $arg['drugList'][$key]['drugName'] = $product['product_name']; // 药品名称 + $arg['drugList'][$key]['specifications'] = $product['product_spec']; // 药品规格 + $arg['drugList'][$key]['price'] = $product['product_price']; // 药品单价 + $arg['drugList'][$key]['packingCount'] = $item['amount']; // 药品数量 + $arg['drugList'][$key]['surplusPackingCount'] = 0; // 处方药品剩余使用数量 + $arg['drugList'][$key]['packingUnit'] = $product['packaging_unit']; // 药品单位 + $arg['drugList'][$key]['singleDosage'] = $product['single_unit']; // 单次用量 + $arg['drugList'][$key]['singleDosageUnit'] = ""; // 单次用量单位 + $arg['drugList'][$key]['useName'] = $product['single_use']; // 用法名称 + $arg['drugList'][$key]['frequencyName'] = $product['frequency_use']; // 频次名称 + $arg['drugList'][$key]['useDays'] = $product['available_days']; // 使用天数 + + $arg['orderDrugList'][$key]['drugCode'] = $product['product_pharmacy_code']; // 药品编码 + $arg['orderDrugList'][$key]['approvalNumber'] = $product['license_number']; // 批准文号 + $arg['orderDrugList'][$key]['drugName'] = $product['product_name']; // 药品名称 + $arg['orderDrugList'][$key]['specifications'] = $product['product_spec']; // 药品规格 + $arg['orderDrugList'][$key]['price'] = $product['product_price']; // 药品单价 + $arg['orderDrugList'][$key]['drugCount'] = $item['amount']; // 药品数量 + $arg['orderDrugList'][$key]['packingUnit'] = $product['packaging_unit']; // 药品单位 + } + + + } } \ No newline at end of file diff --git a/app/Services/PatientOrderService.php b/app/Services/PatientOrderService.php index f64c9e2..b08030f 100644 --- a/app/Services/PatientOrderService.php +++ b/app/Services/PatientOrderService.php @@ -1245,17 +1245,21 @@ class PatientOrderService extends BaseService } // 获取运费金额 - $Prescription = new Prescription(); - - $result = $Prescription->getLogisticsFee(); - if ($amount_total >= $result['drugCost']){ - $logistics_fee = 0; - }else{ - $logistics_fee = $result['freight']; + $logistics_fee = 0; + if (env("APP_ENV") == "prod"){ + $Prescription = new Prescription(); + $result = $Prescription->getLogisticsFee(); + if ($amount_total < $result['drugCost']){ + $logistics_fee = $result['freight']; + } } // 实际支付金额 - $payment_amount_total = $amount_total + $logistics_fee; + if (env("APP_ENV") == "prod"){ + $payment_amount_total = 0.01; + }else{ + $payment_amount_total = $amount_total + $logistics_fee; + } // 获取收货地址 $params = array(); diff --git a/app/Services/UserPharmacistService.php b/app/Services/UserPharmacistService.php index e1adcc1..3d545f0 100644 --- a/app/Services/UserPharmacistService.php +++ b/app/Services/UserPharmacistService.php @@ -127,8 +127,6 @@ class UserPharmacistService extends BaseService public function putPrescriptionVerify(): array { $user_info = $this->request->getAttribute("userInfo") ?? []; - $user_info['user_id'] = "534534546"; - $user_info['client_user_id'] = "534534546"; $order_prescription_id = $this->request->route('order_prescription_id'); $pharmacist_audit_status = $this->request->input('pharmacist_audit_status'); @@ -230,6 +228,9 @@ class UserPharmacistService extends BaseService return fail(HttpEnumCode::SERVER_ERROR, "处方审核失败"); } + // 上报处方平台 + + // 发送消息 $ImService = new ImService(); diff --git a/extend/Prescription/Prescription.php b/extend/Prescription/Prescription.php index 8119e8a..77f5b86 100644 --- a/extend/Prescription/Prescription.php +++ b/extend/Prescription/Prescription.php @@ -155,6 +155,30 @@ class Prescription } } + /** + * 上报处方 + * @param array $arg + * @return array + */ + public function reportPrescription(array $arg): array + { + $option = [ + "json" => $arg + ]; + + try { + $response = $this->httpRequest($this->api_url . $this->version . '/preOrder/receivePreOrder', $option); + if (empty($response)){ + // 返回值为空 + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } + + return $response; + } catch (GuzzleException $e) { + throw new BusinessException($e->getMessage()); + } + } + /** * 请求封装 * @param string $path