wangming 4 주 전
부모
커밋
724c160995

+ 25 - 22
yami-shop-api/src/main/java/com/yami/shop/api/controller/PayController.java

@@ -1,16 +1,5 @@
-/*
- * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
- *
- * https://www.gz-yami.com/
- *
- * 未经允许,不可做商业用途!
- *
- * 版权所有,侵权必究!
- */
-
 package com.yami.shop.api.controller;
 
-
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.yami.shop.bean.app.param.PayParam;
@@ -18,21 +7,27 @@ import com.yami.shop.bean.model.Order;
 import com.yami.shop.bean.model.RefundDelivery;
 import com.yami.shop.bean.pay.PayInfoDto;
 import com.yami.shop.common.exception.GlobalException;
+import com.yami.shop.common.util.Arith;
 import com.yami.shop.security.api.model.YamiUser;
 import com.yami.shop.security.api.util.SecurityUtils;
 import com.yami.shop.service.*;
+import com.yami.shop.wx.po.JsapiPayInfoPo;
+import com.yami.shop.wx.service.WxProviderService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import lombok.SneakyThrows;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
+import java.util.Map;
 
 @RestController
-@RequestMapping("/p/order")
+@RequestMapping("/order")
+//@RequestMapping("/p/order")
 @Api(tags = "订单接口")
 @AllArgsConstructor
 public class PayController {
@@ -42,31 +37,39 @@ public class PayController {
     private final OrderService orderService;
     private final OrderRefundService orderRefundService;
     private final RefundDeliveryService refundDeliveryService;
+    @Autowired
+    private final WxProviderService wxProviderService;
+
 
     /**
      * 支付接口
      */
+    @SneakyThrows
     @PostMapping("/pay")
     @ApiOperation(value = "根据订单号进行支付", notes = "根据订单号进行支付")
-    @SneakyThrows
-    public ResponseEntity<?> pay(HttpServletResponse httpResponse, @Valid @RequestBody PayParam payParam) {
+    public ResponseEntity<?> pay(@Valid @RequestBody PayParam payParam) {
         YamiUser user = SecurityUtils.getUser();
         String userId = user.getUserId();
-
         if (!user.isEnabled()) {
             throw new GlobalException("您已被禁用,不能购买,请联系平台客服");
         }
-
-
         PayInfoDto payInfo = payService.pay(userId, payParam);
 
-        payInfo.setBizUserId(user.getBizUserId());
-        payInfo.setPayType(payParam.getPayType());
-        payInfo.setApiNoticeUrl("/notice/pay/order/" + payParam.getPayType());
-        payInfo.setReturnUrl(payParam.getReturnUrl());
+        if (payInfo.getPayAmount() < 0.01 && payInfo.getIsScore() == 1) {
+            return ResponseEntity.ok().build();
+        }
 
+        if (payInfo.getPayAmount() < 0.01) {
+            throw new GlobalException("订单金额有误,无法进行支付");
+        }
 
-        return payManagerService.doPay(httpResponse, payInfo);
+        JsapiPayInfoPo po = new JsapiPayInfoPo();
+        po.setDescription(payInfo.getBody());
+        po.setTotal((int) Arith.mul(payInfo.getPayAmount(), 100));
+        po.setOpenId(user.getBizUserId());
+        po.setOutTradeNo(payInfo.getPayNo());
+        po.setNotifyUrl("http://localhost:8112/notice/pay/order/" + payParam.getPayType());
+        return ResponseEntity.ok(wxProviderService.subJsapi(po));
     }
 
 

+ 1 - 2
yami-shop-bean/src/main/java/com/yami/shop/bean/pay/PayInfoDto.java

@@ -34,7 +34,6 @@ public class PayInfoDto {
      */
     private Double payAmount;
 
-
     /**
      * 是否纯积分商品订单 0不是 1是
      */
@@ -56,7 +55,7 @@ public class PayInfoDto {
     private String returnUrl;
 
     /**
-     * 第三方用户id
+     * 第三方用户id(openid)
      */
     private String bizUserId;
 

+ 3 - 0
yami-shop-service/src/main/java/com/yami/shop/service/impl/PayServiceImpl.java

@@ -71,10 +71,13 @@ public class PayServiceImpl implements PayService {
                             .eq(OrderSettlement::getUserId,userId)
                             .eq(OrderSettlement::getOrderNumber,orderNumber)
             );
+            System.out.println(orderSettlement);
             if (Objects.equals(orderSettlement.getPayStatus(), 1)) {
                 throw new GlobalException("支付失败,订单不在未支付状态");
             }
             Order order = orderMapper.getOrderByOrderNumber(orderNumber);
+            System.out.println("order"+order);
+            System.out.println(payParam.getPayType());
             order.setPayType(payParam.getPayType());
             orderMapper.updateById(order);
 

+ 3 - 0
yami-shop-wx/src/main/java/com/yami/shop/wx/po/JsapiPayInfoPo.java

@@ -28,4 +28,7 @@ public class JsapiPayInfoPo {
     @ApiModelProperty(value = "outTradeNo")
     @NotNull(message = "outTradeNo不能为空...")
     private String outTradeNo;
+
+    @ApiModelProperty(value = "notifyUrl",hidden = true)
+    private String notifyUrl;
 }

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

@@ -60,7 +60,7 @@ public class WxProviderServiceImpl implements WxProviderService {
         params.put("payer", payerMap);
         params.put("description", po.getDescription());
         params.put("out_trade_no", po.getOutTradeNo());
-        params.put("notify_url", wechatPayServiceConfig.getNotifyUrl());
+        params.put("notify_url", po.getNotifyUrl());
         JSONObject attachJson = new JSONObject();
         attachJson.put("orderNo", po.getOutTradeNo());
         params.put("attach", JSONObject.toJSONString(attachJson));