优化预约表单并支持散客预约

This commit is contained in:
2026-10-20 13:29:55 +08:00
parent 4a7bd90088
commit c952a913e8
17 changed files with 1376 additions and 275 deletions
@@ -16,6 +16,8 @@ public class PlanningAppointmentCreateDTO {
private String appointmentTime;
private String appointmentStartTime;
private Integer durationMinutes;
private BigDecimal amount;
private Boolean createCustomerRecord;
private String manualProductTitle;
private BigDecimal manualProductPrice;
private String manualProductDescription;
@@ -44,6 +44,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -183,11 +184,18 @@ public class PlanningServiceImpl implements PlanningService {
ensureWithinBusinessHours(shopId, startTime, endTime);
BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
BigDecimal amount = unitPrice.multiply(BigDecimal.valueOf(quantity));
BigDecimal amount = dto.getAmount() == null
? unitPrice.multiply(BigDecimal.valueOf(quantity))
: dto.getAmount();
if (amount.compareTo(BigDecimal.ZERO) < 0) {
throw new RuntimeException("成交金额不能小于0");
}
OrderDO order = new OrderDO();
order.setOrderNo("ORD" + snowflakeIdGenerator.nextIdString());
order.setUserId(customer.getId());
order.setUserId(customer == null ? null : customer.getId());
order.setCustomerNameSnapshot(customer == null ? trimToNull(dto.getCustomerName()) : null);
order.setCustomerPhoneSnapshot(customer == null ? trimToNull(dto.getPhone()) : null);
order.setShopId(shopId);
order.setTotalAmount(amount);
order.setActualAmount(amount);
@@ -208,7 +216,7 @@ public class PlanningServiceImpl implements PlanningService {
item.setOrderId(order.getId());
item.setProductId(product.getId());
item.setQuantity(quantity);
item.setPrice(unitPrice);
item.setPrice(amount.divide(BigDecimal.valueOf(quantity), 2, RoundingMode.HALF_UP));
item.setArtistId(artist == null ? null : artist.getId());
item.setAppointmentTime(startTime);
item.setIsDelete(0);
@@ -295,7 +303,8 @@ public class PlanningServiceImpl implements PlanningService {
Map<Long, PlanningArtistVO> artistMap = listArtists(order.getShopId(), item.getArtistId()).stream()
.collect(Collectors.toMap(PlanningArtistVO::getId, Function.identity(), (a, b) -> a));
Map<Long, UserDO> customerMap = order.getUserId() == null ? Map.of() : loadUsers(Set.of(order.getUserId()));
return toAppointmentVO(reservation, item, order, product, customerMap.get(order.getUserId()), artistMap);
UserDO customer = order.getUserId() == null ? null : customerMap.get(order.getUserId());
return toAppointmentVO(reservation, item, order, product, customer, artistMap);
}
@Override
@@ -516,7 +525,7 @@ public class PlanningServiceImpl implements PlanningService {
continue;
}
ProductDO product = item == null ? null : productMap.get(item.getProductId());
UserDO customer = customerMap.get(order.getUserId());
UserDO customer = order.getUserId() == null ? null : customerMap.get(order.getUserId());
result.add(toAppointmentVO(reservation, item, order, product, customer, artistMap));
if (reservation.getOrderItemId() != null) {
reservationItemIds.add(reservation.getOrderItemId());
@@ -531,7 +540,7 @@ public class PlanningServiceImpl implements PlanningService {
continue;
}
ProductDO product = productMap.get(item.getProductId());
UserDO customer = customerMap.get(order.getUserId());
UserDO customer = order.getUserId() == null ? null : customerMap.get(order.getUserId());
result.add(toAppointmentVO(null, item, order, product, customer, artistMap));
}
result.sort(Comparator.comparing(PlanningAppointmentVO::getStartTime, Comparator.nullsLast(String::compareTo))
@@ -731,12 +740,19 @@ public class PlanningServiceImpl implements PlanningService {
private ProductDO createManualAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) {
String title = trimToNull(dto.getManualProductTitle());
String imageFileIds = trimToNull(dto.getManualProductImageFileIds());
if (!hasText(title)) {
throw new RuntimeException("请选择预约作品或填写手动作品名称");
title = firstNonBlank(dto.getCustomerName(), hasText(imageFileIds) ? "散客款式" : null);
}
BigDecimal price = dto.getManualProductPrice();
if (price == null || price.compareTo(BigDecimal.ZERO) < 0) {
throw new RuntimeException("手动作品价格不能小于0");
if (!hasText(title) && !hasText(imageFileIds)) {
throw new RuntimeException("请填写美甲款式名称或上传款式图片");
}
BigDecimal price = dto.getManualProductPrice() == null ? dto.getAmount() : dto.getManualProductPrice();
if (price == null) {
throw new RuntimeException("成交金额不能为空");
}
if (price.compareTo(BigDecimal.ZERO) < 0) {
throw new RuntimeException("成交金额不能小于0");
}
int durationMinutes = requireAppointmentDuration(dto.getDurationMinutes());
ProductDO product = new ProductDO();
@@ -746,7 +762,7 @@ public class PlanningServiceImpl implements PlanningService {
product.setTags(trimToNull(dto.getManualProductTags()));
product.setTargetAudience(trimToNull(dto.getManualProductTargetAudience()));
product.setPrecautions(trimToNull(dto.getManualProductPrecautions()));
product.setImageFileIds(trimToNull(dto.getManualProductImageFileIds()));
product.setImageFileIds(imageFileIds);
product.setPrice(price);
product.setLikeCount(0);
product.setCollectCount(0);
@@ -786,11 +802,17 @@ public class PlanningServiceImpl implements PlanningService {
}
return customer;
}
String customerName = firstNonBlank(dto.getCustomerName(), dto.getPhone());
if (!hasText(customerName)) {
throw new RuntimeException("客户姓名不能为空");
}
String customerName = trimToNull(dto.getCustomerName());
String phone = trimToNull(dto.getPhone());
if (!hasText(customerName) && hasText(phone)) {
throw new RuntimeException("填写手机号时请同时填写客户姓名");
}
if (Boolean.FALSE.equals(dto.getCreateCustomerRecord())) {
return null;
}
if (!hasText(customerName)) {
return null;
}
List<com.xiaowang.jayucloud.salon.core.modules.user.vo.UserVO> matches =
userService.findCustomerMatches(customerName, phone, shopId);
if (matches.size() > 1) {