无关风月
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
package com.ruoyi.order.controller;
 
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.order.entity.Order;
import com.ruoyi.order.entity.ServeRecord;
import com.ruoyi.order.entity.Withdraw;
import com.ruoyi.order.entity.WithdrawalSetting;
import com.ruoyi.order.request.WithdrawExportRequest;
import com.ruoyi.order.service.OrderService;
import com.ruoyi.order.service.ServeRecordService;
import com.ruoyi.order.service.WithdrawService;
import com.ruoyi.order.vo.MoneyQueryRequest;
import com.ruoyi.order.vo.UserWithdrawRecordVO;
import com.ruoyi.order.vo.WithdrawDetailVO;
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 java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 用户提现申请记录表 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-07-09
 */
@RestController
@RequestMapping("/withdraw")
public class WithdrawController {
 
    @Resource
    private WithdrawService withdrawService;
    @Resource
    private OrderService orderService;
    @Resource
    private ServeRecordService serveRecordService;
 
    /**
     * 用户所关联提现记录分页列表
     *
     * @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(@RequestParam(value = "nickname", required = false) String nickname,
                                                      @RequestParam(value = "userPhone", required = false) String userPhone,
                                                      @RequestParam(value = "applyForTime", required = false) String applyForTime,
                                                      @RequestParam(value = "state", required = false) Integer state,
                                                      @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                      @RequestParam(name = "userIds") List<Integer> userIds) {
        return R.ok(withdrawService.withdrawPage(userIds,nickname, userPhone, applyForTime, state, Page.of(pageNum, pageSize)));
    }
    @GetMapping(value = "/withdrawPage1")
    public R<Page<UserWithdrawRecordVO>> withdrawPage1(@RequestParam(value = "cityList", required = false)List<String> cityList,@RequestParam(value = "nickname", required = false) String nickname,
                                                      @RequestParam(value = "userPhone", required = false) String userPhone,
                                                      @RequestParam(value = "applyForTime", required = false) String applyForTime,
                                                      @RequestParam(value = "state", required = false) Integer state,
                                                      @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                      @RequestParam(name = "userIds") List<Integer> userIds,
                                                       @RequestParam("siteIds") List<String> siteIds) {
        return R.ok(withdrawService.withdrawPage1(cityList,userIds,nickname, userPhone, applyForTime, state, Page.of(pageNum, pageSize),siteIds));
    }
    /**
     * 查看提现记录详情
     *
     * @param id 提现记录id
     */
    @ApiOperation(value = "提现记录详情", tags = {"后台-用户管理-提现列表"})
    @GetMapping(value = "/withdrawRecordDetail")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "提现记录id", name = "id", dataType = "Integer", required = true)
    })
    public R<Withdraw> withdrawRecordDetail(@RequestParam("id") Long id) {
        Withdraw withdraw = withdrawService.lambdaQuery().eq(Withdraw::getId, id)
                .eq(Withdraw::getIsDelete, 0).one();
        return R.ok(withdraw);
    }
 
    /**
     * 提现管理-提现审批
     *
     * @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<Boolean> withdrawExamine(@RequestParam("id") Long id, @RequestParam("state") Integer state,
                                      @RequestParam(value = "opinion", required = false) String opinion,
                                      @RequestParam(value = "openId") String openId,
                                      @RequestParam(value = "userId") Integer userId) {
        Withdraw withdraw = withdrawService.lambdaQuery().eq(Withdraw::getId, id).eq(Withdraw::getIsDelete, 0)
                .eq(Withdraw::getState, 0).one();
        if (null == withdraw) {
            return R.fail(503, "当前提现记录审批状态异常!");
        }
        // 修改审批状态及审批意见
        withdraw.setState(state);
        withdraw.setOpinion(opinion);
        // 同意提现申请,更改订单提现状态
        boolean update = true;
        if (Constants.ONE.equals(state)) {
            update = orderService.lambdaUpdate()
                    .set(Order::getIsWithdrawal, Constants.ONE)
                    .eq(Order::getId, withdraw.getOrderId()).update();
            Order order = orderService.lambdaQuery()
                    .eq(Order::getId, withdraw.getOrderId())
                    .eq(Order::getIsDelete, 0).one();
            if (null == order) {
                throw new GlobalException("订单信息异常!");
            }
            Boolean b = withdrawService.confirmWithdraw(openId, userId, order);
//            if (!b) {
//                throw new GlobalException("提现失败!");
//            }
        }else {
            Order order = orderService.lambdaQuery()
                    .eq(Order::getId, withdraw.getOrderId())
                    .eq(Order::getIsDelete, 0).one();
            if (null == order) {
                throw new GlobalException("订单信息异常!");
            }
            order.setIsWithdrawal(0);
            orderService.updateById(order);
        }
        update = update && withdrawService.updateById(withdraw);
        return R.ok(update);
    }
 
    /**
     * 用户提现记录导出
     *
     * @param exportRequest 提现记录
     */
    @ApiOperation(value = "用户提现管理-excel导出用户提现记录", tags = {"后台-用户管理-提现列表"})
    @PostMapping(value = "/excelExport")
    public R<List<UserWithdrawRecordVO>> excelExport(@RequestBody WithdrawExportRequest exportRequest) {
        return R.ok(withdrawService.excelExport(exportRequest));
    }
 
    /**
     * 批量删除提现记录
     *
     * @param ids 轮播图多条id拼接
     * @return 封装分页数据
     */
    @ApiOperation(value = "批量删除提现记录", tags = {"后台-用户管理-提现列表"})
    @GetMapping(value = "/batchDelete")
    public R<String> batchDelete(@RequestParam("ids") String ids) {
        List<String> idList = Arrays.stream(ids.split(",")).collect(Collectors.toList());
        List<Withdraw> list = withdrawService.lambdaQuery().in(Withdraw::getId, idList).list();
        list.forEach(data -> data.setIsDelete(1));
        return withdrawService.updateBatchById(list) ? R.ok() : R.fail();
    }
 
    /**
     * 根据类型统计提现金额
     *
     * @param request 根据类型统计提现金额
     * @return 提现金额
     */
    @ApiOperation(value = "根据类型统计提现金额", tags = {"后台-用户管理-提现列表"})
    @PostMapping(value = "/withdrawalTotalMoney")
    public R<BigDecimal> withdrawalTotalMoney(@RequestBody MoneyQueryRequest request) {
        return R.ok(withdrawService.withdrawalTotalMoney(request));
    }
 
    /**
     * 修改系统设置-关闭/开启审核
     *
     * @return 操作结果
     */
    @ApiOperation(value = "关闭/开启审核", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/enableProcess")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "审核状态(0:未开启,1:已开启)", name = "enableProcess", dataType = "Integer", required = true)
    })
    public R<Boolean> enableProcess(@RequestParam("enableProcess") Integer enableProcess) {
        return R.ok(withdrawService.enableProcess(enableProcess));
    }
 
    /**
     * 获取系统设置-审核设置
     * --远程调用
     *
     * @return 操作结果
     */
    @GetMapping(value = "/withdrawProcess")
    public R<WithdrawalSetting> withdrawProcess() {
        return R.ok(withdrawService.withdrawProcess());
    }
 
    /**
     * 全局审核状态
     */
    @ApiOperation(value = "全局审核状态", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/withdrawState")
    public R<WithdrawalSetting> withdrawState() {
        return R.ok(withdrawService.withdrawProcess());
    }
 
    /**
     * 用户所关联提现记录分页列表
     *
     * @param userId   用户id
     * @param pageNum  页码
     * @param pageSize 每页显示条数
     * @return 分页列表
     */
    @ApiOperation(value = "用户详情-提现记录分页列表", tags = {"后台-用户管理-用户列表"})
    @GetMapping(value = "/withdrawList")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户id", name = "userId", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<Page<UserWithdrawRecordVO>> withdrawList(@RequestParam("userId") Integer userId,
                                                      @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return R.ok(withdrawService.withdrawList(userId, Page.of(pageNum, pageSize)));
    }
    @GetMapping(value = "/withdrawList1")
    public R<Page<UserWithdrawRecordVO>> withdrawList1(@RequestParam("cityList") List<String> cityList,@RequestParam("userId") Integer userId,
                                                      @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                       @RequestParam("siteIds") List<String> siteIds) {
        return R.ok(withdrawService.withdrawList1(cityList,userId, Page.of(pageNum, pageSize),siteIds));
    }
 
 
    /************************************* 用户端 **************************************************/
 
    /**
     * 根据订单获取用户提现申请记录
     */
    @ApiOperation(value = "根据订单获取用户提现申请记录", tags = {"用户端"})
    @GetMapping(value = "/withdrawRecordByUser")
    public R<List<Withdraw>> withdrawRecordByUser(@RequestParam("orderId") String orderId,
                                                  @RequestParam("userId") Integer userId) {
        return R.ok(withdrawService.lambdaQuery().eq(Withdraw::getUserId, userId)
                .eq(Withdraw::getOrderId, orderId).list());
    }
 
    /**
     * 用户提交提现申请
     */
    @ApiOperation(value = "用户提交提现申请", tags = {"用户端"})
    @GetMapping(value = "/confirmWithdrawByUser")
    public synchronized R<Boolean> confirmWithdrawByUser(@RequestParam("orderId") String orderId,
                                            @RequestParam("userId") Integer userId,
                                            @RequestParam("openId") String openId,
                                            @RequestParam("userPhone") String userPhone) {
        return R.ok(withdrawService.confirmWithdrawByUser(orderId, userId, openId, userPhone));
    }
 
    @GetMapping("/withdrawListByUser")
    @ApiOperation(value = "用户订单列表", tags = {"用户端"})
    public R<Page<Order>> withdrawListByUser(@RequestParam("userId") Integer userId,
                                             @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return R.ok(orderService.lambdaQuery().eq(Order::getUserId, userId)
                .eq(Order::getState, 3).page(Page.of(pageNum, pageSize)));
    }
 
    @GetMapping("/withdrawRecordList")
    @ApiOperation(value = "用户提现申请记录", tags = {"用户端"})
    public R<Page<Withdraw>> withdrawRecordList(@RequestParam("userId") Integer userId,
                                                @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return R.ok(withdrawService.lambdaQuery().eq(Withdraw::getUserId, userId)
                .eq(Withdraw::getIsDelete, 0).orderByDesc(Withdraw::getCreateTime)
                .page(Page.of(pageNum, pageSize)));
    }
 
    @GetMapping("/withdrawDetailByUser")
    @ApiOperation(value = "提现订单详情", tags = {"用户端"})
    public R<WithdrawDetailVO> withdrawDetailByUser(@RequestParam("orderId") String orderId) {
        Order order = orderService.lambdaQuery()
                .eq(Order::getId, orderId).eq(Order::getIsDelete, 0).one();
        if (null == order) {
            throw new GlobalException("订单不存在!");
        }
        ServeRecord serveRecord = serveRecordService.lambdaQuery()
                .eq(ServeRecord::getOrderId, orderId).eq(ServeRecord::getIsDelete, 0).one();
        Withdraw withdraw = withdrawService.lambdaQuery().eq(Withdraw::getOrderId, orderId)
                .eq(Withdraw::getIsDelete, 0)
                .orderByDesc(Withdraw::getCreateTime)
                .last("limit 1").one();
        WithdrawDetailVO withdrawDetailVO = new WithdrawDetailVO();
        withdrawDetailVO.setOrderId(order.getId());
        withdrawDetailVO.setOrderNumber(order.getOrderNumber());
        withdrawDetailVO.setUserId(order.getUserId());
        withdrawDetailVO.setServeId(order.getServeId());
        withdrawDetailVO.setServeName(order.getServeName());
        withdrawDetailVO.setServePrice(order.getServePrice());
        withdrawDetailVO.setOrderMoney(order.getOrderMoney());
        withdrawDetailVO.setReservationName(order.getReservationName());
        withdrawDetailVO.setReservationPhone(order.getReservationPhone());
        withdrawDetailVO.setReservationAddress(order.getReservationAddress());
        withdrawDetailVO.setTime(order.getTime());
        withdrawDetailVO.setAcceptTime(order.getAcceptTime());
        withdrawDetailVO.setServerId(order.getServerId());
        withdrawDetailVO.setServerName(order.getServerName());
        withdrawDetailVO.setServerPhone(order.getServerPhone());
        withdrawDetailVO.setReservationRemark(order.getReservationRemark());
        withdrawDetailVO.setState(order.getState());
        withdrawDetailVO.setArriveTime(order.getArriveTime());
        withdrawDetailVO.setCompleteTime(order.getCompleteTime());
        withdrawDetailVO.setSubsidy(order.getSubsidy());
        withdrawDetailVO.setIsWithdrawal(order.getIsWithdrawal());
        if (null != withdraw) {
            withdrawDetailVO.setWithdrawalState(withdraw.getState());
            withdrawDetailVO.setWithdrawalTime(withdraw.getCreateTime());
        }
        withdrawDetailVO.setPackageInfo(order.getPackageInfo());
        withdrawDetailVO.setAddress(order.getAddress());
        if (null != serveRecord) {
            withdrawDetailVO.setPhoto(serveRecord.getPhoto());
        }
        return R.ok(withdrawDetailVO);
    }
 
}