Compare commits

..
6 Commits
Author SHA1 Message Date
haomingming 315adad6d0 Merge branch 'dev'
Build Docker / build (push) Has been cancelled
2026-01-06 17:51:31 +08:00
haomingming e223725c49 Merge branch 'dev'
Build Docker / build (push) Has been cancelled
2025-12-23 10:49:39 +08:00
haomingming ef2ae67a37 Merge branch 'dev'
Build Docker / build (push) Waiting to run
2025-12-23 09:45:29 +08:00
haomingming 7690ec848b Merge branch 'dev'
Build Docker / build (push) Waiting to run
2025-12-22 14:29:20 +08:00
haomingming 569b2a84fd Merge branch 'dev'
Build Docker / build (push) Waiting to run
2025-12-22 13:32:13 +08:00
haomingming bc61f09ad0 合并 dev
Build Docker / build (push) Has been cancelled
2025-10-22 15:06:05 +08:00
42 changed files with 458 additions and 3137 deletions
-1
View File
@@ -4,7 +4,6 @@
*.patch
.idea/
.git/
docs/
runtime/
vendor/
.phpintel/
@@ -261,12 +261,7 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage
}
// 修改处方文件表,添加prescription_pdf_oss_path字段
$this->modifyOrderPrescriptionFile(
$data['prescription_file_id'],
$prescription_pdf_oss_path,
$prescription_open_result['file_id'],
$prescription_open_result
);
$this->modifyOrderPrescriptionFile($data['prescription_file_id'],$prescription_pdf_oss_path,$prescription_open_result['file_id']);
// 修改处方表为通过
$this->modifyOrderPrescription($data['order_prescription_id'],1);
@@ -443,7 +438,7 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage
* @param string $hospital_ca_file_id 医院签章文件id
* @return void
*/
protected function modifyOrderPrescriptionFile(string $prescription_file_id,string $prescription_pdf_oss_path,string $hospital_ca_file_id,array $pharmacist_ca_data = []): void
protected function modifyOrderPrescriptionFile(string $prescription_file_id,string $prescription_pdf_oss_path,string $hospital_ca_file_id): void
{
try {
$params = array();
@@ -452,11 +447,6 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage
$data = array();
$data['hospital_ca_file_id'] = $hospital_ca_file_id;
$data['prescription_pdf_oss_path'] = $prescription_pdf_oss_path;
$data['pharmacist_ca_supplier'] = $pharmacist_ca_data['ca_supplier'] ?? "";
$data['pharmacist_ca_sign_type'] = $pharmacist_ca_data['ca_sign_type'] ?? "";
$data['pharmacist_ca_sign_originaltext'] = $pharmacist_ca_data['ca_sign_originaltext'] ?? "";
$data['pharmacist_ca_sign_text'] = $pharmacist_ca_data['ca_sign_text'] ?? "";
$data['pharmacist_ca_sign_time'] = $pharmacist_ca_data['ca_sign_time'] ?? "";
OrderPrescriptionFile::edit($params,$data);
}catch(\Exception $e){
@@ -1,88 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Amqp\Consumer;
use App\Model\MessageIm;
use Extend\Alibaba\Oss;
use GuzzleHttp\Client;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\Amqp\Result;
use PhpAmqpLib\Message\AMQPMessage;
use App\Utils\Log;
/**
* IM 多媒体文件异步处理消费者
*/
#[Consumer(exchange: 'amqp.direct', routingKey: 'UploadImMedia', queue: 'UploadImMediaQueue', name: "UploadImMediaConsumer", nums: 1)]
class UploadImMediaConsumer extends ConsumerMessage
{
public function consumeMessage($data, AMQPMessage $message): string
{
try {
$messageKey = $data['message_key'];
$msgType = $data['msg_type'];
$msgContent = $data['msg_content'];
// 初始化 Http Client 和 OSS
$client = new Client(['verify' => false, 'timeout' => 30]); // 设置合适的超时时间
$oss = new Oss();
$needUpdate = false;
$customDomain = config('alibaba.oss.custom_domain_name'); // 取 OSS 自定义域名
// 1. 根据不同类型提取 URL 并转存 OSS
if ($msgType === 'TIMImageElem' && isset($msgContent['ImageInfoArray'])) {
// 图片通常包含原图、大图、缩略图,根据需求替换
foreach ($msgContent['ImageInfoArray'] as &$imageInfo) {
if (!empty($imageInfo['URL'])) {
$content = $client->get($imageInfo['URL'])->getBody()->getContents();
$filename = "im/image/" . date('Ymd') . "/" . $messageKey . "_" . $imageInfo['Type'] . ".jpg";
$ossFilename = $oss->putObject($filename, $content);
$imageInfo['URL'] = rtrim($customDomain, '/') . '/' . $ossFilename;
$needUpdate = true;
}
}
} elseif ($msgType === 'TIMSoundElem' && !empty($msgContent['Url'])) {
// 语音消息
$content = $client->get($msgContent['Url'])->getBody()->getContents();
$filename = "im/sound/" . date('Ymd') . "/" . $messageKey . ".amr";
$ossFilename = $oss->putObject($filename, $content);
$msgContent['Url'] = rtrim($customDomain, '/') . '/' . $ossFilename;
$needUpdate = true;
} elseif ($msgType === 'TIMVideoFileElem') {
// 视频文件
if (!empty($msgContent['VideoUrl'])) {
$content = $client->get($msgContent['VideoUrl'])->getBody()->getContents();
$filename = "im/video/" . date('Ymd') . "/" . $messageKey . ".mp4";
$ossFilename = $oss->putObject($filename, $content);
$msgContent['VideoUrl'] = rtrim($customDomain, '/') . '/' . $ossFilename;
$needUpdate = true;
}
// 视频封面图
if (!empty($msgContent['ThumbUrl'])) {
$content = $client->get($msgContent['ThumbUrl'])->getBody()->getContents();
$filename = "im/video_thumb/" . date('Ymd') . "/" . $messageKey . ".jpg";
$ossFilename = $oss->putObject($filename, $content);
$msgContent['ThumbUrl'] = rtrim($customDomain, '/') . '/' . $ossFilename;
$needUpdate = true;
}
}
// 2. 更新对应记录的 JSON 数据
if ($needUpdate) {
MessageIm::where(['message_key' => $messageKey])->update([
'message_content' => json_encode($msgContent, JSON_UNESCAPED_UNICODE)
]);
}
return Result::ACK; // 任务成功完成
} catch (\Throwable $e) {
Log::getInstance("UploadImMediaConsumer")->error("IM多媒体上传OSS失败: " . $e->getMessage() . ' Line: ' . $e->getLine());
// 如果抛错可以 DROP 掉或者返回 REQUEUE 进入死信重试队列
return Result::DROP;
}
}
}
@@ -1,27 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Amqp\Producer;
use Hyperf\Amqp\Annotation\Producer;
use Hyperf\Amqp\Message\ProducerMessage;
/**
* IM 多媒体文件异步下载并上传 OSS
*/
#[Producer(exchange: 'amqp.direct', routingKey: 'UploadImMedia')]
class UploadImMediaProducer extends ProducerMessage
{
/**
* @param array $data
* [
* "message_key" => "消息唯一ID",
* "msg_type" => "消息类型",
* "msg_content" => "消息具体内容(数组)"
* ]
*/
public function __construct(array $data)
{
$this->payload = $data;
}
}
+13 -312
View File
@@ -9,12 +9,12 @@ use App\Model\HospitalDepartmentCustom;
use App\Model\OrderInquiry;
use App\Model\OrderInquiryCase;
use App\Model\OrderPrescription;
use App\Model\OrderPrescriptionFile;
use App\Model\OrderPrescriptionIcd;
use App\Model\OrderPrescriptionProduct;
use App\Model\PatientFamily;
use App\Model\Product;
use App\Model\ReportRegulatory;
use App\Model\UserCaCert;
use App\Model\UserDoctor;
use App\Model\UserDoctorInfo;
use App\Model\UserPharmacist;
@@ -188,7 +188,7 @@ class ReportRegulatoryCommand extends HyperfCommand
}else{
$this->line("C-2、检测处方(抄方)数据");
// 获取上报数据-处方 (抄方类型)
$report_prescription_data = $this->getReportTransferPrescriptionDataV2($order_inquiry, $order_prescription);
$report_prescription_data = $this->getReportTransferPrescriptionData($order_inquiry, $order_prescription);
}
$this->line("C-3、上报处方");
@@ -198,17 +198,6 @@ class ReportRegulatoryCommand extends HyperfCommand
$this->line("C-4、上报处方成功" . json_encode($result,JSON_UNESCAPED_UNICODE));
$report_prescription_detail_data = $this->getReportPrescriptionDetailData(
$order_prescription,
$report_prescription_data
);
if (empty($report_prescription_detail_data)) {
throw new BusinessException("处方明细数据错误");
}
$result = $regulatoryPlatform->uploadRecipeDetail($report_prescription_detail_data);
$this->line("C-4-1、上报处方明细成功" . json_encode($result,JSON_UNESCAPED_UNICODE));
// 上报成功
$res = $this->modifyReportRegulatoryPrescription($report_regulatory, 1);
if (!$res) {
@@ -485,7 +474,7 @@ class ReportRegulatoryCommand extends HyperfCommand
$params['user_id'] = $user_doctor['user_id'];
$params['type'] = 2;
$params['is_latest'] = 1;
$doctor_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'doctor');
$doctor_user_ca_cert = UserCaCert::getOne($params);
if (empty($doctor_user_ca_cert)){
$this->line("错误:无医生ca数据");
return false;
@@ -496,7 +485,7 @@ class ReportRegulatoryCommand extends HyperfCommand
$params['user_id'] = $user_pharmacist['user_id'];
$params['type'] = 2;
$params['is_latest'] = 1;
$pharmacist_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'pharmacist');
$pharmacist_user_ca_cert = UserCaCert::getOne($params);
if (empty($pharmacist_user_ca_cert)){
$this->line("错误:无药师ca数据");
return false;
@@ -544,13 +533,6 @@ class ReportRegulatoryCommand extends HyperfCommand
$data['recipeNo'] = $order_prescription['order_prescription_id']; // 医院处方编号
$data['cityId'] = "510100"; // 城市ID(参考地区字段)
$pharmacist_ca_data = $this->getStoredPrescriptionCaData($order_prescription['order_prescription_id'], 'pharmacist');
$data['caSupplier'] = $pharmacist_ca_data['caSupplier'] ?? "";
$data['caSignType'] = $pharmacist_ca_data['caSignType'] ?? "";
$data['caSignTime'] = $pharmacist_ca_data['caSignTime'] ?? "";
$data['caSignOriginaltext'] = $pharmacist_ca_data['caSignOriginaltext'] ?? "";
$data['caSignText'] = $pharmacist_ca_data['caSignText'] ?? "";
return $data;
}
@@ -562,7 +544,6 @@ class ReportRegulatoryCommand extends HyperfCommand
*/
private function getReportTransferPrescriptionData(array|object $order_inquiry, array|object $order_prescription): bool|array
{
return $this->getReportTransferPrescriptionDataV2($order_inquiry, $order_prescription);
// 获取医生数据
$params = array();
$params['doctor_id'] = $order_prescription['doctor_id'];
@@ -657,7 +638,7 @@ class ReportRegulatoryCommand extends HyperfCommand
$params['user_id'] = $user_doctor['user_id'];
$params['type'] = 2;
$params['is_latest'] = 1;
$doctor_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'doctor');
$doctor_user_ca_cert = UserCaCert::getOne($params);
if (empty($doctor_user_ca_cert)){
$this->line("错误:无医生ca数据");
return false;
@@ -668,7 +649,7 @@ class ReportRegulatoryCommand extends HyperfCommand
$params['user_id'] = $user_pharmacist['user_id'];
$params['type'] = 2;
$params['is_latest'] = 1;
$pharmacist_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'pharmacist');
$pharmacist_user_ca_cert = UserCaCert::getOne($params);
if (empty($pharmacist_user_ca_cert)){
$this->line("错误:无药师ca数据");
return false;
@@ -716,160 +697,6 @@ class ReportRegulatoryCommand extends HyperfCommand
$data['recipeNo'] = $order_prescription['order_prescription_id']; // 医院处方编号
$data['cityId'] = "510100"; // 城市ID(参考地区字段)
$pharmacist_ca_data = $this->getStoredPrescriptionCaData($order_prescription['order_prescription_id'], 'pharmacist');
$data['caSupplier'] = $pharmacist_ca_data['caSupplier'] ?? "";
$data['caSignType'] = $pharmacist_ca_data['caSignType'] ?? "";
$data['caSignTime'] = $pharmacist_ca_data['caSignTime'] ?? "";
$data['caSignOriginaltext'] = $pharmacist_ca_data['caSignOriginaltext'] ?? "";
$data['caSignText'] = $pharmacist_ca_data['caSignText'] ?? "";
return $data;
}
private function getReportTransferPrescriptionDataV2(array|object $order_inquiry, array|object $order_prescription): bool|array
{
$params = array();
$params['doctor_id'] = $order_prescription['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
$this->line("閿欒锛氬尰鐢熸暟鎹敊璇?");
return false;
}
$params = array();
$params['doctor_id'] = $order_prescription['doctor_id'];
$user_doctor_info = UserDoctorInfo::getOne($params);
if (empty($user_doctor_info)) {
$this->line("閿欒锛氬尰鐢熻鎯呮暟鎹敊璇?");
return false;
}
$params = array();
$params['department_custom_id'] = $user_doctor['department_custom_id'];
$hospital_department_custom = HospitalDepartmentCustom::getOne($params);
if (empty($hospital_department_custom)) {
$this->line("閿欒锛氬尰鐢熻嚜瀹氫箟鏁版嵁閿欒");
return false;
}
$params = array();
$params['family_id'] = $order_inquiry['family_id'];
$patient_family = PatientFamily::getOne($params);
if (empty($patient_family)) {
$this->line("閿欒锛氶棶璇婃偅鑰呮暟鎹敊璇?");
return false;
}
$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)) {
$this->line("閿欒锛氭偅鑰呴棶璇婄梾渚嬮敊璇?");
return false;
}
$params = array();
$params['pharmacist_id'] = $order_prescription['pharmacist_id'];
$user_pharmacist = UserPharmacist::getOne($params);
if (empty($user_pharmacist)) {
$this->line("閿欒锛氳嵂甯堟暟鎹敊璇?");
return false;
}
$params = array();
$params['pharmacist_id'] = $order_prescription['pharmacist_id'];
$user_pharmacist_info = UserPharmacistInfo::getOne($params);
if (empty($user_pharmacist_info)) {
$this->line("閿欒锛氳嵂甯堣鎯呮暟鎹敊璇?");
return false;
}
$params = array();
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
$order_prescription_icd = OrderPrescriptionIcd::getList($params);
if (empty($order_prescription_icd)) {
$this->line("閿欒锛氭棤澶嶈瘖鐤剧梾璇婃柇鏁版嵁");
return false;
}
$icd_name = "";
$icd_name_data = array_column($order_prescription_icd->toArray(), 'icd_name');
if (!empty($icd_name_data)) {
if (count($icd_name_data) > 1) {
$icd_name = implode('|', $icd_name_data);
} else {
$icd_name = $icd_name_data[0];
}
}
$order_prescription_product = $this->getPreProductData($order_prescription['order_prescription_id']);
if (empty($order_prescription_product)) {
$this->line("閿欒锛氭棤澶勬柟鍟嗗搧鏁版嵁");
return false;
}
$doctor_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'doctor');
if (empty($doctor_user_ca_cert)) {
$this->line("閿欒锛氭棤鍖荤敓ca鏁版嵁");
return false;
}
$pharmacist_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'pharmacist');
if (empty($pharmacist_user_ca_cert)) {
$this->line("閿欒锛氭棤鑽笀ca鏁版嵁");
return false;
}
$data = array();
$data['thirdUniqueid'] = $order_inquiry['order_inquiry_id'];
$data['orgName'] = "鎴愰兘閲戠墰娆f鐩哥収浜掕仈缃戝尰闄?";
$data['orgCode'] = "MA6CGUDA251010619D2112";
$data['section'] = $hospital_department_custom['department_name'];
$data['sectionCode'] = $hospital_department_custom['department_code'];
$data['docName'] = $user_doctor['user_name'];
$data['docCertificateNum'] = $user_doctor_info['qualification_cert_num'];
$data['pharmacistName'] = $user_pharmacist_info['card_name'];
$data['pharmacistOrg'] = "鎴愰兘閲戠墰娆f鐩哥収浜掕仈缃戝尰闄?";
$data['pharmacistCertificateNum'] = $user_pharmacist_info['qualification_cert_num'];
$data['furtherConsultNo'] = $order_inquiry['order_inquiry_id'];
$data['furtherConsultDiagnosis'] = $icd_name;
$data['patientName'] = $order_inquiry['patient_name'];
$data['patientSex'] = $order_inquiry['patient_sex'] == 0 ?: 1;
$data['patientAge'] = (int) $order_inquiry['patient_age'];
$data['patientIdcardType'] = 1;
$data['patientIdcardNum'] = $patient_family['id_number'];
$data['feeType'] = 1;
$data['medicalHistory'] = $order_inquiry_case['disease_desc'];
$data['recipeTime'] = $order_prescription['doctor_created_time'];
$data['recipeType'] = 2;
$data['reviewTime'] = $order_prescription['pharmacist_verify_time'];
$data['recipeUnitPrice'] = $order_prescription_product['amount_total'];
$data['drugName'] = $order_prescription_product['drug_name'];
$data['drugCode'] = $order_prescription_product['drug_code'];
$data['drugCommonName'] = $order_prescription_product['drug_common_name'];
$data['specification'] = $order_prescription_product['specification'];
$data['frequency'] = $order_prescription_product['frequency'];
$data['usage'] = $order_prescription_product['usage'];
$data['doseUnit'] = $order_prescription_product['dose_unit'];
$data['doseEachTime'] = $order_prescription_product['dose_each_time'];
$data['medicationDays'] = $order_prescription_product['medication_days'];
$data['quantity'] = $order_prescription_product['quantity'];
$data['drugPackage'] = $order_prescription_product['drug_package'];
$data['recipeAllPrice'] = $order_prescription_product['amount_total'];
$data['uploadTime'] = date("Y-m-d H:i:s", time());
$data['docCaSign'] = $doctor_user_ca_cert['cert_base64'];
$data['pharmacistCaSign'] = $pharmacist_user_ca_cert['cert_base64'];
$data['recipeNo'] = $order_prescription['order_prescription_id'];
$data['cityId'] = "510100";
$pharmacist_ca_data = $this->getStoredPrescriptionCaData($order_prescription['order_prescription_id'], 'pharmacist');
$data['caSupplier'] = $pharmacist_ca_data['caSupplier'] ?? "";
$data['caSignType'] = $pharmacist_ca_data['caSignType'] ?? "";
$data['caSignTime'] = $pharmacist_ca_data['caSignTime'] ?? "";
$data['caSignOriginaltext'] = $pharmacist_ca_data['caSignOriginaltext'] ?? "";
$data['caSignText'] = $pharmacist_ca_data['caSignText'] ?? "";
return $data;
}
@@ -909,9 +736,9 @@ class ReportRegulatoryCommand extends HyperfCommand
$specification = $item['product_spec']; // 规格
$frequency = $item['frequency_use']; // 使用频度
$usage = $item['single_use']; // 用法
$dose_unit = $item['single_unit']; // 剂量单位
$dose_each_time = $item['single_unit']; // 每次剂量
$medication_days = (double)$item['available_days']; // 用药天数
$dose_unit = $product['single_unit']; // 剂量单位
$dose_each_time = $product['single_unit']; // 每次剂量
$medication_days = (double)$product['available_days']; // 用药天数
$quantity = (double)$item['prescription_product_num']; // 数量
$drug_package = $item['packaging_unit']; // 药品包装
} else {
@@ -921,22 +748,14 @@ class ReportRegulatoryCommand extends HyperfCommand
$specification = $specification . "|" . $item['product_spec']; // 规格
$frequency = $frequency . "|" . $item['frequency_use']; // 使用频度
$usage = $usage . "|" . $item['single_use']; // 用法
$dose_unit = $dose_unit . "|" . $item['single_unit']; // 剂量单位
$dose_each_time = $dose_each_time . "|" . $item['single_unit']; // 每次剂量
$medication_days = $medication_days . "|" . (double)$item['available_days']; // 用药天数
$dose_unit = $dose_unit . "|" . $product['single_unit']; // 剂量单位
$dose_each_time = $dose_each_time . "|" . $product['single_unit']; // 每次剂量
$medication_days = $medication_days . "|" . (double)$product['available_days']; // 用药天数
$quantity = $quantity . "|" . (double)$item['prescription_product_num']; // 数量
$drug_package = $drug_package . "|" . $item['packaging_unit']; // 药品包装
}
$amount_total = bcadd(
(string) $amount_total,
bcmul(
(string) ($item['product_price'] ?? $product['product_price'] ?? 0),
(string) $item['prescription_product_num'],
2
),
2
);
$amount_total += $item['product_price'] * $item['prescription_product_num'];
}
$result = array();
@@ -956,121 +775,11 @@ class ReportRegulatoryCommand extends HyperfCommand
return $result;
}
private function getPreProductDetailData(string $order_prescription_id): array
{
$params = array();
$params['order_prescription_id'] = $order_prescription_id;
$order_prescription_product = OrderPrescriptionProduct::getList($params);
if (empty($order_prescription_product)) {
$this->line("错误:无处方药品数据");
return [];
}
$result = [];
foreach ($order_prescription_product as $item) {
$params = array();
$params['product_id'] = $item['product_id'];
$product = Product::getWithAmountOne($params);
if (empty($product)) {
$this->line("错误:无药品数据");
return [];
}
$amount_total = bcmul(
(string) ($item['product_price'] ?? $product['product_price'] ?? 0),
(string) $item['prescription_product_num'],
2
);
$result[] = [
'drug_name' => (string) ($item['product_name'] ?? ''),
'drug_code' => (string) ($product['product_pharmacy_code'] ?? ''),
'drug_common_name' => (string) ($product['common_name'] ?? ''),
'specification' => (string) ($item['product_spec'] ?? ''),
'frequency' => (string) ($item['frequency_use'] ?? ''),
'usage' => (string) ($item['single_use'] ?? ''),
'dose_unit' => (string) ($item['single_unit'] ?? $product['single_unit'] ?? ''),
'dose_each_time' => (string) ($item['single_unit'] ?? $product['single_unit'] ?? ''),
'medication_days' => (string) ($item['available_days'] ?? $product['available_days'] ?? ''),
'quantity' => (string) $item['prescription_product_num'],
'drug_package' => (string) ($item['packaging_unit'] ?? ''),
'product_price' => (string) ($item['product_price'] ?? $product['product_price'] ?? 0),
'amount_total' => $amount_total,
];
}
return $result;
}
private function getReportPrescriptionDetailData(
array|object $order_prescription,
array $report_prescription_data
): array {
$product_details = $this->getPreProductDetailData((string) $order_prescription['order_prescription_id']);
if (empty($product_details)) {
return [];
}
$result = [];
foreach ($product_details as $detail) {
$row = $report_prescription_data;
$row['recipeUnitPrice'] = $detail['product_price'];
$row['drugName'] = $detail['drug_name'];
$row['drugCode'] = $detail['drug_code'];
$row['drugCommonName'] = $detail['drug_common_name'];
$row['specification'] = $detail['specification'];
$row['frequency'] = $detail['frequency'];
$row['usage'] = $detail['usage'];
$row['doseUnit'] = $detail['dose_unit'];
$row['doseEachTime'] = $detail['dose_each_time'];
$row['medicationDays'] = $detail['medication_days'];
$row['quantity'] = $detail['quantity'];
$row['drugPackage'] = $detail['drug_package'];
$row['recipeAllPrice'] = $detail['amount_total'];
$row['uploadTime'] = date("Y-m-d H:i:s", time());
$result[] = $row;
}
return $result;
}
/**
* 获取上报数据-网络咨询
* @param array|object $order_inquiry
* @return array
*/
private function getStoredPrescriptionCaData(string|int $order_prescription_id, string $role): array
{
$params = array();
$params['order_prescription_id'] = $order_prescription_id;
$order_prescription_file = OrderPrescriptionFile::getOne($params);
if (empty($order_prescription_file)) {
return [];
}
$prefix = $role === 'doctor' ? 'doctor' : 'pharmacist';
return [
'caSupplier' => (string) ($order_prescription_file[$prefix . '_ca_supplier'] ?? ''),
'caSignType' => (string) ($order_prescription_file[$prefix . '_ca_sign_type'] ?? ''),
'caSignTime' => (string) ($order_prescription_file[$prefix . '_ca_sign_time'] ?? ''),
'caSignOriginaltext' => (string) ($order_prescription_file[$prefix . '_ca_sign_originaltext'] ?? ''),
'caSignText' => (string) ($order_prescription_file[$prefix . '_ca_sign_text'] ?? ''),
];
}
private function buildLegacyCaCertPayload(string|int $order_prescription_id, string $role): array
{
$ca_data = $this->getStoredPrescriptionCaData($order_prescription_id, $role);
if (empty($ca_data['caSignText'])) {
return [];
}
return [
'cert_base64' => $ca_data['caSignText'],
];
}
private function getConsultData(array|object $order_inquiry): array
{
// 获取医生数据
@@ -1127,7 +836,6 @@ class ReportRegulatoryCommand extends HyperfCommand
$data['section'] = $hospital_department_custom['department_name'];//科室名称
$data['sectionCode'] = $hospital_department_custom['department_code'];//科室编码
$data['docName'] = $user_doctor['user_name'];// 姓名(医师、护师、技师)
$data['doc_idcard'] = $user_doctor_info['card_num']; // 医生身份证号
$data['certificateNum'] = $user_doctor_info['qualification_cert_num']; // 执业资格证号
$data['patientName'] = $order_inquiry['patient_name']; // 患者姓名
$data['patientAge'] = (int)$order_inquiry['patient_age']; // 患者年龄
@@ -1284,13 +992,6 @@ class ReportRegulatoryCommand extends HyperfCommand
$data['cityId'] = "510100"; // 城市ID(参考地区字段)
$data['isMark'] = 1;//是否留痕 1:代表留痕;0:代表未留痕
$doctor_ca_data = $this->getStoredPrescriptionCaData($order_prescription['order_prescription_id'], 'doctor');
$data['caSupplier'] = $doctor_ca_data['caSupplier'] ?? "";
$data['caSignType'] = $doctor_ca_data['caSignType'] ?? "";
$data['caSignTime'] = $doctor_ca_data['caSignTime'] ?? "";
$data['caSignOriginaltext'] = $doctor_ca_data['caSignOriginaltext'] ?? "";
$data['caSignText'] = $doctor_ca_data['caSignText'] ?? "";
return $data;
}
}
+74 -128
View File
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace App\Command;
use App\Model\Pharmacy;
use App\Model\Product;
use App\Model\ProductPlatform;
use App\Utils\Log;
@@ -22,18 +21,6 @@ use Symfony\Component\Console\Input\InputArgument;
#[Command]
class getProductCommand extends HyperfCommand
{
protected array $active_pharmacies = [];
protected function getPharmacy(string $code)
{
if (empty($this->active_pharmacies)) {
$list = Pharmacy::where('status', 1)->get();
foreach ($list as $p) {
$this->active_pharmacies[$p->pharmacy_code] = $p;
}
}
return $this->active_pharmacies[$code] ?? null;
}
public function __construct(protected ContainerInterface $container)
{
parent::__construct('getProduct:command');
@@ -45,109 +32,48 @@ class getProductCommand extends HyperfCommand
$this->setDescription('获取处方平台商品数据');
}
protected function logInfo(string $message): void
{
$this->line(date('Y-m-d H:i:s') . ' [INFO] ' . $message);
Log::getInstance('getProductCommand')->info($message);
}
protected function logWarn(string $message): void
{
$this->warn(date('Y-m-d H:i:s') . ' [WARN] ' . $message);
Log::getInstance('getProductCommand')->warning($message);
}
protected function logError(string $message): void
{
$this->error(date('Y-m-d H:i:s') . ' [ERROR] ' . $message);
Log::getInstance('getProductCommand')->error($message);
}
// 主逻辑处理
public function handle()
{
$startTime = microtime(true);
$this->logInfo("================== [getProductCommand] 处方平台商品目录同步开始 ==================");
$stats = [
'total_received' => 0,
'created' => 0,
'updated' => 0,
'unchanged' => 0,
'skipped_invalid' => 0,
'skipped_pharmacy' => 0,
'failed' => 0,
];
$this->line("商品更新开始");
try {
// 预加载已启用的药房列表
if (empty($this->active_pharmacies)) {
$list = Pharmacy::where('status', 1)->get();
foreach ($list as $p) {
$this->active_pharmacies[$p->pharmacy_code] = $p;
}
}
if (empty($this->active_pharmacies)) {
$this->logError("未找到任何已启用的药房配置,请先在药房管理中添加并启用药房后再执行同步");
return;
}
$pharmacyListStr = implode(', ', array_map(function ($p) {
return "{$p->pharmacy_name}({$p->pharmacy_code})";
}, array_values($this->active_pharmacies)));
$this->logInfo("当前系统已启用药房 (" . count($this->active_pharmacies) . " 个): [{$pharmacyListStr}]");
$prescription = new Prescription();
$page = 1;
$page_size = 100;
$result = $prescription->getProd(1, 100);
if (!empty($result['rows'])) {
foreach ($result['rows'] as $item) {
// 执行入库
$this->handleData($item);
}
$this->logInfo("正在请求第 1 页商品目录数据 (pageSize={$page_size})...");
$result = $prescription->getProd(1, $page_size);
$count = ceil($result['count'] / ($page * $page_size));
if (empty($result) || !isset($result['rows'])) {
$this->logWarn("处方平台未返回有效的商品目录数据,任务结束");
return;
}
if ($result['count'] > $page * $page_size) {
for ($i = 2; $i < $count; $i++) {
try {
$result = $prescription->getProd($i, $page_size);
if (!isset($result['rows'])) {
continue;
}
$totalCount = (int)($result['count'] ?? count($result['rows']));
$totalPages = (int)ceil($totalCount / $page_size);
$this->logInfo("处方平台商品目录查询成功: 平台总数据量={$totalCount} 条,总页数={$totalPages} 页");
// 处理第 1 页
$this->logInfo(">>> 正在处理第 1/{$totalPages} 页数据 (当前页 " . count($result['rows']) . " 条)...");
foreach ($result['rows'] as $item) {
$stats['total_received']++;
$this->handleData($item, $stats);
}
// 处理后续页
if ($totalPages > 1) {
for ($i = 2; $i <= $totalPages; $i++) {
$this->logInfo(">>> 正在请求并处理第 {$i}/{$totalPages} 页数据...");
try {
$pageResult = $prescription->getProd($i, $page_size);
if (!isset($pageResult['rows']) || empty($pageResult['rows'])) {
$this->logWarn("第 {$i} 页返回空数据,跳过");
continue;
foreach ($result['rows'] as $item) {
// 执行入库
$this->handleData($item);
}
} catch (\Exception $e) {
$this->line("部分商品更新失败:" . $e->getMessage());
}
foreach ($pageResult['rows'] as $item) {
$stats['total_received']++;
$this->handleData($item, $stats);
}
} catch (\Throwable $e) {
$this->logError("第 {$i} 页商品同步失败: " . $e->getMessage());
}
}
}
} catch (\Throwable $e) {
$this->logError("商品同步全局异常: " . $e->getMessage());
} catch (\Exception $e) {
$this->line("商品更新失败:" . $e->getMessage());
}
$duration = round(microtime(true) - $startTime, 2);
$this->logInfo("================== [getProductCommand] 处方平台商品目录同步完成 ==================");
$this->logInfo("总耗时: {$duration}s | 平台接收: {$stats['total_received']} 条 | 新增入库: {$stats['created']} 条 | 变更更新: {$stats['updated']} 条 | 资料无变动: {$stats['unchanged']} 条 | 非本院药房忽略: {$stats['skipped_pharmacy']} 条 | 字段缺失跳过: {$stats['skipped_invalid']} 条 | 处理失败: {$stats['failed']} 条");
$this->line("商品更新成功");
}
/**
@@ -164,25 +90,41 @@ class getProductCommand extends HyperfCommand
/**
* 入库
* @param array $item
* @param array $stats
* @return bool
*/
protected function handleData(array $item, array &$stats): bool
protected function handleData(array $item): bool
{
if (empty($item['drugCode']) || empty($item['drugPrice']) || empty($item['thirdCode']) || empty($item['thirdDrugCode']) || empty($item['approvalNumber'])) {
$drugName = $item['tradeName'] ?? '未知名';
$this->logWarn("【跳过-字段缺失】药品 [{$drugName}] 缺少必要字段(drugCode/drugPrice/thirdCode/thirdDrugCode/approvalNumber)");
$stats['skipped_invalid']++;
if (empty($item['drugCode'])) {
return false;
}
if (empty($item['drugPrice'])) {
return false;
}
if (empty($item['thirdCode'])) {
return false;
}
if (empty($item['thirdDrugCode'])) {
return false;
}
if (empty($item['approvalNumber'])) {
return false;
}
try {
Db::beginTransaction();
$pharmacy = $this->getPharmacy($item['thirdCode']);
if (empty($pharmacy)) {
$pharmacy_code = \Hyperf\Config\config("prescription_platform.pharmacy_code");
if (empty($pharmacy_code)) {
$pharmacy_code = "JG-10009";
}
// 非药店编码
if ($pharmacy_code != $item['thirdCode']) {
Db::rollBack();
$stats['skipped_pharmacy']++;
return false;
}
@@ -191,7 +133,6 @@ class getProductCommand extends HyperfCommand
$params['product_platform_code'] = $item['drugCode'];
$params['product_pharmacy_code'] = $item['thirdDrugCode'];
$params['license_number'] = $item['approvalNumber'];
$params['pharmacy_code'] = $item['thirdCode'];
$product_platform = ProductPlatform::getOne($params);
if (!empty($product_platform)) {
// 已存在,更新
@@ -248,7 +189,7 @@ class getProductCommand extends HyperfCommand
if (isset($item['packingUnit'])) {
if ($product_platform['retail_unit'] != $item['packingUnit']) {
$product_platform_data['retail_unit'] = $item['packingUnit'];
$product_data['packaging_unit'] = $item['packingUnit'];
$product_data['packaging_unit'] = $item['packingUnit']; // 平台返回零售包装单位为:盒,此结果适用于商品表的基本包装单位
}
}
@@ -273,10 +214,6 @@ class getProductCommand extends HyperfCommand
}
}
$product_platform_data['pharmacy_code'] = $item['thirdCode'];
$product_data['pharmacy_code'] = $item['thirdCode'];
$product_data['pharmacy_id'] = (string)$pharmacy->pharmacy_id;
if (!empty($product_platform_data)) {
// 更新商品表-处方平台
$params = array();
@@ -295,20 +232,19 @@ class getProductCommand extends HyperfCommand
Product::edit($params, $product_data);
}
}
$this->logInfo("【更新药品】药房 [{$pharmacy->pharmacy_name}({$item['thirdCode']})] 药品 [{$item['tradeName']}] (ID: {$product_platform['product_platform_id']}, 价格: {$item['drugPrice']})");
$stats['updated']++;
} else {
$stats['unchanged']++;
}
} else {
// 不存在,创建
$data = array();
$data['pharmacy_code'] = $item['thirdCode'];
// 商品名称
if (isset($item['tradeName'])) {
$data['product_name'] = $item['tradeName'];
}
// 商品价格
$data['product_price'] = $item['drugPrice'];
// 药品类型
if (isset($item['drugClassCode'])) {
if ($item['drugClassCode'] == 1) {
$data['product_type'] = 1;
@@ -319,25 +255,41 @@ class getProductCommand extends HyperfCommand
}
}
// 处方平台商品编码
$data['product_platform_code'] = $item['drugCode'];
// 第三方药店商品编码
$data['product_pharmacy_code'] = $item['thirdDrugCode'];
// 商品规格
if (isset($item['specifications'])) {
$data['product_spec'] = $item['specifications'];
}
// 批准文号
$data['license_number'] = $item['approvalNumber'];
// 生产厂家
if (isset($item['manufacturer'])) {
$data['manufacturer'] = $item['manufacturer'];
}
// 单次剂量单位
if (isset($item['defaultSingleDosageUnit'])) {
$data['single_unit'] = $item['defaultSingleDosageUnit'];
}
// 基本包装单位
if (isset($item['basicPackingUnit'])) {
$data['packaging_unit'] = $item['basicPackingUnit'];
}
// 基本包装数量
if (isset($item['basicPackingCount'])) {
$data['packaging_count'] = $item['basicPackingCount'];
}
// 零售包装单位
if (isset($item['packingUnit'])) {
$data['retail_unit'] = $item['packingUnit'];
}
@@ -345,20 +297,14 @@ class getProductCommand extends HyperfCommand
$product_platform = ProductPlatform::addProductPlatform($data);
if (empty($product_platform)) {
Db::rollBack();
$this->logError("【新增失败】药房 [{$pharmacy->pharmacy_name}({$item['thirdCode']})] 药品 [{$item['tradeName']}] 写入数据库失败");
$stats['failed']++;
return false;
$this->line("商品更新失败:" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
$this->logInfo("【新增入库】药房 [{$pharmacy->pharmacy_name}({$item['thirdCode']})] 药品 [{$item['tradeName']}] (平台编码: {$item['drugCode']}, 批准文号: {$item['approvalNumber']}, 价格: {$item['drugPrice']})");
$stats['created']++;
}
Db::commit();
} catch (\Throwable $e) {
} catch (\Exception $e) {
Db::rollBack();
$drugName = $item['tradeName'] ?? '未知名';
$this->logError("【更新异常】药品 [{$drugName}] (thirdDrugCode: {$item['thirdDrugCode']}) 异常: " . $e->getMessage());
$stats['failed']++;
$this->line("商品更新失败:" . $e->getMessage());
return false;
}
+60 -125
View File
@@ -7,7 +7,6 @@ namespace App\Command;
use App\Model\Product;
use App\Model\ProductAmountRecord;
use App\Model\ProductPlatformAmount;
use App\Utils\Log;
use Extend\Prescription\Prescription;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
@@ -31,188 +30,124 @@ class getProductStockCommand extends HyperfCommand
$this->setDescription('获取处方平台商品库存数据');
}
protected function logInfo(string $message): void
{
$this->line(date('Y-m-d H:i:s') . ' [INFO] ' . $message);
Log::getInstance('getProductStockCommand')->info($message);
}
protected function logWarn(string $message): void
{
$this->warn(date('Y-m-d H:i:s') . ' [WARN] ' . $message);
Log::getInstance('getProductStockCommand')->warning($message);
}
protected function logError(string $message): void
{
$this->error(date('Y-m-d H:i:s') . ' [ERROR] ' . $message);
Log::getInstance('getProductStockCommand')->error($message);
}
public function handle()
{
$startTime = microtime(true);
$this->logInfo("================== [getProductStockCommand] 商品库存更新开始 ==================");
$stats = [
'total' => 0,
'success' => 0,
'stock_changed' => 0,
'stock_unchanged' => 0,
'skipped' => 0,
'failed' => 0,
];
$this->line("商品库存更新开始");
try {
$pageSize = 20;
// 获取商品
$params = array();
$params['product_status'] = 1;
$product = Product::getPage($params, ['*'], 1, $pageSize);
if (empty($product['data'])) {
$this->logInfo("当前无可更新库存的在架商品,任务结束");
$product = Product::getPage($params,['*'],1,10);
if (empty($product['data'])){
$this->line("商品库存更新成功,无可更新库存商品");
return;
}
$totalCount = (int)($product['total'] ?? count($product['data']));
$lastPage = (int)($product['last_page'] ?? 1);
$this->logInfo("在架商品总数: {$totalCount} 件,共 {$lastPage} 页,每页批次: {$pageSize} 件");
$prescription = new Prescription();
for ($page = 1; $page <= $lastPage; $page++) {
if ($page > 1) {
$product = Product::getPage($params, ['*'], $page, $pageSize);
if (empty($product['data'])) {
break;
}
foreach ($product['data'] as $item){
if (!empty($item['product_pharmacy_code'])){
$result = $prescription->getProdStock($item['product_pharmacy_code']);
$this->handleData($item['product_platform_id'],$item['product_platform_code'],$result[0]);
}
}
$this->logInfo(">>> 正在处理第 {$page}/{$lastPage} 页商品库存 (当前页 " . count($product['data']) . " 件)...");
foreach ($product['data'] as $item) {
$stats['total']++;
if (empty($item['product_pharmacy_code'])) {
$this->logWarn("【跳过】商品 [{$item['product_name']}] (ID: {$item['product_id']}) 未配置第三方药品编码(product_pharmacy_code)");
$stats['skipped']++;
continue;
if ($product['last_page'] > 1){
for ($i = 2; $i <= $product['last_page']; $i++) {
// 获取商品
$params = array();
$product = Product::getPage($params,['*'],$i,10);
if (empty($product['data'])){
$this->line("商品库存更新成功,无可更新库存商品");
return;
}
$pharmacy_code = $item['pharmacy_code'] ?? '';
try {
$result = $prescription->getProdStock($item['product_pharmacy_code'], $pharmacy_code);
if (empty($result) || !isset($result[0])) {
$this->logWarn("【库存响应空】商品 [{$item['product_name']}] 药房 [{$pharmacy_code}] 平台未返回库存数据");
$stats['failed']++;
continue;
}
$prescription = new Prescription();
$res = $this->handleData($item, $result[0], $stats);
if ($res) {
$stats['success']++;
} else {
$stats['failed']++;
foreach ($product['data'] as $item){
if (!empty($item['product_pharmacy_code'])){
$result = $prescription->getProdStock($item['product_pharmacy_code']);
$this->handleData($item['product_platform_id'],$item['product_platform_code'],$result[0]);
}
} catch (\Throwable $e) {
$this->logError("【查询库存失败】商品 [{$item['product_name']}] (药店编码: {$item['product_pharmacy_code']}, 药房: {$pharmacy_code}) 异常: " . $e->getMessage());
$stats['failed']++;
}
}
}
} catch (\Throwable $e) {
$this->logError("商品库存更新全局异常:" . $e->getMessage());
} catch (\Exception $e) {
$this->line("商品库存更新失败:" . $e->getMessage());
}
$duration = round(microtime(true) - $startTime, 2);
$this->logInfo("================== [getProductStockCommand] 商品库存更新完成 ==================");
$this->logInfo("总耗时: {$duration}s | 检查总数: {$stats['total']} | 成功: {$stats['success']} (变动: {$stats['stock_changed']}, 未变: {$stats['stock_unchanged']}) | 跳过: {$stats['skipped']} | 失败: {$stats['failed']}");
$this->line("商品库存更新成功");
}
/**
* 入库
* @param Product|array $item
* @param string $product_platform_id
* @param string $product_platform_code
* @param array $resultData
* @param array $stats
* @return bool
*/
public function handleData(Product|array $item, array $resultData, array &$stats = []): bool
public function handleData(string $product_platform_id,string $product_platform_code,array $resultData): bool
{
$quantity = (int)($resultData['quantity'] ?? 0);
$product_platform_id = (string)$item['product_platform_id'];
$product_platform_code = (string)$item['product_platform_code'];
$product_name = (string)($item['product_name'] ?? '');
$pharmacy_code = (string)($item['pharmacy_code'] ?? '');
if (empty($resultData['quantity'])){
$resultData['quantity'] = 0;
}
try {
Db::beginTransaction();
// 当前库存数量
$stock = 0;
$params = array();
$params['product_platform_id'] = $product_platform_id;
$params['product_platform_code'] = $product_platform_code;
$product_platform_amount = ProductPlatformAmount::getSharedLockOne($params);
$old_stock = 0;
if (empty($product_platform_amount)) {
if (empty($product_platform_amount)){
// 无库存数据,新增
$data = array();
$data['product_platform_id'] = $product_platform_id;
$data['product_platform_code'] = $product_platform_code;
$data['stock'] = $quantity;
$data['stock'] = $resultData['quantity'];
$product_platform_amount = ProductPlatformAmount::addProductPlatformAmount($data);
if (empty($product_platform_amount)) {
if (empty($product_platform_amount)){
Db::rollBack();
$this->logError("商品 [{$product_name}] 新增库存数据失败: " . json_encode($data, JSON_UNESCAPED_UNICODE));
return false;
$this->line("商品库存更新失败,无法新增库存数据" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
$this->logInfo("【初始化库存】商品 [{$product_name}] 药房 [{$pharmacy_code}] 初始库存: {$quantity}");
$stats['stock_changed']++;
} else {
$old_stock = (int)$product_platform_amount['stock'];
}else{
$stock = $product_platform_amount['stock'];
// 存在库存数据,修改
$data = array();
$data['stock'] = $quantity;
$data['stock'] = $resultData['quantity'];
$params = array();
$params['amount_id'] = $product_platform_amount['amount_id'];
ProductPlatformAmount::edit($params, $data);
if ($old_stock !== $quantity) {
$diff = $quantity - $old_stock;
$diffStr = ($diff > 0 ? "+{$diff}" : "{$diff}");
$this->logInfo("【库存变动】商品 [{$product_name}] 药房 [{$pharmacy_code}] 原库存: {$old_stock} -> 最新库存: {$quantity} (变动: {$diffStr})");
$stats['stock_changed']++;
} else {
$this->logInfo("【库存无变化】商品 [{$product_name}] 药房 [{$pharmacy_code}] 当前库存: {$quantity}");
$stats['stock_unchanged']++;
}
ProductPlatformAmount::edit($params,$data);
}
// 增加库存记录(仅在库存发生变动或首次初始化时记录)
if ($old_stock !== $quantity || empty($product_platform_amount)) {
$params = array();
$params['product_platform_id'] = $product_platform_id;
$product = Product::getOne($params);
if (!empty($product)) {
$data = array();
$data['product_id'] = $product['product_id'];
$data['change_quantity'] = $quantity - $old_stock;
$data['quantity'] = $quantity;
$data['change_time'] = date('Y-m-d H:i:s', time());
$data['remark'] = "处方平台库存定时同步";
$product_amount_record = ProductAmountRecord::addProductAmountRecord($data);
if (empty($product_amount_record)) {
Db::rollBack();
$this->logError("商品 [{$product_name}] 增加库存流水记录失败: " . json_encode($data, JSON_UNESCAPED_UNICODE));
return false;
}
// 获取商品数据
$params = array();
$params['product_platform_id'] = $product_platform_id;
$product = Product::getOne($params);
if (!empty($product)){
// 增加库存记录
$data = array();
$data['product_id'] = $product['product_id'];
$data['change_quantity'] = $resultData['quantity'] - $stock; // 库存变动的数量 变动的库存-原库存
$data['quantity'] = $resultData['quantity']; // 变动后库存数量
$data['change_time'] = date('Y-m-d H:i:s',time());
$data['remark'] = "库存同步";
$product_amount_record = ProductAmountRecord::addProductAmountRecord($data);
if (empty($product_amount_record)){
Db::rollBack();
$this->line("商品库存更新失败,增加库存记录失败" . json_encode($data, JSON_UNESCAPED_UNICODE));
}
}
Db::commit();
} catch (\Throwable $e) {
Db::rollBack();
$this->logError("商品 [{$product_name}] 更新库存事务异常: " . $e->getMessage());
$this->line("商品库存更新失败:" . $e->getMessage());
return false;
}
@@ -1,45 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Request\DoctorPharmacyRequest;
use App\Services\DoctorPharmacyService;
use Psr\Http\Message\ResponseInterface;
class DoctorPharmacyController extends AbstractController
{
/**
* 获取医生绑定的药房列表
*/
public function getDoctorPharmacyList(): ResponseInterface
{
$service = new DoctorPharmacyService();
$data = $service->getDoctorPharmacyList();
return $this->response->json($data);
}
/**
* 设置医生默认药房
*/
public function setDoctorDefaultPharmacy(): ResponseInterface
{
$request = $this->container->get(DoctorPharmacyRequest::class);
$request->scene('setDefault')->validateResolved();
$service = new DoctorPharmacyService();
$data = $service->setDoctorDefaultPharmacy();
return $this->response->json($data);
}
/**
* 获取平台公开正常运营的药房列表
*/
public function getPublicPharmacyList(): ResponseInterface
{
$service = new DoctorPharmacyService();
$data = $service->getPublicPharmacyList();
return $this->response->json($data);
}
}
-6
View File
@@ -89,12 +89,6 @@ class TestController extends AbstractController
// 疾病名称
protected string $icd_name;
public function testError()
{
// 模拟触发 SQLSTATE[42S22]: Column not found 数据库报错
Db::select("SELECT nonexistent_column_test FROM gdxz_user_ca_cert LIMIT 1");
}
public function test(){
// $this->test_8();
// $this->test_3();
-132
View File
@@ -1,132 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Relations\HasOne;
use Hyperf\Snowflake\Concern\Snowflake;
/**
* @property int|string $doctor_pharmacy_id 主键ID
* @property int|string $doctor_id 医生ID
* @property int|string $pharmacy_id 药房ID
* @property int $is_default 是否默认药房(0:否 1:是)
* @property int $status 绑定状态(0:禁用 1:正常)
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
* @property-read Pharmacy|null $Pharmacy
* @property-read UserDoctor|null $UserDoctor
*/
class DoctorPharmacy extends Model
{
use Snowflake;
/**
* The table associated with the model.
*/
protected ?string $table = 'doctor_pharmacy';
/**
* The primary key for the model.
*/
protected string $primaryKey = 'doctor_pharmacy_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [
'doctor_pharmacy_id',
'doctor_id',
'pharmacy_id',
'is_default',
'status',
'created_at',
'updated_at',
];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = [
'doctor_pharmacy_id' => 'string',
'doctor_id' => 'string',
'pharmacy_id' => 'string',
'is_default' => 'integer',
'status' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* 关联药房信息表
*/
public function Pharmacy(): HasOne
{
return $this->hasOne(Pharmacy::class, 'pharmacy_id', 'pharmacy_id');
}
/**
* 关联医生表
*/
public function UserDoctor(): HasOne
{
return $this->hasOne(UserDoctor::class, 'doctor_id', 'doctor_id');
}
/**
* 获取医生当前绑定的有效默认药房(包含药房有效性及 pharmacy_code 非空校验)
*/
public static function getDoctorDefaultPharmacy(int|string $doctorId): ?Pharmacy
{
$bind = self::where([
'doctor_id' => (string) $doctorId,
'is_default' => 1,
'status' => 1,
])->first();
if (empty($bind)) {
return null;
}
$pharmacy = Pharmacy::getValidPharmacy($bind->pharmacy_id);
if (empty($pharmacy) || empty($pharmacy->pharmacy_code)) {
return null;
}
return $pharmacy;
}
/**
* 获取单条数据
*/
public static function getOne(array $params, array $fields = ['*']): ?self
{
return self::where($params)->first($fields);
}
/**
* 获取列表数据
*/
public static function getList(array $params = [], array $fields = ['*']): Collection
{
return self::where($params)->get($fields);
}
/**
* 新增绑定
*/
public static function addDoctorPharmacy(array $data): self
{
return self::create($data);
}
/**
* 修改
*/
public static function edit(array $params, array $data): int
{
return self::where($params)->update($data);
}
}
+1 -17
View File
@@ -36,16 +36,12 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property string $patient_name 患者姓名-就诊人
* @property int $patient_sex 患者性别-就诊人(1:男 2:女)
* @property int $patient_age 患者年龄-就诊人
* @property int|string $pharmacy_id 开方药房id
* @property string $pharmacy_code 开方药房代码快照
* @property string $pharmacy_name 开方药房名称快照
* @property string $doctor_advice 医嘱
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
* @property-read \Hyperf\Database\Model\Collection|OrderPrescriptionIcd[] $OrderPrescriptionIcd
* @property-read \Hyperf\Database\Model\Collection|OrderPrescriptionProduct[] $OrderPrescriptionProduct
* @property-read UserDoctor $UserDoctor
* @property-read Pharmacy|null $Pharmacy
*/
class OrderPrescription extends Model
{
@@ -59,22 +55,10 @@ class OrderPrescription extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['order_prescription_id', 'order_inquiry_id', 'doctor_id', 'pharmacy_id', 'pharmacy_code', 'pharmacy_name', 'patient_id', 'family_id', 'pharmacist_id', 'prescription_status', 'pharmacist_audit_status', 'pharmacist_verify_time', 'pharmacist_fail_reason', 'platform_audit_status', 'platform_fail_time', 'platform_fail_reason', 'is_auto_phar_verify', 'doctor_created_time', 'expired_time', 'is_delete', 'prescription_code', 'doctor_name', 'patient_name', 'patient_sex', 'patient_age', 'doctor_advice', 'created_at', 'updated_at'];
protected array $casts = [
'pharmacy_id' => 'string',
];
protected array $fillable = ['order_prescription_id', 'order_inquiry_id', 'doctor_id', 'patient_id', 'family_id', 'pharmacist_id', 'prescription_status', 'pharmacist_audit_status', 'pharmacist_verify_time', 'pharmacist_fail_reason', 'platform_audit_status', 'platform_fail_time', 'platform_fail_reason', 'is_auto_phar_verify', 'doctor_created_time', 'expired_time', 'is_delete', 'prescription_code', 'doctor_name', 'patient_name', 'patient_sex', 'patient_age', 'doctor_advice', 'created_at', 'updated_at'];
protected string $primaryKey = "order_prescription_id";
/**
* 关联药房表
*/
public function Pharmacy(): HasOne
{
return $this->hasOne(Pharmacy::class, 'pharmacy_id', 'pharmacy_id');
}
/**
* 关联处方疾病表
*/
+1 -1
View File
@@ -33,7 +33,7 @@ class OrderPrescriptionFile extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['prescription_file_id', 'order_prescription_id', 'doctor_ca_file_id', 'doctor_ca_supplier', 'doctor_ca_sign_type', 'doctor_ca_sign_originaltext', 'doctor_ca_sign_text', 'doctor_ca_sign_time', 'pharmacist_ca_supplier', 'pharmacist_ca_sign_type', 'pharmacist_ca_sign_originaltext', 'pharmacist_ca_sign_text', 'pharmacist_ca_sign_time', 'hospital_ca_file_id', 'prescription_img_oss_path', 'prescription_pdf_oss_path', 'is_converted_pdf', 'created_at', 'updated_at'];
protected array $fillable = ['prescription_file_id', 'order_prescription_id', 'doctor_ca_file_id', 'hospital_ca_file_id', 'prescription_img_oss_path', 'prescription_pdf_oss_path', 'is_converted_pdf', 'created_at', 'updated_at'];
protected string $primaryKey = "prescription_file_id";
+1 -1
View File
@@ -40,7 +40,7 @@ class OrderPrescriptionProduct extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['prescription_product_id', 'order_prescription_id', 'product_id', 'use_status', 'prescription_product_num', 'product_name', 'product_price', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'created_at', 'updated_at'];
protected array $fillable = ['prescription_product_id', 'order_prescription_id', 'product_id', 'use_status', 'prescription_product_num', 'product_name', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'created_at', 'updated_at'];
protected string $primaryKey = "prescription_product_id";
+1 -19
View File
@@ -55,17 +55,12 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property string $consignee_name_mask 收货人姓名(掩码)
* @property string $consignee_tel 收货人电话
* @property string $consignee_tel_mask 收货人电话(掩码)
* @property int|string $pharmacy_id 发货药房id
* @property string $pharmacy_code 发货药房代码快照
* @property string $pharmacy_name 发货药房名称快照
* @property int $delivery_type 配送方式(1:自提 2:快递)
* @property Carbon $created_at 创建时间
* @property Carbon $updated_at 修改时间
* @property-read Collection|OrderProductItem[]|null $OrderProductItem
* @property-read OrderPrescription|null $OrderPrescription
* @property-read PatientFamily|null $PatientFamily
* @property-read Collection|OrderPrescriptionIcd[]|null $OrderPrescriptionIcd
* @property-read Pharmacy|null $Pharmacy
*/
class OrderProduct extends Model
{
@@ -79,23 +74,10 @@ class OrderProduct extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'order_id', 'doctor_id', 'pharmacy_id', 'pharmacy_code', 'pharmacy_name', 'delivery_type', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'logistics_company_code', 'sub_logistics_status', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'report_pre_status', 'report_pre_time', 'report_pre_fail_reason', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
protected array $casts = [
'pharmacy_id' => 'string',
'delivery_type' => 'integer',
];
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'order_id', 'doctor_id', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'logistics_company_code', 'sub_logistics_status', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'report_pre_status', 'report_pre_time', 'report_pre_fail_reason', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
protected string $primaryKey = "order_product_id";
/**
* 关联药房表
*/
public function Pharmacy(): HasOne
{
return $this->hasOne(Pharmacy::class, 'pharmacy_id', 'pharmacy_id');
}
/**
* 关联订单商品item表
*/
-133
View File
@@ -1,133 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\Snowflake\Concern\Snowflake;
/**
* @property int|string $pharmacy_id 主键ID
* @property string $pharmacy_name 药房名称
* @property string $pharmacy_code 药房代码
* @property string $postage 基础邮费
* @property string $free_shipping_threshold 满额包邮门槛
* @property int $is_pickup 是否支持自提(0:否 1:是)
* @property string $telephone 联系电话
* @property int $province_id 省份ID
* @property string $province 省份名称
* @property int $city_id 城市ID
* @property string $city 城市名称
* @property int $county_id 区县ID
* @property string $county 区县名称
* @property string $address 详细地址
* @property int $status 状态(0:禁用 1:正常 2:删除)
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
* @property-read Collection|DoctorPharmacy[] $DoctorPharmacy
*/
class Pharmacy extends Model
{
use Snowflake;
/**
* The table associated with the model.
*/
protected ?string $table = 'pharmacy';
/**
* The primary key for the model.
*/
protected string $primaryKey = 'pharmacy_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [
'pharmacy_id',
'pharmacy_name',
'pharmacy_code',
'postage',
'free_shipping_threshold',
'is_pickup',
'telephone',
'province_id',
'province',
'city_id',
'city',
'county_id',
'county',
'address',
'status',
'created_at',
'updated_at',
];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = [
'pharmacy_id' => 'string',
'postage' => 'string',
'free_shipping_threshold' => 'string',
'is_pickup' => 'integer',
'province_id' => 'integer',
'city_id' => 'integer',
'county_id' => 'integer',
'status' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* 关联医生药房绑定表
*/
public function DoctorPharmacy(): HasMany
{
return $this->hasMany(DoctorPharmacy::class, 'pharmacy_id', 'pharmacy_id');
}
/**
* 获取单条有效药房数据
*/
public static function getValidPharmacy(int|string $pharmacyId): ?self
{
return self::where([
'pharmacy_id' => (string) $pharmacyId,
'status' => 1,
])->first();
}
/**
* 获取单条药房信息
*/
public static function getOne(array $params, array $fields = ['*']): ?self
{
return self::where($params)->first($fields);
}
/**
* 获取药房列表
*/
public static function getList(array $params = [], array $fields = ['*']): Collection
{
return self::where($params)->get($fields);
}
/**
* 分页查询药房
*/
public static function getPage(array $params, array $fields = ['*'], ?int $page = null, ?int $per_page = 10): array
{
$raw = self::where($params)->paginate($per_page, $fields, 'page', $page);
return [
'current_page' => $raw->currentPage(),
'total' => $raw->total(),
'data' => $raw->items(),
'per_page' => $raw->perPage(),
'last_page' => $raw->lastPage(),
];
}
}
+1 -7
View File
@@ -23,8 +23,6 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property int $product_type 药品类型(0:未知 1:中成药 2:西药)
* @property string $product_platform_code 处方平台商品编码
* @property string $product_pharmacy_code 第三方药店商品编码
* @property int|string $pharmacy_id 所属药房ID
* @property string $pharmacy_code 所属药房编码
* @property string $product_cover_img 商品封面图
* @property string $product_spec 商品规格
* @property string $license_number 批准文号
@@ -51,11 +49,7 @@ class Product extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['product_id', 'product_platform_id', 'pharmacy_id', 'pharmacy_code', 'product_status', 'is_delete', 'prescription_num', 'product_name', 'common_name', 'product_price', 'mnemonic_code', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_cover_img', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'product_remarks', 'created_at', 'updated_at'];
protected array $casts = [
'pharmacy_id' => 'string',
];
protected array $fillable = ['product_id', 'product_platform_id', 'product_status', 'is_delete', 'prescription_num', 'product_name', 'common_name', 'product_price', 'mnemonic_code', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_cover_img', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'product_remarks', 'created_at', 'updated_at'];
protected string $primaryKey = "product_id";
+1 -2
View File
@@ -16,7 +16,6 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property int $product_type 药品类型(0:未知 1:中成药 2:西药)
* @property string $product_platform_code 处方平台商品编码
* @property string $product_pharmacy_code 第三方药店商品编码
* @property string $pharmacy_code 所属药房编码
* @property string $product_spec 商品规格
* @property string $license_number 批准文号
* @property string $manufacturer 生产厂家
@@ -39,7 +38,7 @@ class ProductPlatform extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['product_platform_id', 'pharmacy_code', 'product_name', 'product_price', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'packaging_unit', 'packaging_count', 'retail_unit', 'created_at', 'updated_at'];
protected array $fillable = ['product_platform_id', 'product_name', 'product_price', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'packaging_unit', 'packaging_count', 'retail_unit', 'created_at', 'updated_at'];
protected string $primaryKey = "product_platform_id";
+2 -10
View File
@@ -76,17 +76,9 @@ class ReportRegulatory extends Model
* @param array $data
* @return ReportRegulatory|\Hyperf\Database\Model\Model
*/
// public static function addReportRegulatory(array $data): ReportRegulatory|\Hyperf\Database\Model\Model
// {
// return self::create($data);
// }
/**
* 暂时不上报监管
*/
public static function addReportRegulatory(array $data): bool
public static function addReportRegulatory(array $data): ReportRegulatory|\Hyperf\Database\Model\Model
{
// 直接返回成功,不执行创建操作
return true;
return self::create($data);
}
/**
-9
View File
@@ -121,15 +121,6 @@ class UserDoctor extends Model
return $this->hasMany(OrderInquiry::class, "doctor_id", "doctor_id");
}
/**
* 关联医生药房绑定表
* @return HasMany
*/
public function DoctorPharmacy(): HasMany
{
return $this->hasMany(DoctorPharmacy::class, "doctor_id", "doctor_id");
}
/**
* 获取医生信息-单条
* @param array $params
-35
View File
@@ -1,35 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Request;
use Hyperf\Validation\Request\FormRequest;
class DoctorPharmacyRequest extends FormRequest
{
protected array $scenes = [
'setDefault' => ['pharmacy_id'],
'bindPharmacy' => ['pharmacy_id'],
];
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'pharmacy_id' => 'required|numeric',
];
}
public function messages(): array
{
return [
'pharmacy_id.required' => '药房ID不能为空',
'pharmacy_id.numeric' => '药房ID必须为数字',
];
}
}
+1 -3
View File
@@ -32,7 +32,6 @@ class PatientOrderRequest extends FormRequest
"address_id",
"product_ids",
"client_type",
"delivery_type",
],
'getPatientPrescriptionOrderList' => [ // 获取处方订单列表
],
@@ -85,8 +84,7 @@ class PatientOrderRequest extends FormRequest
'order_no' => 'required',
'order_prescription_id' => 'required',
'address_id' => 'nullable',
'delivery_type' => ['nullable', 'integer', Rule::in([1, 2])],
'address_id' => 'required',
'product_ids' => 'required|array|min:1',
'detection_status' => 'required|integer|min:0|max:5',
'order_service_status' => 'required|integer|min:0|max:4',
-2
View File
@@ -56,7 +56,6 @@ class UserDoctorRequest extends FormRequest
'prescription_icd',// 诊断疾病[]
// 'doctor_advice', // 医嘱
'prescription_product',// 处方药品[]
'pharmacy_id', // 药房id(可选,未传则取默认药房)
],
'getDoctorMessageList' => [ // 获取医生问诊消息列表
'message_inquiry_type',// 消息订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:结束)
@@ -95,7 +94,6 @@ class UserDoctorRequest extends FormRequest
'prescription_icd' => 'required|array|min:1',
'doctor_advice' => 'required',
'prescription_product' => 'required|array|min:1|max:5',
'pharmacy_id' => 'nullable|numeric',
'message_inquiry_type' => 'required|integer|min:1|max:5',
];
}
-42
View File
@@ -16,8 +16,6 @@ use App\Model\HospitalDepartmentCustom;
use App\Model\HotSearchKeyword;
use App\Model\OperationManual;
use App\Model\Product;
use App\Model\DoctorPharmacy;
use App\Model\Pharmacy;
use Hyperf\Redis\Redis;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@@ -244,23 +242,6 @@ class BasicDataService extends BaseService
$params = array();
$params['product_status'] = 1;
$params['is_delete'] = 0;
// 若是医生端,则只展示医生选定/默认药房下的药品
if (isset($user_info['user_type']) && $user_info['user_type'] == 2) {
$doctor_id = $user_info['client_user_id'] ?? 0;
$pharmacy_id = $this->request->input('pharmacy_id');
if (isset($pharmacy_id) && $pharmacy_id !== '') {
$pharmacy = Pharmacy::getValidPharmacy($pharmacy_id);
} else {
$pharmacy = DoctorPharmacy::getDoctorDefaultPharmacy($doctor_id);
}
if (empty($pharmacy) || empty($pharmacy->pharmacy_code)) {
return success([]);
}
$params['pharmacy_code'] = $pharmacy->pharmacy_code;
}
$product = Product::getSearchKeywordList($params, $product_keyword,$fields);
if (empty($product)) {
return success();
@@ -468,29 +449,6 @@ class BasicDataService extends BaseService
$params = array();
$params['product_status'] = 1;
$params['is_delete'] = 0;
// 若是医生端,则只展示医生选定/默认药房下的药品
if (isset($user_info['user_type']) && $user_info['user_type'] == 2) {
$doctor_id = $user_info['client_user_id'] ?? 0;
$pharmacy_id = $this->request->input('pharmacy_id');
if (isset($pharmacy_id) && $pharmacy_id !== '') {
$pharmacy = Pharmacy::getValidPharmacy($pharmacy_id);
} else {
$pharmacy = DoctorPharmacy::getDoctorDefaultPharmacy($doctor_id);
}
if (empty($pharmacy) || empty($pharmacy->pharmacy_code)) {
return success([
'total' => 0,
'per_page' => (int)$per_page,
'current_page' => (int)$page,
'last_page' => 0,
'data' => [],
]);
}
$params['pharmacy_code'] = $pharmacy->pharmacy_code;
}
$product = Product::getWithAmountPage($params, $keyword,$fields, $page, $per_page);
if (empty($product['data'])) {
return success($product);
+20 -49
View File
@@ -56,8 +56,6 @@ class CaService extends BaseService
// 处方pdf oss地址
protected string $prescription_pdf_oss_path;
protected array $sign_result = [];
/**
* 初始化类,此处会获取基础数据
* @param array|object $order_prescription 处方表数据
@@ -256,33 +254,13 @@ class CaService extends BaseService
$data['product'][] = $product;
}
dump($this->entity_id);
$cert_sign_result = $CaOnline->getCertSign($this->entity_id, $this->entity_id, $data);
// 验证云证书签名 验证无需处理,只要不返回错误即可
$CaOnline->verifyPkcs7($cert_sign_result['signP7'], $data);
$this->cert_serial_number = $cert_sign_result['certSerialnumber'];
$sign_originaltext = hash_hmac("sha1", json_encode($data, JSON_UNESCAPED_UNICODE), config('ca.online.secret'));
$timestamp_sign = "";
try {
$timestamp_result = $CaOnline->getTimestampSign($sign_originaltext);
if (is_array($timestamp_result)) {
$timestamp_sign = $timestamp_result['signedData'] ?? "";
} elseif (is_string($timestamp_result)) {
$timestamp_sign = $timestamp_result;
}
} catch (\Throwable $throwable) {
$timestamp_sign = "";
}
$this->sign_result = [
'ca_supplier' => (string) config('regulatory_platform.ca_supplier', '2'),
'ca_sign_type' => (string) config('regulatory_platform.ca_sign_type', '1'),
'ca_sign_originaltext' => $sign_originaltext,
'ca_sign_text' => $cert_sign_result['signP7'] ?? "",
'ca_sign_time' => $timestamp_sign,
'cert_serial_number' => $cert_sign_result['certSerialnumber'] ?? "",
];
}
/**
@@ -290,11 +268,6 @@ class CaService extends BaseService
* @param array|object $order_prescription
* @return string
*/
public function getSignResult(): array
{
return $this->sign_result;
}
public function createPrescriptionImgPdf(array|object $order_prescription): string
{
// 打开基础处方图片
@@ -528,31 +501,29 @@ class CaService extends BaseService
$CaOnline = new CaOnline();
// 检测是否已添加签章配置
// $params = array();
// $params['cert_serial_number'] = $this->cert_serial_number;
// $user_ca_cert = UserCaCert::getOne($params);
// if (empty($user_ca_cert)){
// // Mock empty cert to bypass check when CA is skipped
// $user_ca_cert = ['is_sign_config' => 1, 'cert_id' => 0];
// }
$params = array();
$params['cert_serial_number'] = $this->cert_serial_number;
$user_ca_cert = UserCaCert::getOne($params);
if (empty($user_ca_cert)){
throw new BusinessException("未申请证书");
}
// if ($user_ca_cert['is_sign_config'] == 0){
// // 添加签章配置
// $data = array();
// $data['sign_param'] = json_encode($sign_param);
// $data['seal_img'] = $sign_image;
if ($user_ca_cert['is_sign_config'] == 0){
// 添加签章配置
$data = array();
$data['sign_param'] = json_encode($sign_param);
$data['seal_img'] = $sign_image;
// $CaOnline->addUserSignConfig($this->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'];
// $data = array();
// $data['sign_config'] = json_encode($sign_param);
// $data['is_sign_config'] = 1;
// UserCaCert::edit($params,$data);
// }
$params = array();
$params['cert_id'] = $user_ca_cert['cert_id'];
$data = array();
$data['sign_config'] = json_encode($sign_param);
$data['is_sign_config'] = 1;
UserCaCert::edit($params,$data);
}
// 打开处方pdf文件
$pdf_file = fopen($this->prescription_pdf_local_path, 'r');
-137
View File
@@ -1,137 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Services;
use App\Constants\HttpEnumCode;
use App\Model\DoctorPharmacy;
use App\Model\Pharmacy;
use Hyperf\DbConnection\Db;
class DoctorPharmacyService extends BaseService
{
/**
* 获取医生已绑定的药房列表
*/
public function getDoctorPharmacyList(): array
{
$user_info = $this->request->getAttribute("userInfo") ?? [];
$doctor_id = $user_info['client_user_id'] ?? 0;
if (empty($doctor_id)) {
return fail(HttpEnumCode::CLIENT_HTTP_UNAUTHORIZED, "用户未登录");
}
$list = DoctorPharmacy::with(['Pharmacy'])->where([
'doctor_id' => (string) $doctor_id,
'status' => 1,
])->get();
$data = [];
foreach ($list as $item) {
$pharmacy = $item->Pharmacy;
if (empty($pharmacy) || $pharmacy->status != 1) {
continue;
}
$data[] = [
'doctor_pharmacy_id' => $item->doctor_pharmacy_id,
'pharmacy_id' => $pharmacy->pharmacy_id,
'pharmacy_name' => $pharmacy->pharmacy_name,
'pharmacy_code' => $pharmacy->pharmacy_code,
'postage' => $pharmacy->postage,
'free_shipping_threshold' => $pharmacy->free_shipping_threshold,
'is_pickup' => $pharmacy->is_pickup,
'telephone' => $pharmacy->telephone,
'province' => $pharmacy->province,
'city' => $pharmacy->city,
'county' => $pharmacy->county,
'address' => $pharmacy->address,
'full_address' => $pharmacy->province . $pharmacy->city . $pharmacy->county . $pharmacy->address,
'is_default' => $item->is_default,
];
}
return success($data);
}
/**
* 设置医生默认药房
*/
public function setDoctorDefaultPharmacy(): array
{
$user_info = $this->request->getAttribute("userInfo") ?? [];
$doctor_id = $user_info['client_user_id'] ?? 0;
$pharmacy_id = $this->request->input('pharmacy_id');
if (empty($doctor_id)) {
return fail(HttpEnumCode::CLIENT_HTTP_UNAUTHORIZED, "用户未登录");
}
if (!isset($pharmacy_id) || $pharmacy_id === '') {
return fail(HttpEnumCode::HTTP_ERROR, "缺少药房ID");
}
// 验证医生是否绑定了该药房
$bind = DoctorPharmacy::where([
'doctor_id' => (string) $doctor_id,
'pharmacy_id' => (string) $pharmacy_id,
'status' => 1,
])->first();
if (empty($bind)) {
return fail(HttpEnumCode::HTTP_ERROR, "未绑定该药房或绑定已被禁用");
}
// 验证药房是否存在且有效
$pharmacy = Pharmacy::getValidPharmacy($pharmacy_id);
if (empty($pharmacy)) {
return fail(HttpEnumCode::HTTP_ERROR, "药房不存在或已暂停服务");
}
if (empty($pharmacy->pharmacy_code)) {
return fail(HttpEnumCode::HTTP_ERROR, "该药房未配置药房编码,无法设为默认药房");
}
Db::beginTransaction();
try {
// 将该医生所有绑定的 is_default 置为 0
DoctorPharmacy::where('doctor_id', (string) $doctor_id)->update(['is_default' => 0]);
// 将目标药房的 is_default 置为 1
DoctorPharmacy::where([
'doctor_id' => (string) $doctor_id,
'pharmacy_id' => (string) $pharmacy_id,
])->update(['is_default' => 1]);
Db::commit();
return success(null, "设置默认药房成功");
} catch (\Throwable $e) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR, "设置默认药房失败:" . $e->getMessage());
}
}
/**
* 获取平台公开正常运营的药房列表
*/
public function getPublicPharmacyList(): array
{
$list = Pharmacy::where('status', 1)->get([
'pharmacy_id',
'pharmacy_name',
'pharmacy_code',
'postage',
'free_shipping_threshold',
'is_pickup',
'telephone',
'province',
'city',
'county',
'address',
]);
return success($list->toArray());
}
}
+2 -13
View File
@@ -152,6 +152,7 @@ class OrderPrescriptionService extends BaseService
throw new BusinessException("医生开方日期错误");
}
dump($user_id);
$CaService = new CaService($order_prescription,$type,$user_id);
// 获取云证书签名+验证云证书签名
@@ -166,15 +167,9 @@ class OrderPrescriptionService extends BaseService
// 进行处方pdf签章
$file_id = $CaService->addSignPdf($type);
$sign_result = $CaService->getSignResult();
$result = array();
$result['prescription_img_oss_path'] = $prescription_img_oss_path ?? "";
$result['file_id'] = $file_id;
$result['ca_supplier'] = $sign_result['ca_supplier'] ?? "";
$result['ca_sign_type'] = $sign_result['ca_sign_type'] ?? "";
$result['ca_sign_originaltext'] = $sign_result['ca_sign_originaltext'] ?? "";
$result['ca_sign_text'] = $sign_result['ca_sign_text'] ?? "";
$result['ca_sign_time'] = $sign_result['ca_sign_time'] ?? "";
return $result;
} catch (\Throwable $e) {
@@ -405,12 +400,7 @@ class OrderPrescriptionService extends BaseService
$arg['payDate'] = $order_product['pay_time']; // 支付时间
$arg['money'] = $order_product['payment_amount_total']; // 订单金额
$arg['freight'] = $order_product['logistics_fee']; // 运费(单位:元)
$arg['takeTypeCode'] = ($order_product['delivery_type'] == 1) ? 1 : 2; // 取货方式 1 自提 2 快递
if (empty($order_product['pharmacy_code'])) {
throw new BusinessException("订单药房编码缺失,无法上报处方平台");
}
$arg['pharmacyOrganizationCode'] = $order_product['pharmacy_code'];//指定药店编码(门店订单必填,其他选填)"
$arg['pharmacyCode'] = $order_product['pharmacy_code'];//指定药店编码 (老文档参数)
$arg['takeTypeCode'] = 2; // 取货方式 1 自提 2 快递,目前只支持快递,传固定值 2
$arg['buyerName'] = $order_product['consignee_name'];// 收货人姓名
$arg['buyerPhone'] = $order_product['consignee_tel'];// 收货人联系方式
$arg['buyerAddress'] = $order_product['address'];// 收货人地址
@@ -422,7 +412,6 @@ class OrderPrescriptionService extends BaseService
$arg['districtName'] = $order_product['county']; // 收货地址(区 县)名称
$arg['presList'][0]['prescriptionNo'] = $order_prescription['prescription_code']; // 处方编号
$arg['presList'][0]['pharmacyCode'] = $order_product['pharmacy_code'];
$arg['presList'][0]['prescriptionSubType'] = 1; // 处方类型 0:无类型 1:普 通处方 2:儿科处 方
$arg['presList'][0]['patientName'] = $order_prescription['patient_name']; // 就诊人姓名
$arg['presList'][0]['patientPhone'] = $user['mobile']; // 就诊人联系方式
+45 -101
View File
@@ -42,7 +42,6 @@ use App\Model\PatientFamily;
use App\Model\PatientFamilyHealth;
use App\Model\PatientFamilyPersonal;
use App\Model\PatientFollow;
use App\Model\Pharmacy;
use App\Model\Product;
use App\Model\ProductPlatformAmount;
use App\Model\SystemInquiryConfig;
@@ -1483,7 +1482,6 @@ class PatientOrderService extends BaseService
$address_id = $this->request->input('address_id');
$product_ids = $this->request->input('product_ids');
$client_type = $this->request->input('client_type');
$delivery_type = (int)$this->request->input('delivery_type', 2); // 1: 自提 2: 快递
// 获取处方数据
$params = array();
@@ -1495,13 +1493,6 @@ class PatientOrderService extends BaseService
return fail();
}
// 获取处方药房信息
$pharmacy_id = $order_prescription['pharmacy_id'] ?? 0;
$pharmacy = Pharmacy::getValidPharmacy($pharmacy_id);
if (empty($pharmacy) || empty($pharmacy['pharmacy_code'])) {
return fail(HttpEnumCode::HTTP_ERROR, "处方所属药房异常,无法下单");
}
// 验证处方状态
if ($order_prescription['prescription_status'] == 1) {
return fail(HttpEnumCode::HTTP_ERROR, "处方未审核");
@@ -1525,28 +1516,13 @@ class PatientOrderService extends BaseService
return fail(HttpEnumCode::HTTP_ERROR, "创建订单失败");
}
// 检测收货方式及收货地址
$user_ship_address = null;
if ($delivery_type == 1) {
// 自提模式,检查药房是否支持自提
if ($pharmacy['is_pickup'] != 1) {
return fail(HttpEnumCode::HTTP_ERROR, "该药房不支持到店自提");
}
if (!empty($address_id)) {
$params = array();
$params['user_id'] = $user_info['user_id'];
$params['address_id'] = $address_id;
$user_ship_address = UserShipAddress::getOne($params);
}
} else {
// 快递模式,必须有收货地址
$params = array();
$params['user_id'] = $user_info['user_id'];
$params['address_id'] = $address_id;
$user_ship_address = UserShipAddress::getOne($params);
if (empty($user_ship_address)) {
return fail(HttpEnumCode::HTTP_ERROR, "收货地址错误");
}
// 检测收货地址
$params = array();
$params['user_id'] = $user_info['user_id'];
$params['address_id'] = $address_id;
$user_ship_address = UserShipAddress::getOne($params);
if (empty($user_ship_address)) {
return fail(HttpEnumCode::HTTP_ERROR, "收货地址错误");
}
$not_enough_product_ids = [];
@@ -1734,17 +1710,17 @@ class PatientOrderService extends BaseService
// 处理运费数据
$app_env = config('app_env', 'prod');
$logistics_fee = 0.00;
if ($delivery_type == 1) {
$logistics_fee = 0.00;
} else {
$postage = (float)($pharmacy['postage'] ?? 0.00);
$threshold = (float)($pharmacy['free_shipping_threshold'] ?? 0.00);
if ($threshold > 0 && (float)$freight_calculation_amount >= $threshold) {
$logistics_fee = 0.00;
} else {
$logistics_fee = $postage;
}
if (env("APP_ENV") == "prod") {
// $Prescription = new Prescription();
// $result = $Prescription->getLogisticsFee();
// if ($freight_calculation_amount < $result['drugCost']) {
// $logistics_fee = $result['freight'];
// }
//测试环境 运费
$logistics_fee = 7;
}else{
//测试环境 运费
$logistics_fee = 0;
}
// 实际支付金额=商品总金额-优惠卷金额+运费金额
@@ -1754,7 +1730,7 @@ class PatientOrderService extends BaseService
(string)$coupon_amount_total,
2
),
(string)$logistics_fee,
$logistics_fee,
2
);
@@ -1816,37 +1792,18 @@ class PatientOrderService extends BaseService
$data['coupon_amount_total'] = $coupon_amount_total; // 优惠卷总金额
$data['payment_amount_total'] = $payment_amount_total; // 实际付款金额
$data['logistics_fee'] = $logistics_fee; // 运费金额
$data['pharmacy_id'] = $pharmacy['pharmacy_id'];
$data['pharmacy_code'] = $pharmacy['pharmacy_code'];
$data['pharmacy_name'] = $pharmacy['pharmacy_name'];
$data['delivery_type'] = $delivery_type;
if (!empty($user_ship_address)) {
$data['province_id'] = $user_ship_address['province_id'];
$data['province'] = $user_ship_address['province'];
$data['city_id'] = $user_ship_address['city_id'];
$data['city'] = $user_ship_address['city'];
$data['county_id'] = $user_ship_address['county_id'];
$data['county'] = $user_ship_address['county'];
$data['address'] = $user_ship_address['address'];
$data['address_mask'] = $user_ship_address['address_mask'];
$data['consignee_name'] = $user_ship_address['consignee_name'];
$data['consignee_name_mask'] = $user_ship_address['consignee_name_mask'];
$data['consignee_tel'] = $user_ship_address['consignee_tel'];
$data['consignee_tel_mask'] = $user_ship_address['consignee_tel_mask'];
} else {
$data['province_id'] = 0;
$data['province'] = "";
$data['city_id'] = 0;
$data['city'] = "";
$data['county_id'] = 0;
$data['county'] = "";
$data['address'] = $pharmacy['pickup_address'] ?? "到店自提";
$data['address_mask'] = $pharmacy['pickup_address'] ?? "到店自提";
$data['consignee_name'] = $order_prescription['patient_name'] ?? "";
$data['consignee_name_mask'] = $order_prescription['patient_name'] ?? "";
$data['consignee_tel'] = "";
$data['consignee_tel_mask'] = "";
}
$data['province_id'] = $user_ship_address['province_id'];
$data['province'] = $user_ship_address['province'];
$data['city_id'] = $user_ship_address['city_id'];
$data['city'] = $user_ship_address['city'];
$data['county_id'] = $user_ship_address['county_id'];
$data['county'] = $user_ship_address['county'];
$data['address'] = $user_ship_address['address'];
$data['address_mask'] = $user_ship_address['address_mask'];
$data['consignee_name'] = $user_ship_address['consignee_name'];
$data['consignee_name_mask'] = $user_ship_address['consignee_name_mask'];
$data['consignee_tel'] = $user_ship_address['consignee_tel'];
$data['consignee_tel_mask'] = $user_ship_address['consignee_tel_mask'];
$order_product = OrderProduct::addOrderProduct($data);
if (empty($order_product)) {
Db::rollBack();
@@ -2197,10 +2154,7 @@ class PatientOrderService extends BaseService
$fields = [
"order_prescription_id",
"order_inquiry_id",
"pharmacy_id",
"pharmacy_code",
"pharmacy_name",
"order_inquiry_id"
];
$params = array();
@@ -2403,19 +2357,19 @@ class PatientOrderService extends BaseService
// 获取可用优惠卷总金额
$coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons);
// 获取运费金额及药房信息
$pharmacy_id = $order_prescription['pharmacy_id'] ?? 0;
$pharmacy = Pharmacy::getValidPharmacy($pharmacy_id);
$logistics_fee = 0.00;
if (!empty($pharmacy)) {
$postage = (float)($pharmacy['postage'] ?? 0.00);
$threshold = (float)($pharmacy['free_shipping_threshold'] ?? 0.00);
if ($threshold > 0 && (float)$freight_calculation_amount >= $threshold) {
$logistics_fee = 0.00;
} else {
$logistics_fee = $postage;
}
// 获取运费金额
$logistics_fee = 0;
if (env("APP_ENV") == "prod") {
// $Prescription = new Prescription();
// $result = $Prescription->getLogisticsFee();
// if ($freight_calculation_amount < $result['drugCost']) {
// $logistics_fee = $result['freight'];
// }
//测试环境 运费
$logistics_fee = 7;
}else{
//测试环境 运费
$logistics_fee = 0;
}
// 实际支付金额=商品总金额-优惠卷金额+运费金额
@@ -2445,16 +2399,6 @@ class PatientOrderService extends BaseService
$result['logistics_fee'] = $logistics_fee;
$result['user_ship_address'] = $user_ship_address;
$result['order_prescription_product'] = $order_prescription_products;
$result['pharmacy_info'] = !empty($pharmacy) ? [
'pharmacy_id' => (string)$pharmacy['pharmacy_id'],
'pharmacy_code' => $pharmacy['pharmacy_code'],
'pharmacy_name' => $pharmacy['pharmacy_name'],
'telephone' => $pharmacy['telephone'] ?? '',
'is_pickup' => $pharmacy['is_pickup'] ?? 0,
'postage' => (string)($pharmacy['postage'] ?? '0.00'),
'free_shipping_threshold' => (string)($pharmacy['free_shipping_threshold'] ?? '0.00'),
'pickup_address' => $pharmacy['pickup_address'] ?? '',
] : null;
return success($result);
}
+14 -48
View File
@@ -40,8 +40,6 @@ use App\Model\OrderServicePackageInquiry;
use App\Model\PatientFollow;
use App\Model\PatientHistoryInquiry;
use App\Model\PatientHistoryInquiry as PatientHistoryInquiryModel;
use App\Model\DoctorPharmacy;
use App\Model\Pharmacy;
use App\Model\Popup;
use App\Model\Product;
use App\Model\ProductPlatformAmount;
@@ -882,6 +880,10 @@ class UserDoctorService extends BaseService
$page = $this->request->input('page', 1);
$per_page = $this->request->input('per_page', 10);
if (empty($user_info)) {
return fail();
}
// 4-5分为好评、3分为中评、2-1分为差评
if ($evaluation_type == 1) {
// 全部
@@ -1201,24 +1203,9 @@ class UserDoctorService extends BaseService
$result['message'] = "成功";
$result['data'] = [];
// 校验医生是否已配置有效的默认药房
$doctor_id = $user_info['client_user_id'] ?? 0;
$default_pharmacy = DoctorPharmacy::getDoctorDefaultPharmacy($doctor_id);
if (empty($default_pharmacy)) {
$result['status'] = 2;
$result['message'] = "您尚未配置默认药房或药房已停用,请联系客服人员完成绑定后再开具处方";
return success($result);
}
$result['data']['default_pharmacy'] = [
'pharmacy_id' => (string)$default_pharmacy->pharmacy_id,
'pharmacy_code' => $default_pharmacy->pharmacy_code,
'pharmacy_name' => $default_pharmacy->pharmacy_name,
];
$params = array();
$params['order_inquiry_id'] = $order_inquiry_id;
$params['doctor_id'] = $doctor_id;
$params['doctor_id'] = $user_info['client_user_id'];
$order_prescription = OrderPrescription::getOne($params);
if (empty($order_prescription)){
return success($result);
@@ -1479,19 +1466,6 @@ class UserDoctorService extends BaseService
$doctor_advice = $this->request->input('doctor_advice');
$prescription_product = $this->request->input('prescription_product');
$disease_desc = $this->request->input('disease_desc'); // 病情主诉
$input_pharmacy_id = $this->request->input('pharmacy_id');
// 获取开方药房
$pharmacy = null;
if (isset($input_pharmacy_id) && $input_pharmacy_id !== '') {
$pharmacy = Pharmacy::getValidPharmacy($input_pharmacy_id);
} else {
$pharmacy = DoctorPharmacy::getDoctorDefaultPharmacy($user_info['client_user_id'] ?? 0);
}
if (empty($pharmacy) || empty($pharmacy['pharmacy_code'])) {
return fail(HttpEnumCode::HTTP_ERROR, "未找到有效的开方药房或药房已被停用,无法开具处方");
}
// 获取医生信息
$params = array();
@@ -1665,9 +1639,6 @@ class UserDoctorService extends BaseService
$data['patient_sex'] = $order_inquiry['patient_sex'];
$data['patient_age'] = $order_inquiry['patient_age'];
$data['doctor_advice'] = $doctor_advice;
$data['pharmacy_id'] = $pharmacy['pharmacy_id'];
$data['pharmacy_code'] = $pharmacy['pharmacy_code'];
$data['pharmacy_name'] = $pharmacy['pharmacy_name'];
$order_prescription = OrderPrescription::addOrderPrescription($data);
if (empty($order_prescription)) {
Db::rollBack();
@@ -1722,12 +1693,6 @@ class UserDoctorService extends BaseService
return fail(HttpEnumCode::HTTP_ERROR,"药品" . $product['product_name'] . "已被删除,无法开具");
}
// 校验药品所属药房是否与处方药房一致
if (!empty($product['pharmacy_code']) && $product['pharmacy_code'] !== $pharmacy['pharmacy_code']) {
Db::rollBack();
return fail(HttpEnumCode::HTTP_ERROR, "药品【" . $product['product_name'] . "】不属于当前药房");
}
// 检测药品是否超出最大可开数
if ($item['prescription_product_num'] > $product['prescription_num']) {
// 库存不足
@@ -1765,7 +1730,6 @@ class UserDoctorService extends BaseService
$data['product_id'] = $item['product_id'];
$data['prescription_product_num'] = $item['prescription_product_num'];
$data['product_name'] = $product['product_name'];
$data['product_price'] = $product['product_price'];
$data['product_spec'] = $product['product_spec'];
$data['license_number'] = $product['license_number'];
$data['manufacturer'] = $product['manufacturer'];
@@ -1835,11 +1799,6 @@ class UserDoctorService extends BaseService
$data = array();
$data['order_prescription_id'] = $order_prescription->order_prescription_id;
$data['doctor_ca_file_id'] = $prescription_open_result['file_id'];
$data['doctor_ca_supplier'] = $prescription_open_result['ca_supplier'] ?? "";
$data['doctor_ca_sign_type'] = $prescription_open_result['ca_sign_type'] ?? "";
$data['doctor_ca_sign_originaltext'] = $prescription_open_result['ca_sign_originaltext'] ?? "";
$data['doctor_ca_sign_text'] = $prescription_open_result['ca_sign_text'] ?? "";
$data['doctor_ca_sign_time'] = $prescription_open_result['ca_sign_time'] ?? "";
$data['prescription_img_oss_path'] = $prescription_open_result['prescription_img_oss_path'];
$order_prescription_file = OrderPrescriptionFile::addOrderPrescriptionFile($data);
if (empty($order_prescription_file)){
@@ -2527,12 +2486,15 @@ class UserDoctorService extends BaseService
$user_info = $this->request->getAttribute("userInfo") ?? [];
if (empty($user_info)){
return fail(HttpEnumCode::HTTP_SUCCESS, "请登录");
}
$result = array();
$result['hospital'] = [];
$result['days'] = 0;
$result['doctor_inquiry_config'] = [];
$result['is_online'] = 0;
$result['follow'] = false;
$fields = [
"doctor_id",
@@ -2581,7 +2543,7 @@ class UserDoctorService extends BaseService
}
// 患者
if (!empty($user_info) && $user_info['user_type'] == 1){
if ($user_info['user_type'] == 1){
// 获取服务天数
$params = array();
$params['patient_id'] = $user_info['client_user_id'];
@@ -2658,6 +2620,10 @@ class UserDoctorService extends BaseService
$user_info = $this->request->getAttribute("userInfo") ?? [];
if (empty($user_info)){
return fail(HttpEnumCode::HTTP_SUCCESS, "请登录");
}
$fields = [
"doctor_id",
"user_id",
-17
View File
@@ -1232,23 +1232,6 @@ class UserService extends BaseService
return $result;
}
// === 新增:投递上传OSS队列 ===
$mediaTypes = ['TIMImageElem', 'TIMSoundElem', 'TIMVideoFileElem', 'TIMFileElem'];
if (in_array($msg_data['MsgBody'][0]['MsgType'], $mediaTypes)) {
try {
$producer = \Hyperf\Context\ApplicationContext::getContainer()->get(\Hyperf\Amqp\Producer::class);
$producerMsg = new \App\Amqp\Producer\UploadImMediaProducer([
'message_key' => $msg_data['MsgKey'],
'msg_type' => $msg_data['MsgBody'][0]['MsgType'],
'msg_content' => $message_content,
]);
$producer->produce($producerMsg);
} catch (\Throwable $e) {
Log::getInstance("UserService-userImAfterSendMsg")->error("投递上传OSS队列失败: " . $e->getMessage());
}
}
// === 新增结束 ===
// im消息通知
if ($is_system == 0 && isset($message_send_result) && isset($order_inquiry_id)){
try {
+1 -9
View File
@@ -19,14 +19,7 @@ class Auth
"/login/wechat_mobile_login" => "post", // 微信登陆
"/login/mobile_login" => "post", // 手机号登陆
"/code/phone" => "post",// 获取手机号验证码
"/patient/doctor/inquiry" => "get", // 获取问诊医生列表
"/doctor/info/inquiry/" => "get", // 获取医生详情-问诊
"/doctor/inquiry/service/" => "get", // 获取医生开启的服务列表
"/patient/doctor/evaluation/" => "get", // 获取医生评价
"/basic/disease/expertise" => "get",// 疾病专长列表-搜索使用
"/patient/article/science" => "get", // 科普文章分页
"/patient/article/science/list" => "get", // 科普文章列表
"/evaluation" => "get", // 获取医生评价列表
"/disease/expertise" => "get",// 疾病专长列表-搜索使用
"/area/province" => "get",// 获取省份信息
"/area/city" => "get", // 获取城市信息
"/area/county" => "get", // 获取区县信息
@@ -46,7 +39,6 @@ class Auth
"/basic/keyword/search" => "get", // 获取热门搜索关键词
"/test/uninquiry" => "get", // 获取未接诊的医生
"/test/refund" => "post", // 测试退款
"/test/error" => "get", // 测试报错
"/test" => "get", // 测试
"/callback/detection" => "post", // 检测所结果回调
"/callback/video/trtc" => "post", // 音视频回调
+2 -2
View File
@@ -25,8 +25,8 @@ class Log
self::getInstance()->{$name}(...$arguments);
}
public static function getInstance(string $name = 'app', string $group = 'default'): LoggerInterface
public static function getInstance(string $name = 'app'): LoggerInterface
{
return ApplicationContext::getContainer()->get(LoggerFactory::class)->get($name, $group);
return ApplicationContext::getContainer()->get(LoggerFactory::class)->get($name);
}
}
-30
View File
@@ -51,34 +51,4 @@ return [
],
'formatter' => $formatter,
],
'regulatory_platform_http_detail' => [
'handler' => [
'class' => Monolog\Handler\RotatingFileHandler::class,
'constructor' => [
'filename' => BASE_PATH . '/runtime/logs/regulatory-platform-http-detail.log',
'level' => Monolog\Logger::INFO,
],
],
'formatter' => $formatter,
],
'regulatory_platform_business' => [
'handler' => [
'class' => Monolog\Handler\RotatingFileHandler::class,
'constructor' => [
'filename' => BASE_PATH . '/runtime/logs/regulatory-platform-business.log',
'level' => Monolog\Logger::INFO,
],
],
'formatter' => $formatter,
],
'regulatory_platform_token' => [
'handler' => [
'class' => Monolog\Handler\RotatingFileHandler::class,
'constructor' => [
'filename' => BASE_PATH . '/runtime/logs/regulatory-platform-token.log',
'level' => Monolog\Logger::INFO,
],
],
'formatter' => $formatter,
],
];
-6
View File
@@ -121,12 +121,6 @@ return [
"client_id" => env('REG_PLAT_CLIENT_ID', '09b117f8d1eb4dbfbf565447205ea60f'),
"client_secret" => env('REG_PLAT_CLIENT_SECRET', 'dcfd9223a3f448b0aae83ce22cdcc015'),
"api_url" => env('REG_PLAT_APP_URL', 'https://202.61.88.184:19200/'),
"sm4_key" => env('REG_PLAT_SM4_KEY', 'e0e295da97ed46cc9ad71b61ed361721'),
"sm4_iv" => env('REG_PLAT_SM4_IV', '8a1f69a58603416a9d5b93c4bb67f72f'),
"sm2_private_key" => env('REG_PLAT_SM2_PRIVATE_KEY', 'bbc97b0418cc92b8f3b7b7764e554beed6b3adb1aa9bfb9e7839583e5ccf4722'),
"sm2_public_key" => env('REG_PLAT_SM2_PUBLIC_KEY', '04fca188451748a35b8c14890a0270fbe787e74f2286b72f6305939c8d527d1fd9fec2926cc0ff6c4f04cfbee2a3d65230565691a8f8453b44665d2b6fbbc79c91'),
"ca_supplier" => env('REG_PLAT_CA_SUPPLIER', '2'),
"ca_sign_type" => env('REG_PLAT_CA_SIGN_TYPE', '1'),
],
'kuaidi100' => [ // 快递100
"key" => env('LOGISTICS_KEY', 'Mpjjgebe8764'),
-14
View File
@@ -18,7 +18,6 @@ use App\Controller\DetectionController;
use App\Controller\DoctorAccountController;
use App\Controller\DoctorAuthController;
use App\Controller\DoctorInquiryConfigController;
use App\Controller\DoctorPharmacyController;
use App\Controller\IndexController;
use App\Controller\InquiryController;
use App\Controller\LoginController;
@@ -260,15 +259,6 @@ Router::addGroup('/doctor', function () {
Router::get('/check', [UserDoctorController::class, 'checkOpenPrescription']);
});
// 药房
Router::addGroup('/pharmacy', function () {
// 获取医生绑定的药房列表
Router::get('', [DoctorPharmacyController::class, 'getDoctorPharmacyList']);
// 设置医生默认药房
Router::put('/default', [DoctorPharmacyController::class, 'setDoctorDefaultPharmacy']);
});
// 常用语
Router::addGroup('/words', function () {
// 获取常用语列表
@@ -782,9 +772,6 @@ Router::addGroup('/basic', function () {
// 获取检测疾病分类列表
Router::get('/detection/disease', [BasicDataController::class, 'getDetectionDiseaseList']);
// 获取公共药房列表
Router::get('/pharmacy', [DoctorPharmacyController::class, 'getPublicPharmacyList']);
});
// 获取医生评价
@@ -925,7 +912,6 @@ Router::addGroup('/case', function () {
// 测试使用
Router::addGroup('/test', function () {
Router::get('', [TestController::class, 'test']);
Router::get('/error', [TestController::class, 'testError']);
// 获取未接诊的医生
Router::get('/uninquiry', [TestController::class, 'uninquiry']);
-36
View File
@@ -46,7 +46,6 @@ abstract class Ca
*/
public function getCertSign(string $user_id, string $pin, array $data): mixed
{
return ['signP7' => 'mock_sign_p7', 'certSerialnumber' => 'mock_serial_number'];
$option = [
'form_params' => [
'entityId' => $user_id, // 用户唯一标识,由业务系统定义
@@ -78,7 +77,6 @@ abstract class Ca
*/
public function verifyPkcs7(string $sign_p7, array $data)
{
return true;
$generator = $this->container->get(IdGeneratorInterface::class);
$option = [
@@ -112,40 +110,8 @@ abstract class Ca
* @param array $data
* @return bool
*/
/**
* Timestamp sign service.
* @param string $to_sign
* @return mixed
*/
public function getTimestampSign(string $to_sign): mixed
{
return ['signedData' => 'mock_timestamp_sign'];
$generator = $this->container->get(IdGeneratorInterface::class);
$option = [
'form_params' => [
'requestId' => $generator->generate(),
'toSign' => $to_sign,
]
];
try {
$response = $this->httpRequest(
$this->api_url . '/signgw-service/api/signgw/timestamap/sign',
$option
);
if (empty($response)) {
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
}
return $response;
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
}
}
public function addUserSignConfig(string $user_id, string $card_num, array $data): bool
{
return true;
$arg = [
'form_params' => [
'userId' => $user_id,//用户标识信息(为云证书entityId)
@@ -263,7 +229,6 @@ abstract class Ca
*/
public function addSignPdf(string $user_id, array $data): mixed
{
return [['fileId' => 'mock_file_id']];
$option = [
'multipart' => [
[
@@ -313,7 +278,6 @@ abstract class Ca
*/
public function getSignedFile(string $entity_id, string $file_id): string
{
return "mock_pdf_content";
$arg = [
'form_params' => [
'userId' => $entity_id,// 用户标识信息(为云证书entityId)
+9 -13
View File
@@ -106,7 +106,7 @@ class Prescription
),
];
Log::getInstance()->info("处方平台获取药品请求数据:" . json_encode($option,JSON_UNESCAPED_UNICODE));
// Log::getInstance()->info("处方平台获取药品请求数据:" . json_encode($option,JSON_UNESCAPED_UNICODE));
try {
$response = $this->httpRequest($this->api_url . $this->version . '/drug/syncDrugCatalogue', $option);
if (empty($response['data'])){
@@ -121,11 +121,11 @@ class Prescription
if (empty($response['data']['result'])){
// 返回值为空
Log::getInstance()->error("处方平台获取药品返回result为空:" . json_encode($response,JSON_UNESCAPED_UNICODE));
// Log::getInstance()->error("处方平台获取药品返回result为空:" . json_encode($response,JSON_UNESCAPED_UNICODE));
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
}
Log::getInstance()->info("处方平台获取药品返回数据:" . json_encode($response,JSON_UNESCAPED_UNICODE));
// Log::getInstance()->info("处方平台获取药品返回数据:" . json_encode($response,JSON_UNESCAPED_UNICODE));
return $response['data']['result'];
} catch (GuzzleException $e) {
Log::getInstance()->error("处方平台获取药品请求异常:" . $e->getMessage());
@@ -136,15 +136,13 @@ class Prescription
/**
* 获取商品库存
* @param string $product_platform_code 处方平台商品编码(此处使用第三方药店商品编码!)
* @param string $pharmacy_code 药房编码
* @return array
*/
public function getProdStock(string $product_platform_code, string $pharmacy_code = ""): array
public function getProdStock(string $product_platform_code): array
{
$code = !empty($pharmacy_code) ? $pharmacy_code : $this->pharmacy_code;
$option = [
"json" => array(
"pharmacyCode" => $code,
"pharmacyCode" => $this->pharmacy_code,
"drugCode" => $product_platform_code,
),
];
@@ -167,15 +165,13 @@ class Prescription
/**
* 获取运费
* @param string $pharmacy_code 药房编码
* @return array
*/
public function getLogisticsFee(string $pharmacy_code = ""): array
public function getLogisticsFee(): array
{
$code = !empty($pharmacy_code) ? $pharmacy_code : $this->pharmacy_code;
$option = [
"json" => array(
"pharmacyCode" => $code,
"pharmacyCode" => $this->pharmacy_code,
),
];
@@ -208,14 +204,14 @@ class Prescription
"json" => $arg
];
Log::getInstance()->info("处方平台上报数据:" . json_encode($option,JSON_UNESCAPED_UNICODE));
// Log::getInstance()->info("处方平台上报数据:" . json_encode($option,JSON_UNESCAPED_UNICODE));
try {
$response = $this->httpRequest($this->api_url . $this->version . '/preOrder/receivePreOrder', $option);
if (empty($response)){
// 返回值错误为空
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
}
Log::getInstance()->info("处方平台返回数据:" . json_encode($response,JSON_UNESCAPED_UNICODE));
// Log::getInstance()->info("处方平台返回数据:" . json_encode($response,JSON_UNESCAPED_UNICODE));
return $response;
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
@@ -1,595 +0,0 @@
<?php
declare(strict_types=1);
namespace Extend\RegulatoryPlatform;
use App\Exception\BusinessException;
use function Hyperf\Config\config;
class RegulatoryPlatformProtocol
{
protected const SM2_CURVE_OID = '1.2.156.10197.1.301';
protected const EC_PUBLIC_KEY_OID = '1.2.840.10045.2.1';
protected ?string $clientId;
protected ?string $clientSecret;
protected ?string $sm4KeyHex;
protected ?string $sm4IvHex;
protected ?string $sm2PrivateKey;
protected ?string $sm2PublicKey;
public function __construct(array $config = [])
{
$this->clientId = $this->resolveConfigValue($config, [
'client_id',
'v2.client_id',
'prod.client_id',
'default.client_id',
]);
$this->clientSecret = $this->resolveConfigValue($config, [
'client_secret',
'v2.client_secret',
'prod.client_secret',
'default.client_secret',
]);
$this->sm4KeyHex = $this->resolveConfigValue($config, [
'sm4_key',
'encrypt_key',
'v2.sm4_key',
'crypto.sm4_key',
'sm4.key',
]);
$this->sm4IvHex = $this->resolveConfigValue($config, [
'sm4_iv',
'encrypt_iv',
'v2.sm4_iv',
'crypto.sm4_iv',
'sm4.iv',
]);
$this->sm2PrivateKey = $this->resolveConfigValue($config, [
'sm2_private_key',
'sign_private_key',
'v2.sm2_private_key',
'crypto.sm2_private_key',
'sm2.private_key',
]);
$this->sm2PublicKey = $this->resolveConfigValue($config, [
'sm2_public_key',
'verify_public_key',
'platform_public_key',
'v2.sm2_public_key',
'crypto.sm2_public_key',
'sm2.public_key',
]);
}
public static function fromConfig(?array $config = null): self
{
$config ??= (array) config('regulatory_platform', []);
return new self($config);
}
public function getClientId(): ?string
{
return $this->clientId;
}
public function getClientSecret(): ?string
{
return $this->clientSecret;
}
public function buildRequestEnvelope(
array $payload,
bool $includeClientId = false,
?string $clientId = null,
?string $clientSecret = null
): array {
$plainText = $this->encodeCanonicalJson($payload, true);
return $this->buildRequestEnvelopeFromPlainText($plainText, $includeClientId, $clientId, $clientSecret);
}
public function buildRequestEnvelopeFromPlainText(
string $plainText,
bool $includeClientId = false,
?string $clientId = null,
?string $clientSecret = null
): array {
$resolvedClientId = $clientId ?? $this->requireClientId();
$resolvedClientSecret = $clientSecret ?? $this->requireClientSecret();
$encryptedHex = $this->encrypt($plainText);
$sign = $this->sign($this->buildSignString($resolvedClientId, $encryptedHex, $resolvedClientSecret));
$envelope = [
'sign' => $sign,
'data' => $encryptedHex,
];
if ($includeClientId) {
$envelope['client_id'] = $resolvedClientId;
}
return $envelope;
}
public function decodeResponseEnvelope(
array $response,
bool $verifySignature = false,
?string $clientId = null,
?string $clientSecret = null
): array {
$envelope = $this->extractResponseEnvelope($response);
$resolvedClientId = $clientId ?? $this->requireClientId();
$resolvedClientSecret = $clientSecret ?? $this->requireClientSecret();
if ($verifySignature) {
$verified = $this->verify(
$this->buildSignString($resolvedClientId, $envelope['data'], $resolvedClientSecret),
$envelope['sign']
);
if (! $verified) {
throw new BusinessException('监管平台响应验签失败');
}
}
$plainText = $this->decrypt($envelope['data']);
$decoded = json_decode($plainText, true);
if (! is_array($decoded)) {
throw new BusinessException('监管平台响应解密成功,但 JSON 解析失败');
}
return [
'envelope' => $envelope,
'plain_text' => $plainText,
'decoded' => $decoded,
];
}
public function buildSignString(string $clientId, string $encryptedHex, ?string $clientSecret = null): string
{
$resolvedClientSecret = $clientSecret ?? $this->requireClientSecret();
return sprintf('client_id=%s&data=%s&key=%s', $clientId, $encryptedHex, $resolvedClientSecret);
}
public function encodeCanonicalJson(array $payload, bool $removeEmptyValues = true): string
{
$normalized = $this->canonicalizePayload($payload, $removeEmptyValues);
$json = json_encode(
$normalized,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION
);
if ($json === false) {
throw new BusinessException('监管平台请求 JSON 编码失败');
}
return $json;
}
public function canonicalizePayload(array $payload, bool $removeEmptyValues = true): array
{
$normalized = $this->normalizeValue($payload, $removeEmptyValues);
if (! is_array($normalized)) {
throw new BusinessException('监管平台请求体格式错误');
}
return $normalized;
}
public function encrypt(string $plainText): string
{
$key = $this->decodeHex($this->requireSm4Key(), 'SM4 key');
$iv = $this->decodeHex($this->requireSm4Iv(), 'SM4 iv');
$cipherText = openssl_encrypt($plainText, 'sm4-cbc', $key, OPENSSL_RAW_DATA, $iv);
if ($cipherText === false) {
throw new BusinessException('监管平台 SM4 加密失败: ' . $this->getLastOpenSslError());
}
return strtolower(bin2hex($cipherText));
}
public function decrypt(string $cipherHex): string
{
$cipherRaw = $this->decodeHex($cipherHex, 'SM4 cipher');
$key = $this->decodeHex($this->requireSm4Key(), 'SM4 key');
$iv = $this->decodeHex($this->requireSm4Iv(), 'SM4 iv');
$plainText = openssl_decrypt($cipherRaw, 'sm4-cbc', $key, OPENSSL_RAW_DATA, $iv);
if ($plainText === false) {
throw new BusinessException('监管平台 SM4 解密失败: ' . $this->getLastOpenSslError());
}
return $plainText;
}
public function sign(string $plainText): string
{
$privateKey = openssl_pkey_get_private($this->resolveKeyMaterial($this->sm2PrivateKey, 'SM2 private key'));
if ($privateKey === false) {
throw new BusinessException('监管平台 SM2 私钥加载失败: ' . $this->getLastOpenSslError());
}
$signature = '';
$result = openssl_sign($plainText, $signature, $privateKey, 'sm3');
if ($result !== true) {
throw new BusinessException('监管平台 SM2 签名失败: ' . $this->getLastOpenSslError());
}
return strtolower(bin2hex($signature));
}
public function verify(string $plainText, string $signatureHex): bool
{
$publicKey = openssl_pkey_get_public($this->resolveKeyMaterial($this->sm2PublicKey, 'SM2 public key'));
if ($publicKey === false) {
throw new BusinessException('监管平台 SM2 公钥加载失败: ' . $this->getLastOpenSslError());
}
$signatureRaw = $this->decodeHex($signatureHex, 'SM2 signature');
$result = openssl_verify($plainText, $signatureRaw, $publicKey, 'sm3');
if ($result === -1) {
throw new BusinessException('监管平台 SM2 验签失败: ' . $this->getLastOpenSslError());
}
return $result === 1;
}
protected function extractResponseEnvelope(array $response): array
{
if (isset($response['data']) && is_array($response['data']) && isset($response['data']['data'])) {
$response = $response['data'];
}
$sign = $response['sign'] ?? null;
$data = $response['data'] ?? null;
if (! is_string($sign) || ! is_string($data) || $sign === '' || $data === '') {
throw new BusinessException('监管平台响应报文缺少 sign/data');
}
return [
'sign' => $sign,
'data' => $data,
];
}
protected function normalizeValue(mixed $value, bool $removeEmptyValues): mixed
{
if (is_array($value)) {
if ($this->isAssoc($value)) {
$normalized = [];
ksort($value);
foreach ($value as $key => $item) {
$item = $this->normalizeValue($item, $removeEmptyValues);
if ($removeEmptyValues && $this->isEmptyValue($item)) {
continue;
}
$normalized[$key] = $item;
}
return $normalized;
}
$normalized = [];
foreach ($value as $item) {
$item = $this->normalizeValue($item, $removeEmptyValues);
if ($removeEmptyValues && $this->isEmptyValue($item)) {
continue;
}
$normalized[] = $item;
}
return $normalized;
}
return $value;
}
protected function isAssoc(array $value): bool
{
return array_keys($value) !== range(0, count($value) - 1);
}
protected function isEmptyValue(mixed $value): bool
{
if ($value === null) {
return true;
}
if (is_string($value)) {
return trim($value) === '';
}
if (is_array($value)) {
return $value === [];
}
return false;
}
protected function decodeHex(string $value, string $label): string
{
$value = trim($value);
if ($value === '' || strlen($value) % 2 !== 0 || ! ctype_xdigit($value)) {
throw new BusinessException(sprintf('监管平台 %s 不是合法十六进制字符串', $label));
}
$decoded = hex2bin($value);
if ($decoded === false) {
throw new BusinessException(sprintf('监管平台 %s 十六进制解码失败', $label));
}
return $decoded;
}
protected function resolveKeyMaterial(?string $key, string $label): string
{
$key = trim((string) $key);
if ($key === '') {
throw new BusinessException(sprintf('监管平台 %s 未配置', $label));
}
if (str_starts_with($key, 'file://')) {
$key = substr($key, 7);
}
if (is_file($key)) {
$contents = file_get_contents($key);
if ($contents === false || trim($contents) === '') {
throw new BusinessException(sprintf('监管平台 %s 文件读取失败', $label));
}
return $contents;
}
if ($label === 'SM2 private key' && $this->isRawHexPrivateKey($key)) {
return $this->buildSm2PrivateKeyPem($key, $this->sm2PublicKey);
}
if ($label === 'SM2 public key' && $this->isRawHexPublicKey($key)) {
return $this->buildSm2PublicKeyPem($key);
}
return $key;
}
protected function resolveConfigValue(array $config, array $paths): ?string
{
foreach ($paths as $path) {
$value = $this->getByPath($config, $path);
if ($value !== null && $value !== '') {
return (string) $value;
}
}
return null;
}
protected function getByPath(array $config, string $path): mixed
{
$current = $config;
foreach (explode('.', $path) as $segment) {
if (! is_array($current) || ! array_key_exists($segment, $current)) {
return null;
}
$current = $current[$segment];
}
return $current;
}
protected function requireClientId(): string
{
if (empty($this->clientId)) {
throw new BusinessException('监管平台 client_id 未配置');
}
return $this->clientId;
}
protected function requireClientSecret(): string
{
if (empty($this->clientSecret)) {
throw new BusinessException('监管平台 client_secret 未配置');
}
return $this->clientSecret;
}
protected function requireSm4Key(): string
{
if (empty($this->sm4KeyHex)) {
throw new BusinessException('监管平台 SM4 key 未配置');
}
return $this->sm4KeyHex;
}
protected function requireSm4Iv(): string
{
if (empty($this->sm4IvHex)) {
throw new BusinessException('监管平台 SM4 iv 未配置');
}
return $this->sm4IvHex;
}
protected function getLastOpenSslError(): string
{
$errors = [];
while (($error = openssl_error_string()) !== false) {
$errors[] = $error;
}
return $errors === [] ? 'unknown openssl error' : implode(' | ', $errors);
}
protected function isRawHexPrivateKey(string $key): bool
{
return strlen($key) === 64 && ctype_xdigit($key);
}
protected function isRawHexPublicKey(string $key): bool
{
if (! ctype_xdigit($key)) {
return false;
}
return in_array(strlen($key), [128, 130], true);
}
protected function buildSm2PrivateKeyPem(string $privateKeyHex, ?string $publicKeyHex = null): string
{
$privateKeyRaw = $this->decodeHex($privateKeyHex, 'SM2 private key');
$sequence = $this->derSequence(
$this->derInteger(1),
$this->derOctetString($privateKeyRaw),
$this->derContextSpecific(0, $this->derObjectIdentifier(self::SM2_CURVE_OID))
);
if (is_string($publicKeyHex) && $this->isRawHexPublicKey(trim($publicKeyHex))) {
$publicKeyRaw = $this->normalizeRawPublicKey(trim($publicKeyHex));
$sequence .= $this->derContextSpecific(1, $this->derBitString($publicKeyRaw));
$sequence = $this->derSequence($this->derInteger(1), $this->derOctetString($privateKeyRaw), $this->derContextSpecific(0, $this->derObjectIdentifier(self::SM2_CURVE_OID)), $this->derContextSpecific(1, $this->derBitString($publicKeyRaw)));
}
return $this->pemEncode('EC PRIVATE KEY', $sequence);
}
protected function buildSm2PublicKeyPem(string $publicKeyHex): string
{
$publicKeyRaw = $this->normalizeRawPublicKey($publicKeyHex);
$algorithm = $this->derSequence(
$this->derObjectIdentifier(self::EC_PUBLIC_KEY_OID),
$this->derObjectIdentifier(self::SM2_CURVE_OID)
);
$subjectPublicKeyInfo = $this->derSequence(
$algorithm,
$this->derBitString($publicKeyRaw)
);
return $this->pemEncode('PUBLIC KEY', $subjectPublicKeyInfo);
}
protected function normalizeRawPublicKey(string $publicKeyHex): string
{
$publicKeyHex = strtolower($publicKeyHex);
if (strlen($publicKeyHex) === 128) {
$publicKeyHex = '04' . $publicKeyHex;
}
return $this->decodeHex($publicKeyHex, 'SM2 public key');
}
protected function pemEncode(string $label, string $der): string
{
return "-----BEGIN {$label}-----\n"
. chunk_split(base64_encode($der), 64, "\n")
. "-----END {$label}-----\n";
}
protected function derSequence(string ...$parts): string
{
return $this->derWrap(0x30, implode('', $parts));
}
protected function derInteger(int $value): string
{
$encoded = '';
$current = $value;
do {
$encoded = chr($current & 0xff) . $encoded;
$current >>= 8;
} while ($current > 0);
if ((ord($encoded[0]) & 0x80) !== 0) {
$encoded = "\x00" . $encoded;
}
return $this->derWrap(0x02, $encoded);
}
protected function derOctetString(string $value): string
{
return $this->derWrap(0x04, $value);
}
protected function derBitString(string $value): string
{
return $this->derWrap(0x03, "\x00" . $value);
}
protected function derObjectIdentifier(string $oid): string
{
$parts = array_map('intval', explode('.', $oid));
if (count($parts) < 2) {
throw new BusinessException('监管平台 OID 格式错误');
}
$encoded = chr(($parts[0] * 40) + $parts[1]);
for ($i = 2; $i < count($parts); $i++) {
$encoded .= $this->encodeOidPart($parts[$i]);
}
return $this->derWrap(0x06, $encoded);
}
protected function derContextSpecific(int $index, string $value): string
{
return $this->derWrap(0xa0 + $index, $value);
}
protected function derWrap(int $tag, string $value): string
{
return chr($tag) . $this->derLength(strlen($value)) . $value;
}
protected function derLength(int $length): string
{
if ($length < 0x80) {
return chr($length);
}
$encoded = '';
$current = $length;
while ($current > 0) {
$encoded = chr($current & 0xff) . $encoded;
$current >>= 8;
}
return chr(0x80 | strlen($encoded)) . $encoded;
}
protected function encodeOidPart(int $value): string
{
if ($value === 0) {
return "\x00";
}
$encoded = '';
$current = $value;
while ($current > 0) {
$encoded = chr($current & 0x7f) . $encoded;
$current >>= 7;
}
$length = strlen($encoded);
for ($i = 0; $i < $length - 1; $i++) {
$encoded[$i] = chr(ord($encoded[$i]) | 0x80);
}
return $encoded;
}
}
File diff suppressed because it is too large Load Diff
+2 -4
View File
@@ -59,16 +59,14 @@ class WechatPay
$this->pay_notify_url = $this->config['product_pay_notify_url'];
$this->refund_notify_url = $this->config['product_refund_notify_url'];
// 之前为北京欣欣账户,现改为成都欣欣账户
$this->pay_config = config("we_chat.applets.pay.1659662936");
$this->pay_config = config("we_chat.applets.pay.1636644248");
}
if ($order_type == 3){
$this->pay_notify_url = $this->config['detection_pay_notify_url'];
$this->refund_notify_url = $this->config['detection_refund_notify_url'];
// 之前为北京欣欣账户,现改为成都欣欣账户
$this->pay_config = config("we_chat.applets.pay.1659662936");
$this->pay_config = config("we_chat.applets.pay.1636644248");
}
if ($order_type == 4){
@@ -1,11 +0,0 @@
ALTER TABLE `order_prescription_file`
ADD COLUMN `doctor_ca_supplier` varchar(16) NOT NULL DEFAULT '' COMMENT '医生CA供应商' AFTER `doctor_ca_file_id`,
ADD COLUMN `doctor_ca_sign_type` varchar(16) NOT NULL DEFAULT '' COMMENT '医生CA签名类型' AFTER `doctor_ca_supplier`,
ADD COLUMN `doctor_ca_sign_originaltext` text COMMENT '医生CA签名原文' AFTER `doctor_ca_sign_type`,
ADD COLUMN `doctor_ca_sign_text` longtext COMMENT '医生CA签名值' AFTER `doctor_ca_sign_originaltext`,
ADD COLUMN `doctor_ca_sign_time` longtext COMMENT '医生CA时间戳签名值' AFTER `doctor_ca_sign_text`,
ADD COLUMN `pharmacist_ca_supplier` varchar(16) NOT NULL DEFAULT '' COMMENT '药师CA供应商' AFTER `doctor_ca_sign_time`,
ADD COLUMN `pharmacist_ca_sign_type` varchar(16) NOT NULL DEFAULT '' COMMENT '药师CA签名类型' AFTER `pharmacist_ca_supplier`,
ADD COLUMN `pharmacist_ca_sign_originaltext` text COMMENT '药师CA签名原文' AFTER `pharmacist_ca_sign_type`,
ADD COLUMN `pharmacist_ca_sign_text` longtext COMMENT '药师CA签名值' AFTER `pharmacist_ca_sign_originaltext`,
ADD COLUMN `pharmacist_ca_sign_time` longtext COMMENT '药师CA时间戳签名值' AFTER `pharmacist_ca_sign_text`;
@@ -1,2 +0,0 @@
ALTER TABLE `order_prescription_product`
ADD COLUMN `product_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '开方时商品单价' AFTER `product_name`;
-140
View File
@@ -1,140 +0,0 @@
-- ==============================================================================
-- 数据库变更脚本:多药房独立药品与库存隔离方案
-- 适用系统:hospital-applets-api
-- 执行说明:
-- 1. 本脚本默认表前缀为 `gdxz_`,若数据库未配置表前缀,请全局替换删除 `gdxz_`。
-- 2. 请在业务低峰期执行,按顺序分批执行:第一部分(新建表)-> 第二部分(修改表)-> 第三部分(数据回填初始化)。
-- 3. 脚本具有幂等性设计(IF NOT EXISTS / ON DUPLICATE KEY UPDATE)。
-- ==============================================================================
-- ==============================================================================
-- 第一部分:新建两张药房核心表
-- ==============================================================================
-- 1.1 药房基础信息表(gdxz_pharmacy)
CREATE TABLE IF NOT EXISTS `gdxz_pharmacy` (
`pharmacy_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '药房ID(雪花算法ID,0表示系统默认/老数据)',
`pharmacy_name` varchar(128) NOT NULL DEFAULT '' COMMENT '药房名称',
`pharmacy_code` varchar(64) NOT NULL DEFAULT '' COMMENT '药房编码(对接第三方药房的thirdCode/pharmacyCode)',
`postage` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '基础运费/邮费(单位:元)',
`free_shipping_threshold` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '满额包邮门槛(单位:元,0表示不免邮)',
`is_pickup` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否支持到店自提(0:不支持 1:支持)',
`telephone` varchar(32) NOT NULL DEFAULT '' COMMENT '药房联系电话',
`province` varchar(64) NOT NULL DEFAULT '' COMMENT '省份名称',
`city` varchar(64) NOT NULL DEFAULT '' COMMENT '城市名称',
`county` varchar(64) NOT NULL DEFAULT '' COMMENT '区县名称',
`address` varchar(255) NOT NULL DEFAULT '' COMMENT '详细地址',
`pickup_address` varchar(255) NOT NULL DEFAULT '' COMMENT '自提详细地址',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态(0:禁用 1:启用)',
`created_at` datetime DEFAULT NULL COMMENT '创建时间',
`updated_at` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`pharmacy_id`),
UNIQUE KEY `uk_pharmacy_code` (`pharmacy_code`),
KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='药房基础信息表';
-- 1.2 医生-药房关联表(gdxz_doctor_pharmacy)
CREATE TABLE IF NOT EXISTS `gdxz_doctor_pharmacy` (
`doctor_pharmacy_id` bigint(20) unsigned NOT NULL COMMENT '关联主键ID(雪花算法ID)',
`doctor_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '医生ID',
`pharmacy_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '药房ID',
`is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否默认药房(0:否 1:是)',
`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态(0:禁用/解绑 1:正常)',
`created_at` datetime DEFAULT NULL COMMENT '创建时间',
`updated_at` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`doctor_pharmacy_id`),
UNIQUE KEY `uk_doctor_pharmacy` (`doctor_id`, `pharmacy_id`),
KEY `idx_doctor_default` (`doctor_id`, `is_default`, `status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='医生-药房绑定关联表';
-- ==============================================================================
-- 第二部分:现有业务表字段扩展(ALTER TABLE)
-- ==============================================================================
-- 2.1 处方主表增加药房快照字段(gdxz_order_prescription)
ALTER TABLE `gdxz_order_prescription`
ADD COLUMN `pharmacy_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '开方药房ID' AFTER `doctor_advice`,
ADD COLUMN `pharmacy_code` varchar(64) NOT NULL DEFAULT '' COMMENT '开方药房编码' AFTER `pharmacy_id`,
ADD COLUMN `pharmacy_name` varchar(128) NOT NULL DEFAULT '' COMMENT '开方药房名称' AFTER `pharmacy_code`,
ADD KEY `idx_pharmacy_code` (`pharmacy_code`);
-- 2.2 药品订单表增加药房快照及配送类型字段(gdxz_order_product)
ALTER TABLE `gdxz_order_product`
ADD COLUMN `pharmacy_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '所属药房ID' AFTER `logistics_fee`,
ADD COLUMN `pharmacy_code` varchar(64) NOT NULL DEFAULT '' COMMENT '所属药房编码' AFTER `pharmacy_id`,
ADD COLUMN `pharmacy_name` varchar(128) NOT NULL DEFAULT '' COMMENT '所属药房名称' AFTER `pharmacy_code`,
ADD COLUMN `delivery_type` tinyint(1) NOT NULL DEFAULT '2' COMMENT '配送方式(1:到店自提 2:快递配送)' AFTER `pharmacy_name`,
ADD KEY `idx_pharmacy_code` (`pharmacy_code`),
ADD KEY `idx_delivery_type` (`delivery_type`);
-- 2.3 药品表增加所属药房隔离字段(gdxz_product)
ALTER TABLE `gdxz_product`
ADD COLUMN `pharmacy_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '所属药房ID' AFTER `product_platform_id`,
ADD COLUMN `pharmacy_code` varchar(64) NOT NULL DEFAULT '' COMMENT '所属药房编码' AFTER `pharmacy_id`,
ADD KEY `idx_pharmacy_code` (`pharmacy_code`);
-- 2.4 处方平台药品目录表增加第三方药房编码(gdxz_product_platform)
ALTER TABLE `gdxz_product_platform`
ADD COLUMN `pharmacy_code` varchar(64) NOT NULL DEFAULT '' COMMENT '第三方药房编码' AFTER `product_pharmacy_code`,
ADD KEY `idx_pharmacy_code` (`pharmacy_code`);
-- ==============================================================================
-- 第三部分:历史数据回填与初始化(DML)
-- ==============================================================================
-- 3.1 初始化系统默认药房记录(pharmacy_id = 0,编码 ZD-10198)
INSERT INTO `gdxz_pharmacy` (
`pharmacy_id`, `pharmacy_name`, `pharmacy_code`,
`postage`, `free_shipping_threshold`, `is_pickup`,
`telephone`, `province`, `city`, `county`, `address`, `pickup_address`,
`status`, `created_at`, `updated_at`
) VALUES (
0, '总院默认药房', 'ZD-10198',
7.00, 0.00, 1,
'010-87573022', '北京市', '北京市', '海淀区', '医疗机构总院院内药房', '医疗机构总院门诊楼1层药房自提窗口',
1, NOW(), NOW()
) ON DUPLICATE KEY UPDATE
`pharmacy_code` = VALUES(`pharmacy_code`),
`pharmacy_name` = VALUES(`pharmacy_name`),
`status` = 1;
-- 3.2 回填现有药品表(gdxz_product)的药房归属为默认药房
UPDATE `gdxz_product`
SET `pharmacy_id` = 0, `pharmacy_code` = 'ZD-10198'
WHERE `pharmacy_code` = '' OR `pharmacy_code` IS NULL;
-- 3.3 回填处方平台目录表(gdxz_product_platform)的药房编码
UPDATE `gdxz_product_platform`
SET `pharmacy_code` = 'ZD-10198'
WHERE `pharmacy_code` = '' OR `pharmacy_code` IS NULL;
-- 3.4 回填历史处方表(gdxz_order_prescription)快照数据
UPDATE `gdxz_order_prescription`
SET `pharmacy_id` = 0, `pharmacy_code` = 'ZD-10198', `pharmacy_name` = '总院默认药房'
WHERE `pharmacy_code` = '' OR `pharmacy_code` IS NULL;
-- 3.5 回填历史药品订单表(gdxz_order_product)快照与配送方式(历史订单默认为快递=2)
UPDATE `gdxz_order_product`
SET `pharmacy_id` = 0, `pharmacy_code` = 'ZD-10198', `pharmacy_name` = '总院默认药房', `delivery_type` = 2
WHERE `pharmacy_code` = '' OR `pharmacy_code` IS NULL;
-- 3.6 为现有所有正常在职的医生,初始化绑定默认药房(避免上线后老医生无法开方)
INSERT IGNORE INTO `gdxz_doctor_pharmacy` (
`doctor_pharmacy_id`, `doctor_id`, `pharmacy_id`, `is_default`, `status`, `created_at`, `updated_at`
)
SELECT
-- 结合时间戳与医生ID生成唯一大整数ID
(UNIX_TIMESTAMP(NOW()) * 1000000 + (d.doctor_id % 1000000)) AS `doctor_pharmacy_id`,
d.doctor_id,
0 AS `pharmacy_id`,
1 AS `is_default`,
1 AS `status`,
NOW() AS `created_at`,
NOW() AS `updated_at`
FROM `gdxz_user_doctor` d
WHERE d.status = 1
AND NOT EXISTS (
SELECT 1 FROM `gdxz_doctor_pharmacy` dp WHERE dp.doctor_id = d.doctor_id
);