liujc 1 năm trước cách đây
mục cha
commit
94f411aa7c

+ 99 - 0
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/open/UserPaymentClient.java

@@ -0,0 +1,99 @@
+package com.yonge.cooleshow.admin.controller.open;
+
+import com.alibaba.fastjson.JSON;
+import com.microsvc.toolkit.common.response.template.R;
+import com.microsvc.toolkit.common.webportal.exception.BizException;
+import com.microsvc.toolkit.config.jwt.utils.JwtUserInfo;
+import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
+import com.microsvc.toolkit.middleware.payment.common.api.entity.PaymentResp;
+import com.microsvc.toolkit.middleware.payment.common.api.entity.RefundResp;
+import com.yonge.cooleshow.biz.dal.service.UserOrderService;
+import com.yonge.cooleshow.biz.dal.service.UserPaymentCoreService;
+import com.yonge.cooleshow.biz.dal.service.UserPaymentOrderService;
+import com.yonge.cooleshow.biz.dal.wrapper.UserPaymentOrderWrapper;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Objects;
+
+@Slf4j
+@RestController
+@RequestMapping("/open/userOrder")
+@Api(tags = "开放权限接口-支付回调")
+public class UserPaymentClient {
+
+    @Autowired
+    private PaymentServiceContext paymentServiceContext;
+    @Autowired
+    private UserPaymentCoreService userPaymentCoreService;
+    @Autowired
+    private UserPaymentOrderService userPaymentOrderService;
+
+    @Autowired
+    private UserOrderService userOrderService;
+
+    /**
+     * 支付消息回调
+     * @param request HttpServletRequest
+     * @return String
+     */
+    @ApiOperation(value = "支付消息回调", notes = "三方支付平台支付消息通知")
+    @ApiImplicitParams({
+        @ApiImplicitParam(name = "vendor", value = "服务提供方", dataType = "String")
+    })
+    @RequestMapping(value = "/payment/callback/{vendor}", method = {RequestMethod.GET, RequestMethod.POST})
+    public String payment(@PathVariable("vendor") String vendor, HttpServletRequest request) {
+
+        // 支付回调消息
+        PaymentResp paymentResp = paymentServiceContext.getPaymentService(vendor).callbackNotifyForPay(request);
+        if (Objects.isNull(paymentResp)) {
+            return null;
+        }
+        log.info("payment vendor={}, paymentResp={}", vendor, JSON.toJSONString(paymentResp));
+        // 支付订单确认
+        UserPaymentOrderWrapper.UserPaymentOrder paymentOrder = userPaymentOrderService
+                .getUserPaymentOrderByOrderNo(paymentResp.getTransNo(), paymentResp.getMerOrderNo());
+        if (Objects.isNull(paymentOrder)) {
+            return paymentResp.getMsg();
+        }
+
+        // 执行支付回调流程
+        userPaymentCoreService.executePaymentCallback(paymentResp);
+
+        return paymentServiceContext.getPaymentService(vendor).returnNotifyResult(request);
+    }
+
+    @ApiOperation(value = "用户付款", notes = "用户付款")
+    @PostMapping("/executePayment")
+    public R<UserPaymentOrderWrapper.PaymentReq> executePayment(@Validated @RequestBody UserPaymentOrderWrapper.PaymentOrderReqConfig config) {
+
+        // 用户登录状态校验
+        if (StringUtils.isBlank(config.getUserId())) {
+            throw BizException.from("用户未登录");
+        }
+
+        // 用户下单请求
+        UserPaymentOrderWrapper.PaymentOrderReqConfig reqConfig = UserPaymentOrderWrapper.PaymentOrderReqConfig.from(config.jsonString());
+
+        JwtUserInfo<Object> userInfo = JwtUserInfo.builder()
+            .userId(config.getUserId())
+            .clientType(config.getUserType().getCode())
+            .build();
+        // 创建用户支付数据
+        UserPaymentOrderWrapper.PaymentReq paymentConfig = userPaymentCoreService.executePayment(userInfo, reqConfig);
+        if (Objects.isNull(paymentConfig)) {
+            throw BizException.from("用户支付请求错误");
+        }
+
+        return R.from(paymentConfig);
+    }
+
+}

+ 0 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/UserPaymentCoreService.java

@@ -48,7 +48,6 @@ public interface UserPaymentCoreService {
      */
     UserPaymentOrderWrapper.PaymentReq executePayment(JwtUserInfo<?> userInfo, UserPaymentOrderWrapper.PaymentOrderReqConfig reqConfig);
 
-    @Transactional
     UserPaymentOrderWrapper.PaymentConfig executeOrder(UserPaymentOrderWrapper.UserPaymentOrder orderReq);
 
     /**

+ 0 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserPaymentCoreServiceImpl.java

@@ -938,6 +938,4 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
         //log.info("scheduleUpdatePaymentOrderStatus PAYMENT_FINISH ------> ");
     }
 
-
-
 }

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/UserPaymentOrderWrapper.java

@@ -566,6 +566,9 @@ public class UserPaymentOrderWrapper {
         @ApiModelProperty("支付用户Id")
         private String userId;
 
+        @ApiModelProperty("支付用户类型")
+        private ClientEnum userType;
+
         public String jsonString() {
             return JSON.toJSONString(this);
         }