package com.caimei.modules.order.utils; import com.caimei.modules.order.entity.NewOrder; import com.caimei.modules.order.entity.NewOrderProduct; import com.caimei.modules.order.entity.NewShopOrder; import com.caimei.modules.product.entity.CmPromotion; import java.util.*; public class OrderUtil { /** * 获取主订单下的所有商品 * * @param newOrder * @return */ public static List getOrderProducts(NewOrder newOrder) { List orderProducts = new ArrayList<>(); List shopOrders = newOrder.getNewShopOrders(); if (newOrder != null && shopOrders != null) { for (NewShopOrder so : shopOrders) { orderProducts.addAll(so.getNewOrderProducts()); } } return orderProducts; } /** * 主订单拆分 * * @param order */ public static void orderSplit(NewOrder order) { int shopOrderNoIndex = 0; List orderProducts = order.getOrderProduct(); // 促销 List promotionsList = order.getPromotions(); List newShopOrders = new ArrayList<>(); Map map = new HashMap<>(); // 把订单中的商品根据供应商不同进行分组,生成子订单 for (NewOrderProduct o : orderProducts) { //子订单存在了 追加orderProduct 到 shopOrder if (map.containsKey(o.getShopID())) { NewShopOrder shopOrder = map.get(o.getShopID()); shopOrder.getNewOrderProducts().add(o); shopOrder.setItemCount(o.getNum() + shopOrder.getItemCount()); // 子订单下商品数量统计 购买数量 shopOrder.setPresentNum(o.getPresentNum() + shopOrder.getPresentNum()); shopOrder.setPreferential(shopOrder.getPreferential() + o.getPreferential()); // 优惠金额 shopOrder.setProductAmount(shopOrder.getProductAmount() + o.getTotalAmount()); // 商品总金额 shopOrder.setDiscountFee(shopOrder.getDiscountFee() + o.getDiscountFee()); //经理折扣统计 shopOrder.setTotalAmount(shopOrder.getTotalAmount() + o.getTotalFee()); shopOrder.setNeedPayAmount(shopOrder.getNeedPayAmount() + o.getShouldPayFee()); shopOrder.setTotalAddedValueTax(shopOrder.getTotalAddedValueTax() + o.getTotalAddedValueTax()); //税费 shopOrder.setBrokerage(shopOrder.getBrokerage() + o.getCmFee()); //佣金 = 应付采美 } else { // 子订单如果不存在 实例化shopOrder NewShopOrder shopOrder = new NewShopOrder(); shopOrder.setDelFlag("0"); shopOrder.setClubID(order.getClubID()); shopOrder.setCanRefundAmount(0D); shopOrder.setRefundAmount(0D); shopOrder.setAccountAmount(0D); shopOrder.setAutoOverTimeMills(0L); shopOrder.setAutoReceiveTimeMills(0L); shopOrder.setPayFlag("0"); shopOrder.setPayStatus("1"); shopOrder.setZeroCostFlag(0); shopOrder.setSplitFlag("1"); //订单默认可拆分 shopOrder.setOrderTime(order.getOrderTime()); shopOrder.setShopOrderNo(getshopOrderNo(order.getOrderNo(), ++shopOrderNoIndex)); shopOrder.setShopID(o.getShopID()); shopOrder.setItemCount(o.getNum()); shopOrder.setSendOutStatus("1"); shopOrder.setOrderSubmitType(4); shopOrder.setFee(null); // 赠品单独列出了 shopOrder.setPresentNum(0); shopOrder.setProductAmount(o.getTotalAmount()); shopOrder.setDiscountFee(o.getDiscountFee()); shopOrder.setTotalAmount(o.getTotalFee()); shopOrder.setPreferential(o.getPreferential()); shopOrder.setTotalAddedValueTax(o.getTotalAddedValueTax()); List newOrderProducts = new ArrayList<>(); // 实例化订单商品集合 newOrderProducts.add(o); shopOrder.setNewOrderProducts(newOrderProducts); shopOrder.setBrokerage(o.getCmFee()); shopOrder.setDiscountAmount((o.getPrice() - o.getDiscountPrice()) * o.getNum()); shopOrder.setTotalAmount(o.getTotalFee()); shopOrder.setNeedPayAmount(o.getShouldPayFee()); shopOrder.setOutStoreNum(0); map.put(o.getShopID(), shopOrder); newShopOrders.add(shopOrder); //在主订单中保存子订单的引用 } } order.setNewShopOrders(newShopOrders); } /** * 根据 orderProducts里面的orderProduct 信息重新统计 shopOrder */ public static void updateShopOrderInfo(NewShopOrder shopOrder, List orderProducts, List promotionsList) { if (orderProducts == null || orderProducts.size() == 0) return; int itemCount = 0; //商品数量统计 (不含赠品) double productAmount = 0D;// 商品总金额 = 总价 double discountAmount = 0D; //折扣金额 double totalAmount = 0D; //总价 = 商品总金额 double needPayAmount = 0D; // 需要支付金额 = 总金额 - 采美豆 - 余额 - 折扣-其它 double preferential = 0D; int presentNum = 0; double totalAddedValueTax = 0D; int outStoreNum = 0; //未出库数量 double discountFee = 0D; //经理折扣 String shopOrderNo = null; Integer shopID = null; double brokerage = 0D;//佣金 Double shopProductAmount = 0D; //商品费 Double shopTaxFee = 0D; //付给供应商税费 double promotionsTouchPrice = 0d; double promotionsReducedPrice = 0d; double shopTouchPrice = 0d; double shopReducedPrice = 0d; double productDiscount = 0d; for (NewOrderProduct o : orderProducts) { // 没有折扣时促销才生效 if (o.getDiscount() == 100d) { for (CmPromotion promotion : promotionsList) { if ("3".equals(promotion.getType())) { shopOrder.setOrderPromotionsId(o.getOrderPromotionsId()); if ("2".equals(promotion.getMode())) { promotionsTouchPrice = promotion.getTouchPrice(); promotionsReducedPrice = promotion.getReducedPrice(); shopTouchPrice += (o.getNum() * o.getPrice()); } } // 单品 if ("1".equals(promotion.getType())) { // 优惠价 if ("1".equals(promotion.getMode())) { shopReducedPrice += (o.getPrice() - promotion.getTouchPrice()) * o.getNum(); productDiscount += (o.getPrice() - promotion.getTouchPrice()) * o.getNum(); } // 单品满减 if ("2".equals(promotion.getMode())) { if (o.getPrice() * o.getNum() > promotion.getTouchPrice()) { shopReducedPrice += promotion.getReducedPrice(); } } } } } if (shopOrderNo == null) shopOrderNo = o.getShopOrderNo(); if (shopID == null) shopID = o.getShopID(); itemCount += (o.getNum() == null ? 0 : o.getNum()); totalAddedValueTax += (o.getTotalAddedValueTax() == null ? 0D : o.getTotalAddedValueTax()); //(这前单价 - 折后单间) * 数量(含赠品) = 折扣金额 discountAmount += (o.getDiscountFee() == null ? 0D : o.getDiscountFee()); productAmount += (o.getTotalAmount() == null ? 0D : o.getTotalAmount()); totalAmount += (o.getTotalFee() == null ? 0D : o.getTotalFee()); needPayAmount += (o.getShouldPayFee() == null ? 0D : o.getShouldPayFee()); preferential += (o.getPreferential() == null ? 0D : o.getPreferential()); presentNum += (o.getPresentNum() == null ? 0 : o.getPresentNum()); outStoreNum += o.getNum() - (o.getNotOutStore() == null ? 0 : o.getNotOutStore()); discountFee += (o.getDiscountFee() == null ? 0D : o.getDiscountFee()); brokerage += (o.getCmFee() == null ? 0D : o.getCmFee()); shopProductAmount += (o.getShopProductAmount() == null ? 0D : o.getShopProductAmount()); shopTaxFee += (o.getShouldPayTotalTax() == null ? 0D : o.getShouldPayTotalTax()); } if (shopTouchPrice > promotionsTouchPrice) { shopReducedPrice += promotionsReducedPrice; } shopOrder.setPromotionFullReduction(shopReducedPrice); shopOrder.setNeedPayAmount(needPayAmount - shopReducedPrice + productDiscount); shopOrder.setTotalAddedValueTax(totalAddedValueTax); shopOrder.setItemCount(itemCount); shopOrder.setProductAmount(productAmount); shopOrder.setDiscountAmount(discountAmount); shopOrder.setTotalAmount(totalAmount); shopOrder.setShopOrderNo(shopOrderNo); shopOrder.setPreferential(preferential); shopOrder.setPresentNum(presentNum); shopOrder.setShopID(shopID); shopOrder.setOutStoreNum(outStoreNum); shopOrder.setDiscountFee(discountFee); shopOrder.setBrokerage(brokerage); shopOrder.setShopProductAmount(shopProductAmount); shopOrder.setShopPostFee(0D); shopOrder.setShopTaxFee(shopTaxFee); shopOrder.setShouldPayShopAmount(shopProductAmount + shopTaxFee); shopOrder.setPayedShopAmount(0D); shopOrder.setShopOtherFee(0D); if (presentNum == 0 && itemCount == 0) shopOrder.setDelFlag("1");// 这个子订单里面的商品全部被拆分走了 这个子订单就没有意义了 } /** * 根据父订单单号 以及子订单的序列生成子订单编号 * * @param orderNo * @param i * @return */ public static String getshopOrderNo(String orderNo, int i) { if (i < 10) { return orderNo + "0" + i; } else { return orderNo + i; } } /** * 订单模块生成新订单号 * * @param platform * @return */ public static String getCmOrderNo(String platform) { Random rand = new Random(); String code = ""; for (int j = 0; j < 5; j++) { code += rand.nextInt(10) + ""; } return platform + System.currentTimeMillis() / 1000 + code; } public static String geneCrmOrderNo() { return getCmOrderNo("C"); } public static String geneWwwOrderNo() { return getCmOrderNo("W"); } public static String geneAdminOrderNo() { return getCmOrderNo("P"); } public static void main(String[] args) { System.out.println(geneWwwOrderNo()); } public static Boolean isBuFenShouKuan(String code) { Boolean res = false; res = NewOrderStatus.isBuFenShouKuan(code); return res; } public static String getPayTypeStr(String payType) { // 1建设银行7297、2广发银行0115、3中信银行7172、4中信银行0897、5中信银行0897-财付通、 // 6中信银行0897-支付宝、7线上-支付宝、8线上-微信支付、9线上-快钱支付,10口头返佣', if ("1".equals(payType)) { return "建设银行7297"; } if ("2".equals(payType)) { return "广发银行0115"; } if ("3".equals(payType)) { return "中信银行7172"; } if ("4".equals(payType)) { return "中信银行0897"; } if ("5".equals(payType)) { return "中信银行0897-财付通"; } if ("6".equals(payType)) { return "中信银行0897-支付宝"; } if ("7".equals(payType)) { return "线上-支付宝"; } if ("8".equals(payType)) { return "线上-微信支付"; } if ("9".equals(payType)) { return "线上-快钱支付"; } if ("10".equals(payType)) { return "口头返佣"; } if ("11".equals(payType)) { return "广发银行5461"; } if ("12".equals(payType)) { return "企业网银"; } if ("13".equals(payType)) { return "PC-微信支付"; } if ("14".equals(payType)) { return "PC-支付宝"; } if ("15".equals(payType)) { return "小程序-微信支付"; } if ("16".equals(payType)) { return "余额抵扣"; } if ("17".equals(payType)) { return "个人网银"; } if ("18".equals(payType)) { return "建设银行1854"; } return ""; } /** * @return * @Author ye.qin * @Description //TODO 获取付款类型 * @Date 2019\8\9 0009 10:35 * @Param */ public static String getPayType(String payType) { // 1建设银行7297, 2中信银行0897, 3中信银行7172, 4广发银行0115, 5广发银行5461 if ("1".equals(payType)) return "建设银行7297"; if ("2".equals(payType)) return "中信银行0897"; if ("3".equals(payType)) return "中信银行7172"; if ("4".equals(payType)) return "广发银行0115"; if ("5".equals(payType)) return "广发银行5461"; return payType; } public static String getReceiptType(String receiptType) { if ("1".equals(receiptType)) return "订单"; if ("2".equals(receiptType)) return "非订单"; if ("3".equals(receiptType)) return "返佣"; return ""; } public static String getReceiptStatus(String receiptStatus) { if ("1".equals(receiptStatus)) return "待确认"; if ("2".equals(receiptStatus)) return "已确认"; if ("3".equals(receiptStatus)) return "审核通过"; if ("4".equals(receiptStatus)) return "审核未通过"; if ("5".equals(receiptStatus)) return "收款撤销"; return ""; } public static String getStatus(String status) { if ("0".equals(status)) return "待确认"; if ("11".equals(status)) return "待收款待发货"; if ("12".equals(status)) return "待收款部分发货"; if ("13".equals(status)) return "待收款全发货"; if ("21".equals(status)) return "部分收款待发货"; if ("22".equals(status)) return "部分收款部分发货"; if ("23".equals(status)) return "部分收款全部发货"; if ("31".equals(status)) return "已收款待发货"; if ("32".equals(status)) return "已收款部分发货"; if ("33".equals(status)) return "已收款全发货"; if ("4".equals(status)) return "交易完成"; if ("5".equals(status)) return "订单完成"; if ("6".equals(status)) return "已关闭"; if ("7".equals(status)) return "交易全退"; return ""; } }