修改创建药品订单
This commit is contained in:
parent
93ccad2946
commit
6939dbd981
@ -1279,7 +1279,6 @@ class PatientOrderService extends BaseService
|
||||
if ($order_prescription['prescription_status'] == 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方未审核");
|
||||
}
|
||||
|
||||
if ($order_prescription['prescription_status'] == 4) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方已失效");
|
||||
}
|
||||
@ -1291,6 +1290,14 @@ 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(HttpEnumCode::HTTP_ERROR, "创建订单失败");
|
||||
}
|
||||
|
||||
// 检测收货地址
|
||||
$params = array();
|
||||
$params['user_id'] = $user_info['user_id'];
|
||||
@ -1303,8 +1310,8 @@ class PatientOrderService extends BaseService
|
||||
$not_enough_product_ids = [];
|
||||
$amount_total = 0;
|
||||
|
||||
// 优惠卷商品数据
|
||||
$coupon_product_datas = array();
|
||||
// 商品数据
|
||||
$product_datas = array();
|
||||
|
||||
foreach ($product_ids as $product_id) {
|
||||
// 检测药品是否存在于处方中
|
||||
@ -1329,36 +1336,71 @@ class PatientOrderService extends BaseService
|
||||
if ($order_prescription_product['prescription_product_num'] > $product['ProductPlatformAmount']['stock']) {
|
||||
// 库存不足
|
||||
$not_enough_product_ids[] = $product_id;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单金额
|
||||
$amount_total = bcadd($amount_total, ($product['product_price'] * $order_prescription_product['prescription_product_num']), 2);
|
||||
|
||||
// 优惠卷商品数据
|
||||
$coupon_product_data = array();
|
||||
// 商品数据
|
||||
$product['product_num'] = $order_prescription_product['prescription_product_num'];
|
||||
$coupon_product_data = $product->toArray();
|
||||
$coupon_product_datas[] = $coupon_product_data;
|
||||
$product_data = $product->toArray();
|
||||
$product_datas[] = $product_data;
|
||||
}
|
||||
|
||||
// 库存不足返回错误
|
||||
if (!empty($not_enough_product_ids)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在库存不足商品", $not_enough_product_ids);
|
||||
}
|
||||
|
||||
// 定义优惠卷金额默认值
|
||||
$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();
|
||||
|
||||
$amount_total = 0;
|
||||
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_price'] = 0;
|
||||
}
|
||||
|
||||
// 此处重新计算药品总金额
|
||||
$amount_total = bcadd(
|
||||
$amount_total,
|
||||
bcmul(
|
||||
$product_data['product_price'],
|
||||
$product_data['product_num'],
|
||||
2
|
||||
),
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取患者购药可用的优惠卷
|
||||
$userCouponService = new UserCouponService();
|
||||
$user_coupons = $userCouponService->getUserProductUsableCoupon($user_info['user_id'], $product_datas);
|
||||
|
||||
// 获取可用优惠卷总金额
|
||||
$coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons);
|
||||
|
||||
// 处理运费数据
|
||||
$app_env = config('app_env', 'prod');
|
||||
if ($app_env != "dev") {
|
||||
@ -1376,7 +1418,15 @@ class PatientOrderService extends BaseService
|
||||
}
|
||||
|
||||
// 实际支付金额=商品总金额-优惠卷金额+运费金额
|
||||
$payment_amount_total = bcadd(bcsub($amount_total , $coupon_amount_total,2), $logistics_fee, 2);
|
||||
$payment_amount_total = bcadd(
|
||||
bcsub(
|
||||
$amount_total ,
|
||||
$coupon_amount_total,
|
||||
2
|
||||
),
|
||||
$logistics_fee,
|
||||
2
|
||||
);
|
||||
if ($app_env == "dev") {
|
||||
$payment_amount_total = 0.01;
|
||||
}
|
||||
@ -1451,26 +1501,9 @@ class PatientOrderService extends BaseService
|
||||
}
|
||||
|
||||
// 新增药品订单详情
|
||||
foreach ($product_ids as $product_id) {
|
||||
foreach ($product_datas as $product_data) {
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$params['product_id'] = $product_id;
|
||||
$order_prescription_product = OrderPrescriptionProduct::getOne($params);
|
||||
if (empty($order_prescription_product)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "创建订单失败");
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$params['product_id'] = $product_id;
|
||||
$product = Product::getOne($params);
|
||||
if (empty($product)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方存在未知药品");
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$params['product_platform_code'] = $product['product_platform_code'];
|
||||
$params['product_platform_code'] = $product_data['product_platform_code'];
|
||||
$product_platform_amount = ProductPlatformAmount::getSharedLockOne($params);
|
||||
if (empty($product_platform_amount)) {
|
||||
Db::rollBack();
|
||||
@ -1481,14 +1514,14 @@ class PatientOrderService extends BaseService
|
||||
$data['order_product_id'] = $order_product['order_product_id'];
|
||||
$data['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||||
$data['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||||
$data['product_id'] = $product_id;
|
||||
$data['product_name'] = $order_prescription_product['product_name'];
|
||||
$data['product_price'] = $product['product_price'] * $order_prescription_product['prescription_product_num'];
|
||||
$data['product_platform_code'] = $product['product_platform_code'];
|
||||
$data['amount'] = $order_prescription_product['prescription_product_num'];
|
||||
$data['manufacturer'] = $order_prescription_product['manufacturer'];
|
||||
$data['product_cover_img'] = $product['product_cover_img'];
|
||||
$data['product_spec'] = $order_prescription_product['product_spec'];
|
||||
$data['product_id'] = $product_data['product_id'];
|
||||
$data['product_name'] = $product_data['product_name'];
|
||||
$data['product_price'] = bcmul($product_data['product_price'],$product_data['product_num'],3);
|
||||
$data['product_platform_code'] = $product_data['product_platform_code'];
|
||||
$data['amount'] = $product_data['product_num'];
|
||||
$data['manufacturer'] = $product_data['manufacturer'];
|
||||
$data['product_cover_img'] = $product_data['product_cover_img'];
|
||||
$data['product_spec'] = $product_data['product_spec'];
|
||||
$order_product_item = OrderProductItem::addOrderProductItem($data);
|
||||
if (empty($order_product_item)) {
|
||||
Db::rollBack();
|
||||
@ -1500,14 +1533,14 @@ class PatientOrderService extends BaseService
|
||||
$data['use_status'] = 1;
|
||||
|
||||
$params = array();
|
||||
$params['prescription_product_id'] = $order_prescription_product['prescription_product_id'];
|
||||
$params['prescription_product_id'] = $product_data['prescription_product_id'];
|
||||
OrderPrescriptionProduct::edit($params, $data);
|
||||
|
||||
// 锁定库存
|
||||
// 库存-1
|
||||
$params = array();
|
||||
$params['amount_id'] = $product_platform_amount['amount_id'];
|
||||
ProductPlatformAmount::dec($params, 'stock', $order_prescription_product['prescription_product_num']);
|
||||
ProductPlatformAmount::dec($params, 'stock', $product_data['product_num']);
|
||||
}
|
||||
|
||||
// 修改处方为已使用
|
||||
@ -1556,13 +1589,18 @@ class PatientOrderService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
// 增加至取消订单延迟队列
|
||||
// 增加至未支付取消订单延迟队列
|
||||
$time = 60 * 30;
|
||||
if (\Hyperf\Config\config('app_env') == "dev"){
|
||||
$time = 60 * 5;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['order_no'] = (string)$order_product['order_product_no'];
|
||||
$data['order_type'] = 2;
|
||||
|
||||
$message = new CancelUnpayOrdersDelayDirectProducer($data);
|
||||
$message->setDelayMs(1000 * 60 * 30);
|
||||
$message->setDelayMs(1000 * $time);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
@ -1846,9 +1884,9 @@ class PatientOrderService extends BaseService
|
||||
// 获取服务包剩余药品数量
|
||||
$remaining_quantity = $OrderServicePackageService->getOrderServiceProductRemainingQuantity($order_service_package_inquiry['order_service_id'],$product_data['product_id']);
|
||||
|
||||
// 可用数量大于处方商品数量,此情况把商品数量置为0
|
||||
// 可用数量大于处方商品数量,此情况把商品价格置为0
|
||||
if ($remaining_quantity >= $product_data['product_num']){
|
||||
$product_data['product_num'] = 0;
|
||||
$product_data['product_price'] = 0;
|
||||
}
|
||||
|
||||
// 此处重新计算药品总金额
|
||||
@ -2872,6 +2910,7 @@ class PatientOrderService extends BaseService
|
||||
$fields = [
|
||||
'order_inquiry_id',
|
||||
'inquiry_status',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
$params = array();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user