|
@@ -2,6 +2,8 @@ package com.caimei365.commodity.service.impl;
|
|
|
|
|
|
import com.caimei365.commodity.mapper.*;
|
|
|
import com.caimei365.commodity.model.ResponseJson;
|
|
|
+import com.caimei365.commodity.model.dto.HeHeSku;
|
|
|
+import com.caimei365.commodity.model.dto.Sku;
|
|
|
import com.caimei365.commodity.model.po.*;
|
|
|
import com.caimei365.commodity.model.vo.*;
|
|
|
import com.caimei365.commodity.service.HeheService;
|
|
@@ -12,6 +14,7 @@ import com.caimei365.commodity.utils.MathUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.aspectj.weaver.ast.Var;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -20,7 +23,6 @@ import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
|
|
|
-import static com.alibaba.fastjson.JSON.parseArray;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -43,8 +45,6 @@ public class HeheServiceImpl implements HeheService {
|
|
|
private ShopMapper shopMapper;
|
|
|
@Resource
|
|
|
private SecondHandMapper secondHandMapper;
|
|
|
- @Autowired
|
|
|
- private PageService pageService;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -169,23 +169,6 @@ public class HeheServiceImpl implements HeheService {
|
|
|
//相关参数
|
|
|
List<ProductParameterPo> parametersList = shopMapper.getProductParameters(productId);
|
|
|
product.setParametersList(parametersList);
|
|
|
- // 商城活动id
|
|
|
- Integer activityId = heheMapper.getActivityIdByProductId(product.getProductId());
|
|
|
- //税费
|
|
|
- boolean addTaxFlag = ("0".equals(product.getIncludedTax()) && ("1".equals(product.getInvoiceType()) || "2".equals(product.getInvoiceType())));
|
|
|
- if (activityId != null && activityId > 0) {
|
|
|
- //活动阶梯
|
|
|
- List<LadderPriceVo> ladderList = heheMapper.getActivityLadderList(activityId, product.getProductId());
|
|
|
- if (addTaxFlag && null != ladderList && ladderList.size() > 0) {
|
|
|
- ladderList.forEach(ladder->{
|
|
|
- BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(ladder.getBuyPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
|
|
|
- BigDecimal price = MathUtil.add(ladder.getBuyPrice(), addedValueTax);
|
|
|
- ladder.setBuyPrice(price.doubleValue());
|
|
|
- });
|
|
|
- }
|
|
|
- // 设置阶梯列表
|
|
|
- product.setLadderList(ladderList);
|
|
|
- }
|
|
|
setProductInfo(product, userId);
|
|
|
return ResponseJson.success(product);
|
|
|
}
|
|
@@ -198,45 +181,69 @@ public class HeheServiceImpl implements HeheService {
|
|
|
|
|
|
private void setProductInfo(HeheProductVo product, Integer userId) {
|
|
|
product.setMainImage(ImageUtils.getImageURL("product", product.getMainImage(), 0, domain));
|
|
|
+ //设置sku
|
|
|
+ List<HeHeSku> heheSkus = heheMapper.findHeheSkus(product.getProductId());
|
|
|
+ heheSkus.forEach(s -> setProductInfoBySku(product, userId, s));
|
|
|
+ //选最低价作为展示
|
|
|
+ heheSkus.sort(Comparator.comparing(HeHeSku::getPrice));
|
|
|
+ //product设值
|
|
|
+ product.setSkus(heheSkus);
|
|
|
+ HeHeSku heHeSku = heheSkus.get(0);
|
|
|
+ product.setPrice(heHeSku.getPrice());
|
|
|
+ product.setSkuId(heHeSku.getSkuId());
|
|
|
+ product.setActiveStatus(null != heHeSku.getActiveStatus() ? heHeSku.getActiveStatus() : null);
|
|
|
+ product.setCollageStatus(null != heHeSku.getCollageStatus() ? heHeSku.getCollageStatus() : null);
|
|
|
+ product.setCollageProduct(null != heHeSku.getCollageProduct() ? heHeSku.getCollageProduct() : null);
|
|
|
+ product.setDiscountStatus(null != heHeSku.getDiscountStatus() ? heHeSku.getDiscountStatus() : null);
|
|
|
+ product.setDiscountEndTime(null != heHeSku.getDiscountEndTime() ? heHeSku.getDiscountEndTime() : null);
|
|
|
+ product.setCouponStatus(null != heHeSku.getCouponStatus() ? heHeSku.getCouponStatus() : null);
|
|
|
+ product.setCouponPrice(null != heHeSku.getCouponPrice() ? heHeSku.getCouponPrice() : null);
|
|
|
+ product.setNormalPrice(null != heHeSku.getNormalPrice() ? heHeSku.getNormalPrice() : null);
|
|
|
+ product.setNormalCouponPrice(null != heHeSku.getNormalCouponPrice() ? heHeSku.getNormalCouponPrice() : null);
|
|
|
+ product.setCouponId(null != heHeSku.getCouponId() ? heHeSku.getCouponId() : null);
|
|
|
+ product.setCouponInfo(null != heHeSku.getCouponInfo() ? heHeSku.getCouponInfo() : null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setProductInfoBySku(HeheProductVo product, Integer userId, HeHeSku sku) {
|
|
|
// 活动id
|
|
|
Integer activityId = heheMapper.getActivityIdByProductId(product.getProductId());
|
|
|
// 拼团商品
|
|
|
- HeheCollageProductPo collageProduct = heheMapper.getCollageProduct(product.getProductId());
|
|
|
+ HeheCollageProductPo collageProduct = heheMapper.getCollageProduct(sku.getSkuId());
|
|
|
// 限时特价
|
|
|
- HeheDiscountPricePo discountPrice = heheMapper.getDiscountPrice(product.getProductId());
|
|
|
+ HeheDiscountPricePo discountPrice = heheMapper.getDiscountPrice(sku.getSkuId());
|
|
|
// 内部优惠折扣
|
|
|
HeHeDiscountVo discount = heheMapper.getProductDiscount(product.getProductId(), userId);
|
|
|
if (activityId != null && activityId > 0) {
|
|
|
- product.setActiveStatus(1);
|
|
|
+ sku.setActiveStatus(1);
|
|
|
//活动阶梯
|
|
|
- List<LadderPriceVo> ladderList = heheMapper.getActivityLadderList(activityId, product.getProductId());
|
|
|
+ List<LadderPriceVo> ladderList = heheMapper.getActivityLadderList(activityId, sku.getSkuId());
|
|
|
if (ladderList != null && ladderList.size() > 0) {
|
|
|
LadderPriceVo ladder = ladderList.get(0);
|
|
|
// 没有起订量概念,默认显示购买1个商品的价格,若第一阶梯为一个商品,则取第一阶梯价格
|
|
|
- product.setPrice(1 == ladder.getBuyNum() ? new BigDecimal(ladder.getBuyPrice()) : product.getPrice());
|
|
|
+ sku.setPrice(1 == ladder.getBuyNum() ? new BigDecimal(ladder.getBuyPrice()) : product.getPrice());
|
|
|
}
|
|
|
} else if (collageProduct != null) {
|
|
|
// 拼团价
|
|
|
- product.setPrice(collageProduct.getPrice());
|
|
|
- product.setCollageStatus(1);
|
|
|
- product.setCollageProduct(collageProduct);
|
|
|
+ sku.setPrice(collageProduct.getPrice());
|
|
|
+ sku.setCollageStatus(1);
|
|
|
+ sku.setCollageProduct(collageProduct);
|
|
|
} else if (discountPrice != null) {
|
|
|
// 限时特价
|
|
|
- product.setPrice(discountPrice.getDiscountPrice());
|
|
|
- product.setDiscountStatus(1);
|
|
|
- product.setDiscountEndTime(discountPrice.getOfflineTime());
|
|
|
+ sku.setPrice(discountPrice.getDiscountPrice());
|
|
|
+ sku.setDiscountStatus(1);
|
|
|
+ sku.setDiscountEndTime(discountPrice.getOfflineTime());
|
|
|
} else if (discount != null) {
|
|
|
BigDecimal price = product.getPrice();
|
|
|
// 折扣价
|
|
|
BigDecimal disPrice = discount.getDiscountPrice();
|
|
|
// 折扣率
|
|
|
Integer dis = discount.getDiscount();
|
|
|
- if (null != disPrice && disPrice.compareTo(BigDecimal.ZERO)>0) {
|
|
|
+ if (null != disPrice && disPrice.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
price = disPrice;
|
|
|
} else if (null != dis && dis > 0) {
|
|
|
price = MathUtil.div(MathUtil.mul(product.getPrice(), dis), 100);
|
|
|
}
|
|
|
- product.setPrice(price);
|
|
|
+ sku.setPrice(price);
|
|
|
}
|
|
|
//税费
|
|
|
boolean addTaxFlag = ("0".equals(product.getIncludedTax()) && ("1".equals(product.getInvoiceType()) || "2".equals(product.getInvoiceType())));
|
|
@@ -244,11 +251,11 @@ public class HeheServiceImpl implements HeheService {
|
|
|
// 售价税费
|
|
|
BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(product.getPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
|
|
|
BigDecimal price = MathUtil.add(product.getPrice(), addedValueTax);
|
|
|
- product.setPrice(price);
|
|
|
+ sku.setPrice(price);
|
|
|
// 原价税费
|
|
|
addedValueTax = MathUtil.div(MathUtil.mul(product.getNormalPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
|
|
|
price = MathUtil.add(product.getNormalPrice(), addedValueTax);
|
|
|
- product.setNormalPrice(price);
|
|
|
+ sku.setNormalPrice(price);
|
|
|
}
|
|
|
// 查询用户的注册时间
|
|
|
Date registerTime = heheMapper.getUserRegisterTime(userId);
|
|
@@ -267,7 +274,7 @@ public class HeheServiceImpl implements HeheService {
|
|
|
List<HeheCouponVo> unableCouponList = new ArrayList<>();
|
|
|
if (couponList.size() > 0) {
|
|
|
// 有可用优惠券
|
|
|
- couponList.forEach(coupon->{
|
|
|
+ couponList.forEach(coupon -> {
|
|
|
if (1 == coupon.getNoThresholdFlag() || MathUtil.compare(product.getPrice(), coupon.getTouchPrice()) >= 0) {
|
|
|
ableCouponList.add(coupon);
|
|
|
} else {
|
|
@@ -279,36 +286,26 @@ public class HeheServiceImpl implements HeheService {
|
|
|
ableCouponList.sort((o1, o2) -> o2.getCouponAmount().compareTo(o1.getCouponAmount()));
|
|
|
HeheCouponVo biggestCoupon = ableCouponList.get(0);
|
|
|
// 现价-最大优惠金额=券后价
|
|
|
- product.setCouponPrice(MathUtil.sub(product.getPrice(), biggestCoupon.getCouponAmount()));
|
|
|
+ sku.setCouponPrice(MathUtil.sub(sku.getPrice(), biggestCoupon.getCouponAmount()));
|
|
|
// 原价-最大优惠金额=原价券后价
|
|
|
- product.setNormalCouponPrice(MathUtil.sub(product.getNormalPrice(), biggestCoupon.getCouponAmount()));
|
|
|
+ sku.setNormalCouponPrice(MathUtil.sub(sku.getNormalPrice(), biggestCoupon.getCouponAmount()));
|
|
|
//这张优惠券未领取才返回优惠券id显示领券购买
|
|
|
if (null != biggestCoupon.getUseStatus() && 0 == biggestCoupon.getUseStatus()) {
|
|
|
- product.setCouponId(biggestCoupon.getCouponId());
|
|
|
+ sku.setCouponId(biggestCoupon.getCouponId());
|
|
|
}
|
|
|
// 券后价标签
|
|
|
- product.setCouponStatus(1);
|
|
|
+ sku.setCouponStatus(1);
|
|
|
} else {
|
|
|
// 根据优惠条件排序,条件小的排前面
|
|
|
unableCouponList.sort(Comparator.comparing(HeheCouponVo::getTouchPrice));
|
|
|
// 优惠券信息
|
|
|
- product.setCouponStatus(2);
|
|
|
+ sku.setCouponStatus(2);
|
|
|
HeheCouponVo smallestCoupon = unableCouponList.get(0);
|
|
|
- product.setCouponInfo("券|满" + smallestCoupon.getTouchPrice() + "元减" + smallestCoupon.getCouponAmount());
|
|
|
+ sku.setCouponInfo("券|满" + smallestCoupon.getTouchPrice() + "元减" + smallestCoupon.getCouponAmount());
|
|
|
}
|
|
|
}
|
|
|
- if (1 == product.getActiveStatus() || 1 == product.getCollageStatus() || 1 == product.getDiscountStatus()) {
|
|
|
- if (1 != product.getCollageStatus() && product.getPrice().compareTo(product.getNormalPrice()) == 0) {
|
|
|
- // 原价与售价相同,不显示原价
|
|
|
- product.setNormalPrice(BigDecimal.ZERO);
|
|
|
- }
|
|
|
- } else if (product.getCouponPrice().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- // 不参与任何活动且未使用优惠券,不显示原价
|
|
|
- product.setNormalPrice(BigDecimal.ZERO);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 设置楼层相关图片的商品信息
|
|
|
*/
|
|
@@ -333,6 +330,7 @@ public class HeheServiceImpl implements HeheService {
|
|
|
|
|
|
/**
|
|
|
* 设置跳转参数
|
|
|
+ *
|
|
|
* @param floorContent
|
|
|
*/
|
|
|
private void setFloorLinkType(FloorContentVo floorContent) {
|