package com.quoted.system.utils; import com.quoted.system.domain.vo.ProductPriceDto; import com.quoted.system.domain.vo.ProductPriceRequestVo; import java.util.ArrayList; import java.util.List; public class StickerUtils { public static List getPrice(ProductPriceRequestVo product) { List list = new ArrayList<>(); Double length = product.getLength(); Double width = product.getWidth(); Integer count = product.getCount(); Integer number = product.getNumber(); List craft_list = PriceCommonUtils.getCraftList(product); double area = length * width / 10000; switch (product.getMaterial()) { case "铜板纸不干胶": // 带1厘米的尺寸,都变成2 if (1 < length && length < 2) { length = Math.ceil(length); } if (1 < width && width < 2) { width = Math.ceil(width); } // 小数部分,四舍五入 length = (double) Math.round(length); width = (double) Math.round(width); // 尺寸小数部分四舍五入后的面积 double roundArea = length * width / 10000; // 一个名片位内做特价:75折,价格在前端写死 double[] priceArr = null; int[] counts = {500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000, 50000}; double[] areas = {0.004, 0.006, 0.008, 0.01, 0.012, 0.015, 0.017, 0.018, 0.02, 0.03, 0.04, 0.06, 0.1, 0.2, 0.3}; //覆膜是否要加价 boolean isMo = true; int MaxCount = 0; if (width < 21 && length < 21) { if (length == 1 && width == 1) { priceArr = new double[]{30, 35, 50, 55, 100, 180, 270, 370, 470, 570}; } else if ((length == 2 && width == 1) || (length == 1 && width == 2)) { priceArr = new double[]{35, 40, 55, 60, 110, 190, 280, 380, 480, 580}; } else if ((length > 2 && length <= 5 && width == 1) || (width > 2 && width <= 5 && length == 1)) { priceArr = new double[]{35, 40, 55, 70, 120, 210, 308, 435, 555, 683}; } else if ((length > 1 && length <= 3 && width == 2) || (width > 1 && width <= 3 && length == 2)) { priceArr = new double[]{35, 40, 55, 70, 120, 210, 308, 435, 555, 683}; } else if ((length > 3 && length <= 5 && width == 2) || (width > 3 && width <= 5 && length == 2)) { priceArr = new double[]{35, 40, 55, 70, 120, 220, 348, 492, 642, 798}; } else if ((length >= 3 && length <= 5 && width == 3) || (length == 3 && width <= 5 && width >= 3)) { priceArr = new double[]{35, 40, 55, 70, 120, 220, 348, 492, 642, 798}; } else if (length == 4 && width == 4) { priceArr = new double[]{35, 40, 55, 70, 120, 220, 348, 492, 642, 798}; } else if ((length == 5 && width == 4) || (length == 4 && width == 5)) { priceArr = new double[]{35, 40, 55, 70, 150, 240, 420, 600, 790, 980}; } else if (((length <= 9 && width <= 5.4) || (length <= 5.4 && width <= 9))) { counts = new int[]{500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000}; priceArr = new double[]{60, 70, 95, 125, 175, 270, 510, 800, 1000, 1200, 1400, 1600, 1800, 2000, 2200}; isMo = false; } else if (area <= 0.003) { counts = new int[]{500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000}; priceArr = new double[]{65, 75, 100, 130, 180, 275, 515, 805, 1005, 1205, 1405, 1605, 1805, 2005, 2205}; isMo = false; if (count >= 40000) { MaxCount = 40000; } } else { list = getManyAreaPrice(count, area, areas); break; } } else { if ((length == 1 && width <= 48) || (width == 1 && length <= 48)) { counts = new int[]{500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000}; priceArr = new double[]{90, 100, 160, 190, 230, 420, 760, 1100, 1400}; isMo = false; if (count >= 40000) { MaxCount = 40000; } } else if ((length == 1 && width <= 60) || (width == 1 && length <= 60)) { counts = new int[]{500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000}; priceArr = new double[]{100, 120, 180, 230, 300, 550, 960, 1300, 1600}; isMo = false; if (count >= 40000) { MaxCount = 40000; } } else if ((length == 1 && width <= 70) || (width == 1 && length <= 70)) { counts = new int[]{500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000}; priceArr = new double[]{110, 130, 200, 270, 330, 580, 1100, 1500, 1900}; isMo = false; if (count >= 40000) { MaxCount = 40000; } } else if ((length == 1 && width <= 80) || (width == 1 && length <= 80)) { counts = new int[]{500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000}; priceArr = new double[]{130, 150, 240, 300, 380, 650, 1200, 1650, 2100}; isMo = false; if (count >= 40000) { MaxCount = 40000; } } else if ((length == 1 && width <= 90) || (width == 1 && length <= 90)) { counts = new int[]{500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000}; priceArr = new double[]{150, 170, 245, 320, 420, 750, 1300, 1750, 2200}; isMo = false; if (count >= 40000) { MaxCount = 40000; } } else if ((length == 1 && width <= 100) || (width == 1 && length <= 100)) { counts = new int[]{500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000}; priceArr = new double[]{170, 200, 260, 350, 480, 860, 1400, 2000, 2600}; isMo = false; if (count >= 40000) { MaxCount = 40000; } } else { list = getManyAreaPrice(count, area, areas); break; } } ProductPriceDto pro = null; if (MaxCount == 0) { for (int i = 0; i < counts.length; i++) { if (counts[i] < count || list.size() > 3) { continue; } pro = new ProductPriceDto(); pro.setCount(counts[i]); double price = priceArr[i]; if (craft_list.contains("覆哑膜") && isMo) { price = Math.ceil(price * 1.2); } pro.setPrice(price); list.add(pro); } } else { pro = new ProductPriceDto(); pro.setCount(count); double price = Math.ceil((Math.ceil(count / 10000.0) - 4) * 150 + 720); pro.setPrice(price); list.add(pro); } break; case "pvc不干胶": case "透明不干胶": if (width < 21 && length < 21) { if ((length <= 9 && width > 5 && width <= 5.4) || (width <= 9 && length > 5 && length <= 5.4)) { width = (Math.floor(width)); length = (Math.floor(length)); } else { // 小数向上取整 width = (Math.ceil(width)); length = (Math.ceil(length)); } if (count <= 10000) { areas = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; counts = new int[]{500, 1000, 2000, 3000, 5000, 10000}; double[][] areas_price = { {90, 90, 90, 90, 90, 90, 90, 90, 90, 100, 120, 120, 130, 130, 140, 150, 150, 160, 160, 180}, {120, 120, 110, 120, 120, 110, 110, 110, 120, 120, 140, 140, 150, 150, 160, 180, 180, 200, 200, 200}, {190, 190, 190, 190, 190, 180, 180, 180, 200, 230, 260, 260, 260, 260, 280, 280, 280, 280, 300, 300}, {220, 220, 220, 220, 220, 220, 220, 240, 240, 270, 270, 270, 290, 290, 290, 290, 320, 320, 340, 340}, {350, 350, 350, 350, 350, 330, 360, 380, 400, 410, 420, 440, 460, 480, 500, 520, 540, 560, 600, 650}, {510, 510, 510, 510, 510, 580, 530, 600, 700, 780, 800, 840, 880, 920, 940, 960, 980, 1000, 1020, 1050}, }; list = getAreasPrice(count, area, areas_price, counts, areas); break; } else { // 1*1,2*1 价格调整成和3*1一致 if (area < 0.0003) { area = 0.0003; } } } counts = new int[]{500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000}; if (area <= 0.0004) { priceArr = new double[]{450.0, 300.0, 238.0, 184.0, 175.0, 158.0, 87.0, 70.0, 65.0, 59.0, 52.0, 48.0, 45.0, 42.0, 39.0, 36.0}; } else if (area <= 0.0006) { priceArr = new double[]{300.0, 200.0, 158.0, 122.0, 117.0, 85.0, 60.0, 50.0, 45.0, 40.0, 38.0, 37.0, 36.0, 35.0, 33.0, 32.0}; } else if (area <= 0.0008) { priceArr = new double[]{260.0, 171.0, 135.0, 105.0, 100.0, 73.0, 51.0, 45.0, 39.0, 33.0, 32.0, 31.0, 30.0, 29.0, 28.0, 27.0}; } else if (area <= 0.001) { priceArr = new double[]{200.0, 133.0, 105.0, 82.0, 78.0, 56.0, 42.0, 33.0, 28.0, 27.0, 26.0, 25.0, 24.0, 23.0, 22.0, 21.0}; } else if (area <= 0.0012) { priceArr = new double[]{150.0, 92.0, 75.0, 62.0, 55.0, 48.0, 35.0, 29.0, 24.0, 23.0, 22.0, 21.0, 20.0, 19.0, 18.0, 17.0}; } else if (area <= 0.0014) { priceArr = new double[]{138.0, 85.0, 70.0, 62.0, 54.0, 43.0, 31.0, 26.0, 22.0, 21.0, 20.0, 19.0, 18.0, 17.0, 16.0, 15.0}; } else if (area <= 0.0016) { priceArr = new double[]{120.0, 80.0, 67.0, 54.0, 51.0, 43.0, 29.0, 23.0, 19.0, 19.0, 19.0, 18.0, 17.0, 16.0, 15.0, 15.0}; } else if (area <= 0.0025) { priceArr = new double[]{118.0, 76.0, 68.0, 51.0, 48.0, 39.0, 20.0, 19.0, 18.0, 17.0, 16.0, 15.0, 14.0, 13.0, 13.0, 13.0}; } else if (area <= 0.0035) { priceArr = new double[]{62.5, 60.0, 63.0, 47.0, 46.0, 38.0, 18.0, 18.0, 18.0, 16.0, 16.0, 15.0, 14.0, 13.0, 12.0, 12.0}; } else if (area <= 0.0045) { priceArr = new double[]{84.0, 50.0, 44.0, 33.0, 25.0, 19.0, 15.0, 14.0, 14.0, 14.0, 13.0, 13.0, 12.0, 12.0, 12.0, 12.0}; } else if (area <= 0.0084) { priceArr = new double[]{56.0, 35.0, 29.0, 26.0, 19.0, 16.0, 15.0, 14.0, 14.0, 13.0, 12.0, 12.0, 12.0, 12.0, 12.0, 12.0}; } else if (area <= 0.012) { priceArr = new double[]{42.0, 26.0, 23.0, 18.0, 14.0, 12.0, 14.0, 13.0, 13.0, 12.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0}; } else if (area <= 0.015) { priceArr = new double[]{36.0, 25.0, 22.0, 17.0, 15.0, 13.0, 13.0, 12.0, 12.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0}; } else if (area <= 0.02) { priceArr = new double[]{35.0, 24.0, 21.0, 17.0, 15.0, 13.0, 13.0, 12.0, 12.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0}; } else if (area <= 0.06) { priceArr = new double[]{32.0, 23.0, 21.0, 17.0, 15.0, 13.0, 13.0, 12.0, 12.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0}; } else if (area <= 0.1) { priceArr = new double[]{30.0, 20.0, 15.0, 13.0, 13.0, 13.0, 13.0, 12.0, 12.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0}; } else if (area <= 0.2) { priceArr = new double[]{17.0, 14.0, 13.0, 12.0, 12.0, 12.0, 12.0, 11.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0}; } else { priceArr = new double[]{15.0, 13.0, 12.0, 12.0, 11.0, 11.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0}; } list = bigSizeAccountPrice(count, area, priceArr, counts); break; default: break; } return list; } private static List getManyAreaPrice(int count, double area, double[] areas) { List list = new ArrayList<>(); int[] counts = new int[]{500, 1000, 2000, 3000, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000}; double[][] areas_price = { {37, 33, 30, 26, 25, 21, 19, 18, 17, 19, 17, 12.8, 12.5, 12, 11.5, 11}, {21, 19, 17, 17, 15, 14, 14, 12, 12, 12.5, 13, 9, 9, 8, 8, 7.8}, {14, 13, 13, 12, 11, 11, 10, 10, 9, 10, 11, 7.8, 7.5, 7.5, 7.2, 7}, {12, 11, 11, 10, 9, 9.5, 9, 8, 8, 9, 10, 6.8, 6.5, 6.5, 6, 6.5}, {10, 9.5, 8, 7.8, 8.5, 9, 8.3, 7, 8, 6.5, 8, 6, 6, 6, 5.5, 5}, {8, 7.5, 6.5, 6.5, 7.6, 8, 7.3, 6, 7.5, 6, 6, 6, 6, 6, 5, 5}, {7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5}, {7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5}, {7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5}, {7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5}, {7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5}, {7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5}, {7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5}, {7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5}, {7.6, 6.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5, 4.5}, }; double basePrice = 0; if (area <= 0.004) { basePrice = 7.5; } else if (area <= 0.006) { basePrice = 6.5; } else if (area <= 0.2) { basePrice = 5.5; } else if (area <= 0.3) { basePrice = 5; } else if (area > 0.3) { basePrice = 4.5; } ProductPriceDto pro = new ProductPriceDto(); if (count > counts[counts.length - 1]) { pro.setCount(count); pro.setPrice(Math.ceil(area * count * basePrice)); list.add(pro); } else { for (int i = 0; i < counts.length; i++) { if (counts[i] < count || list.size() > 3) { continue; } double price = getPriceInArea(counts[i], area, areas, areas_price[i]); pro = new ProductPriceDto(); pro.setCount(counts[i]); pro.setPrice(Math.ceil(price)); list.add(pro); } } return list; } private static List getAreasPrice(int count, double area, double[][] areas_price, int[] counts, double[] areas) { List list = new ArrayList<>(); ProductPriceDto pro = new ProductPriceDto(); int areaIndex = 0; for (int i = 0; i < areas.length; i++) { if (area < areas[i]) { break; } areaIndex = i; } for (int i = 0; i < counts.length; i++) { if (counts[i] < count) { continue; } double[] priceArr = areas_price[i]; pro = new ProductPriceDto(); pro.setCount(counts[i]); pro.setPrice(priceArr[areaIndex]); list.add(pro); } return list; } private static List bigSizeAccountPrice(int count, Double area, double[] priceArr, int[] bigCountArr) { List list = new ArrayList<>(); ProductPriceDto pro = new ProductPriceDto(); if (count > bigCountArr[bigCountArr.length - 1]) { pro.setCount(count); pro.setPrice(Math.ceil(area * count * priceArr[bigCountArr.length - 1])); list.add(pro); } for (int i = 0; i < bigCountArr.length; i++) { if (bigCountArr[i] < count) { continue; } pro = new ProductPriceDto(); pro.setCount(bigCountArr[i]); pro.setPrice(Math.ceil(area * bigCountArr[i] * priceArr[i])); list.add(pro); } return list; } // 判断小尺寸是否大于大尺寸价格 private static double getPriceInArea(int count, Double area, double[] priceArr, double[] areas) { double lastPrice = 0, price = 0; if (area > areas[areas.length - 1]) { price = area * count * priceArr[areas.length - 1]; lastPrice = area * count * priceArr[areas.length - 2]; if (lastPrice > price) { price = lastPrice; } } for (int i = 0; i < areas.length; i++) { if (areas[i] < area) { continue; } double lastArea = 0; if (i > 0) { lastArea = areas[i - 1]; lastPrice = lastArea * count * priceArr[i - 1]; } price = area * count * priceArr[i]; if (lastPrice > price) { price = lastPrice; } break; } return price; } }