|
|
@@ -1,6 +1,7 @@
|
|
|
package com.chuanghai.ihotel.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -20,6 +21,7 @@ import com.chuanghai.ihotel.controller.request.SubmitOrderRequest;
|
|
|
import com.chuanghai.ihotel.dao.HotelOrderDao;
|
|
|
import com.chuanghai.ihotel.dto.EventMessageDTO;
|
|
|
import com.chuanghai.ihotel.dto.LockRoomDTO;
|
|
|
+import com.chuanghai.ihotel.entity.HotelOrderBillEntity;
|
|
|
import com.chuanghai.ihotel.entity.HotelOrderEntity;
|
|
|
import com.chuanghai.ihotel.entity.HotelUserEntity;
|
|
|
import com.chuanghai.ihotel.entity.RoomEntity;
|
|
|
@@ -29,8 +31,10 @@ import com.chuanghai.ihotel.enums.EventMessageTypeEnum;
|
|
|
import com.chuanghai.ihotel.enums.OrderBillStatuEnum;
|
|
|
import com.chuanghai.ihotel.enums.OrderStatuEnum;
|
|
|
import com.chuanghai.ihotel.enums.UserIdentityTypeEnum;
|
|
|
+import com.chuanghai.ihotel.service.HotelOrderBillService;
|
|
|
import com.chuanghai.ihotel.service.HotelOrderService;
|
|
|
import com.chuanghai.ihotel.service.HotelUserService;
|
|
|
+import com.chuanghai.ihotel.service.RoomDoorLockDataService;
|
|
|
import com.chuanghai.ihotel.service.RoomRealtimeStatuService;
|
|
|
import com.chuanghai.ihotel.service.RoomService;
|
|
|
import com.chuanghai.ihotel.service.RoomTypeService;
|
|
|
@@ -39,6 +43,7 @@ import com.chuanghai.ihotel.util.CommonUtil;
|
|
|
import com.chuanghai.ihotel.vo.ConfirmOrderVO;
|
|
|
import com.chuanghai.ihotel.vo.LoginUserVO;
|
|
|
import com.chuanghai.ihotel.vo.OrderSubmitVO;
|
|
|
+import com.chuanghai.ihotel.vo.UserOrderDetailVO;
|
|
|
import com.chuanghai.ihotel.vo.UserOrderIndexVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
@@ -71,6 +76,10 @@ public class HotelOrderServiceImpl extends ServiceImpl<HotelOrderDao, HotelOrder
|
|
|
@Autowired
|
|
|
private RoomService roomService;
|
|
|
@Autowired
|
|
|
+ private HotelOrderBillService orderBillService;
|
|
|
+ @Autowired
|
|
|
+ private RoomDoorLockDataService doorLockService;
|
|
|
+ @Autowired
|
|
|
private PayComponent payComponent;
|
|
|
@Autowired
|
|
|
private JXNXSPayConfig jxnxsPayConfig;
|
|
|
@@ -376,4 +385,129 @@ public class HotelOrderServiceImpl extends ServiceImpl<HotelOrderDao, HotelOrder
|
|
|
roomRealtimeStatuService.releaseByBizId(orderEntity.getId());
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public UserOrderDetailVO userOrderDetail(Long orderId) {
|
|
|
+ HotelOrderEntity orderEntity = userGetOrderById(orderId);
|
|
|
+
|
|
|
+ UserOrderDetailVO detailVO = new UserOrderDetailVO();
|
|
|
+ BeanUtils.copyProperties(orderEntity, detailVO);
|
|
|
+
|
|
|
+ RoomTypeEntity roomType = roomTypeService.myGetById(orderEntity.getRoomTypeId());
|
|
|
+ detailVO.setRoomTypeUsualPrice(roomType.getUsualPrice());
|
|
|
+ detailVO.setRoomTypeDiscountPrice(roomType.getDiscountPrice());
|
|
|
+
|
|
|
+ // 订单状态为已入住之后,查询水电等相关信息
|
|
|
+ if (Integer.valueOf(orderEntity.getOrderStatu()).intValue() >= Integer.valueOf(OrderStatuEnum.HOLD_ON.getCode()).intValue()) {
|
|
|
+ HotelOrderBillEntity orderBill = orderBillService.findByOrderId(orderId);
|
|
|
+ if (orderBill == null) {
|
|
|
+ throw new RRException(BizCodeEnume.UNKNOW_EXCEPTION, "用户订单详情-订单状态错误");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(orderBill, detailVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ return detailVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public OrderSubmitVO getOrderPayParam(Long orderId) {
|
|
|
+ HotelOrderEntity orderEntity = userGetOrderById(orderId);
|
|
|
+ if (!OrderStatuEnum.WAIT_PAY.getCode().equalsIgnoreCase(orderEntity.getOrderStatu())) {
|
|
|
+ throw new RRException(BizCodeEnume.PARAMETER_ERROR, "当前订单状态为非待支付状态");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 支付参数
|
|
|
+ String payUrl = String.format(jxnxsPayConfig.getPayUrl(), orderEntity.getOrderNo(), orderEntity.getPayAmount());
|
|
|
+ return OrderSubmitVO.builder().orderId(orderId).payUrl(payUrl).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void userDeleteOrder(Long orderId) {
|
|
|
+ HotelOrderEntity order = userGetOrderById(orderId);
|
|
|
+
|
|
|
+ String orderStatu = order.getOrderStatu();
|
|
|
+
|
|
|
+ // 已取消、待支付、已完成订单才可以被删除
|
|
|
+ if (!(OrderStatuEnum.CANCEL.getCode().equalsIgnoreCase(orderStatu)
|
|
|
+ || OrderStatuEnum.WAIT_PAY.getCode().equalsIgnoreCase(orderStatu)
|
|
|
+ || OrderStatuEnum.FINISH_PAY.getCode().equalsIgnoreCase(orderStatu))) {
|
|
|
+ throw new RRException(BizCodeEnume.PERMISSION_DENIED, "当前订单不可删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateWrapper<HotelOrderEntity> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", orderId);
|
|
|
+ updateWrapper.set("delete_flag", "0"); // 0表示删除
|
|
|
+ updateWrapper.last("limit 1");
|
|
|
+
|
|
|
+ this.update(null, updateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void userCancelOrder(Long orderId) {
|
|
|
+ HotelOrderEntity order = userGetOrderById(orderId);
|
|
|
+
|
|
|
+ // 已取消、待支付、已完成订单才可以被删除
|
|
|
+ if (!OrderStatuEnum.WAIT_PAY.getCode().equalsIgnoreCase(order.getOrderStatu())) {
|
|
|
+ throw new RRException(BizCodeEnume.PERMISSION_DENIED, "当前订单不可取消");
|
|
|
+ }
|
|
|
+ UpdateWrapper<HotelOrderEntity> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", orderId);
|
|
|
+ updateWrapper.set("order_statu", OrderStatuEnum.WAIT_PAY.getCode());
|
|
|
+ updateWrapper.last("limit 1");
|
|
|
+ this.update(null, updateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void userHoldOrder(Long orderId) {
|
|
|
+ HotelOrderEntity order = userGetOrderById(orderId);
|
|
|
+ // 支付完成状态的订单才可以办理入住
|
|
|
+ if (!OrderStatuEnum.FINISH_PAY.getCode().equalsIgnoreCase(order.getOrderStatu())) {
|
|
|
+ throw new RRException(BizCodeEnume.PERMISSION_DENIED, "订单状态异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 订单有效时间校验
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ if (now.isAfter(order.getEnableEndTime())) {
|
|
|
+ throw new RRException(BizCodeEnume.PERMISSION_DENIED, "订单超过有效时间");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long roomId = order.getRoomId();
|
|
|
+ // 水电抄表 => 生成结账单
|
|
|
+ orderBillService.generateBill(orderId, roomId);
|
|
|
+
|
|
|
+ // 门锁密码
|
|
|
+ doorLockService.generatePassword(order);
|
|
|
+
|
|
|
+ // 更新订单状态
|
|
|
+ UpdateWrapper<HotelOrderEntity> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("id", orderId);
|
|
|
+ updateWrapper.set("order_statu", OrderStatuEnum.HOLD_ON.getCode());
|
|
|
+ updateWrapper.last("limit 1");
|
|
|
+ this.update(null, updateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户根据订单id获取订单
|
|
|
+ * @param orderId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private HotelOrderEntity userGetOrderById(Long orderId) {
|
|
|
+ HotelOrderEntity orderEntity = this.getById(orderId);
|
|
|
+ if ("0".equalsIgnoreCase(orderEntity.getDeleteFlag())) {
|
|
|
+ throw new RRException(BizCodeEnume.PARAMETER_ERROR, "订单不存在,订单已删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (orderEntity == null) {
|
|
|
+ throw new RRException(BizCodeEnume.PARAMETER_ERROR, "订单不存在,无效的orderId");
|
|
|
+ }
|
|
|
+
|
|
|
+ LoginUserVO loginUserVO = LoginCheckAspect.threadLocal.get();
|
|
|
+ String userFlag = loginUserVO.getCardNumber();
|
|
|
+ if (!orderEntity.getUserFlag().equalsIgnoreCase(userFlag)) {
|
|
|
+ throw new RRException(BizCodeEnume.PERMISSION_DENIED, "非自己的订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ return orderEntity;
|
|
|
+ }
|
|
|
}
|