多药房
Build Docker / build (push) Canceled after 0s

This commit is contained in:
haomingming
2026-09-08 10:09:07 +08:00
parent 4dfcdacb12
commit d3fce247e5
20 changed files with 782 additions and 65 deletions
+44
View File
@@ -16,6 +16,8 @@ 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;
@@ -242,6 +244,24 @@ 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 {
$defaultPharmacy = DoctorPharmacy::getDoctorDefaultPharmacy($doctor_id);
$pharmacy = ($defaultPharmacy && $defaultPharmacy->Pharmacy && $defaultPharmacy->Pharmacy->status == 1) ? $defaultPharmacy->Pharmacy : null;
}
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();
@@ -449,6 +469,30 @@ 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 {
$defaultPharmacy = DoctorPharmacy::getDoctorDefaultPharmacy($doctor_id);
$pharmacy = ($defaultPharmacy && $defaultPharmacy->Pharmacy && $defaultPharmacy->Pharmacy->status == 1) ? $defaultPharmacy->Pharmacy : null;
}
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);
+137
View File
@@ -0,0 +1,137 @@
<?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());
}
}
+6 -1
View File
@@ -405,7 +405,11 @@ 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'] = 2; // 取货方式 1 自提 2 快递,目前只支持快递,传固定值 2
$arg['takeTypeCode'] = ($order_product['delivery_type'] == 1) ? 1 : 2; // 取货方式 1 自提 2 快递
if (empty($order_product['pharmacy_code'])) {
throw new BusinessException("订单药房编码缺失,无法上报处方平台");
}
$arg['pharmacyCode'] = $order_product['pharmacy_code'];
$arg['buyerName'] = $order_product['consignee_name'];// 收货人姓名
$arg['buyerPhone'] = $order_product['consignee_tel'];// 收货人联系方式
$arg['buyerAddress'] = $order_product['address'];// 收货人地址
@@ -417,6 +421,7 @@ 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']; // 就诊人联系方式
+101 -45
View File
@@ -42,6 +42,7 @@ 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;
@@ -1482,6 +1483,7 @@ 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();
@@ -1493,6 +1495,13 @@ 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, "处方未审核");
@@ -1516,13 +1525,28 @@ class PatientOrderService extends BaseService
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, "收货地址错误");
// 检测收货方式及收货地址
$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, "收货地址错误");
}
}
$not_enough_product_ids = [];
@@ -1710,17 +1734,17 @@ class PatientOrderService extends BaseService
// 处理运费数据
$app_env = config('app_env', 'prod');
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;
$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;
}
}
// 实际支付金额=商品总金额-优惠卷金额+运费金额
@@ -1730,7 +1754,7 @@ class PatientOrderService extends BaseService
(string)$coupon_amount_total,
2
),
$logistics_fee,
(string)$logistics_fee,
2
);
@@ -1792,18 +1816,37 @@ class PatientOrderService extends BaseService
$data['coupon_amount_total'] = $coupon_amount_total; // 优惠卷总金额
$data['payment_amount_total'] = $payment_amount_total; // 实际付款金额
$data['logistics_fee'] = $logistics_fee; // 运费金额
$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'];
$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'] = "";
}
$order_product = OrderProduct::addOrderProduct($data);
if (empty($order_product)) {
Db::rollBack();
@@ -2154,7 +2197,10 @@ class PatientOrderService extends BaseService
$fields = [
"order_prescription_id",
"order_inquiry_id"
"order_inquiry_id",
"pharmacy_id",
"pharmacy_code",
"pharmacy_name",
];
$params = array();
@@ -2357,19 +2403,19 @@ class PatientOrderService extends BaseService
// 获取可用优惠卷总金额
$coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons);
// 获取运费金额
$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;
// 获取运费金额及药房信息
$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;
}
}
// 实际支付金额=商品总金额-优惠卷金额+运费金额
@@ -2399,6 +2445,16 @@ 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);
}
+43 -1
View File
@@ -40,6 +40,8 @@ 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;
@@ -1199,9 +1201,24 @@ 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) || empty($default_pharmacy->Pharmacy) || $default_pharmacy->Pharmacy->status != 1 || empty($default_pharmacy->Pharmacy->pharmacy_code)) {
$result['status'] = 2;
$result['message'] = "您尚未配置默认药房或药房已停用,请前往【我的-药房设置】完成绑定后再开具处方";
return success($result);
}
$result['data']['default_pharmacy'] = [
'pharmacy_id' => (string)$default_pharmacy->Pharmacy->pharmacy_id,
'pharmacy_code' => $default_pharmacy->Pharmacy->pharmacy_code,
'pharmacy_name' => $default_pharmacy->Pharmacy->pharmacy_name,
];
$params = array();
$params['order_inquiry_id'] = $order_inquiry_id;
$params['doctor_id'] = $user_info['client_user_id'];
$params['doctor_id'] = $doctor_id;
$order_prescription = OrderPrescription::getOne($params);
if (empty($order_prescription)){
return success($result);
@@ -1462,6 +1479,22 @@ 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 {
$doctor_default = DoctorPharmacy::getDoctorDefaultPharmacy($user_info['client_user_id'] ?? 0);
if ($doctor_default && $doctor_default->Pharmacy && $doctor_default->Pharmacy->status == 1) {
$pharmacy = $doctor_default->Pharmacy;
}
}
if (empty($pharmacy) || empty($pharmacy['pharmacy_code'])) {
return fail(HttpEnumCode::HTTP_ERROR, "未找到有效的开方药房或药房已被停用,无法开具处方");
}
// 获取医生信息
$params = array();
@@ -1635,6 +1668,9 @@ 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();
@@ -1689,6 +1725,12 @@ 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']) {
// 库存不足