浏览代码

商品价格逻辑

chao 4 年之前
父节点
当前提交
7d081f6d6c

+ 25 - 3
src/main/java/com/caimei365/commodity/mapper/PriceMapper.java

@@ -1,7 +1,11 @@
 package com.caimei365.commodity.mapper;
 package com.caimei365.commodity.mapper;
 
 
+import com.caimei365.commodity.model.vo.LadderPriceVo;
 import com.caimei365.commodity.model.vo.PriceVo;
 import com.caimei365.commodity.model.vo.PriceVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 
 /**
 /**
  * Description
  * Description
@@ -11,11 +15,29 @@ import org.apache.ibatis.annotations.Mapper;
  */
  */
 @Mapper
 @Mapper
 public interface PriceMapper {
 public interface PriceMapper {
+    /**
+     * 根据用户Id查询用户身份
+     */
+    Integer getIdentityByUserId(Integer userId);
     /**
     /**
      * 根据商品id查找价格
      * 根据商品id查找价格
-     *
-     * @param productId 商品id
-     * @return PriceVo
      */
      */
     PriceVo getDetailPrice(Integer productId);
     PriceVo getDetailPrice(Integer productId);
+    /**
+     * 根据商品id集合查找 价格列表
+     */
+    List<PriceVo> getListPriceByProductIds(@Param("productIds") List<Integer> productIds);
+    /**
+     * 获取最低阶梯价(价格最低,阶梯数最大)
+     */
+    LadderPriceVo findLowerLadderPrice(Integer productId);
+    /**
+     * 获取最高阶梯价(价格最高,阶梯数最小)
+     */
+    LadderPriceVo findMaxLadderPrice(Integer productId);
+    /**
+     * 根据商品ID和用户ID 查询复购价
+     */
+    Double getRepurchasePrice(@Param("productId") Integer productId, @Param("userId") Integer userId);
+
 }
 }

+ 13 - 0
src/main/java/com/caimei365/commodity/mapper/PromotionsMapper.java

@@ -1,7 +1,11 @@
 package com.caimei365.commodity.mapper;
 package com.caimei365.commodity.mapper;
 
 
+import com.caimei365.commodity.model.vo.CartItemVo;
+import com.caimei365.commodity.model.vo.PromotionsVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
 
 
+import java.util.List;
+
 /**
 /**
  * Description
  * Description
  *
  *
@@ -10,4 +14,13 @@ import org.apache.ibatis.annotations.Mapper;
  */
  */
 @Mapper
 @Mapper
 public interface PromotionsMapper {
 public interface PromotionsMapper {
+    /**
+     * 获取促销商品信息
+     */
+    PromotionsVo getPromotionsByProductId(Integer productId);
+    /**
+     * 获取促销赠品
+     */
+    List<CartItemVo> getProductGifts(Integer promotionsId);
+
 }
 }

+ 102 - 0
src/main/java/com/caimei365/commodity/model/vo/CartItemVo.java

@@ -0,0 +1,102 @@
+package com.caimei365.commodity.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * 顶部购物车数据
+ *
+ * @author : Charles
+ * @date : 2021/4/9
+ */
+@Data
+public class CartItemVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private Integer id;
+    private Integer productId;
+    private Integer supplierId;
+    private String name;
+    private String image;
+    private Double price;
+    private Double originalPrice;
+    private String unit;
+    /**
+     * 是否是赠品 2是,其他否
+     */
+    private Integer productType;
+    /**
+     * 增量
+     */
+    private Integer step;
+    /**
+     * 起订量
+     */
+    private Integer min;
+    /**
+     * 商品上架状态:0逻辑删除 1待审核 2已上架 3已下架 8审核未通过 9已冻结
+     */
+    private Integer validFlag;
+    /**
+     * 价格可见度:0公开价格 1不公开价格 2仅对会员机构公开
+     */
+    private Integer priceFlag;
+    /**
+     * 活动状态:1有效,0失效
+     */
+    private Integer actStatus;
+    /**
+     * 启用阶梯价格标识:1是,0否
+     */
+    private Integer ladderFlag;
+    /**
+     * 库存
+     */
+    private Integer stock;
+    /**
+     * 购买数量
+     */
+    private Integer number;
+    /**
+     * 购物车失效状态:0有效,1后台删除的,2冻结的,3下架,4售罄 >7库存不足,5价格仅会员可见,6未公开价格
+     */
+    private Integer status;
+    /**
+     * 阶梯价
+     */
+    List<LadderPriceVo> ladderPrices;
+    /**
+     * 促销活动
+     */
+    private PromotionsVo promotions;
+    /**
+     * 商品的类别:1正常商品(默认),2二手商品
+     */
+    private String productCategory;
+    /**
+     * 商品货号
+     */
+    private String productCode;
+
+    private Boolean productsChecked = false;
+
+    /**
+     * 是否含税 0不含税,1含税,2未知
+     */
+    private String includedTax;
+
+    /**
+     * 发票类型(基于是否含税基础) 1增值税票,2普通票, 3不能开票
+     */
+    private String invoiceType;
+
+    /**
+     * 机构税率
+     */
+    private BigDecimal taxRate;
+
+
+}

+ 43 - 0
src/main/java/com/caimei365/commodity/model/vo/LadderPriceVo.java

@@ -0,0 +1,43 @@
+package com.caimei365.commodity.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 阶梯价格
+ *
+ * @author : Charles
+ * @date : 2021/4/9
+ */
+@Data
+public class LadderPriceVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+    private Integer id;
+    /**
+     * 商品id
+     */
+    private Integer productId;
+    /**
+     * 第几阶梯
+     */
+    private Integer ladderNum;
+    /**
+     * 购买数量
+     */
+    private Integer buyNum;
+    /**
+     * 购买价格
+     */
+    private Double buyPrice;
+    /**
+     * 下一阶数量
+     */
+    private Integer maxNum;
+    /**
+     * 显示数量 如:1~3
+     */
+    private String numRange;
+
+}
+

+ 11 - 10
src/main/java/com/caimei365/commodity/model/vo/PromotionsVo.java

@@ -6,6 +6,7 @@ import lombok.Data;
 import java.io.Serializable;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.Date;
+import java.util.List;
 
 
 /**
 /**
  * 促销活动
  * 促销活动
@@ -36,11 +37,11 @@ public class PromotionsVo implements Serializable {
     /**
     /**
      * 优惠价/满减/满赠的设定价格(如满999赠商品)
      * 优惠价/满减/满赠的设定价格(如满999赠商品)
      */
      */
-    private BigDecimal touchPrice;
+    private Double touchPrice;
     /**
     /**
      * 减免价格
      * 减免价格
      */
      */
-    private BigDecimal reducedPrice;
+    private Double reducedPrice;
     /**
     /**
      * 开始时间
      * 开始时间
      */
      */
@@ -67,12 +68,12 @@ public class PromotionsVo implements Serializable {
      * 主订单id
      * 主订单id
      */
      */
     private Integer orderId;
     private Integer orderId;
-//    /**
-//     * 该优惠下商品
-//     */
-//    private List<CartItem> productList;
-//    /**
-//     * 该优惠下赠品品
-//     */
-//    private List<CartItem> giftList;
+    /**
+     * 该优惠下商品
+     */
+    private List<CartItemVo> productList;
+    /**
+     * 该优惠下赠品品
+     */
+    private List<CartItemVo> giftList;
 }
 }

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

@@ -1,14 +1,20 @@
 package com.caimei365.commodity.service.impl;
 package com.caimei365.commodity.service.impl;
 
 
+import com.aliyun.opensearch.sdk.dependencies.com.google.common.collect.Lists;
 import com.caimei365.commodity.mapper.PriceMapper;
 import com.caimei365.commodity.mapper.PriceMapper;
 import com.caimei365.commodity.mapper.PromotionsMapper;
 import com.caimei365.commodity.mapper.PromotionsMapper;
 import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.vo.CartItemVo;
+import com.caimei365.commodity.model.vo.LadderPriceVo;
 import com.caimei365.commodity.model.vo.PriceVo;
 import com.caimei365.commodity.model.vo.PriceVo;
+import com.caimei365.commodity.model.vo.PromotionsVo;
 import com.caimei365.commodity.service.PriceService;
 import com.caimei365.commodity.service.PriceService;
+import com.caimei365.commodity.utils.MathUtil;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.List;
 
 
 /**
 /**
@@ -24,6 +30,7 @@ public class PriceServiceImpl implements PriceService {
     private PriceMapper priceMapper;
     private PriceMapper priceMapper;
     @Resource
     @Resource
     private PromotionsMapper promotionsMapper;
     private PromotionsMapper promotionsMapper;
+
     /**
     /**
      * 获取商品详情价格
      * 获取商品详情价格
      *
      *
@@ -36,13 +43,9 @@ public class PriceServiceImpl implements PriceService {
         // 数据库获取基本价格信息
         // 数据库获取基本价格信息
         PriceVo price = priceMapper.getDetailPrice(productId);
         PriceVo price = priceMapper.getDetailPrice(productId);
         // 根据用户id设置详细价格
         // 根据用户id设置详细价格
-        //setPriceByUserId(price, userId);
-        // 屏蔽成本价
-        price.setCostProportional(0d);
-        price.setCostPrice(0d);
-
-
-        return null;
+        setPriceByUserId(price, userId);
+        log.info(">>>读取商品价格,商品ID:" + productId + ",用户ID:" + userId);
+        return ResponseJson.success(price);
     }
     }
 
 
     /**
     /**
@@ -54,72 +57,104 @@ public class PriceServiceImpl implements PriceService {
      */
      */
     @Override
     @Override
     public ResponseJson<List<PriceVo>> getListPrice(Integer userId, String productIds) {
     public ResponseJson<List<PriceVo>> getListPrice(Integer userId, String productIds) {
-        return null;
+        List<Integer> productIdList = Lists.newArrayList();
+        if (productIds.contains(",")) {
+            String[] productArr = productIds.split(",");
+            for (String id : productArr) {
+                productIdList.add(Integer.parseInt(id));
+            }
+        } else {
+            productIdList.add(Integer.parseInt(productIds));
+        }
+        if (productIdList.size() == 0 || null == userId) {
+            return ResponseJson.error("商品Id参数错误", null);
+        }
+        // 数据库获取基本价格信息
+        List<PriceVo> priceList = priceMapper.getListPriceByProductIds(productIdList);
+        for (PriceVo price : priceList) {
+            // 根据用户id设置详细价格
+            setPriceByUserId(price, userId);
+        }
+        log.info(">>>读取商品列表价格,商品IDs:" + productIds + ",用户ID:" + userId);
+        return ResponseJson.success(priceList);
     }
     }
 
 
-
-//    private void setPriceByUserId(PriceVo price, Integer userId) {
-//        // 默认非促销活动状态
-//        price.setActStatus(0);
-//        // 设置划线价
-//        price.setOriginalPrice(price.getPrice());
-//        // 根据商品id查询商品活动
-//        PromotionsVo promotions = promotionsMapper.getPromotionsByProductId(price.getProductId());
-//        //促销活动价
-//        if (null != promotions) {
-//            if (promotions.getMode() == 3) {
-//                // 获取赠品
-//                List<CartItem> giftList = promotionsMapper.getProductGifts(promotions.getId());
-//                promotions.setGiftList(giftList);
-//            }
-//            price.setActStatus(1);
-//            price.setPromotions(promotions);
-//            price.setLadderPriceFlag(0);
-//            if (promotions.getType() == 1 && promotions.getMode() == 1 && null != promotions.getTouchPrice()) {
-//                price.setPrice(promotions.getTouchPrice().doubleValue());
-//                //添加税费
-//                if ("0".equals(price.getIncludedTax()) && ("1".equals(price.getInvoiceType()) || "2".equals(price.getInvoiceType()))) {
-//                    BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(promotions.getTouchPrice(), price.getTaxRate()), BigDecimal.valueOf(100));
-//                    promotions.setTouchPrice(MathUtil.add(promotions.getTouchPrice(),addedValueTax));
-//                }
-//            }
-//        } else {
-//            if (null != user) {
-//                if (1 == price.getLadderPriceFlag()) {
-//                    // 阶梯价
-//                    LadderPrice ladderPrice = priceMapper.findLowerLadderPrice(price.getProductId());
-//                    LadderPrice ladderPrice2 = priceMapper.findMaxLadderPrice(price.getProductId());
-//                    if (null != ladderPrice) {
-//                        price.setPrice(ladderPrice.getBuyPrice());
-//                        if (null != ladderPrice2){
-//                            price.setMinBuyNumber(ladderPrice2.getBuyNum());
-//                        }
-//                    } else {
-//                        price.setLadderPriceFlag(0);
-//                    }
-//                } else {
-//                    // 复购价
-//                    Double repurchase = priceMapper.getRepurchasePrice(price.getProductId(), user.getUserID());
-//                    if (null != repurchase && repurchase > 0) {
-//                        price.setPrice(repurchase);
-//                        price.setLadderPriceFlag(0);
-//                    }
-//                }
-//            }
-//        }
-//        //添加税费
-//        if ("0".equals(price.getIncludedTax()) && ("1".equals(price.getInvoiceType()) || "2".equals(price.getInvoiceType()))) {
-//            price.setPrice(price.getPrice() + (price.getPrice().doubleValue() * price.getTaxRate().doubleValue()) /100);
-//        }
-//        if (null == user) {
-//            price.setPrice(0d);
-//            price.setCostPrice(0d);
-//            price.setUserIdentity(0);
-//        } else {
-//            // 用户身份: 2-会员机构, 4-普通机构
-//            price.setUserIdentity(user.getUserIdentity());
-//        }
-//    }
+    /**
+     * 根据用户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<CartItemVo> giftList = promotionsMapper.getProductGifts(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);
+    }
 
 
 
 
 
 

+ 365 - 0
src/main/java/com/caimei365/commodity/utils/MathUtil.java

@@ -0,0 +1,365 @@
+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
+ *
+ * @author : Charles
+ * @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 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;
+		}
+	}
+
+	/**
+	 * 两个实数相加
+	 *
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	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
+	 */
+	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
+	 */
+	public static BigDecimal mul(Object v1, Object v2) {
+		BigDecimal b1 = convert(v1);
+		BigDecimal b2 = convert(v2);
+		return b1.multiply(b2);
+
+	}
+
+	/**
+	 * 相个实数相乘并四舍五入到Sacle位
+	 *
+	 * @param v1
+	 * @param v2
+	 * @param scale
+	 * @return
+	 */
+	public static BigDecimal mul(Object v1, Object v2, int scale) {
+		if (scale < 0) {
+			throw new IllegalArgumentException("四舍五入的位数不能为负数");
+		}
+		BigDecimal b1 = convert(v1);
+		BigDecimal b2 = convert(v2);
+		return b1.multiply(b2).setScale(scale, BigDecimal.ROUND_HALF_UP);
+
+	}
+
+	/**
+	 * 两个实数比较
+	 *
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	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;
+	}
+
+	/**
+	 * 两个整数比较
+	 *
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static int compareInt(Integer v1, Integer v2) {
+
+		if (v1 == null) {
+			v1 = new Integer(0);
+		}
+		if (v2 == null) {
+			v2 = new Integer(0);
+		}
+		return v1.compareTo(v2);
+	}
+
+	/**
+	 * 判断两个整数是否相等
+	 *
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static boolean equal(Integer v1, Integer v2) {
+
+		int result = compareInt(v1, v2);
+		return result == 0;
+	}
+
+	/**
+	 * 判断两个整数不等
+	 *
+	 * @param v1
+	 * @param v2
+	 * @return
+	 */
+	public static boolean notEqual(Integer v1, Integer v2) {
+		int result = compareInt(v1, v2);
+		return result != 0;
+	}
+
+	/**
+	 * 实数的四舍五入函数
+	 *
+	 * @param v
+	 * @param scale
+	 * @return
+	 */
+	public static BigDecimal round(Object v, int scale) {
+		if (scale < 0) {
+			throw new IllegalArgumentException("四舍五入的位数不能为负数");
+		}
+		BigDecimal b = convert(v);
+		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);
+	}
+
+}

+ 52 - 0
src/main/resources/mapper/PriceMapper.xml

@@ -1,6 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei365.commodity.mapper.PriceMapper">
 <mapper namespace="com.caimei365.commodity.mapper.PriceMapper">
+    <select id="getIdentityByUserId" resultType="java.lang.Integer">
+        select userIdentity from user where userID = #{userId}
+    </select>
     <select id="getDetailPrice" resultType="com.caimei365.commodity.model.vo.PriceVo">
     <select id="getDetailPrice" resultType="com.caimei365.commodity.model.vo.PriceVo">
         select
         select
             p.productID as productId,
             p.productID as productId,
@@ -20,4 +23,53 @@
         from product p
         from product p
         where productID = #{productId}
         where productID = #{productId}
     </select>
     </select>
+    <select id="getListPriceByProductIds" resultType="com.caimei365.commodity.model.vo.PriceVo">
+        select
+            p.productID as productId,
+            p.price1 as price,
+            p.minBuyNumber as minBuyNumber,
+            p.price1TextFlag as priceFlag,
+            p.ladderPriceFlag as ladderPriceFlag,
+            p.normalPrice as normalPrice,
+            p.costPrice as costPrice,
+            p.costProportional as costProportional,
+            p.costCheckFlag as costCheckFlag,
+            p.step as step,
+            p.shopID as supplierId,
+            p.includedTax as includedTax,
+            p.invoiceType as invoiceType,
+            p.taxPoint as taxRate
+        from product as p
+        where productID IN
+          <foreach collection="productIds" open="(" separator="," close=")" item="productId">
+              #{productId}
+          </foreach>
+    </select>
+    <select id="findLowerLadderPrice" resultType="com.caimei365.commodity.model.vo.LadderPriceVo">
+        select
+        	id, productId, ladderNum, buyNum, buyPrice
+        from product_ladder_price
+        where productId = #{productId} and userType = 3 and delFlag = 0
+        order by ladderNum DESC
+        limit 1
+    </select>
+    <select id="findMaxLadderPrice" resultType="com.caimei365.commodity.model.vo.LadderPriceVo">
+        select
+        	id, productId, ladderNum, buyNum, buyPrice
+        from product_ladder_price
+        where productId = #{productId} and userType = 3 and delFlag = 0
+        order by ladderNum ASC
+        limit 1
+    </select>
+    <select id="getRepurchasePrice" resultType="java.lang.Double">
+        select
+          r.currentPrice
+        from repeat_purchase_price r
+        left join product p on p.productID = r.productId
+        where r.productId = #{productId} and userId = #{userId}
+        and ((p.costCheckFlag=1 and r.currentPrice <![CDATA[ >= ]]> p.costPrice) or p.costCheckFlag=2)
+        and p.price1 <![CDATA[ >= ]]> r.currentPrice
+        and r.delFlag = 0
+    </select>
+
 </mapper>
 </mapper>

+ 42 - 1
src/main/resources/mapper/PromotionsMapper.xml

@@ -1,5 +1,46 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei365.commodity.mapper.PromotionsMapper">
 <mapper namespace="com.caimei365.commodity.mapper.PromotionsMapper">
-
+    <select id="getPromotionsByProductId" resultType="com.caimei365.commodity.model.vo.PromotionsVo">
+        select pr.id,
+               pr.name,
+               pr.description,
+               pr.type,
+               pr.mode,
+               pr.touchPrice,
+               pr.reducedPrice,
+               pr.beginTime,
+               pr.endTime,
+               pr.status,
+               prp.productId,
+               prp.supplierId
+        from cm_promotions pr
+                 left join cm_promotions_product prp on pr.id = prp.promotionsId
+        where (prp.productId = #{productId} or
+               prp.supplierId = (select p.shopID from product p where p.productID = #{productId})
+            )
+          and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
+          and pr.delFlag not in (1,2)
+        order by pr.type desc
+        limit 1
+    </select>
+    <select id="getProductGifts" resultType="com.caimei365.commodity.model.vo.CartItemVo">
+		select
+			cpg.id as id,
+			p.productID as productId,
+			p.shopID as supplierId,
+			p.`name` as `name`,
+			p.mainImage as image,
+			cpg.number as number,
+			0 as price,
+			2 as productType,
+			p.price1 as originalPrice,
+			p.unit as unit,
+			p.validFlag as validFlag,
+			p.stock as stock
+		from product p
+		left join cm_promotions_gift cpg on cpg.productId = p.productID
+		where cpg.promotionsId = #{promotionsId}
+		order by cpg.addTime desc
+    </select>
 </mapper>
 </mapper>