feat(print): 支持多种照片打印类型的价格计算

- 新增手机照片打印(PHOTO_PRINT_MU)和特效照片打印(PHOTO_PRINT_FX)枚举类型
- 在价格计算服务中增加isPrintProduct方法统一判断打印类商品
- 修改订单服务跳过打印类商品重复购买检查逻辑
-优化打印机服务根据sourceId分类统计不同照片类型数量
- 分别计算普通、手机、特效照片打印的价格和数量- 更新价格计算逻辑以支持多种打印类型商品项
This commit is contained in:
2025-11-14 01:08:12 +08:00
parent ec34437e9d
commit 661aa4567f
4 changed files with 157 additions and 35 deletions

View File

@@ -912,6 +912,8 @@ public class OrderServiceImpl implements IOrderService {
checkSetAlreadyPurchased(userId, faceId, scenicId, product.getProductType()); checkSetAlreadyPurchased(userId, faceId, scenicId, product.getProductType());
break; break;
case PHOTO_PRINT: case PHOTO_PRINT:
case PHOTO_PRINT_MU:
case PHOTO_PRINT_FX:
case MACHINE_PRINT: case MACHINE_PRINT:
// 打印类商品允许重复购买,跳过检查 // 打印类商品允许重复购买,跳过检查
log.debug("跳过打印类商品重复购买检查: productType={}, productId={}", log.debug("跳过打印类商品重复购买检查: productType={}, productId={}",

View File

@@ -14,6 +14,8 @@ public enum ProductType {
RECORDING_SET("RECORDING_SET", "录像集"), RECORDING_SET("RECORDING_SET", "录像集"),
PHOTO_SET("PHOTO_SET", "照相集"), PHOTO_SET("PHOTO_SET", "照相集"),
PHOTO_PRINT("PHOTO_PRINT", "照片打印"), PHOTO_PRINT("PHOTO_PRINT", "照片打印"),
PHOTO_PRINT_MU("PHOTO_PRINT_MU", "手机照片打印"),
PHOTO_PRINT_FX("PHOTO_PRINT_FX", "特效照片打印"),
MACHINE_PRINT("MACHINE_PRINT", "一体机打印"); MACHINE_PRINT("MACHINE_PRINT", "一体机打印");
private final String code; private final String code;

View File

@@ -30,6 +30,17 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService {
private final IDiscountDetectionService discountDetectionService; private final IDiscountDetectionService discountDetectionService;
private final IVoucherService voucherService; private final IVoucherService voucherService;
/**
* 判断是否为打印类商品
* 打印类商品的价格计算方式为:单价 × 数量
*/
private boolean isPrintProduct(ProductType productType) {
return productType == ProductType.PHOTO_PRINT
|| productType == ProductType.PHOTO_PRINT_MU
|| productType == ProductType.PHOTO_PRINT_FX
|| productType == ProductType.MACHINE_PRINT;
}
@Override @Override
public PriceCalculationResult calculatePrice(PriceCalculationRequest request) { public PriceCalculationResult calculatePrice(PriceCalculationRequest request) {
if (request.getProducts() == null || request.getProducts().isEmpty()) { if (request.getProducts() == null || request.getProducts().isEmpty()) {
@@ -190,7 +201,7 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService {
try { try {
PriceProductConfig baseConfig = productConfigService.getProductConfig(productType.getCode(), productId); PriceProductConfig baseConfig = productConfigService.getProductConfig(productType.getCode(), productId);
if (baseConfig != null) { if (baseConfig != null) {
if (productType == ProductType.PHOTO_PRINT || productType == ProductType.MACHINE_PRINT) { if (isPrintProduct(productType)) {
return baseConfig.getBasePrice().multiply(BigDecimal.valueOf(product.getQuantity())); return baseConfig.getBasePrice().multiply(BigDecimal.valueOf(product.getQuantity()));
} else { } else {
return baseConfig.getBasePrice(); return baseConfig.getBasePrice();
@@ -205,7 +216,7 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService {
try { try {
PriceProductConfig defaultConfig = productConfigService.getProductConfig(productType.getCode(), "default"); PriceProductConfig defaultConfig = productConfigService.getProductConfig(productType.getCode(), "default");
if (defaultConfig != null) { if (defaultConfig != null) {
if (productType == ProductType.PHOTO_PRINT || productType == ProductType.MACHINE_PRINT) { if (isPrintProduct(productType)) {
return defaultConfig.getBasePrice().multiply(BigDecimal.valueOf(product.getQuantity())); return defaultConfig.getBasePrice().multiply(BigDecimal.valueOf(product.getQuantity()));
} else { } else {
return defaultConfig.getBasePrice(); return defaultConfig.getBasePrice();
@@ -219,7 +230,7 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService {
List<PriceProductConfig> configs = productConfigService.getProductConfig(productType.getCode()); List<PriceProductConfig> configs = productConfigService.getProductConfig(productType.getCode());
if (!configs.isEmpty()) { if (!configs.isEmpty()) {
PriceProductConfig baseConfig = configs.get(0); // 使用第一个配置作为默认 PriceProductConfig baseConfig = configs.get(0); // 使用第一个配置作为默认
if (productType == ProductType.PHOTO_PRINT || productType == ProductType.MACHINE_PRINT) { if (isPrintProduct(productType)) {
return baseConfig.getBasePrice().multiply(BigDecimal.valueOf(product.getQuantity())); return baseConfig.getBasePrice().multiply(BigDecimal.valueOf(product.getQuantity()));
} else { } else {
return baseConfig.getBasePrice(); return baseConfig.getBasePrice();
@@ -253,7 +264,7 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService {
actualPrice = baseConfig.getBasePrice(); actualPrice = baseConfig.getBasePrice();
originalPrice = baseConfig.getOriginalPrice(); originalPrice = baseConfig.getOriginalPrice();
if (productType == ProductType.PHOTO_PRINT || productType == ProductType.MACHINE_PRINT) { if (isPrintProduct(productType)) {
actualPrice = actualPrice.multiply(BigDecimal.valueOf(product.getQuantity())); actualPrice = actualPrice.multiply(BigDecimal.valueOf(product.getQuantity()));
if (originalPrice != null) { if (originalPrice != null) {
originalPrice = originalPrice.multiply(BigDecimal.valueOf(product.getQuantity())); originalPrice = originalPrice.multiply(BigDecimal.valueOf(product.getQuantity()));
@@ -273,7 +284,7 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService {
actualPrice = defaultConfig.getBasePrice(); actualPrice = defaultConfig.getBasePrice();
originalPrice = defaultConfig.getOriginalPrice(); originalPrice = defaultConfig.getOriginalPrice();
if (productType == ProductType.PHOTO_PRINT || productType == ProductType.MACHINE_PRINT) { if (isPrintProduct(productType)) {
actualPrice = actualPrice.multiply(BigDecimal.valueOf(product.getQuantity())); actualPrice = actualPrice.multiply(BigDecimal.valueOf(product.getQuantity()));
if (originalPrice != null) { if (originalPrice != null) {
originalPrice = originalPrice.multiply(BigDecimal.valueOf(product.getQuantity())); originalPrice = originalPrice.multiply(BigDecimal.valueOf(product.getQuantity()));
@@ -292,7 +303,7 @@ public class PriceCalculationServiceImpl implements IPriceCalculationService {
actualPrice = baseConfig.getBasePrice(); actualPrice = baseConfig.getBasePrice();
originalPrice = baseConfig.getOriginalPrice(); originalPrice = baseConfig.getOriginalPrice();
if (productType == ProductType.PHOTO_PRINT || productType == ProductType.MACHINE_PRINT) { if (isPrintProduct(productType)) {
actualPrice = actualPrice.multiply(BigDecimal.valueOf(product.getQuantity())); actualPrice = actualPrice.multiply(BigDecimal.valueOf(product.getQuantity()));
if (originalPrice != null) { if (originalPrice != null) {
originalPrice = originalPrice.multiply(BigDecimal.valueOf(product.getQuantity())); originalPrice = originalPrice.multiply(BigDecimal.valueOf(product.getQuantity()));

View File

@@ -354,37 +354,89 @@ public class PrinterServiceImpl implements PrinterService {
@Override @Override
public PriceObj queryPrice(Long memberId, Long scenicId, Long faceId) { public PriceObj queryPrice(Long memberId, Long scenicId, Long faceId) {
List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId, faceId); List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId, faceId);
// 计算照片总数量
long count = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity()))
.mapToInt(MemberPrintResp::getQuantity)
.sum();
PriceObj obj = new PriceObj(); PriceObj obj = new PriceObj();
obj.setScenicId(scenicId); obj.setScenicId(scenicId);
obj.setGoodsId(faceId); obj.setGoodsId(faceId);
obj.setFaceId(faceId); obj.setFaceId(faceId);
obj.setGoodsType(3); obj.setGoodsType(3);
if (count == 0) { // 按照 sourceId 分类照片
// sourceId > 0: 普通照片打印 (PHOTO_PRINT)
// sourceId == null: 手机照片打印 (PHOTO_PRINT_MU)
// sourceId == 0: 特效照片打印 (PHOTO_PRINT_FX)
long normalCount = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() != null && item.getSourceId() > 0)
.mapToInt(MemberPrintResp::getQuantity)
.sum();
long mobileCount = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() == null)
.mapToInt(MemberPrintResp::getQuantity)
.sum();
long effectCount = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() != null && item.getSourceId() == 0)
.mapToInt(MemberPrintResp::getQuantity)
.sum();
long totalCount = normalCount + mobileCount + effectCount;
if (totalCount == 0) {
// 如果没有照片,返回零价格 // 如果没有照片,返回零价格
obj.setPrice(BigDecimal.ZERO); obj.setPrice(BigDecimal.ZERO);
obj.setSlashPrice(BigDecimal.ZERO); obj.setSlashPrice(BigDecimal.ZERO);
obj.setFree(false); obj.setFree(false);
return obj; return obj;
} }
// 构建价格计算请求 // 构建价格计算请求
PriceCalculationRequest request = new PriceCalculationRequest(); PriceCalculationRequest request = new PriceCalculationRequest();
request.setUserId(memberId); request.setUserId(memberId);
// 创建照片打印商品项 // 创建商品项列表
ProductItem photoItem = new ProductItem(); List<ProductItem> productItems = new ArrayList<>();
photoItem.setProductType(ProductType.PHOTO_PRINT);
photoItem.setProductId(scenicId.toString());
photoItem.setQuantity(Long.valueOf(count).intValue());
photoItem.setPurchaseCount(1);
photoItem.setScenicId(scenicId.toString());
request.setProducts(Collections.singletonList(photoItem)); // 添加普通照片打印商品项 (sourceId > 0)
if (normalCount > 0) {
ProductItem normalPhotoItem = new ProductItem();
normalPhotoItem.setProductType(ProductType.PHOTO_PRINT);
normalPhotoItem.setProductId(scenicId.toString());
normalPhotoItem.setQuantity(Long.valueOf(normalCount).intValue());
normalPhotoItem.setPurchaseCount(1);
normalPhotoItem.setScenicId(scenicId.toString());
productItems.add(normalPhotoItem);
log.debug("普通照片打印数量: {}", normalCount);
}
// 添加手机照片打印商品项 (sourceId == null)
if (mobileCount > 0) {
ProductItem mobilePhotoItem = new ProductItem();
mobilePhotoItem.setProductType(ProductType.PHOTO_PRINT_MU);
mobilePhotoItem.setProductId(scenicId.toString());
mobilePhotoItem.setQuantity(Long.valueOf(mobileCount).intValue());
mobilePhotoItem.setPurchaseCount(1);
mobilePhotoItem.setScenicId(scenicId.toString());
productItems.add(mobilePhotoItem);
log.debug("手机照片打印数量: {}", mobileCount);
}
// 添加特效照片打印商品项 (sourceId == 0)
if (effectCount > 0) {
ProductItem effectPhotoItem = new ProductItem();
effectPhotoItem.setProductType(ProductType.PHOTO_PRINT_FX);
effectPhotoItem.setProductId(scenicId.toString());
effectPhotoItem.setQuantity(Long.valueOf(effectCount).intValue());
effectPhotoItem.setPurchaseCount(1);
effectPhotoItem.setScenicId(scenicId.toString());
productItems.add(effectPhotoItem);
log.debug("特效照片打印数量: {}", effectCount);
}
request.setProducts(productItems);
// 使用统一价格计算服务 // 使用统一价格计算服务
PriceCalculationResult result = priceCalculationService.calculatePrice(request); PriceCalculationResult result = priceCalculationService.calculatePrice(request);
@@ -505,8 +557,32 @@ public class PrinterServiceImpl implements PrinterService {
} }
// 验证照片数量 // 验证照片数量
List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId, faceId); List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId, faceId);
long count = userPhotoList.stream().filter(item -> Objects.nonNull(item.getQuantity())).mapToInt(MemberPrintResp::getQuantity).sum();
if (count == 0) { // 按照 sourceId 分类照片
// sourceId > 0: 普通照片打印 (PHOTO_PRINT)
// sourceId == null: 手机照片打印 (PHOTO_PRINT_MU)
// sourceId == 0: 特效照片打印 (PHOTO_PRINT_FX)
long normalCount = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() != null && item.getSourceId() > 0)
.mapToInt(MemberPrintResp::getQuantity)
.sum();
long mobileCount = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() == null)
.mapToInt(MemberPrintResp::getQuantity)
.sum();
long effectCount = userPhotoList.stream()
.filter(item -> Objects.nonNull(item.getQuantity())
&& item.getSourceId() != null && item.getSourceId() == 0)
.mapToInt(MemberPrintResp::getQuantity)
.sum();
long totalCount = normalCount + mobileCount + effectCount;
if (totalCount == 0) {
throw new BaseException("没有可打印的照片"); throw new BaseException("没有可打印的照片");
} }
@@ -536,15 +612,46 @@ public class PrinterServiceImpl implements PrinterService {
request.setUserId(memberId); request.setUserId(memberId);
request.setScenicId(scenicId); request.setScenicId(scenicId);
// 创建照片打印商品项 // 创建商品项列表
ProductItem photoItem = new ProductItem(); List<ProductItem> productItems = new ArrayList<>();
photoItem.setProductType(ProductType.PHOTO_PRINT);
photoItem.setProductId(scenicId.toString());
photoItem.setQuantity(Long.valueOf(count).intValue());
photoItem.setPurchaseCount(1);
photoItem.setScenicId(scenicId.toString());
request.setProducts(Collections.singletonList(photoItem)); // 添加普通照片打印商品项 (sourceId > 0)
if (normalCount > 0) {
ProductItem normalPhotoItem = new ProductItem();
normalPhotoItem.setProductType(ProductType.PHOTO_PRINT);
normalPhotoItem.setProductId(scenicId.toString());
normalPhotoItem.setQuantity(Long.valueOf(normalCount).intValue());
normalPhotoItem.setPurchaseCount(1);
normalPhotoItem.setScenicId(scenicId.toString());
productItems.add(normalPhotoItem);
log.debug("创建订单-普通照片打印数量: {}", normalCount);
}
// 添加手机照片打印商品项 (sourceId == null)
if (mobileCount > 0) {
ProductItem mobilePhotoItem = new ProductItem();
mobilePhotoItem.setProductType(ProductType.PHOTO_PRINT_MU);
mobilePhotoItem.setProductId(scenicId.toString());
mobilePhotoItem.setQuantity(Long.valueOf(mobileCount).intValue());
mobilePhotoItem.setPurchaseCount(1);
mobilePhotoItem.setScenicId(scenicId.toString());
productItems.add(mobilePhotoItem);
log.debug("创建订单-手机照片打印数量: {}", mobileCount);
}
// 添加特效照片打印商品项 (sourceId == 0)
if (effectCount > 0) {
ProductItem effectPhotoItem = new ProductItem();
effectPhotoItem.setProductType(ProductType.PHOTO_PRINT_FX);
effectPhotoItem.setProductId(scenicId.toString());
effectPhotoItem.setQuantity(Long.valueOf(effectCount).intValue());
effectPhotoItem.setPurchaseCount(1);
effectPhotoItem.setScenicId(scenicId.toString());
productItems.add(effectPhotoItem);
log.debug("创建订单-特效照片打印数量: {}", effectCount);
}
request.setProducts(productItems);
PriceCalculationResult priceResult = priceCalculationService.calculatePrice(request); PriceCalculationResult priceResult = priceCalculationService.calculatePrice(request);