新增彩印通成本

This commit is contained in:
2026-06-25 12:54:47 +08:00
parent 88d097f630
commit 79f0ae9e07
7 changed files with 996 additions and 1 deletions
@@ -379,6 +379,7 @@ public class ProductController {
}
product.setRole(user.getRole());
PricingStrategy pricingStrategy = PricingStrategyFactory.getStrategy(product.getProTypeValue());
assert pricingStrategy != null;
PricingListVo listvo = pricingStrategy.calculatePrice(product, user.getRole());
if (listvo.getCode() != 0) {
return Msg.fail(listvo.getMsg());
@@ -408,6 +409,52 @@ public class ProductController {
return Msg.success().add("proList", proList);
}
@RequestMapping("/getProductCastPrice")
public Msg getProductCastPrice(Product product, HttpServletRequest request) {
SysUser user = (SysUser) request.getSession().getAttribute("USER_SESSION");
if (StringUtils.isEmpty(product.getCount()) || product.getCount() <= 0) {
return Msg.fail("数量必须大于0");
}
String size = product.getSize();
if (!StringUtils.isEmpty(size)) {
product.setLength(Double.valueOf(size.substring(0, size.indexOf("*"))));
String other_size = size;
if (size.contains(",")) {
size = size.split(",")[0];
}
if (size.indexOf(("*"), size.indexOf("*") + 1) == -1) {
product.setWidth(Double.valueOf(size.substring(size.indexOf("*") + 1)));
} else {
product.setWidth(Double.valueOf(size.substring(size.indexOf("*") + 1, size.indexOf(("*"), size.indexOf("*") + 1))));
product.setLength(Math.abs(Double.parseDouble(size.substring(size.indexOf(("*"), size.indexOf("*") + 1) + 1))));
}
}
product.setRole(user.getRole());
PricingListVo listvo = priceService.getCostPrice(product);
if (listvo.getCode() != 0) {
return Msg.fail(listvo.getMsg());
}
List<ProductVo> proList = listvo.getProList();
if (proList == null || proList.size() == 0 || proList.get(0).getPrice() == 0) {
return Msg.fail("暂无报价");
}
if (listvo.getCode() != 0) {
return Msg.fail(listvo.getMsg());
}
proList = listvo.getProList();
// 把角色存入,前台判断,区分不同价格
for (ProductVo p : proList) {
p.setRole(user.getRole());
}
return Msg.success().add("proList", proList);
}
/*public List<Product> f_getPrice( int priceArr[], int count, String craftMo) {
List<Product> list = new ArrayList<Product>();
Product p = new Product();
@@ -3,6 +3,7 @@ package lingtao.net.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lingtao.net.bean.Product;
import lingtao.net.util.PriceUtils;
import lingtao.net.vo.PricingListVo;
import lingtao.net.vo.ProductVo;
import lingtao.net.vo.ProvidePrice;
@@ -10,6 +11,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
@@ -572,4 +574,223 @@ public class PriceService {
return new Province(province, city, district, detailAddress);
}
public PricingListVo getCostPrice(Product product) {
if (product.getProTypeValue() == null) {
return new PricingListVo(100, "暂无设置价格。");
}
if (!"彩印通".equals(product.getPlantName())) {
return new PricingListVo(100, "暂无设置价格。");
}
if ("彩印通".equals(product.getPlantName()) && "卡片".equals(product.getProTypeValue())) {
return getCYTCardPrice(product);
}
if ("彩印通".equals(product.getPlantName()) && "不干胶".equals(product.getProTypeValue())) {
return getCYTStickerPrice(product);
}
return null;
}
private PricingListVo getCYTStickerPrice(Product product) {
List<ProductVo> resultList = new ArrayList<>();
double width = product.getWidth();
double length = product.getLength();
int count = product.getCount();
int number = product.getNumber();
// 定义纸张尺寸(单位:毫米)
double paperLength = 287; // 纸张长度
double paperWidth = 406; // 纸张宽度
width = convertToMillimetersWithMargin(width, 2);
length = convertToMillimetersWithMargin(length, 2);
List<String> smallPaper = Arrays.asList("加厚铜版纸不干胶", "艾丽铜板不干胶", "特光不干胶", "铜板可移不干胶", "牛皮纸", "书写纸", "易碎纸", "大红洒金");
if (smallPaper.contains(product.getKind())) {
paperLength = 300; // 纸张长度
paperWidth = 420; // 纸张宽度
}
if (!isWithinPaperSize(width, length, paperLength, paperWidth)) {
return new PricingListVo(100, "超出纸张尺寸限制"); // 返回空列表表示不适用
}
double basePrice = 3;
if ("加厚铜版纸不干胶".equals(product.getKind())) {
basePrice = 2;
}
if ("黑胶铜版(遮盖/遮光)".equals(product.getKind())) {
basePrice = 4;
}
if ("牛皮纸".equals(product.getKind())) {
basePrice = 1.8;
}
if ("书写纸".equals(product.getKind())) {
basePrice = 1.8;
}
if ("易碎纸".equals(product.getKind())) {
basePrice = 4;
}
if ("洒金宣纸(白色)".equals(product.getKind())) {
basePrice = 4;
}
if ("超白浮雕纹".equals(product.getKind())) {
basePrice = 3.5;
}
if ("净白彩岩纹".equals(product.getKind())) {
basePrice = 3.5;
}
List<String> base_2 = Arrays.asList("艾丽铜板不干胶", "特光不干胶", "铜板可移不干胶", "大红洒金", "白布纹纸");
if (base_2.contains(product.getKind())) {
basePrice = 2.5;
}
basePrice = Math.max(2, basePrice);
// 计算一张纸能容纳的最大金属标数量
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
// 计算所需纸张数量
int requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
BigDecimal price = new BigDecimal(basePrice).multiply(new BigDecimal(requiredSheets)).setScale(2, RoundingMode.HALF_UP);
ProductVo pro = new ProductVo();
pro.setPrice(price.doubleValue());
pro.setCount(count);
pro.setNumber(number);
resultList.add(pro);
return new PricingListVo(resultList);
}
private PricingListVo getCYTCardPrice(Product product) {
List<ProductVo> resultList = new ArrayList<>();
double width = product.getWidth();
double length = product.getLength();
int count = product.getCount();
int number = product.getNumber();
// 定义纸张尺寸(单位:毫米)
double paperLength = 300; // 纸张长度
double paperWidth = 420; // 纸张宽度
width = convertToMillimetersWithMargin(width, 2);
length = convertToMillimetersWithMargin(length, 2);
if (!isWithinPaperSize(width, length, paperLength, paperWidth)) {
return new PricingListVo(100, "超出纸张尺寸限制"); // 返回空列表表示不适用
}
List<String> list = Arrays.asList("300克双铜纸", "300克单铜白卡", "300克冰白卡纸", "300克荷兰白卡", "300克水晶磨砂", "300克铂金磨砂", "300克米黄荷兰白", "300克雅典米白灵感纸", "300克米黄丝绵纸", "325克素面镭射卡白底", "330克超白草香纸", "350克雅柔纸", "350克冰白卡纸", "350克荷兰白卡", "350克布纹", "350克蛋壳纹", "350克安格纹", "350克刚古纹", "350克米黄刚古纹", "350克米黄冰白", "350克超白超感纸", "雅柔毯纹超白");
int[] counts = new int[]{0, 5, 10, 20, 25, 50};
double[] basePrices = new double[]{1.8, 9, 17, 34, 41.25, 82.5};
if ("300克单铜白卡".equals(product.getKind())) {
basePrices = new double[]{2, 10, 19, 38, 45, 90};
}
if ("300克冰白卡纸".equals(product.getKind())) {
basePrices = new double[]{2.5, 12.5, 24, 46, 55, 100};
}
if ("300克荷兰白卡".equals(product.getKind())) {
basePrices = new double[]{2.1, 10.5, 21, 40, 50, 90};
}
if ("300克水晶磨砂".equals(product.getKind())) {
basePrices = new double[]{5, 40, 47, 100, 107.5, 200};
}
if ("300克铂金磨砂".equals(product.getKind())) {
basePrices = new double[]{4.5, 22.5, 42, 80, 95, 175};
}
if ("300克米黄荷兰白".equals(product.getKind())) {
basePrices = new double[]{2.5, 12.5, 24, 46, 55, 100};
}
if ("300克雅典米白灵感纸".equals(product.getKind())) {
basePrices = new double[]{3, 15, 28, 52, 62.5, 115};
}
if ("300克米黄丝绵纸".equals(product.getKind())) {
basePrices = new double[]{3.5, 17.5, 34, 66, 80, 150};
}
if ("325克素面镭射卡白底".equals(product.getKind())) {
basePrices = new double[]{5, 25, 45, 86, 100, 190};
}
if ("330克超白草香纸".equals(product.getKind())) {
basePrices = new double[]{5, 25, 48, 90, 107.5, 200};
}
if ("350克雅柔纸".equals(product.getKind())) {
basePrices = new double[]{3, 15, 28, 54, 65, 125};
}
if ("350克米黄冰白".equals(product.getKind())) {
basePrices = new double[]{3, 15, 28, 54, 65, 125};
}
if ("雅柔毯纹超白".equals(product.getKind())) {
basePrices = new double[]{20, 38, 70, 82.5, 150};
}
List<String> list_100 = Arrays.asList("350克冰白卡纸", "350克荷兰白卡", "350克布纹", "350克蛋壳纹", "350克安格纹", "350克刚古纹", "350克米黄刚古纹", "350克超白超感纸");
if (list_100.contains(product.getKind())) {
basePrices = new double[]{2.5, 12.5, 24, 46, 55, 100};
}
// 计算一张纸能容纳的最大金属标数量
double maxItemsPerSheet = calculateMaxItemsPerSheet(length, width, paperLength, paperWidth);
// 计算所需纸张数量
int requiredSheets = calculateRequiredSheets(count, number, maxItemsPerSheet);
double basePrice = PriceUtils.TableCountDoublePrice(requiredSheets, basePrices, counts);
basePrice = Math.max(2.5, basePrice);
BigDecimal price = new BigDecimal(basePrice).multiply(new BigDecimal(requiredSheets)).setScale(2, RoundingMode.HALF_UP);
ProductVo pro = new ProductVo();
pro.setPrice(price.doubleValue());
pro.setCount(count);
pro.setNumber(number);
resultList.add(pro);
return new PricingListVo(resultList);
}
/**
* 将给定的尺寸转换为毫米,并在每边增加3毫米的边距
*
* @param size 需要转换的原始尺寸
* @return 转换后的尺寸,单位为毫米,包括边距
*/
private double convertToMillimetersWithMargin(double size, int num) {
return size * 10 + 2 * num; // 换成毫米,每边+2
}
/**
* 检查给定的长度和宽度是否在纸张尺寸范围内
*
* @param length 需要检查的长度
* @param width 需要检查的宽度
* @param paperLength 纸张的长度
* @param paperWidth 纸张的宽度
* @return 如果给定尺寸在纸张尺寸范围内,则返回true;否则返回false
*/
private boolean isWithinPaperSize(double length, double width, double paperLength, double paperWidth) {
return (length <= paperLength && width <= paperWidth) || (length <= paperWidth && width <= paperLength);
}
/**
* 计算每张纸最多可以容纳的物品数量
*
* @param length 物品的长度
* @param width 物品的宽度
* @param paperLength 纸张的长度
* @param paperWidth 纸张的宽度
* @return 每张纸最多可以容纳的物品数量
*/
private double calculateMaxItemsPerSheet(double length, double width, double paperLength, double paperWidth) {
return Math.max(
Math.floor(paperLength / length) * Math.floor(paperWidth / width),
Math.floor(paperLength / width) * Math.floor(paperWidth / length)
);
}
/**
* 计算完成指定数量的物品所需的纸张数量
*
* @param count 物品的总数量
* @param number 每个物品需要的数量
* @param maxItemsPerSheet 每张纸最多可以容纳的物品数量
* @return 完成指定数量的物品所需的纸张数量
*/
private int calculateRequiredSheets(int count, int number, double maxItemsPerSheet) {
return (int) Math.ceil((count * number) / maxItemsPerSheet);
}
}
@@ -4490,12 +4490,56 @@ public class ProductService {
case "躺椅":
priceList = getDeckCharitPrice(dto, width, length);
return chucklePrice(role, priceList, dto);
case "钥匙扣":
priceList = getKeychain(dto, width, length);
return chucklePrice(role, priceList, dto);
default:
break;
}
return null;
}
private List<Product> getKeychain(Product dto, Double width, Double length) {
List<String> carft_list = dto.getCraft() == null ? new ArrayList<>() : Arrays.asList(dto.getCraft());
List<Product> priceList = new ArrayList<>();
int count = dto.getCount();
int number = dto.getNumber();
double price = 0;
double min_price = 35;
if (width * length / 10000 < 0.001) {
double basePrice = 1;
price = basePrice * count * dto.getNumber();
} else {
double area = width * length / 10000 * count * dto.getNumber();
double[] areas = {0, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 1, 2, 3, 5, 7, 9, 10, 20, 50};
int[] prices = {0, 1100, 1000, 950, 900, 850, 800, 750, 700, 650, 600, 550, 500, 480, 470, 460};
if ("4".equals(dto.getKindValue())) {
prices = new int[]{0, 1130, 1030, 980, 930, 880, 830, 780, 730, 680, 630, 580, 530, 510, 500, 490};
}
double last_price = 450;
price = PriceUtils.TableUnitPrice(area, prices, areas, last_price);
price = Math.max(price, min_price) + ((dto.getNumber() - 1) * 8);
}
double craft_price = 0;
if (!StringUtils.isEmpty(dto.getBianma())) {
double craft_base = 0.1;
if ("圆型钥匙扣银色".equals(dto.getBianma()) || "珠链银色".equals(dto.getBianma())) {
craft_base = 0;
}
craft_price = Math.ceil(craft_base * count * dto.getNumber());
}
String weight = df.format(width * length * 4.17 * dto.getCount() * 0.1 * number / 1000 * 2);
Product pro = new Product();
pro.setCount(dto.getCount());
pro.setNumber(dto.getNumber());
pro.setWeight(weight);
pro.setPrice(Math.ceil(price + craft_price));
priceList.add(pro);
return priceList;
}
private List<Product> getDeckCharitPrice(Product dto, Double width, Double length) {
List<String> craft_lists = dto.getCraft() == null ? new ArrayList<>() : Arrays.asList(dto.getCraft());
List<String> craft_list = new ArrayList<>(craft_lists);
@@ -3739,6 +3739,26 @@ public class PriceUtils {
return price;
}
public static double TableCountDoublePrice(double area, double[] price_list, int[] areas) {
double price = 0;
int startIndex = 0;
int endIndex = 0;
for (int i = 0; i < areas.length; i++) {
if (area > areas[i]) {
startIndex = endIndex;
endIndex = Math.min(i + 1, areas.length - 1);
}
}
if (startIndex == endIndex && startIndex == 0) {
price = price_list[endIndex];
} else if (startIndex == endIndex) {
price = (price_list[endIndex]);
} else {
price = ((areas[endIndex] - area) / (areas[endIndex] - areas[startIndex])) * price_list[startIndex] + ((area - areas[startIndex]) / (areas[endIndex] - areas[startIndex])) * price_list[endIndex];
}
return price;
}
public static double TableUnitPrice(double area, int[] price_list, double[] areas, double last_price) {
double price = 0;
int startIndex = 0;