Browse Source

修改bug

夏文涛 2 years ago
parent
commit
697e889734

+ 1 - 1
mhotel/src/com/happy/action/AppBookingAction.java

@@ -261,7 +261,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
      * userId; // 下单人id
      * 用户点击订房操作,生成订单
      */
-    public String createOrder() {
+    public String createOrder() throws ParseException {
         // 插入订单数据到表中
         JSONObject jsonObject = new JSONObject();
         if (Func.checkNull(houseId) || Func.checkNull(startTime) || Func.checkNull(endTime)

+ 1 - 0
mhotel/src/com/happy/action/AppBookingCommentAction.java

@@ -303,6 +303,7 @@ public class AppBookingCommentAction extends ActionSupport implements ServletReq
         JSONObject jsonObject = new JSONObject();
 
         JSONObject json = GetHttpParam.getHttpParam(request);
+        System.out.println("参数:"+json.toString());
         if (json == null) {
             jsonObject.put("code", 400);
             jsonObject.put("success", false);

+ 1 - 1
mhotel/src/com/happy/dao/impl/BookingCommentImplDao.java

@@ -48,7 +48,7 @@ public class BookingCommentImplDao implements BookingCommentDao {
      */
     @Override
     public String insertBookingComment(BookingComment bookingComment) {
-        String sql = "insert into `booking_comment`(id,comment_id,comment_parent_id,comment_name,booking_id,hotel_id,house_id,content,comment_status,score, " +
+        String sql = "insert into `booking_comment` (id,comment_id,comment_parent_id,comment_name,booking_id,hotel_id,house_id,content,comment_status,score, " +
                 "score_ws,score_fw,score_ss,score_wz,create_id,create_username,create_date,modify_date,status) " +
                 "values(:id,:comment_id,:comment_parent_id,:comment_name,:booking_id,:hotel_id,:house_id,:content,:comment_status,:score,:score_ws,:score_fw,:score_ss,:score_wz,:create_id,:create_username,:create_date,:modify_date,:status) ";
         MapSqlParameterSource sps = new MapSqlParameterSource();

+ 1 - 1
mhotel/src/com/happy/dao/impl/BookingComplainImplDao.java

@@ -143,7 +143,7 @@ public class BookingComplainImplDao implements BookingComplainDao {
                 "\t( SELECT bcp.progress_type FROM booking_complaint_progress bcp WHERE bcp.complaint_id = bc.id ORDER BY bcp.create_date DESC LIMIT 1 ) AS progressType \n" +
                 "FROM\n" +
                 "\t`booking_complaint` bc\n" +
-                "\tLEFT JOIN booking b ON b.id = bc.booking_id AND b.status_del=1  LEFT JOIN file_info fi on bc.house_id=fi.link_id  where bc.create_id=:usersId  DESC limit :start,:rows )bc2 ORDER BY bc2.progressType asc ,bc2.dateTime DESC ";
+                "\tLEFT JOIN booking b ON b.id = bc.booking_id AND b.status_del=1  LEFT JOIN file_info fi on bc.house_id=fi.link_id  where bc.create_id=:usersId limit :start,:rows )bc2 ORDER BY bc2.progressType asc ,bc2.dateTime DESC ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("start", start);
         sps.addValue("rows", rows);

+ 2 - 1
mhotel/src/com/happy/service/AppBookService.java

@@ -3,6 +3,7 @@ package com.happy.service;
 import com.happy.Model.Booking;
 import com.happy.dto.IPage;
 
+import java.text.ParseException;
 import java.util.List;
 
 public interface AppBookService {
@@ -19,7 +20,7 @@ public interface AppBookService {
      * @param userId
      * @return
      */
-    public String createOrder(String bookingId, String houseId,String startTime,String endTime,String houseOrderNumber,String userName,String userPhone, String userId,String complaintId,String useId);
+    public String createOrder(String bookingId, String houseId,String startTime,String endTime,String houseOrderNumber,String userName,String userPhone, String userId,String complaintId,String useId) throws ParseException;
 
 
 //    /**

+ 123 - 62
mhotel/src/com/happy/service/impl/AppBookImplService.java

@@ -14,13 +14,19 @@ import com.happy.constant.ResultStatusCode;
 import com.happy.dao.BookDao;
 import com.happy.dto.IPage;
 import com.happy.service.*;
+import com.happy.vo.DailyPriceVo;
+import com.happy.vo.HousePriceDataVo;
+import com.happy.vo.HousePriceOneDataVo;
+import com.happy.vo.HousePriceResultVo;
 import org.apache.struts2.ServletActionContext;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.text.ParseException;
 import java.util.*;
+import java.util.stream.Collectors;
 
 
 @Service("AppBookService")
@@ -40,6 +46,8 @@ public class AppBookImplService implements AppBookService {
     public HotelDictService hotelDictService;
     @Resource
     public AdminManagerService adminManagerService;
+    @Resource
+    public HousePriceService housePriceService;
 
     @Resource
     public HotelCoupomService hotelCoupomService;
@@ -48,7 +56,7 @@ public class AppBookImplService implements AppBookService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public String createOrder(String bookingId, String houseId, String startTime, String endTime, String houseOrderNumber, String userName, String userPhone, String userId, String complaintId, String useId) {
+    public String createOrder(String bookingId, String houseId, String startTime, String endTime, String houseOrderNumber, String userName, String userPhone, String userId, String complaintId, String useId) throws ParseException {
         if (Func.checkNull(houseId) || Func.checkNull(startTime) || Func.checkNull(endTime)
                 || Func.checkNull(houseOrderNumber) || Func.checkNull(userName) || Func.checkNull(userPhone) || Func.checkNull(userId))
             return null;
@@ -59,13 +67,13 @@ public class AppBookImplService implements AppBookService {
         Hotel hotel = hotelService.getOen(s1.toString());
         Users user = userService.queryByUserId(userId);
         AdminManager adminManager = adminManagerService.getById(Func.parseInt(house.getManagerId()));
-        if (house == null || hotel == null || user == null  || adminManager == null )
+        if (house == null || hotel == null || user == null || adminManager == null)
             return "无法获取数据";
 
         Booking booking = new Booking();
 
-        int day = DateUtil.getDayDiff(startTime,endTime); // 中间多少天
-        String orderLiveTime= Func.parseInt(houseOrderNumber)+ OrderEnum.间.toString()+ day +OrderEnum.晚.toString();
+        int day = DateUtil.getDayDiff(startTime, endTime); // 中间多少天
+        String orderLiveTime = Func.parseInt(houseOrderNumber) + OrderEnum.间.toString() + day + OrderEnum.晚.toString();
         String hotelType = hotelDictService.getDictNameById(Integer.parseInt(hotel.getHtype()));// 民宿类型hotel.getHtype()
 
 
@@ -93,64 +101,119 @@ public class AppBookImplService implements AppBookService {
         booking.setHouseOrderNumber(Func.parseInt(houseOrderNumber));
         booking.setHouseAreas(house.gethAreas());
         booking.setHouseRemake(house.getRemark());
-        double totalPrice = Func.parseDbl(houseOrderNumber) * house.getPrice() * day;
+
+        /**
+         * 2023-09-15 A-jax 订单总价等于房间数量 * 这些天的价格总和 * 预定天数
+         */
+        List<HousePriceDataVo> priceDatas = housePriceService.queryPriceByHouseId(Integer.valueOf(house.getId()), startTime, TimeExchange.TimeDesD(endTime, -1));
+
+        List<HousePriceOneDataVo> oneDatas = new ArrayList<>();
+        //将数据处理成单天的
+        for (HousePriceDataVo hp : priceDatas) {
+            if (hp.getStartTime().equals(hp.getEndTime())) {
+                HousePriceOneDataVo oneData = new HousePriceOneDataVo();
+                oneData.setSetDate(hp.getStartTime());
+                oneData.setCreateDate(hp.getCreateDate());
+                oneData.setPrice(hp.getPrice());
+                oneData.setHouseId(hp.getHouseId());
+                oneDatas.add(oneData);
+            } else {
+                int beDateNum = TimeExchange.daysBetween(hp.getStartTime(), hp.getEndTime());
+                for (int i = 0; i <= beDateNum; i++) {
+                    HousePriceOneDataVo oneData = new HousePriceOneDataVo();
+                    oneData.setSetDate(TimeExchange.TimeDesD(hp.getStartTime(), i));
+                    oneData.setCreateDate(hp.getCreateDate());
+                    oneData.setPrice(hp.getPrice());
+                    oneData.setHouseId(hp.getHouseId());
+                    oneDatas.add(oneData);
+                }
+            }
+        }
+
+        List<String> dateStrs = new ArrayList<>();
+        int dateNum = TimeExchange.daysBetween(startTime, endTime);
+        for (int i = 0; i <= dateNum; i++) {
+            String date = TimeExchange.TimeDesD(startTime, i);
+            dateStrs.add(date);
+        }
+
+        /**
+         * 获取该房型默认价格
+         */
+        Double housePrice = houseService.queryPriceByHouseId(Integer.valueOf(house.getId()));
+        Double dayPrices = 0.0;
+        for (String dateStr : dateStrs) {
+            HousePriceResultVo data = new HousePriceResultVo();
+            data.setDate(dateStr);
+            List<HousePriceOneDataVo> datas = oneDatas.stream().filter(e -> e.getSetDate().equals(dateStr)).sorted(Comparator.comparing(HousePriceOneDataVo::getCreateDate, Comparator.reverseOrder())).collect(Collectors.toList());
+
+            if (!dateStr.equals(endTime)) {
+                if (datas.size() > 0) {
+                    dayPrices = dayPrices + datas.get(0).getPrice();
+                } else {
+                    dayPrices = dayPrices + housePrice;
+                }
+            }
+        }
+
+        double totalPrice = Func.parseDbl(houseOrderNumber) * dayPrices * day;
 
         if (!Func.checkNull(complaintId) && !Func.checkNull(useId)) {
             HotelCouponStatus hotelCouponStatus = hotelCoupomStatusService.getById(useId);
-            if (hotelCouponStatus!=null) {
+            if (hotelCouponStatus != null) {
                 hotelCouponStatus.setStatus(2);
                 hotelCouponStatus.setBookingId(bookingId);
                 BigDecimal totalPriceBigDecimal = new BigDecimal(totalPrice);
 
-            //        优惠券
-            HotelCoupon hotelCoupon = hotelCoupomService.getById(complaintId);
-            Integer type = hotelCoupon.getType();
-            if (1 == type) {
+                //        优惠券
+                HotelCoupon hotelCoupon = hotelCoupomService.getById(complaintId);
+                Integer type = hotelCoupon.getType();
+                if (1 == type) {
 //            满减金额
-                Double meetPrice = hotelCoupon.getMeetPrice();
-                BigDecimal meetPriceBigDecimal = new BigDecimal(meetPrice);
-
-                if (meetPrice < totalPrice) {
-                    //            减免金额
-                    Double deductionPrice = hotelCoupon.getDeductionPrice();
-                    BigDecimal deductionPriceBigDecimal = new BigDecimal(deductionPrice);
-                    //            实付金额
-                    BigDecimal subtract = totalPriceBigDecimal.subtract(deductionPriceBigDecimal);
-                    totalPrice = subtract.doubleValue();
-                    hotelCouponStatus.setDiscountAmount(deductionPrice);
-                    hotelCoupomStatusService.update(hotelCouponStatus);
-                }
-
-            } else if (2 == type) {
+                    Double meetPrice = hotelCoupon.getMeetPrice();
+                    BigDecimal meetPriceBigDecimal = new BigDecimal(meetPrice);
+
+                    if (meetPrice < totalPrice) {
+                        //            减免金额
+                        Double deductionPrice = hotelCoupon.getDeductionPrice();
+                        BigDecimal deductionPriceBigDecimal = new BigDecimal(deductionPrice);
+                        //            实付金额
+                        BigDecimal subtract = totalPriceBigDecimal.subtract(deductionPriceBigDecimal);
+                        totalPrice = subtract.doubleValue();
+                        hotelCouponStatus.setDiscountAmount(deductionPrice);
+                        hotelCoupomStatusService.update(hotelCouponStatus);
+                    }
+
+                } else if (2 == type) {
 //            享受的折扣
-                Double rebatePrice = hotelCoupon.getRebatePrice();
-                BigDecimal rebatePriceBigDecimal = new BigDecimal(rebatePrice/10);
+                    Double rebatePrice = hotelCoupon.getRebatePrice();
+                    BigDecimal rebatePriceBigDecimal = new BigDecimal(rebatePrice / 10);
 
 //            最大减免金额
-                Double maxDeduction = hotelCoupon.getMaxDeduction();
-                BigDecimal maxDeductionBigDecimal = new BigDecimal(maxDeduction);
+                    Double maxDeduction = hotelCoupon.getMaxDeduction();
+                    BigDecimal maxDeductionBigDecimal = new BigDecimal(maxDeduction);
 
 //            折扣后的价格
-                BigDecimal bigDecimal = totalPriceBigDecimal.multiply(rebatePriceBigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
-                double v = bigDecimal.doubleValue();
+                    BigDecimal bigDecimal = totalPriceBigDecimal.multiply(rebatePriceBigDecimal).setScale(2, BigDecimal.ROUND_HALF_UP);
+                    double v = bigDecimal.doubleValue();
 
 //            减去最大折扣后的价格
-                BigDecimal subtract = totalPriceBigDecimal.subtract(maxDeductionBigDecimal);
-                double v1 = subtract.doubleValue();
-
-                if (v > v1) {
-                    totalPrice = v;
-                    BigDecimal subtract1 = totalPriceBigDecimal.subtract(bigDecimal);
-                    hotelCouponStatus.setDiscountAmount(subtract1.doubleValue());
-                } else if (v < v1) {
-                    totalPrice = v1;
-                    hotelCouponStatus.setDiscountAmount(maxDeduction);
-                }else if (v==v1){
-                    totalPrice = v1;
-                    hotelCouponStatus.setDiscountAmount(maxDeduction);
-                }
+                    BigDecimal subtract = totalPriceBigDecimal.subtract(maxDeductionBigDecimal);
+                    double v1 = subtract.doubleValue();
+
+                    if (v > v1) {
+                        totalPrice = v;
+                        BigDecimal subtract1 = totalPriceBigDecimal.subtract(bigDecimal);
+                        hotelCouponStatus.setDiscountAmount(subtract1.doubleValue());
+                    } else if (v < v1) {
+                        totalPrice = v1;
+                        hotelCouponStatus.setDiscountAmount(maxDeduction);
+                    } else if (v == v1) {
+                        totalPrice = v1;
+                        hotelCouponStatus.setDiscountAmount(maxDeduction);
+                    }
 
-                hotelCoupomStatusService.update(hotelCouponStatus);
+                    hotelCoupomStatusService.update(hotelCouponStatus);
 
                 }
             }
@@ -175,9 +238,9 @@ public class AppBookImplService implements AppBookService {
         int i = bookService.insertBooking(booking);
 
         // 生成订单时,写入数据操作
-        bookinglogService.addBooklog(OrderEnum.生成订单.toString(),booking);
+        bookinglogService.addBooklog(OrderEnum.生成订单.toString(), booking);
 
-        if ( i == 0)
+        if (i == 0)
             return ResultStatusCode.CANNTBOOKING.CANNTBOOKING.getMsg();
 
         return null;
@@ -191,7 +254,7 @@ public class AppBookImplService implements AppBookService {
         if (Func.checkNull(houseOrderNumber))
             houseOrderNumber = "0";
 
-        if(house.getNumber() < Func.parseInt(houseOrderNumber))
+        if (house.getNumber() < Func.parseInt(houseOrderNumber))
             return OrderEnum.超出限定房间数量.toString();
 
         // 判断是否有房间,对每个房型进行标识
@@ -215,45 +278,43 @@ public class AppBookImplService implements AppBookService {
 
         Map<String, Integer> timeMap = new HashMap(); // map<时间,天数>进行累加
 //        int totalNum = 0;
-        for (Booking booking: bookList) {
+        for (Booking booking : bookList) {
             if (Func.checkNull(booking.getHouseId()))
                 continue;
 
-            int day = DateUtil.getDayDiff(booking.getOrderStartTime(),booking.getOrderEndTime());
+            int day = DateUtil.getDayDiff(booking.getOrderStartTime(), booking.getOrderEndTime());
             for (int i = 0; i < day; i++) {
-                String time = DateUtil.parseDateToStr(DateUtil.addDate(DateUtil.parseDateOnly(booking.getOrderStartTime()),Calendar.DATE,i),DateUtil.Time_Formatter_Day);
-                if (!timeMap.containsKey(time))
-                {
-                    timeMap.put(time,booking.getHouseOrderNumber());
+                String time = DateUtil.parseDateToStr(DateUtil.addDate(DateUtil.parseDateOnly(booking.getOrderStartTime()), Calendar.DATE, i), DateUtil.Time_Formatter_Day);
+                if (!timeMap.containsKey(time)) {
+                    timeMap.put(time, booking.getHouseOrderNumber());
                     continue;
                 }
 
-                timeMap.put(time,booking.getHouseOrderNumber() + Func.parseInt(timeMap.get(time)));
+                timeMap.put(time, booking.getHouseOrderNumber() + Func.parseInt(timeMap.get(time)));
             }
         }
 
         List<String> dayQueryList = new ArrayList();
         // 遍历查询的每一天当做一个列表数据
-        int dayQuerys = DateUtil.getDayDiff(startTime,endTime);
+        int dayQuerys = DateUtil.getDayDiff(startTime, endTime);
         for (int i = 0; i < dayQuerys; i++) {
-            String time = DateUtil.parseDateToStr(DateUtil.addDate(DateUtil.parseDateOnly(startTime),Calendar.DATE,i),DateUtil.Time_Formatter_Day);
+            String time = DateUtil.parseDateToStr(DateUtil.addDate(DateUtil.parseDateOnly(startTime), Calendar.DATE, i), DateUtil.Time_Formatter_Day);
             dayQueryList.add(time);
         }
 
 
-        for (String dayQuery: dayQueryList) {
+        for (String dayQuery : dayQueryList) {
             if (Func.checkNull(dayQuery))
                 continue;
 
-            if (timeMap.containsKey(dayQuery))
-            {
+            if (timeMap.containsKey(dayQuery)) {
                 int totalNum = timeMap.get(dayQuery); // 当天房间的数量
                 // 订单中房数量》= 总房间数量 表示已满
                 if (totalNum >= house.getNumber())
                     return dayQuery + OrderEnum.房间已满.toString();
 
                 // 现存房数量 《 要订的订房数量   表示已满
-                if((house.getNumber() - totalNum) < Func.parseInt(houseOrderNumber))
+                if ((house.getNumber() - totalNum) < Func.parseInt(houseOrderNumber))
                     return dayQuery + OrderEnum.房间已满.toString();
             }