浏览代码

产品/仪器页面数据

chao 4 年之前
父节点
当前提交
ccc13a7112

+ 225 - 0
src/main/java/com/caimei365/commodity/components/PriceUtilService.java

@@ -0,0 +1,225 @@
+package com.caimei365.commodity.components;
+
+
+import com.caimei365.commodity.mapper.PriceMapper;
+import com.caimei365.commodity.mapper.PromotionsMapper;
+import com.caimei365.commodity.model.vo.*;
+import com.caimei365.commodity.utils.MathUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.stream.IntStream;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2020/6/22
+ */
+@Slf4j
+@Service
+public class PriceUtilService {
+    @Resource
+    private PriceMapper priceMapper;
+    @Resource
+    private PromotionsMapper promotionsMapper;
+    /**
+     * 根据价格返回价格等级
+     * @param price 价格
+     * @return priceGrade 价格等级
+     */
+    public Integer getPriceGrade(Double price){
+        int grade = 1;
+        if (price > 50 * 10000) {
+            grade = 5;
+        } else if (price > 25 * 10000) {
+            grade = 4;
+        } else if (price > 10 * 10000) {
+            grade = 3;
+        } else if (price > 2.5 * 10000) {
+            grade = 2;
+        }
+        return grade;
+    }
+
+    /**
+     * 设置阶梯价展示数据
+     * @param ladderPrices  List<LadderPriceVo>
+     * @param tax           TaxVo
+     */
+    public void setLadderPriceList(List<LadderPriceVo> ladderPrices, TaxVo tax) {
+        IntStream.range(0, ladderPrices.size()).forEach(i -> {
+            //税费标志
+            boolean taxFlag = "0".equals(tax.getIncludedTax()) && ("1".equals(tax.getInvoiceType()) || "2".equals(tax.getInvoiceType()));
+            //添加税费
+            if (taxFlag) {
+                BigDecimal taxFee = MathUtil.div(MathUtil.mul(ladderPrices.get(i).getBuyPrice(), tax.getTaxPoint()), 100);
+                ladderPrices.get(i).setBuyPrice(MathUtil.add(ladderPrices.get(i).getBuyPrice(),taxFee).doubleValue());
+            }
+            if (i == ladderPrices.size() - 1) {
+                ladderPrices.get(i).setMaxNum(0);
+                ladderPrices.get(i).setNumRange("≥" + ladderPrices.get(i).getBuyNum());
+            } else {
+                ladderPrices.get(i).setMaxNum(ladderPrices.get(i + 1).getBuyNum());
+                String buyNumRangeShow = ladderPrices.get(i).getBuyNum() + "~" + (ladderPrices.get(i + 1).getBuyNum() - 1);
+                ladderPrices.get(i).setNumRange(buyNumRangeShow);
+            }
+        });
+    }
+
+    /**
+     * 根据用户id设置详细价格
+     *
+     * @param price 商品价格类
+     * @param userId 用户Id
+     */
+    public void setPriceByUserId(PriceVo price, Integer userId) {
+        // 根据用户Id查询用户身份
+        Integer identity = priceMapper.getIdentityByUserId(userId);
+        if (null != identity && identity > 0) {
+            // 用户身份: 2-会员机构, 4-普通机构
+            price.setUserIdentity(identity);
+            // 默认非促销活动状态
+            price.setActStatus(0);
+            // 设置划线价
+            price.setOriginalPrice(price.getPrice());
+            //税费标志
+            boolean taxFlag = "0".equals(price.getIncludedTax()) && ("1".equals(price.getInvoiceType()) || "2".equals(price.getInvoiceType()));
+            // 根据商品id查询商品活动
+            PromotionsVo promotions = promotionsMapper.getPromotionsByProductId(price.getProductId());
+            if (null != promotions) {
+                // 促销活动
+                price.setActStatus(1);
+                price.setLadderPriceFlag(0);
+                if (promotions.getMode() == 3) {
+                    // 获取赠品
+                    List<ProductItemVo> giftList = promotionsMapper.getPromotionGifts(promotions.getId());
+                    promotions.setGiftList(giftList);
+                }
+                if (promotions.getType() == 1 && promotions.getMode() == 1 && null != promotions.getTouchPrice()) {
+                    price.setPrice(promotions.getTouchPrice());
+                    //添加税费
+                    if (taxFlag) {
+                        BigDecimal taxFee = MathUtil.div(MathUtil.mul(promotions.getTouchPrice(), price.getTaxRate()), 100);
+                        promotions.setTouchPrice(MathUtil.add(promotions.getTouchPrice(),taxFee).doubleValue());
+                    }
+                }
+                price.setPromotions(promotions);
+            } else {
+                if (null != userId) {
+                    if (1 == price.getLadderPriceFlag()) {
+                        // 阶梯价
+                        LadderPriceVo lowerPrice = priceMapper.findLowerLadderPrice(price.getProductId());
+                        LadderPriceVo lowerBuyNum = priceMapper.findMaxLadderPrice(price.getProductId());
+                        if (null != lowerPrice) {
+                            price.setPrice(lowerPrice.getBuyPrice());
+                            if (null != lowerBuyNum){
+                                price.setMinBuyNumber(lowerBuyNum.getBuyNum());
+                            }
+                        } else {
+                            price.setLadderPriceFlag(0);
+                        }
+                    } else {
+                        // 复购价
+                        Double repurchase = priceMapper.getRepurchasePrice(price.getProductId(), userId);
+                        if (null != repurchase && repurchase > 0) {
+                            price.setPrice(repurchase);
+                            price.setLadderPriceFlag(0);
+                        }
+                    }
+                }
+            }
+            //添加税费
+            if (taxFlag) {
+                BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(price.getPrice(), price.getTaxRate()), 100);
+                price.setPrice(MathUtil.add(price.getPrice(), thisTaxFee).doubleValue());
+            }
+        } else {
+            price.setPrice(0d);
+            price.setOriginalPrice(0d);
+            price.setUserIdentity(0);
+        }
+        // 屏蔽成本价
+        price.setCostProportional(0d);
+        price.setCostPrice(0d);
+    }
+
+        /**
+     * 根据用户id设置详细价格
+     *
+     * @param product 商品价格类
+     * @param userId 用户Id
+     */
+    public void setItemPriceByUserId(ProductItemVo product, Integer userId) {
+        // 设置价格等级
+        product.setPriceGrade(getPriceGrade(product.getPrice()));
+        // 根据用户Id查询用户身份
+        Integer identity = priceMapper.getIdentityByUserId(userId);
+        if (null != identity && identity > 0) {
+            // 用户身份: 2-会员机构, 4-普通机构
+            product.setUserIdentity(identity);
+            // 默认非促销活动状态
+            product.setActStatus(0);
+            // 设置划线价
+            product.setOriginalPrice(product.getPrice());
+            //税费标志
+            boolean taxFlag = "0".equals(product.getIncludedTax()) && ("1".equals(product.getInvoiceType()) || "2".equals(product.getInvoiceType()));
+            // 根据商品id查询商品活动
+            PromotionsVo promotions = promotionsMapper.getPromotionsByProductId(product.getProductId());
+            if (null != promotions) {
+                // 促销活动
+                product.setActStatus(1);
+                product.setLadderFlag(0);
+                if (promotions.getMode() == 3) {
+                    // 获取赠品
+                    List<ProductItemVo> giftList = promotionsMapper.getPromotionGifts(promotions.getId());
+                    promotions.setGiftList(giftList);
+                }
+                if (promotions.getType() == 1 && promotions.getMode() == 1 && null != promotions.getTouchPrice()) {
+                    product.setPrice(promotions.getTouchPrice());
+                    //添加税费
+                    if (taxFlag) {
+                        BigDecimal taxFee = MathUtil.div(MathUtil.mul(promotions.getTouchPrice(), product.getTaxRate()), 100);
+                        promotions.setTouchPrice(MathUtil.add(promotions.getTouchPrice(),taxFee).doubleValue());
+                    }
+                }
+                product.setPromotions(promotions);
+            } else {
+                if (null != userId) {
+                    if (1 == product.getLadderFlag()) {
+                        // 阶梯价
+                        LadderPriceVo lowerPrice = priceMapper.findLowerLadderPrice(product.getProductId());
+                        LadderPriceVo lowerBuyNum = priceMapper.findMaxLadderPrice(product.getProductId());
+                        if (null != lowerPrice) {
+                            product.setPrice(lowerPrice.getBuyPrice());
+                            if (null != lowerBuyNum){
+                                product.setMin(lowerBuyNum.getBuyNum());
+                            }
+                        } else {
+                            product.setLadderFlag(0);
+                        }
+                    } else {
+                        // 复购价
+                        Double repurchase = priceMapper.getRepurchasePrice(product.getProductId(), userId);
+                        if (null != repurchase && repurchase > 0) {
+                            product.setPrice(repurchase);
+                            product.setLadderFlag(0);
+                        }
+                    }
+                }
+            }
+            //添加税费
+            if (taxFlag) {
+                BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(product.getPrice(), product.getTaxRate()), 100);
+                product.setPrice(MathUtil.add(product.getPrice(), thisTaxFee).doubleValue());
+            }
+        } else {
+            product.setPrice(0d);
+            product.setOriginalPrice(0d);
+            product.setUserIdentity(0);
+        }
+    }
+}

+ 5 - 0
src/main/java/com/caimei365/commodity/mapper/ProductMapper.java

@@ -57,4 +57,9 @@ public interface ProductMapper {
      * @param source
      */
     List<FloorImageVo> getFloorImageById(Integer id, Integer source);
+    /**
+     * 获取商品及价格
+     * @param productId
+     */
+    ProductItemVo getProductItemById(Integer productId);
 }

+ 45 - 67
src/main/java/com/caimei365/commodity/model/vo/ProductItemVo.java

@@ -15,94 +15,72 @@ import java.util.List;
 @Data
 public class ProductItemVo implements Serializable {
     private static final long serialVersionUID = 1L;
+    /** itemId */
     private Integer id;
-    /** 商品Id */
+    /** 商品productID */
     private Integer productId;
-    /** 供应商Id */
-    private Integer shopId;
-    /** 商品名称 */
+    /** 名称name */
     private String name;
-    /** 商品图片 */
+    /** 主图mainImage */
     private String image;
-    /** 商品价格 */
+    /** 品牌 */
+    private String brandName;
+    /** 包装规格 */
+    private String unit;
+    /** 商品货号 */
+    private String code;
+    /** 机构价 */
     private Double price;
+    /** 是否公开机构价 0公开价格 1不公开价格 */
+    private Integer priceFlag;
+    /** 计算后价格等级 */
+    private Integer priceGrade;
+    /** 商品可见度:(3:所有人可见,2:普通机构可见,1:会员机构可见) */
+    private String visibility;
+    /** 所属供应商Id,关联供应商表 */
+    private Integer shopId;
+    /** 搜索关键词searchKey */
+    private String keyword;
+    /** 美博会商品活动状态 */
+    private Integer actFlag;
     /** 商品原价 */
     private Double originalPrice;
-    /** 商品单位 */
-    private String unit;
-    /**
-     * 是否是赠品 2是,其他否
-     */
+    /** 购买数量 */
+    private Integer number;
+    /** 是否是赠品 2是,其他否 */
     private Integer productType;
-    /**
-     * 增量
-     */
+    /** 增量 */
     private Integer step;
-    /**
-     * 起订量
-     */
+    /** 起订量 */
     private Integer min;
-    /**
-     * 商品上架状态:0逻辑删除 1待审核 2已上架 3已下架 8审核未通过 9已冻结
-     */
+    /** 商品上架状态:0逻辑删除 1待审核 2已上架 3已下架 8审核未通过 9已冻结 */
     private Integer validFlag;
-    /**
-     * 价格可见度:0公开价格 1不公开价格 2仅对会员机构公开
-     */
-    private Integer priceFlag;
-    /**
-     * 活动状态:1有效,0失效
-     */
+    /** 活动状态:1有效,0失效 */
     private Integer actStatus;
-    /**
-     * 启用阶梯价格标识:1是,0否
-     */
+    /** 启用阶梯价格标识:1是,0否 */
     private Integer ladderFlag;
-    /**
-     * 库存
-     */
+    /** 库存 */
     private Integer stock;
-    /**
-     * 购买数量
-     */
-    private Integer number;
-    /**
-     * 购物车失效状态:0有效,1后台删除的,2冻结的,3下架,4售罄 >7库存不足,5价格仅会员可见,6未公开价格
-     */
+    /** 购物车失效状态:0有效,1后台删除的,2冻结的,3下架,4售罄 >7库存不足,5价格仅会员可见,6未公开价格 */
     private Integer status;
-    /**
-     * 阶梯价
-     */
+    /** 阶梯价 */
     List<LadderPriceVo> ladderPrices;
-    /**
-     * 促销活动
-     */
+    /** 促销活动 */
     private PromotionsVo promotions;
-    /**
-     * 商品的类别:1正常商品(默认),2二手商品
-     */
+    /** 商品的类别:1正常商品(默认),2二手商品 */
     private String productCategory;
-    /**
-     * 商品货号
-     */
+    /** 商品货号 */
     private String productCode;
-
+    /** 商品是否默认选中 */
     private Boolean productsChecked = false;
-
-    /**
-     * 是否含税 0不含税,1含税,2未知
-     */
+    /** 是否含税 0不含税,1含税,2未知 */
     private String includedTax;
-
-    /**
-     * 发票类型(基于是否含税基础) 1增值税票,2普通票, 3不能开票
-     */
+    /** 发票类型(基于是否含税基础) 1增值税票,2普通票, 3不能开票 */
     private String invoiceType;
-
-    /**
-     * 机构税率
-     */
+    /** 机构税率 */
     private BigDecimal taxRate;
-
-
+    /** 用户身份: 2-会员机构, 4-普通机构 */
+    private Integer userIdentity;
+    /** 是否启用详聊,1不开启,2开启(开启详聊不展示交易价)*/
+    private Integer detailTalkFlag;
 }

+ 6 - 106
src/main/java/com/caimei365/commodity/service/impl/PriceServiceImpl.java

@@ -1,20 +1,18 @@
 package com.caimei365.commodity.service.impl;
 
 import com.aliyun.opensearch.sdk.dependencies.com.google.common.collect.Lists;
+import com.caimei365.commodity.components.PriceUtilService;
 import com.caimei365.commodity.mapper.PriceMapper;
 import com.caimei365.commodity.mapper.PromotionsMapper;
 import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.vo.*;
 import com.caimei365.commodity.service.PriceService;
-import com.caimei365.commodity.utils.MathUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
-import java.math.BigDecimal;
 import java.util.List;
-import java.util.stream.IntStream;
 
 /**
  * Description
@@ -29,6 +27,8 @@ public class PriceServiceImpl implements PriceService {
     private PriceMapper priceMapper;
     @Resource
     private PromotionsMapper promotionsMapper;
+    @Resource
+    private PriceUtilService priceUtilService;
 
     /**
      * 获取商品详情价格
@@ -42,7 +42,7 @@ public class PriceServiceImpl implements PriceService {
         // 数据库获取基本价格信息
         PriceVo price = priceMapper.getDetailPrice(productId);
         // 根据用户id设置详细价格
-        setPriceByUserId(price, userId);
+        priceUtilService.setPriceByUserId(price, userId);
         log.info(">>>读取商品价格,商品ID:" + productId + ",用户ID:" + userId);
         return ResponseJson.success(price);
     }
@@ -72,7 +72,7 @@ public class PriceServiceImpl implements PriceService {
         List<PriceVo> priceList = priceMapper.getListPriceByProductIds(productIdList);
         for (PriceVo price : priceList) {
             // 根据用户id设置详细价格
-            setPriceByUserId(price, userId);
+            priceUtilService.setPriceByUserId(price, userId);
         }
         log.info(">>>读取商品列表价格,商品IDs:" + productIds + ",用户ID:" + userId);
         return ResponseJson.success(priceList);
@@ -89,112 +89,12 @@ public class PriceServiceImpl implements PriceService {
         List<LadderPriceVo> ladderPrices = priceMapper.getladderPricesByProductId(productId);
         TaxVo tax = priceMapper.getTaxByProductId(productId);
         if (!CollectionUtils.isEmpty(ladderPrices)) {
-            setLadderPriceList(ladderPrices, tax);
+            priceUtilService.setLadderPriceList(ladderPrices, tax);
         }
         return ResponseJson.success(ladderPrices);
     }
 
-    /**
-     * 设置阶梯价展示数据
-     * @param ladderPrices  List<LadderPriceVo>
-     * @param tax           TaxVo
-     */
-    private void setLadderPriceList(List<LadderPriceVo> ladderPrices, TaxVo tax) {
-        IntStream.range(0, ladderPrices.size()).forEach(i -> {
-            //税费标志
-            boolean taxFlag = "0".equals(tax.getIncludedTax()) && ("1".equals(tax.getInvoiceType()) || "2".equals(tax.getInvoiceType()));
-            //添加税费
-            if (taxFlag) {
-                BigDecimal taxFee = MathUtil.div(MathUtil.mul(ladderPrices.get(i).getBuyPrice(), tax.getTaxPoint()), 100);
-                ladderPrices.get(i).setBuyPrice(MathUtil.add(ladderPrices.get(i).getBuyPrice(),taxFee).doubleValue());
-            }
-            if (i == ladderPrices.size() - 1) {
-                ladderPrices.get(i).setMaxNum(0);
-                ladderPrices.get(i).setNumRange("≥" + ladderPrices.get(i).getBuyNum());
-            } else {
-                ladderPrices.get(i).setMaxNum(ladderPrices.get(i + 1).getBuyNum());
-                String buyNumRangeShow = ladderPrices.get(i).getBuyNum() + "~" + (ladderPrices.get(i + 1).getBuyNum() - 1);
-                ladderPrices.get(i).setNumRange(buyNumRangeShow);
-            }
-        });
-    }
 
-    /**
-     * 根据用户id设置详细价格
-     *
-     * @param price 商品价格类
-     * @param userId 用户Id
-     */
-    private void setPriceByUserId(PriceVo price, Integer userId) {
-        // 根据用户Id查询用户身份
-        Integer identity = priceMapper.getIdentityByUserId(userId);
-        if (null != identity && identity > 0) {
-            // 用户身份: 2-会员机构, 4-普通机构
-            price.setUserIdentity(identity);
-            // 默认非促销活动状态
-            price.setActStatus(0);
-            // 设置划线价
-            price.setOriginalPrice(price.getPrice());
-            //税费标志
-            boolean taxFlag = "0".equals(price.getIncludedTax()) && ("1".equals(price.getInvoiceType()) || "2".equals(price.getInvoiceType()));
-            // 根据商品id查询商品活动
-            PromotionsVo promotions = promotionsMapper.getPromotionsByProductId(price.getProductId());
-            if (null != promotions) {
-                // 促销活动
-                price.setActStatus(1);
-                price.setLadderPriceFlag(0);
-                if (promotions.getMode() == 3) {
-                    // 获取赠品
-                    List<ProductItemVo> giftList = promotionsMapper.getPromotionGifts(promotions.getId());
-                    promotions.setGiftList(giftList);
-                }
-                if (promotions.getType() == 1 && promotions.getMode() == 1 && null != promotions.getTouchPrice()) {
-                    price.setPrice(promotions.getTouchPrice());
-                    //添加税费
-                    if (taxFlag) {
-                        BigDecimal taxFee = MathUtil.div(MathUtil.mul(promotions.getTouchPrice(), price.getTaxRate()), 100);
-                        promotions.setTouchPrice(MathUtil.add(promotions.getTouchPrice(),taxFee).doubleValue());
-                    }
-                }
-                price.setPromotions(promotions);
-            } else {
-                if (null != userId) {
-                    if (1 == price.getLadderPriceFlag()) {
-                        // 阶梯价
-                        LadderPriceVo lowerPrice = priceMapper.findLowerLadderPrice(price.getProductId());
-                        LadderPriceVo lowerBuyNum = priceMapper.findMaxLadderPrice(price.getProductId());
-                        if (null != lowerPrice) {
-                            price.setPrice(lowerPrice.getBuyPrice());
-                            if (null != lowerBuyNum){
-                                price.setMinBuyNumber(lowerBuyNum.getBuyNum());
-                            }
-                        } else {
-                            price.setLadderPriceFlag(0);
-                        }
-                    } else {
-                        // 复购价
-                        Double repurchase = priceMapper.getRepurchasePrice(price.getProductId(), userId);
-                        if (null != repurchase && repurchase > 0) {
-                            price.setPrice(repurchase);
-                            price.setLadderPriceFlag(0);
-                        }
-                    }
-                }
-            }
-            //添加税费
-            if (taxFlag) {
-                BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(price.getPrice(), price.getTaxRate()), 100);
-                price.setPrice(MathUtil.add(price.getPrice(), thisTaxFee).doubleValue());
-            }
-        } else {
-            price.setPrice(0d);
-            price.setOriginalPrice(0d);
-            price.setUserIdentity(0);
-        }
-        // 屏蔽成本价
-        price.setCostProportional(0d);
-        price.setCostPrice(0d);
-    }
 
 
 

+ 28 - 27
src/main/java/com/caimei365/commodity/service/impl/ProductServiceImpl.java

@@ -6,6 +6,7 @@ import com.caimei365.commodity.model.vo.*;
 import com.caimei365.commodity.service.ProductService;
 import com.caimei365.commodity.utils.AppletsLinkUtil;
 import com.caimei365.commodity.utils.ImageUtils;
+import com.caimei365.commodity.components.PriceUtilService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
@@ -31,6 +32,8 @@ public class ProductServiceImpl implements ProductService {
     private String domain;
     @Resource
     private ProductMapper productMapper;
+    @Resource
+    private PriceUtilService priceUtilService;
 
     /**
      * 获取分类列表
@@ -129,33 +132,31 @@ public class ProductServiceImpl implements ProductService {
             image.setLinkType(linkType);
             image.setLinkParam(linkParam);
             if (image.getProductId() != null) {
-//                ProductItemVo product = homePageDao.findProduct(image.getProductId());
-//                if (product != null) {
-//                    image.setName(product.getName());
-//                    image.setImage(ImageUtils.getImageURL("product", product.getMainImage(), 0, domain));
-//                    // 设置价格等级
-//                    product.setPrice1Grade(ProductUtils.getPriceGrade(product.getPrice1()));
-//                    image.setListType(1);
-//                    repeatPurchaseService.setProductPrice(product, userId);
-//                    image.setProduct(product);
-//                    if (userId != null) {
-//                        UserVo user = loginDao.findUser(userId);
-//                        if (user != null) {
-//                            product.setUserIdentity(user.getUserIdentity());
-//                            if (4 == user.getUserIdentity() && "1".equals(product.getVisibility())) {
-//                                iterator.remove();
-//                            }
-//                        } else {
-//                            if ("1".equals(product.getVisibility()) || "2".equals(product.getVisibility())) {
-//                                iterator.remove();
-//                            }
-//                        }
-//                    } else {
-//                        if ("1".equals(product.getVisibility()) || "2".equals(product.getVisibility())) {
-//                            iterator.remove();
-//                        }
-//                    }
-//                }
+                // 获取商品及价格
+                ProductItemVo product = productMapper.getProductItemById(image.getProductId());
+                if (product != null) {
+                    image.setListType(1);
+                    image.setName(product.getName());
+                    image.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
+                    // 设置商品价格
+                    priceUtilService.setItemPriceByUserId(product, userId);
+                    image.setProduct(product);
+                    if (userId != null) {
+                        if (product.getUserIdentity() > 0) {
+                            if (4 == product.getUserIdentity() && "1".equals(product.getVisibility())) {
+                                iterator.remove();
+                            }
+                        } else {
+                            if ("1".equals(product.getVisibility()) || "2".equals(product.getVisibility())) {
+                                iterator.remove();
+                            }
+                        }
+                    } else {
+                        if ("1".equals(product.getVisibility()) || "2".equals(product.getVisibility())) {
+                            iterator.remove();
+                        }
+                    }
+                }
             } else {
                 image.setListType(2);
             }

+ 4 - 2
src/main/java/com/caimei365/commodity/service/impl/PromotionsServiceImpl.java

@@ -9,7 +9,7 @@ import com.caimei365.commodity.model.vo.PromotionsVo;
 import com.caimei365.commodity.service.PromotionsService;
 import com.caimei365.commodity.utils.AppletsLinkUtil;
 import com.caimei365.commodity.utils.ImageUtils;
-import com.caimei365.commodity.utils.PriceUtil;
+import com.caimei365.commodity.components.PriceUtilService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
@@ -36,6 +36,8 @@ public class PromotionsServiceImpl implements PromotionsService {
     private String domain;
     @Resource
     private PromotionsMapper promotionsMapper;
+    @Resource
+    private PriceUtilService priceUtilService;
     /**
      * 专题活动列表数据
      *
@@ -104,7 +106,7 @@ public class PromotionsServiceImpl implements PromotionsService {
         List<ProductListVo> list = promotionsMapper.getProductListByPromotions(promotionsId, visibilityList);
         // 设置价格等级 及 老图片路径
         list.forEach(product -> {
-            product.setPriceGrade(PriceUtil.getpriceGrade(product.getPrice()));
+            product.setPriceGrade(priceUtilService.getPriceGrade(product.getPrice()));
             product.setPrice(0d);
             product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
         });

+ 4 - 2
src/main/java/com/caimei365/commodity/service/impl/SearchIndexServiceImpl.java

@@ -15,7 +15,7 @@ import com.caimei365.commodity.model.search.*;
 import com.caimei365.commodity.service.SearchIndexService;
 import com.caimei365.commodity.service.SearchQueryService;
 import com.caimei365.commodity.utils.ImageUtils;
-import com.caimei365.commodity.utils.PriceUtil;
+import com.caimei365.commodity.components.PriceUtilService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -44,6 +44,8 @@ public class SearchIndexServiceImpl implements SearchIndexService {
     private SearchOpenService searchOpenService;
     @Resource
     private SearchQueryService searchQueryService;
+    @Resource
+    private PriceUtilService priceUtilService;
     /**
      * 初始化(添加)所有索引
      *
@@ -995,7 +997,7 @@ public class SearchIndexServiceImpl implements SearchIndexService {
         product.setM_id(mallId);
         product.setP_all(1);
         // 价格等级
-        product.setP_price_grade(PriceUtil.getpriceGrade(product.getP_price().doubleValue()));
+        product.setP_price_grade(priceUtilService.getPriceGrade(product.getP_price().doubleValue()));
         DocumentDTO<ProductDO> productDoc = new DocumentDTO<>();
         productDoc.setCmd("add");
         productDoc.setFields(product);

+ 4 - 3
src/main/java/com/caimei365/commodity/service/impl/SearchProductServiceImpl.java

@@ -13,7 +13,7 @@ import com.caimei365.commodity.model.vo.PaginationVo;
 import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.service.SearchProductService;
 import com.caimei365.commodity.utils.Json2PojoUtil;
-import com.caimei365.commodity.utils.PriceUtil;
+import com.caimei365.commodity.components.PriceUtilService;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
@@ -40,7 +40,8 @@ public class SearchProductServiceImpl implements SearchProductService {
     private SearchMapper searchMapper;
     @Resource
     private SearchOpenService searchOpenService;
-
+    @Resource
+    private PriceUtilService priceUtilService;
     /**
      * 根据关键词搜索商品
      *
@@ -203,7 +204,7 @@ public class SearchProductServiceImpl implements SearchProductService {
         PageHelper.startPage(num, size);
         List<ProductListVo> productList = searchMapper.queryProduct(identity, keyword, shopId, bigTypeId, smallTypeId, tinyTypeId, classifyId, sortField, sortType);
         productList.forEach(product -> {
-            product.setPriceGrade(PriceUtil.getpriceGrade(product.getPrice()));
+            product.setPriceGrade(priceUtilService.getPriceGrade(product.getPrice()));
             product.setPrice(0d);
         });
         PaginationVo<ProductListVo> pageData = new PaginationVo<>(productList);

+ 59 - 261
src/main/java/com/caimei365/commodity/utils/MathUtil.java

@@ -3,11 +3,6 @@ package com.caimei365.commodity.utils;
 import org.apache.commons.lang.StringUtils;
 
 import java.math.BigDecimal;
-import java.text.DecimalFormat;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
 
 /**
  * Description
@@ -16,139 +11,44 @@ import java.util.Set;
  * @date : 2021/4/9
  */
 public class MathUtil {
-
-
-
-	public static int default_scale = 4;
-
-	private static final int MAX_GENERATE_COUNT = 99999;
-	private static int generateCount = 0;
-
-
-	/**
-	 * 两个实数相除,默认四舍五入到4位
-	 *
-	 * @param v1
-	 * @param v2
-	 * @return
-	 */
-	public static BigDecimal div(Object v1, Object v2) {
-		return div(v1, v2, default_scale);
-	}
-
-	/**
-	 * 两个实数相除,默认四舍五入到scale位
-	 *
-	 * @param v1
-	 * @param v2
-	 * @param scale
-	 * @return
-	 */
-	public static BigDecimal div(Object v1, Object v2, int scale) {
-		if (scale < 0) {
-			throw new IllegalArgumentException("四舍五入的位数不能为负数");
-		}
-		BigDecimal b1 = convert(v1);
-		BigDecimal b2 = convert(v2);
-		if (equal0(b2)) {
-			throw new IllegalArgumentException("除数不能为0");
-		}
-		return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP);
-	}
-
-	public static String formatDouble(double s) {
-		DecimalFormat fmt = new DecimalFormat("0.00");
-		return fmt.format(s);
-	}
-
-	public static String[] intersect(String[] arr1, String[] arr2){
-		List<String> l = new LinkedList<String>();
-		Set<String> common = new HashSet<String>();
-		for(String str:arr1){
-			if(!l.contains(str)){
-				l.add(str);
-			}
-		}
-		for(String str:arr2){
-			if(l.contains(str)){
-				common.add(str);
-			}
-		}
-		String[] result={};
-		return common.toArray(result);
-	}
-
-
-	public static synchronized String getUniqueString() {
-		if (generateCount > 99999) {generateCount = 0;}
-		String uniqueNumber = Long.toString(System.currentTimeMillis())
-				+ Integer.toString(generateCount);
-		generateCount++;
-		return uniqueNumber;
-	}
-
+    /** 默认小数位 */
+	private static final int DEFAULT_SCALE = 4;
 	/**
 	 *
 	 * 构造函数
 	 */
-	private MathUtil() {
-
-	}
-
-	/**
-	 * 类型转换函数
-	 *
-	 * @param o
-	 * @return
-	 */
-	public static BigDecimal convert(Object o) {
-		if (o == null) {
-			return BigDecimal.ZERO;
-		} else if (o instanceof BigDecimal) {
-			return (BigDecimal) o;
-		}
-		String str = o.toString();
-		if (StringUtils.isNotBlank(str)) {
-			return new BigDecimal(str);
-		} else {
-			return BigDecimal.ZERO;
-		}
-	}
+	private MathUtil() {}
 
 	/**
 	 * 两个实数相加
 	 *
-	 * @param v1
-	 * @param v2
-	 * @return
+	 * @param v1 BigDecimal
+	 * @param v2 BigDecimal
+	 * @return BigDecimal
 	 */
 	public static BigDecimal add(Object v1, Object v2) {
 		BigDecimal b1 = convert(v1);
 		BigDecimal b2 = convert(v2);
 		return b1.add(b2);
-
 	}
-
 	/**
 	 * 两个实数相减
 	 *
-	 * @param v1
-	 * @param v2
-	 * @return
+	 * @param v1 BigDecimal
+	 * @param v2 BigDecimal
+	 * @return BigDecimal
 	 */
 	public static BigDecimal sub(Object v1, Object v2) {
 		BigDecimal b1 = convert(v1);
 		BigDecimal b2 = convert(v2);
 		return b1.subtract(b2);
-
 	}
-
 	/**
 	 * 两个实数相乘
 	 *
-	 * @param v1
-	 * @param v2
-	 * @return
+	 * @param v1 BigDecimal
+	 * @param v2 BigDecimal
+	 * @return BigDecimal
 	 */
 	public static BigDecimal mul(Object v1, Object v2) {
 		BigDecimal b1 = convert(v1);
@@ -156,7 +56,6 @@ public class MathUtil {
 		return b1.multiply(b2);
 
 	}
-
 	/**
 	 * 相个实数相乘并四舍五入到Sacle位
 	 *
@@ -172,73 +71,73 @@ public class MathUtil {
 		BigDecimal b1 = convert(v1);
 		BigDecimal b2 = convert(v2);
 		return b1.multiply(b2).setScale(scale, BigDecimal.ROUND_HALF_UP);
-
 	}
-
 	/**
-	 * 两个实数比较
+	 * 两个实数相除,四舍五入到默认位数
 	 *
-	 * @param v1
-	 * @param v2
-	 * @return
+	 * @param v1 BigDecimal
+	 * @param v2 BigDecimal
+	 * @return BigDecimal
 	 */
-	public static int compare(Object v1, Object v2) {
-		BigDecimal b1 = convert(v1);
-		BigDecimal b2 = convert(v2);
-		return b1.compareTo(b2);
-	}
-
-	public static boolean equal0(Object v1) {
-		BigDecimal b1 = convert(v1);
-		return b1.compareTo(BigDecimal.ZERO) == 0;
-	}
-
-	public static boolean notEqual0(Object v1) {
-		BigDecimal b1 = convert(v1);
-		return b1.compareTo(BigDecimal.ZERO) != 0;
+	public static BigDecimal div(Object v1, Object v2) {
+		return div(v1, v2, DEFAULT_SCALE);
 	}
-
 	/**
-	 * 两个整数比较
+	 * 两个实数相除,默认四舍五入到scale位
 	 *
-	 * @param v1
-	 * @param v2
-	 * @return
+	 * @param v1 BigDecimal
+	 * @param v2 BigDecimal
+	 * @param scale 小数位
+	 * @return BigDecimal
 	 */
-	public static int compareInt(Integer v1, Integer v2) {
-
-		if (v1 == null) {
-			v1 = new Integer(0);
+	public static BigDecimal div(Object v1, Object v2, int scale) {
+		if (scale < 0) {
+			throw new IllegalArgumentException("四舍五入的位数不能为负数");
 		}
-		if (v2 == null) {
-			v2 = new Integer(0);
+		BigDecimal b1 = convert(v1);
+		BigDecimal b2 = convert(v2);
+		if (equal0(b2)) {
+			throw new IllegalArgumentException("除数不能为0");
 		}
-		return v1.compareTo(v2);
+		return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP);
 	}
 
 	/**
-	 * 判断两个整数是否相等
+	 * 两个实数比较
 	 *
-	 * @param v1
-	 * @param v2
-	 * @return
+	 * @param v1 BigDecimal
+	 * @param v2 BigDecimal
+	 * @return int [1:v1>v2, 0:v1=v2, 1:v1<v2]
 	 */
-	public static boolean equal(Integer v1, Integer v2) {
-
-		int result = compareInt(v1, v2);
-		return result == 0;
+	public static int compare(Object v1, Object v2) {
+		BigDecimal b1 = convert(v1);
+		BigDecimal b2 = convert(v2);
+		return b1.compareTo(b2);
 	}
 
 	/**
-	 * 判断两个整数不等
+	 * 类型转换函数
 	 *
-	 * @param v1
-	 * @param v2
-	 * @return
+	 * @param o <T>
+	 * @return BigDecimal
 	 */
-	public static boolean notEqual(Integer v1, Integer v2) {
-		int result = compareInt(v1, v2);
-		return result != 0;
+	public static BigDecimal convert(Object o) {
+		if (o == null) {
+			return BigDecimal.ZERO;
+		} else if (o instanceof BigDecimal) {
+			return (BigDecimal) o;
+		}
+		String str = o.toString();
+		if (StringUtils.isNotBlank(str)) {
+			return new BigDecimal(str);
+		} else {
+			return BigDecimal.ZERO;
+		}
+	}
+
+	private static boolean equal0(Object v1) {
+		BigDecimal b1 = convert(v1);
+		return b1.compareTo(BigDecimal.ZERO) == 0;
 	}
 
 	/**
@@ -256,108 +155,7 @@ public class MathUtil {
 		return b.setScale(scale, BigDecimal.ROUND_HALF_UP);
 	}
 
-	/**
-	 * 将字符串转换成整型
-	 *
-	 * @param value
-	 * @param defaultNum
-	 * @return
-	 */
-	public static int parsetInt(String value, int defaultNum) {
-		if (value != null && !value.equals("")) {
-			int num = defaultNum;
-			try {
-				num = Integer.parseInt(value);
-			} catch (Exception ignored) {
-			}
-			return num;
-		} else {
-			return defaultNum;
-		}
-	}
-
-	/**
-	 * 将string转换为double
-	 *
-	 * @param value
-	 * @param defaultNum
-	 * @return
-	 */
-	public static double parseDouble(String value, double defaultNum) {
-		if (StringUtils.isBlank(value)) {
-			return defaultNum;
-		}
-
-		value = value.replaceAll(",", "");
-		value = value.replaceAll(" ", "");
-		value = value.replaceAll("¥", "");
-
-		double num = defaultNum;
-		try {
-			num = Double.parseDouble(value);
-		} catch (Exception ignored) {
-		}
-		return num;
-	}
-
-	/**
-	 * 将string 转换为double
-	 *
-	 * @param value
-	 * @return
-	 */
-	public static double parseDouble(String value) {
-		return parseDouble(value, 0);
-	}
-
-	public static int isNullInteger(Integer v) {
-		if (v == null) {
-			return 0;
-		} else {
-			return v.intValue();
-		}
-	}
-
-	//
-	private static double EARTH_RADIUS = 6378.137;
-
-	private static double rad(double d) {
-
-		return d * Math.PI / 180.0;
-
-	}
-
-	public static double getDistance(double lat1, double lng1, double lat2, double lng2) {
-
-		double radLat1 = rad(lat1);
-
-		double radLat2 = rad(lat2);
-
-		double a = radLat1 - radLat2;
-
-		double b = rad(lng1) - rad(lng2);
-
-		double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
-
-		+ Math.cos(radLat1) * Math.cos(radLat2)
-
-		* Math.pow(Math.sin(b / 2), 2)));
-
-		s = s * EARTH_RADIUS;
-
-		s = Math.round(s * 10000) / 10000;
-
-		return s;
-
-	}
-
 //	public static void main(String[] args){
-//		double lat1=118.105736;
-//		double lng1=24.491558;
-//		double lat2=118.110749;
-//		double lng2=24.492824;
-//		double t=getDistance(lat1,lng1,lat2,lng2);
-//		System.out.println(t);
 //	}
 
 }

+ 0 - 137
src/main/java/com/caimei365/commodity/utils/PriceUtil.java

@@ -1,137 +0,0 @@
-package com.caimei365.commodity.utils;
-
-import org.springframework.util.StringUtils;
-
-import java.math.BigDecimal;
-
-/**
- * Description
- *
- * @author : Charles
- * @date : 2020/6/22
- */
-public class PriceUtil {
-    /** 默认小数位 */
-	private static final int DEFAULT_SCALE = 4;
-
-	/**
-	 * 两个实数比较
-	 *
-	 * @param v1 BigDecimal
-	 * @param v2 BigDecimal
-	 * @return int [1:v1>v2, 0:v1=v2, 1:v1<v2]
-	 */
-	public static int compare(Object v1, Object v2) {
-		BigDecimal b1 = convert(v1);
-		BigDecimal b2 = convert(v2);
-		return b1.compareTo(b2);
-	}
-	/**
-	 * 两个实数相加
-	 *
-	 * @param v1 BigDecimal
-	 * @param v2 BigDecimal
-	 * @return BigDecimal
-	 */
-	public static BigDecimal add(Object v1, Object v2) {
-		BigDecimal b1 = convert(v1);
-		BigDecimal b2 = convert(v2);
-		return b1.add(b2);
-	}
-	/**
-	 * 两个实数相减
-	 *
-	 * @param v1 BigDecimal
-	 * @param v2 BigDecimal
-	 * @return BigDecimal
-	 */
-	public static BigDecimal sub(Object v1, Object v2) {
-		BigDecimal b1 = convert(v1);
-		BigDecimal b2 = convert(v2);
-		return b1.subtract(b2);
-	}
-	/**
-	 * 两个实数相乘
-	 *
-	 * @param v1 BigDecimal
-	 * @param v2 BigDecimal
-	 * @return BigDecimal
-	 */
-	public static BigDecimal mul(Object v1, Object v2) {
-		BigDecimal b1 = convert(v1);
-		BigDecimal b2 = convert(v2);
-		return b1.multiply(b2);
-
-	}
-	/**
-	 * 两个实数相除,四舍五入到默认位数
-	 *
-	 * @param v1 BigDecimal
-	 * @param v2 BigDecimal
-	 * @return BigDecimal
-	 */
-	public static BigDecimal div(Object v1, Object v2) {
-		return div(v1, v2, DEFAULT_SCALE);
-	}
-	/**
-	 * 两个实数相除,默认四舍五入到scale位
-	 *
-	 * @param v1 BigDecimal
-	 * @param v2 BigDecimal
-	 * @param scale 小数位
-	 * @return BigDecimal
-	 */
-	public static BigDecimal div(Object v1, Object v2, int scale) {
-		if (scale < 0) {
-			throw new IllegalArgumentException("四舍五入的位数不能为负数");
-		}
-		BigDecimal b1 = convert(v1);
-		BigDecimal b2 = convert(v2);
-		if (equal0(b2)) {
-			throw new IllegalArgumentException("除数不能为0");
-		}
-		return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP);
-	}
-	/**
-	 * 类型转换函数
-	 *
-	 * @param o <T>
-	 * @return BigDecimal
-	 */
-	private static BigDecimal convert(Object o) {
-		if (o == null) {
-			return BigDecimal.ZERO;
-		} else if (o instanceof BigDecimal) {
-			return (BigDecimal) o;
-		}
-		String str = o.toString();
-		if (!StringUtils.isEmpty(str)) {
-			return new BigDecimal(str);
-		} else {
-			return BigDecimal.ZERO;
-		}
-	}
-	private static boolean equal0(Object v1) {
-		BigDecimal b1 = convert(v1);
-		return b1.compareTo(BigDecimal.ZERO) == 0;
-	}
-
-    /**
-     * 根据价格返回价格等级
-     * @param price 价格
-     * @return priceGrade 价格等级
-     */
-    public static Integer getpriceGrade(Double price){
-        int grade = 1;
-        if (price > 50 * 10000) {
-            grade = 5;
-        } else if (price > 25 * 10000) {
-            grade = 4;
-        } else if (price > 10 * 10000) {
-            grade = 3;
-        } else if (price > 2.5 * 10000) {
-            grade = 2;
-        }
-        return grade;
-    }
-}

+ 25 - 0
src/main/resources/mapper/ProductMapper.xml

@@ -91,5 +91,30 @@
         </if>
         order by sort desc, createDate desc
     </select>
+    <select id="getProductItemById" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
+        select
+            p.productID as productId,
+            p.`name` as name,
+            p.mainImage as image,
+            p.unit as unit,
+            p.productCode as code,
+            p.price1TextFlag as priceFlag,
+            p.price1 as price,
+            p.shopID as shopId,
+            p.searchKey as keyword,
+            p.price8Text as actFlag,
+            p.minBuyNumber as min,
+            p.ladderPriceFlag as ladderFlag,
+            p.normalPrice as normalPrice,
+            p.step as step,
+            p.shopID as shopId,
+            p.taxPoint as taxRate,
+            p.includedTax as includedTax,
+            p.invoiceType as invoiceType,
+            cshd.detailTalkFlag
+        from product p
+        left join cm_second_hand_detail cshd on p.productID = cshd.productID
+        where p.productID = #{productId}
+    </select>
 
 </mapper>