wjj 1 天之前
父节点
当前提交
433d5b4f9f

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStoreOrderCreateParam.java

@@ -64,4 +64,6 @@ public class FsStoreOrderCreateParam implements Serializable
     private FsCompanyExternalPayReceipt receipt;
 
     private Long companyCustomerId;//患者会员id
+
+    private BigDecimal prepaidAmount;//预付金额
 }

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStoreOrderCreateUserParam.java

@@ -50,4 +50,6 @@ public class FsStoreOrderCreateUserParam implements Serializable
      * 收款Id
      */
     private Long receiveMoneyId;
+
+    private BigDecimal prepaidAmount;//预付金额
 }

+ 19 - 0
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreCartScrmServiceImpl.java

@@ -15,6 +15,7 @@ import com.fs.hisStore.config.MedicalMallConfig;
 import com.fs.hisStore.domain.FsStoreCartScrm;
 import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
 import com.fs.hisStore.domain.FsStoreProductGroupScrm;
+import com.fs.hisStore.domain.FsStoreProductScrm;
 import com.fs.hisStore.dto.StoreProductGroupDTO;
 import com.fs.hisStore.mapper.FsStoreCartScrmMapper;
 import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
@@ -147,6 +148,15 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
 
     @Override
     public R addCart(long uid, FsStoreCartParam cartParam) {
+        FsStoreProductScrm fsStoreProductScrm = fsStoreProductMapper.selectFsStoreProductById(cartParam.getProductId());
+        if (fsStoreProductScrm == null) {
+            return R.error("商品不存在");
+        }
+        String type = null;
+        Integer isGift = fsStoreProductScrm.getIsGift();
+        if (isGift == 1) {
+            type = "gift";
+        }
         //如果是直接购买,直接写入记录
         if(cartParam.getIsBuy()==1){
             FsStoreCartScrm storeCart = FsStoreCartScrm.builder()
@@ -160,6 +170,9 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
                     .isBuy(cartParam.getIsBuy())
                     .build();
             storeCart.setCreateTime(new Date());
+            if (type != null) {
+                storeCart.setType(type);
+            }
             checkProductStock(cartParam.getProductId(),storeCart.getProductAttrValueId());
             fsStoreCartMapper.insertFsStoreCart(storeCart);
             return R.ok().put("id",storeCart.getId());
@@ -186,6 +199,9 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
                         .isBuy(0)
                         .build();
                 storeCart.setCreateTime(new Date());
+                if (type != null) {
+                    storeCart.setType(type);
+                }
                 checkProductStock(cartParam.getProductId(),storeCart.getProductAttrValueId());
                 fsStoreCartMapper.insertFsStoreCart(storeCart);
                 return R.ok().put("id",storeCart.getId());
@@ -193,6 +209,9 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
             else{
                 storeCart=cart.get(0);
                 storeCart.setCartNum(cartParam.getCartNum() + cart.get(0).getCartNum());
+                if (type != null) {
+                    storeCart.setType(type);
+                }
                 storeCart.setUpdateTime(new Date());
                 checkProductStock(cartParam.getProductId(),storeCart.getProductAttrValueId());
                 fsStoreCartMapper.updateFsStoreCart(storeCart);

+ 75 - 46
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -886,45 +886,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             if (param.getPayType().equals("1")) {
                 //全款支付
                 storeOrder.setStatus(0);
-                FsCompanyExternalPayReceipt receipt = param.getReceipt();
-                if (param.getCompanyCustomerId() != null && receipt != null) {
-                    int compareTo = receipt.getTotalFee().compareTo(storeOrder.getPayPrice());
-                    //部分抵扣 把订单总金额减去收款金额
-                    if (compareTo < 0) {
-                        storeOrder.setTotalPrice(storeOrder.getTotalPrice().subtract(receipt.getTotalFee()));
-                        storeOrder.setPayPrice(storeOrder.getPayPrice().subtract(receipt.getTotalFee()));
-                        storeOrder.setDeductionPrice(receipt.getTotalFee());
-                    }
-                    //全部抵扣需把支付金额改成订单总金额
-                    if (compareTo >= 0) {
-                        storeOrder.setPaid(1);
-                        storeOrder.setStatus(1);
-                        storeOrder.setPayPrice(new BigDecimal(0));
-                        storeOrder.setDeductionPrice(receipt.getTotalFee());
-                        storeOrder.setPayMoney(storeOrder.getTotalPrice());
-                    }
-                }
             } else if (param.getPayType().equals("2")) {
                 //物流代收
                 storeOrder.setStatus(1);
-                FsCompanyExternalPayReceipt receipt = param.getReceipt();
-                if (param.getCompanyCustomerId() != null && receipt != null) {
-                    int compareTo = receipt.getTotalFee().compareTo(storeOrder.getPayPrice());
-                    if (compareTo < 0) {
-                        storeOrder.setTotalPrice(storeOrder.getTotalPrice().subtract(receipt.getTotalFee()));
-                        storeOrder.setPayPrice(storeOrder.getPayPrice().subtract(receipt.getTotalFee()));
-                        storeOrder.setDeductionPrice(receipt.getTotalFee());
-                    }
-                    if (compareTo >= 0) {
-                        storeOrder.setPayMoney(storeOrder.getTotalPrice());
-                        storeOrder.setPayPrice(new BigDecimal(0));
-                        storeOrder.setDeductionPrice(receipt.getTotalFee());
-                        //全部抵扣 支付类型改成全款支付
-                        storeOrder.setPayType("1");
-                    }
-                    storeOrder.setPaid(1);
-                }
-
             } else if (param.getPayType().equals("3")) {
                 //货到付款
                 BigDecimal amount = param.getAmount();  //货到付款 自定义代收金额
@@ -936,6 +900,55 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                     storeOrder.setStatus(1);
                 }
             }
+            FsCompanyExternalPayReceipt receipt = param.getReceipt();
+            if (param.getCompanyCustomerId() != null) {
+                //预付金
+                if (param.getPayType().equals("5")) {
+                    boolean b = param.getPrepaidAmount().compareTo(storeOrder.getTotalPrice()) >= 0;
+                    if (b) {
+                        return R.error("定金不能大于等于订单总价");
+                    }
+                    storeOrder.setStatus(0);
+                    storeOrder.setPayPrice(param.getPrepaidAmount());
+                    storeOrder.setPayType("2");
+                }
+                if (receipt != null) {
+                    int compareTo = receipt.getTotalFee().compareTo(storeOrder.getPayPrice());
+                    if(param.getPayType().equals("1")) {
+                        //全款
+                        if (compareTo < 0) {
+                            storeOrder.setTotalPrice(storeOrder.getTotalPrice().subtract(receipt.getTotalFee()));
+                            storeOrder.setPayPrice(storeOrder.getPayPrice().subtract(receipt.getTotalFee()));
+                            storeOrder.setDeductionPrice(receipt.getTotalFee());
+                            storeOrder.setStatus(0);
+                        } else {
+                            storeOrder.setPayMoney(storeOrder.getTotalPrice());
+                            storeOrder.setPayPrice(new BigDecimal(0));
+                            storeOrder.setDeductionPrice(receipt.getTotalFee());
+                            storeOrder.setPaid(1);
+                            storeOrder.setStatus(1);
+                        }
+                    } else if (param.getPayType().equals("2")) {
+                        //物流代收
+                        if (compareTo < 0) {
+                            storeOrder.setTotalPrice(storeOrder.getTotalPrice().subtract(receipt.getTotalFee()));
+                            storeOrder.setPayPrice(storeOrder.getPayPrice().subtract(receipt.getTotalFee()));
+                            storeOrder.setPayMoney(receipt.getTotalFee());
+                            storeOrder.setDeductionPrice(receipt.getTotalFee());
+                            storeOrder.setStatus(1);
+                        } else {
+                            storeOrder.setPayType("1");
+                            storeOrder.setPayMoney(storeOrder.getTotalPrice());
+                        }
+                        storeOrder.setPaid(1);
+                    }
+                } else {
+                    //物理代收付款
+                    if (param.getPayType().equals("2")) {
+                        storeOrder.setPaid(1);
+                    }
+                }
+            }
             Boolean isPay = true;
             if (param.getOrderCreateType() != null && param.getOrderCreateType() == 3 && param.getCompanyId() != null) {
                 //后台制单 判断是否需要付款
@@ -1697,6 +1710,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                         .isPay(0)
                         .isDel(0)
                         .isBuy(0)
+                        .type("gift")
                         .build();
                 storeCart.setCreateTime(new Date());
                 cartService.checkProductStock(giftProduct.getProductId(), storeCart.getProductAttrValueId());
@@ -1725,6 +1739,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             createParam.setOrderMedium(param.getOrderMedium()); //后台制单
             createParam.setReceipt(receipt);//收款信息
             createParam.setCompanyCustomerId(param.getCompanyCustomerId());
+            createParam.setPrepaidAmount(param.getPrepaidAmount());//预付金额
             return this.createOrder(param.getUserId(), createParam);
         } else {
             throw new CustomException("创建失败");
@@ -3419,7 +3434,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
 
         if ("truePrice".equals(key)) {
             for (FsStoreCartQueryVO storeCart : cartInfo) {
-                sumPrice = NumberUtil.add(sumPrice, NumberUtil.mul(storeCart.getCartNum(), storeCart.getPrice()));
+                if ("product".equals(storeCart.getType())) {
+                    sumPrice = NumberUtil.add(sumPrice, NumberUtil.mul(storeCart.getCartNum(), storeCart.getPrice()));
+                }
             }
         } else if ("costPrice".equals(key)) {
             for (FsStoreCartQueryVO storeCart : cartInfo) {
@@ -4320,7 +4337,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
     @Override
     @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
     public R pay(FsStoreOrderPayParam param) {
+        logger.info("开始支付,参数:{}",param);
         FsStoreOrderScrm order=this.selectFsStoreOrderById(param.getOrderId());
+        logger.info("订单信息:{}",order);
         if(order==null){
             return R.error("订单不存在");
         }
@@ -4366,10 +4385,16 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                 }
                 else if(param.getPayType().equals(2)){
                     order.setPayType("2");
-                    BigDecimal payMoney=order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
-                    payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
-                    order.setPayDelivery(order.getPayPrice().subtract(payMoney));
-                    order.setPayMoney(payMoney);
+                    if (order.getCompanyCustomerId() == null) {
+                        BigDecimal payMoney=order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
+                        payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
+                        order.setPayDelivery(order.getPayPrice().subtract(payMoney));
+                        order.setPayMoney(payMoney);
+                    }else {
+                        order.setPayMoney(order.getPayPrice());
+                        order.setPayDelivery(order.getTotalPrice().subtract(order.getPayMoney()));
+                    }
+
                 }
                 else if(param.getPayType().equals(3)){
                     //货到付款
@@ -4857,11 +4882,15 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                 }
                 else if(param.getPayType().equals(2)){
 
-                    order.setPayType("2");
-                    BigDecimal payMoney=order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
-                    payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
-                    order.setPayDelivery(order.getPayPrice().subtract(payMoney));
-                    order.setPayMoney(payMoney);
+                    if (order.getCompanyCustomerId() == null) {
+                        BigDecimal payMoney=order.getPayPrice().multiply(new BigDecimal(storeConfig.getPayRate())).divide(new BigDecimal(100));
+                        payMoney=new BigDecimal(payMoney.setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
+                        order.setPayDelivery(order.getPayPrice().subtract(payMoney));
+                        order.setPayMoney(payMoney);
+                    }else {
+                        order.setPayMoney(order.getPayPrice());
+                        order.setPayDelivery(order.getTotalPrice().subtract(order.getPayMoney()));
+                    }
                 }
                 else if(param.getPayType().equals(3)){
                     //货到付款

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/vo/FsStoreCartQueryVO.java

@@ -28,6 +28,8 @@ import java.math.BigDecimal;
     @Excel(name = "商品数量")
     private Integer cartNum;
 
+    private String type;
+
     String productImage;
 
     String productName;

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/vo/FsStoreProductAttrValueVO.java

@@ -41,5 +41,7 @@ public class FsStoreProductAttrValueVO implements Serializable {
 
     private String cateName;
 
+    private Integer isGift;
+
 
 }