Browse Source

add deliver

wangming 18 hours ago
parent
commit
7019d8e9c4

+ 39 - 10
yami-shop-api/src/main/java/com/yami/shop/api/controller/MyOrderController.java

@@ -13,7 +13,7 @@ package com.yami.shop.api.controller;
 import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.google.common.collect.Lists;
 import com.yami.shop.bean.app.dto.*;
 import com.yami.shop.bean.enums.OrderStatus;
 import com.yami.shop.bean.enums.RefundStatusEnum;
@@ -26,9 +26,15 @@ import com.yami.shop.common.util.PageParam;
 import com.yami.shop.config.ShopConfig;
 import com.yami.shop.dao.PointsRecordMapper;
 import com.yami.shop.security.api.util.SecurityUtils;
+import com.yami.shop.security.comment.dao.AppConnectMapper;
+import com.yami.shop.security.comment.model.AppConnect;
 import com.yami.shop.service.*;
 import com.yami.shop.service.hb.IHBOrderService;
 import com.yami.shop.utils.CullenUtils;
+import com.yami.shop.wx.po.TraceWaybill;
+import com.yami.shop.wx.po.TraceWaybillDetail;
+import com.yami.shop.wx.po.TraceWaybillGoodsInfo;
+import com.yami.shop.wx.service.impl.WxProviderServiceImpl;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -53,26 +59,49 @@ import java.util.Objects;
 public class MyOrderController {
 
     private final OrderService orderService;
-
     private final MapperFacade mapperFacade;
-
     private final UserAddrOrderService userAddrOrderService;
-
     private final ProductService productService;
-
     private final SkuService skuService;
-
     private final ShopConfig shopConfig;
-
     private final MyOrderService myOrderService;
-
     private final ShopDetailService shopDetailService;
-
     private final OrderItemService orderItemService;
     private final IHBOrderService ihbOrderService;
-
     private final OrderRefundService orderRefundService;
     private final PointsRecordMapper pointsRecordMapper;
+    private final OrderSettlementService orderSettlementService;
+    private final AppConnectMapper appConnectMapper;
+    private final DeliveryService deliveryService;
+
+    @SuppressWarnings("all")
+    @GetMapping("/getWaybillToken")
+    @ApiOperation(value = "微信物流-获取waybill_token")
+    public ResponseEntity<String> getWaybillToken(@RequestParam(value = "orderNumber") String orderNumber) {
+        CullenUtils.validateDataThrowException(orderNumber==null,"订单号不能为空...");
+        AppConnect connect = appConnectMapper.getByUserId(SecurityUtils.getUser().getUserId(), 1);
+        CullenUtils.validateDataThrowException(orderNumber==null,"openid不存在...");
+        Order order = orderService.getOrderByOrderNumber(orderNumber);
+        CullenUtils.validateDataThrowException(order==null,"订单不存在...");
+        UserAddrOrder userAddrOrder = userAddrOrderService.getById(order.getAddrOrderId());
+        CullenUtils.validateDataThrowException(userAddrOrder==null,"收货地址不存在...");
+        Delivery delivery = deliveryService.getById(order.getDvyId());
+        CullenUtils.validateDataThrowException(delivery==null,"订单未发货...");
+        List<OrderItem> orderItemList = orderItemService.getOrderItemsByOrderNumber(orderNumber);
+        CullenUtils.validateDataThrowException(orderItemList.isEmpty(),"订单项不存在...");
+        OrderSettlement settlement = orderSettlementService.getOne(new LambdaQueryWrapper<OrderSettlement>().eq(OrderSettlement::getOrderNumber, orderNumber));
+        CullenUtils.validateDataThrowException(settlement==null,"订单结算不存在...");
+        TraceWaybill traceWaybill = new TraceWaybill();
+        traceWaybill.setOpenid(connect.getBizUserId());
+        traceWaybill.setReceiverPhone(userAddrOrder.getMobile());
+        traceWaybill.setDeliveryId(delivery.getDvyNo());
+        traceWaybill.setWaybillId(order.getDvyFlowId());
+        List<TraceWaybillGoodsInfo> goodsInfoList = Lists.newArrayList();
+        orderItemList.forEach(item -> goodsInfoList.add(new TraceWaybillGoodsInfo(item.getProdName(),item.getPic())));
+        traceWaybill.setGoodsInfo(new TraceWaybillDetail(goodsInfoList));
+        traceWaybill.setTransId(settlement.getBizPayNo());
+        return ResponseEntity.ok(WxProviderServiceImpl.traceWaybill(traceWaybill));
+    }
 
 
     /**

+ 0 - 1
yami-shop-api/src/main/java/com/yami/shop/api/controller/OrderController.java

@@ -330,7 +330,6 @@ public class OrderController {
         return ResponseEntity.ok(new OrderNumbersDto(orderNumbers.toString(), mergerOrder.getNextPay()));
     }
 
-
     @GetMapping("/getOrderPayInfoByOrderNumber")
     @ApiOperation(value = "获取订单支付信息", notes = "获取订单支付的商品/地址信息")
     @ApiImplicitParam(name = "orderNumbers", value = "订单流水号", required = true, dataType = "String")

+ 39 - 0
yami-shop-wx/src/main/java/com/yami/shop/wx/po/TraceWaybill.java

@@ -0,0 +1,39 @@
+package com.yami.shop.wx.po;
+
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author kaur
+ */
+@Data
+@ApiModel(value = "trace_waybill")
+public class TraceWaybill {
+
+    @ApiModelProperty(value = "openid")
+    @SerializedName("openid")
+    private String openid;
+
+    @ApiModelProperty(value = "收件人手机号")
+    @SerializedName("receiver_phone")
+    private String receiverPhone;
+
+    @ApiModelProperty(value = "运力id SF")
+    @SerializedName("delivery_id")
+    private String deliveryId;
+
+    @ApiModelProperty(value = "运单号")
+    @SerializedName("waybill_id")
+    private String waybillId;
+
+    @ApiModelProperty(value = "商品信息")
+    @SerializedName("goods_info")
+    private TraceWaybillDetail goodsInfo;
+
+    @ApiModelProperty(value = "交易单号")
+    @SerializedName("trans_id")
+    private String transId;
+
+}

+ 25 - 0
yami-shop-wx/src/main/java/com/yami/shop/wx/po/TraceWaybillDetail.java

@@ -0,0 +1,25 @@
+package com.yami.shop.wx.po;
+
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+/**
+ * @author kaur
+ */
+@Data
+@ApiModel(value = "TraceWaybillDetailList")
+@NoArgsConstructor
+@AllArgsConstructor
+public class TraceWaybillDetail {
+
+    @ApiModelProperty(value = "商品信息")
+    @SerializedName("detail_list")
+    private List<TraceWaybillGoodsInfo> detailList;
+
+}

+ 27 - 0
yami-shop-wx/src/main/java/com/yami/shop/wx/po/TraceWaybillGoodsInfo.java

@@ -0,0 +1,27 @@
+package com.yami.shop.wx.po;
+
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author kaur
+ */
+@Data
+@ApiModel(value = "TraceWaybillGoodsInfo")
+@AllArgsConstructor
+@NoArgsConstructor
+public class TraceWaybillGoodsInfo {
+
+    @ApiModelProperty(value = "goods_name")
+    @SerializedName("goods_name")
+    private String goodsName;
+
+    @ApiModelProperty(value = "goods_img_url")
+    @SerializedName("goods_img_url")
+    private String goodsImgUrl;
+
+}

+ 42 - 7
yami-shop-wx/src/main/java/com/yami/shop/wx/service/impl/WxProviderServiceImpl.java

@@ -1,4 +1,5 @@
 package com.yami.shop.wx.service.impl;
+import com.yami.shop.wx.po.*;
 
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
@@ -17,8 +18,6 @@ import com.yami.shop.wx.config.CombinePayUrlEnum;
 import com.yami.shop.wx.config.WechatPayServiceConfig;
 import com.yami.shop.wx.config.WxConstants;
 import com.yami.shop.wx.form.*;
-import com.yami.shop.wx.po.JsapiPayInfoPo;
-import com.yami.shop.wx.po.RefundInfoPo;
 import com.yami.shop.wx.service.WxProviderService;
 import com.yami.shop.wx.utils.*;
 import lombok.SneakyThrows;
@@ -445,7 +444,7 @@ public class WxProviderServiceImpl implements WxProviderService {
     public static void uploadShippingInfo(String trackingNo, String transactionId, String itemDesc,
                                            String phone, String openid, String expressCompany, Integer type) {
         AccessToken accessToken = AccessTokenApi.getAccessToken(WxConstants.APPLET_APPID, WxConstants.APPLET_SECRET);
-        String url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" + accessToken;
+        String url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" + accessToken.getToken();
         // 定义日期时间格式化对象
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
         // 格式化日期时间
@@ -506,11 +505,45 @@ public class WxProviderServiceImpl implements WxProviderService {
         }
     }
 
-    private static String rsaEncryptData(String data) {
-        return data;
+
+    public static String traceWaybill(TraceWaybill traceWaybill) {
+        AccessToken accessToken = AccessTokenApi.getAccessToken(WxConstants.APPLET_APPID, WxConstants.APPLET_SECRET);
+        String url = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/trace_waybill?access_token=" + accessToken.getToken();
+        try {
+            CloseableHttpClient httpClient = HttpClients.createDefault();
+            HttpPost httpPost = new HttpPost(url);
+            httpPost.addHeader("Content-Type", "application/json");
+            StringEntity requestBody = new StringEntity(new Gson().toJson(traceWaybill),  ContentType.APPLICATION_JSON.withCharset("UTF-8"));
+            httpPost.setEntity(requestBody);
+            CloseableHttpResponse response = httpClient.execute(httpPost);
+            HttpEntity responseEntity = response.getEntity();
+            String responseString = EntityUtils.toString(responseEntity,"UTF-8");
+            log.info(responseString);
+            response.close();
+            httpClient.close();
+            return responseString;
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+
+    private static void trace_waybill() {
+        TraceWaybill traceWaybill = new TraceWaybill();
+        traceWaybill.setOpenid("openid");
+        traceWaybill.setReceiverPhone("接收人电话");
+        traceWaybill.setDeliveryId("SF");
+        traceWaybill.setWaybillId("SF123456");
+        List<TraceWaybillGoodsInfo> goodsInfoList = Lists.newArrayList();
+        goodsInfoList.add(new TraceWaybillGoodsInfo("可口可乐","地址"));
+        traceWaybill.setGoodsInfo(new TraceWaybillDetail(goodsInfoList));
+        traceWaybill.setTransId("交易id");
+        System.out.println(new Gson().toJson(traceWaybill));
     }
 
 
+
     //测试
     public static void serviceAddMerchant() {
         SubmitInfo submitInfo = new SubmitInfo();
@@ -604,9 +637,11 @@ public class WxProviderServiceImpl implements WxProviderService {
         System.out.println(json);
     }
 
+    private static String rsaEncryptData(String data) {
+        return data;
+    }
 
     public static void main(String[] args) {
-
-        serviceAddMerchant();
+        trace_waybill();
     }
 }