From 2903407977b5d8372b67d038362fa10c8d6d8f5c Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Thu, 18 Apr 2024 15:19:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=A4=84=E6=96=B9=E8=AE=A2=E5=8D=95=E6=94=AF=E4=BB=98=E9=A1=B5?= =?UTF-8?q?=E8=AF=A6=E6=83=85=20=E9=87=91=E9=A2=9D=E3=80=81=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=8D=B7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/OrderServicePackageService.php | 24 ++++++ app/Services/PatientOrderService.php | 88 ++++++++++++++------- 2 files changed, 83 insertions(+), 29 deletions(-) diff --git a/app/Services/OrderServicePackageService.php b/app/Services/OrderServicePackageService.php index 8a9b642..d32a49c 100644 --- a/app/Services/OrderServicePackageService.php +++ b/app/Services/OrderServicePackageService.php @@ -1256,4 +1256,28 @@ class OrderServicePackageService extends BaseService return $result; } + + /** + * 获取服务包剩余药品数量 + * @param string|int $order_service_id + * @param string|int $product_id + * @return int + */ + public function getOrderServiceProductRemainingQuantity(string|int $order_service_id,string|int $product_id): int + { + $remaining_quantity = 0; + + $params = array(); + $params['order_service_id'] = $$order_service_id; + $params['product_id'] = $product_id; + $order_service_package_product = OrderServicePackageProduct::getOne($params); + if (!empty($order_service_package_product)){ + $remaining_quantity = $order_service_package_product['quantity'] - $order_service_package_product['used_quantity']; + if ($remaining_quantity < 0){ + $remaining_quantity = 0; + } + } + + return $remaining_quantity; + } } \ No newline at end of file diff --git a/app/Services/PatientOrderService.php b/app/Services/PatientOrderService.php index d8bb6e6..e5727a0 100644 --- a/app/Services/PatientOrderService.php +++ b/app/Services/PatientOrderService.php @@ -1776,59 +1776,89 @@ class PatientOrderService extends BaseService return fail(HttpEnumCode::HTTP_ERROR, "处方已使用"); } + // 获取问诊订单数据 + $params = array(); + $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)){ + return fail(); + } + // 获取处方药品信息 $params = array(); $params['order_prescription_id'] = $order_prescription['order_prescription_id']; - $order_prescription_product = OrderPrescriptionProduct::getList($params); - if (empty($order_prescription_product)) { + $order_prescription_products = OrderPrescriptionProduct::getList($params); + if (empty($order_prescription_products)) { return fail(HttpEnumCode::SERVER_ERROR); } - $amount_total = 0; + // 处理药品数据 + $amount_total = 0; // 总金额 + $product_datas = array(); // 商品数据 - // 优惠卷商品数据 - $coupon_product_datas = array(); - - foreach ($order_prescription_product as &$item) { + foreach ($order_prescription_products as &$order_prescription_product) { $params = array(); - $params['product_id'] = $item['product_id']; + $params['product_id'] = $order_prescription_product['product_id']; $product = Product::getWithAmountOne($params); if (empty($product)) { return fail(HttpEnumCode::HTTP_ERROR, "处方存在未知药品"); } - $item['status'] = 1; // 正常 + $order_prescription_product['status'] = 1; // 正常 // 检测商品库存 if (!empty($product['ProductPlatformAmount'])) { - if ($item['prescription_product_num'] > $product['ProductPlatformAmount']['stock']) { + if ($order_prescription_product['prescription_product_num'] > $product['ProductPlatformAmount']['stock']) { // 库存不足 - $item['status'] = 2; - continue; + $order_prescription_product['status'] = 2; } } - $amount_total = bcadd($amount_total,($product['product_price'] * $item['prescription_product_num']),2); + $amount_total = bcadd($amount_total,($product['product_price'] * $order_prescription_product['prescription_product_num']),2); - // 优惠卷商品数据 - $coupon_product_data = array(); - $product['product_num'] = $item['prescription_product_num']; - $coupon_product_data = $product->toArray(); - $coupon_product_datas[] = $coupon_product_data; + // 处方药品数据 + $product['product_num'] = $order_prescription_product['prescription_product_num']; + $product_data = $product->toArray(); + $product_datas[] = $product_data; } - // 定义优惠卷金额默认值 - $coupon_amount_total = 0; - - if (!empty($coupon_product_datas)) { - // 获取患者购药可用的优惠卷 - $userCouponService = new UserCouponService(); - $user_coupons = $userCouponService->getUserProductUsableCoupon($user_info['user_id'], $coupon_product_datas); - - // 获取可用优惠卷总金额 - $coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons); + if (empty($product_datas)) { + return fail(); } + // 处理健康包赠送商品 + if ($order_inquiry['inquiry_type'] == 1 && $order_inquiry['inquiry_mode'] == 8){ + // 获取问诊订单关联服务包id + $params = array(); + $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id']; + $order_service_package_inquiry = OrderServicePackageInquiry::getOne($params); + if (empty($order_service_package_inquiry)){ + return fail(); + } + + // 此处不检测未支付的商品订单,在创建订单时会进行数量的扣减 + // 处理商品数量 + $OrderServicePackageService = new OrderServicePackageService(); + + foreach ($product_datas as &$product_data){ + $remaining_quantity = $OrderServicePackageService->getOrderServiceProductRemainingQuantity($order_service_package_inquiry['order_service_id'],$product_data['product_id']); + // 可用数量大于处方商品数量,此情况把商品数量置为0 + if ($remaining_quantity >= $product_data['product_num']){ + $product_data['product_num'] = 0; + } + + // 此处重新计算药品总金额 + $amount_total = bcadd($amount_total,($product_data['product_price'] * $product_data['product_num']),2); + } + } + + // 获取患者购药可用的优惠卷 + $userCouponService = new UserCouponService(); + $user_coupons = $userCouponService->getUserProductUsableCoupon($user_info['user_id'], $product_datas); + + // 获取可用优惠卷总金额 + $coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons); + // 获取运费金额 $logistics_fee = 0; if (env("APP_ENV") == "prod") { @@ -1868,7 +1898,7 @@ class PatientOrderService extends BaseService $result['payment_amount_total'] = $payment_amount_total; $result['logistics_fee'] = $logistics_fee; $result['user_ship_address'] = $user_ship_address; - $result['order_prescription_product'] = $order_prescription_product; + $result['order_prescription_product'] = $order_prescription_products; return success($result); }