Przeglądaj źródła

入住时添加房费

qh 2 lat temu
rodzic
commit
95804c64f2

+ 1 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/dto/BookingOrderSaveDto.java

@@ -23,6 +23,7 @@ public class BookingOrderSaveDto  {
     private List<BusLivingLayoutDayPrice> livingRoomDayPrices;
     @ApiModelProperty(value = "如果是团队预定,关联房间ID和房型每天价格 走这个参数")
     private List<BookingBatchRoomsDto> batchRooms;
+    @ApiModelProperty(value = "订单的费用信息,这里添加的费用默认关联到主房")
     private List<BusOrderFee> orderFees;
     // 联系人名称
     private String contactName;

+ 54 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/enums/FeeSubjectType.java

@@ -0,0 +1,54 @@
+package org.jeecg.modules.business.enums;
+
+import org.jeecg.common.system.vo.DictModel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public enum FeeSubjectType {
+
+    YA_JIN(1,"押金"),
+    YU_SHOU(2,"预收房费"),
+    MEI_RI_FANG_FEI(3,"每日房费");
+
+    Integer key;
+
+    String title;
+
+    FeeSubjectType(Integer key, String title){
+        this.key = key;
+        this.title = title;
+    }
+    public Integer getKey() {
+        return key;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    /**
+     * 获取字典数据
+     * @return
+     */
+    public static List<DictModel> getDictList(){
+        List<DictModel> list = new ArrayList<>();
+        DictModel dictModel = null;
+        for(CouponsEventEnum e: CouponsEventEnum.values()){
+            dictModel = new DictModel();
+            dictModel.setValue(e.key.toString());
+            dictModel.setText(e.title);
+            list.add(dictModel);
+        }
+        return list;
+    }
+
+    public static FeeSubjectType val(Integer key){
+        for(FeeSubjectType bld: values()){
+            if(bld.key .equals(key)){
+                return bld;
+            }
+        }
+        return null;
+    }
+}

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

@@ -4,16 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.TokenUtils;
 import org.jeecg.modules.business.dto.BatchOrderSavaDto;
 import org.jeecg.modules.business.dto.BookingBatchRoomsDto;
 import org.jeecg.modules.business.dto.BookingOrderSaveDto;
 import org.jeecg.modules.business.dto.TodayBookingQueryDto;
 import org.jeecg.modules.business.entity.*;
-import org.jeecg.modules.business.enums.BookingOrdersType;
-import org.jeecg.modules.business.enums.BookingStatusTypeEnum;
-import org.jeecg.modules.business.enums.CheckInTypeEnum;
-import org.jeecg.modules.business.enums.CustomerTypeEnum;
+import org.jeecg.modules.business.enums.*;
 import org.jeecg.modules.business.mapper.BusRoomBookingOrdersMapper;
 import org.jeecg.modules.business.service.*;
 import org.jeecg.modules.business.vo.BatchOrderEditVo;
@@ -33,6 +31,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.util.*;
@@ -74,6 +73,9 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
     @Resource
     private CesRoomsServiceImpl roomsService;
 
+    @Resource
+    private IBusOrderFeeService feeService;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String bookingOrderSave(BookingOrderSaveDto item, Boolean isTeam) {
@@ -987,19 +989,57 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
 
     private Map<String,String> bookingRoomToLiving(BookingOrderSaveDto livingData, List<ExtendBusBookingRoomsVo> roomIds, BookingOrderEditVo bookingOrderVo) {
         Map<String,String> results = new HashMap<>();
+
         roomIds.forEach(bkRoom-> {
             if(livingData.getRoomIds().stream().filter(s->s.getRoomId().equals(bkRoom.getRoomId())).count() == 0)
                 throw new JeecgBootException("房间信息未找到");
+
             List<BusLivingCustomer> customers = livingData.getRoomIds().stream().filter(s->s.getRoomId().equals(bkRoom.getRoomId())).findFirst().get().getLivingCustomers();
             if(customers == null || customers.size() == 0) throw new JeecgBootException("请添加客户信息");
             String livingOrderId = bookingToLive(bkRoom.getId(), customers);
-
-
+            // 费用关联到主房
+            if(livingData.getOrderFees()!=null && livingData.getOrderFees().size() > 0 && bkRoom.getIsMain() !=null && bkRoom.getIsMain()) {
+                livingData.getOrderFees().forEach(s->{
+                    s.setRoomId(bkRoom.getRoomId());
+                    s.setLivingOrderId(livingOrderId);
+                    s.setCreateTime(new Date());
+                    s.setFeeType(2);// 收款
+                    if(FeeSubjectType.val(s.getSubjectType()) == null) {
+                        throw new JeecgBootException("收款项目不存在,请核对后操作");
+                    }
+                });
+                feeService.saveBatch(livingData.getOrderFees());
+            }
+            // 另外每个房间还要在入住时生成每日房费账单
+            BusOrderFee roomFee = new BusOrderFee();
+            roomFee.setRoomId(bkRoom.getRoomId());
+            roomFee.setLivingOrderId(livingOrderId);
+            roomFee.setFeeType(1); // 消费
+            BigDecimal dayRoomFee =  currentDayFee(bkRoom.getLayoutDayPrices(),null);
+            if(dayRoomFee == null)
+                throw new JeecgBootException("未找到当日房价");
+            roomFee.setMoney(dayRoomFee); // 取当日房费的优惠价  其他时间要查询房价方案、每日房价,房型门市价按照规则去取
+            roomFee.setCreateTime(new Date());
+            roomFee.setDayTime(new Date());
+            feeService.save(roomFee);
             results.put(bkRoom.getRoomId(),livingOrderId);
         });
         return results;
     }
 
+    private BigDecimal currentDayFee(List<BusBookingLayoutDayPrice> dayPrices, BigDecimal defaultPrice){
+        Optional<BusBookingLayoutDayPrice> opDayPrice = dayPrices.stream().filter(
+                s-> DateUtils.formatDate(s.getDayTime())
+                        .equals(DateUtils.formatDate(new Date())
+        )).findFirst();
+        if(opDayPrice.isPresent()) {
+            return opDayPrice.get().getPrice();
+        } else {
+            return defaultPrice;
+        }
+    }
+
+
 
     private BusRoomsLivingOrder copyBookingToAcceptOrder(BusRoomBookingOrders bkOrder) {
         BusRoomsLivingOrder livingOrder = new BusRoomsLivingOrder();