回溯点:保存注册预约客户流程修复进度

This commit is contained in:
2026-10-30 13:02:38 +08:00
parent 7b40ee1650
commit 53b6fcaa11
45 changed files with 960 additions and 132 deletions
@@ -27,8 +27,12 @@ import com.xiaowang.jayucloud.salon.core.modules.product.service.ProductService;
import com.xiaowang.jayucloud.salon.core.modules.product.vo.ProductVO;
import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper;
import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopDTO;
import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopAppointmentSettingsDTO;
import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopNameUpdateDTO;
import com.xiaowang.jayucloud.salon.core.modules.shop.service.ShopService;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopVO;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopAppointmentSettingsVO;
import com.xiaowang.jayucloud.salon.core.modules.manager.vo.AppointmentCustomerOptionVO;
import com.xiaowang.jayucloud.salon.core.modules.user.dto.UserDTO;
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
import com.xiaowang.jayucloud.salon.core.modules.user.service.UserService;
@@ -151,6 +155,30 @@ public class AdminManagerController {
return Result.success(userService.findCustomerMatches(nickname, phone, shopId));
}
@GetMapping("/customers/identity-matches")
@RequirePermission("user:view")
public Result<List<AppointmentCustomerOptionVO>> customerIdentityMatches(HttpServletRequest request,
@RequestParam String nickname,
@RequestParam(required = false) String wechatId,
@RequestParam(required = false) String phone) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requireShopContext(currentUser);
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
return Result.success(userService.findCustomerIdentityMatches(nickname, wechatId, phone, shopId));
}
@GetMapping("/customers/appointment-options")
@RequirePermission("user:view")
public Result<PageResultVO<AppointmentCustomerOptionVO>> appointmentCustomerOptions(HttpServletRequest request,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "30") Integer size,
@RequestParam(required = false) String keyword) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
adminScopeHelper.requireShopContext(currentUser);
return Result.success(userService.listCustomersForAppointment(page, size, keyword, shopId));
}
@GetMapping("/customers/{id}")
@RequirePermission("user:view")
public Result<UserVO> customer(HttpServletRequest request, @PathVariable Long id) {
@@ -327,4 +355,33 @@ public class AdminManagerController {
}
return Result.success(shopService.updateShop(shopId, dto));
}
@GetMapping("/shop/appointment-settings")
@RequirePermission("shop:view")
public Result<ShopAppointmentSettingsVO> appointmentSettings(HttpServletRequest request) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requireShopContext(currentUser);
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
return Result.success(shopService.getAppointmentSettings(shopId));
}
@PutMapping("/shop/appointment-settings")
@RequirePermission("shop:edit")
@OperationGuard(action = "manager-shop-appointment-settings-update", ttlSeconds = 10, message = "预约设置正在保存,请勿重复提交")
public Result<Boolean> updateAppointmentSettings(HttpServletRequest request, @RequestBody ShopAppointmentSettingsDTO dto) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requireShopContext(currentUser);
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
return Result.success(shopService.updateAppointmentSettings(shopId, dto));
}
@PutMapping("/shop/name")
@RequirePermission("shop:edit")
@OperationGuard(action = "manager-shop-name-review", ttlSeconds = 10, message = "门店名称正在提交审核,请勿重复操作")
public Result<Boolean> updateShopName(HttpServletRequest request, @RequestBody ShopNameUpdateDTO dto) {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
adminScopeHelper.requireShopContext(currentUser);
Long shopId = adminScopeHelper.resolveShopScope(currentUser, null);
return Result.success(shopService.updateShopName(shopId, dto));
}
}
@@ -0,0 +1,17 @@
package com.xiaowang.jayucloud.salon.core.modules.manager.vo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class AppointmentCustomerOptionVO {
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
private String name;
private String phone;
private String avatar;
private LocalDateTime createdAt;
}
@@ -8,6 +8,7 @@ import java.math.BigDecimal;
public class PlanningAppointmentCreateDTO {
private Long customerUserId;
private String customerName;
private String wechatId;
private String phone;
private Long productId;
private Integer quantity;
@@ -111,7 +111,8 @@ public class PlanningServiceImpl implements PlanningService {
Long shopId = requirePlanningShopId(currentUser);
ShopDO shop = shopMapper.selectById(shopId);
PlanningCalendarSupport.BusinessHours businessHours = PlanningCalendarSupport.parseBusinessHours(
shop == null ? null : shop.getBusinessHours()
shop == null ? null : (StringUtils.hasText(shop.getAppointmentBusinessHours())
? shop.getAppointmentBusinessHours() : shop.getBusinessHours())
);
List<PlanningArtistVO> artists = listArtists(shopId, artistId);
@@ -136,6 +137,8 @@ public class PlanningServiceImpl implements PlanningService {
PlanningCalendarVO vo = new PlanningCalendarVO();
vo.setBusinessStartTime(businessHours.start().toString());
vo.setBusinessEndTime(businessHours.end().toString());
vo.setDefaultAppointmentDurationMinutes(shop == null || shop.getDefaultAppointmentDurationMinutes() == null
|| shop.getDefaultAppointmentDurationMinutes() <= 0 ? DEFAULT_DURATION_MINUTES : shop.getDefaultAppointmentDurationMinutes());
vo.setSlotMinutes(DEFAULT_SLOT_MINUTES);
vo.setArtists(artists);
vo.setSchedules(scheduleVos);
@@ -176,16 +179,23 @@ public class PlanningServiceImpl implements PlanningService {
}
Long shopId = requirePlanningShopId(currentUser);
shopBusinessExpiryService.assertShopActive(shopId);
requireAppointmentDuration(dto.getDurationMinutes());
ProductDO product = resolveAppointmentProduct(dto, shopId);
UserDO artist = dto.getArtistId() == null ? null : requireActiveArtist(dto.getArtistId(), shopId);
UserDO customer = resolveCustomer(shopId, dto);
ShopDO shop = shopMapper.selectById(shopId);
int shopDefaultDuration = resolveShopDefaultDuration(shop);
int quantity = dto.getQuantity() == null || dto.getQuantity() <= 0 ? 1 : dto.getQuantity();
int durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes()) * quantity;
ProductDO product = dto.getProductId() == null ? null : requireActiveProduct(dto.getProductId(), shopId);
int durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes(), shopDefaultDuration) * quantity;
LocalDateTime startTime = parseAppointmentStart(dto.getAppointmentStartTime(), dto.getAppointmentDate(), dto.getAppointmentTime());
LocalDateTime endTime = startTime.plusMinutes(durationMinutes);
ensureFutureAppointmentTime(startTime);
ensureWithinBusinessHours(shopId, startTime, endTime);
if (product == null) {
product = createManualAppointmentProduct(dto, shopId, shopDefaultDuration);
durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes(), shopDefaultDuration) * quantity;
endTime = startTime.plusMinutes(durationMinutes);
ensureWithinBusinessHours(shopId, startTime, endTime);
}
UserDO artist = dto.getArtistId() == null ? null : requireActiveArtist(dto.getArtistId(), shopId);
UserDO customer = resolveCustomer(currentUser, shopId, dto);
BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
BigDecimal amount = dto.getAmount() == null
@@ -325,7 +335,8 @@ public class PlanningServiceImpl implements PlanningService {
ProductDO product = requireActiveProduct(item.getProductId(), order.getShopId());
Long targetArtistId = dto.getArtistId() == null ? item.getArtistId() : dto.getArtistId();
UserDO artist = requireActiveArtist(targetArtistId, order.getShopId());
int durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes()) *
ShopDO shop = shopMapper.selectById(order.getShopId());
int durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes(), resolveShopDefaultDuration(shop)) *
Math.max(1, item.getQuantity() == null ? 1 : item.getQuantity());
LocalDateTime startTime = hasText(dto.getAppointmentStartTime()) || hasText(dto.getAppointmentDate()) || hasText(dto.getAppointmentTime())
? parseAppointmentStart(dto.getAppointmentStartTime(), dto.getAppointmentDate(), dto.getAppointmentTime())
@@ -334,6 +345,7 @@ public class PlanningServiceImpl implements PlanningService {
throw new RuntimeException("预约时间不能为空");
}
LocalDateTime endTime = startTime.plusMinutes(durationMinutes);
ensureFutureAppointmentTime(startTime);
ensureWithinBusinessHours(order.getShopId(), startTime, endTime);
appointmentCapacityService.moveReservationForArtistChange(
@@ -559,7 +571,8 @@ public class PlanningServiceImpl implements PlanningService {
if (start == null && item != null) {
start = item.getAppointmentTime();
}
int durationMinutes = resolveDurationMinutes(product, null) * Math.max(1, item == null || item.getQuantity() == null ? 1 : item.getQuantity());
ShopDO shop = order == null || order.getShopId() == null ? null : shopMapper.selectById(order.getShopId());
int durationMinutes = resolveDurationMinutes(product, null, resolveShopDefaultDuration(shop)) * Math.max(1, item == null || item.getQuantity() == null ? 1 : item.getQuantity());
LocalDateTime end = reservation == null ? null : reservation.getAppointmentEndTime();
if (end == null && start != null) {
end = start.plusMinutes(durationMinutes);
@@ -736,14 +749,14 @@ public class PlanningServiceImpl implements PlanningService {
return product;
}
private ProductDO resolveAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) {
private ProductDO resolveAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId, int defaultDurationMinutes) {
if (dto.getProductId() != null) {
return requireActiveProduct(dto.getProductId(), shopId);
}
return createManualAppointmentProduct(dto, shopId);
return createManualAppointmentProduct(dto, shopId, defaultDurationMinutes);
}
private ProductDO createManualAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) {
private ProductDO createManualAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId, int defaultDurationMinutes) {
String title = trimToNull(dto.getManualProductTitle());
String imageFileIds = trimToNull(dto.getManualProductImageFileIds());
if (!hasText(title)) {
@@ -759,7 +772,8 @@ public class PlanningServiceImpl implements PlanningService {
if (price.compareTo(BigDecimal.ZERO) < 0) {
throw new RuntimeException("成交金额不能小于0");
}
int durationMinutes = requireAppointmentDuration(dto.getDurationMinutes());
int durationMinutes = dto.getDurationMinutes() == null || dto.getDurationMinutes() <= 0
? defaultDurationMinutes : dto.getDurationMinutes();
ProductDO product = new ProductDO();
product.setShopId(shopId);
product.setTitle(title);
@@ -780,13 +794,6 @@ public class PlanningServiceImpl implements PlanningService {
return product;
}
private int requireAppointmentDuration(Integer durationMinutes) {
if (durationMinutes == null || durationMinutes <= 0) {
throw new RuntimeException("预约时长不能为空且必须大于0分钟");
}
return durationMinutes;
}
private UserDO requireActiveArtist(Long artistId, Long shopId) {
if (artistId == null) {
throw new RuntimeException("请选择美甲师");
@@ -799,8 +806,9 @@ public class PlanningServiceImpl implements PlanningService {
return artist;
}
private UserDO resolveCustomer(Long shopId, PlanningAppointmentCreateDTO dto) {
private UserDO resolveCustomer(UserDO currentUser, Long shopId, PlanningAppointmentCreateDTO dto) {
if (dto.getCustomerUserId() != null) {
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, dto.getCustomerUserId(), "客户不属于当前店铺");
UserDO customer = userMapper.selectById(dto.getCustomerUserId());
if (customer == null || Integer.valueOf(1).equals(customer.getIsDelete()) || !Integer.valueOf(0).equals(customer.getType())) {
throw new RuntimeException("客户不存在");
@@ -808,6 +816,7 @@ public class PlanningServiceImpl implements PlanningService {
return customer;
}
String customerName = trimToNull(dto.getCustomerName());
String wechatId = trimToNull(dto.getWechatId());
String phone = trimToNull(dto.getPhone());
if (!hasText(customerName) && hasText(phone)) {
throw new RuntimeException("填写手机号时请同时填写客户姓名");
@@ -818,15 +827,15 @@ public class PlanningServiceImpl implements PlanningService {
if (!hasText(customerName)) {
return null;
}
List<com.xiaowang.jayucloud.salon.core.modules.user.vo.UserVO> matches =
userService.findCustomerMatches(customerName, phone, shopId);
List<com.xiaowang.jayucloud.salon.core.modules.manager.vo.AppointmentCustomerOptionVO> matches =
userService.findCustomerIdentityMatches(customerName, dto.getWechatId(), phone, shopId);
if (matches.size() > 1) {
throw new RuntimeException("存在多个匹配客户,请先选择已有客户");
}
if (!matches.isEmpty()) {
return userMapper.selectById(matches.get(0).getId());
}
Long customerId = userService.createManagerCustomer(customerName, phone, shopId);
Long customerId = userService.createManagerCustomer(customerName, wechatId, phone, shopId);
return userMapper.selectById(customerId);
}
@@ -851,7 +860,9 @@ public class PlanningServiceImpl implements PlanningService {
private void ensureWithinBusinessHours(Long shopId, LocalDateTime startTime, LocalDateTime endTime) {
ShopDO shop = shopMapper.selectById(shopId);
PlanningCalendarSupport.BusinessHours hours = PlanningCalendarSupport.parseBusinessHours(shop == null ? null : shop.getBusinessHours());
String configuredHours = shop == null ? null : (StringUtils.hasText(shop.getAppointmentBusinessHours())
? shop.getAppointmentBusinessHours() : shop.getBusinessHours());
PlanningCalendarSupport.BusinessHours hours = PlanningCalendarSupport.parseBusinessHours(configuredHours);
LocalTime start = startTime.toLocalTime();
LocalTime end = endTime.toLocalTime();
if (start.isBefore(hours.start()) || end.isAfter(hours.end()) || !startTime.toLocalDate().equals(endTime.toLocalDate())) {
@@ -859,6 +870,21 @@ public class PlanningServiceImpl implements PlanningService {
}
}
private void ensureFutureAppointmentTime(LocalDateTime startTime) {
LocalDate today = LocalDate.now();
if (startTime.toLocalDate().isBefore(today)) {
throw new RuntimeException("历史日期请使用历史补单");
}
if (!startTime.isAfter(LocalDateTime.now())) {
throw new RuntimeException("预约时间已过,请使用历史补单");
}
}
private int resolveShopDefaultDuration(ShopDO shop) {
return shop == null || shop.getDefaultAppointmentDurationMinutes() == null || shop.getDefaultAppointmentDurationMinutes() <= 0
? DEFAULT_DURATION_MINUTES : shop.getDefaultAppointmentDurationMinutes();
}
private LocalDateTime parseAppointmentStart(String appointmentStartTime, String appointmentDate, String appointmentTime) {
if (hasText(appointmentStartTime)) {
String normalized = appointmentStartTime.trim().replace('T', ' ');
@@ -880,10 +906,14 @@ public class PlanningServiceImpl implements PlanningService {
}
private int resolveDurationMinutes(ProductDO product, Integer overrideMinutes) {
return resolveDurationMinutes(product, overrideMinutes, DEFAULT_DURATION_MINUTES);
}
private int resolveDurationMinutes(ProductDO product, Integer overrideMinutes, int defaultMinutes) {
if (overrideMinutes != null && overrideMinutes > 0) {
return overrideMinutes;
}
return PlanningCalendarSupport.parseDurationMinutes(product == null ? null : product.getApproximateDuration(), DEFAULT_DURATION_MINUTES);
return PlanningCalendarSupport.parseDurationMinutes(product == null ? null : product.getApproximateDuration(), defaultMinutes);
}
private boolean isVisibleOrder(OrderDO order, Long shopId) {
@@ -8,6 +8,7 @@ import java.util.List;
public class PlanningCalendarVO {
private String businessStartTime;
private String businessEndTime;
private Integer defaultAppointmentDurationMinutes;
private Integer slotMinutes;
private List<PlanningArtistVO> artists;
private List<PlanningScheduleVO> schedules;
@@ -486,7 +486,11 @@ public class WorkbenchRegistrationServiceImpl implements WorkbenchRegistrationSe
}
private WorkbenchRegistrationStatusVO toStatus(WorkbenchRegistrationApplicationDO application) {
return new WorkbenchRegistrationStatusVO(application.getId(), application.getApplicationNo(), application.getRoleType(), application.getStatus(), application.getRejectReason(), application.getShopId(), application.getShopName());
ContentModerationRecordDO moderation = application.getContentModerationRecordId() == null
? null : contentModerationRecordMapper.selectById(application.getContentModerationRecordId());
return new WorkbenchRegistrationStatusVO(application.getId(), application.getApplicationNo(), application.getRoleType(),
application.getStatus(), application.getRejectReason(), application.getShopId(), application.getShopName(),
moderation == null ? null : moderation.getStatus(), moderation == null ? null : moderation.getReason());
}
private WorkbenchRegistrationReviewVO toReviewVO(WorkbenchRegistrationApplicationDO application, UserDO applicant,
@@ -13,4 +13,6 @@ public class WorkbenchRegistrationStatusVO {
private String rejectReason;
private Long shopId;
private String shopName;
private String contentModerationStatus;
private String contentModerationReason;
}
@@ -0,0 +1,9 @@
package com.xiaowang.jayucloud.salon.core.modules.shop.dto;
import lombok.Data;
@Data
public class ShopAppointmentSettingsDTO {
private String businessHours;
private Integer defaultAppointmentDurationMinutes;
}
@@ -0,0 +1,8 @@
package com.xiaowang.jayucloud.salon.core.modules.shop.dto;
import lombok.Data;
@Data
public class ShopNameUpdateDTO {
private String shopName;
}
@@ -76,6 +76,12 @@ public class ShopDO extends BaseEntity {
@TableField("business_hours")
private String businessHours;
@TableField("appointment_business_hours")
private String appointmentBusinessHours;
@TableField("default_appointment_duration_minutes")
private Integer defaultAppointmentDurationMinutes;
/**
* 店铺封面图文件ID集合(Banner图),多个ID以逗号分隔
*/
@@ -6,6 +6,9 @@ import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopDTO;
import com.xiaowang.jayucloud.salon.core.common.vo.PageResultVO;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopTrustProfileVO;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopVO;
import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopAppointmentSettingsDTO;
import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopNameUpdateDTO;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopAppointmentSettingsVO;
import java.util.List;
@@ -51,6 +54,12 @@ public interface ShopService extends IService<ShopDO> {
*/
ShopVO getShopById(Long id);
ShopAppointmentSettingsVO getAppointmentSettings(Long id);
boolean updateAppointmentSettings(Long id, ShopAppointmentSettingsDTO settings);
boolean updateShopName(Long id, ShopNameUpdateDTO request);
/** Public shop detail with the approved-content visibility gate applied. */
ShopVO getPublicShopById(Long id);
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.type.TypeReference;
import com.xiaowang.jayucloud.salon.core.config.AppCacheProperties;
import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopDTO;
import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopAppointmentSettingsDTO;
import com.xiaowang.jayucloud.salon.core.modules.shop.dto.ShopNameUpdateDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderArtistReviewDO;
import com.xiaowang.jayucloud.salon.core.modules.product.entity.ProductDO;
import com.xiaowang.jayucloud.salon.core.modules.shop.entity.ShopDO;
@@ -34,6 +36,9 @@ import com.xiaowang.jayucloud.salon.core.modules.file.vo.ObjectStorageFileVO;
import com.xiaowang.jayucloud.salon.core.common.vo.PageResultVO;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopTrustProfileVO;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopVO;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopAppointmentSettingsVO;
import com.xiaowang.jayucloud.salon.core.modules.privacy.entity.ContentModerationRecordDO;
import com.xiaowang.jayucloud.salon.core.modules.privacy.mapper.ContentModerationRecordMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -44,6 +49,8 @@ import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
@@ -88,6 +95,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
* Variable `shopMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
*/
private final ShopMapper shopMapper;
private final ContentModerationRecordMapper contentModerationRecordMapper;
private final ShopBusinessExpiryService shopBusinessExpiryService;
/**
* Variable `couponService`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
@@ -208,6 +216,97 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
return updated;
}
@Override
public ShopAppointmentSettingsVO getAppointmentSettings(Long id) {
ShopDO shop = shopMapper.selectById(id);
if (shop == null || Integer.valueOf(1).equals(shop.getIsDelete())) {
throw new IllegalArgumentException("门店不存在");
}
ShopAppointmentSettingsVO result = new ShopAppointmentSettingsVO();
result.setShopName(shop.getShopName());
ContentModerationRecordDO latestReview = contentModerationRecordMapper.selectOne(Wrappers.lambdaQuery(ContentModerationRecordDO.class)
.eq(ContentModerationRecordDO::getContentType, "SHOP")
.eq(ContentModerationRecordDO::getBusinessId, id)
.eq(ContentModerationRecordDO::getIsDelete, 0)
.orderByDesc(ContentModerationRecordDO::getVersionNo)
.last("limit 1"));
result.setShopNameModerationStatus(latestReview == null ? shop.getModerationStatus() : latestReview.getStatus());
if (latestReview != null && StringUtils.hasText(latestReview.getPayloadJson())) {
try {
result.setPendingShopName(objectMapper.readTree(latestReview.getPayloadJson()).path("shopName").asText(null));
} catch (Exception ignored) {
result.setPendingShopName(null);
}
}
result.setBusinessHours(StringUtils.hasText(shop.getAppointmentBusinessHours())
? shop.getAppointmentBusinessHours() : shop.getBusinessHours());
result.setDefaultAppointmentDurationMinutes(shop.getDefaultAppointmentDurationMinutes() == null
|| shop.getDefaultAppointmentDurationMinutes() <= 0 ? 60 : shop.getDefaultAppointmentDurationMinutes());
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateAppointmentSettings(Long id, ShopAppointmentSettingsDTO settings) {
if (settings == null) throw new IllegalArgumentException("预约设置不能为空");
ShopDO shop = shopMapper.selectById(id);
if (shop == null || Integer.valueOf(1).equals(shop.getIsDelete())) {
throw new IllegalArgumentException("门店不存在");
}
String businessHours = normalizeAppointmentBusinessHours(settings.getBusinessHours());
Integer duration = settings.getDefaultAppointmentDurationMinutes();
if (duration == null || duration < 15 || duration > 720) {
throw new IllegalArgumentException("默认预约时长需在15至720分钟之间");
}
shop.setAppointmentBusinessHours(businessHours);
shop.setDefaultAppointmentDurationMinutes(duration);
return shopMapper.updateById(shop) > 0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateShopName(Long id, ShopNameUpdateDTO request) {
if (request == null || !StringUtils.hasText(request.getShopName())) {
throw new IllegalArgumentException("门店名称不能为空");
}
ShopDO shop = shopMapper.selectById(id);
if (shop == null || Integer.valueOf(1).equals(shop.getIsDelete())) {
throw new IllegalArgumentException("门店不存在");
}
ShopDTO profile = new ShopDTO();
profile.setShopName(request.getShopName().trim());
profile.setDescription(shop.getDescription());
profile.setAddress(shop.getAddress());
profile.setMapProvider(shop.getMapProvider());
profile.setLongitude(shop.getLongitude());
profile.setLatitude(shop.getLatitude());
profile.setBusinessHours(shop.getBusinessHours());
profile.setCoverImageFileId(shop.getCoverImageFileId());
profile.setImageFileIds(shop.getImageFileIds());
profile.setThemePrimaryColor(shop.getThemePrimaryColor());
profile.setThemeSecondaryColor(shop.getThemeSecondaryColor());
profile.setThemeAccentColor(shop.getThemeAccentColor());
profile.setThemePageBgColor(shop.getThemePageBgColor());
profile.setThemeCardBgColor(shop.getThemeCardBgColor());
profile.setThemeBackgroundImageFileId(shop.getThemeBackgroundImageFileId());
submitShopSnapshot(shop, profile);
return true;
}
private String normalizeAppointmentBusinessHours(String value) {
if (!StringUtils.hasText(value)) throw new IllegalArgumentException("请设置门店营业时间");
String[] parts = value.trim().split("-");
if (parts.length != 2) throw new IllegalArgumentException("营业时间格式不正确");
try {
LocalTime start = LocalTime.parse(parts[0].trim());
LocalTime end = LocalTime.parse(parts[1].trim());
if (!start.isBefore(end)) throw new IllegalArgumentException("营业结束时间必须晚于开始时间");
return start + "-" + end;
} catch (DateTimeParseException exception) {
throw new IllegalArgumentException("营业时间格式不正确,请使用小时和分钟");
}
}
private boolean updateShopOperationalFields(ShopDO current, ShopDTO dto) {
boolean changed = false;
if (dto.getStatus() != null) {
@@ -226,6 +325,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
target.setId(source.getId()); target.setShopName(source.getShopName()); target.setDescription(source.getDescription());
target.setAddress(source.getAddress()); target.setMapProvider(source.getMapProvider()); target.setLongitude(source.getLongitude());
target.setLatitude(source.getLatitude()); target.setBusinessHours(source.getBusinessHours()); target.setCoverImageFileId(source.getCoverImageFileId());
target.setAppointmentBusinessHours(source.getAppointmentBusinessHours()); target.setDefaultAppointmentDurationMinutes(source.getDefaultAppointmentDurationMinutes());
target.setImageFileIds(source.getImageFileIds()); target.setThemePrimaryColor(source.getThemePrimaryColor());
target.setThemeSecondaryColor(source.getThemeSecondaryColor()); target.setThemeAccentColor(source.getThemeAccentColor());
target.setThemePageBgColor(source.getThemePageBgColor()); target.setThemeCardBgColor(source.getThemeCardBgColor());
@@ -903,6 +1003,7 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
shopVO.setLatitude(shopDO.getLatitude());
shopVO.setNavigationUrls(mapService.buildNavigationUrls(shopDO.getShopName(), shopDO.getAddress(), shopDO.getLongitude(), shopDO.getLatitude()));
shopVO.setBusinessHours(shopDO.getBusinessHours());
shopVO.setModerationStatus(shopDO.getModerationStatus());
shopVO.setCoverImageFileId(shopDO.getCoverImageFileId());
shopVO.setCoverImageUrls(new java.util.ArrayList<>());
shopVO.setImageFileIds(shopDO.getImageFileIds());
@@ -0,0 +1,12 @@
package com.xiaowang.jayucloud.salon.core.modules.shop.vo;
import lombok.Data;
@Data
public class ShopAppointmentSettingsVO {
private String shopName;
private String shopNameModerationStatus;
private String pendingShopName;
private String businessHours;
private Integer defaultAppointmentDurationMinutes;
}
@@ -70,6 +70,8 @@ public class ShopVO {
*/
private String businessHours;
private String moderationStatus;
/**
* 店铺封面图文件ID集合(Banner图),多个ID以逗号分隔
*/
@@ -17,6 +17,7 @@ import com.xiaowang.jayucloud.salon.core.common.vo.PageResultVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserStatisticsVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserRelationVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserVO;
import com.xiaowang.jayucloud.salon.core.modules.manager.vo.AppointmentCustomerOptionVO;
import java.util.List;
@@ -42,6 +43,10 @@ public interface UserService extends IService<UserDO> {
List<UserVO> findCustomerMatches(String nickname, String phone, Long shopId);
List<AppointmentCustomerOptionVO> findCustomerIdentityMatches(String nickname, String wechatId, String phone, Long shopId);
PageResultVO<AppointmentCustomerOptionVO> listCustomersForAppointment(Integer page, Integer size, String keyword, Long shopId);
/**
* Update an existing record.
@@ -57,6 +57,7 @@ import com.xiaowang.jayucloud.salon.core.modules.auth.vo.LoginResponseVO;
import com.xiaowang.jayucloud.salon.core.common.vo.PageResultVO;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopSimpleVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserVO;
import com.xiaowang.jayucloud.salon.core.modules.manager.vo.AppointmentCustomerOptionVO;
import com.xiaowang.jayucloud.salon.core.modules.shop.vo.ShopVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserRelationVO;
import com.xiaowang.jayucloud.salon.core.modules.user.vo.UserStatisticsVO;
@@ -606,6 +607,75 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
}).collect(Collectors.toList());
}
@Override
public List<AppointmentCustomerOptionVO> findCustomerIdentityMatches(String nickname, String wechatId, String phone, Long shopId) {
if (!StringUtils.hasText(nickname)) return List.of();
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class)
.eq(UserDO::getNickname, nickname.trim())
.eq(UserDO::getType, 0)
.eq(UserDO::getIsDelete, 0);
applyCustomerShopScope(wrapper, shopId);
String normalizedName = nickname.trim();
String normalizedWechatId = UserProfileFieldSupport.normalizeOptionalText(wechatId);
String normalizedPhone = StringUtils.hasText(phone) ? phone.trim() : null;
return userMapper.selectList(wrapper).stream()
.filter(user -> Objects.equals(normalizedName, user.getNickname()))
.filter(user -> Objects.equals(normalizedWechatId, UserProfileFieldSupport.normalizeOptionalText(user.getWechatId())))
.filter(user -> Objects.equals(normalizedPhone, decryptPhone(user.getPhone())))
.map(user -> {
AppointmentCustomerOptionVO customer = new AppointmentCustomerOptionVO();
customer.setId(user.getId());
customer.setName(user.getNickname());
String contactPhone = decryptPhone(user.getContactPhone());
customer.setPhone(StringUtils.hasText(contactPhone) ? contactPhone : decryptPhone(user.getPhone()));
customer.setAvatar(resolveAccessibleAvatar(user.getAvatar()));
customer.setCreatedAt(user.getCreateTime());
return customer;
}).collect(Collectors.toList());
}
@Override
public PageResultVO<AppointmentCustomerOptionVO> listCustomersForAppointment(Integer page, Integer size, String keyword, Long shopId) {
int safePage = page == null || page < 1 ? 1 : page;
int safeSize = size == null ? 30 : Math.max(1, Math.min(size, 100));
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class)
.eq(UserDO::getType, 0)
.eq(UserDO::getIsDelete, 0)
.orderByDesc(UserDO::getCreateTime);
applyCustomerShopScope(wrapper, shopId);
if (StringUtils.hasText(keyword)) {
String search = keyword.trim();
wrapper.and(query -> {
query.like(UserDO::getNickname, search);
if (search.matches(PHONE_REGEX)) query.or(phoneQuery -> addPhoneMatch(phoneQuery, search));
});
}
Page<UserDO> users = userMapper.selectPage(new Page<>(safePage, safeSize), wrapper);
PageResultVO<AppointmentCustomerOptionVO> result = new PageResultVO<>();
result.setList(users.getRecords().stream().map(user -> {
AppointmentCustomerOptionVO option = new AppointmentCustomerOptionVO();
option.setId(user.getId());
option.setName(user.getNickname());
String contactPhone = decryptPhone(user.getContactPhone());
String phone = StringUtils.hasText(contactPhone) ? contactPhone : decryptPhone(user.getPhone());
option.setPhone(phone);
option.setAvatar(resolveAccessibleAvatar(user.getAvatar()));
option.setCreatedAt(user.getCreateTime());
return option;
}).collect(Collectors.toList()));
result.setTotal(users.getTotal());
result.setPage(safePage);
result.setSize(safeSize);
return result;
}
private void applyCustomerShopScope(LambdaQueryWrapper<UserDO> wrapper, Long shopId) {
if (shopId == null || shopId <= 0) return;
List<Long> shopUserIds = userShopBindingSupport.listUserIdsByShopId(shopId, true);
if (shopUserIds.isEmpty()) wrapper.eq(UserDO::getShopId, shopId);
else wrapper.and(query -> query.eq(UserDO::getShopId, shopId).or().in(UserDO::getId, shopUserIds));
}
/**
* 分配默认权限
* @param userId 用户ID
@@ -0,0 +1,35 @@
SET @column_exists = (
SELECT COUNT(1)
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 't_shop'
AND column_name = 'appointment_business_hours'
);
SET @migration_sql = IF(
@column_exists = 0,
'ALTER TABLE t_shop ADD COLUMN appointment_business_hours VARCHAR(20) NULL COMMENT ''预约运营营业时间'' AFTER business_hours',
'SELECT 1'
);
PREPARE migration_statement FROM @migration_sql;
EXECUTE migration_statement;
DEALLOCATE PREPARE migration_statement;
SET @column_exists = (
SELECT COUNT(1)
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = 't_shop'
AND column_name = 'default_appointment_duration_minutes'
);
SET @migration_sql = IF(
@column_exists = 0,
'ALTER TABLE t_shop ADD COLUMN default_appointment_duration_minutes INT NOT NULL DEFAULT 60 COMMENT ''默认预约服务时长(分钟)'' AFTER business_hours',
'SELECT 1'
);
PREPARE migration_statement FROM @migration_sql;
EXECUTE migration_statement;
DEALLOCATE PREPARE migration_statement;
UPDATE t_shop
SET default_appointment_duration_minutes = 60
WHERE default_appointment_duration_minutes IS NULL OR default_appointment_duration_minutes <= 0;