|
|
@@ -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();
|
|
|
}
|
|
|
|