|
@@ -7,6 +7,7 @@ import com.caimei365.commodity.model.dto.Sku;
|
|
|
import com.caimei365.commodity.model.vo.*;
|
|
|
import com.caimei365.commodity.utils.ImageUtils;
|
|
|
import com.caimei365.commodity.utils.MathUtil;
|
|
|
+import com.google.common.util.concurrent.AtomicDouble;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -18,6 +19,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
@@ -86,11 +88,11 @@ public class PriceUtilService {
|
|
|
|
|
|
/**
|
|
|
* 根据用户id设置详细价格
|
|
|
- *
|
|
|
+ * ind=1不屏蔽价格
|
|
|
* @param price 商品价格类
|
|
|
* @param userId 用户Id
|
|
|
*/
|
|
|
- public void setPriceByUserId(PriceVo price, Integer userId) {
|
|
|
+ public void setPriceByUserId(PriceVo price, Integer userId, Integer ind) {
|
|
|
// 根据用户Id查询用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构
|
|
|
Integer identity = priceMapper.getIdentityByUserId(userId);
|
|
|
if (null == identity) {
|
|
@@ -127,19 +129,20 @@ public class PriceUtilService {
|
|
|
// 设置价格标志(协销|价格公开|仅对医美机构公开|仅对会员机构公开|供应商自己的商品)
|
|
|
boolean setFlag = identity == 1 || priceFlag == 0 || (priceFlag == 3 && clubType == 1) || (priceFlag == 2 && (identity == 2 || isSuperVip)) || isShopOwn;
|
|
|
|
|
|
- List<Sku> skus = price.getSkus();
|
|
|
- if (null == skus || skus.size() < 1) {
|
|
|
- List<Sku> skuList = priceMapper.findSkus(price.getProductId());
|
|
|
- price.setSkus(skuList);
|
|
|
- skus = skuList;
|
|
|
- }
|
|
|
-
|
|
|
- AtomicBoolean ladderFlag= new AtomicBoolean(false);
|
|
|
+ List<Sku> skus = priceMapper.findSkus(price.getProductId());
|
|
|
+ AtomicDouble atomicDouble = new AtomicDouble();
|
|
|
+ atomicDouble.set(skus.get(0).getPrice());
|
|
|
+ int size = skus.size();
|
|
|
+ //税费标志
|
|
|
+ boolean taxFlag = "0".equals(price.getIncludedTax()) && ("1".equals(price.getInvoiceType()) || "2".equals(price.getInvoiceType()));
|
|
|
+ //未设置价格
|
|
|
+ price.setLadderPriceFlag(0);
|
|
|
+ price.setPrice(skus.get(0).getPrice());
|
|
|
+ price.setSkuId(skus.get(0).getSkuId());
|
|
|
+ price.setMinBuyNumber(skus.get(0).getMinBuyNumber());
|
|
|
+ price.setUnit(skus.get(0).getUnit());
|
|
|
+ price.setStock(skus.get(0).getStock());
|
|
|
skus.forEach(s -> {
|
|
|
- // 设置划线价
|
|
|
- s.setOriginalPrice(s.getPrice());
|
|
|
- //税费标志
|
|
|
- boolean taxFlag = "0".equals(price.getIncludedTax()) && ("1".equals(price.getInvoiceType()) || "2".equals(price.getInvoiceType()));
|
|
|
if (1 == price.getSvipProductFlag()) {
|
|
|
// 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
|
|
|
s.setLadderPriceFlag(0);
|
|
@@ -150,14 +153,18 @@ public class PriceUtilService {
|
|
|
price.setSvipPriceTag(MathUtil.div(price.getSvipDiscount(), 10, 1) + "折");
|
|
|
if (isSuperVip) {
|
|
|
// 超级会员用户设置优惠价
|
|
|
+ price.setOriginalPrice(atomicDouble.get());
|
|
|
+ s.setOriginalPrice(s.getPrice());
|
|
|
svipDiscountPrice = MathUtil.div(MathUtil.mul(s.getPrice(), price.getSvipDiscount()), 100, 2);
|
|
|
s.setPrice(svipDiscountPrice.doubleValue());
|
|
|
+ price.setPrice(svipDiscountPrice.doubleValue());
|
|
|
}
|
|
|
} else if (2 == price.getSvipPriceType()) {
|
|
|
// 直接优惠价
|
|
|
if (isSuperVip) {
|
|
|
// 超级会员用户设置优惠价
|
|
|
s.setPrice(svipDiscountPrice.doubleValue());
|
|
|
+ price.setPrice(svipDiscountPrice.doubleValue());
|
|
|
}
|
|
|
if (taxFlag) {
|
|
|
//添加税费
|
|
@@ -176,40 +183,58 @@ public class PriceUtilService {
|
|
|
promotions.setGiftList(giftList);
|
|
|
}
|
|
|
if (promotions.getType() == 1 && promotions.getMode() == 1 && null != promotions.getTouchPrice()) {
|
|
|
+ s.setOriginalPrice(s.getPrice());
|
|
|
+ price.setOriginalPrice(atomicDouble.get());
|
|
|
s.setPrice(promotions.getTouchPrice());
|
|
|
+ price.setPrice(promotions.getTouchPrice());
|
|
|
}
|
|
|
price.setPromotions(promotions);
|
|
|
} else {
|
|
|
if (null != userId) {
|
|
|
if (1 == s.getLadderPriceFlag()) {
|
|
|
- // 阶梯价
|
|
|
- LadderPriceVo lowerPrice = priceMapper.findLowerLadderPrice(s.getSkuId());
|
|
|
+ // sku的阶梯价
|
|
|
LadderPriceVo lowerBuyNum = priceMapper.findMaxLadderPrice(s.getSkuId());
|
|
|
- if (null != lowerPrice) {
|
|
|
- if (null != lowerBuyNum) {
|
|
|
- s.setMinBuyNumber(lowerBuyNum.getBuyNum());
|
|
|
- s.setPrice(lowerBuyNum.getBuyPrice());
|
|
|
- s.setStock(lowerBuyNum.getStock());
|
|
|
- s.setUnit(lowerBuyNum.getUnit());
|
|
|
- }
|
|
|
- } else {
|
|
|
- s.setLadderPriceFlag(0);
|
|
|
- }
|
|
|
+ s.setMinBuyNumber(lowerBuyNum.getBuyNum());
|
|
|
+ s.setPrice(lowerBuyNum.getBuyPrice());
|
|
|
+ s.setStock(lowerBuyNum.getStock());
|
|
|
+ s.setUnit(lowerBuyNum.getUnit());
|
|
|
List<LadderPriceVo> ladderPrices = priceMapper.getLadderPricesByProductId(s.getSkuId());
|
|
|
TaxVo tax = priceMapper.getTaxByProductId(price.getProductId());
|
|
|
if (!CollectionUtils.isEmpty(ladderPrices)) {
|
|
|
setLadderPriceList(ladderPrices, tax);
|
|
|
}
|
|
|
s.setLadderPriceList(ladderPrices);
|
|
|
- ladderFlag.set(true);
|
|
|
price.setLadderPriceFlag(1);
|
|
|
- price.setSkuId(ladderPrices.get(0).getSkuId());
|
|
|
- price.setPrice(ladderPrices.get(0).getBuyPrice());
|
|
|
- price.setMinBuyNumber(ladderPrices.get(0).getBuyNum());
|
|
|
- price.setStock(ladderPrices.get(0).getStock());
|
|
|
- price.setUnit(ladderPrices.get(0).getUnit());
|
|
|
+ if (1 == size) {
|
|
|
+ //1.对于只有一个SKU的商品,各个商品列表直接显示机构价即可:若是阶梯价,则显示第一级阶梯的价格:
|
|
|
+ price.setSkuId(ladderPrices.get(0).getSkuId());
|
|
|
+ price.setPrice(ladderPrices.get(0).getBuyPrice());
|
|
|
+ price.setMinBuyNumber(ladderPrices.get(0).getBuyNum());
|
|
|
+ price.setStock(ladderPrices.get(0).getStock());
|
|
|
+ price.setUnit(ladderPrices.get(0).getUnit());
|
|
|
+ } else {
|
|
|
+ //2.对于有多个SKU的商品,各个商品列表显示所有SKU中最低的价格:
|
|
|
+ // 若SKU中,全部都是阶梯价,则显示所有SKU中第一级阶梯的价格中的最低价,
|
|
|
+ // 若SKU中,使用阶梯价和不使用阶梯价(只是用机构价》并存,则用机构价和第一级阶梯价比大小,展示最小的价格
|
|
|
+ // skuid分组取第一阶梯中最便宜的
|
|
|
+ ProductItemVo lowLadderPrice = priceMapper.findLowPriceOfAll(price.getProductId());
|
|
|
+ ProductItemVo lowAllPrice = priceMapper.findLowPriceOfPrice(price.getProductId());
|
|
|
+ if (null != lowLadderPrice) {
|
|
|
+ ProductItemVo productItemVo = lowLadderPrice.getPrice() > lowAllPrice.getPrice() ? lowAllPrice : lowLadderPrice;
|
|
|
+ price.setPrice(productItemVo.getPrice());
|
|
|
+ price.setSkuId(productItemVo.getSkuId());
|
|
|
+ price.setMinBuyNumber(productItemVo.getMinBuyNumber());
|
|
|
+ price.setUnit(productItemVo.getUnit());
|
|
|
+ price.setStock(productItemVo.getStock());
|
|
|
+ } else {
|
|
|
+ price.setPrice(lowAllPrice.getPrice());
|
|
|
+ price.setSkuId(lowAllPrice.getSkuId());
|
|
|
+ price.setMinBuyNumber(lowAllPrice.getMinBuyNumber());
|
|
|
+ price.setUnit(lowAllPrice.getUnit());
|
|
|
+ price.setStock(lowAllPrice.getStock());
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
- price.setLadderPriceFlag(0);
|
|
|
// 复购价
|
|
|
Double repurchase = priceMapper.getRepurchasePrice(s.getSkuId(), userId);
|
|
|
if (null != repurchase && repurchase > 0) {
|
|
@@ -228,16 +253,16 @@ public class PriceUtilService {
|
|
|
s.setOriginalPrice(MathUtil.add(s.getOriginalPrice(), originalTaxFee).doubleValue());
|
|
|
}
|
|
|
});
|
|
|
- //给一个默认的最低价和最低起订量
|
|
|
- if(!ladderFlag.get()){
|
|
|
- price.setPrice(skus.get(0).getPrice());
|
|
|
- price.setSkuId(skus.get(0).getSkuId());
|
|
|
- price.setMinBuyNumber(skus.get(0).getMinBuyNumber());
|
|
|
- price.setUnit(skus.get(0).getUnit());
|
|
|
- price.setStock(skus.get(0).getStock());
|
|
|
+ // price添加税费
|
|
|
+ if (taxFlag) {
|
|
|
+ BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(price.getPrice(), price.getTaxRate()), 100, 2);
|
|
|
+ price.setPrice(MathUtil.add(price.getPrice(), thisTaxFee).doubleValue());
|
|
|
+ BigDecimal originalTaxFee = MathUtil.div(MathUtil.mul(price.getOriginalPrice(), price.getTaxRate()), 100, 2);
|
|
|
+ price.setOriginalPrice(MathUtil.add(price.getOriginalPrice(), originalTaxFee).doubleValue());
|
|
|
}
|
|
|
price.setSkus(skus);
|
|
|
- if (!setFlag) {
|
|
|
+ // 身份不对
|
|
|
+ if (!setFlag && 1 != ind) {
|
|
|
price.setSkus(priceMapper.findSkusOutOfPrice(price.getProductId()));
|
|
|
price.setUserIdentity(0);
|
|
|
if (null != promotions) {
|
|
@@ -250,21 +275,23 @@ public class PriceUtilService {
|
|
|
price.setActStatus(0);
|
|
|
}
|
|
|
}
|
|
|
+ log.info("看看pirce----------------"+price);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置商品主图及价格
|
|
|
+ * ind=1不屏蔽价格
|
|
|
*
|
|
|
* @param userId 用户Id
|
|
|
* @param product ProductItemVo
|
|
|
*/
|
|
|
- public void setProductDetails(Integer userId, ProductItemVo product) {
|
|
|
+ public void setProductDetails(Integer userId, ProductItemVo product, Integer ind) {
|
|
|
// 设置图片
|
|
|
product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
|
|
|
// 数据库获取基本价格信息
|
|
|
PriceVo price = priceMapper.getDetailPrice(product.getProductId());
|
|
|
// 根据用户id设置详细价格
|
|
|
- setPriceByUserId(price, userId);
|
|
|
+ setPriceByUserId(price, userId, ind);
|
|
|
// 设置价格
|
|
|
product.setActStatus(price.getActStatus());
|
|
|
product.setPromotions(price.getPromotions());
|