Преглед на файлове

Merge remote-tracking branch 'origin/developer' into developerA

chao преди 3 години
родител
ревизия
ae35db40f9

+ 24 - 0
src/main/java/com/caimei365/order/feign/CommodityFeign.java

@@ -0,0 +1,24 @@
+package com.caimei365.order.feign;
+
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/10/11
+ */
+@FeignClient("CAIMEI365-CLOUD-COMMODITY")
+public interface CommodityFeign {
+    /**
+     * 更新商品销量
+     * @param productInfo [ // 商品id,数量
+     *                   {"productId": 2789, "productCount": 1},
+     *                   {"productId": 2790, "productCount": 2}
+     *                 ]
+     */
+    @PostMapping("/commodity/price/sales/update")
+    String productSaleUpdate(@RequestParam String productInfo);
+}

+ 10 - 0
src/main/java/com/caimei365/order/service/RemoteCallService.java

@@ -1,6 +1,7 @@
 package com.caimei365.order.service;
 
 import org.springframework.http.HttpHeaders;
+import org.springframework.web.bind.annotation.PostMapping;
 
 /**
  * 订单推送服务
@@ -47,4 +48,13 @@ public interface RemoteCallService {
      */
     String getLogisticsByNumber(String number, String companyCode, String mobile);
 
+    /**
+     * 更新商品销量
+     * @param productInfo [ // 商品id,数量
+     *                   {"productId": 2789, "productCount": 1},
+     *                   {"productId": 2790, "productCount": 2}
+     *                 ]
+     */
+    String productSaleUpdate(String productInfo);
+
 }

+ 25 - 0
src/main/java/com/caimei365/order/service/impl/RemoteCallServiceImpl.java

@@ -1,6 +1,7 @@
 package com.caimei365.order.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.caimei365.order.feign.CommodityFeign;
 import com.caimei365.order.feign.ToolsFeign;
 import com.caimei365.order.feign.UserFeign;
 import com.caimei365.order.mapper.MessagePushMapper;
@@ -36,6 +37,8 @@ public class RemoteCallServiceImpl implements RemoteCallService {
     private ToolsFeign toolsFeign;
     @Resource
     private UserFeign userFeign;
+    @Resource
+    private CommodityFeign commodityFeign;
 
     /**
      * 生成短链接
@@ -149,4 +152,26 @@ public class RemoteCallServiceImpl implements RemoteCallService {
         }
         return resultData.get();
     }
+
+    /**
+     * 更新商品销量
+     *
+     * @param productInfo [ // 商品id,数量
+     *                    {"productId": 2789, "productCount": 1},
+     *                    {"productId": 2790, "productCount": 2}
+     *                    ]
+     */
+    @Override
+    public String productSaleUpdate(String productInfo) {
+        AtomicReference<String> resultData = new AtomicReference<>("");
+        try {
+            // 调用 ToolsFeign 获取物流
+            String jsonStr = commodityFeign.productSaleUpdate(productInfo);
+            log.info("更新商品销量:"+productInfo);
+            resultData.set(jsonStr);
+        } catch (Exception e) {
+            log.error("更新商品销量失败:", e);
+        }
+        return resultData.get();
+    }
 }

+ 10 - 0
src/main/java/com/caimei365/order/service/impl/SubmitServiceImpl.java

@@ -358,6 +358,8 @@ public class SubmitServiceImpl implements SubmitService {
         AtomicDouble payableAmount = new AtomicDouble(0);
         // 余额支付金额
         AtomicDouble balancePayFee = new AtomicDouble(0);
+        // 统计销量用
+        JSONArray salesInfo = new JSONArray();
 
         // 二手订单标记(二手订单不能同正常商品下单,只能单个商品立即购买下单)
         boolean secondHandOrderFlag = false;
@@ -646,6 +648,11 @@ public class SubmitServiceImpl implements SubmitService {
                     // 税费
                     product.setAddedValueTax(discountTax);
                     product.setTotalAddedValueTax(taxFee);
+                    // 销量
+                    JSONObject salesObject = new JSONObject();
+                    salesObject.put("productId", product.getProductId());
+                    salesObject.put("productCount", product.getNum());
+                    salesInfo.add(salesObject);
                 }
                 // 付供应商税费
                 if (null == product.getShopTaxRate() || product.getShopTaxRate() <= 0) {
@@ -1347,6 +1354,9 @@ public class SubmitServiceImpl implements SubmitService {
             info.put("code", 2);
             info.put("msg", "提交成功但未支付!");
         }
+        // 统计销量
+        remoteCallService.productSaleUpdate(salesInfo.toString());
+        // 返回结果
         return ResponseJson.success("操作成功!", info);
     }
 

+ 2 - 2
src/main/resources/mapper/SubmitMapper.xml

@@ -31,14 +31,14 @@
         INSERT INTO cm_order_product (orderID, orderNo, shopOrderID, shopOrderNo, orderPromotionsId, productId, shopId, name,
                                     productImage, price, price1, shopName, costPrice, normalPrice, ladderPriceFlag, discountPrice, discount,
                                     totalAmount, totalFee, shouldPayFee, productUnit, num, presentNum, discountFee, includedTax,
-                                    invoiceType, taxRate, addedValueTax, totalAddedValueTax, singleShouldPayTotalTax, shouldPayTotalTax,
+                                    invoiceType, taxRate, addedValueTax, totalAddedValueTax, supplierTaxRate, singleShouldPayTotalTax, shouldPayTotalTax,
                                     shopProductAmount, singleShopFee, shopFee, singleOtherFee, otherFee, singleCmFee, cmFee,
                                     payStatus, buyAgainFlag, notOutStore, isActProduct, productType, svipPriceFlag,svipPriceType,
                                       svipDiscount,svipReduction)
         VALUES (#{orderId},#{orderNo},#{shopOrderId},#{shopOrderNo},#{orderPromotionsId},#{productId},#{shopId},#{name},
                 #{image},#{price},#{price},#{shopName},#{costPrice},#{normalPrice},#{ladderPriceFlag},#{discountPrice},#{discount},
                 #{totalAmount},#{totalFee},#{shouldPayFee},#{productUnit},#{num},#{presentNum},#{discountFee},#{includedTax},
-                #{invoiceType},#{taxRate},#{addedValueTax},#{totalAddedValueTax},#{singleShouldPayTotalTax},#{shouldPayTotalTax},
+                #{invoiceType},#{taxRate},#{addedValueTax},#{totalAddedValueTax},#{shopTaxRate},#{singleShouldPayTotalTax},#{shouldPayTotalTax},
                 #{shopProductAmount},#{singleShopFee},#{shopFee},#{singleOtherFee},#{otherFee},#{singleCmFee},#{cmFee},
                 #{payStatus},#{buyAgainFlag},#{notOutStore},#{actProduct},#{productType},#{svipPriceFlag},#{svipPriceType},#{svipDiscount},#{svipReduction})
     </insert>