wjj vor 2 Tagen
Ursprung
Commit
516af2c417

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

@@ -1,5 +1,6 @@
 package com.fs.hisStore.param;
 
+import com.fs.qw.domain.FsCompanyExternalPayReceipt;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
@@ -56,4 +57,11 @@ public class FsStoreOrderCreateParam implements Serializable
     private Integer orderMedium; //媒体来源
 
     private Boolean isUserApp = true;
+
+    /**
+     * 收款信息
+     */
+    private FsCompanyExternalPayReceipt receipt;
+
+    private Long companyCustomerId;//患者会员id
 }

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

@@ -18,4 +18,6 @@ public class FsStoreOrderPayParam implements Serializable
     private Integer payType;
 
     private String appId;
+
+    private Long userId;
 }

+ 91 - 1
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -96,7 +96,9 @@ import com.fs.hisStore.domain.*;
 import com.fs.hisStore.enums.*;
 import com.fs.hisStore.service.*;
 import com.fs.qw.domain.FsCompanyCustomer;
+import com.fs.qw.domain.FsCompanyExternalPayReceipt;
 import com.fs.qw.mapper.FsCompanyCustomerMapper;
+import com.fs.qw.mapper.FsCompanyExternalPayReceiptMapper;
 import com.fs.system.service.ISysConfigService;
 import com.fs.wx.miniapp.config.WxMaProperties;
 import com.fs.ybPay.domain.OrderResult;
@@ -356,6 +358,9 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
     @Autowired
     private FsCompanyCustomerMapper fsCompanyCustomerMapper;
 
+    @Autowired
+    private FsCompanyExternalPayReceiptMapper companyExternalPayReceiptMapper;
+
     //ERP 类型到服务的映射
     private Map<Integer, IErpOrderService> erpServiceMap;
     @PostConstruct
@@ -620,6 +625,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         if (StringUtils.isNotEmpty(cartParam.getGiftCartIds())) {
             List<FsStoreCartQueryVO> giftCarts = cartMapper.selectFsStoreCartListByIds(cartParam.getGiftCartIds());
             redisCache.setCacheObject("orderGiftCarts:" + uuid, giftCarts, 300, TimeUnit.SECONDS);
+            redisCache.setCacheObject("orderGiftCartKey:" + uuid, cartParam.getGiftCartIds(), 300, TimeUnit.SECONDS);
         }
         redisCache.setCacheObject("orderKey:" + uuid, cartParam.getCartIds(), 300, TimeUnit.SECONDS);
         redisCache.setCacheObject("orderCarts:" + uuid, carts, 300, TimeUnit.SECONDS);
@@ -744,6 +750,10 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
 //        Integer totalNum = 0;
         BigDecimal integral = BigDecimal.ZERO;
         if (cartIds != null) {
+            //赠品
+            List<FsStoreCartQueryVO> giftCarts = redisCache.getCacheObject("orderGiftCarts:" + param.getOrderKey());
+            String giftCartIds = redisCache.getCacheObject("orderGiftCartKey:" + param.getOrderKey());
+
             //获取购物车列表
             List<FsStoreCartQueryVO> carts = redisCache.getCacheObject("orderCarts:" + param.getOrderKey());
             //获取地址
@@ -754,6 +764,19 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             Boolean isIntegral = false;
             //组合数据
             FsStoreOrderScrm storeOrder = new FsStoreOrderScrm();
+            //扣减金额
+            if (ObjectUtil.isNotNull(param.getReceipt())) {
+                storeOrder.setDeductionPrice(param.getReceipt().getTotalFee());
+                //收款记录更新
+                try {
+                      FsCompanyExternalPayReceipt receipt = new FsCompanyExternalPayReceipt();
+                      receipt.setId(param.getReceipt().getId());
+                      receipt.setStatus(1);
+                      companyExternalPayReceiptMapper.updateFsCompanyExternalPayReceipt(receipt);
+                } catch (Exception e) {
+                    logger.error("收款记录更新失败:{}", e.getMessage());
+                }
+            }
             //订单类型
             storeOrder.setErpType(carts.get(0).getErpType());
             storeOrder.setStoreHouseCode("CK01");
@@ -789,6 +812,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             }
 
             //storeOrder.setCompanyUserId(fsUser.getCompanyUserId());
+            storeOrder.setCompanyCustomerId(param.getCompanyCustomerId());
             storeOrder.setUserId(userId);
             storeOrder.setOrderCode(orderSn);
             storeOrder.setRealName(address.getRealName());
@@ -862,9 +886,45 @@ 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();  //货到付款 自定义代收金额
@@ -931,6 +991,12 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             this.deStockIncSale(carts);
             //保存OrderItem
             List<FsStoreOrderItemScrm> listOrderItem = new ArrayList<>();
+            //赠品和商品合并
+            if (CollectionUtil.isNotEmpty(giftCarts)) {
+                //减库存加销量
+                this.deStockIncSale(giftCarts);
+                carts.addAll(giftCarts);
+            }
             //保存购物车商品信息
             for (FsStoreCartQueryVO vo : carts) {
                 FsStoreCartDTO fsStoreCartDTO = new FsStoreCartDTO();
@@ -966,6 +1032,11 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                 listOrderItem.add(item);
             }
             if (listOrderItem.size() > 0) {
+                if (StringUtils.isNotEmpty(giftCartIds)) {
+                    cartMapper.updateIsPay(giftCartIds);
+                    String newCartIds = storeOrder.getCartId() + "," + giftCartIds;
+                    storeOrder.setCartId(newCartIds);
+                }
                 String itemJson = JSONUtil.toJsonStr(listOrderItem);
                 storeOrder.setItemJson(itemJson);
                 fsStoreOrderMapper.updateFsStoreOrder(storeOrder);
@@ -1556,6 +1627,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
     @Override
     @Transactional
     public R createUserOrder(FsStoreOrderCreateUserParam param) {
+        FsCompanyExternalPayReceipt receipt = null;
         if (param.getCompanyCustomerId() != null) {
             FsCompanyCustomer fsCompanyCustomer = fsCompanyCustomerMapper.selectFsCompanyCustomerById(param.getCompanyCustomerId());
             if (fsCompanyCustomer == null) {
@@ -1570,12 +1642,22 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             address.setProvince(param.getProvince());
             address.setCity(param.getCity());
             address.setDistrict(param.getDistrict());
+            address.setCreateTime(new Date());
             address.setUserId(1L);//目前默认给id为1的用户
             int i = userAddressMapper.insertFsUserAddress(address);
             if (i <= 0) {
                 return R.error("收货地址保存失败");
             }
             param.setAddressId(address.getId());
+            if (param.getReceiveMoneyId() != null) {
+                receipt = companyExternalPayReceiptMapper.selectFsCompanyExternalPayReceiptById(param.getReceiveMoneyId());
+                if (receipt == null) {
+                    return R.error("收款信息不存在");
+                }
+                if (receipt.getStatus() != 0) {
+                    return R.error("收款信息已处理");
+                }
+            }
         } else {
             if (param.getUserId() == null) {
                 return R.error("会员不能为空");
@@ -1641,6 +1723,8 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             createParam.setOrderCreateType(3); //后台制单
             createParam.setOrderType(param.getOrderType());
             createParam.setOrderMedium(param.getOrderMedium()); //后台制单
+            createParam.setReceipt(receipt);//收款信息
+            createParam.setCompanyCustomerId(param.getCompanyCustomerId());
             return this.createOrder(param.getUserId(), createParam);
         } else {
             throw new CustomException("创建失败");
@@ -4258,8 +4342,14 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         }catch (Exception e){
 
         }
+        //获取用户信息
+        FsUserScrm user= null;
+        if(order.getCompanyCustomerId() != null) {
+            user = userService.selectFsUserById(param.getUserId());
+        } else {
+            userService.selectFsUserById(order.getUserId());
 
-        FsUserScrm user=userService.selectFsUserById(order.getUserId());
+        }
         if(user!=null){
             //已改价处理
             if(order.getIsEditMoney()!=null&&order.getIsEditMoney()==1){

+ 1 - 0
fs-user-app/src/main/java/com/fs/app/controller/store/StoreOrderScrmController.java

@@ -210,6 +210,7 @@ public class StoreOrderScrmController extends AppBaseController {
     public R pay(HttpServletRequest request, @Validated @RequestBody FsStoreOrderPayParam param)
     {
         Long orderId = param.getOrderId();
+        param.setUserId(Long.parseLong(getUserId()));
         logger.info("开始处理支付请求, 订单号: {}, 支付类型: {}", orderId, param.getPayType());
 
         RLock lock = redissonClient.getLock(String.format(LOCK_KEY_PAY,orderId));