小程序预约详情支持图片预览、编辑预约与完成收款拆分
This commit is contained in:
+26
@@ -2,6 +2,7 @@ package com.xiaowang.jayucloud.salon.core.modules.manager.controller.admin;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.annotation.OperationGuard;
|
||||
import com.xiaowang.jayucloud.salon.core.annotation.RequirePermission;
|
||||
import com.xiaowang.jayucloud.salon.core.common.BusinessException;
|
||||
import com.xiaowang.jayucloud.salon.core.common.Result;
|
||||
import com.xiaowang.jayucloud.salon.core.common.vo.PageResultVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.artist.dto.ArtistColorUpdateDTO;
|
||||
@@ -16,6 +17,7 @@ import com.xiaowang.jayucloud.salon.core.modules.artist.vo.ArtistScheduleRuleSet
|
||||
import com.xiaowang.jayucloud.salon.core.modules.artist.vo.ArtistScheduleRuleVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.artist.vo.ArtistScheduleVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.manager.dto.ManagerCustomerCreateDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderOfflinePaymentDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.service.OrderService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.vo.OrderVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.planning.dto.PlanningAppointmentCreateDTO;
|
||||
@@ -120,6 +122,30 @@ public class AdminManagerController {
|
||||
return Result.success(planningService.getAppointment(currentUser, orderItemId));
|
||||
}
|
||||
|
||||
@PutMapping("/planning/appointments/{orderItemId}")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-update-appointment", ttlSeconds = 10, message = "预约保存处理中,请勿重复提交")
|
||||
public Result<PlanningAppointmentVO> updateAppointment(HttpServletRequest request,
|
||||
@PathVariable Long orderItemId,
|
||||
@RequestBody PlanningAppointmentCreateDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(planningService.updateAppointment(currentUser, orderItemId, dto));
|
||||
}
|
||||
|
||||
@PostMapping("/orders/{orderId}/offline-payment")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-order-offline-payment", ttlSeconds = 10, message = "收款登记处理中,请勿重复提交")
|
||||
public Result<OrderVO> registerOfflinePayment(HttpServletRequest request,
|
||||
@PathVariable Long orderId,
|
||||
@RequestBody OrderOfflinePaymentDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
if (Integer.valueOf(3).equals(currentUser.getType())) {
|
||||
throw new BusinessException(403, "美甲师账号不能登记收款");
|
||||
}
|
||||
Long scopedShopId = adminScopeHelper.resolveShopScope(currentUser, null);
|
||||
return Result.success(orderService.registerOfflinePayment(orderId, currentUser.getId(), scopedShopId, dto));
|
||||
}
|
||||
|
||||
@PutMapping("/planning/appointments/{orderItemId}/time-artist")
|
||||
@RequirePermission("order:process")
|
||||
@OperationGuard(action = "manager-planning-move-appointment", ttlSeconds = 10, message = "预约调整处理中,请勿重复提交")
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 线下收款登记入参。
|
||||
* 当前仅支持 payMethod=OFFLINE,paidAmount 必须与订单应付金额一致。
|
||||
* payMethod 可选 OFFLINE、CASH、WECHAT、ALIPAY;paidAmount 为实收金额,允许与订单应付金额不一致。
|
||||
*/
|
||||
@Data
|
||||
public class OrderOfflinePaymentDTO {
|
||||
|
||||
+8
-14
@@ -1827,8 +1827,11 @@ public class OrderServiceImpl implements OrderService {
|
||||
throw new RuntimeException("收款登记信息不能为空");
|
||||
}
|
||||
String payMethod = dto.getPayMethod() == null ? "" : dto.getPayMethod().trim().toUpperCase();
|
||||
if (!PAYMENT_METHOD_OFFLINE.equals(payMethod)) {
|
||||
throw new RuntimeException("当前仅支持线下收款,payMethod 只能为 OFFLINE");
|
||||
if (!PAYMENT_METHOD_OFFLINE.equals(payMethod)
|
||||
&& !"CASH".equals(payMethod)
|
||||
&& !"WECHAT".equals(payMethod)
|
||||
&& !"ALIPAY".equals(payMethod)) {
|
||||
throw new RuntimeException("payMethod 只能为 OFFLINE、CASH、WECHAT 或 ALIPAY");
|
||||
}
|
||||
if (dto.getPaidAmount() == null) {
|
||||
throw new RuntimeException("实收金额不能为空");
|
||||
@@ -1852,31 +1855,22 @@ public class OrderServiceImpl implements OrderService {
|
||||
throw new RuntimeException("订单已取消,不能登记收款");
|
||||
}
|
||||
|
||||
BigDecimal expectedAmount = order.getPayAmount() == null ? order.getActualAmount() : order.getPayAmount();
|
||||
if (expectedAmount == null) {
|
||||
expectedAmount = BigDecimal.ZERO;
|
||||
}
|
||||
if (dto.getPaidAmount().compareTo(expectedAmount) != 0) {
|
||||
throw new RuntimeException("实收金额必须等于订单应付金额 "
|
||||
+ expectedAmount.stripTrailingZeros().toPlainString() + " 元");
|
||||
}
|
||||
|
||||
LocalDateTime paidAt = (dto.getPaidAt() == null ? LocalDateTime.now() : dto.getPaidAt()).withNano(0);
|
||||
if (PAYMENT_STATUS_PAID.equals(order.getPaymentStatus())) {
|
||||
boolean sameMethod = PAYMENT_METHOD_OFFLINE.equals(order.getPaymentMethod());
|
||||
boolean sameMethod = payMethod.equals(order.getPaymentMethod());
|
||||
boolean sameAmount = order.getPaidAmount() != null && order.getPaidAmount().compareTo(dto.getPaidAmount()) == 0;
|
||||
boolean sameTime = order.getPayTime() != null && order.getPayTime().withNano(0).equals(paidAt);
|
||||
if (sameMethod && sameAmount && sameTime) {
|
||||
return buildOrderVO(order);
|
||||
}
|
||||
throw new RuntimeException("该订单已登记线下收款,金额或收款时间与首次登记不一致,不能重复登记");
|
||||
throw new RuntimeException("该订单已登记收款,金额或收款方式与首次登记不一致,不能重复登记");
|
||||
}
|
||||
if (order.getPaymentStatus() != null && !PAYMENT_STATUS_UNPAID.equals(order.getPaymentStatus())) {
|
||||
throw new RuntimeException("订单当前支付状态为 " + order.getPaymentStatus() + ",不能登记线下收款");
|
||||
}
|
||||
|
||||
order.setPaymentStatus(PAYMENT_STATUS_PAID);
|
||||
order.setPaymentMethod(PAYMENT_METHOD_OFFLINE);
|
||||
order.setPaymentMethod(payMethod);
|
||||
order.setPaidAmount(dto.getPaidAmount());
|
||||
order.setPayTime(paidAt);
|
||||
order.setPaidBy(operatorId);
|
||||
|
||||
+2
@@ -22,6 +22,8 @@ public interface PlanningService {
|
||||
|
||||
PlanningAppointmentVO getAppointment(UserDO currentUser, Long orderItemId);
|
||||
|
||||
PlanningAppointmentVO updateAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentCreateDTO dto);
|
||||
|
||||
PlanningAppointmentVO moveAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentMoveDTO dto);
|
||||
|
||||
Boolean updateStatus(UserDO currentUser, Long orderId, PlanningAppointmentStatusDTO dto);
|
||||
|
||||
+151
@@ -349,6 +349,146 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
return toAppointmentVO(reservation, item, order, product, customer, artistMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlanningAppointmentVO updateAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentCreateDTO dto) {
|
||||
if (dto == null) {
|
||||
throw new RuntimeException("预约信息不能为空");
|
||||
}
|
||||
if (orderItemId == null) {
|
||||
throw new RuntimeException("预约ID不能为空");
|
||||
}
|
||||
if (Integer.valueOf(3).equals(currentUser.getType())) {
|
||||
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());
|
||||
if ("HISTORICAL_BACKFILL".equals(order.getOrderSource())) {
|
||||
throw new RuntimeException("历史补单不支持编辑预约");
|
||||
}
|
||||
int currentStatus = order.getStatus() == null ? -1 : order.getStatus();
|
||||
if (currentStatus == OrderStatus.COMPLETED.getCode()) {
|
||||
throw new RuntimeException("预约已完成,不能编辑");
|
||||
}
|
||||
if (currentStatus == OrderStatus.CANCELLED.getCode()) {
|
||||
throw new RuntimeException("预约已取消,不能编辑");
|
||||
}
|
||||
if (currentStatus == OrderStatus.IN_SERVICE.getCode()) {
|
||||
throw new RuntimeException("服务中的预约不能编辑");
|
||||
}
|
||||
if (currentStatus != OrderStatus.PRICE_CONFIRMING.getCode()
|
||||
&& currentStatus != OrderStatus.PENDING_SERVICE.getCode()) {
|
||||
throw new RuntimeException("当前状态不可编辑预约");
|
||||
}
|
||||
|
||||
Long shopId = order.getShopId();
|
||||
ShopDO shop = shopMapper.selectById(shopId);
|
||||
int shopDefaultDuration = resolveShopDefaultDuration(shop);
|
||||
int quantity = item.getQuantity() == null || item.getQuantity() <= 0 ? 1 : item.getQuantity();
|
||||
ProductDO product = resolveUpdateProduct(dto, item, shopId, shopDefaultDuration);
|
||||
int durationMinutes = resolveDurationMinutes(product, dto.getDurationMinutes(), shopDefaultDuration) * quantity;
|
||||
LocalDateTime startTime = parseAppointmentStart(dto.getAppointmentStartTime(), dto.getAppointmentDate(), dto.getAppointmentTime());
|
||||
LocalDateTime endTime = startTime.plusMinutes(durationMinutes);
|
||||
|
||||
boolean timeChanged = item.getAppointmentTime() == null || !item.getAppointmentTime().equals(startTime);
|
||||
if (timeChanged) {
|
||||
ensureFutureAppointmentTime(startTime);
|
||||
}
|
||||
ensureWithinBusinessHours(shopId, startTime, endTime);
|
||||
|
||||
UserDO artist = dto.getArtistId() == null ? null : requireActiveArtist(dto.getArtistId(), shopId);
|
||||
boolean artistChanged = !Objects.equals(item.getArtistId(), artist == null ? null : artist.getId());
|
||||
|
||||
BigDecimal unitPrice = product.getPrice() == null ? BigDecimal.ZERO : product.getPrice();
|
||||
BigDecimal amount = dto.getAmount() == null
|
||||
? unitPrice.multiply(BigDecimal.valueOf(quantity))
|
||||
: dto.getAmount();
|
||||
if (amount.compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("成交金额不能小于0");
|
||||
}
|
||||
boolean paid = "PAID".equals(order.getPaymentStatus());
|
||||
BigDecimal currentAmount = order.getActualAmount();
|
||||
if (paid && (currentAmount == null || currentAmount.compareTo(amount) != 0)) {
|
||||
throw new RuntimeException("订单已收款,不能修改成交金额");
|
||||
}
|
||||
|
||||
UserDO customer = resolveCustomer(currentUser, shopId, dto);
|
||||
order.setUserId(customer == null ? null : customer.getId());
|
||||
order.setCustomerNameSnapshot(customer == null ? trimToNull(dto.getCustomerName()) : null);
|
||||
order.setCustomerPhoneSnapshot(customer == null ? trimToNull(dto.getPhone()) : null);
|
||||
order.setCustomerRemark(trimToNull(dto.getRemark()));
|
||||
if (!paid) {
|
||||
order.setTotalAmount(amount);
|
||||
order.setActualAmount(amount);
|
||||
order.setPayAmount(amount);
|
||||
}
|
||||
orderMapper.updateById(order);
|
||||
|
||||
item.setProductId(product.getId());
|
||||
item.setPrice(amount.divide(BigDecimal.valueOf(quantity), 2, RoundingMode.HALF_UP));
|
||||
item.setArtistId(artist == null ? null : artist.getId());
|
||||
item.setAppointmentTime(startTime);
|
||||
item.setIsDelete(0);
|
||||
orderItemMapper.updateById(item);
|
||||
|
||||
if (artist != null && (artistChanged || timeChanged)) {
|
||||
appointmentCapacityService.moveReservationForArtistChange(
|
||||
order.getId(),
|
||||
item.getId(),
|
||||
shopId,
|
||||
artist.getId(),
|
||||
artist.getId(),
|
||||
product.getTitle(),
|
||||
startTime,
|
||||
endTime
|
||||
);
|
||||
} else if (artist == null && artistChanged) {
|
||||
appointmentReservationMapper.releaseByOrderItem(item.getId(), "RELEASED");
|
||||
}
|
||||
return getAppointment(currentUser, item.getId());
|
||||
}
|
||||
|
||||
private ProductDO resolveUpdateProduct(PlanningAppointmentCreateDTO dto, OrderItemDO item, Long shopId, int shopDefaultDuration) {
|
||||
if (dto.getProductId() != null) {
|
||||
return requireActiveProduct(dto.getProductId(), shopId);
|
||||
}
|
||||
String title = trimToNull(dto.getManualProductTitle());
|
||||
if (!hasText(title)) {
|
||||
throw new RuntimeException("请填写美甲款式名称");
|
||||
}
|
||||
ProductDO existing = item.getProductId() == null ? null : productMapper.selectById(item.getProductId());
|
||||
boolean editableManualProduct = existing != null
|
||||
&& PRODUCT_SOURCE_TYPE_MANAGER_APPOINTMENT.equals(existing.getSourceType())
|
||||
&& !Integer.valueOf(1).equals(existing.getIsDelete())
|
||||
&& shopId.equals(existing.getShopId());
|
||||
if (!editableManualProduct) {
|
||||
return createManualAppointmentProduct(dto, shopId, shopDefaultDuration);
|
||||
}
|
||||
BigDecimal price = dto.getManualProductPrice() == null ? dto.getAmount() : dto.getManualProductPrice();
|
||||
if (price == null) {
|
||||
price = BigDecimal.ZERO;
|
||||
}
|
||||
if (price.compareTo(BigDecimal.ZERO) < 0) {
|
||||
throw new RuntimeException("成交金额不能小于0");
|
||||
}
|
||||
int durationMinutes = dto.getDurationMinutes() == null || dto.getDurationMinutes() <= 0
|
||||
? shopDefaultDuration : dto.getDurationMinutes();
|
||||
existing.setTitle(title);
|
||||
existing.setDescription(trimToNull(dto.getManualProductDescription()));
|
||||
existing.setTags(trimToNull(dto.getManualProductTags()));
|
||||
existing.setTargetAudience(trimToNull(dto.getManualProductTargetAudience()));
|
||||
existing.setPrecautions(trimToNull(dto.getManualProductPrecautions()));
|
||||
existing.setImageFileIds(trimToNull(dto.getManualProductImageFileIds()));
|
||||
existing.setPrice(price);
|
||||
existing.setApproximateDuration(durationMinutes + "分钟");
|
||||
existing.setBookableArtists(dto.getArtistId() == null ? null : String.valueOf(dto.getArtistId()));
|
||||
productMapper.updateById(existing);
|
||||
return existing;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlanningAppointmentVO moveAppointment(UserDO currentUser, Long orderItemId, PlanningAppointmentMoveDTO dto) {
|
||||
@@ -658,6 +798,17 @@ public class PlanningServiceImpl implements PlanningService {
|
||||
vo.setAmount(order == null ? null : order.getActualAmount());
|
||||
vo.setRemark(order == null ? null : order.getCustomerRemark());
|
||||
vo.setCancelReason(order == null ? null : order.getCancelReason());
|
||||
vo.setProductSourceType(product == null ? null : product.getSourceType());
|
||||
vo.setProductDescription(product == null ? null : product.getDescription());
|
||||
vo.setProductTags(product == null ? null : product.getTags());
|
||||
vo.setProductTargetAudience(product == null ? null : product.getTargetAudience());
|
||||
vo.setProductPrecautions(product == null ? null : product.getPrecautions());
|
||||
vo.setProductImageFileIds(product == null ? null : product.getImageFileIds());
|
||||
vo.setPaymentStatus(order == null ? null : order.getPaymentStatus());
|
||||
vo.setPaymentMethod(order == null ? null : order.getPaymentMethod());
|
||||
vo.setPayAmount(order == null ? null : order.getPayAmount());
|
||||
vo.setPaidAmount(order == null ? null : order.getPaidAmount());
|
||||
vo.setPayTime(order == null || order.getPayTime() == null ? null : DATE_TIME_FORMATTER.format(order.getPayTime()));
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
||||
+14
@@ -39,4 +39,18 @@ public class PlanningAppointmentVO {
|
||||
private BigDecimal amount;
|
||||
private String remark;
|
||||
private String cancelReason;
|
||||
/** 风格库来源,MANAGER_APPOINTMENT 表示手动录入的款式 */
|
||||
private String productSourceType;
|
||||
private String productDescription;
|
||||
private String productTags;
|
||||
private String productTargetAudience;
|
||||
private String productPrecautions;
|
||||
private String productImageFileIds;
|
||||
/** 支付状态:UNPAID / PAID */
|
||||
private String paymentStatus;
|
||||
/** 收款方式:OFFLINE / CASH / WECHAT / ALIPAY */
|
||||
private String paymentMethod;
|
||||
private BigDecimal payAmount;
|
||||
private BigDecimal paidAmount;
|
||||
private String payTime;
|
||||
}
|
||||
|
||||
+23
-8
@@ -2,8 +2,11 @@ package com.xiaowang.jayucloud.salon.core.modules.order.service.impl;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderOfflinePaymentDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.entity.OrderDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderItemMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.mapper.OrderMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.order.support.OrderStatus;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.shop.mapper.ShopMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.mapper.UserMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -23,31 +26,43 @@ class OrderServiceImplOfflinePaymentTest {
|
||||
@Mock
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Mock
|
||||
private OrderItemMapper orderItemMapper;
|
||||
|
||||
@Mock
|
||||
private ShopMapper shopMapper;
|
||||
|
||||
@Mock
|
||||
private UserMapper userMapper;
|
||||
|
||||
@InjectMocks
|
||||
private OrderServiceImpl service;
|
||||
|
||||
@Test
|
||||
void rejectsNonOfflinePaymentMethod() {
|
||||
void rejectsUnknownPaymentMethod() {
|
||||
OrderOfflinePaymentDTO dto = offlinePayment(new BigDecimal("100"), LocalDateTime.now());
|
||||
dto.setPayMethod("WECHAT");
|
||||
dto.setPayMethod("CARD");
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class,
|
||||
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
|
||||
|
||||
assertEquals("当前仅支持线下收款,payMethod 只能为 OFFLINE", error.getMessage());
|
||||
assertEquals("payMethod 只能为 OFFLINE、CASH、WECHAT 或 ALIPAY", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsAmountMismatch() {
|
||||
void allowsAmountAdjustment() {
|
||||
OrderDO order = order(1L, OrderStatus.PENDING_SERVICE.getCode(), "UNPAID");
|
||||
order.setPayAmount(new BigDecimal("100.00"));
|
||||
when(orderMapper.selectByIdForUpdate(1L)).thenReturn(order);
|
||||
when(orderItemMapper.selectByOrderId(1L)).thenReturn(java.util.Collections.emptyList());
|
||||
OrderOfflinePaymentDTO dto = offlinePayment(new BigDecimal("90"), LocalDateTime.now());
|
||||
dto.setPayMethod("CASH");
|
||||
|
||||
RuntimeException error = assertThrows(RuntimeException.class,
|
||||
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
|
||||
service.registerOfflinePayment(1L, 9L, 2L, dto);
|
||||
|
||||
assertEquals("实收金额必须等于订单应付金额 100 元", error.getMessage());
|
||||
assertEquals("PAID", order.getPaymentStatus());
|
||||
assertEquals("CASH", order.getPaymentMethod());
|
||||
assertEquals(new BigDecimal("90"), order.getPaidAmount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,7 +91,7 @@ class OrderServiceImplOfflinePaymentTest {
|
||||
RuntimeException error = assertThrows(RuntimeException.class,
|
||||
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
|
||||
|
||||
assertEquals("该订单已登记线下收款,金额或收款时间与首次登记不一致,不能重复登记", error.getMessage());
|
||||
assertEquals("该订单已登记收款,金额或收款方式与首次登记不一致,不能重复登记", error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user