修改商品订单金额计算
This commit is contained in:
parent
448180598d
commit
5811ab949d
@ -1468,10 +1468,11 @@ class PatientOrderService extends BaseService
|
||||
}
|
||||
|
||||
$not_enough_product_ids = [];
|
||||
$amount_total = 0;
|
||||
|
||||
// 商品数据
|
||||
$product_datas = array();
|
||||
$amount_total = 0; // 总金额
|
||||
$product_datas = array(); // 商品数据
|
||||
$discount_amount = 0;// 优惠金额
|
||||
$freight_calculation_amount = 0; // 药品总金额-计算运费使用
|
||||
|
||||
foreach ($product_ids as $product_id) {
|
||||
// 检测药品是否存在于处方中
|
||||
@ -1506,6 +1507,8 @@ class PatientOrderService extends BaseService
|
||||
$product['product_num'] = $order_prescription_product['prescription_product_num'];
|
||||
$product['used_quantity'] = 0; // 健康包服务下已使用赠送药品的数量,默认赋0
|
||||
$product['actual_quantity'] = $order_prescription_product['prescription_product_num']; // 实际药品数量 = 处方数量 - 健康包可使用的赠送药品数量
|
||||
$product['actual_product_price'] = $product['product_price']; // 实际药品价格
|
||||
$product['discount_amount'] = 0; // 药品优惠金额
|
||||
$product_data = $product->toArray();
|
||||
$product_datas[] = $product_data;
|
||||
}
|
||||
@ -1536,7 +1539,12 @@ class PatientOrderService extends BaseService
|
||||
// 处理商品数量
|
||||
$OrderServicePackageService = new OrderServicePackageService();
|
||||
|
||||
// 处理商品数量、金额,重新赋0,上面已计算过
|
||||
$amount_total = 0;
|
||||
|
||||
// 药品总金额-计算运费使用,重新赋0,上面已计算过
|
||||
$freight_calculation_amount = 0;
|
||||
|
||||
foreach ($product_datas as $key => $product_data) {
|
||||
// 获取服务包内某一药品的总数量
|
||||
$total_quantity = $OrderServicePackageService->getOrderServiceProductTotalQuantity($order_service_package_detail['package_id'], $product_data['product_id']);
|
||||
@ -1544,30 +1552,71 @@ class PatientOrderService extends BaseService
|
||||
// 获取服务包内某一药品的剩余数量
|
||||
$remaining_quantity = $OrderServicePackageService->getOrderServiceProductCanUseQuantity($order_service_package['order_service_id'], $product_data['product_id'], $total_quantity);
|
||||
|
||||
// 实际药品价格
|
||||
$actual_product_price = 0;
|
||||
|
||||
// 可用数量大于处方商品数量
|
||||
if ($remaining_quantity >= $product_data['product_num']) {
|
||||
// 把商品价格置为0。金额按照0计算
|
||||
$product_datas[$key]['product_price'] = 0;
|
||||
// 药品优惠金额
|
||||
$product_datas[$key]['discount_amount'] = $product_data['product_price'] - 35;
|
||||
|
||||
// 已使用数量 = 原数量+此次使用数量
|
||||
$product_datas[$key]['used_quantity'] = $product_data['product_num'];
|
||||
|
||||
// 实际药品数量 = 处方数量 - 健康包可使用的赠送药品数量
|
||||
$product_datas[$key]['actual_quantity'] = 0;
|
||||
|
||||
// 实际药品价格
|
||||
$actual_product_price = 35 * $product_datas[$key]['used_quantity'];
|
||||
} else {
|
||||
// 已使用数量 = 最大可用数量;表示此服务包商品已使用完毕
|
||||
$product_datas[$key]['used_quantity'] = $remaining_quantity;
|
||||
|
||||
// 实际药品数量 = 处方数量 - 健康包可使用的赠送药品数量
|
||||
$product_datas[$key]['actual_quantity'] = $product_data['product_num'] - $remaining_quantity;
|
||||
|
||||
// 实际药品价格= 35 * 剩余免费药品数量 + 原价 * 实际药品数量
|
||||
$actual_product_price = bcadd(
|
||||
bcmul(
|
||||
35,
|
||||
$product_datas[$key]['used_quantity'],
|
||||
2
|
||||
),
|
||||
bcmul(
|
||||
$product_datas[$key]['product_price'],
|
||||
$product_datas[$key]['actual_quantity'],
|
||||
2
|
||||
),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
// 此处重新计算药品总金额
|
||||
$amount_total = bcadd(
|
||||
$amount_total,
|
||||
$actual_product_price,
|
||||
2
|
||||
);
|
||||
|
||||
// 此处重新计算药品优惠金额
|
||||
if ($discount_amount > 0){
|
||||
$discount_amount = bcadd(
|
||||
$discount_amount,
|
||||
bcmul(
|
||||
$product_datas[$key]['discount_amount'],
|
||||
$product_datas[$key]['used_quantity'],
|
||||
2
|
||||
),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
// 此处计算药品总金额-计算运费使用
|
||||
$freight_calculation_amount = bcadd(
|
||||
$freight_calculation_amount,
|
||||
bcmul(
|
||||
$product_datas[$key]['product_price'],
|
||||
$product_datas[$key]['actual_quantity'],
|
||||
$product_datas[$key]['product_num'],
|
||||
2
|
||||
),
|
||||
2
|
||||
@ -1589,7 +1638,7 @@ class PatientOrderService extends BaseService
|
||||
$Prescription = new Prescription();
|
||||
|
||||
$result = $Prescription->getLogisticsFee();
|
||||
if ($amount_total >= $result['drugCost']) {
|
||||
if ($freight_calculation_amount >= $result['drugCost']) {
|
||||
$logistics_fee = 0;
|
||||
} else {
|
||||
$logistics_fee = $result['freight'];
|
||||
@ -2031,6 +2080,8 @@ class PatientOrderService extends BaseService
|
||||
// 处理药品数据
|
||||
$amount_total = 0; // 总金额
|
||||
$product_datas = array(); // 商品数据
|
||||
$discount_amount = 0;// 优惠金额
|
||||
$freight_calculation_amount = 0; // 药品总金额-计算运费使用
|
||||
|
||||
foreach ($order_prescription_products as &$order_prescription_product) {
|
||||
$params = array();
|
||||
@ -2050,12 +2101,18 @@ class PatientOrderService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
// 总金额
|
||||
$amount_total = bcadd($amount_total, ($product['product_price'] * $order_prescription_product['prescription_product_num']), 2);
|
||||
|
||||
// 药品总金额-计算运费使用
|
||||
$freight_calculation_amount = $amount_total;
|
||||
|
||||
// 处方药品数据
|
||||
$product['product_num'] = $order_prescription_product['prescription_product_num'];
|
||||
$product['used_quantity'] = 0; // 已使用数量
|
||||
$product['actual_quantity'] = $order_prescription_product['prescription_product_num']; // 实际药品数量 = 处方数量 - 健康包可使用的赠送药品数量
|
||||
$product['actual_product_price'] = $product['product_price']; // 实际药品价格
|
||||
$product['discount_amount'] = 0; // 药品优惠金额
|
||||
$product_data = $product->toArray();
|
||||
$product_datas[] = $product_data;
|
||||
}
|
||||
@ -2078,8 +2135,12 @@ class PatientOrderService extends BaseService
|
||||
}
|
||||
|
||||
// 此处不检测未支付的商品订单,在创建订单时会进行数量的扣减
|
||||
// 处理商品数量、金额
|
||||
// 处理商品数量、金额,重新赋0,上面已计算过
|
||||
$amount_total = 0;
|
||||
|
||||
// 药品总金额-计算运费使用,重新赋0,上面已计算过
|
||||
$freight_calculation_amount = 0;
|
||||
|
||||
foreach ($product_datas as &$product_data) {
|
||||
// 获取服务包内某一药品的总数量
|
||||
$total_quantity = $OrderServicePackageService->getOrderServiceProductTotalQuantity($order_service_package_detail['package_id'], $product_data['product_id']);
|
||||
@ -2087,30 +2148,74 @@ class PatientOrderService extends BaseService
|
||||
// 获取服务包内某一药品的剩余数量
|
||||
$remaining_quantity = $OrderServicePackageService->getOrderServiceProductCanUseQuantity($order_service_package['order_service_id'], $product_data['product_id'], $total_quantity);
|
||||
|
||||
// 实际药品价格
|
||||
$actual_product_price = 0;
|
||||
|
||||
// 可用数量大于处方商品数量
|
||||
if ($remaining_quantity >= $product_data['product_num']) {
|
||||
// 把商品价格置为0。金额按照0计算
|
||||
$product_data['product_price'] = 0;
|
||||
// 药品优惠金额
|
||||
$product_data['discount_amount'] = $product_data['product_price'] - 35;
|
||||
|
||||
// 实际药品价格
|
||||
$actual_product_price = 35 * $product_data['product_num'];
|
||||
|
||||
// 已使用数量 = 原数量+此次使用数量
|
||||
$product_data['used_quantity'] = $product_data['product_num'];
|
||||
|
||||
// 实际药品数量 = 处方数量 - 健康包可使用的赠送药品数量
|
||||
$product_data['actual_quantity'] = 0;
|
||||
|
||||
// 实际药品价格
|
||||
$actual_product_price = 35 * $product_data['used_quantity'];
|
||||
} else {
|
||||
// 已使用数量 = 最大可用数量;表示此服务包商品已使用完毕
|
||||
$product_data['used_quantity'] = $remaining_quantity;
|
||||
|
||||
// 实际药品数量 = 处方数量 - 健康包可使用的赠送药品数量
|
||||
$product_data['actual_quantity'] = $product_data['product_num'] - $remaining_quantity;
|
||||
|
||||
// 实际药品价格= 35 * 剩余免费药品数量 + 原价 * 实际药品数量
|
||||
$actual_product_price = bcadd(
|
||||
bcmul(
|
||||
35,
|
||||
$product_data['used_quantity'],
|
||||
2
|
||||
),
|
||||
bcmul(
|
||||
$product_data['product_price'],
|
||||
$product_data['actual_quantity'],
|
||||
2
|
||||
),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
// 此处重新计算药品总金额
|
||||
$amount_total = bcadd(
|
||||
$amount_total,
|
||||
$actual_product_price,
|
||||
2
|
||||
);
|
||||
|
||||
// 此处重新计算药品优惠金额
|
||||
if ($discount_amount > 0){
|
||||
$discount_amount = bcadd(
|
||||
$discount_amount,
|
||||
bcmul(
|
||||
$product_data['discount_amount'],
|
||||
$product_data['used_quantity'],
|
||||
2
|
||||
),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
// 此处计算药品总金额-计算运费使用
|
||||
$freight_calculation_amount = bcadd(
|
||||
$freight_calculation_amount,
|
||||
bcmul(
|
||||
$product_data['product_price'],
|
||||
$product_data['actual_quantity'],
|
||||
$product_data['product_num'],
|
||||
2
|
||||
),
|
||||
2
|
||||
@ -2130,7 +2235,7 @@ class PatientOrderService extends BaseService
|
||||
if (env("APP_ENV") == "prod") {
|
||||
$Prescription = new Prescription();
|
||||
$result = $Prescription->getLogisticsFee();
|
||||
if ($amount_total < $result['drugCost']) {
|
||||
if ($freight_calculation_amount < $result['drugCost']) {
|
||||
$logistics_fee = $result['freight'];
|
||||
}
|
||||
}
|
||||
@ -2156,6 +2261,7 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$result = array();
|
||||
$result['amount_total'] = $amount_total;
|
||||
$result['discount_amount'] = $discount_amount; // 优惠金额
|
||||
$result['coupon_amount_total'] = $coupon_amount_total;
|
||||
$result['payment_amount_total'] = $payment_amount_total;
|
||||
$result['logistics_fee'] = $logistics_fee;
|
||||
|
||||
@ -389,7 +389,7 @@ class UserCouponService extends BaseService
|
||||
}
|
||||
|
||||
$product_price = bcadd($product_price,
|
||||
bcmul( // 商品价格*数量
|
||||
bcmul( // 商品价格*实际数量数量
|
||||
$coupon_product_data['product_price'],
|
||||
$coupon_product_data['actual_quantity'],
|
||||
2
|
||||
|
||||
@ -180,7 +180,7 @@ class Prescription
|
||||
}
|
||||
|
||||
return $response['data'];
|
||||
} catch (GuzzleException $e) {
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
@ -189,6 +189,8 @@ class Prescription
|
||||
* 上报处方
|
||||
* @param array $arg
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function reportPrescription(array $arg): array
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user