基于mall4j产品的二开项目后端
lee
2024-12-18 921461a3f906d74403aeb6a27051deb77eca10fc
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
package com.yami.shop.api.controller.cdn;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.yami.shop.bean.model.*;
import com.yami.shop.bean.param.*;
import com.yami.shop.common.bean.HuaWeiOss;
import com.yami.shop.common.config.Constant;
import com.yami.shop.common.enums.WalletEnum;
import com.yami.shop.common.i18n.I18nMessage;
import com.yami.shop.common.response.ResponseEnum;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.regex.Pattern;
 
@RestController
@RequestMapping("/cdn/myWallet")
@Tag(name = "钱包相关")
public class CdnMyWalletController {
    @Autowired
    private CdnUserWalletService cdnUserWalletService;
    @Autowired
    private CdnFlowService cdnFlowService;
    @Autowired
    private UserService userService;
    @Autowired
    private CdnUserRechargeService cdnUserRechargeService;
    @Autowired
    private CdnUserBankService cdnUserBankService;
    @Autowired
    private CdnConfigService cdnConfigService;
    @Autowired
    private SysConfigService sysConfigService;
    @Autowired
    private CdnWithdrawalService cdnWithdrawalService;
    @Autowired
    private CdnWalletService cdnWalletService;
    @Autowired
    private CdnFlownameService cdnFlownameService;
    @Autowired
    private CdnTeamRelationService cdnTeamRelationService;
 
 
    private static final Pattern NUMERIC_PATTERN = Pattern.compile("\\d+");
 
    @GetMapping("/getWalletDetail")
    @Operation(summary = "查看明细", description = "查看明细")
    @Parameters({
            @Parameter(name = "userId", description = "用户id"),
            @Parameter(name = "page", description = "当前页"),
            @Parameter(name = "pageSize", description = "每页条数"),
            @Parameter(name = "walletId", description = "币种id 8流量 9金牛豆 10 幸运池 11积分")
    })
    public ServerResponseEntity<CdnUserWalletParam> getWalletDetail(@RequestParam(name = "userId") String userId,
                                                                    @RequestParam(name = "page") Integer page,
                                                                    @RequestParam(name = "pageSize") Integer pageSize,
                                                                    @RequestParam(name = "walletId") Integer walletId) {
        CdnUserWallet cdnUserWallet = cdnUserWalletService.getOne(Wrappers.<CdnUserWallet>lambdaQuery()
                .eq(CdnUserWallet::getUserId, userId)
                .eq(CdnUserWallet::getWalletId, walletId));
        Page<CdnFlow> p = new Page<>(page, pageSize);
        IPage<CdnFlow> flows = cdnFlowService.page(p, Wrappers.lambdaQuery(CdnFlow.class)
                .eq(CdnFlow::getUserId, userId)
                .eq(CdnFlow::getWalletId, walletId)
                .eq(CdnFlow::getDelStatus, 0)
                .orderByDesc(CdnFlow::getCreateTime)
                .orderByAsc(CdnFlow::getId));
        if (!flows.getRecords().isEmpty()) {
            for (CdnFlow flow : flows.getRecords()) {
                CdnFlowname cdnFlowname = cdnFlownameService.getOne(Wrappers.<CdnFlowname>lambdaQuery().eq(CdnFlowname::getId, flow.getFlownameId()));
                flow.setFlowname(cdnFlowname != null ? cdnFlowname.getName() : "无");
            }
        }
        CdnUserWalletParam userWalletParam = new CdnUserWalletParam();
        userWalletParam.setBalance(cdnUserWallet.getMoney());
        userWalletParam.setFlows(flows);
        return ServerResponseEntity.success(userWalletParam);
    }
 
    @GetMapping("/isPayPassword")
    @Operation(summary = "查看是否设置支付密码", description = "查看是否设置支付密码")
    public ServerResponseEntity<Boolean> isPayPassword(@RequestParam(name = "userId") String userId) {
        User user = userService.getById(userId);
        if (user.getPayPassword() == null || user.getPayPassword().equals("")) {
            return ServerResponseEntity.success(false);
        }
        return ServerResponseEntity.success(true);
    }
 
    @PostMapping("/setPayPassword")
    @Operation(summary = "设置支付密码", description = "设置支付密码")
    public ServerResponseEntity setPayPassword(@RequestBody PayPasswordParam setPayPasswordParam) {
        if (setPayPasswordParam.getPayPassword().length() > 6) {
            return ServerResponseEntity.showFailMsg("密码格式错误");
        }
        User user = userService.getById(setPayPasswordParam.getUserId());
        if (user != null) {
            if (user.getPayPassword() == null) {
                String ppw = encryptWithMD5(setPayPasswordParam.getPayPassword());
                user.setPayPassword(ppw);
                userService.updateById(user);
                return ServerResponseEntity.success();
            }
            String ppw = encryptWithMD5(setPayPasswordParam.getPayPassword());
            if (user.getPayPassword().equals(ppw)) {
                return ServerResponseEntity.showFailMsg("不能与原密码一致");
            }
            user.setPayPassword(ppw);
            userService.updateById(user);
        } else {
            return ServerResponseEntity.showFailMsg("用户不存在");
        }
        return ServerResponseEntity.success();
    }
 
    @PostMapping("/modifyPayPassword")
    @Operation(summary = "修改支付密码", description = "修改支付密码")
    public ServerResponseEntity modifyPayPassword(@Valid @RequestBody SetPayPasswordParam payPasswordParam) {
        if (payPasswordParam.getOldPayPassword().length() > 6 || !isNumericPayPassword(payPasswordParam.getOldPayPassword())) {
            return ServerResponseEntity.showFailMsg("旧密码格式错误");
        }
        if (payPasswordParam.getNewPayPassword().length() > 6 || !isNumericPayPassword(payPasswordParam.getNewPayPassword())) {
            return ServerResponseEntity.showFailMsg("新密码格式错误");
        }
        if (!payPasswordParam.getConfirmPayPassword().equals(payPasswordParam.getNewPayPassword())) {
            return ServerResponseEntity.showFailMsg("密码和确认密码不一致");
        }
        if (payPasswordParam.getOldPayPassword().equals(payPasswordParam.getNewPayPassword())) {
            return ServerResponseEntity.showFailMsg("新密码不能与旧密码一致");
        }
        User user = userService.getById(payPasswordParam.getUserId());
        if (user != null) {
            if (user.getPayPassword() == null) {
                return ServerResponseEntity.showFailMsg("支付密码还未设置,不能修改");
            }
            String old = encryptWithMD5(payPasswordParam.getOldPayPassword());
            if (!old.equals(user.getPayPassword())) {
                return ServerResponseEntity.showFailMsg("旧密码输入错误");
            }
            String ppw = encryptWithMD5(payPasswordParam.getNewPayPassword());
            user.setPayPassword(ppw);
            userService.updateById(user);
        } else {
            return ServerResponseEntity.showFailMsg("用户不存在");
        }
        return ServerResponseEntity.success();
    }
    @PostMapping("/pay/vaildPwd")
    @Operation(summary = "校验支付密码", description = "校验支付密码")
    public ServerResponseEntity vaildPayPassword(@RequestBody PayPasswordParam setPayPasswordParam) {
        if (setPayPasswordParam.getPayPassword().length() > 6) {
            return ServerResponseEntity.showFailMsg("密码格式错误");
        }
        User user = userService.getById(setPayPasswordParam.getUserId());
        if (user != null) {
            if (user.getPayPassword() == null) {
                return ServerResponseEntity.showFailMsg("支付密码还未设置,请先设置支付密码");
            }
 
            String ppw = encryptWithMD5(setPayPasswordParam.getPayPassword());
            if (user.getPayPassword().equals(ppw)) {
                return ServerResponseEntity.success("密码验证成功");
            }
        } else {
            return ServerResponseEntity.showFailMsg("用户不存在");
        }
        return ServerResponseEntity.showFailMsg("支付密码错误");
    }
 
    @PostMapping("/transferAccounts")
    @Operation(summary = "转账", description = "转账")
    public ServerResponseEntity transferAccounts(@RequestBody CdnTransFerAccountParam cdnTransFerAccountParam) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
        List<CdnFlow> cdnFlow = cdnFlowService.list(
                Wrappers.<CdnFlow>lambdaQuery()
                        .eq(CdnFlow::getUserId, cdnTransFerAccountParam.getUserId())
                        .like(CdnFlow::getMemo, "转账")
                        .eq(CdnFlow::getDelStatus, 0)
                        .between(CdnFlow::getCreateTime, thirtyMinutesAgo, now));
        if (!cdnFlow.isEmpty()){
            return ServerResponseEntity.showFailMsg("1分钟内只能转账一次");
        }
        String wallet = cdnConfigService.selectValueByName("transferAccounts");
        Double transferService = Double.parseDouble(cdnConfigService.selectValueByName("transferAccounts_service"));
        if (wallet != null && !wallet.equals("")) {
            boolean found = false;
            String[] wallets = wallet.split(",");
            for (String s :wallets){
                if (s.equals(cdnTransFerAccountParam.getWalletId() + "")) {
                    found = true;
                    break;
                }
            }
            if (!found){
                return ServerResponseEntity.showFailMsg("该钱包不可转账!");
            }
        }
        User u = userService.getUserByUserId(cdnTransFerAccountParam.getUserId());
        if (u.getZhuanzhang() != 1) return ServerResponseEntity.showFailMsg("不可转账,请联系客服");
        String ppw = encryptWithMD5(cdnTransFerAccountParam.getPayPassword());
        User user = userService.getById(cdnTransFerAccountParam.getUserId());
        if (user.getPayPassword() == null) {
            return ServerResponseEntity.showFailMsg("请先设置支付密码");
        }
        if (!ppw.equals(user.getPayPassword())) {
            return ServerResponseEntity.showFailMsg("支付密码错误");
        }
        CdnUserWallet cdnUserWallet = cdnUserWalletService.getOne(Wrappers.<CdnUserWallet>lambdaQuery()
                .eq(CdnUserWallet::getUserId, cdnTransFerAccountParam.getUserId())
                .eq(CdnUserWallet::getWalletId, cdnTransFerAccountParam.getWalletId()));
        BigDecimal service = BigDecimal.valueOf(transferService);
        if (cdnUserWallet != null) {
            if (cdnUserWallet.getMoney().compareTo(cdnTransFerAccountParam.getAmount()) < 0) {
                return ServerResponseEntity.showFailMsg("余额不足");
            }
            User payeeUser = userService.getOne(Wrappers.<User>lambdaQuery().eq(User::getUserMobile, cdnTransFerAccountParam.getMobile()));
            if (payeeUser == null) {
                return ServerResponseEntity.showFailMsg("收款人不存在");
            }
            if (payeeUser.getUserId().equals(cdnTransFerAccountParam.getUserId())) {
                return ServerResponseEntity.showFailMsg("不能给自己转账");
            }
            //转账人
            CdnTeamRelation cdnTeamRelations = cdnTeamRelationService.geteamRelationByUserId(cdnTransFerAccountParam.getUserId());
            if(cdnTeamRelations != null){
                if(cdnTeamRelations.getPids() != null && cdnTeamRelations.getPids().indexOf(payeeUser.getUserId()) > -1){// 转账人的上级 包含 收款人的用户Id
                    // 执行转账逻辑
                    Boolean b = cdnFlowService.executeTransferAccounts(cdnTransFerAccountParam.getUserId(), cdnTransFerAccountParam.getWalletId(), cdnTransFerAccountParam.getAmount(), payeeUser.getUserId());
                    if (b) {
                        return ServerResponseEntity.success();
                    }
                }else{
                    //收款人
                    CdnTeamRelation CdnTeamRelation = cdnTeamRelationService.geteamRelationByUserId(payeeUser.getUserId());
                    if (CdnTeamRelation == null) {
                        return ServerResponseEntity.showFailMsg("转账失败");
                    }else {
                        if(CdnTeamRelation.getPids() != null && CdnTeamRelation.getPids().indexOf(cdnTransFerAccountParam.getUserId()) > -1){// 收款人的上级 包含 转账人的用户Id
                            // 执行转账逻辑
                            Boolean b = cdnFlowService.executeTransferAccounts(cdnTransFerAccountParam.getUserId(), cdnTransFerAccountParam.getWalletId(), cdnTransFerAccountParam.getAmount(), payeeUser.getUserId());
                            if (b) {
                                return ServerResponseEntity.success();
                            }
                        }else {
                            return ServerResponseEntity.showFailMsg("非上下级一条线的用户不能转账!");
                        }
                    }
                }
            }else{
                return ServerResponseEntity.showFailMsg("转账失败!");
            }
        }
        return ServerResponseEntity.showFailMsg("转账失败");
    }
 
    @PostMapping("/transfer")
    @Operation(summary = "划转", description = "划转")
    public ServerResponseEntity transfer(@RequestBody CdnTransFerParam cdnTransFerParam) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
        List<CdnFlow> cdnFlow = cdnFlowService.list(
                Wrappers.<CdnFlow>lambdaQuery()
                        .eq(CdnFlow::getUserId, cdnTransFerParam.getUserId())
                        .like(CdnFlow::getMemo, "划转")
                        .eq(CdnFlow::getDelStatus, 0)
                        .between(CdnFlow::getCreateTime, thirtyMinutesAgo, now));
        if (!cdnFlow.isEmpty()){
            return ServerResponseEntity.showFailMsg("1分钟内只能划转一次");
        }
        User u = userService.getUserByUserId(cdnTransFerParam.getUserId());
        if (u.getHuazhuan() != 1) return ServerResponseEntity.showFailMsg("不可划转,请联系客服");
        String ppw = encryptWithMD5(cdnTransFerParam.getPayPassword());
        User user = userService.getById(cdnTransFerParam.getUserId());
        if (user.getPayPassword() == null) {
            return ServerResponseEntity.showFailMsg("请先设置支付密码");
        }
        if (!ppw.equals(user.getPayPassword())) {
            return ServerResponseEntity.showFailMsg("支付密码错误");
        }
        CdnUserWallet cdnUserWallet = cdnUserWalletService.getOne(Wrappers.<CdnUserWallet>lambdaQuery()
                .eq(CdnUserWallet::getUserId, cdnTransFerParam.getUserId())
                .eq(CdnUserWallet::getWalletId, cdnTransFerParam.getWalletId()));
        if (cdnUserWallet != null) {
            if (cdnUserWallet.getMoney().compareTo(cdnTransFerParam.getAmount()) < 0) {
                return ServerResponseEntity.showFailMsg("余额不足");
            }
            // 执行划转逻辑
            Boolean b = cdnFlowService.executeTransfer(cdnTransFerParam.getUserId(), cdnTransFerParam.getWalletId(), cdnTransFerParam.getAmount(), cdnTransFerParam.getTransFerWalletId());
            if (b) {
                return ServerResponseEntity.success();
            }
        }
        return ServerResponseEntity.showFailMsg("划转失败");
    }
 
 
    @PostMapping("/cash")
    @Operation(summary = "兑现幸运池", description = "兑现幸运池")
    public ServerResponseEntity cash(@RequestBody CdnTransFerParam cdnTransFerParam) {
        if(StringUtils.isBlank(cdnTransFerParam.getUserId())){
            return ServerResponseEntity.showFailMsg("用户Id不能为空!");
        }
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
        List<CdnFlow> cdnFlow = cdnFlowService.list(
                Wrappers.<CdnFlow>lambdaQuery()
                        .eq(CdnFlow::getUserId, cdnTransFerParam.getUserId())
                        .like(CdnFlow::getMemo, "兑换")
                        .eq(CdnFlow::getDelStatus, 0)
                        .between(CdnFlow::getCreateTime, thirtyMinutesAgo, now));
        if (!cdnFlow.isEmpty()){
            return ServerResponseEntity.showFailMsg("1分钟内只能兑换一次");
        }
        User u = userService.getUserByUserId(cdnTransFerParam.getUserId());
        if (u.getHuazhuan() != 1) return ServerResponseEntity.showFailMsg("不可兑换,请联系客服");
        String ppw = encryptWithMD5(cdnTransFerParam.getPayPassword());
        User user = userService.getById(cdnTransFerParam.getUserId());
        if (user.getPayPassword() == null) {
            return ServerResponseEntity.showFailMsg("请先设置支付密码");
        }
        if (!ppw.equals(user.getPayPassword())) {
            return ServerResponseEntity.showFailMsg("支付密码错误");
        }
        CdnUserWallet cdnUserWallet = cdnUserWalletService.getOne(Wrappers.<CdnUserWallet>lambdaQuery()
                .eq(CdnUserWallet::getUserId, cdnTransFerParam.getUserId())
                .eq(CdnUserWallet::getWalletId, cdnTransFerParam.getWalletId()));
        if (cdnUserWallet != null) {
            if (cdnUserWallet.getMoney().compareTo(cdnTransFerParam.getAmount()) < 0) {
                return ServerResponseEntity.showFailMsg("金牛豆不足");
            }
            // 执行兑换逻辑
            cdnTransFerParam.setTransFerWalletId(WalletEnum.LUCKPOOL.value());
            String msg = cdnFlowService.cash(cdnTransFerParam.getUserId(), cdnTransFerParam.getWalletId(), cdnTransFerParam.getAmount(), cdnTransFerParam.getTransFerWalletId());
            if(ResponseEnum.OK.getMsg().equals(msg)){
                return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
            }else {
                return ServerResponseEntity.showFailMsg(msg);
            }
        }
        return ServerResponseEntity.showFailMsg("兑换失败");
    }
 
    @GetMapping("/getRechargeQrCode")
    @Operation(summary = "获取充值二维码", description = "获取充值二维码")
    public ServerResponseEntity<RechargeParam> getRechargeQrCode() {
        RechargeParam rechargeParam = new RechargeParam();
        Object rechargeimg = cdnConfigService.selectValueByName("rechargeimg");
        HuaWeiOss aliOss = sysConfigService.getSysConfigObject(Constant.HUAWEI_OBS_CONFIG, HuaWeiOss.class);
        if (aliOss != null) {
            String bucketName = aliOss.getBucketName();//shjw2024
            String endpoint = aliOss.getEndpoint(); //https://oss-cn-shanghai.aliyuncs.com
            String pre = endpoint.substring(0, 8);
            String fix = endpoint.substring(8);
            String path = pre + bucketName + "." + fix;
            String img = rechargeimg.toString();
            rechargeParam.setImg(path + "/" + img);
        }
        String moneyArr = cdnConfigService.selectValueByName("money_arr");
        Gson gson = new Gson();
        Type type = new TypeToken<Map<String, String>>(){}.getType();
 
        try {
            Map<String, String> map = gson.fromJson(moneyArr, type);
            List<String> moneyList = new ArrayList<>(map.values());
            rechargeParam.setMoneyArr(moneyList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String rechageHour = cdnConfigService.selectValueByName("rechage_hour");
        rechargeParam.setRechageHour(rechageHour);
        return ServerResponseEntity.success(rechargeParam);
    }
 
    @PostMapping("/recharge")
    @Operation(summary = "充值", description = "充值")
    public ServerResponseEntity recharge(@RequestBody CdnUserRecharge cdnUserRecharge) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
        CdnUserRecharge cdnUserRecharge1 = cdnUserRechargeService.getOne(
                Wrappers.<CdnUserRecharge>lambdaQuery()
                        .eq(CdnUserRecharge::getUserId, cdnUserRecharge.getUserId())
                        .eq(CdnUserRecharge::getStatus, 0)
                        .between(CdnUserRecharge::getCreateTime, thirtyMinutesAgo, now));
        if (cdnUserRecharge1 != null){
            return ServerResponseEntity.showFailMsg("1分钟内只能充值一次");
        }
        String rechageHour = cdnConfigService.selectValueByName("rechage_hour");
        // 获取今天的日期
        LocalDateTime today = LocalDateTime.now();
        Integer hour = today.getHour();
        String[] parts = rechageHour.split("-"); // 使用 - 分割字符串
        String startHour = parts[0]; // 截取起始小时
        String endHour = parts[1]; // 截取结束小时
        if (hour <= Integer.parseInt(startHour) || hour > Integer.parseInt(endHour)) {
            return ServerResponseEntity.showFailMsg("充值时间限制" + rechageHour);
        }
//        String moneyArr = cdnConfigService.selectValueByName("money_arr"); //{"0":"2000","1":"6000","2":"15000","3":"150000"}
//        Gson gson = new Gson();
//        Type type = new TypeToken<Map<String, String>>(){}.getType();
//        try {
//            Map<String, String> map = gson.fromJson(moneyArr, type);
//            List<String> moneyList = new ArrayList<>(map.values());
//            if (!moneyList.contains(cdnUserRecharge.getMoney().toString())) {
//                return ServerResponseEntity.showFailMsg("充值金额错误");
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
 
        cdnUserRecharge.setCreateTime(new Date());
        cdnUserRechargeService.save(cdnUserRecharge);
        return ServerResponseEntity.success();
    }
    @GetMapping("/getUserBank")
    @Operation(summary = "获取银行卡列表", description = "获取银行卡列表")
    public ServerResponseEntity<List<CdnUserBank>> getUserBank(@RequestParam("userId") String userId) {
        return ServerResponseEntity.success(cdnUserBankService.list(Wrappers.<CdnUserBank>lambdaQuery().eq(CdnUserBank::getUserId, userId)));
    }
 
    @PostMapping("/deleteUserBank")
    @Operation(summary = "删除用户银行卡信息", description = "删除用户银行卡信息")
    public ServerResponseEntity<String> deleteUserBank(@RequestBody CdnUserBank bank) {
        Integer num = cdnUserBankService.deleteUserBank(bank);
        if(num > 0){
            return ServerResponseEntity.success();
        }
        return ServerResponseEntity.showFailMsg(I18nMessage.getMessage("删除银行卡信息失败!"));
    }
 
    @PostMapping("/updateUserBank")
    @Operation(summary = "修改用户银行卡信息", description = "修改用户银行卡信息")
    public ServerResponseEntity<String> updateUserBank(@RequestBody CdnUserBank bank) {
        Boolean flag =  cdnUserBankService.updateById(bank);
        if(flag){
            return ServerResponseEntity.success();
        }
        return ServerResponseEntity.showFailMsg(I18nMessage.getMessage("修改银行卡信息失败!"));
    }
 
    @PostMapping("/withdrawal")
    @Operation(summary = "提现", description = "提现")
    @Transactional(rollbackFor = Exception.class)
    public ServerResponseEntity withdrawal(@RequestBody CdnWithdrawal cdnWithdrawal) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
        CdnWithdrawal cdnWithdrawal1 = cdnWithdrawalService.getOne(
                Wrappers.<CdnWithdrawal>lambdaQuery()
                        .eq(CdnWithdrawal::getUserId, cdnWithdrawal.getUserId())
                        .eq(CdnWithdrawal::getStatus, 0)
                        .between(CdnWithdrawal::getCreateTime, thirtyMinutesAgo, now));
        if (cdnWithdrawal1 != null){
            return ServerResponseEntity.showFailMsg("1分钟内只能提现一次");
        }
        return cdnWithdrawalService.executeWithdrawal(cdnWithdrawal);
    }
 
    @GetMapping("/getWithdrawal")
    @Operation(summary = "获取提现配置", description = "获取提现配置")
    public ServerResponseEntity<CdnWithdrawalConfigParam> getUserWithdrawal() {
        CdnWithdrawalConfigParam cdnWithdrawalConfigParam = new CdnWithdrawalConfigParam();
        cdnWithdrawalConfigParam.setWithdrawalService(cdnConfigService.selectValueByName("withdrawal_service"));
        cdnWithdrawalConfigParam.setWithdrawalThreshold(cdnConfigService.selectValueByName("withdrawal_threshold"));
        cdnWithdrawalConfigParam.setWithdrawalTitle(cdnConfigService.selectValueByName("withdrawal_title"));
        cdnWithdrawalConfigParam.setWithdrawDay(cdnConfigService.selectValueByName("withdraw_day"));
        // 获取今天的日期
        LocalDateTime today = LocalDateTime.now();
        // 获取今天是周几
        Integer dayOfWeek = today.getDayOfMonth();
        if (!dayOfWeek.equals(Integer.parseInt(cdnWithdrawalConfigParam.getWithdrawDay()))) {
            cdnWithdrawalConfigParam.setIsDraw(false);
        }else{
            cdnWithdrawalConfigParam.setIsDraw(true);
        }
        cdnWithdrawalConfigParam.setWithdrawalDay(cdnConfigService.selectValueByName("withdrawal_day"));
        cdnWithdrawalConfigParam.setWithdrawHour(cdnConfigService.selectValueByName("withdraw_hour"));
        cdnWithdrawalConfigParam.setWithdrawalBluePointPoundage(cdnConfigService.selectValueByName("withdrawal_bluePoint_poundage"));
        return ServerResponseEntity.success(cdnWithdrawalConfigParam);
    }
 
    @GetMapping("/getConvertConfig")
    @Operation(summary = "获取划转配置", description = "获取划转配置")
    public ServerResponseEntity<CdnConvertConfigParam> getConvertConfig() {
        CdnConvertConfigParam cdnConvertConfigParam = new CdnConvertConfigParam();
        String convert = cdnConfigService.selectValueByName("convert");
        if(!StringUtils.isEmpty(convert)){
            String[] converts = convert.split(",");
            Map<String,String> convertMap = new HashMap<>();
            for (String c : converts){
                CdnWallet cw = cdnWalletService.getOne(Wrappers.lambdaQuery(CdnWallet.class).eq(CdnWallet::getId, Integer.parseInt(c)));
                convertMap.put(c,cw.getName());
            }
            cdnConvertConfigParam.setConvert(convertMap);
        }
        String convertReceive = cdnConfigService.selectValueByName("convert_receive");
        String[] convertReceives = convertReceive.split(",");
        Map<String,String> convertReceiveMap = new HashMap<>();
        for (String c : convertReceives){
            CdnWallet cw = cdnWalletService.getOne(Wrappers.lambdaQuery(CdnWallet.class).eq(CdnWallet::getId, Integer.parseInt(c)));
            convertReceiveMap.put(c,cw.getName());
        }
        cdnConvertConfigParam.setConvertReceive(convertReceiveMap);
        String convertPoundage = cdnConfigService.selectValueByName("convert_poundage");
        cdnConvertConfigParam.setConvertPoundage(convertPoundage);
        String transferReceive = cdnConfigService.selectValueByName("transferAccounts");
        String[] transfer = transferReceive.split(",");
        Map<String,String> transferMap = new HashMap<>();
        for (String c : transfer){
            CdnWallet cw = cdnWalletService.getOne(Wrappers.lambdaQuery(CdnWallet.class).eq(CdnWallet::getId, Integer.parseInt(c)));
            transferMap.put(c,cw.getName());
        }
        cdnConvertConfigParam.setTransferList(transferMap);
 
        String transferService = cdnConfigService.selectValueByName("transferAccounts_service");
        cdnConvertConfigParam.setTransferPoundage(transferService);
        return ServerResponseEntity.success(cdnConvertConfigParam);
    }
 
 
    @GetMapping("/getWalletLog")
    @Operation(summary = "获取用户提现记录", description = "获取用户提现记录")
    public ServerResponseEntity<List<CdnWithdrawal>> getUserWalletLog(@RequestParam String userId) {
        List<CdnWithdrawal> cdnWithdrawalList = cdnWithdrawalService.list(Wrappers.lambdaQuery(CdnWithdrawal.class)
                .eq(CdnWithdrawal::getUserId, userId)
                .orderByDesc(CdnWithdrawal::getCreateTime));
        return ServerResponseEntity.success(cdnWithdrawalList);
    }
 
    @GetMapping("/getWalletLogPage")
    @Operation(summary = "分页获取用户提现记录", description = "获取用户提现记录")
    public ServerResponseEntity<IPage<CdnWithdrawal>> getUserWalletLog(@RequestParam Integer page,@RequestParam Integer pageSize,@RequestParam String userId) {
        PageParam<CdnWithdrawal> param = new PageParam<>();
        param.setCurrent(page);
        param.setSize(pageSize);
        LambdaQueryWrapper<CdnWithdrawal> wrapper = new LambdaQueryWrapper<>(CdnWithdrawal.class);
        wrapper.orderByDesc(CdnWithdrawal::getCreateTime);
        wrapper.eq(CdnWithdrawal::getUserId, userId);
        PageParam<CdnWithdrawal> page1 = cdnWithdrawalService.page(param, wrapper);
        if (!page1.getRecords().isEmpty()) {
            for (CdnWithdrawal cdnWithdrawal1 : page1.getRecords()) {
                CdnUserWallet info = userService.getInfo(cdnWithdrawal1.getUserId(), cdnWithdrawal1.getWalletId());
                if (info != null) {
                    cdnWithdrawal1.setNickName(info.getNickName());
                    cdnWithdrawal1.setMobile(info.getMobile());
                    cdnWithdrawal1.setWalletName(info.getWalletName());
                }
                CdnUserBank cdnUserBank = cdnUserBankService.getById(cdnWithdrawal1.getUserBankId());
                if (cdnUserBank != null) {
                    cdnWithdrawal1.setBankCode(cdnUserBank.getBankcode());
                    cdnWithdrawal1.setBank(cdnUserBank.getBank());
                    cdnWithdrawal1.setType(cdnUserBank.getType());
                    cdnWithdrawal1.setRealName(cdnUserBank.getName());
                }
            }
        }
        return ServerResponseEntity.success(page1);
    }
 
    @GetMapping("/getUserStatus")
    @Operation(summary = "获取用户 提现/划转/转账 状态", description = "获取用户 提现/划转/转账 状态")
    public ServerResponseEntity<User> getUserStatus(@RequestParam String userId) {
        return ServerResponseEntity.success(userService.getById(userId));
    }
 
    @GetMapping("/getBankConfig")
    @Operation(summary = "获取银行卡配置", description = "获取银行卡配置")
    public ServerResponseEntity<CdnBankConfigParam> getUserConfigBank() {
        String bankName = cdnConfigService.selectValueByName("bank_name");
        String bankCode = cdnConfigService.selectValueByName("bank_code");
        String companyName = cdnConfigService.selectValueByName("company_name");
        CdnBankConfigParam cdnBankConfigParam = new CdnBankConfigParam(bankName, bankCode, companyName);
        return ServerResponseEntity.success(cdnBankConfigParam);
    }
 
    @GetMapping("/getRechargeLog")
    @Operation(summary = "获取用户充值记录", description = "获取用户充值记录")
    public ServerResponseEntity<List<CdnUserRecharge>> getUserRechargeLog(@RequestParam String userId) {
        List<CdnUserRecharge> cdnUserRechargeList = cdnUserRechargeService.list(Wrappers.lambdaQuery(CdnUserRecharge.class)
                .eq(CdnUserRecharge::getUserId, userId).orderByDesc(CdnUserRecharge::getCreateTime));
        return ServerResponseEntity.success(cdnUserRechargeList);
    }
 
    /**
     * 验证支付密码是否为纯数字。
     *
     * @param payPassword 待验证的支付密码字符串
     * @return 如果支付密码为纯数字则返回true,否则返回false
     */
    public static boolean isNumericPayPassword(String payPassword) {
        return NUMERIC_PATTERN.matcher(payPassword).matches();
    }
 
    // 支付密码加密
    public static String encryptWithMD5(String password) {
        try {
            // 创建一个MD5的消息摘要对象
            MessageDigest md = MessageDigest.getInstance("MD5");
 
            // 将密码转换为字节数组并进行MD5摘要
            byte[] messageDigest = md.digest(password.getBytes());
 
            // 将摘要转换为16进制字符串
            BigInteger no = new BigInteger(1, messageDigest);
            String hashtext = no.toString(16);
 
            // 补齐长度到32位
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
 
            return hashtext;
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("MD5 hashing algorithm not found", e);
        }
    }
}