From efdb99f8cecc4afb592afad79c761081d5d5cf22 Mon Sep 17 00:00:00 2001
From: lee <4766465@qq.com>
Date: Wed, 18 Dec 2024 13:27:00 +0800
Subject: [PATCH] init

---
 yami-shop-api/src/main/java/com/yami/shop/api/controller/PayNoticeController.java |   95 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/yami-shop-api/src/main/java/com/yami/shop/api/controller/PayNoticeController.java b/yami-shop-api/src/main/java/com/yami/shop/api/controller/PayNoticeController.java
new file mode 100644
index 0000000..541c1a7
--- /dev/null
+++ b/yami-shop-api/src/main/java/com/yami/shop/api/controller/PayNoticeController.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
+ *
+ * https://www.mall4j.com/
+ *
+ * 未经允许,不可做商业用途!
+ *
+ * 版权所有,侵权必究!
+ */
+package com.yami.shop.api.controller;
+
+import com.alipay.api.AlipayApiException;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.github.binarywang.wxpay.exception.WxPayException;
+import com.yami.shop.bean.bo.PayInfoResultBO;
+import com.yami.shop.bean.enums.PayEntry;
+import com.yami.shop.bean.enums.PayStatus;
+import com.yami.shop.bean.model.PayInfo;
+import com.yami.shop.common.enums.PayType;
+import com.yami.shop.common.response.ResponseEnum;
+import com.yami.shop.common.response.ServerResponseEntity;
+import com.yami.shop.manager.impl.PayManager;
+import com.yami.shop.service.PayInfoService;
+import com.yami.shop.user.common.service.UserBalanceService;
+import com.yami.shop.user.common.service.UserLevelService;
+import io.swagger.v3.oas.annotations.Hidden;
+import lombok.AllArgsConstructor;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.UnsupportedEncodingException;
+import java.util.Objects;
+
+/**
+ * @author LGH
+ */
+@Hidden
+@RestController
+@RequestMapping("/notice/pay")
+@AllArgsConstructor
+public class PayNoticeController {
+
+    private final PayManager payManager;
+
+    private final PayInfoService payInfoService;
+
+    private final UserLevelService userLevelService;
+
+    private final UserBalanceService userBalanceService;
+
+
+    /**
+     * 支付异步回调
+     */
+    @RequestMapping("/{payEntry}/{payType}")
+    public ServerResponseEntity<String> notice(HttpServletRequest request,
+                                         @PathVariable("payEntry") Integer payEntry,
+                                         @PathVariable("payType") Integer payType,
+                                         @RequestBody(required = false) String data) throws WxPayException, UnsupportedEncodingException, AlipayApiException {
+
+        PayInfoResultBO payInfoResultBO = payManager.validateAndGetPayInfo(request, PayType.instance(payType), data);
+
+        // 校验订单参数异常
+        if (!payInfoResultBO.getIsPaySuccess()) {
+            return ServerResponseEntity.success(null);
+        }
+
+        PayInfo payInfo = payInfoService.getOne(new LambdaQueryWrapper<PayInfo>().eq(PayInfo::getPayNo, payInfoResultBO.getPayNo()));
+
+        // 已经支付
+        if (Objects.equals(payInfo.getPayStatus(), PayStatus.PAYED.value()) || Objects.equals(payInfo.getPayStatus(), PayStatus.REFUND.value())) {
+            return ServerResponseEntity.success(payInfoResultBO.getSuccessString());
+        }
+        // 支付金额不对
+        if (!Objects.equals(payInfo.getPayAmount(), payInfoResultBO.getPayAmount()) && !Objects.equals(payInfo.getPayType(), PayType.PAYPAL.value())) {
+            return ServerResponseEntity.fail(ResponseEnum.UNAUTHORIZED);
+        }
+
+        if (Objects.equals(payEntry, PayEntry.ORDER.value())) {
+            return payInfoService.noticeOrder(payInfoResultBO, payInfo);
+        }
+        else if (Objects.equals(payEntry, PayEntry.RECHARGE.value())) {
+            return userBalanceService.noticeRecharge(payInfoResultBO, payInfo);
+        }
+        else if (Objects.equals(payEntry, PayEntry.VIP.value())) {
+            return userLevelService.noticeBuyVip(payInfoResultBO, payInfo);
+        }
+
+        return ServerResponseEntity.fail(ResponseEnum.UNAUTHORIZED);
+    }
+
+}

--
Gitblit v1.9.3