diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerController.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerController.java index b83add13..c96a7c36 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerController.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/manager/controller/admin/AdminManagerController.java @@ -17,6 +17,7 @@ import com.xiaowang.jayucloud.core.modules.artist.vo.ArtistScheduleVO; import com.xiaowang.jayucloud.core.modules.manager.dto.ManagerCustomerCreateDTO; import com.xiaowang.jayucloud.core.modules.manager.dto.ManagerCustomerUpdateDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO; +import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentImageDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO; @@ -112,9 +113,20 @@ public class AdminManagerController { @PathVariable Long orderItemId, @RequestBody PlanningAppointmentMoveDTO dto) { UserDO currentUser = adminScopeHelper.getCurrentUser(request); + requireManagerOperator(currentUser); return Result.success(planningService.moveAppointment(currentUser, orderItemId, dto)); } + @PutMapping("/planning/appointments/{orderItemId}/images") + @RequirePermission("order:process") + @OperationGuard(action = "manager-planning-update-appointment-images", ttlSeconds = 10, message = "预约图片保存处理中,请勿重复提交") + public Result updateAppointmentImages(HttpServletRequest request, + @PathVariable Long orderItemId, + @RequestBody PlanningAppointmentImageDTO dto) { + UserDO currentUser = adminScopeHelper.getCurrentUser(request); + return Result.success(planningService.updateAppointmentImages(currentUser, orderItemId, dto)); + } + @PutMapping("/planning/appointments/{orderId}/status") @RequirePermission("order:process") @OperationGuard(action = "manager-planning-update-appointment-status", ttlSeconds = 10, message = "预约状态处理中,请勿重复提交") @@ -432,6 +444,13 @@ public class AdminManagerController { } } + private void requireManagerOperator(UserDO currentUser) { + if (Integer.valueOf(2).equals(currentUser.getType())) { + return; + } + throw new RuntimeException("只有店长可以改派预约"); + } + private boolean hasEmployeeUserBasicChanges(NailArtistInfoDTO dto) { return dto.getNickname() != null || dto.getAvatar() != null diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/order/entity/OrderItemDO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/order/entity/OrderItemDO.java index c53f72df..d98a4af4 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/order/entity/OrderItemDO.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/order/entity/OrderItemDO.java @@ -37,6 +37,11 @@ public class OrderItemDO extends BaseEntity { private Boolean depositPaid; private Boolean needRemoval; private Boolean fromMeituan; + private String appointmentProductTitle; + private String appointmentProductDescription; + private String appointmentProductTags; + private String appointmentProductPrecautions; + private String appointmentProductImageFileIds; /** * Field `artistId` (Long): data variable carried by this DTO/VO/entity. Check controller/service usage to see when it is filled. */ diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/controller/admin/AdminPlanningController.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/controller/admin/AdminPlanningController.java index 10180331..cfc43339 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/controller/admin/AdminPlanningController.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/controller/admin/AdminPlanningController.java @@ -79,6 +79,7 @@ public class AdminPlanningController { @PathVariable Long orderItemId, @RequestBody PlanningAppointmentMoveDTO dto) { UserDO currentUser = adminScopeHelper.getCurrentUser(request); + requireManagerOperator(currentUser); return Result.success(planningService.moveAppointment(currentUser, orderItemId, dto)); } @@ -91,4 +92,11 @@ public class AdminPlanningController { UserDO currentUser = adminScopeHelper.getCurrentUser(request); return Result.success(planningService.updateStatus(currentUser, orderId, dto)); } + + private void requireManagerOperator(UserDO currentUser) { + if (Integer.valueOf(2).equals(currentUser.getType())) { + return; + } + throw new RuntimeException("只有店长可以改派预约"); + } } diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/dto/PlanningAppointmentImageDTO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/dto/PlanningAppointmentImageDTO.java new file mode 100644 index 00000000..7e7921f9 --- /dev/null +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/dto/PlanningAppointmentImageDTO.java @@ -0,0 +1,8 @@ +package com.xiaowang.jayucloud.core.modules.planning.dto; + +import lombok.Data; + +@Data +public class PlanningAppointmentImageDTO { + private String imageFileIds; +} diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/PlanningService.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/PlanningService.java index f1afc342..9fbd28ae 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/PlanningService.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/PlanningService.java @@ -1,6 +1,7 @@ package com.xiaowang.jayucloud.core.modules.planning.service; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO; +import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentImageDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO; @@ -21,5 +22,7 @@ public interface PlanningService { PlanningAppointmentVO moveAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentMoveDTO dto); + PlanningAppointmentVO updateAppointmentImages(UserDO currentUser, Long orderItemId, PlanningAppointmentImageDTO dto); + Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto); } diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java index 1ea9955e..f0192edf 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImpl.java @@ -2,6 +2,7 @@ package com.xiaowang.jayucloud.core.modules.planning.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO; +import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentImageDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentMoveDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentStatusDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO; @@ -10,6 +11,9 @@ import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleException import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleDO; import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleRuleDO; import com.xiaowang.jayucloud.core.modules.artist.entity.NailArtistInfoDO; +import com.xiaowang.jayucloud.core.modules.file.service.ObjectStorageFileService; +import com.xiaowang.jayucloud.core.modules.file.support.ObjectStorageUrlSupport; +import com.xiaowang.jayucloud.core.modules.file.vo.ObjectStorageFileVO; import com.xiaowang.jayucloud.core.modules.order.entity.OrderDO; import com.xiaowang.jayucloud.core.modules.order.entity.OrderItemDO; import com.xiaowang.jayucloud.core.modules.product.entity.ProductDO; @@ -57,6 +61,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -75,7 +80,6 @@ public class PlanningServiceImpl implements PlanningService { private static final int MONTH_AVAILABLE_MINUTES = 90; private static final String RESERVATION_PENDING_QUOTE = "PENDING_QUOTE"; private static final String RESERVATION_CONFIRMED = "CONFIRMED"; - private static final String PRODUCT_SOURCE_TYPE_MANAGER_APPOINTMENT = "MANAGER_APPOINTMENT"; private static final String ENCODED_UNSET_PASSWORD = "$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW"; private static final List ACTIVE_RESERVATION_STATUS = List.of("LOCKED", RESERVATION_PENDING_QUOTE, RESERVATION_CONFIRMED); private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @@ -93,6 +97,8 @@ public class PlanningServiceImpl implements PlanningService { private final OrderMapper orderMapper; private final OrderItemMapper orderItemMapper; private final ProductMapper productMapper; + private final ObjectStorageFileService objectStorageFileService; + private final ObjectStorageUrlSupport objectStorageUrlSupport; private final ShopMapper shopMapper; private final ShopScheduleExceptionMapper shopScheduleExceptionMapper; private final AppointmentCapacityService appointmentCapacityService; @@ -192,7 +198,7 @@ public class PlanningServiceImpl implements PlanningService { OrderItemDO item = new OrderItemDO(); item.setOrderId(order.getId()); - item.setProductId(product.getId()); + item.setProductId(product == null ? null : product.getId()); item.setQuantity(quantity); item.setPrice(unitPrice); item.setArtistId(artist.getId()); @@ -200,6 +206,7 @@ public class PlanningServiceImpl implements PlanningService { item.setDepositPaid(Boolean.TRUE.equals(dto.getDepositPaid())); item.setNeedRemoval(Boolean.TRUE.equals(dto.getNeedRemoval())); item.setFromMeituan(Boolean.TRUE.equals(dto.getFromMeituan())); + applyAppointmentProductSnapshot(item, product, dto); item.setIsDelete(0); orderItemMapper.insert(item); @@ -208,7 +215,7 @@ public class PlanningServiceImpl implements PlanningService { item.getId(), shopId, artist.getId(), - product.getTitle(), + resolveAppointmentProductTitle(product, dto), startTime, endTime, trimToNull(dto.getClientRequestId()) @@ -260,7 +267,9 @@ public class PlanningServiceImpl implements PlanningService { LocalDateTime endTime = startTime.plusMinutes(durationMinutes); ensureWithinBusinessHours(order.getShopId(), startTime, endTime); - BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice(); + BigDecimal unitPrice = product == null + ? resolveAppointmentUnitPrice(null, dto) + : product.getPrice() == null ? BigDecimal.ZERO : product.getPrice(); BigDecimal amount = unitPrice.multiply(BigDecimal.valueOf(quantity)); appointmentCapacityService.moveReservationForArtistChange( @@ -269,7 +278,7 @@ public class PlanningServiceImpl implements PlanningService { order.getShopId(), item.getArtistId(), artist.getId(), - product.getTitle(), + resolveAppointmentProductTitle(product, dto), startTime, endTime ); @@ -282,11 +291,12 @@ public class PlanningServiceImpl implements PlanningService { order.setPayAmount(amount); orderMapper.updateById(order); - item.setProductId(product.getId()); + item.setProductId(product == null ? null : product.getId()); item.setQuantity(quantity); item.setPrice(unitPrice); item.setArtistId(artist.getId()); item.setAppointmentTime(startTime); + applyAppointmentProductSnapshot(item, product, dto); if (dto.getDepositPaid() != null) { item.setDepositPaid(dto.getDepositPaid()); } @@ -312,7 +322,7 @@ public class PlanningServiceImpl implements PlanningService { } OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId()); requireEditableAppointment(order); - ProductDO product = requireActiveProduct(item.getProductId(), order.getShopId()); + ProductDO product = item.getProductId() == null ? null : 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()) * @@ -332,7 +342,7 @@ public class PlanningServiceImpl implements PlanningService { order.getShopId(), item.getArtistId(), artist.getId(), - product.getTitle(), + resolveAppointmentDisplayTitle(null, item, product), startTime, endTime ); @@ -343,6 +353,23 @@ public class PlanningServiceImpl implements PlanningService { return getAppointment(currentUser, item.getId()); } + @Override + @Transactional + public PlanningAppointmentVO updateAppointmentImages(UserDO currentUser, Long orderItemId, PlanningAppointmentImageDTO dto) { + if (orderItemId == null || dto == null) { + throw new RuntimeException("预约图片信息不能为空"); + } + OrderItemDO item = orderItemMapper.selectByIdForUpdate(orderItemId); + if (item == null || Integer.valueOf(1).equals(item.getIsDelete())) { + throw new RuntimeException("预约不存在"); + } + OrderDO order = requireAccessibleOrder(currentUser, item.getOrderId()); + requireEditableAppointment(order); + item.setAppointmentProductImageFileIds(trimToNull(dto.getImageFileIds())); + orderItemMapper.updateById(item); + return getAppointment(currentUser, item.getId()); + } + @Override @Transactional public Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto) { @@ -670,9 +697,7 @@ public class PlanningServiceImpl implements PlanningService { vo.setCustomerName(resolveAppointmentCustomerName(order, customer)); vo.setCustomerPhone(customer == null ? null : firstNonBlank(customer.getContactPhone(), customer.getPhone(), "")); vo.setProductId(product == null ? item == null ? null : item.getProductId() : product.getId()); - vo.setProductTitle(reservation != null && hasText(reservation.getProductTitle()) - ? reservation.getProductTitle() - : product == null ? "预约作品" : product.getTitle()); + vo.setProductTitle(resolveAppointmentDisplayTitle(reservation, item, product)); vo.setArtistId(artistId); vo.setArtistName(artist == null ? "未分配" : artist.getName()); vo.setArtistColor(artist == null ? ARTIST_COLORS.get(0) : artist.getColor()); @@ -693,6 +718,11 @@ public class PlanningServiceImpl implements PlanningService { vo.setConflictReason(resolveAppointmentConflictReason(occupancyStatus)); vo.setAmount(order == null ? null : order.getActualAmount()); vo.setRemark(order == null ? null : order.getCustomerRemark()); + vo.setProductDescription(resolveAppointmentProductDescription(item, product)); + vo.setProductTags(resolveAppointmentProductTags(item, product)); + vo.setProductPrecautions(resolveAppointmentProductPrecautions(item, product)); + vo.setProductImageFileIds(resolveAppointmentProductImageFileIds(item, product)); + vo.setProductImageUrls(resolveImageUrls(parseLongTokens(vo.getProductImageFileIds()))); return vo; } @@ -857,10 +887,11 @@ public class PlanningServiceImpl implements PlanningService { if (dto.getProductId() != null) { return requireActiveProduct(dto.getProductId(), shopId); } - return createManualAppointmentProduct(dto, shopId); + requireManualAppointmentProduct(dto); + return null; } - private ProductDO createManualAppointmentProduct(PlanningAppointmentCreateDTO dto, Long shopId) { + private void requireManualAppointmentProduct(PlanningAppointmentCreateDTO dto) { String title = trimToNull(dto.getManualProductTitle()); if (!hasText(title)) { throw new RuntimeException("请选择预约作品或填写手动作品名称"); @@ -869,30 +900,11 @@ public class PlanningServiceImpl implements PlanningService { if (price == null || price.compareTo(BigDecimal.ZERO) < 0) { throw new RuntimeException("手动作品价格不能小于0"); } - int durationMinutes = requireAppointmentDuration(dto.getDurationMinutes()); - ProductDO product = new ProductDO(); - product.setShopId(shopId); - product.setTitle(title); - product.setDescription(trimToNull(dto.getManualProductDescription())); - product.setTags(trimToNull(dto.getManualProductTags())); - product.setTargetAudience(trimToNull(dto.getManualProductTargetAudience())); - product.setPrecautions(trimToNull(dto.getManualProductPrecautions())); - product.setImageFileIds(trimToNull(dto.getManualProductImageFileIds())); - product.setPrice(price); - product.setLikeCount(0); - product.setCollectCount(0); - product.setApproximateDuration(durationMinutes + "分钟"); - product.setBookableArtists(dto.getArtistId() == null ? null : String.valueOf(dto.getArtistId())); - product.setFrontVisible(0); - product.setSourceType(PRODUCT_SOURCE_TYPE_MANAGER_APPOINTMENT); - product.setIsDelete(0); - productMapper.insert(product); - return product; } private BigDecimal resolveAppointmentUnitPrice(ProductDO product, PlanningAppointmentCreateDTO dto) { if (dto.getManualProductPrice() == null) { - return product.getPrice() == null ? BigDecimal.ZERO : product.getPrice(); + return product == null || product.getPrice() == null ? BigDecimal.ZERO : product.getPrice(); } if (dto.getManualProductPrice().compareTo(BigDecimal.ZERO) < 0) { throw new RuntimeException("本次价格不能小于0"); @@ -900,6 +912,30 @@ public class PlanningServiceImpl implements PlanningService { return dto.getManualProductPrice(); } + private void applyAppointmentProductSnapshot(OrderItemDO item, ProductDO product, PlanningAppointmentCreateDTO dto) { + item.setAppointmentProductTitle(resolveAppointmentProductTitle(product, dto)); + item.setAppointmentProductDescription(product == null + ? trimToNull(dto.getManualProductDescription()) + : trimToNull(product.getDescription())); + item.setAppointmentProductTags(product == null + ? trimToNull(dto.getManualProductTags()) + : trimToNull(product.getTags())); + item.setAppointmentProductPrecautions(product == null + ? trimToNull(dto.getManualProductPrecautions()) + : trimToNull(product.getPrecautions())); + item.setAppointmentProductImageFileIds(product == null + ? trimToNull(dto.getManualProductImageFileIds()) + : trimToNull(product.getImageFileIds())); + } + + private String resolveAppointmentProductTitle(ProductDO product, PlanningAppointmentCreateDTO dto) { + return firstNonBlank( + dto == null ? null : dto.getManualProductTitle(), + product == null ? null : product.getTitle(), + "预约作品" + ); + } + private int requireAppointmentDuration(Integer durationMinutes) { if (durationMinutes == null || durationMinutes <= 0) { throw new RuntimeException("预约时长不能为空且必须大于0分钟"); @@ -984,6 +1020,47 @@ public class PlanningServiceImpl implements PlanningService { ); } + private String resolveAppointmentDisplayTitle(AppointmentReservationDO reservation, OrderItemDO item, ProductDO product) { + return firstNonBlank( + reservation == null ? null : reservation.getProductTitle(), + item == null ? null : item.getAppointmentProductTitle(), + product == null ? null : product.getTitle(), + "预约作品" + ); + } + + private String resolveAppointmentProductDescription(OrderItemDO item, ProductDO product) { + return firstNonBlank( + item == null ? null : item.getAppointmentProductDescription(), + product == null ? null : product.getDescription(), + "" + ); + } + + private String resolveAppointmentProductTags(OrderItemDO item, ProductDO product) { + return firstNonBlank( + item == null ? null : item.getAppointmentProductTags(), + product == null ? null : product.getTags(), + "" + ); + } + + private String resolveAppointmentProductPrecautions(OrderItemDO item, ProductDO product) { + return firstNonBlank( + item == null ? null : item.getAppointmentProductPrecautions(), + product == null ? null : product.getPrecautions(), + "" + ); + } + + private String resolveAppointmentProductImageFileIds(OrderItemDO item, ProductDO product) { + return firstNonBlank( + item == null ? null : item.getAppointmentProductImageFileIds(), + product == null ? null : product.getImageFileIds(), + "" + ); + } + private OrderDO requireAccessibleOrder(UserDO currentUser, Long orderId) { OrderDO order = orderMapper.selectById(orderId); if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) { @@ -1176,6 +1253,45 @@ public class PlanningServiceImpl implements PlanningService { return list == null ? List.of() : list; } + private List parseLongTokens(String value) { + if (!hasText(value)) { + return List.of(); + } + List result = new ArrayList<>(); + String[] tokens = value.split(","); + for (int index = 0; index < tokens.length; index += 1) { + String token = tokens[index].trim(); + if (token.isEmpty()) { + continue; + } + try { + result.add(Long.parseLong(token)); + } catch (NumberFormatException e) { + throw new RuntimeException("预约作品图片文件ID格式不正确:" + token); + } + } + return result; + } + + private List resolveImageUrls(List fileIds) { + if (fileIds == null || fileIds.isEmpty()) { + return List.of(); + } + Map fileMap = objectStorageFileService.getObjectStorageFileMapByIds(new LinkedHashSet<>(fileIds)); + List urls = new ArrayList<>(); + for (Long fileId : fileIds) { + ObjectStorageFileVO file = fileMap.get(fileId); + if (file == null) { + continue; + } + String imageUrl = objectStorageUrlSupport.toAccessibleUrl(file); + if (hasText(imageUrl)) { + urls.add(imageUrl); + } + } + return urls; + } + private String firstNonBlank(String... values) { for (String value : values) { if (hasText(value)) { diff --git a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningAppointmentVO.java b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningAppointmentVO.java index 38bd39b1..7d375fb3 100644 --- a/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningAppointmentVO.java +++ b/JY-Core/src/main/java/com/xiaowang/jayucloud/core/modules/planning/vo/PlanningAppointmentVO.java @@ -3,6 +3,8 @@ package com.xiaowang.jayucloud.core.modules.planning.vo; import lombok.Data; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; @Data public class PlanningAppointmentVO { @@ -33,4 +35,9 @@ public class PlanningAppointmentVO { private String conflictReason; private BigDecimal amount; private String remark; + private String productDescription; + private String productTags; + private String productPrecautions; + private String productImageFileIds; + private List productImageUrls = new ArrayList<>(); } diff --git a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java index acfa77a2..f09fd3b7 100644 --- a/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java +++ b/JY-Core/src/test/java/com/xiaowang/jayucloud/core/modules/planning/service/impl/PlanningServiceImplTest.java @@ -6,12 +6,16 @@ import com.xiaowang.jayucloud.core.modules.artist.mapper.ArtistScheduleException import com.xiaowang.jayucloud.core.modules.artist.mapper.NailArtistInfoMapper; import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleDO; import com.xiaowang.jayucloud.core.modules.artist.entity.ArtistScheduleRuleDO; +import com.xiaowang.jayucloud.core.modules.file.service.ObjectStorageFileService; +import com.xiaowang.jayucloud.core.modules.file.support.ObjectStorageUrlSupport; +import com.xiaowang.jayucloud.core.modules.file.vo.ObjectStorageFileVO; import com.xiaowang.jayucloud.core.modules.order.entity.OrderDO; import com.xiaowang.jayucloud.core.modules.order.entity.OrderItemDO; import com.xiaowang.jayucloud.core.modules.order.mapper.OrderItemMapper; import com.xiaowang.jayucloud.core.modules.order.mapper.OrderMapper; import com.xiaowang.jayucloud.core.modules.order.service.OrderService; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentCreateDTO; +import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentImageDTO; import com.xiaowang.jayucloud.core.modules.planning.dto.PlanningAppointmentUpdateDTO; import com.xiaowang.jayucloud.core.modules.planning.entity.AppointmentReservationDO; import com.xiaowang.jayucloud.core.modules.planning.mapper.AppointmentReservationMapper; @@ -37,6 +41,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; +import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -76,6 +81,12 @@ class PlanningServiceImplTest { @Mock private ProductMapper productMapper; + @Mock + private ObjectStorageFileService objectStorageFileService; + + @Mock + private ObjectStorageUrlSupport objectStorageUrlSupport; + @Mock private ShopMapper shopMapper; @@ -106,6 +117,8 @@ class PlanningServiceImplTest { orderMapper, orderItemMapper, productMapper, + objectStorageFileService, + objectStorageUrlSupport, shopMapper, shopScheduleExceptionMapper, appointmentCapacityService, @@ -115,7 +128,7 @@ class PlanningServiceImplTest { } @Test - void createAppointmentShouldHideManualProductFromFront() { + void createAppointmentShouldStoreManualProductSnapshotWithoutCreatingProduct() { UserDO manager = user(2, 8L); UserDO artist = user(3, 8L); artist.setId(20L); @@ -132,14 +145,14 @@ class PlanningServiceImplTest { dto.setDurationMinutes(90); dto.setManualProductTitle(" 日落贝壳 "); dto.setManualProductPrice(new BigDecimal("168.00")); + dto.setManualProductDescription(" 轻透贝壳款 "); + dto.setManualProductTags(" 贝壳 "); + dto.setManualProductPrecautions(" 避免磕碰 "); + dto.setManualProductImageFileIds("501,502"); dto.setClientRequestId("manual-product-test"); + OrderItemDO[] storedItem = new OrderItemDO[1]; when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); - when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> { - ProductDO product = invocation.getArgument(0); - product.setId(100L); - return 1; - }); when(userMapper.selectById(20L)).thenReturn(artist); when(userMapper.selectById(30L)).thenReturn(customer); when(shopMapper.selectById(8L)).thenReturn(shop); @@ -152,19 +165,10 @@ class PlanningServiceImplTest { 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 -> { - OrderItemDO item = new OrderItemDO(); - item.setId(300L); - item.setOrderId(200L); - item.setProductId(100L); - item.setArtistId(20L); - item.setQuantity(1); - item.setAppointmentTime(LocalDateTime.of(2026, 6, 26, 13, 0)); - item.setIsDelete(0); - return item; - }); + when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> storedItem[0]); when(orderMapper.selectById(200L)).thenAnswer(invocation -> { OrderDO order = new OrderDO(); order.setId(200L); @@ -175,18 +179,6 @@ class PlanningServiceImplTest { order.setIsDelete(0); return order; }); - when(productMapper.selectById(100L)).thenAnswer(invocation -> { - ProductDO product = new ProductDO(); - product.setId(100L); - product.setShopId(8L); - product.setTitle("日落贝壳"); - product.setPrice(new BigDecimal("168.00")); - product.setApproximateDuration("90分钟"); - product.setFrontVisible(0); - product.setSourceType("MANAGER_APPOINTMENT"); - product.setIsDelete(0); - return product; - }); AppointmentReservationDO reservation = new AppointmentReservationDO(); reservation.setOrderItemId(300L); reservation.setArtistId(20L); @@ -195,20 +187,33 @@ class PlanningServiceImplTest { reservation.setAppointmentEndTime(LocalDateTime.of(2026, 6, 26, 14, 30)); when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation); when(userMapper.selectBatchIds(any())).thenReturn(List.of(customer)); + ObjectStorageFileVO firstFile = new ObjectStorageFileVO(); + firstFile.setId(501L); + ObjectStorageFileVO secondFile = new ObjectStorageFileVO(); + secondFile.setId(502L); + when(objectStorageFileService.getObjectStorageFileMapByIds(any())).thenReturn(Map.of( + 501L, firstFile, + 502L, secondFile + )); + when(objectStorageUrlSupport.toAccessibleUrl(firstFile)).thenReturn("https://img.example/501.jpg"); + when(objectStorageUrlSupport.toAccessibleUrl(secondFile)).thenReturn("https://img.example/502.jpg"); var appointment = planningService.createAppointment(manager, dto); - ArgumentCaptor captor = ArgumentCaptor.forClass(ProductDO.class); - org.mockito.Mockito.verify(productMapper).insert(captor.capture()); - ProductDO product = captor.getValue(); - assertThat(product.getTitle()).isEqualTo("日落贝壳"); - assertThat(product.getFrontVisible()).isZero(); - assertThat(product.getSourceType()).isEqualTo("MANAGER_APPOINTMENT"); - assertThat(product.getImageFileIds()).isNull(); + org.mockito.Mockito.verify(productMapper, org.mockito.Mockito.never()).insert(any(ProductDO.class)); + assertThat(storedItem[0].getProductId()).isNull(); + assertThat(storedItem[0].getAppointmentProductTitle()).isEqualTo("日落贝壳"); + assertThat(storedItem[0].getAppointmentProductDescription()).isEqualTo("轻透贝壳款"); + assertThat(storedItem[0].getAppointmentProductTags()).isEqualTo("贝壳"); + assertThat(storedItem[0].getAppointmentProductPrecautions()).isEqualTo("避免磕碰"); + assertThat(storedItem[0].getAppointmentProductImageFileIds()).isEqualTo("501,502"); ArgumentCaptor orderCaptor = ArgumentCaptor.forClass(OrderDO.class); org.mockito.Mockito.verify(orderMapper).insert(orderCaptor.capture()); assertThat(orderCaptor.getValue().getCustomerName()).isEqualTo("王女士"); assertThat(appointment.getCustomerName()).isEqualTo("王女士"); + assertThat(appointment.getProductTitle()).isEqualTo("日落贝壳"); + assertThat(appointment.getProductImageFileIds()).isEqualTo("501,502"); + assertThat(appointment.getProductImageUrls()).containsExactly("https://img.example/501.jpg", "https://img.example/502.jpg"); } @Test @@ -230,17 +235,10 @@ class PlanningServiceImplTest { dto.setNeedRemoval(true); dto.setFromMeituan(true); - ProductDO[] storedProduct = new ProductDO[1]; UserDO[] storedCustomer = new UserDO[1]; OrderDO[] storedOrder = new OrderDO[1]; OrderItemDO[] storedItem = new OrderItemDO[1]; when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); - when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> { - ProductDO product = invocation.getArgument(0); - product.setId(100L); - storedProduct[0] = product; - return 1; - }); when(userMapper.selectById(20L)).thenReturn(artist); when(shopMapper.selectById(8L)).thenReturn(shop); when(snowflakeIdGenerator.nextIdString()).thenReturn("202607200001", "202607200002"); @@ -264,10 +262,10 @@ class PlanningServiceImplTest { }); when(orderItemMapper.selectById(300L)).thenAnswer(invocation -> storedItem[0]); when(orderMapper.selectById(200L)).thenAnswer(invocation -> storedOrder[0]); - when(productMapper.selectById(100L)).thenAnswer(invocation -> storedProduct[0]); AppointmentReservationDO reservation = reservation(20L, 200L, 300L, LocalDateTime.of(2026, 7, 20, 15, 0), LocalDateTime.of(2026, 7, 20, 16, 0)); + reservation.setProductTitle("净色护理"); when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation); when(userMapper.selectBatchIds(any())).thenAnswer(invocation -> List.of(storedCustomer[0])); @@ -279,10 +277,14 @@ class PlanningServiceImplTest { assertThat(customerCaptor.getValue().getPhone()).isNull(); assertThat(customerCaptor.getValue().getContactPhone()).isNull(); assertThat(customerCaptor.getValue().getAccount()).isEqualTo("guest202607200001"); + org.mockito.Mockito.verify(productMapper, org.mockito.Mockito.never()).insert(any(ProductDO.class)); + assertThat(storedItem[0].getProductId()).isNull(); + assertThat(storedItem[0].getAppointmentProductTitle()).isEqualTo("净色护理"); assertThat(storedItem[0].getDepositPaid()).isTrue(); assertThat(storedItem[0].getNeedRemoval()).isTrue(); assertThat(storedItem[0].getFromMeituan()).isTrue(); assertThat(appointment.getCustomerName()).isEqualTo("到店王女士"); + assertThat(appointment.getProductTitle()).isEqualTo("净色护理"); assertThat(appointment.getDepositPaid()).isTrue(); assertThat(appointment.getNeedRemoval()).isTrue(); assertThat(appointment.getFromMeituan()).isTrue(); @@ -368,11 +370,6 @@ class PlanningServiceImplTest { dto.setManualProductPrice(new BigDecimal("100.00")); when(adminScopeHelper.resolveShopScope(manager, null)).thenReturn(8L); - when(productMapper.insert(any(ProductDO.class))).thenAnswer(invocation -> { - ProductDO product = invocation.getArgument(0); - product.setId(100L); - return 1; - }); when(userMapper.selectById(20L)).thenReturn(artist); when(userMapper.selectById(30L)).thenReturn(customer); when(shopMapper.selectById(8L)).thenReturn(shop); @@ -404,6 +401,53 @@ class PlanningServiceImplTest { org.mockito.Mockito.verify(orderItemMapper, org.mockito.Mockito.never()).updateById(any()); } + @Test + void updateAppointmentImagesShouldPersistSnapshotImageIdsAndReturnUrls() { + UserDO manager = user(2, 8L); + UserDO artist = user(3, 8L); + artist.setId(20L); + artist.setNickname("小王"); + UserDO customer = user(0, 8L); + customer.setId(30L); + customer.setNickname("王女士"); + OrderDO order = order(200L, 8L, 30L); + OrderItemDO item = orderItem(300L, 200L, null, 20L, LocalDateTime.of(2026, 7, 21, 13, 0)); + item.setAppointmentProductTitle("手绘款"); + item.setAppointmentProductImageFileIds("501"); + PlanningAppointmentImageDTO dto = new PlanningAppointmentImageDTO(); + dto.setImageFileIds("601,602"); + AppointmentReservationDO reservation = reservation(20L, 200L, 300L, + LocalDateTime.of(2026, 7, 21, 13, 0), + LocalDateTime.of(2026, 7, 21, 14, 0)); + reservation.setProductTitle("手绘款"); + ObjectStorageFileVO firstFile = new ObjectStorageFileVO(); + firstFile.setId(601L); + ObjectStorageFileVO secondFile = new ObjectStorageFileVO(); + secondFile.setId(602L); + + when(orderItemMapper.selectByIdForUpdate(300L)).thenReturn(item); + when(orderMapper.selectById(200L)).thenReturn(order); + when(orderItemMapper.selectById(300L)).thenReturn(item); + when(appointmentReservationMapper.selectOne(any())).thenReturn(reservation); + when(userMapper.selectList(any())).thenReturn(List.of(artist)); + when(nailArtistInfoMapper.selectList(any())).thenReturn(List.of()); + when(userMapper.selectBatchIds(any())).thenReturn(List.of(customer)); + when(objectStorageFileService.getObjectStorageFileMapByIds(any())).thenReturn(Map.of( + 601L, firstFile, + 602L, secondFile + )); + when(objectStorageUrlSupport.toAccessibleUrl(firstFile)).thenReturn("https://img.example/601.jpg"); + when(objectStorageUrlSupport.toAccessibleUrl(secondFile)).thenReturn("https://img.example/602.jpg"); + + var appointment = planningService.updateAppointmentImages(manager, 300L, dto); + + assertThat(item.getAppointmentProductImageFileIds()).isEqualTo("601,602"); + org.mockito.Mockito.verify(orderItemMapper).updateById(item); + assertThat(appointment.getProductTitle()).isEqualTo("手绘款"); + assertThat(appointment.getProductImageFileIds()).isEqualTo("601,602"); + assertThat(appointment.getProductImageUrls()).containsExactly("https://img.example/601.jpg", "https://img.example/602.jpg"); + } + @Test void calendarMarksMonthAvailabilityByContinuousNinetyMinuteWindow() { UserDO manager = user(2, 8L); diff --git a/JY-Salon-WeChat/api/planning.js b/JY-Salon-WeChat/api/planning.js index 9cbe3234..5808b078 100644 --- a/JY-Salon-WeChat/api/planning.js +++ b/JY-Salon-WeChat/api/planning.js @@ -30,6 +30,14 @@ module.exports = { }) }, + updateAppointmentImages(orderItemId, data) { + return request({ + url: `/manager/planning/appointments/${orderItemId}/images`, + method: 'PUT', + data + }) + }, + updateStatus(orderId, status) { return request({ url: `/manager/planning/appointments/${orderId}/status`, diff --git a/JY-Salon-WeChat/api/tags.js b/JY-Salon-WeChat/api/tags.js new file mode 100644 index 00000000..34d78fe7 --- /dev/null +++ b/JY-Salon-WeChat/api/tags.js @@ -0,0 +1,9 @@ +const request = require('../utils/request') + +module.exports = { + listAll() { + return request({ + url: '/tag/list/all' + }) + } +} diff --git a/JY-Salon-WeChat/pages/appointment-detail/index.js b/JY-Salon-WeChat/pages/appointment-detail/index.js index e1864860..50d17d02 100644 --- a/JY-Salon-WeChat/pages/appointment-detail/index.js +++ b/JY-Salon-WeChat/pages/appointment-detail/index.js @@ -1,5 +1,44 @@ const planningApi = require('../../api/planning') const { markPlanningRefresh } = require('../../utils/planning-refresh') +const { chooseImageFilePaths, uploadObjectFile } = require('../../utils/upload') + +function canTransferAppointment() { + const app = getApp() + const userInfo = app.globalData.userInfo || {} + return Number(userInfo.type) === 2 +} + +function splitImageValues(value) { + return String(value || '') + .split(',') + .map(item => item.trim()) + .filter(Boolean) +} + +function resolveProductImageUrls(appointment) { + if (appointment && Array.isArray(appointment.productImageUrls)) { + return appointment.productImageUrls.filter(Boolean) + } + return [] +} + +async function uploadAppointmentImageFiles(limit) { + const filePaths = await chooseImageFilePaths(limit) + const fileIds = [] + const imageUrls = [] + for (let index = 0; index < filePaths.length; index += 1) { + const filePath = filePaths[index] + const uploadResult = await uploadObjectFile(filePath) + const fileId = uploadResult.id || uploadResult.fileId + const fileUrl = uploadResult.fileUrl || uploadResult.primaryUrl || filePath + if (!fileId) { + throw new Error('预约图片上传成功但未返回文件ID') + } + fileIds.push(String(fileId)) + imageUrls.push(fileUrl) + } + return { fileIds, imageUrls } +} Page({ data: { @@ -7,11 +46,18 @@ Page({ appointment: {}, avatarText: '', timeText: '', + productImageUrls: [], + productImageFileIds: '', + imageUploading: false, + canTransferAppointment: false, loadError: '' }, onLoad(options) { - this.setData({ id: options.id || '' }) + this.setData({ + id: options.id || '', + canTransferAppointment: canTransferAppointment() + }) this.loadDetail() }, @@ -24,16 +70,22 @@ Page({ appointment: {}, avatarText: '', timeText: '', + productImageUrls: [], + productImageFileIds: '', loadError: error.message || '预约详情加载失败' }) } }, applyAppointment(appointment) { + const imageUrls = resolveProductImageUrls(appointment) this.setData({ appointment, avatarText: String(appointment.customerName || '客').slice(0, 1), timeText: `${(appointment.startTime || '').slice(0, 16)} - ${(appointment.endTime || '').slice(11, 16)}`, + productImageUrls: imageUrls, + productImageFileIds: String(appointment.productImageFileIds || ''), + canTransferAppointment: canTransferAppointment(), loadError: '' }) }, @@ -62,9 +114,97 @@ Page({ }, goTransfer() { + if (!this.data.canTransferAppointment) { + wx.showToast({ title: '只有店长可以改派预约', icon: 'none' }) + return + } wx.navigateTo({ url: `/pages/artist-transfer/index?id=${this.data.id}` }) }, + async persistAppointmentImages(fileIds) { + const appointment = await planningApi.updateAppointmentImages(this.data.id, { + imageFileIds: fileIds.join(',') + }) + markPlanningRefresh() + this.applyAppointment(appointment) + }, + + async chooseAppointmentImages() { + if (this.data.imageUploading) { + return + } + const currentFileIds = splitImageValues(this.data.productImageFileIds) + const remainingCount = 9 - currentFileIds.length + if (remainingCount <= 0) { + wx.showToast({ title: '最多上传 9 张作品图片', icon: 'none' }) + return + } + this.setData({ imageUploading: true }) + try { + const uploaded = await uploadAppointmentImageFiles(remainingCount) + if (uploaded.fileIds.length === 0) { + return + } + await this.persistAppointmentImages(currentFileIds.concat(uploaded.fileIds)) + wx.showToast({ title: '图片已保存' }) + } catch (error) { + wx.showToast({ title: error.message || '图片上传失败', icon: 'none' }) + } finally { + this.setData({ imageUploading: false }) + } + }, + + async replaceAppointmentImages() { + if (this.data.imageUploading) { + return + } + this.setData({ imageUploading: true }) + try { + const uploaded = await uploadAppointmentImageFiles(9) + if (uploaded.fileIds.length === 0) { + return + } + await this.persistAppointmentImages(uploaded.fileIds) + wx.showToast({ title: '图片已保存' }) + } catch (error) { + wx.showToast({ title: error.message || '图片上传失败', icon: 'none' }) + } finally { + this.setData({ imageUploading: false }) + } + }, + + async removeAppointmentImage(event) { + if (this.data.imageUploading) { + return + } + const index = Number(event.currentTarget.dataset.index) + const currentFileIds = splitImageValues(this.data.productImageFileIds) + if (!Number.isInteger(index) || index < 0 || index >= currentFileIds.length) { + return + } + const nextFileIds = currentFileIds.filter((item, itemIndex) => itemIndex !== index) + this.setData({ imageUploading: true }) + try { + await this.persistAppointmentImages(nextFileIds) + wx.showToast({ title: '图片已保存' }) + } catch (error) { + wx.showToast({ title: error.message || '图片保存失败', icon: 'none' }) + } finally { + this.setData({ imageUploading: false }) + } + }, + + previewProductImage(event) { + const current = this.data.productImageUrls[Number(event.currentTarget.dataset.index)] + if (!current) { + return + } + wx.previewImage({ + current, + urls: this.data.productImageUrls + }) + }, + back() { wx.navigateBack() } diff --git a/JY-Salon-WeChat/pages/appointment-detail/index.wxml b/JY-Salon-WeChat/pages/appointment-detail/index.wxml index 7b21f317..d1c1d6ce 100644 --- a/JY-Salon-WeChat/pages/appointment-detail/index.wxml +++ b/JY-Salon-WeChat/pages/appointment-detail/index.wxml @@ -15,7 +15,7 @@ {{appointment.statusText}} - + @@ -38,6 +38,25 @@ + + + 作品图片 + + + + + + + × + + + {{imageUploading ? '...' : '+'}} + + + 暂无图片 + + + 备注 {{appointment.remark || '暂无备注'}} diff --git a/JY-Salon-WeChat/pages/appointment-detail/index.wxss b/JY-Salon-WeChat/pages/appointment-detail/index.wxss index 00b7edcd..d34a54c2 100644 --- a/JY-Salon-WeChat/pages/appointment-detail/index.wxss +++ b/JY-Salon-WeChat/pages/appointment-detail/index.wxss @@ -95,6 +95,93 @@ line-height: 1.6; } +.section-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16rpx; +} + +.image-action { + flex: 0 0 auto; + width: 156rpx; + min-width: 156rpx; + max-width: 156rpx; + padding: 0; + text-align: right; +} + +.image-card { + padding: 20rpx; +} + +.detail-image-list { + display: flex; + flex-wrap: wrap; + gap: 14rpx; +} + +.detail-image-item { + position: relative; + width: 150rpx; + height: 150rpx; +} + +.detail-image { + display: block; + width: 150rpx; + height: 150rpx; + border-radius: 16rpx; + background: #efe5da; +} + +.detail-image-remove { + position: absolute; + top: -10rpx; + right: -10rpx; + display: flex; + align-items: center; + justify-content: center; + width: 34rpx; + height: 34rpx; + border-radius: 50%; + background: #bf4949; + color: #fff; + font-size: 24rpx; + font-weight: 900; + line-height: 34rpx; +} + +.detail-image-add { + display: flex; + align-items: center; + justify-content: center; + width: 150rpx; + height: 150rpx; + border: 2rpx dashed #d5bfa9; + border-radius: 16rpx; + background: #fff8ef; + color: #b78b63; + font-size: 52rpx; + font-weight: 500; + line-height: 1; +} + +.detail-image-add.disabled { + opacity: 0.55; +} + +.detail-image-empty { + display: flex; + align-items: center; + justify-content: center; + min-height: 142rpx; + border-radius: 16rpx; + background: #f7efe7; + color: #9a9288; + font-size: 26rpx; +} + .action-row { display: grid; grid-template-columns: 1fr 1fr 1fr; diff --git a/JY-Salon-WeChat/pages/appointment-form/index.js b/JY-Salon-WeChat/pages/appointment-form/index.js index 70f112c3..663e5bed 100644 --- a/JY-Salon-WeChat/pages/appointment-form/index.js +++ b/JY-Salon-WeChat/pages/appointment-form/index.js @@ -1,5 +1,6 @@ const planningApi = require('../../api/planning') const productsApi = require('../../api/products') +const tagsApi = require('../../api/tags') const customersApi = require('../../api/customers') const dateUtil = require('../../utils/date') const { markPlanningRefresh } = require('../../utils/planning-refresh') @@ -256,6 +257,58 @@ function normalizeProduct(product, artists) { } } +function normalizeTagOption(tag) { + const name = String((tag && (tag.displayName || tag.tagName || tag.name)) || '').trim() + if (!name) { + return null + } + return { + id: (tag && tag.id) || name, + name + } +} + +function normalizeTagOptions(tags) { + const source = Array.isArray(tags) ? tags : [] + const names = new Set() + return source + .map(normalizeTagOption) + .filter(Boolean) + .filter(item => { + if (names.has(item.name)) { + return false + } + names.add(item.name) + return true + }) +} + +function resolveTagPickerIndex(tagOptions, value) { + const firstTag = String(value || '').split(/[;,,、]/)[0].trim() + if (!firstTag) { + return 0 + } + const index = tagOptions.findIndex(item => item.name === firstTag) + return index >= 0 ? index : 0 +} + +function resolveTagValue(tagOptions, value) { + const tokens = String(value || '') + .split(/[;,,、]/) + .map(item => item.trim()) + .filter(Boolean) + if (tokens.length === 0) { + return '' + } + if (!Array.isArray(tagOptions) || tagOptions.length === 0) { + return '' + } + const matched = tokens + .map(token => tagOptions.find(item => item.name === token)) + .find(Boolean) + return matched ? matched.name : '' +} + function splitManualImageValues(value) { return String(value || '') .split(',') @@ -335,6 +388,9 @@ Page({ manualProductImageUrls: [], productKeyword: '', productError: '', + tagOptions: [], + tagPickerIndex: 0, + tagError: '', conflictTip: '', conflictLevel: 'free', canCreateAppointment: true, @@ -385,12 +441,33 @@ Page({ productError: error.message || '作品列表加载失败' }) } + await this.loadTags() await this.loadArtists() this.refreshProductCards() await this.refreshAvailableTimes() this.checkAvailability() }, + async loadTags() { + try { + const tagsData = await tagsApi.listAll() + const tagOptions = normalizeTagOptions(tagsData.list || tagsData || []) + const selectedTag = resolveTagValue(tagOptions, this.data.form.manualProductTags) + this.setData({ + tagOptions, + tagPickerIndex: resolveTagPickerIndex(tagOptions, selectedTag), + 'form.manualProductTags': selectedTag, + tagError: '' + }) + } catch (error) { + this.setData({ + tagOptions: [], + tagPickerIndex: 0, + tagError: error.message || '标签加载失败' + }) + } + }, + async loadArtists() { try { const calendar = await planningApi.calendar({ @@ -522,17 +599,20 @@ Page({ }, openProductModal() { + this.openManualProductPanel() + }, + + openProductTemplateSheet() { + this.setData({ productKeyword: '' }) this.refreshProductCards() this.setData({ - productModalVisible: true, - manualProductPanelVisible: false + productModalVisible: true }) }, closeProductModal() { this.setData({ - productModalVisible: false, - manualProductPanelVisible: false + productModalVisible: false }) }, @@ -542,7 +622,9 @@ Page({ : splitManualImageValues(this.data.form.manualProductImageUrl) this.setData({ manualProductPanelVisible: true, - manualProductImageUrls: imageUrls + productModalVisible: false, + manualProductImageUrls: imageUrls, + tagPickerIndex: resolveTagPickerIndex(this.data.tagOptions, this.data.form.manualProductTags) }) }, @@ -550,7 +632,10 @@ Page({ if (this.data.manualImageUploading) { return } - this.setData({ manualProductPanelVisible: false }) + this.setData({ + manualProductPanelVisible: false, + productModalVisible: false + }) }, stopTap() { @@ -564,30 +649,43 @@ Page({ selectProduct(event) { const selectedProduct = this.data.filteredProducts.find(item => String(item.id) === String(event.currentTarget.dataset.id)) || {} const price = formatProductPrice(selectedProduct.price) + const productTag = resolveTagValue(this.data.tagOptions, parseProductTags(selectedProduct).join(',')) + const imageUrls = Array.isArray(selectedProduct.imageUrls) ? selectedProduct.imageUrls : [] this.setData({ selectedProduct, - 'form.productId': selectedProduct.id, - 'form.manualProductTitle': '', + 'form.productId': '', + 'form.manualProductTitle': selectedProduct.title || '', 'form.manualProductPrice': price, - 'form.manualProductDescription': '', - 'form.manualProductTags': '', - 'form.manualProductPrecautions': '', - 'form.manualProductImageFileIds': '', - 'form.manualProductImageUrl': '', - manualProductImageUrls: [], - manualProductPanelVisible: false, + 'form.manualProductDescription': selectedProduct.description || '', + 'form.manualProductTags': productTag, + 'form.manualProductPrecautions': selectedProduct.precautions || '', + 'form.manualProductImageFileIds': selectedProduct.imageFileIds || '', + 'form.manualProductImageUrl': imageUrls.join(','), + manualProductImageUrls: imageUrls, + productModalVisible: false, + tagPickerIndex: resolveTagPickerIndex(this.data.tagOptions, productTag), 'form.durationMinutes': String(parseInt(selectedProduct.approximateDuration, 10) || this.data.form.durationMinutes || '') }) - this.closeProductModal() this.refreshAvailableTimes() this.checkAvailability() }, + onManualTagChange(event) { + const tag = this.data.tagOptions[Number(event.detail.value)] + if (!tag) { + return + } + this.setData({ + tagPickerIndex: Number(event.detail.value), + 'form.manualProductTags': tag.name + }) + }, + useManualProduct() { const title = String(this.data.form.manualProductTitle || '').trim() const price = Number(this.data.form.manualProductPrice) if (!title || Number.isNaN(price) || price < 0) { - wx.showToast({ title: '请填写手动预约作品名称和价格', icon: 'none' }) + wx.showToast({ title: '请填写作品名称和价格', icon: 'none' }) return } this.setData({ diff --git a/JY-Salon-WeChat/pages/appointment-form/index.wxml b/JY-Salon-WeChat/pages/appointment-form/index.wxml index a8564272..8134d269 100644 --- a/JY-Salon-WeChat/pages/appointment-form/index.wxml +++ b/JY-Salon-WeChat/pages/appointment-form/index.wxml @@ -31,10 +31,9 @@ - 预约作品 + 选择作品 - {{selectedProduct.title || form.manualProductTitle || '请选择预约作品'}} - 手动 + {{form.manualProductTitle || selectedProduct.title || '请选择作品'}} @@ -98,18 +97,58 @@ {{conflictTip}} - - + + + + 选择作品 + × + + + + + + + + + + + {{form.manualProductTags || (tagOptions.length ? '请选择标签' : '暂无标签')}} + › + + + + + {{tagError}} + + + 作品图片 + + + + + × + + + {{manualImageUploading ? '...' : '+'}} + + + + + + + + + - 选择预约作品 + 使用已有作品模板 × {{productError}} - + 图 @@ -125,49 +164,6 @@ 暂无匹配作品 - - - 没有合适作品? - 临时新增一个预约作品,提交时会一并保存到预约信息。 - - - - - - - - - 新增预约作品 - 填写本次预约使用的作品信息 - - × - - 手动新增预约作品 - - - - -