优化店务小程序预约作品价格交互
This commit is contained in:
+11
-1
@@ -168,7 +168,7 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
LocalDateTime endTime = startTime.plusMinutes(durationMinutes);
|
||||
ensureWithinBusinessHours(shopId, startTime, endTime);
|
||||
|
||||
BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
|
||||
BigDecimal unitPrice = resolveAppointmentUnitPrice(product, dto);
|
||||
BigDecimal amount = unitPrice.multiply(BigDecimal.valueOf(quantity));
|
||||
|
||||
OrderDO order = new OrderDO();
|
||||
@@ -890,6 +890,16 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return product;
|
||||
}
|
||||
|
||||
private BigDecimal resolveAppointmentUnitPrice(ProductDO product, PlanningAppointmentCreateDTO dto) {
|
||||
if (dto.getManualProductPrice() == null) {
|
||||
return product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
|
||||
}
|
||||
if (dto.getManualProductPrice().compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("本次价格不能小于0");
|
||||
}
|
||||
return dto.getManualProductPrice();
|
||||
}
|
||||
|
||||
private int requireAppointmentDuration(Integer durationMinutes) {
|
||||
if (durationMinutes == null || durationMinutes <= 0) {
|
||||
throw new RuntimeException("预约时长不能为空且必须大于0分钟");
|
||||
|
||||
+59
@@ -288,6 +288,65 @@ class PlanningServiceImplTest {
|
||||
assertThat(appointment.getFromMeituan()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAppointmentShouldUseAppointmentPriceWithoutChangingProductPrice() {
|
||||
UserDO manager = user(2, 8L);
|
||||
UserDO artist = user(3, 8L);
|
||||
artist.setId(20L);
|
||||
UserDO customer = user(0, 8L);
|
||||
customer.setId(30L);
|
||||
ShopDO shop = new ShopDO();
|
||||
shop.setBusinessHours("10:00-22:00");
|
||||
ProductDO product = product(100L, 8L, "90分钟");
|
||||
product.setPrice(new BigDecimal("168.00"));
|
||||
PlanningAppointmentCreateDTO dto = new PlanningAppointmentCreateDTO();
|
||||
dto.setCustomerUserId(30L);
|
||||
dto.setProductId(100L);
|
||||
dto.setArtistId(20L);
|
||||
dto.setAppointmentDate("2026-07-21");
|
||||
dto.setAppointmentTime("14:00");
|
||||
dto.setDurationMinutes(90);
|
||||
dto.setManualProductPrice(new BigDecimal("188.00"));
|
||||
|
||||
OrderDO[] storedOrder = new OrderDO[1];
|
||||
OrderItemDO[] storedItem = new OrderItemDO[1];
|
||||
when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L);
|
||||
when(productMapper.selectById(100L)).thenReturn(product);
|
||||
when(userMapper.selectById(20L)).thenReturn(artist);
|
||||
when(userMapper.selectById(30L)).thenReturn(customer);
|
||||
when(shopMapper.selectById(8L)).thenReturn(shop);
|
||||
when(snowflakeIdGenerator.nextIdString()).thenReturn("202607210001");
|
||||
when(orderMapper.insert(any(OrderDO.class))).thenAnswer(invocation -> {
|
||||
OrderDO order = invocation.getArgument(0);
|
||||
order.setId(200L);
|
||||
storedOrder[0] = order;
|
||||
return 1;
|
||||
});
|
||||
when(orderItemMapper.insert(any(OrderItemDO.class))).thenAnswer(invocation -> {
|
||||
OrderItemDO item = invocation.getArgument(0);
|
||||
item.setId(300L);
|
||||
storedItem[0] = item;
|
||||
return 1;
|
||||
});
|
||||
when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> storedItem[0]);
|
||||
when(orderMapper.selectById(200L)).thenAnswer(invocation -> storedOrder[0]);
|
||||
AppointmentReservationDO reservation = reservation(20L, 200L, 300L,
|
||||
LocalDateTime.of(2026, 7, 21, 14, 0),
|
||||
LocalDateTime.of(2026, 7, 21, 15, 30));
|
||||
when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation);
|
||||
when(userMapper.selectBatchIds(any())).thenReturn(List.of(customer));
|
||||
|
||||
var appointment = planningService.createAppointment(manager, dto);
|
||||
|
||||
assertThat(storedOrder[0].getTotalAmount()).isEqualByComparingTo("188.00");
|
||||
assertThat(storedOrder[0].getActualAmount()).isEqualByComparingTo("188.00");
|
||||
assertThat(storedOrder[0].getPayAmount()).isEqualByComparingTo("188.00");
|
||||
assertThat(storedItem[0].getPrice()).isEqualByComparingTo("188.00");
|
||||
assertThat(product.getPrice()).isEqualByComparingTo("168.00");
|
||||
assertThat(appointment.getAmount()).isEqualByComparingTo("188.00");
|
||||
org.mockito.Mockito.verify(productMapper, org.mockito.Mockito.never()).insert(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAppointmentRejectsStoreRestDay() {
|
||||
UserDO manager = user(2, 8L);
|
||||
|
||||
Reference in New Issue
Block a user