From 6605000c9124bb3334061c143d16c0cd2080b624 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Thu, 9 Nov 2023 11:31:11 +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=E4=BC=98=E6=83=A0=E5=8D=B7=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/PatientOrderService.php | 34 ++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/app/Services/PatientOrderService.php b/app/Services/PatientOrderService.php index 34114c8..ca0078f 100644 --- a/app/Services/PatientOrderService.php +++ b/app/Services/PatientOrderService.php @@ -1212,6 +1212,10 @@ class PatientOrderService extends BaseService $payment_amount_total = 0.01; } + if ($payment_amount_total <= 0){ + return fail(HttpEnumCode::SERVER_ERROR); + } + // 确定支付渠道 // 支付渠道(1:小程序支付 2:微信扫码支付) if ($client_type == 1) { @@ -1580,7 +1584,10 @@ class PatientOrderService extends BaseService } $amount_total = 0; - $coupon_amount_total = 0; + + // 优惠卷商品数据 + $coupon_product_datas = array(); + foreach ($order_prescription_product as &$item) { $params = array(); $params['product_id'] = $item['product_id']; @@ -1600,7 +1607,25 @@ class PatientOrderService extends BaseService } } - $amount_total += $product['product_price'] * $item['prescription_product_num']; + $amount_total = bcadd($amount_total,($product['product_price'] * $item['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; + } + + // 定义优惠卷金额默认值 + $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); } // 获取运费金额 @@ -1613,11 +1638,10 @@ class PatientOrderService extends BaseService } } - // 实际支付金额 + // 实际支付金额=商品总金额-优惠卷金额+运费金额 + $payment_amount_total = bcadd(bcsub($amount_total , $coupon_amount_total,2), $logistics_fee, 2); if (env("APP_ENV") == "dev") { $payment_amount_total = 0.01; - } else { - $payment_amount_total = $amount_total + $logistics_fee; } // 获取收货地址