|
@@ -14,6 +14,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
@@ -125,106 +126,119 @@ public class PriceUtilService {
|
|
|
}
|
|
|
// 设置价格标志(协销|价格公开|仅对医美机构公开|仅对会员机构公开|供应商自己的商品)
|
|
|
boolean setFlag = identity == 1 || priceFlag == 0 || (priceFlag == 3 && clubType == 1) || (priceFlag == 2 && (identity == 2 || isSuperVip)) || isShopOwn;
|
|
|
- if (setFlag) {
|
|
|
- List<Sku> skus = price.getSkus();
|
|
|
- if (null == skus || skus.size() < 1) {
|
|
|
- List<Sku> skuList = priceMapper.findSkus(price.getProductId());
|
|
|
- price.setSkus(skuList);
|
|
|
- skus = skuList;
|
|
|
- }
|
|
|
- //给一个默认的最低价和最低起订量
|
|
|
- price.setPrice(skus.get(0).getPrice());
|
|
|
- price.setSkuId(skus.get(0).getSkuId());
|
|
|
- price.setMinBuyNumber(skus.get(0).getMinBuyNumber());
|
|
|
- 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);
|
|
|
- // 超级会员优惠价
|
|
|
- BigDecimal svipDiscountPrice = price.getSvipDiscountPrice();
|
|
|
- if (1 == price.getSvipPriceType()) {
|
|
|
- // 折扣价
|
|
|
- price.setSvipPriceTag(MathUtil.div(price.getSvipDiscount(), 10, 1) + "折");
|
|
|
- if (isSuperVip) {
|
|
|
- // 超级会员用户设置优惠价
|
|
|
- svipDiscountPrice = MathUtil.div(MathUtil.mul(s.getPrice(), price.getSvipDiscount()), 100, 2);
|
|
|
- s.setPrice(svipDiscountPrice.doubleValue());
|
|
|
- }
|
|
|
- } else if (2 == price.getSvipPriceType()) {
|
|
|
- // 直接优惠价
|
|
|
- if (isSuperVip) {
|
|
|
- // 超级会员用户设置优惠价
|
|
|
- s.setPrice(svipDiscountPrice.doubleValue());
|
|
|
- }
|
|
|
- if (taxFlag) {
|
|
|
- //添加税费
|
|
|
- BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(svipDiscountPrice, price.getTaxRate()), 100, 2);
|
|
|
- svipDiscountPrice = MathUtil.add(svipDiscountPrice, thisTaxFee);
|
|
|
- }
|
|
|
- price.setSvipPriceTag("¥" + svipDiscountPrice);
|
|
|
+
|
|
|
+ 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);
|
|
|
+ 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);
|
|
|
+ // 超级会员优惠价
|
|
|
+ BigDecimal svipDiscountPrice = price.getSvipDiscountPrice();
|
|
|
+ if (1 == price.getSvipPriceType()) {
|
|
|
+ // 折扣价
|
|
|
+ price.setSvipPriceTag(MathUtil.div(price.getSvipDiscount(), 10, 1) + "折");
|
|
|
+ if (isSuperVip) {
|
|
|
+ // 超级会员用户设置优惠价
|
|
|
+ svipDiscountPrice = MathUtil.div(MathUtil.mul(s.getPrice(), price.getSvipDiscount()), 100, 2);
|
|
|
+ s.setPrice(svipDiscountPrice.doubleValue());
|
|
|
}
|
|
|
- } else if (null != promotions) {
|
|
|
- // 促销活动
|
|
|
- price.setActStatus(1);
|
|
|
- s.setLadderPriceFlag(0);
|
|
|
- if (promotions.getMode() == 3) {
|
|
|
- // 获取赠品
|
|
|
- List<ProductItemVo> giftList = promotionsMapper.getPromotionGifts(promotions.getId());
|
|
|
- promotions.setGiftList(giftList);
|
|
|
+ } else if (2 == price.getSvipPriceType()) {
|
|
|
+ // 直接优惠价
|
|
|
+ if (isSuperVip) {
|
|
|
+ // 超级会员用户设置优惠价
|
|
|
+ s.setPrice(svipDiscountPrice.doubleValue());
|
|
|
}
|
|
|
- if (promotions.getType() == 1 && promotions.getMode() == 1 && null != promotions.getTouchPrice()) {
|
|
|
- s.setPrice(promotions.getTouchPrice());
|
|
|
+ if (taxFlag) {
|
|
|
+ //添加税费
|
|
|
+ BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(svipDiscountPrice, price.getTaxRate()), 100, 2);
|
|
|
+ svipDiscountPrice = MathUtil.add(svipDiscountPrice, thisTaxFee);
|
|
|
}
|
|
|
- price.setPromotions(promotions);
|
|
|
- } else {
|
|
|
- if (null != userId) {
|
|
|
- if (1 == s.getLadderPriceFlag()) {
|
|
|
- // 阶梯价
|
|
|
- LadderPriceVo lowerPrice = priceMapper.findLowerLadderPrice(s.getSkuId());
|
|
|
- LadderPriceVo lowerBuyNum = priceMapper.findMaxLadderPrice(s.getSkuId());
|
|
|
- if (null != lowerPrice) {
|
|
|
- if (null != lowerBuyNum) {
|
|
|
- s.setMinBuyNumber(lowerBuyNum.getBuyNum());
|
|
|
- s.setPrice(lowerBuyNum.getBuyPrice());
|
|
|
- }
|
|
|
- } else {
|
|
|
- s.setLadderPriceFlag(0);
|
|
|
- }
|
|
|
- List<LadderPriceVo> ladderPrices = priceMapper.getLadderPricesByProductId(s.getSkuId());
|
|
|
- TaxVo tax = priceMapper.getTaxByProductId(price.getProductId());
|
|
|
- if (!CollectionUtils.isEmpty(ladderPrices)) {
|
|
|
- setLadderPriceList(ladderPrices, tax);
|
|
|
+ price.setSvipPriceTag("¥" + svipDiscountPrice);
|
|
|
+ }
|
|
|
+ } else if (null != promotions) {
|
|
|
+ // 促销活动
|
|
|
+ price.setActStatus(1);
|
|
|
+ s.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()) {
|
|
|
+ s.setPrice(promotions.getTouchPrice());
|
|
|
+ }
|
|
|
+ price.setPromotions(promotions);
|
|
|
+ } else {
|
|
|
+ if (null != userId) {
|
|
|
+ if (1 == s.getLadderPriceFlag()) {
|
|
|
+ // 阶梯价
|
|
|
+ LadderPriceVo lowerPrice = priceMapper.findLowerLadderPrice(s.getSkuId());
|
|
|
+ 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());
|
|
|
}
|
|
|
- s.setLadderPriceList(ladderPrices);
|
|
|
- price.setLadderPriceFlag(1);
|
|
|
- price.setPrice(lowerPrice.getBuyPrice());
|
|
|
- price.setMinBuyNumber(lowerPrice.getBuyNum());
|
|
|
} else {
|
|
|
- price.setLadderPriceFlag(0);
|
|
|
- // 复购价
|
|
|
- Double repurchase = priceMapper.getRepurchasePrice(s.getSkuId(), userId);
|
|
|
- if (null != repurchase && repurchase > 0) {
|
|
|
- s.setPrice(repurchase);
|
|
|
- s.setRepurchaseFlag(1);
|
|
|
- s.setLadderPriceFlag(0);
|
|
|
- }
|
|
|
+ s.setLadderPriceFlag(0);
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ } else {
|
|
|
+ price.setLadderPriceFlag(0);
|
|
|
+ // 复购价
|
|
|
+ Double repurchase = priceMapper.getRepurchasePrice(s.getSkuId(), userId);
|
|
|
+ if (null != repurchase && repurchase > 0) {
|
|
|
+ s.setPrice(repurchase);
|
|
|
+ s.setRepurchaseFlag(1);
|
|
|
+ s.setLadderPriceFlag(0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //添加税费
|
|
|
- if (taxFlag) {
|
|
|
- BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(s.getPrice(), price.getTaxRate()), 100, 2);
|
|
|
- s.setPrice(MathUtil.add(s.getPrice(), thisTaxFee).doubleValue());
|
|
|
- BigDecimal originalTaxFee = MathUtil.div(MathUtil.mul(s.getOriginalPrice(), price.getTaxRate()), 100, 2);
|
|
|
- s.setOriginalPrice(MathUtil.add(s.getOriginalPrice(), originalTaxFee).doubleValue());
|
|
|
- }
|
|
|
- });
|
|
|
- price.setSkus(skus);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ //添加税费
|
|
|
+ if (taxFlag) {
|
|
|
+ BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(s.getPrice(), price.getTaxRate()), 100, 2);
|
|
|
+ s.setPrice(MathUtil.add(s.getPrice(), thisTaxFee).doubleValue());
|
|
|
+ BigDecimal originalTaxFee = MathUtil.div(MathUtil.mul(s.getOriginalPrice(), price.getTaxRate()), 100, 2);
|
|
|
+ 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.setSkus(skus);
|
|
|
+ if (!setFlag) {
|
|
|
+ price.setSkus(priceMapper.findSkusOutOfPrice(price.getProductId()));
|
|
|
price.setUserIdentity(0);
|
|
|
if (null != promotions) {
|
|
|
price.setActStatus(1);
|
|
@@ -247,45 +261,8 @@ public class PriceUtilService {
|
|
|
public void setProductDetails(Integer userId, ProductItemVo product) {
|
|
|
// 设置图片
|
|
|
product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
|
|
|
- // 设置sku
|
|
|
- List<Sku> skus = priceMapper.findSkus(product.getProductId());
|
|
|
- AtomicBoolean lowPrice = new AtomicBoolean(false);
|
|
|
- skus.forEach(s -> {
|
|
|
- // 设置价格等级
|
|
|
- s.setPriceGrade(getPriceGrade(s.getPrice()));
|
|
|
- s.setOriginalPrice(s.getPrice());
|
|
|
- if (1 == s.getLadderPriceFlag()) {
|
|
|
- List<LadderPriceVo> ladderPrices = priceMapper.getLadderPricesByProductId(s.getSkuId());
|
|
|
- TaxVo tax = priceMapper.getTaxByProductId(product.getProductId());
|
|
|
- if (!CollectionUtils.isEmpty(ladderPrices)) {
|
|
|
- setLadderPriceList(ladderPrices, tax);
|
|
|
- }
|
|
|
- s.setLadderPriceList(ladderPrices);
|
|
|
- lowPrice.set(true);
|
|
|
- }
|
|
|
- });
|
|
|
- //设置展示的默认最低价和展示最低价的规格
|
|
|
- if (lowPrice.get()) {
|
|
|
- ProductItemVo showProduct = priceMapper.findLowPrice(product.getProductId());
|
|
|
- product.setSkuId(showProduct.getSkuId());
|
|
|
- product.setPrice(showProduct.getPrice());
|
|
|
- product.setOriginalPrice(showProduct.getPrice());
|
|
|
- product.setUnit(showProduct.getUnit());
|
|
|
- product.setMinBuyNumber(showProduct.getMinBuyNumber());
|
|
|
- product.setPriceGrade(getPriceGrade(showProduct.getPrice()));
|
|
|
- } else {
|
|
|
- List<Sku> collect = skus.stream().sorted(Comparator.comparing(Sku::getPrice)).collect(Collectors.toList());
|
|
|
- product.setSkuId(collect.get(0).getSkuId());
|
|
|
- product.setPrice(collect.get(0).getPrice());
|
|
|
- product.setOriginalPrice(collect.get(0).getPrice());
|
|
|
- product.setUnit(collect.get(0).getUnit());
|
|
|
- product.setMinBuyNumber(collect.get(0).getMinBuyNumber());
|
|
|
- product.setPriceGrade(getPriceGrade(collect.get(0).getPrice()));
|
|
|
- }
|
|
|
- product.setSkus(skus);
|
|
|
// 数据库获取基本价格信息
|
|
|
PriceVo price = priceMapper.getDetailPrice(product.getProductId());
|
|
|
- price.setSkus(skus);
|
|
|
// 根据用户id设置详细价格
|
|
|
setPriceByUserId(price, userId);
|
|
|
// 设置价格
|
|
@@ -294,6 +271,14 @@ public class PriceUtilService {
|
|
|
product.setUserIdentity(price.getUserIdentity());
|
|
|
product.setSvipProductFlag(price.getSvipProductFlag());
|
|
|
product.setSvipPriceTag(price.getSvipPriceTag());
|
|
|
+ product.setPrice(price.getPrice());
|
|
|
+ product.setSkuId(price.getSkuId());
|
|
|
+ product.setOriginalPrice(price.getPrice());
|
|
|
+ product.setPriceGrade(getPriceGrade(price.getPrice()));
|
|
|
+ product.setMinBuyNumber(price.getMinBuyNumber());
|
|
|
+ product.setUnit(price.getUnit());
|
|
|
+ product.setStock(price.getStock());
|
|
|
+ product.setSkus(price.getSkus());
|
|
|
}
|
|
|
|
|
|
}
|