修改 获取处方订单支付页详情 金额、优惠卷问题
This commit is contained in:
parent
5d61a9113c
commit
2903407977
@ -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;
|
||||
}
|
||||
}
|
||||
@ -1776,58 +1776,88 @@ 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($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);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($coupon_product_datas)) {
|
||||
// 获取患者购药可用的优惠卷
|
||||
$userCouponService = new UserCouponService();
|
||||
$user_coupons = $userCouponService->getUserProductUsableCoupon($user_info['user_id'], $coupon_product_datas);
|
||||
$user_coupons = $userCouponService->getUserProductUsableCoupon($user_info['user_id'], $product_datas);
|
||||
|
||||
// 获取可用优惠卷总金额
|
||||
$coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons);
|
||||
}
|
||||
|
||||
// 获取运费金额
|
||||
$logistics_fee = 0;
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user