浏览代码

套餐包优惠卷金额计算代码同步

Long 1 周之前
父节点
当前提交
309fb01627
共有 1 个文件被更改,包括 97 次插入97 次删除
  1. 97 97
      fs-service/src/main/java/com/fs/his/service/impl/FsPackageOrderServiceImpl.java

+ 97 - 97
fs-service/src/main/java/com/fs/his/service/impl/FsPackageOrderServiceImpl.java

@@ -341,106 +341,106 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
             return R.error("无效的类型参数");
         }
     }
-    public Map<String,Object> computeOrderMoney(BigDecimal orderPrice,FsPackageOrderComputeParam param){
-        Map<String,Object> moneys=new HashMap<>();
-        BigDecimal payPrice=orderPrice;
-        BigDecimal payMoney=new BigDecimal(0);
-        BigDecimal payRemain=new BigDecimal(0);
-        BigDecimal payDelivery=new BigDecimal(0);
-        BigDecimal discountMoney=new BigDecimal(0);
-        String json=configService.selectConfigByKey("his.package");
-        PackageConfigDTO configDTO=JSONUtil.toBean(json, PackageConfigDTO.class);
-        if(param.getUserCouponId()!=null&&param.getUserCouponId()>0l){
-            FsUserCoupon userCoupon=userCouponService.selectFsUserCouponById(param.getUserCouponId());
-            if(userCoupon==null){
-
-            }
-            if(userCoupon.getStatus()!=0){
+    public Map<String, Object> computeOrderMoney(BigDecimal orderPrice, FsPackageOrderComputeParam param) {
+        Map<String, Object> moneys = new HashMap<>();
+        BigDecimal payPrice = orderPrice;
+        BigDecimal payMoney = new BigDecimal(0);
+        BigDecimal payRemain = new BigDecimal(0);
+        BigDecimal payDelivery = new BigDecimal(0);
+        BigDecimal discountMoney = new BigDecimal(0);
+        String json = configService.selectConfigByKey("his.package");
+        PackageConfigDTO configDTO = JSONUtil.toBean(json, PackageConfigDTO.class);
+        if (param.getUserCouponId() != null && param.getUserCouponId() > 0l) {
+            FsUserCoupon userCoupon = userCouponService.selectFsUserCouponById(param.getUserCouponId());
+            if (userCoupon != null) {
+                if (userCoupon.getStatus() == 0) {
+                    FsCoupon coupon = couponService.selectFsCouponByCouponId(userCoupon.getCouponId());
+                    if (coupon.getCouponType().equals(1)) {
+                        if (coupon.getMinPrice().compareTo(orderPrice) <=0) {
+                            if (coupon.getPrice().compareTo(orderPrice) >= 0) {
+                                payPrice = new BigDecimal(0);
+                                discountMoney = coupon.getPrice();
+                            } else {
+                                payPrice = orderPrice.subtract(coupon.getPrice());
+                                discountMoney = coupon.getPrice();
+                            }
+                        }
+                        //中药免单券
+                    } else if (coupon.getCouponType().equals(2)) {
+                        payPrice = new BigDecimal(0);
+                        discountMoney = orderPrice;
+                        //问诊免单券
+                    } else if (coupon.getCouponType().equals(3)) {
+
+                        //中药打折券
+                    } else if (coupon.getCouponType().equals(4)) {
+                        payPrice = orderPrice.multiply(coupon.getRate()).divide(new BigDecimal(100));
+                        discountMoney = coupon.getPrice().subtract(orderPrice);
+                        //私域疗法券
+                    } else if (coupon.getCouponType().equals(5)) {
+                        if (coupon.getMinPrice().compareTo(orderPrice) <=0) {
+                            if (coupon.getPrice().compareTo(orderPrice) >= 0) {
+                                payPrice = new BigDecimal(0);
+                                discountMoney = coupon.getPrice();
+                            } else {
+                                payPrice = orderPrice.subtract(coupon.getPrice());
+                                discountMoney = coupon.getPrice();
 
-            }
-            FsCoupon coupon=couponService.selectFsCouponByCouponId(userCoupon.getCouponId());
-            if(coupon.getCouponType().equals(1)){
-                if(coupon.getMinPrice().compareTo(orderPrice)==1){
-
-                }
-                if(coupon.getPrice().compareTo(orderPrice)>=0){
-                    payPrice=new BigDecimal(0);
-                    discountMoney=coupon.getPrice();
-                }
-                else{
-                    payPrice=orderPrice.subtract(coupon.getPrice());
-                    discountMoney=coupon.getPrice();
 
+                            }
+                        }
+                        //公域疗法券
+                    }else if (coupon.getCouponType().equals(6)){
+                        if (coupon.getMinPrice().compareTo(orderPrice) >=0) {
+                            //throw  new ServiceException("优惠劵最低金额大于订单金额");
 
+                        }
+                        if (coupon.getPrice().compareTo(orderPrice) >= 0) {
+                            payPrice = new BigDecimal(0);
+                            discountMoney = coupon.getPrice();
+                        } else {
+                            payPrice = orderPrice.subtract(coupon.getPrice());
+                            discountMoney = coupon.getPrice();
+                        }
+                    }
                 }
             }
-            else if(coupon.getCouponType().equals(2)){
-                payPrice=new BigDecimal(0);
-                discountMoney=orderPrice;
-
-            }
-            else if(coupon.getCouponType().equals(3)){
-
-
-            }
-            else if(coupon.getCouponType().equals(4)){
-                payPrice= orderPrice.multiply(coupon.getRate()).divide(new BigDecimal(100));
-                discountMoney=coupon.getPrice().subtract(orderPrice);
 
-            }
-            else if(coupon.getCouponType().equals(5)){
-                if(coupon.getMinPrice().compareTo(orderPrice)==1){
 
-                }
-                if(coupon.getPrice().compareTo(orderPrice)>=0){
-                    payPrice=new BigDecimal(0);
-                    discountMoney=coupon.getPrice();
-                }
-                else{
-                    payPrice=orderPrice.subtract(coupon.getPrice());
-                    discountMoney=coupon.getPrice();
-
-
-                }
-
-            }
-        }
-        else{
-            payPrice=orderPrice;
-            discountMoney=new BigDecimal(0);
+        } else {
+            payPrice = orderPrice;
+            discountMoney = new BigDecimal(0);
         }
 
-        if(payPrice.compareTo(new BigDecimal(0))==1){
-            if(param.getPayType().equals(1)){
+        if (payPrice.compareTo(new BigDecimal(0)) == 1) {
+            if (param.getPayType().equals(1)) {
                 //全款
-                payMoney=payPrice;
-                payRemain=new BigDecimal(0);
-                payDelivery=new BigDecimal(0);
+                payMoney = payPrice;
+                payRemain = new BigDecimal(0);
+                payDelivery = new BigDecimal(0);
 
-            }
-            else if (param.getPayType().equals(2)){
+            } else if (param.getPayType().equals(2)) {
                 //代收
-                payMoney= payPrice.multiply(new BigDecimal((100-configDTO.getPayRate()))).divide(new BigDecimal(100));
-                payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
-                payRemain=payPrice.subtract(payMoney);
-                payDelivery=new BigDecimal(0);
-                if(payRemain.compareTo(new BigDecimal(0))==0){
-                    throw  new CustomException("代收金额应大于0");
+                payMoney = payPrice.multiply(new BigDecimal((100 - configDTO.getPayRate()))).divide(new BigDecimal(100));
+                payMoney = new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
+                payRemain = payPrice.subtract(payMoney);
+                payDelivery = new BigDecimal(0);
+                if (payRemain.compareTo(new BigDecimal(0)) == 0) {
+                    throw new CustomException("代收金额应大于0");
                 }
-            }
-            else if(param.getPayType().equals(3)){
+            } else if (param.getPayType().equals(3)) {
                 //货到付款
-                payMoney=configDTO.getPayDelivery();
-                payPrice=payPrice.add(configDTO.getPayDelivery());
-                payRemain=payPrice.subtract(configDTO.getPayDelivery());
-                payDelivery=configDTO.getPayDelivery();
+                payMoney = configDTO.getPayDelivery();
+                payPrice = payPrice.add(configDTO.getPayDelivery());
+                payRemain = payPrice.subtract(configDTO.getPayDelivery());
+                payDelivery = configDTO.getPayDelivery();
             }
         }
-        moneys.put("payPrice",payPrice);
-        moneys.put("payMoney",payMoney);
-        moneys.put("payRemain",payRemain);
-        moneys.put("payDelivery",payDelivery);
-        moneys.put("discountMoney",discountMoney);
+        moneys.put("payPrice", payPrice);
+        moneys.put("payMoney", payMoney);
+        moneys.put("payRemain", payRemain);
+        moneys.put("payDelivery", payDelivery);
+        moneys.put("discountMoney", discountMoney);
         List<StoreOrderProductDTO> gifts=new ArrayList<>();
         if(configDTO.getGiftStoreId()!=null&&param.getStoreId()!=null&&configDTO.getGiftStoreId().equals(param.getStoreId())&&param.getPayType()==1&&param.getCompanyId()!=null&&param.getCompanyUserId()!=null&&param.getCompanyId()>0&&payPrice.compareTo(configDTO.getGiftPrice())>=0){
             gifts=configDTO.getGift();
@@ -613,6 +613,19 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
             computeParam.setUserCouponId(order.getUserCouponId());
         }
 
+        Map<String,Object> moneys=computeOrderMoney(order.getTotalPrice(),computeParam);
+        fsPackageOrder.setPayMoney((BigDecimal)moneys.get("payMoney"));
+        fsPackageOrder.setPayPrice((BigDecimal)moneys.get("payPrice"));
+        fsPackageOrder.setPayDelivery((BigDecimal)moneys.get("payDelivery"));
+        if (param.getUserCouponId()!=null&&param.getUserCouponId()>0){
+            fsPackageOrder.setUserCouponId(param.getUserCouponId());
+
+        }
+        fsPackageOrder.setDiscountMoney((BigDecimal)moneys.get("discountMoney"));
+        fsPackageOrder.setPayRemain((BigDecimal)moneys.get("payRemain"));
+        fsPackageOrder.setPayType(param.getPayType());
+        fsPackageOrderMapper.updateFsPackageOrder(fsPackageOrder);
+
         if (param.getUserCouponId()!=null&&param.getUserCouponId()>0){
             FsUserCoupon userCoupon=userCouponService.selectFsUserCouponById(param.getUserCouponId());
             FsCoupon coupon=couponService.selectFsCouponByCouponId(userCoupon.getCouponId());
@@ -626,19 +639,6 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
             userCouponService.updateFsUserCoupon(userCoupon);
         }
 
-
-        Map<String,Object> moneys=computeOrderMoney(order.getTotalPrice(),computeParam);
-        fsPackageOrder.setPayMoney((BigDecimal)moneys.get("payMoney"));
-        fsPackageOrder.setPayPrice((BigDecimal)moneys.get("payPrice"));
-        fsPackageOrder.setPayDelivery((BigDecimal)moneys.get("payDelivery"));
-        if (param.getUserCouponId()!=null&&param.getUserCouponId()>0){
-            fsPackageOrder.setUserCouponId(param.getUserCouponId());
-
-        }
-        fsPackageOrder.setDiscountMoney((BigDecimal)moneys.get("discountMoney"));
-        fsPackageOrder.setPayRemain((BigDecimal)moneys.get("payRemain"));
-        fsPackageOrder.setPayType(param.getPayType());
-        fsPackageOrderMapper.updateFsPackageOrder(fsPackageOrder);
         return R.ok();
 
     }