基于mall4j产品的二开项目后端
lee
2024-12-18 efdb99f8cecc4afb592afad79c761081d5d5cf22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许,不可做商业用途!
 *
 * 版权所有,侵权必究!
 */
package com.yami.shop.api.controller;
 
 
import com.yami.shop.bean.app.param.PayParam;
import com.yami.shop.bean.enums.PayEntry;
import com.yami.shop.bean.pay.PayInfoDto;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.manager.impl.PayManager;
import com.yami.shop.security.api.model.YamiUser;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.PayInfoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
 
/**
 * @author LGH
 */
@RestController
@RequestMapping("/p/order")
@Tag(name = "订单支付接口")
@AllArgsConstructor
public class PayController {
 
    private final PayInfoService payInfoService;
    private final PayManager payManager;
 
    @PostMapping("/pay")
    @Operation(summary = "根据订单号进行支付" , description = "根据订单号进行支付")
    @SneakyThrows
    public ServerResponseEntity<?> pay(HttpServletResponse httpResponse, @Valid @RequestBody PayParam payParam) {
        YamiUser user = SecurityUtils.getUser();
        String userId = user.getUserId();
        if (!user.getEnabled()) {
            // 您已被禁用,不能购买,请联系平台客服
            throw new YamiShopBindException("yami.order.pay.user.disable");
        }
        PayInfoDto payInfo = payInfoService.pay(userId, payParam);
        payInfo.setBizUserId(user.getBizUserId());
        payInfo.setPayType(payParam.getPayType());
        payInfo.setApiNoticeUrl("/notice/pay/" + PayEntry.ORDER.value() + "/" + payParam.getPayType());
        payInfo.setReturnUrl(payParam.getReturnUrl());
        return payManager.doPay(httpResponse, payInfo);
    }
 
    @GetMapping("/isPay/{payEntry}/{orderNumbers}")
    @Operation(summary = "根据订单号查询该订单是否已经支付" , description = "根据订单号查询该订单是否已经支付")
    @Parameter(name = "orderNumbers", description = "多个订单号拼接" , required = true)
    public ServerResponseEntity<Boolean> isPay(@PathVariable Integer payEntry, @PathVariable String orderNumbers) {
        YamiUser user = SecurityUtils.getUser();
        Integer count = payInfoService.queryPay(orderNumbers, user.getUserId(), payEntry);
        boolean res = count != null && count == 1;
        return ServerResponseEntity.success(res);
    }
}