Bladeren bron

提交订单-统计销量

chao 3 jaren geleden
bovenliggende
commit
2222f4e0cd

+ 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

@@ -352,6 +352,8 @@ public class SubmitServiceImpl implements SubmitService {
         AtomicDouble payableAmount = new AtomicDouble(0);
         // 余额支付金额
         AtomicDouble balancePayFee = new AtomicDouble(0);
+        // 统计销量用
+        JSONArray salesInfo = new JSONArray();
 
         // 二手订单标记(二手订单不能同正常商品下单,只能单个商品立即购买下单)
         boolean secondHandOrderFlag = false;
@@ -610,6 +612,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) {
@@ -1302,6 +1309,9 @@ public class SubmitServiceImpl implements SubmitService {
             info.put("code", 2);
             info.put("msg", "提交成功但未支付!");
         }
+        // 统计销量
+        remoteCallService.productSaleUpdate(salesInfo.toString());
+        // 返回结果
         return ResponseJson.success("操作成功!", info);
     }