|
|
@@ -2,6 +2,7 @@ package shop.alien.store.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
@@ -15,6 +16,7 @@ import shop.alien.entity.store.dto.UserReservationDTO;
|
|
|
import shop.alien.entity.store.vo.StoreMainInfoVo;
|
|
|
import shop.alien.entity.store.vo.StoreReservationListVo;
|
|
|
import shop.alien.entity.store.vo.UserReservationVo;
|
|
|
+import shop.alien.mapper.UserReservationOrderMapper;
|
|
|
import shop.alien.store.vo.BookingTableItemVo;
|
|
|
import shop.alien.store.vo.ReservationOrderDetailVo;
|
|
|
import shop.alien.mapper.UserReservationMapper;
|
|
|
@@ -53,6 +55,8 @@ public class UserReservationServiceImpl extends ServiceImpl<UserReservationMappe
|
|
|
|
|
|
private final ReservationOrderPaymentTimeoutService reservationOrderPaymentTimeoutService;
|
|
|
|
|
|
+ private final UserReservationOrderMapper userReservationOrderMapper;
|
|
|
+
|
|
|
/** 预约状态:待确认 */
|
|
|
private static final int STATUS_PENDING = 0;
|
|
|
/** 预约状态:已取消(不参与约满统计与展示) */
|
|
|
@@ -107,10 +111,22 @@ public class UserReservationServiceImpl extends ServiceImpl<UserReservationMappe
|
|
|
order.setReservationId(reservation.getId());
|
|
|
order.setUserId(reservation.getUserId());
|
|
|
order.setStoreId(reservation.getStoreId());
|
|
|
- order.setOrderStatus(0);
|
|
|
- order.setPaymentStatus(0);
|
|
|
+ // 当store_booking_settings.reservation = 1时,订单状态为待使用(1),不为1时,订单状态为待支付(0)
|
|
|
+ order.setOrderStatus(
|
|
|
+ storeBookingSettingsService.getByStoreId(reservation.getStoreId()) != null && "1".equals(
|
|
|
+ storeBookingSettingsService.getByStoreId(reservation.getStoreId()).getReservation()) ? 0 : 1);
|
|
|
order.setIsMerchantReservation(0);
|
|
|
+ fillOrderFromStoreSettings(order, reservation);
|
|
|
+ return order;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 按门店预订配置填充订单的收费/订金/取消政策等字段(与 add 一致)
|
|
|
+ */
|
|
|
+ private void fillOrderFromStoreSettings(UserReservationOrder order, UserReservation reservation) {
|
|
|
+ if (reservation == null || reservation.getStoreId() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
StoreBookingSettings settings = storeBookingSettingsService.getByStoreId(reservation.getStoreId());
|
|
|
if (settings != null && "1".equals(settings.getReservation()) && settings.getReservationMoney() != null && settings.getReservationMoney() > 0) {
|
|
|
order.setOrderCostType(1);
|
|
|
@@ -128,8 +144,6 @@ public class UserReservationServiceImpl extends ServiceImpl<UserReservationMappe
|
|
|
order.setDepositAmount(BigDecimal.ZERO);
|
|
|
order.setCancellationPolicyType(0);
|
|
|
}
|
|
|
-
|
|
|
- return order;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -137,7 +151,9 @@ public class UserReservationServiceImpl extends ServiceImpl<UserReservationMappe
|
|
|
if (dto.getId() == null) {
|
|
|
throw new RuntimeException("预约ID不能为空");
|
|
|
}
|
|
|
- UserReservation existing = this.getById(dto.getId());
|
|
|
+ // 根据订单id获取预约信息
|
|
|
+ UserReservationOrder userReservationOrder = userReservationOrderMapper.selectById(dto.getId());
|
|
|
+ UserReservation existing = this.getById(userReservationOrder.getReservationId());
|
|
|
if (existing == null) {
|
|
|
throw new RuntimeException("预约不存在");
|
|
|
}
|
|
|
@@ -148,16 +164,45 @@ public class UserReservationServiceImpl extends ServiceImpl<UserReservationMappe
|
|
|
this.updateById(entity);
|
|
|
|
|
|
saveReservationTables(existing.getId(), dto.getTableIds());
|
|
|
+
|
|
|
+ // 与 add 一致:同步 user_reservation_order(无则创建,有则仅待支付时按门店配置刷新)
|
|
|
+ UserReservation updatedReservation = this.getById(existing.getId());
|
|
|
+ LambdaQueryWrapper<UserReservationOrder> orderWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderWrapper.eq(UserReservationOrder::getReservationId, existing.getId()).last("LIMIT 1");
|
|
|
+ UserReservationOrder order = userReservationOrderService.getOne(orderWrapper);
|
|
|
+ if (order == null) {
|
|
|
+ order = buildReservationOrder(updatedReservation);
|
|
|
+ userReservationOrderService.save(order);
|
|
|
+ if (order.getOrderCostType() != null && order.getOrderCostType() == 1 && order.getOrderSn() != null) {
|
|
|
+ reservationOrderPaymentTimeoutService.setReservationOrderPaymentTimeout(order.getOrderSn(), 15 * 60);
|
|
|
+ }
|
|
|
+ } else if (order.getOrderStatus() != null && order.getOrderStatus() == 0) {
|
|
|
+ fillOrderFromStoreSettings(order, updatedReservation);
|
|
|
+ userReservationOrderService.updateById(order);
|
|
|
+ if (order.getOrderCostType() != null && order.getOrderCostType() == 1 && order.getOrderSn() != null) {
|
|
|
+ reservationOrderPaymentTimeoutService.setReservationOrderPaymentTimeout(order.getOrderSn(), 15 * 60);
|
|
|
+ }
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean removeReservation(Integer id) {
|
|
|
- UserReservation one = this.getById(id);
|
|
|
+
|
|
|
+ UserReservationOrder one = userReservationOrderService.getOne(new LambdaUpdateWrapper<UserReservationOrder>()
|
|
|
+ .eq(UserReservationOrder::getId, id));
|
|
|
if (one == null) {
|
|
|
throw new RuntimeException("预约不存在");
|
|
|
}
|
|
|
- userReservationTableMapper.physicalDeleteByReservationId(id);
|
|
|
+ // 假删除:将 delete_flag 置为 1(与 add 对应的三张表)
|
|
|
+ userReservationOrderService.update(
|
|
|
+ new LambdaUpdateWrapper<UserReservationOrder>()
|
|
|
+ .eq(UserReservationOrder::getId, one.getId())
|
|
|
+ .set(UserReservationOrder::getOrderStatus, 4));
|
|
|
+ userReservationTableMapper.update(null,
|
|
|
+ new LambdaUpdateWrapper<UserReservationTable>()
|
|
|
+ .eq(UserReservationTable::getReservationId, one.getReservationId())
|
|
|
+ .set(UserReservationTable::getDeleteFlag, 1));
|
|
|
return this.removeById(id);
|
|
|
}
|
|
|
|