Browse Source

1、调整疗法包报错问题

yys 1 month ago
parent
commit
a03ea6099e

+ 236 - 0
fs-common/src/main/java/com/fs/his/dto/FsPackagePruductDTO.java

@@ -0,0 +1,236 @@
+package com.fs.his.dto;
+
+import java.math.BigDecimal;
+
+/**
+ * 套餐包商品 DTO(注意类名历史拼写 Pruduct)
+ */
+public class FsPackagePruductDTO {
+
+    private Long id;
+
+    private Long productId;
+
+    private String sku;
+
+    private Integer stock;
+
+    private Integer sales;
+
+    private BigDecimal price;
+
+    /** 图片 */
+    private String image;
+
+    /** 店铺名称 */
+    private String storeName;
+
+    private BigDecimal agentPrice;
+
+    /** 商品条码 */
+    private String barCode;
+
+    /** 原价 */
+    private BigDecimal otPrice;
+    /** 产品名称 */
+    private String productName;
+    /** 产品数量 */
+    private Integer count;
+    /** 产品类型 */
+    private Integer productType;
+    /** 产品类别名称 */
+    private String cateName;
+    /** 处方规格 */
+    private String prescribeSpec;
+    /** 使用方法 */
+    private String usageMethod;
+    /** 使用频率单位 */
+    private Integer usageFrequencyUnit;
+    /** 每次使用数量 */
+    private String usagePerUseCount;
+    /** 价格 */
+    private BigDecimal money;
+    /** 成本价格 */
+    private BigDecimal costPrice;
+    /** 是否为药品 */
+    private Integer isDrug;
+
+    public FsPackagePruductDTO() {
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getProductId() {
+        return productId;
+    }
+
+    public void setProductId(Long productId) {
+        this.productId = productId;
+    }
+
+    public String getSku() {
+        return sku;
+    }
+
+    public void setSku(String sku) {
+        this.sku = sku;
+    }
+
+    public Integer getStock() {
+        return stock;
+    }
+
+    public void setStock(Integer stock) {
+        this.stock = stock;
+    }
+
+    public Integer getSales() {
+        return sales;
+    }
+
+    public void setSales(Integer sales) {
+        this.sales = sales;
+    }
+
+    public BigDecimal getPrice() {
+        return price;
+    }
+
+    public void setPrice(BigDecimal price) {
+        this.price = price;
+    }
+
+    public String getImage() {
+        return image;
+    }
+
+    public void setImage(String image) {
+        this.image = image;
+    }
+
+    public String getStoreName() {
+        return storeName;
+    }
+
+    public void setStoreName(String storeName) {
+        this.storeName = storeName;
+    }
+
+    public BigDecimal getAgentPrice() {
+        return agentPrice;
+    }
+
+    public void setAgentPrice(BigDecimal agentPrice) {
+        this.agentPrice = agentPrice;
+    }
+
+    public String getBarCode() {
+        return barCode;
+    }
+
+    public void setBarCode(String barCode) {
+        this.barCode = barCode;
+    }
+
+    public BigDecimal getOtPrice() {
+        return otPrice;
+    }
+
+    public void setOtPrice(BigDecimal otPrice) {
+        this.otPrice = otPrice;
+    }
+
+    public String getProductName() {
+        return productName;
+    }
+
+    public void setProductName(String productName) {
+        this.productName = productName;
+    }
+
+    public Integer getCount() {
+        return count;
+    }
+
+    public void setCount(Integer count) {
+        this.count = count;
+    }
+
+    public Integer getProductType() {
+        return productType;
+    }
+
+    public void setProductType(Integer productType) {
+        this.productType = productType;
+    }
+
+    public String getCateName() {
+        return cateName;
+    }
+
+    public void setCateName(String cateName) {
+        this.cateName = cateName;
+    }
+
+    public String getPrescribeSpec() {
+        return prescribeSpec;
+    }
+
+    public void setPrescribeSpec(String prescribeSpec) {
+        this.prescribeSpec = prescribeSpec;
+    }
+
+    public String getUsageMethod() {
+        return usageMethod;
+    }
+
+    public void setUsageMethod(String usageMethod) {
+        this.usageMethod = usageMethod;
+    }
+
+    public Integer getUsageFrequencyUnit() {
+        return usageFrequencyUnit;
+    }
+
+    public void setUsageFrequencyUnit(Integer usageFrequencyUnit) {
+        this.usageFrequencyUnit = usageFrequencyUnit;
+    }
+
+    public String getUsagePerUseCount() {
+        return usagePerUseCount;
+    }
+
+    public void setUsagePerUseCount(String usagePerUseCount) {
+        this.usagePerUseCount = usagePerUseCount;
+    }
+
+    public BigDecimal getMoney() {
+        return money;
+    }
+
+    public void setMoney(BigDecimal money) {
+        this.money = money;
+    }
+
+    public BigDecimal getCostPrice() {
+        return costPrice;
+    }
+
+    public void setCostPrice(BigDecimal costPrice) {
+        this.costPrice = costPrice;
+    }
+
+    public Integer getIsDrug() {
+        return isDrug;
+    }
+
+    public void setIsDrug(Integer isDrug) {
+        this.isDrug = isDrug;
+    }
+}

+ 0 - 60
fs-service/src/main/java/com/fs/his/dto/FsPackagePruductDTO.java

@@ -1,60 +0,0 @@
-package com.fs.his.dto;
-
-import lombok.Data;
-
-import java.math.BigDecimal;
-
-@Data
-public class FsPackagePruductDTO {
-
-    private Long id;
-
-    private Long productId;
-
-    private String sku;
-
-    private Integer stock;
-
-    private Integer sales;
-
-    private BigDecimal price;
-
-    /** 图片 */
-    private String image;
-
-    /** 图片 */
-    private String storeName;
-
-    private BigDecimal agentPrice;
-
-    /** 商品条码 */
-    private String barCode;
-
-    /** 原价 */
-    private BigDecimal otPrice;
-    /** 产品名称 */
-    private String productName;
-    /** 产品数量 */
-    private Integer count;
-    /** 产品类型 */
-    private Integer productType;
-    /** 产品类别名称 */
-    private String cateName;
-    /** 处方规格 */
-    private String prescribeSpec;
-    /** 使用方法 */
-    private String usageMethod;
-    /** 使用频率单位 */
-    private Integer usageFrequencyUnit;
-    /** 每次使用数量 */
-    private String usagePerUseCount;
-    /**  价格 */
-    private BigDecimal money;
-    /** 成本价格 */
-    private BigDecimal costPrice;
-    /** 是否为药品 */
-    private Integer isDrug;
-
-    public FsPackagePruductDTO() {
-    }
-}

+ 15 - 5
fs-service/src/main/java/com/fs/live/service/impl/LiveOrderServiceImpl.java

@@ -2437,8 +2437,8 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
             LiveCouponUser couponUser=liveCouponUserService.selectLiveCouponUserById(param.getCouponUserId());
             if(couponUser!=null&&couponUser.getStatus()==0){
                 if(couponUser.getUseMinPrice().compareTo(payPrice)< 1){
-                    payPrice=payPrice.subtract(couponUser.getCouponPrice());
-                    deductionPrice = couponUser.getCouponPrice();
+                    deductionPrice = resolveCouponDeduction(payPrice, couponUser.getCouponPrice());
+                    payPrice = payPrice.subtract(deductionPrice);
                 }
             }
         }
@@ -4430,9 +4430,9 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
                     return R.error("非法操作");
                 }
                 if (couponUser.getUseMinPrice().compareTo(payPrice) < 1) {
-                    discountMoney = couponUser.getCouponPrice();
+                    discountMoney = resolveCouponDeduction(payPrice, couponUser.getCouponPrice());
                     storeOrder.setCouponId(couponUser.getId());
-                    storeOrder.setCouponPrice(couponUser.getCouponPrice());
+                    storeOrder.setCouponPrice(discountMoney);
                     //更新优惠券状态
                     couponUser.setStatus(1);
                     couponUser.setUseTime(new Date());
@@ -4720,7 +4720,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
                 }
                 if (couponUser.getUseMinPrice().compareTo(payPrice) < 1) {
                     liveOrder.setUserCouponId(couponUser.getId());
-                    liveOrder.setDiscountMoney(couponUser.getCouponPrice());
+                    liveOrder.setDiscountMoney(resolveCouponDeduction(payPrice, couponUser.getCouponPrice()));
                     //更新优惠券状态
                     couponUser.setStatus(1);
                     couponUser.setUseTime(new Date());
@@ -4791,6 +4791,16 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
         }
     }
 
+    /**
+     * 优惠券抵扣金额不超过应付金额,避免出现负实付。
+     */
+    private BigDecimal resolveCouponDeduction(BigDecimal payPrice, BigDecimal couponPrice) {
+        if (payPrice == null || couponPrice == null || payPrice.compareTo(BigDecimal.ZERO) <= 0) {
+            return BigDecimal.ZERO;
+        }
+        return couponPrice.compareTo(payPrice) > 0 ? payPrice : couponPrice;
+    }
+
     private BigDecimal handleDeliveryMoney(LiveOrder liveOrder) {
         BigDecimal storePostage = BigDecimal.ZERO;
         BigDecimal badCode = BigDecimal.valueOf(-1);