|
@@ -2,13 +2,22 @@ package com.caimei.service.impl;
|
|
|
|
|
|
import com.caimei.mapper.ProductMapper;
|
|
import com.caimei.mapper.ProductMapper;
|
|
import com.caimei.model.ResponseJson;
|
|
import com.caimei.model.ResponseJson;
|
|
|
|
+import com.caimei.model.po.*;
|
|
import com.caimei.model.vo.ClubVo;
|
|
import com.caimei.model.vo.ClubVo;
|
|
|
|
+import com.caimei.model.vo.LadderPriceVo;
|
|
|
|
+import com.caimei.model.vo.ProductVo;
|
|
import com.caimei.service.ProductService;
|
|
import com.caimei.service.ProductService;
|
|
|
|
+import com.caimei.util.MathUtil;
|
|
|
|
+import com.caimei.util.ProductUtils;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
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.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -21,6 +30,8 @@ import java.util.List;
|
|
public class ProductServiceImpl implements ProductService {
|
|
public class ProductServiceImpl implements ProductService {
|
|
@Resource
|
|
@Resource
|
|
private ProductMapper productMapper;
|
|
private ProductMapper productMapper;
|
|
|
|
+ @Value("${caimei.oldapi}")
|
|
|
|
+ private String domain;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ResponseJson<PageInfo<ClubVo>> clubList(Integer organizeId, String name, Integer pageNum, Integer pageSize) {
|
|
public ResponseJson<PageInfo<ClubVo>> clubList(Integer organizeId, String name, Integer pageNum, Integer pageSize) {
|
|
@@ -32,4 +43,148 @@ public class ProductServiceImpl implements ProductService {
|
|
|
|
|
|
return ResponseJson.success(pageInfo);
|
|
return ResponseJson.success(pageInfo);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<PageInfo<ProductVo>> productList(Integer organizeId, String productName, Integer pageNum, Integer pageSize) {
|
|
|
|
+ if (null == organizeId) {
|
|
|
|
+ return ResponseJson.error("参数异常", null);
|
|
|
|
+ }
|
|
|
|
+ PageHelper.startPage(pageNum,pageSize);
|
|
|
|
+ List<ProductVo> productList = productMapper.findProductList(organizeId, productName);
|
|
|
|
+ for (ProductVo product : productList) {
|
|
|
|
+ setProductPrice(product);
|
|
|
|
+ }
|
|
|
|
+ PageInfo<ProductVo> pageInfo = new PageInfo<>(productList);
|
|
|
|
+ return ResponseJson.success(pageInfo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<ProductVo> productDetails(Integer productId) {
|
|
|
|
+ ProductVo product = productMapper.findProductByProductId(productId);
|
|
|
|
+ if (product == null) {
|
|
|
|
+ //商品不存在
|
|
|
|
+ return ResponseJson.error("商品不存在",null);
|
|
|
|
+ }
|
|
|
|
+ String[] split = null;
|
|
|
|
+ //商品标签
|
|
|
|
+ if (product.getTags() != null) {
|
|
|
|
+ String tags = product.getTags();
|
|
|
|
+ tags = tags.replace(" ", ",").replace("、", ",").replace(",", ",");
|
|
|
|
+ if (tags.contains(",")) {
|
|
|
|
+ split = tags.split(",");
|
|
|
|
+ List<String> list = new ArrayList();
|
|
|
|
+ for (String s : split) {
|
|
|
|
+ if (s != null && !s.equals("")) {
|
|
|
|
+ list.add(s);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ split = list.toArray(new String[list.size()]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ product.setTagsList(split);
|
|
|
|
+ product.setMainImage(ProductUtils.getImageURL("product", product.getMainImage(), 0, domain));
|
|
|
|
+ //商品图片
|
|
|
|
+ List<ProductImagePo> imageList = productMapper.findProductImagesByOriginalId(product.getOriginalProductId());
|
|
|
|
+ for (ProductImagePo image : imageList) {
|
|
|
|
+ String imageURL = ProductUtils.getImageURL("product", image.getImage(), 0, domain);
|
|
|
|
+ image.setImage(imageURL);
|
|
|
|
+ }
|
|
|
|
+ product.setImageList(imageList);
|
|
|
|
+ //商品详情
|
|
|
|
+ ProductDetailInfoPo productDetail = productMapper.findProductDetailByOriginalId(product.getOriginalProductId());
|
|
|
|
+ product.setProductDetail(productDetail);
|
|
|
|
+ //价格等级
|
|
|
|
+ String priceGrade = ProductUtils.getPriceGrade(product.getPrice().doubleValue());
|
|
|
|
+ product.setPriceGrade(priceGrade);
|
|
|
|
+ //商品分类
|
|
|
|
+ String typeName = productMapper.findTypeName(product.getBigTypeId(),product.getSmallTypeId(), product.getTinyTypeId());
|
|
|
|
+ product.setTypeName(typeName);
|
|
|
|
+ //品牌名称
|
|
|
|
+ String brandName = productMapper.findBrandNameByBrandId(product.getBrandId());
|
|
|
|
+ if (StringUtils.isNotBlank(brandName)) {
|
|
|
|
+ product.setBrandName(brandName);
|
|
|
|
+ }
|
|
|
|
+ //相关参数
|
|
|
|
+ List<RelatedParametersPo> parametersList = productMapper.findParametersByOriginalId(product.getOriginalProductId());
|
|
|
|
+ product.setParametersList(parametersList);
|
|
|
|
+ if (0 != product.getStatus()) {
|
|
|
|
+ setProductPrice(product);
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.success(product);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setProductPrice(ProductVo product){
|
|
|
|
+ // 设置图片
|
|
|
|
+ product.setMainImage(ProductUtils.getImageURL("product", product.getMainImage(), 0, domain));
|
|
|
|
+ // 设置商品展示价格
|
|
|
|
+ PromotionsPo activity = productMapper.findPromotionByProductId(product.getProductId());
|
|
|
|
+ if (null != activity) {
|
|
|
|
+ product.setActStatus(1);
|
|
|
|
+ product.setPromotion(activity);
|
|
|
|
+ product.setLadderPriceFlag(0);
|
|
|
|
+ // 活动价
|
|
|
|
+ if (activity.getType() == 1 && null != activity.getTouchPrice()) {
|
|
|
|
+ product.setRetailPrice(activity.getTouchPrice());
|
|
|
|
+ }else {
|
|
|
|
+ product.setRetailPrice(product.getPrice());
|
|
|
|
+ }
|
|
|
|
+ } else if (1 == product.getLadderPriceFlag()) {
|
|
|
|
+ // 启用阶梯价格
|
|
|
|
+ getLadderPrice(product);
|
|
|
|
+ } else {
|
|
|
|
+ product.setActStatus(0);
|
|
|
|
+ product.setLadderPriceFlag(0);
|
|
|
|
+ product.setRetailPrice(product.getPrice());
|
|
|
|
+ }
|
|
|
|
+ //添加税费
|
|
|
|
+ boolean addTaxFlag = (0 == product.getIncludedTax() && (1 == product.getInvoiceType() || 2 == product.getInvoiceType()));
|
|
|
|
+ if (addTaxFlag) {
|
|
|
|
+ BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(product.getRetailPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100));
|
|
|
|
+ BigDecimal price = MathUtil.add(product.getRetailPrice(), addedValueTax);
|
|
|
|
+ product.setRetailPrice(price);
|
|
|
|
+ if (activity != null && activity.getType() == 1 && activity.getMode() == 1) {
|
|
|
|
+ activity.setTouchPrice(price);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void getLadderPrice(ProductVo product) {
|
|
|
|
+ product.setActStatus(0);
|
|
|
|
+ // 启用阶梯价格
|
|
|
|
+ List<LadderPriceVo> ladderPriceList = productMapper.findLadderPriceByProductId(product.getProductId());
|
|
|
|
+ if (ladderPriceList.size() > 0) {
|
|
|
|
+ for (int i = 0; i < ladderPriceList.size(); i++) {
|
|
|
|
+ if (null != ladderPriceList.get(i)) {
|
|
|
|
+ String buyNumRangeShow;
|
|
|
|
+ if ((i + 1) < ladderPriceList.size() && null != ladderPriceList.get(i + 1)) {
|
|
|
|
+ buyNumRangeShow = ladderPriceList.get(i).getBuyNum() + "~" + (ladderPriceList.get(i + 1).getBuyNum() - 1L);
|
|
|
|
+ } else {
|
|
|
|
+ buyNumRangeShow = "≥" + ladderPriceList.get(i).getBuyNum();
|
|
|
|
+ }
|
|
|
|
+ ladderPriceList.get(i).setBuyNumRangeShow(buyNumRangeShow);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ product.setRetailPrice(ladderPriceList.get(0).getBuyPrice());
|
|
|
|
+ product.setMinBuyNumber(ladderPriceList.get(0).getBuyNum());
|
|
|
|
+ product.setLadderPriceList(ladderPriceList);
|
|
|
|
+ //阶梯价列表添加税费
|
|
|
|
+ boolean addTaxFlag = (0 == product.getIncludedTax() && (1 == product.getInvoiceType() || 2 == product.getInvoiceType()));
|
|
|
|
+ if (addTaxFlag) {
|
|
|
|
+ ladderPriceList.stream().forEach(item->{
|
|
|
|
+ item.setBuyPrice(MathUtil.add(item.getBuyPrice(), MathUtil.div(MathUtil.mul(item.getBuyPrice(), product.getClubTaxPoint()), 100)));
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 阶梯价格异常,关闭阶梯价格
|
|
|
|
+ product.setLadderPriceFlag(0);
|
|
|
|
+ product.setRetailPrice(product.getPrice());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|