无关风月
21 小时以前 7cab5bda99ca42188bc15b2dae7d1fa4d1833fd9
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package com.ruoyi.admin.controller;
 
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.admin.entity.Franchisee;
import com.ruoyi.admin.entity.User;
import com.ruoyi.admin.service.FranchiseeService;
import com.ruoyi.admin.service.UserService;
import com.ruoyi.admin.service.WithdrawService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.api.entity.UserWithdrawRecordVO;
import com.ruoyi.order.api.entity.Withdraw;
import com.ruoyi.order.api.entity.WithdrawExportRequest;
import com.ruoyi.order.api.feignClient.WithdrawClient;
import com.ruoyi.system.api.model.LoginUser;
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.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 用户提现记录表 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-05-29
 */
@RestController
@RequestMapping("/withdraw")
@Api(tags = {"后台-用户管理-提现列表"})
public class WithdrawController {
 
    @Resource
    private WithdrawService withdrawService;
    @Resource
    private WithdrawClient withdrawClient;
    @Resource
    private UserService userService;
 
    @Resource
    private TokenService tokenService;
    @Resource
    private FranchiseeService franchiseeService;
    /**
     * 用户所关联提现记录分页列表
     *
     * @param pageNum  页码
     * @param pageSize 每页显示条数
     * @return 分页列表
     */
    @ApiOperation(value = "用户提现管理-提现记录分页列表", tags = {"后台-用户管理-提现列表"})
    @GetMapping(value = "/withdrawPage")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户昵称", name = "nickname", dataType = "String"),
            @ApiImplicitParam(value = "手机号", name = "userPhone", dataType = "String"),
            @ApiImplicitParam(value = "申请时间", name = "applyForTime", dataType = "String"),
            @ApiImplicitParam(value = "审核状态(0待审核;1已通过;2已驳回)", name = "state", dataType = "Integer"),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<Page<UserWithdrawRecordVO>> withdrawPage(String nickname, String userPhone,
                                                      String applyForTime, Integer state,
                                                      @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
 
            List<Integer> userIds = userService.lambdaQuery().like(User::getNickname, nickname).list().stream().map(User::getId).collect(Collectors.toList());
        if (nickname!=null&&nickname!="") {
            if (userIds.isEmpty()) {
                return R.ok(new Page<UserWithdrawRecordVO>());
            }
        }
        LoginUser loginUser = tokenService.getLoginUser();
        List<String> cityList = loginUser.getCityList();
 
 
        Integer franchiseeId = loginUser.getSysUser().getFranchiseeId();
        String[] siteIds = new String[0];
        if (franchiseeId!=null){
            Franchisee byId = franchiseeService.getById(franchiseeId);
            siteIds = byId.getSiteIds().split(",");
            if (loginUser.getIsFranchisee()&&siteIds.length==0){
                return R.ok();
            }
        }
 
 
        Page<UserWithdrawRecordVO> page = withdrawClient.withdrawPage1(cityList,nickname, userPhone, applyForTime,
                state, pageNum, pageSize,userIds, Arrays.asList(siteIds)).getData();
        if (null != page) {
            for (UserWithdrawRecordVO record : page.getRecords()) {
                Integer userId = record.getUserId();
                User user = userService.lambdaQuery()
                        .eq(User::getId, userId)
                        .eq(User::getIsDelete, 0).one();
                if (null != user) {
                    record.setUserNo(user.getUserNo());
                    record.setNickname(user.getNickname());
                    record.setProfilePicture(user.getProfilePicture());
                }
            }
        }
        return R.ok(page);
    }
 
    /**
     * 查看提现记录详情
     *
     * @param id 提现记录id
     */
    @ApiOperation(value = "提现记录详情", tags = {"后台-用户管理-提现列表"})
    @GetMapping(value = "/withdrawRecordDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "提现记录id", name = "id", dataType = "Integer", required = true)
    })
    public R<Withdraw> withdrawRecordDetail(@RequestParam Long id) {
        return withdrawClient.withdrawRecordDetail(id);
    }
 
    /**
     * 提现管理-提现审批
     *
     * @param id      提现记录id
     * @param state   审批结果
     * @param opinion 审批意见
     */
    @ApiOperation(value = "提现管理-提现审批", tags = {"后台-用户管理-提现列表"})
    @GetMapping(value = "/withdrawExamine")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "提现记录id", name = "id", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "审批意见", name = "opinion", dataType = "String"),
            @ApiImplicitParam(value = "审批同意/不同意(1同意;2驳回)", name = "state", dataType = "Integer", required = true)
    })
    public R<String> withdrawExamine(@RequestParam Long id, @RequestParam Integer state, String opinion) {
        Withdraw withdraw = withdrawClient.withdrawRecordDetail(id).getData();
        if (null == withdraw) {
            throw new GlobalException("提现记录不存在或已删除!");
        }
        User user = userService.lambdaQuery()
                .eq(User::getId, withdraw.getUserId())
                .eq(User::getIsDelete, 0).one();
        if (null == user) {
            throw new GlobalException("提交申请的用户信息不存在!");
        }
        Boolean data = withdrawClient.withdrawExamine(id, state, opinion, user.getOpenId(), user.getId()).getData();
        if (null != data) {
            return data ? R.ok(null, "审批成功!") : R.fail("审批失败!");
        } else {
            return R.fail("审批失败!");
        }
    }
 
    /**
     * 用户提现记录导出
     *
     * @param exportRequest 提现记录
     */
    @ApiOperation(value = "用户提现管理-excel导出用户提现记录", tags = {"后台-用户管理-提现列表"})
    @PostMapping(value = "/excelExport")
    public R<String> excelExport(@RequestBody WithdrawExportRequest exportRequest, HttpServletResponse response) {
        List<UserWithdrawRecordVO> data = withdrawClient.excelExport(exportRequest).getData();
        // 独立service
        return withdrawService.excelExport(data, response);
    }
 
    /**
     * 批量删除提现记录
     *
     * @param ids 轮播图多条id拼接
     * @return 封装分页数据
     */
    @ApiOperation(value = "批量删除提现记录", tags = {"后台-用户管理-提现列表"})
    @GetMapping(value = "/batchDelete")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "多个id ',' 拼接", name = "ids", dataType = "String", required = true)
    })
    public R<String> batchDelete(@RequestParam String ids) {
        return withdrawClient.batchDelete(ids);
    }
 
}