Browse Source

供应商给机构下单

huangzhiguo 1 year ago
parent
commit
e9ea415b74

+ 41 - 0
src/main/java/com/caimei365/commodity/controller/ShopApi.java

@@ -0,0 +1,41 @@
+package com.caimei365.commodity.controller;
+
+import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.vo.PaginationVo;
+import com.caimei365.commodity.model.vo.ProductDetailVo;
+import com.caimei365.commodity.service.ShopOrderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/9/28
+ */
+@RestController
+@RequestMapping("/commodity/Shop")
+public class ShopApi {
+
+    @Autowired private ShopOrderService shopOrderService;
+
+    /**
+     * 供应商商品数据
+     * @param shopId
+     * @param name
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @GetMapping("/getShopProduct")
+    public ResponseJson<PaginationVo<ProductDetailVo>> getShopProductList(Integer shopId, String name, Integer pageNum, Integer pageSize) {
+        if (null == shopId) {
+            return ResponseJson.error(-1, "供应商Id不能为空", null);
+        }
+        return shopOrderService.getShopProductList(shopId, name, pageNum, pageSize);
+    }
+}

+ 19 - 0
src/main/java/com/caimei365/commodity/mapper/PriceMapper.java

@@ -46,6 +46,14 @@ public interface PriceMapper {
      * 根据skuId查询阶梯价列表
      */
     List<LadderPriceVo> getLadderPricesByProductId(Integer skuId);
+
+    /**
+     * 根据skuId查询阶梯价列表 组织
+     * @param skuId
+     * @param organizeId
+     * @return
+     */
+    List<LadderPriceVo> getLadderPricesOrganizeByProductId(@Param("skuId") Integer skuId, @Param("organizeId") Integer organizeId);
     /**
      * 获取最低阶梯价(价格最低,阶梯数最大)
      */
@@ -54,6 +62,13 @@ public interface PriceMapper {
      * 获取最高阶梯价(价格最高,阶梯数最小)
      */
     LadderPriceVo findMaxLadderPrice(Integer skuId);
+
+    /**
+     * 获取最高阶梯价(价格最高,阶梯数最小)联合丽格
+     * @param skuId
+     * @return
+     */
+    LadderPriceVo findOrganizeMaxLadderPrice(@Param("skuId") Integer skuId,@Param("organizeId") Integer organizeId);
     /**
      * 根据商品ID和用户ID 查询复购价
      */
@@ -130,8 +145,12 @@ public interface PriceMapper {
 
     ProductItemVo findLowPriceOfAll(Integer productId);
 
+    ProductItemVo findLowPriceOfOrganizeAll(@Param("productId") Integer productId, @Param("organizeId") Integer organizeId);
+
     ProductItemVo findLowPriceOfPrice(Integer productId);
 
+    ProductItemVo findLowPriceOfOrganizePrice(@Param("productId") Integer productId, @Param("organizeId") Integer organizeId);
+
     VipSkuPriceDto getVipSku(Integer skuId);
 
     Double getTouchPriceBySku(Integer skuId,Integer promotionId);

+ 32 - 0
src/main/java/com/caimei365/commodity/mapper/ShopOrderMapper.java

@@ -0,0 +1,32 @@
+package com.caimei365.commodity.mapper;
+
+import com.caimei365.commodity.model.dto.Sku;
+import com.caimei365.commodity.model.vo.ProductDetailVo;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/9/28
+ */
+@Mapper
+public interface ShopOrderMapper {
+    /**
+     * 供应商商品集合
+     * @param shopId
+     * @return
+     */
+    List<ProductDetailVo> getShopProductList(@Param("shopId") Integer shopId, @Param("name") String name);
+
+    /**
+     * 商品对应上架商城的 sku
+     * @param productId
+     * @param organizeIdList
+     * @return
+     */
+    List<Sku> getSkuList(@Param("productId") Integer productId, @Param("organizeIdList") List<String> organizeIdList);
+}

+ 8 - 0
src/main/java/com/caimei365/commodity/model/vo/ProductDetailVo.java

@@ -59,6 +59,10 @@ public class ProductDetailVo implements Serializable {
      * 商品productID
      */
     private Integer productId;
+    /**
+     * 上架商城
+     */
+    private String groundMall;
     /**
      * 所属供应商Id
      */
@@ -143,6 +147,10 @@ public class ProductDetailVo implements Serializable {
      * 是否使用活动角标:1是,空或0不是[与actType搭配使用,仅用于标识非真正活动]
      */
     private Integer actFlag;
+    /**
+     * 机构税率
+     */
+    private BigDecimal taxRate;
     /**
      * 是否含税   0不含税,1含税,2未知
      */

+ 25 - 0
src/main/java/com/caimei365/commodity/service/ShopOrderService.java

@@ -0,0 +1,25 @@
+package com.caimei365.commodity.service;
+
+import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.vo.PaginationVo;
+import com.caimei365.commodity.model.vo.ProductDetailVo;
+
+import java.util.Map;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/9/28
+ */
+public interface ShopOrderService {
+    /**
+     * 供应商商品数据
+     * @param shopId
+     * @param name
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    ResponseJson<PaginationVo<ProductDetailVo>> getShopProductList(Integer shopId, String name,Integer pageNum, Integer pageSize);
+}

+ 161 - 0
src/main/java/com/caimei365/commodity/service/impl/ShopOrderServiceImpl.java

@@ -0,0 +1,161 @@
+package com.caimei365.commodity.service.impl;
+
+import com.caimei365.commodity.mapper.PriceMapper;
+import com.caimei365.commodity.mapper.ShopMapper;
+import com.caimei365.commodity.mapper.ShopOrderMapper;
+import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.dto.Sku;
+import com.caimei365.commodity.model.po.ProductImagePo;
+import com.caimei365.commodity.model.vo.*;
+import com.caimei365.commodity.service.ShopOrderService;
+import com.caimei365.commodity.utils.ImageUtils;
+import com.caimei365.commodity.utils.MathUtil;
+import com.github.pagehelper.PageHelper;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.IntStream;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2023/9/28
+ */
+@Service
+public class ShopOrderServiceImpl implements ShopOrderService {
+    @Value("${caimei.wwwDomain}")
+    private String domain;
+
+    @Resource private ShopOrderMapper shopOrderMapper;
+
+    @Resource private ShopMapper shopMapper;
+
+    @Resource private PriceMapper priceMapper;
+
+    /**
+     * 供应商商品数据
+     * @param shopId
+     * @param name
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @Override
+    public ResponseJson<PaginationVo<ProductDetailVo>> getShopProductList(Integer shopId, String name, Integer pageNum, Integer pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        List<ProductDetailVo> shopProductList = shopOrderMapper.getShopProductList(shopId, name);
+        // 处理上架商城, 版本只显示联合丽格的sku
+        List<String> organizeIdList = new ArrayList<>();
+        organizeIdList.add("4");
+        shopProductList.forEach( product -> {
+            // 主图
+            product.setMainImage(ImageUtils.getImageURL("product", product.getMainImage(), 0, domain));
+            // 商品图片
+            List<ProductImagePo> imageList = shopMapper.getProductImages(product.getProductId());
+            for (ProductImagePo image : imageList) {
+                String imageURL = ImageUtils.getImageURL("product", image.getImage(), 0, domain);
+                image.setImage(imageURL);
+            }
+            product.setImageList(imageList);
+            // 获取商品sku
+            List<Sku> skuList = shopOrderMapper.getSkuList(product.getProductId(), organizeIdList);
+            product.setSkus(skuList);
+            Sku sku = skuList.get(0);
+            product.setSkuId(sku.getSkuId());
+            product.setUnit(sku.getUnit());
+            product.setPrice(sku.getPrice());
+            product.setMinBuyNumber(sku.getMinBuyNumber());
+
+            skuList.forEach( s -> {
+                if (1 == s.getLadderPriceFlag()) {
+                    // sku的阶梯价
+                    LadderPriceVo lowerBuyNum = priceMapper.findOrganizeMaxLadderPrice(s.getSkuId(), 4);
+                    s.setMinBuyNumber(lowerBuyNum.getBuyNum());
+                    s.setPrice(lowerBuyNum.getBuyPrice());
+                    s.setStock(lowerBuyNum.getStock());
+                    s.setUnit(lowerBuyNum.getUnit());
+                    List<LadderPriceVo> ladderPrices = priceMapper.getLadderPricesOrganizeByProductId(s.getSkuId(), 4);
+                    TaxVo tax = priceMapper.getTaxByProductId(product.getProductId());
+                    if (!CollectionUtils.isEmpty(ladderPrices)) {
+                        setLadderPriceList(ladderPrices, tax);
+                    }
+                    s.setLadderPriceList(ladderPrices);
+                    product.setLadderPriceFlag(1);
+                    if (1 == skuList.size()) {
+                        //1.对于只有一个SKU的商品,各个商品列表直接显示机构价即可:若是阶梯价,则显示第一级阶梯的价格:
+                        product.setSkuId(ladderPrices.get(0).getSkuId());
+                        product.setPrice(ladderPrices.get(0).getBuyPrice());
+                        product.setMinBuyNumber(ladderPrices.get(0).getBuyNum());
+                        product.setStock(ladderPrices.get(0).getStock());
+                        product.setUnit(ladderPrices.get(0).getUnit());
+                    } else {
+                        //2.对于有多个SKU的商品,各个商品列表显示所有SKU中最低的价格:
+                        // 若SKU中,全部都是阶梯价,则显示所有SKU中第一级阶梯的价格中的最低价,
+                        // 若SKU中,使用阶梯价和不使用阶梯价(只是用机构价》并存,则用机构价和第一级阶梯价比大小,展示最小的价格
+                        // skuid分组取第一阶梯中最便宜的
+                        ProductItemVo lowLadderPrice = priceMapper.findLowPriceOfOrganizeAll(product.getProductId(), 4);
+                        ProductItemVo lowAllPrice = priceMapper.findLowPriceOfOrganizePrice(product.getProductId(), 4);
+                        if (null != lowLadderPrice) {
+                            ProductItemVo productItemVo = lowLadderPrice.getPrice() > lowAllPrice.getPrice() ? lowAllPrice : lowLadderPrice;
+                            product.setPrice(productItemVo.getPrice());
+                            product.setSkuId(productItemVo.getSkuId());
+                            product.setMinBuyNumber(productItemVo.getMinBuyNumber());
+                            product.setUnit(productItemVo.getUnit());
+                            product.setStock(productItemVo.getStock());
+                        } else {
+                            product.setPrice(lowAllPrice.getPrice());
+                            product.setSkuId(lowAllPrice.getSkuId());
+                            product.setMinBuyNumber(lowAllPrice.getMinBuyNumber());
+                            product.setUnit(lowAllPrice.getUnit());
+                            product.setStock(lowAllPrice.getStock());
+                        }
+                    }
+                }
+            });
+            // 税费标志
+            boolean taxFlag = "0".equals(product.getIncludedTax()) && ("1".equals(product.getInvoiceType()) || "2".equals(product.getInvoiceType()));
+            if (taxFlag) {
+                BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(sku.getPrice(), product.getTaxRate()), 100, 2);
+                product.setPrice(MathUtil.add(product.getPrice(), thisTaxFee).doubleValue());
+                BigDecimal originalTaxFee = MathUtil.div(MathUtil.mul(sku.getOriginalPrice(), product.getTaxRate()), 100, 2);
+                product.setOriginalPrice(MathUtil.add(product.getOriginalPrice(), originalTaxFee).doubleValue());
+            }
+        });
+
+        PaginationVo<ProductDetailVo> page = new PaginationVo<>(shopProductList);
+        return ResponseJson.success(page);
+    }
+
+
+    /**
+     * 设置阶梯价展示数据
+     *
+     * @param ladderPrices List<LadderPriceVo>
+     * @param tax          TaxVo
+     */
+    public void setLadderPriceList(List<LadderPriceVo> ladderPrices, TaxVo tax) {
+        IntStream.range(0, ladderPrices.size()).forEach(i -> {
+            //税费标志
+            boolean taxFlag = 0 == tax.getIncludedTax() && 1 == tax.getInvoiceType() || 2 == tax.getInvoiceType();
+            //添加税费
+            if (taxFlag) {
+                BigDecimal taxFee = MathUtil.div(MathUtil.mul(ladderPrices.get(i).getBuyPrice(), tax.getTaxPoint()), 100, 2);
+                ladderPrices.get(i).setBuyPrice(MathUtil.add(ladderPrices.get(i).getBuyPrice(), taxFee).doubleValue());
+            }
+            if (i == ladderPrices.size() - 1) {
+                ladderPrices.get(i).setMaxNum(0);
+                ladderPrices.get(i).setNumRange("≥" + ladderPrices.get(i).getBuyNum());
+            } else {
+                ladderPrices.get(i).setMaxNum(ladderPrices.get(i + 1).getBuyNum());
+                String buyNumRangeShow = ladderPrices.get(i).getBuyNum() + "~" + (ladderPrices.get(i + 1).getBuyNum() - 1);
+                ladderPrices.get(i).setNumRange(buyNumRangeShow);
+            }
+        });
+    }
+}

+ 54 - 0
src/main/resources/mapper/PriceMapper.xml

@@ -96,6 +96,22 @@
           and delFlag = 0
         order by buynum asc
     </select>
+
+    <select id="getLadderPricesOrganizeByProductId" resultType="com.caimei365.commodity.model.vo.LadderPriceVo">
+        SELECT plp.skuId,
+               plp.productId,
+               plp.buyNum,
+               cs.stock,
+               plp.buyPrice,
+               cs.unit
+        FROM product_ladder_price plp
+                 LEFT JOIN cm_sku cs ON plp.skuId = cs.skuId
+        WHERE plp.skuId = #{skuId}
+          AND cs.organizeId = #{organizeId}
+          AND plp.userType = 3
+          AND plp.delFlag = 0
+        ORDER BY plp.buynum ASC
+    </select>
     <select id="findLowerLadderPrice" resultType="com.caimei365.commodity.model.vo.LadderPriceVo">
         select id,
                skuId,
@@ -128,6 +144,26 @@
         order by buyprice desc
         limit 1
     </select>
+
+    <select id="findOrganizeMaxLadderPrice" resultType="com.caimei365.commodity.model.vo.LadderPriceVo">
+        select plp.id,
+               plp.skuId,
+               plp.productId,
+               plp.ladderNum,
+               cs.unit,
+               cs.stock,
+               plp.buyNum,
+               plp.buyPrice
+        from product_ladder_price plp
+                 left join cm_sku cs on cs.skuId = plp.skuId
+        where plp.skuId = #{skuId}
+          and cs.organizeId = #{organizeId}
+          and plp.userType = 3
+          and plp.delFlag = 0
+        order by plp.buyprice desc
+        limit 1
+    </select>
+
     <select id="getRepurchasePrice" resultType="java.lang.Double">
         select r.currentPrice,
                p.productType
@@ -292,6 +328,15 @@
         order by plp.buyPrice asc
         limit 1
     </select>
+    <select id="findLowPriceOfOrganizeAll" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
+        select plp.buyPrice as price, cs.unit as unit, plp.buyNum as minBuyNumber, cs.skuId as skuId, cs.stock
+        from product_ladder_price plp
+                 left join cm_sku cs on plp.skuId = cs.skuId
+        where plp.productId = #{productId} and cs.organizeId = #{organizeId}
+        GROUP BY plp.skuId
+        order by plp.buyPrice asc
+        limit 1
+    </select>
     <select id="findLowPriceOfPrice" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
         SELECT price, unit, skuId, stock,
         ifnull(minBuyNumber, (SELECT buyNum FROM product_ladder_price WHERE skuId = cm_sku.skuId ORDER BY buyNum asc LIMIT 1)) AS minBuyNumber
@@ -300,6 +345,15 @@
         ORDER BY price ASC
         LIMIT 1
     </select>
+
+    <select id="findLowPriceOfOrganizePrice" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
+        SELECT price, unit, skuId, stock,
+               ifnull(minBuyNumber, (SELECT buyNum FROM product_ladder_price WHERE skuId = cm_sku.skuId ORDER BY buyNum asc LIMIT 1)) AS minBuyNumber
+        FROM cm_sku
+        WHERE productId = #{productId} and organizeId = #{organizeId}
+        ORDER BY price ASC
+        LIMIT 1
+    </select>
     <select id="getVipSku" resultType="com.caimei365.commodity.model.dto.VipSkuPriceDto">
         select priceType,discountPrice,discount,productId,skuId
         from cm_svip_product_sku

+ 59 - 0
src/main/resources/mapper/ShopOrderMapper.xml

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.caimei365.commodity.mapper.ShopOrderMapper">
+
+
+    <select id="getShopProductList" resultType="com.caimei365.commodity.model.vo.ProductDetailVo">
+        select distinct p.productID       as productId,
+               p.groundMall AS groundMall,
+               p.actStatus,
+               p.name,
+               p.aliasName,
+               p.mainImage       as image,
+               p.productCode     as code,
+               p.priceFlag,
+               p.searchKey       as keyword,
+               p.step,
+               p.shopID          as shopId,
+               p.taxPoint        as taxRate,
+               p.includedTax,
+               p.invoiceType,
+               p.productCategory as productCategory,
+               copi.validFlag,
+               p.featuredFlag,
+               p.commodityType,
+               p.bigTypeID       as bigTypeId,
+               p.smallTypeID     as smallTypeId,
+               p.tinyTypeID      as tinyTypeId,
+               p.productType
+        from product p
+        left join cm_organize_product_info copi on copi.productId = p.productID
+        where p.shopId = #{shopId} and copi.validFlag = 2 and p.groundMall NOT LIKE '0'
+        <if test="name != null and name != ''">
+            and p.name like concat('%',#{name},'%')
+        </if>
+    </select>
+
+    <select id="getSkuList" resultType="com.caimei365.commodity.model.dto.Sku">
+        select
+            skuId,
+            productId,
+            minBuyNumber,
+            ifnull(ladderPriceFlag, 0) as ladderPriceFlag,
+            price,
+            price as originalPrice,
+            unit,
+            stock,
+            organizePercent,
+            shopPercent,
+            cmPercent
+        from cm_sku
+        where productId = #{productId}
+          <if test="organizeIdList.size() > 0">
+            and organizeId in
+                <foreach collection="organizeIdList" item="organizeId" open="(" separator="," close=")">
+                    #{organizeId}
+                </foreach>
+          </if>
+    </select>
+</mapper>