|
@@ -1,14 +1,20 @@
|
|
|
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.PromotionsMapper;
|
|
|
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.PromotionsVo;
|
|
|
import com.caimei365.commodity.service.PriceService;
|
|
|
+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;
|
|
|
|
|
|
/**
|
|
@@ -24,6 +30,7 @@ public class PriceServiceImpl implements PriceService {
|
|
|
private PriceMapper priceMapper;
|
|
|
@Resource
|
|
|
private PromotionsMapper promotionsMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 获取商品详情价格
|
|
|
*
|
|
@@ -36,13 +43,9 @@ public class PriceServiceImpl implements PriceService {
|
|
|
// 数据库获取基本价格信息
|
|
|
PriceVo price = priceMapper.getDetailPrice(productId);
|
|
|
// 根据用户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
|
|
|
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);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|