修改开具处方问题

This commit is contained in:
2023-09-08 17:49:22 +08:00
parent 47d36afcb6
commit 4afcbaacf0
4 changed files with 171 additions and 186 deletions
+46 -102
View File
@@ -38,81 +38,77 @@ class CaService extends BaseService
// 是否已添加签章配置(第一次需申请)
protected string $is_sign_config;
// 用户签名图片地址
// 签名图片地址
public string $sign_image_path;
// 医院签名图片地址
protected string $hospital_sign_image_path;
// 用户唯一标识
protected string $user_entity_id;
// 医院唯一标识
protected string $hospital_entity_id;
// 唯一标识
protected string $entity_id;
// 证书序列号
protected string $cert_serial_number;
// 身份证号
// 身份证号/信用代码
protected string $card_num;
// 信用代码
protected string $org_num;
// 处方pdf本地地址
protected string $prescription_pdf_local_path;
// 处方pdf oss地址
protected string $prescription_pdf_oss_path;
/**
* 初始化类,此处会获取基础数据
* @param array|object $order_prescription 处方表数据
* @param array|object $user 用户表数据
* @param string|int $user_id 用户id
* @param int $type 类型 1:医院 2:医生 3:药师
*/
public function __construct(array|object $order_prescription,array|object $user){
public function __construct(array|object $order_prescription,int $type,string|int $user_id = ""){
// 获取用户、医院签名图片地址、用户标识信息
$params = array();
$params['user_id'] = $user['user_id'];
if ($user['user_type'] == 2) {
if ($type == 1){
// 医院
$this->sign_image_path = "basic/file/hospital_signature.png";
$this->entity_id = "5345345461";
$this->card_num = "91510106MABTJY4K9R";
}elseif($type == 2){
// 用户
$params = array();
$params['user_id'] = $user_id;
$user_doctor_info = UserDoctorInfo::getOne($params);
if (empty($user_doctor_info)) {
throw new BusinessException("用户数据错误");
}
$user_sign_image_path = $user_doctor_info['sign_image'];
$this->sign_image_path = substr($user_doctor_info['sign_image'], 1, strlen($user_doctor_info['sign_image']) - 1);
$app_env = config('app_env','dev');
if ($app_env == 'prod'){
$this->user_entity_id = $user_doctor_info['user_id'];
$this->entity_id = $user_doctor_info['user_id'];
}else{
$this->user_entity_id = "491925054435950592";
$this->entity_id = "491925054435950592";
}
$this->card_num = $user_doctor_info['card_num'];
} else {
} elseif ($type == 3){
$params = array();
$params['user_id'] = $user_id;
$user_pharmacist_info = UserPharmacistInfo::getOne($params);
if (empty($user_pharmacist_info)) {
throw new BusinessException("用户数据错误");
}
$user_sign_image_path = $user_pharmacist_info['sign_image'];
$this->user_entity_id = $user['user_id'];
$this->card_num = $user_pharmacist_info['card_num'];
// 去除用户签名图片第一个/ oss不识别
$this->sign_image_path = substr($user_pharmacist_info['sign_image'], 1, strlen($user_pharmacist_info['sign_image']) - 1);
$this->hospital_sign_image_path = "basic/file/hospital_signature.png";
$this->hospital_entity_id = "5345345461";
$this->org_num = "91510106MABTJY4K9R";
$this->entity_id = $user_id;
$this->card_num = $user_pharmacist_info['card_num'];
} else{
throw new BusinessException("用户类型错误");
}
if (empty($user_sign_image_path) || empty($this->user_entity_id)) {
if (empty($this->sign_image_path) || empty($this->entity_id)) {
throw new BusinessException("无签名图片/用户唯一标识");
}
// 去除用户签名图片第一个/ oss不识别
$this->sign_image_path = substr($user_sign_image_path, 1, strlen($user_sign_image_path) - 1);
$order_prescription_id = $order_prescription['order_prescription_id'];
// 创建协程客户端
@@ -225,9 +221,8 @@ class CaService extends BaseService
/**
* 获取云证书签名+验证云证书签名
* @param array|object $order_prescription
* @param int $type 类型 1:用户 2:医院
*/
public function getVerifyCertSign(array|object $order_prescription,int $type)
public function getVerifyCertSign(array|object $order_prescription)
{
$CaOnline = new CaOnline();
@@ -254,13 +249,7 @@ class CaService extends BaseService
$data['product'][] = $product;
}
if ($type == 1){
// 用户
$cert_sign_result = $CaOnline->getCertSign($this->user_entity_id, $this->user_entity_id, $data);
}else{
// 医院
$cert_sign_result = $CaOnline->getCertSign($this->hospital_entity_id, $this->hospital_entity_id, $data);
}
$cert_sign_result = $CaOnline->getCertSign($this->entity_id, $this->entity_id, $data);
// 验证云证书签名 验证无需处理,只要不返回错误即可
$CaOnline->verifyPkcs7($cert_sign_result['signP7'], $data);
@@ -411,38 +400,23 @@ class CaService extends BaseService
/**
* 下载Oss中处方pdf
* 存在:当次发版内医生开具后,药师再去开具
* 不存在:医生开具后,进行发版过,此时需重新下载
* @return void
*/
public function downOssPdfToLocal(): void
{
$res = file_exists($this->prescription_pdf_local_path);
if (!$res){
// 去除第一个/ oss不识别
// $prescription_pdf_path = substr($doctor_pdf_oss_path, 1, strlen($doctor_pdf_oss_path) - 1);
$oss = new Oss();
$oss->getObjectToLocal($this->prescription_pdf_oss_path, $this->prescription_pdf_local_path);
}
$oss = new Oss();
$oss->getObjectToLocal($this->prescription_pdf_oss_path, $this->prescription_pdf_local_path);
}
/**
* 下载CA中pdf至本地文件
* @param string $file_id
* @param int $type 类型 1:用户 2:医院
* @return void
*/
public function downCaPdfToLocal(string $file_id,int $type): void
public function downCaPdfToLocal(string $file_id): void
{
$CaOnline = new CaOnline();
if ($type == 1){
// 用户
$prescription_pdf_result = $CaOnline->getSignedFile($this->user_entity_id, $file_id);
}else{
// 医院
$prescription_pdf_result = $CaOnline->getSignedFile($this->hospital_entity_id, $file_id);
}
$prescription_pdf_result = $CaOnline->getSignedFile($this->entity_id, $file_id);
$file = fopen($this->prescription_pdf_local_path, "w");
fwrite($file, $prescription_pdf_result);
@@ -452,20 +426,13 @@ class CaService extends BaseService
/**
* 下载CA中的pdf并上传至oss
* @param string $file_id
* @param int $type 类型 1:用户 2:医院
* @return string oss地址
*/
public function downCaPdfToOss(string $file_id,int $type): string
public function downCaPdfToOss(string $file_id): string
{
$CaOnline = new CaOnline();
if ($type == 1){
// 用户
$prescription_pdf_result = $CaOnline->getSignedFile($this->user_entity_id, $file_id);
}else{
// 医院
$prescription_pdf_result = $CaOnline->getSignedFile($this->hospital_entity_id, $file_id);
}
$prescription_pdf_result = $CaOnline->getSignedFile($this->entity_id, $file_id);
// 上传oss
$oss = new Oss();
@@ -479,27 +446,15 @@ class CaService extends BaseService
*/
public function addSignPdf(string $type): string
{
// 下载签名图片
$oss = new Oss();
if ($type == 1){
$local_path = "./extend/Ca/hospital_signature.png";
$res = file_exists($local_path);
if ($res){
// 读取本地文件
$sign_image = fopen($local_path,'r');
}
$style = "image/resize,w_300,h_300";
}else{
$style = "image/resize,m_lfit,w_100,h_350";
}
if (!isset($sign_image)){
$oss = new Oss();
if ($type == 1){
$style = "image/resize,w_300,h_300";
$sign_image = $oss->getCusTomObjectToRAM($this->hospital_sign_image_path, $style);
}else{
$style = "image/resize,m_lfit,w_100,h_350";
$sign_image = $oss->getCusTomObjectToRAM($this->sign_image_path, $style);
}
}
$sign_image = $oss->getCusTomObjectToRAM($this->sign_image_path, $style);
$sign_image = base64_encode($sign_image);
if (!$sign_image) {
@@ -512,24 +467,18 @@ class CaService extends BaseService
$lly = "210"; // 左边底部Y坐标 控制上下(越小越下)
$urx = "520"; // 右边上部x坐标
$ury = "360"; // 右边上部y坐标
$entity_id = $this->hospital_entity_id;
} elseif ($type == 2){
// 医生端
$llx = "120"; // 左边底部X坐标
$lly = "190"; // 左边底部Y坐标
$urx = "190"; // 右边上部x坐标
$ury = "140"; // 右边上部y坐标
$entity_id = $this->user_entity_id;
}else{
// 药师端
$llx = "350"; // 左边底部X坐标
$lly = "190"; // 左边底部Y坐标
$urx = "440"; // 右边上部x坐标
$ury = "140"; // 右边上部y坐标
$entity_id = $this->user_entity_id;
}
$sign_param = [
@@ -559,11 +508,7 @@ class CaService extends BaseService
$data['sign_param'] = json_encode($sign_param);
$data['seal_img'] = $sign_image;
if ($type == 1){
$CaOnline->addUserSignConfig($entity_id,$this->org_num,$data);
}else{
$CaOnline->addUserSignConfig($entity_id,$this->card_num,$data);
}
$CaOnline->addUserSignConfig($this->entity_id,$this->card_num,$data);
$params = array();
$params['cert_id'] = $user_ca_cert['cert_id'];
@@ -580,17 +525,16 @@ class CaService extends BaseService
throw new BusinessException("处方pdf打开失败");
}
// 处方pdf进行签章
$data = array();
$data['sign_param'] = json_encode($sign_param);
$data['pdf_file'] = $pdf_file;
$sign_pdf_result = $CaOnline->addSignPdf($entity_id, $data);
$sign_pdf_result = $CaOnline->addSignPdf($this->entity_id, $data);
if (empty($sign_pdf_result[0]['fileId'])) {
throw new BusinessException("处方签章失败");
}
return $sign_pdf_result[0]['fileId'];
}
}