8.6
luodangjia
2024-08-06 1529842471c8c07a5181a10404b6dff2a0944500
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.ruoyi.user.controller;
 
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.api.entity.Withdraw;
import com.ruoyi.order.api.entity.WithdrawDetailVO;
import com.ruoyi.order.api.feignClient.WithdrawClient;
import com.ruoyi.system.api.model.LoginUserInfo;
import com.ruoyi.user.service.WithdrawService;
import com.ruoyi.user.vo.WithdrawListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;
 
/**
 * <p>
 * 用户提现申请记录表 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-06-07
 */
@RestController
@RequestMapping("/withdraw")
@Api(tags = {"用户端-个人中心-提现"})
public class WithdrawController {
 
    @Resource
    private WithdrawService withdrawService;
    @Resource
    private TokenService tokenService;
    @Resource
    private WithdrawClient withdrawClient;
    @Resource
    private RedisService redisService;
 
    @GetMapping("/withdrawList")
    @ApiOperation(value = "提现列表", tags = {"用户端-个人中心-提现"})
    public R<WithdrawListVO> withdrawList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        return R.ok(withdrawService.withdrawList(loginUser.getUserid(), pageNum, pageSize));
    }
 
    @GetMapping("/withdrawDetail")
    @ApiOperation(value = "提现详情", tags = {"用户端-个人中心-提现"})
    public R<WithdrawDetailVO> withdrawDetail(@RequestParam String orderId) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        return withdrawClient.withdrawDetailByUser(orderId);
    }
 
    @GetMapping("/confirmWithdraw")
    @ApiOperation(value = "确认提现", tags = {"用户端-个人中心-提现"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true)
    })
 
    public synchronized R<Boolean> confirmWithdraw(@RequestParam String orderId) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        if (redisService.hasKey(orderId)) {
            return R.fail("该笔订单已申请提现");
//            return R.repeatedSubmission("请勿重复提交!");
        }
        redisService.setCacheObject(orderId, "1", 10L, TimeUnit.SECONDS);
        Boolean b = withdrawService.confirmWithdraw(orderId, loginUser.getUserid());
 
        if (b){
            return R.ok();
        }else {
            return R.fail("该笔订单已申请提现");
        }
    }
 
    @GetMapping("/withdrawRecord")
    @ApiOperation(value = "提现记录", tags = {"用户端-个人中心-提现"})
    public R<Page<Withdraw>> withdrawRecord(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        Page<Withdraw> data = withdrawClient.withdrawRecordList(loginUser.getUserid(), pageNum, pageSize).getData();
        BigDecimal b = BigDecimal.ZERO;
        if (null != data) {
            for (Withdraw record : data.getRecords()) {
                b = b.add(record.getApplyForMoney());
            }
        }
        return R.ok(data);
    }
 
}