Browse Source

采美sku bugfix

zhijiezhao 2 years ago
parent
commit
b4f1897f11

+ 9 - 0
src/main/java/com/caimei/modules/bulkpurchase/entity/PurchaseProduct.java

@@ -17,6 +17,7 @@ import java.util.List;
 public class PurchaseProduct extends DataEntity<PurchaseProduct> {
 
     private static final long serialVersionUID = 1L;
+    private Integer skuId;   //默认skuId
     private String discounts; //是否支持叠加优惠,1支持,2不支持
     private String purchaseProductName;        // 商品名称
     private String name;        // 商品名称
@@ -94,6 +95,14 @@ public class PurchaseProduct extends DataEntity<PurchaseProduct> {
      */
     private Double svipTaxReduction;
 
+    public Integer getSkuId() {
+        return skuId;
+    }
+
+    public void setSkuId(Integer skuId) {
+        this.skuId = skuId;
+    }
+
     public Integer getSkuStr() {
         return skuStr;
     }

+ 13 - 11
src/main/java/com/caimei/modules/bulkpurchase/web/PurchaseProductController.java

@@ -105,7 +105,9 @@ public class PurchaseProductController extends BaseController {
                 } else {
                     p.setCouponsLogo(1);
                 }
-                p.setSkuList(productDao.findSkuList(p.getProductId().intValue()));
+                List<CmSku> skuList = productDao.findSkuList(p.getProductId().intValue());
+                p.setSkuId(skuList.get(0).getSkuId());
+                p.setSkuList(skuList);
                 long productId = p.getProductId();
                 String discountPrice = p.getPrice();//默认折扣单价
                 if (priceFlag) {
@@ -141,17 +143,17 @@ public class PurchaseProductController extends BaseController {
                 // 初始化超级会员优惠
                 p.setSvipReduction(0d);
                 if (1 == p.getSvipPriceFlag()) {
-                    if (1 == p.getSvipPriceType()) {
-                        p.setSvipDiscountPrice(MathUtil.div(MathUtil.mul(new Double(p.getPrice()), p.getSvipDiscount()), 100, 2).doubleValue());
-                    }
+//                    if (1 == p.getSvipPriceType()) {
+//                        p.setSvipDiscountPrice(MathUtil.div(MathUtil.mul(new Double(p.getPrice()), p.getSvipDiscount()), 100, 2).doubleValue());
+//                    }
                     // 商品的超级会员优惠=原价-超级会员优惠价
-                    p.setSvipReduction(MathUtil.sub(p.getPrice(), p.getSvipDiscountPrice()).doubleValue());
-                    if ("0".equals(p.getIncludedTax()) && ("1".equals(p.getInvoiceType()) || "2".equals(p.getInvoiceType()))) {
-                        // 计算优惠的税费
-                        BigDecimal taxReduction = MathUtil.div(MathUtil.mul(p.getSvipReduction(), p.getTaxRate()), 100);
-                        p.setSvipReduction(MathUtil.add(p.getSvipReduction(), taxReduction).doubleValue());
-                        p.setSvipTaxReduction(taxReduction.doubleValue());
-                    }
+//                    p.setSvipReduction(MathUtil.sub(p.getPrice(), p.getSvipDiscountPrice()).doubleValue());
+//                    if ("0".equals(p.getIncludedTax()) && ("1".equals(p.getInvoiceType()) || "2".equals(p.getInvoiceType()))) {
+//                        // 计算优惠的税费
+//                        BigDecimal taxReduction = MathUtil.div(MathUtil.mul(p.getSvipReduction(), p.getTaxRate()), 100);
+//                        p.setSvipReduction(MathUtil.add(p.getSvipReduction(), taxReduction).doubleValue());
+//                        p.setSvipTaxReduction(taxReduction.doubleValue());
+//                    }
                 } else if (null != cmPromotion) {
                     p.setCmPromotion(cmPromotion);
                     p.setLadderPriceFlag(0);

+ 1 - 0
src/main/java/com/caimei/modules/order/dao/NewOrderProductDao.java

@@ -105,4 +105,5 @@ public interface NewOrderProductDao extends CrudDao<NewOrderProduct> {
     Integer countReturnedFreightProduct(Integer shopOrderID);
 
 
+    Double findPriceBySku(String skuId);
 }

+ 5 - 0
src/main/java/com/caimei/modules/order/web/NewOrderController.java

@@ -428,6 +428,11 @@ public class NewOrderController extends BaseController {
                     if (ladderPriceFlag != null && !"".equals(ladderPriceFlag)) {
                         o.setLadderPriceFlag(Integer.valueOf(ladderPriceFlag));
                     }
+                    if (null == o.getPrice()) {
+                        Double price = newOrderProductDao.findPriceBySku(jsonObject.getString("skuId"));
+                        o.setPrice(price);
+                    }
+                    o.setSkuID(Integer.valueOf(jsonObject.getString("skuId")));
                     o.setSplitCode(productDao.getSplitCodeByProductId(o.getProductID()));
                     if ("0".equals(productType)) {
                         o.setPreferential((o.getPrice() - o.getDiscountPrice()) * o.getNum());//折扣

+ 2 - 0
src/main/java/com/caimei/modules/product/dao/ProductDao.java

@@ -211,4 +211,6 @@ public interface ProductDao extends CrudDao<Product> {
     Integer findSkuId(Integer productID);
 
     void updateCmSku(CmSku cmSku);
+
+    CmSku findSku(Integer productId);
 }

+ 88 - 65
src/main/java/com/caimei/modules/svip/service/CmSvipProductService.java

@@ -3,6 +3,8 @@ package com.caimei.modules.svip.service;
 import java.math.BigDecimal;
 import java.util.List;
 
+import com.caimei.modules.product.dao.ProductDao;
+import com.caimei.modules.product.entity.CmSku;
 import com.caimei.modules.product.entity.Product;
 import com.caimei.modules.svip.entity.CmSvipProductAdsImage;
 import com.caimei.utils.AppUtils;
@@ -20,81 +22,102 @@ import javax.annotation.Resource;
 
 /**
  * 超级会员优惠商品Service
+ *
  * @author Aslee
  * @version 2021-09-23
  */
 @Service
 @Transactional(readOnly = true)
 public class CmSvipProductService extends CrudService<CmSvipProductDao, CmSvipProduct> {
-	@Resource
-	private CmSvipProductDao cmSvipProductDao;
+    @Resource
+    private CmSvipProductDao cmSvipProductDao;
+    @Resource
+    private ProductDao productDao;
 
-	public CmSvipProduct get(String id) {
-		return super.get(id);
-	}
-	
-	public List<CmSvipProduct> findList(CmSvipProduct cmSvipProduct) {
-		return super.findList(cmSvipProduct);
-	}
-	
-	public Page<CmSvipProduct> findPage(Page<CmSvipProduct> page, CmSvipProduct cmSvipProduct) {
-		Page<CmSvipProduct> page1 = super.findPage(page, cmSvipProduct);
-		List<CmSvipProduct> list = page1.getList();
-		String wwwServer = Global.getConfig("wwwServer");
-		list.forEach(product->{
-			if (StringUtil.isNotBlank(product.getProductImage())) {
-				product.setProductImage(AppUtils.getImageURL("product", product.getProductImage(), 0, wwwServer));
-			}
-		});
-		return page1;
-	}
-	
-	@Transactional(readOnly = false)
-	public void save(CmSvipProduct cmSvipProduct) {
-		if (cmSvipProduct.getIsNewRecord()) {
-			Integer priceType = null == cmSvipProduct.getDiscount() ? 2 : 1;
-			cmSvipProduct.setPriceType(priceType);
-			cmSvipProduct.setSort(1);
-		}
-		super.save(cmSvipProduct);
-	}
-	
-	@Transactional(readOnly = false)
-	public void delete(CmSvipProduct cmSvipProduct) {
-		super.delete(cmSvipProduct);
-	}
+    public CmSvipProduct get(String id) {
+        CmSvipProduct cmSvipProduct = super.get(id);
+        CmSku sku = productDao.findSku(cmSvipProduct.getProductId());
+        cmSvipProduct.setPrice(BigDecimal.valueOf(sku.getPrice()));
+        cmSvipProduct.setCostCheckFlag(sku.getCostCheckFlag().toString());
+        if (1 == sku.getCostCheckFlag()) {
+            cmSvipProduct.setCostPrice(sku.getCostPrice().toString());
+        } else {
+            cmSvipProduct.setCostProportional(sku.getCostProportional().toString());
+        }
+        return cmSvipProduct;
+    }
 
+    public List<CmSvipProduct> findList(CmSvipProduct cmSvipProduct) {
+        List<CmSvipProduct> list = super.findList(cmSvipProduct);
+        list.forEach(product -> {
+            CmSku sku = productDao.findSku(product.getProductId());
+            product.setPrice(BigDecimal.valueOf(sku.getPrice()));
+        });
+        return list;
+    }
 
-	@Transactional(readOnly = false)
-	public Page<Product> findProductPage(Page<Product> productPage, Product product) {
-		List<Integer> ids = cmSvipProductDao.findSvipProductIds();
-		product.setIds(ids);
-		product.setPage(productPage);
-		List<Product> productList = cmSvipProductDao.findAllProduct(product);
-		String wwwServer = Global.getConfig("wwwServer");
-		productList.forEach(item -> {
-			if (StringUtil.isNotBlank(item.getMainImage())) {
-				item.setMainImage(AppUtils.getImageURL("product", item.getMainImage(), 0, wwwServer));
-			}
-			if (ids.contains(item.getProductID())) {
-				item.setExistsFlag("1");
-			}
-		});
-		productPage.setList(productList);
-		return productPage;
-	}
+    public Page<CmSvipProduct> findPage(Page<CmSvipProduct> page, CmSvipProduct cmSvipProduct) {
+        Page<CmSvipProduct> page1 = super.findPage(page, cmSvipProduct);
+        List<CmSvipProduct> list = page1.getList();
+        String wwwServer = Global.getConfig("wwwServer");
+        list.forEach(product -> {
+            CmSku sku = productDao.findSku(product.getProductId());
+            product.setPrice(BigDecimal.valueOf(sku.getPrice()));
+            if (StringUtil.isNotBlank(product.getProductImage())) {
+                product.setProductImage(AppUtils.getImageURL("product", product.getProductImage(), 0, wwwServer));
+            }
+        });
+        return page1;
+    }
 
-	@Transactional(readOnly = false)
-	public void saveSort(String sort, String id) {
-		cmSvipProductDao.saveSort(sort, id);
-	}
+    @Transactional(readOnly = false)
+    public void save(CmSvipProduct cmSvipProduct) {
+        if (cmSvipProduct.getIsNewRecord()) {
+            Integer priceType = null == cmSvipProduct.getDiscount() ? 2 : 1;
+            cmSvipProduct.setPriceType(priceType);
+            cmSvipProduct.setSort(1);
+        }
+        super.save(cmSvipProduct);
+    }
 
-	public CmSvipProductAdsImage getAdsImage() {
-		return cmSvipProductDao.getAdsImage();
-	}
+    @Transactional(readOnly = false)
+    public void delete(CmSvipProduct cmSvipProduct) {
+        super.delete(cmSvipProduct);
+    }
 
-	@Transactional(readOnly = false)
-	public void saveAdsImage(CmSvipProductAdsImage adsImage) {
-		cmSvipProductDao.saveAdsImage(adsImage);
-	}
+
+    @Transactional(readOnly = false)
+    public Page<Product> findProductPage(Page<Product> productPage, Product product) {
+        List<Integer> ids = cmSvipProductDao.findSvipProductIds();
+        product.setIds(ids);
+        product.setPage(productPage);
+        List<Product> productList = cmSvipProductDao.findAllProduct(product);
+        String wwwServer = Global.getConfig("wwwServer");
+        productList.forEach(item -> {
+            CmSku sku = productDao.findSku(item.getProductID());
+            item.setPrice(sku.getPrice());
+            if (StringUtil.isNotBlank(item.getMainImage())) {
+                item.setMainImage(AppUtils.getImageURL("product", item.getMainImage(), 0, wwwServer));
+            }
+            if (ids.contains(item.getProductID())) {
+                item.setExistsFlag("1");
+            }
+        });
+        productPage.setList(productList);
+        return productPage;
+    }
+
+    @Transactional(readOnly = false)
+    public void saveSort(String sort, String id) {
+        cmSvipProductDao.saveSort(sort, id);
+    }
+
+    public CmSvipProductAdsImage getAdsImage() {
+        return cmSvipProductDao.getAdsImage();
+    }
+
+    @Transactional(readOnly = false)
+    public void saveAdsImage(CmSvipProductAdsImage adsImage) {
+        cmSvipProductDao.saveAdsImage(adsImage);
+    }
 }

+ 5 - 0
src/main/resources/mappings/modules/order/OrderProductMapper.xml

@@ -623,5 +623,10 @@
           and rp.status = '2'
           and rp.delFlag = '0'
     </select>
+    <select id="findPriceBySku" resultType="java.lang.Double">
+        select price
+        from cm_sku
+        where skuId = #{skuId}
+    </select>
 
 </mapper>

+ 14 - 5
src/main/resources/mappings/modules/product/ProductMapper.xml

@@ -1777,7 +1777,7 @@
             stock=#{stock},
             unit=#{unit},
             minBuyNumber=#{minBuyNumber}
-        where skuId=#{skuId}
+        where skuId = #{skuId}
     </update>
 
     <select id="getProductByTypeName" resultType="com.caimei.modules.brand.entity.BrandAndProductType">
@@ -2014,11 +2014,11 @@
         where productId = #{productID}
     </select>
     <select id="findLadderPriceBySku" resultType="com.caimei.modules.product.entity.CmLadderPrice">
-        select skuId,productId,userType,ladderNum,buyNum,buyPrice,delFlag
+        select skuId, productId, userType, ladderNum, buyNum, buyPrice, delFlag
         FROM product_ladder_price
         WHERE productId = #{productId}
           AND userType = 3
-          AND skuId=#{skuId}
+          AND skuId = #{skuId}
           AND buyNum is NOT null
           AND buyPrice is NOT null
           AND delFlag = 0
@@ -2044,10 +2044,19 @@
                cs.costPrice,
                chs.price
         from cm_sku cs
-        left join cm_hehe_sku chs on cs.skuId=chs.skuId
+                 left join cm_hehe_sku chs on cs.skuId = chs.skuId
         where cs.productId = #{productID}
     </select>
     <select id="findSkuId" resultType="java.lang.Integer">
-        select skuId from cm_sku where productId=#{productId}
+        select skuId
+        from cm_sku
+        where productId = #{productId}
+    </select>
+    <select id="findSku" resultType="com.caimei.modules.product.entity.CmSku">
+        select price, costPrice, costCheckFlag, costProportional
+        from cm_sku
+        where productId=#{productId}
+        order by price asc
+        limit 1
     </select>
 </mapper>

+ 4 - 7
src/main/resources/mappings/modules/svip/CmSvipProductMapper.xml

@@ -13,14 +13,10 @@
         p.mainImage as "productImage",
         p.name as "productName",
 		s.name as "shopName",
-        p.price,
         p.includedTax,
         p.invoiceType,
         p.taxPoint,
-        p.supplierTaxPoint,
-        p.costCheckFlag,
-        p.costPrice,
-        p.costProportional
+        p.supplierTaxPoint
     </sql>
 
     <sql id="cmSvipProductJoins">
@@ -84,7 +80,7 @@
     </select>
     <select id="findAllProduct" resultType="com.caimei.modules.product.entity.Product">
         SELECT
-        a.*,s.name AS "shopName"
+        a.productId,a.mainImage,a.name,s.name AS "shopName"
         FROM product a
         LEFT JOIN shop s on s.shopID = a.shopID
         <where>
@@ -92,7 +88,8 @@
              and a.productID not in (
             select productId from cm_promotions_product cpp left join
             cm_promotions cp on cpp.promotionsId = cp.id where cp.delFlag != '2')
-            and a.ladderPriceFlag = '0' and priceFlag != '1'
+            and priceFlag != '1'
+            and a.productId not in(SELECT DISTINCT productId FROM cm_sku WHERE ladderPriceFlag=1)
             <if test="productID != null">
                 AND a.productID = #{productID}
             </if>

+ 2 - 0
src/main/webapp/WEB-INF/views/modules/bulkpurchase/orderForm.jsp

@@ -264,6 +264,7 @@
         <thead>
         <tr>
             <th>商品ID</th>
+            <th>skuId</th>
             <th hidden></th>
             <th hidden></th>
             <th>商品名称</th>
@@ -289,6 +290,7 @@
             <tr id="product_${orderProduct.productId}" data-value='${fns:toJson(orderProduct)}'
                 data-index="${index.index}">
                 <td>${orderProduct.productId}</td>
+                <td>${orderProduct.skuId}</td>
                 <td hidden>${orderProduct.shopId}</td>
                 <td hidden>${orderProduct.shopName}</td>
                 <td>${orderProduct.name}</td>

+ 44 - 9
src/main/webapp/WEB-INF/views/modules/bulkpurchase/orderPurchaseProductList.jsp

@@ -297,17 +297,47 @@
             //切换价格
             var price = "priceLabel" + ind;//单价
             var singlePrice = "#" + "discountPrice" + ind;
-            var totalFee = "#"+"totalFee" + ind;
+            var totalFee = "#" + "totalFee" + ind;
             var skus = JSON.parse($("#hideSkus").val());
             var skuIndex = skuStr.split("/")[1];
-            console.log(skus[skuIndex].price);
+            debugger;
+            console.log(skus[skuIndex].skuId);
+            $checkItem["skuId"] =skus[skuIndex].skuId;
+            $("#skuId" + ind).text(skus[skuIndex].skuId);
             //页面价格赋值
             document.getElementById(price).innerHTML = skus[skuIndex].price;
             $(singlePrice).val(skus[skuIndex].price);
             $(totalFee).val(skus[skuIndex].price);
+            var discount = $checkItem["discount"];
             $checkItem["price"] = skus[skuIndex].price;
-            $checkItem["discountPrice"] = skus[skuIndex].price;
+            $checkItem["discountPrice"] = skus[skuIndex].price * discount / 100;
             $checkItem["totalFee"] = skus[skuIndex].price;
+            $("#discountPrice" + ind).val(skus[skuIndex].price * discount / 100);
+            var tax = 0;
+            var invoiceType = $checkItem["invoiceType"];
+            var discountPrice = $checkItem["discountPrice"];
+            var taxRate = $checkItem["taxRate"];
+            var productId = $checkItem["productId"];
+            var num = $checkItem["num"];
+            var includedTax=$checkItem["includedTax"];
+            var base =skus[skuIndex].price* discount / 100;
+            if (productId >= 6060 && productId <= 6069) {
+                tax = 0;
+            } else if ("3"===invoiceType) {
+                tax = "---";
+            } else {
+                tax = discountPrice * taxRate / 100;
+                if("0"===includedTax){
+                    base += discountPrice * taxRate / 100;
+                }
+            }
+            $checkItem["addedValueTax"] = tax;
+            $checkItem["totalAddedValueTax"] = tax * num;
+            $("#addedValueTax" + ind).val(tax);
+            $("#totalAddedValueTax" + ind).val(tax * num);
+            var total = base * num;
+            $("#totalFee" + ind).val(total);
+            $checkItem["totalFee"] = total;
             $("#check-item" + ind).val(JSON.stringify($checkItem));
         }
     </script>
@@ -347,6 +377,7 @@
         <tr>
             <th style="width:20px;"></th>
             <th>商品ID</th>
+            <th>skuId</th>
             <th>商品名称</th>
             <th>商品编码</th>
             <th>供应商名称</th>
@@ -380,6 +411,10 @@
                         <font color="red">(曾购)</font>
                     </c:if>
                 </td>
+                <td>
+                    <label id="skuId${state.index}" value="${purchaseProduct.skuList[0].skuId}"
+                           disabled>${purchaseProduct.skuList[0].skuId}</label>
+                </td>
                 <td title="${purchaseProduct.purchaseProductName}">${fns:abbr(purchaseProduct.purchaseProductName,16)}</td>
                 <td>${purchaseProduct.productNo}</td>
                 <td title="${purchaseProduct.shopName}">${fns:abbr(purchaseProduct.shopName,10)}</td>
@@ -418,18 +453,18 @@
                     <input type="text" name="discount" id="discount${state.index}"
                            value="${empty purchaseProduct.discount ?100:(purchaseProduct.discount)}"
                            onchange="discountPriceVal(${state.index})"
-                    ${(purchaseProduct.productId ge 6060 and purchaseProduct.productId le 6069)
-                            or purchaseProduct.ladderPriceFlag eq 1
-                            or purchaseProduct.svipPriceFlag eq 1?'readonly="readonly"':''}
+                        ${(purchaseProduct.productId ge 6060 and purchaseProduct.productId le 6069)
+                                or purchaseProduct.ladderPriceFlag eq 1
+                                or purchaseProduct.svipPriceFlag eq 1?'readonly="readonly"':''}
                            style="width: 50px">%
                 </td>
                 <td>
                     <input name="discountPrice" id="discountPrice${state.index}"
                            value="${empty purchaseProduct.discount ?(purchaseProduct.svipPriceFlag eq 1?purchaseProduct.svipDiscountPrice: purchaseProduct.price):(purchaseProduct.discount)}"
                            onchange="countDiscount(${state.index})"
-                    ${(purchaseProduct.productId ge 6060 and purchaseProduct.productId le 6069)
-                            or purchaseProduct.ladderPriceFlag eq 1
-                            or purchaseProduct.svipPriceFlag eq 1?'readonly="readonly"':''}
+                        ${(purchaseProduct.productId ge 6060 and purchaseProduct.productId le 6069)
+                                or purchaseProduct.ladderPriceFlag eq 1
+                                or purchaseProduct.svipPriceFlag eq 1?'readonly="readonly"':''}
                            style="width: 80px;text-decoration: ${purchaseProduct.cmPromotion.mode eq 1?'line-through':''}">
                     <c:if test="${purchaseProduct.ladderPriceFlag eq 1}"><br>
                         <a href="javascript:;" class="ladderPrice"><span>阶梯价格</span>