合并 dev-trae 到 dev:Salon 线下收款登记与完成校验、ArtList Flyway 底座与安全清理、Salon 系统设置页重排

This commit is contained in:
2026-11-04 19:07:38 +08:00
81 changed files with 3192 additions and 4246 deletions
@@ -3,6 +3,8 @@ package com.xiaowang.jayucloud.salon.core.modules.order.controller.admin;
import com.xiaowang.jayucloud.salon.core.annotation.RequirePermission;
import com.xiaowang.jayucloud.salon.core.annotation.OperationGuard;
import com.xiaowang.jayucloud.salon.core.common.Result;
import com.xiaowang.jayucloud.salon.core.common.BusinessException;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderOfflinePaymentDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteSubmitDTO;
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
import com.xiaowang.jayucloud.salon.core.modules.order.service.OrderService;
@@ -160,4 +162,21 @@ public class AdminOrderController {
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
return Result.success(orderService.confirmShopQuote(id, currentUser.getId(), currentUser.getType()));
}
/**
* 店长登记线下收款。当前仅支持 payMethod=OFFLINE,实收金额必须等于订单应付金额。
*/
@PostMapping("/{orderId}/offline-payment")
@RequirePermission("order:process")
@OperationGuard(action = "admin-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));
}
}
@@ -0,0 +1,18 @@
package com.xiaowang.jayucloud.salon.core.modules.order.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 线下收款登记入参。
* 当前仅支持 payMethod=OFFLINE,paidAmount 必须与订单应付金额一致。
*/
@Data
public class OrderOfflinePaymentDTO {
private String payMethod;
private BigDecimal paidAmount;
private LocalDateTime paidAt;
private String paidRemark;
}
@@ -56,6 +56,9 @@ public class OrderDO extends BaseEntity {
private String paymentMethod;
private String paymentOrderNo;
private String refundStatus;
private Long paidBy;
private String paidByType;
private String paidRemark;
private String customerRemark;
private String cancelReason;
private String customerNameSnapshot;
@@ -21,6 +21,9 @@ public interface OrderMapper extends BaseMapper<OrderDO> {
@Select("SELECT * FROM t_order WHERE order_no = #{orderNo}")
OrderDO selectByOrderNo(@Param("orderNo") String orderNo);
@Select("SELECT * FROM t_order WHERE id = #{orderId} FOR UPDATE")
OrderDO selectByIdForUpdate(@Param("orderId") Long orderId);
@Select("SELECT DISTINCT o.* FROM t_order o " +
"INNER JOIN t_order_item oi ON o.id = oi.order_id " +
"WHERE oi.artist_id = #{artistId} AND o.is_delete = 0 " +
@@ -4,6 +4,7 @@ import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRejectDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRequestDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistReviewSubmitDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderOfflinePaymentDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteReplyDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteSubmitDTO;
import com.xiaowang.jayucloud.salon.core.modules.artist.vo.ArtistCalendarAppointmentVO;
@@ -130,6 +131,11 @@ public interface OrderService {
OrderVO confirmShopQuote(Long orderId, Long operatorId, Integer operatorType);
/**
* 登记线下收款。operatorShopId 为当前操作人的门店作用域,为空表示平台管理员。
*/
OrderVO registerOfflinePayment(Long orderId, Long operatorId, Long operatorShopId, OrderOfflinePaymentDTO dto);
OrderVO replyQuote(Long orderId, Long userId, OrderQuoteReplyDTO dto);
OrderVO confirmUserQuote(Long orderId, Long userId);
@@ -9,6 +9,7 @@ import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeReje
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistChangeRequestDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderArtistReviewSubmitDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderItemDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderOfflinePaymentDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteItemDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteReplyDTO;
import com.xiaowang.jayucloud.salon.core.modules.order.dto.OrderQuoteSubmitDTO;
@@ -133,6 +134,10 @@ public class OrderServiceImpl implements OrderService {
*/
private static final String COUPON_SOURCE_SYSTEM_VIP = "SYSTEM_VIP";
private static final int BOOKING_UNAVAILABLE_CODE = 409;
private static final String PAYMENT_STATUS_UNPAID = "UNPAID";
private static final String PAYMENT_STATUS_PAID = "PAID";
private static final String PAYMENT_METHOD_OFFLINE = "OFFLINE";
private static final String PAID_BY_TYPE_SHOP_MANAGER = "SHOP_MANAGER";
private static final String ISSUE_ORDER_ITEM = "ORDER_ITEM";
private static final String ISSUE_PRODUCT_UNAVAILABLE = "PRODUCT_UNAVAILABLE";
private static final String ISSUE_SHOP_MISMATCH = "SHOP_MISMATCH";
@@ -1454,6 +1459,9 @@ public class OrderServiceImpl implements OrderService {
&& !"HISTORICAL_BACKFILL".equals(order.getOrderSource())) {
throw new RuntimeException("普通预约不能进入服务中状态");
}
if (targetStatus == OrderStatus.COMPLETED) {
ensurePaidBeforeCompletion(order);
}
if (!Integer.valueOf(OrderStatus.PENDING_SERVICE.getCode()).equals(order.getStatus())
&& !(Integer.valueOf(OrderStatus.IN_SERVICE.getCode()).equals(order.getStatus())
&& (status == OrderStatus.COMPLETED.getCode() || status == OrderStatus.CANCELLED.getCode()))
@@ -1534,6 +1542,7 @@ public class OrderServiceImpl implements OrderService {
*/
throw new RuntimeException("当前订单状态不允许完成");
}
ensurePaidBeforeCompletion(order);
List<OrderItemDO> activeItems = orderItemMapper.selectByOrderId(orderId).stream()
.filter(item -> !Integer.valueOf(1).equals(item.getIsDelete()))
@@ -1808,6 +1817,75 @@ public class OrderServiceImpl implements OrderService {
return buildOrderVO(orderMapper.selectById(order.getId()));
}
@Override
@Transactional
public OrderVO registerOfflinePayment(Long orderId, Long operatorId, Long operatorShopId, OrderOfflinePaymentDTO dto) {
if (orderId == null) {
throw new RuntimeException("订单ID不能为空");
}
if (dto == null) {
throw new RuntimeException("收款登记信息不能为空");
}
String payMethod = dto.getPayMethod() == null ? "" : dto.getPayMethod().trim().toUpperCase();
if (!PAYMENT_METHOD_OFFLINE.equals(payMethod)) {
throw new RuntimeException("当前仅支持线下收款,payMethod 只能为 OFFLINE");
}
if (dto.getPaidAmount() == null) {
throw new RuntimeException("实收金额不能为空");
}
if (dto.getPaidAmount().compareTo(BigDecimal.ZERO) < 0) {
throw new RuntimeException("实收金额不能小于0");
}
String paidRemark = trimToNull(dto.getPaidRemark());
if (paidRemark != null && paidRemark.length() > 500) {
throw new RuntimeException("收款备注不能超过500个字符");
}
OrderDO order = orderMapper.selectByIdForUpdate(orderId);
if (order == null || Integer.valueOf(1).equals(order.getIsDelete())) {
throw new RuntimeException("订单不存在");
}
if (operatorShopId != null && !operatorShopId.equals(order.getShopId())) {
throw new BusinessException(403, "无权处理其他店铺订单");
}
if (Integer.valueOf(OrderStatus.CANCELLED.getCode()).equals(order.getStatus())) {
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 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("该订单已登记线下收款,金额或收款时间与首次登记不一致,不能重复登记");
}
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.setPaidAmount(dto.getPaidAmount());
order.setPayTime(paidAt);
order.setPaidBy(operatorId);
order.setPaidByType(PAID_BY_TYPE_SHOP_MANAGER);
order.setPaidRemark(paidRemark);
orderMapper.updateById(order);
return buildOrderVO(order);
}
@Override
@Transactional
public OrderVO replyQuote(Long orderId, Long userId, OrderQuoteReplyDTO dto) {
@@ -2258,9 +2336,18 @@ public class OrderServiceImpl implements OrderService {
}
/**
* Purpose: trimToNull supports OrderServiceImpl.java by holding or executing the trim to null business role.
* 完成订单前强制校验收款状态:未收款不得完成,不设任何豁免。
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
*/
/**
* 完成订单前强制校验收款状态:未收款不得完成,不设任何豁免。
*/
private void ensurePaidBeforeCompletion(OrderDO order) {
if (!PAYMENT_STATUS_PAID.equals(order.getPaymentStatus())) {
throw new RuntimeException("订单未收款,不能完成;请先登记线下收款");
}
}
private String trimToNull(String value) {
if (!StringUtils.hasText(value)) {
return null;
@@ -3284,6 +3371,13 @@ public class OrderServiceImpl implements OrderService {
orderVO.setPaymentMethod(order.getPaymentMethod());
orderVO.setPaymentOrderNo(order.getPaymentOrderNo());
orderVO.setRefundStatus(order.getRefundStatus());
orderVO.setPaidBy(order.getPaidBy());
orderVO.setPaidByType(order.getPaidByType());
orderVO.setPaidRemark(order.getPaidRemark());
if (order.getPaidBy() != null) {
UserDO payer = getUserFromCache(order.getPaidBy(), userCache);
orderVO.setPaidByName(payer == null ? null : payer.getNickname());
}
orderVO.setCustomerRemark(order.getCustomerRemark());
orderVO.setQuoteStatus(order.getQuoteStatus());
orderVO.setQuoteStatusText(resolveQuoteStatusText(order.getQuoteStatus(), order.getStatus()));
@@ -64,6 +64,10 @@ public class OrderVO {
private String paymentMethod;
private String paymentOrderNo;
private String refundStatus;
private Long paidBy;
private String paidByName;
private String paidByType;
private String paidRemark;
private String customerRemark;
private String quoteStatus;
private String orderSource;
@@ -0,0 +1,41 @@
-- 订单线下收款登记:记录收款人、收款人类型与收款备注
-- 说明:pay_time、payment_method、paid_amount、payment_status 已存在,本次不重复新增。
SET @column_exists = (
SELECT COUNT(1) FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = 't_order' AND column_name = 'paid_by'
);
SET @migration_sql = IF(
@column_exists = 0,
'ALTER TABLE t_order ADD COLUMN paid_by BIGINT UNSIGNED NULL COMMENT ''收款登记人用户ID'' AFTER refund_status',
'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_order' AND column_name = 'paid_by_type'
);
SET @migration_sql = IF(
@column_exists = 0,
'ALTER TABLE t_order ADD COLUMN paid_by_type VARCHAR(20) NULL COMMENT ''收款登记人类型,线下收款固定为 SHOP_MANAGER'' AFTER paid_by',
'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_order' AND column_name = 'paid_remark'
);
SET @migration_sql = IF(
@column_exists = 0,
'ALTER TABLE t_order ADD COLUMN paid_remark VARCHAR(500) NULL COMMENT ''收款登记备注'' AFTER paid_by_type',
'SELECT 1'
);
PREPARE migration_statement FROM @migration_sql;
EXECUTE migration_statement;
DEALLOCATE PREPARE migration_statement;
@@ -0,0 +1,111 @@
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.OrderMapper;
import com.xiaowang.jayucloud.salon.core.modules.order.support.OrderStatus;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class OrderServiceImplOfflinePaymentTest {
@Mock
private OrderMapper orderMapper;
@InjectMocks
private OrderServiceImpl service;
@Test
void rejectsNonOfflinePaymentMethod() {
OrderOfflinePaymentDTO dto = offlinePayment(new BigDecimal("100"), LocalDateTime.now());
dto.setPayMethod("WECHAT");
RuntimeException error = assertThrows(RuntimeException.class,
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
assertEquals("当前仅支持线下收款,payMethod 只能为 OFFLINE", error.getMessage());
}
@Test
void rejectsAmountMismatch() {
OrderDO order = order(1L, OrderStatus.PENDING_SERVICE.getCode(), "UNPAID");
order.setPayAmount(new BigDecimal("100.00"));
when(orderMapper.selectByIdForUpdate(1L)).thenReturn(order);
OrderOfflinePaymentDTO dto = offlinePayment(new BigDecimal("90"), LocalDateTime.now());
RuntimeException error = assertThrows(RuntimeException.class,
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
assertEquals("实收金额必须等于订单应付金额 100 元", error.getMessage());
}
@Test
void rejectsCancelledOrder() {
OrderDO order = order(1L, OrderStatus.CANCELLED.getCode(), "UNPAID");
order.setPayAmount(new BigDecimal("100"));
when(orderMapper.selectByIdForUpdate(1L)).thenReturn(order);
OrderOfflinePaymentDTO dto = offlinePayment(new BigDecimal("100"), LocalDateTime.now());
RuntimeException error = assertThrows(RuntimeException.class,
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
assertEquals("订单已取消,不能登记收款", error.getMessage());
}
@Test
void rejectsRepeatedRegistrationWithDifferentTime() {
OrderDO order = order(1L, OrderStatus.PENDING_SERVICE.getCode(), "PAID");
order.setPayAmount(new BigDecimal("100"));
order.setPaymentMethod("OFFLINE");
order.setPaidAmount(new BigDecimal("100"));
order.setPayTime(LocalDateTime.of(2026, 11, 4, 10, 0, 0));
when(orderMapper.selectByIdForUpdate(1L)).thenReturn(order);
OrderOfflinePaymentDTO dto = offlinePayment(new BigDecimal("100"), LocalDateTime.of(2026, 11, 4, 11, 0, 0));
RuntimeException error = assertThrows(RuntimeException.class,
() -> service.registerOfflinePayment(1L, 9L, 2L, dto));
assertEquals("该订单已登记线下收款,金额或收款时间与首次登记不一致,不能重复登记", error.getMessage());
}
@Test
void rejectsCompletingUnpaidOrder() {
OrderDO order = order(1L, OrderStatus.PENDING_SERVICE.getCode(), "UNPAID");
order.setOrderSource("NORMAL");
when(orderMapper.selectById(1L)).thenReturn(order);
RuntimeException error = assertThrows(RuntimeException.class,
() -> service.processOrder(1L, OrderStatus.COMPLETED.getCode()));
assertEquals("订单未收款,不能完成;请先登记线下收款", error.getMessage());
}
private OrderOfflinePaymentDTO offlinePayment(BigDecimal amount, LocalDateTime paidAt) {
OrderOfflinePaymentDTO dto = new OrderOfflinePaymentDTO();
dto.setPayMethod("OFFLINE");
dto.setPaidAmount(amount);
dto.setPaidAt(paidAt);
return dto;
}
private OrderDO order(Long id, Integer status, String paymentStatus) {
OrderDO order = new OrderDO();
order.setId(id);
order.setShopId(2L);
order.setStatus(status);
order.setPaymentStatus(paymentStatus);
order.setIsDelete(0);
return order;
}
}