多药房
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
+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);
}