Browse Source

物流信息改为随订单详情返回,移除物流订单API

Menethil 7 years ago
parent
commit
78127aed91

+ 29 - 8
litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java

@@ -1,9 +1,9 @@
 package org.linlinjava.litemall.core.express;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.linlinjava.litemall.core.express.config.ExpressProperties;
+import org.linlinjava.litemall.core.express.dao.ExpressInfo;
 import org.linlinjava.litemall.core.util.HttpUtil;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
 import org.springframework.util.Base64Utils;
 
 import java.net.URLEncoder;
@@ -33,24 +33,45 @@ public class ExpressService {
     /**
      * 获取物流供应商名
      *
-     * @param vendooCode
+     * @param vendorCode
      * @return
      */
-    public String getVendorName(String vendooCode) {
+    public String getVendorName(String vendorCode) {
         for (Map<String, String> item : properties.getVendors()) {
-            if (item.get("code").equals(vendooCode))
+            if (item.get("code").equals(vendorCode))
                 return item.get("name");
         }
         return null;
     }
 
     /**
+     * 获取物流信息
+     *
+     * @param expCode
+     * @param expNo
+     * @return
+     */
+    public ExpressInfo getExpressInfo(String expCode, String expNo) {
+        try {
+            String result = getOrderTracesByJson(expCode, expNo);
+            ObjectMapper objMap = new ObjectMapper();
+            ExpressInfo ei = objMap.readValue(result, ExpressInfo.class);
+            ei.setShipperName(getVendorName(expCode));
+            return ei;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+    /**
      * Json方式 查询订单物流轨迹
      *
      * @throws Exception
      */
-    public String getOrderTracesByJson(String expCode, String expNo) throws Exception {
-        if(!properties.isEnable()){
+    private String getOrderTracesByJson(String expCode, String expNo) throws Exception {
+        if (!properties.isEnable()) {
             return null;
         }
 
@@ -101,7 +122,7 @@ public class ExpressService {
      * @param charset  编码方式
      * @return DataSign签名
      */
-    private String encrypt(String content, String keyValue, String charset)  {
+    private String encrypt(String content, String keyValue, String charset) {
         if (keyValue != null) {
             content = content + keyValue;
         }

+ 9 - 0
litemall-core/src/main/java/org/linlinjava/litemall/core/express/dao/ExpressInfo.java

@@ -28,6 +28,8 @@ public class ExpressInfo {
     @JsonProperty("Success")
     private boolean Success;
 
+    private String ShipperName;
+
     public void setLogisticCode(String LogisticCode) {
         this.LogisticCode = LogisticCode;
     }
@@ -76,4 +78,11 @@ public class ExpressInfo {
         return Success;
     }
 
+    public String getShipperName() {
+        return ShipperName;
+    }
+
+    public void setShipperName(String shipperName) {
+        ShipperName = shipperName;
+    }
 }

+ 0 - 59
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxExpressController.java

@@ -1,59 +0,0 @@
-package org.linlinjava.litemall.wx.web;
-
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.linlinjava.litemall.core.express.ExpressService;
-import org.linlinjava.litemall.core.express.dao.ExpressInfo;
-import org.linlinjava.litemall.core.util.JacksonUtil;
-import org.linlinjava.litemall.core.util.ResponseUtil;
-import org.linlinjava.litemall.wx.annotation.LoginUser;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * 物流信息查询接口
- */
-@RestController
-@RequestMapping("/wx/express")
-@Validated
-public class WxExpressController {
-
-    @Autowired
-    private ExpressService expressService;
-
-    @PostMapping("query")
-    public Object query(@LoginUser Integer userId, @RequestBody String body) {
-        if (userId == null) {
-            return ResponseUtil.unlogin();
-        }
-
-        String expCode = JacksonUtil.parseString(body, "expCode");
-        String expNo = JacksonUtil.parseString(body, "expNo");
-
-        try {
-            String result = expressService.getOrderTracesByJson(expCode, expNo);
-
-            ObjectMapper objMap = new ObjectMapper();
-            ExpressInfo ei = objMap.readValue(result, ExpressInfo.class);
-
-            Map<String, Object> data = new HashMap<>();
-            data.put("expCode", ei.getLogisticCode());
-            data.put("expNo", ei.getShipperCode());
-            data.put("expName", expressService.getVendorName(expCode));
-            data.put("Traces", ei.getTraces());
-
-            return ResponseUtil.ok(data);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        return ResponseUtil.badArgument();
-    }
-}

+ 13 - 0
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxOrderController.java

@@ -9,6 +9,8 @@ import com.github.binarywang.wxpay.service.WxPayService;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.linlinjava.litemall.core.express.ExpressService;
+import org.linlinjava.litemall.core.express.dao.ExpressInfo;
 import org.linlinjava.litemall.core.notify.NotifyService;
 import org.linlinjava.litemall.core.notify.NotifyType;
 import org.linlinjava.litemall.core.qcode.QCodeService;
@@ -28,6 +30,7 @@ import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
 import org.springframework.transaction.support.DefaultTransactionDefinition;
 import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -95,6 +98,8 @@ public class WxOrderController {
     private LitemallGrouponService grouponService;
     @Autowired
     private QCodeService qCodeService;
+    @Autowired
+    private ExpressService expressService;
 
     public WxOrderController() {
     }
@@ -251,6 +256,14 @@ public class WxOrderController {
         Map<String, Object> result = new HashMap<>();
         result.put("orderInfo", orderVo);
         result.put("orderGoods", orderGoodsVoList);
+
+        // 订单状态为已发货且物流信息不为空
+        //"YTO", "800669400640887922"
+        if (order.getOrderStatus().equals(OrderUtil.STATUS_SHIP)) {
+            ExpressInfo ei = expressService.getExpressInfo(order.getShipChannel(), order.getShipSn());
+            result.put("expressInfo", ei);
+        }
+
         return ResponseUtil.ok(result);
 
     }

+ 3 - 7
litemall-wx-api/src/test/java/org/linlinjava/litemall/wx/ExpressTest.java

@@ -1,6 +1,5 @@
 package org.linlinjava.litemall.wx;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.linlinjava.litemall.core.express.ExpressService;
@@ -17,15 +16,12 @@ public class ExpressTest {
     @Test
     public void test() {
         ExpressService expressService = new ExpressService();
-        String result = null;
+        ExpressInfo ei = null;
         try {
-            result = expressService.getOrderTracesByJson("YTO", "800669400640887922");
-            ObjectMapper objMap = new ObjectMapper();
-            ExpressInfo ei = objMap.readValue(result, ExpressInfo.class);
-            ei.getTraces();
+            ei = expressService.getExpressInfo("YTO", "800669400640887922");
         } catch (Exception e) {
             e.printStackTrace();
         }
-        System.out.print(result);
+        System.out.print(ei);
     }
 }