Ver código fonte

会员卡支付账单

qh 2 anos atrás
pai
commit
66019826e7

+ 2 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/BusOrderFee.java

@@ -105,6 +105,8 @@ public class BusOrderFee implements Serializable {
     private String contactId;
     @ApiModelProperty(value = "结账状态,1未结账2已结账")
     private Integer preferentialStatus;
+    @ApiModelProperty(value = "会员卡结费ID")
+    private String vipCardId;
 
 
 

+ 1 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusMemberBalanceLogServiceImpl.java

@@ -34,7 +34,7 @@ public class BusMemberBalanceLogServiceImpl extends ServiceImpl<BusMemberBalance
      * @param prefix
      * @return
      */
-    private String randomNumber(String prefix) {
+    public static String randomNumber(String prefix) {
         int first = new Random(10).nextInt(8) + 1;
         int hashCode = UUID.randomUUID().toString().hashCode();
         if (hashCode < 0) {

+ 68 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusRoomBookingOrdersServiceImpl.java

@@ -73,6 +73,18 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
     @Resource
     private IBusOrderFeeService feeService;
 
+    @Resource
+    private IBusMarketCouponsCashUsedService marketCouponsCashUsedService;
+
+    @Resource
+    private IBusMemberCardService memberCardService;
+
+    @Resource
+    private IBusMemberBalanceLogService memberBalanceLogService;
+
+    @Resource
+    private  IBusRoomPayTypeService payTypeService;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String bookingOrderSave(BookingOrderSaveDto item, Boolean isTeam) {
@@ -1185,12 +1197,31 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
         return true;
     }
 
+    String getBookingRoomHotelId(BusBookingRooms bookingRoom) {
+        return roomsService.getById(bookingRoom.getRoomId()).getHotelId();
+    }
     private void settleFee(BusBookingRooms mainRoom, BusRoomsLivingOrder mainRoomOrder, List<BusOrderFee> feeItems, List<BusOrderFee> settleFees) {
         if(settleFees.size() == 0) throw new JeecgBootException("参数错误");
+        String hotelId =  getBookingRoomHotelId(mainRoom);
+        LoginUser user = TokenUtils.getAuthUser();
+        if(user == null) throw new JeecgBootException("请登录");
+        if(hotelId == null) throw  new JeecgBootException("未找到酒店");
         BusOrderFee preferFeeItem = null;
         if(settleFees.stream().anyMatch(s->s.getIsPreferential().equals(true))){
             preferFeeItem = settleFees.stream().filter(s->s.getIsPreferential().equals(true)).findFirst().get();
             if(preferFeeItem.getMoney()==null || preferFeeItem.getMoney().compareTo(BigDecimal.valueOf(0)) <= 0) throw new JeecgBootException("优惠价不能小于或等于0");
+            if(preferFeeItem.getCouponscashId() != null && !preferFeeItem.getCouponscashId().isEmpty()) {
+                BusMarketCouponsCashUsed couponTicket = marketCouponsCashUsedService.getById(preferFeeItem.getCouponscashId()); // 优惠票券
+                if(couponTicket == null) throw new JeecgBootException("优惠券不存在");
+                if(!couponTicket.getStatus().equals(CouponsStatusEnum.received.getKey())) {
+                    CouponsStatusEnum couponStatusText = CouponsStatusEnum.val(couponTicket.getStatus());
+                    if(couponStatusText == null) throw new JeecgBootException("优惠券状态异常");
+                    throw new JeecgBootException("优惠券"+ couponStatusText.getTitle());
+                } else {
+                    couponTicket.setStatus(CouponsStatusEnum.used.getKey());
+                    marketCouponsCashUsedService.updateById(couponTicket);
+                }
+            }
             preferFeeItem.setCreateTime(new Date());
             preferFeeItem.setSubjectType(FeeSubjectType.YOU_HUI.getKey());
             preferFeeItem.setFeeType(1);
@@ -1201,9 +1232,45 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
             preferFeeItem.setPreferentialStatus(2);
             feeService.save(preferFeeItem);
         }
-
+        List<BusRoomPayType> payTypes = payTypeService.list();
         settleFees.forEach(s->{
             if(s.getIsPreferential().equals(true)) return;
+
+            String payTypeId = s.getPayType();
+            if(payTypeId != null && !payTypeId.isEmpty()) {
+                Optional<BusRoomPayType> opPayType = payTypes.stream().filter(a->a.getId().equals(payTypeId)).findAny();
+                if(!opPayType.isPresent()) throw new JeecgBootException("收款支付方式错误");
+                BusRoomPayType payType = opPayType.get();
+                // 会员卡付费
+                if(payType.getName().equals("会员卡")) {
+                    if(mainRoomOrder.getCustomerType() == null || !mainRoomOrder.getCustomerType().equals(CustomerTypeEnum.VIP.getKey()))
+                        throw new JeecgBootException("客人类型不是会员");
+                    if(mainRoomOrder.getVipCustomerId() == null || mainRoomOrder.getVipCustomerId().isEmpty())
+                        throw new JeecgBootException("会员不存在");
+                    BusMemberCard vipCard = memberCardService.getById(mainRoomOrder.getVipCustomerId());
+                    if(vipCard == null) throw new JeecgBootException("会员不存在");
+                    if(vipCard.getBalance().compareTo(s.getMoney()) < 0) throw new JeecgBootException("会员卡余额不足");
+                    vipCard.setBalance(vipCard.getBalance().subtract(s.getMoney()));
+                    // log
+                    BusMemberBalanceLog balanceLog = new BusMemberBalanceLog();
+                    balanceLog.setMoney(s.getMoney());
+                    balanceLog.setBalance(vipCard.getBalance());
+                    balanceLog.setType(2);// 扣费
+                    balanceLog.setStatus(1);// TODO:不知道干什么用的 貌似是个啥支付状态
+                    balanceLog.setGiveMoney(new BigDecimal(0));
+                    balanceLog.setRemarks("房间收费扣款");
+                    balanceLog.setHotelId(hotelId);
+                    balanceLog.setTenantId(user.getRelTenantIds());
+                    balanceLog.setPaymentMethod("");
+                    balanceLog.setPayMoney(new BigDecimal(0));
+                    balanceLog.setCode(BusMemberBalanceLogServiceImpl.randomNumber("KF"));
+                    balanceLog.setCreateTime(new Date());
+                    memberBalanceLogService.save(balanceLog);
+                    // todo 积分规则
+
+//                    memberBalanceLogService.
+                }
+            }
             s.setCreateTime(new Date());
             s.setPreferentialStatus(2);
             s.setFeeType(2);