wangming 3 周之前
父節點
當前提交
2ef916b35e
共有 1 個文件被更改,包括 10 次插入16 次删除
  1. 10 16
      yami-shop-api/src/main/java/com/yami/shop/api/controller/PayController.java

+ 10 - 16
yami-shop-api/src/main/java/com/yami/shop/api/controller/PayController.java

@@ -12,7 +12,6 @@ import com.yami.shop.bean.app.param.PayParam;
 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.common.util.IPHelper;
 import com.yami.shop.security.api.model.YamiUser;
@@ -45,6 +44,7 @@ public class PayController {
     private final OrderService orderService;
     private final RefundDeliveryService refundDeliveryService;
     private final WxProviderService wxProviderService;
+    private final String notifyUrl="http://he56cd66.natappfree.cc";
 
 
     @SneakyThrows
@@ -89,11 +89,8 @@ public class PayController {
     public ResponseEntity<?> pay(@Valid @RequestBody PayParam payParam) {
         System.out.println("开始进行支付...");
         YamiUser user = SecurityUtils.getUser();
-        String userId = user.getUserId();
-        if (!user.isEnabled()) {
-            throw new GlobalException("您已被禁用,不能购买,请联系平台客服");
-        }
-        PayInfoDto payInfo = payService.pay(userId, payParam);
+        CullenUtils.validateDataThrowException(!user.isEnabled(), "您已被禁用,不能购买,请联系平台客服");
+        PayInfoDto payInfo = payService.pay(user.getUserId(), payParam);
 
         if (payInfo.getPayAmount() < 0.01 && payInfo.getIsScore() == 1) {
             return ResponseEntity.ok().build();
@@ -106,7 +103,7 @@ public class PayController {
         po.setTotal(1);
         po.setOpenId(user.getBizUserId());
         po.setOutTradeNo(payInfo.getPayNo());
-        po.setNotifyUrl(getNotifyUrl("http://he56cd66.natappfree.cc"));
+        po.setNotifyUrl(getNotifyUrl(notifyUrl));
         return ResponseEntity.ok(wxProviderService.subJsapi(po));
     }
 
@@ -114,8 +111,6 @@ public class PayController {
     @ApiOperation(value = "退货配送费", notes = "退货配送费")
     @SneakyThrows
     public ResponseEntity<?> refundPay(@Valid @RequestBody PayParam payParam) {
-        YamiUser user = SecurityUtils.getUser();
-
         RefundDelivery refundDelivery = refundDeliveryService.getOne(new LambdaQueryWrapper<RefundDelivery>()
                 .eq(RefundDelivery::getRefundSn, payParam.getOrderNumbers()));
 
@@ -124,21 +119,20 @@ public class PayController {
         JsapiPayInfoPo po = new JsapiPayInfoPo();
         po.setDescription("退货配送费");
         po.setTotal((int) Arith.mul(refundDelivery.getPrice(), 100));
-        po.setOpenId(user.getBizUserId());
+        po.setOpenId(SecurityUtils.getUser().getBizUserId());
         po.setOutTradeNo("refundSn" + payParam.getOrderNumbers());
-        po.setNotifyUrl(getNotifyUrl("http://localhost:8112"));
+        po.setNotifyUrl(getNotifyUrl(notifyUrl));
         return ResponseEntity.ok(wxProviderService.subJsapi(po));
     }
 
     @GetMapping("/isPay/{orderNumbers}")
     @ApiOperation(value = "根据订单号查询该订单是否已经支付", notes = "根据订单号查询该订单是否已经支付")
     public ResponseEntity<Boolean> isPay(@PathVariable String orderNumbers) {
-        YamiUser user = SecurityUtils.getUser();
-        String userId = user.getUserId();
-
         String[] orderNumberArr = orderNumbers.split(StrUtil.COMMA);
-        String orderNumber = orderNumberArr[0];
-        int count = orderService.count(new LambdaQueryWrapper<Order>().eq(Order::getOrderNumber, orderNumber).eq(Order::getUserId, userId).eq(Order::getIsPayed, 1));
+        int count = orderService.count(new LambdaQueryWrapper<Order>()
+                .eq(Order::getOrderNumber, orderNumberArr[0])
+                .eq(Order::getUserId, SecurityUtils.getUser().getUserId())
+                .eq(Order::getIsPayed, 1));
         return ResponseEntity.ok(count > 0);
     }