Pu Zhibing
3 天以前 e5bdd46a51ebfda768262ff51c17879241ea2b14
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
package com.supersavedriving.user.modular.api;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.heredata.hos.model.bucket.Bucket;
import com.sun.xml.internal.bind.v2.TODO;
import com.supersavedriving.user.core.common.annotion.ServiceLog;
import com.supersavedriving.user.core.util.ToolUtil;
import com.supersavedriving.user.modular.system.model.*;
import com.supersavedriving.user.modular.system.service.*;
import com.supersavedriving.user.modular.system.util.*;
import com.supersavedriving.user.modular.system.util.GaoDe.MapUtil;
import com.supersavedriving.user.modular.system.util.GaoDe.model.District;
import com.supersavedriving.user.modular.system.util.MallBook.model.InterfaceResponse;
import com.supersavedriving.user.modular.system.util.MallBook.util.RSASignature;
import com.supersavedriving.user.modular.system.util.huawei.OBSUtil;
import com.supersavedriving.user.modular.system.util.qianyuntong.NCOSSUtil;
import com.supersavedriving.user.modular.system.util.qianyuntong.QianYunTongConfig;
import com.supersavedriving.user.modular.system.util.qianyuntong.SMSUtil;
import com.supersavedriving.user.modular.system.util.qianyuntong.model.SendSmsRequest;
import com.supersavedriving.user.modular.system.util.weChat.WeChatUtil;
import com.supersavedriving.user.modular.system.warpper.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 用户控制器
 */
@RestController
@RequestMapping("")
public class AppUserController {
 
    @Autowired
    private IAppUserService appUserService;
 
    @Autowired
    private IDriverService driverService;
 
    @Autowired
    private ISystemConfigService systemConfigService;
 
 
    @Autowired
    private IUserToCouponService userToCouponService;
 
    @Autowired
    private IAccountChangeDetailService accountChangeDetailService;
 
    @Autowired
    private IComplaintService complaintService;
 
    @Autowired
    private RedisUtil redisUtil;
 
    @Autowired
    private WeChatUtil weChatUtil;
 
    @Autowired
    private TUserCouponService userCouponService;
 
    @Autowired
    private TCheckCarActivityService  checkCarActivityService;
    @Autowired
    private ITBranchOfficeAreaService branchOfficeAreaService;
    
    @Resource
    private QianYunTongConfig qianYunTongConfig;
 
 
 
 
 
    @ResponseBody
    @PostMapping("/base/appUser/getUrlLink")
    @ApiOperation(value = "获取跳转微信url_link", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "跳转小程序路径", name = "path", required = true, dataType = "string"),
            @ApiImplicitParam(value = "跳转的附带参数", name = "query", required = false, dataType = "string"),
    })
    public ResponseWarpper<String> getUrlLink(String path, String query){
        try {
            String urlLink = weChatUtil.getUrlLink(path, query, "trial");
            return ResponseWarpper.success(urlLink);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
 
    @ResponseBody
    @PostMapping("/base/appUser/appUserLogin")
    @ApiOperation(value = "微信登录", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "微信jscode", name = "jscode", required = true, dataType = "string"),
    })
    public ResponseWarpper appUserLogin(String jscode,Integer userId){
        if(ToolUtil.isEmpty(jscode)){
            return ResponseWarpper.success(ResultUtil.paranErr("jscode"));
        }
        try {
            ResultUtil resultUtil = appUserService.appUserLogin(jscode);
            return ResponseWarpper.success(resultUtil);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/base/appUser/signInToRegister")
    @ApiOperation(value = "微信手机授权登录", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
    })
    public ResponseWarpper<SignInToRegisterWarpper> signInToRegister(SignInToRegister signInToRegister){
        try {
            ResultUtil<SignInToRegisterWarpper> resultUtil = appUserService.signInToRegister(signInToRegister);
            return ResponseWarpper.success(resultUtil);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
    
    
    
    @ResponseBody
    @PostMapping("/base/appUser/queryCaptcha")
    @ApiOperation(value = "发送短信验证码", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
    })
    public ResponseWarpper queryCaptcha(String phone){
        try {
            AppUserUtil.queryCaptcha(phone);
            return ResponseWarpper.success();
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
    
    
    @ResponseBody
    @PostMapping("/base/appUser/verificationCodeLogin")
    @ApiOperation(value = "手机验证码登录", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
    })
    public ResponseWarpper<SignInToRegisterWarpper> verificationCodeLogin(VerificationCodeLogin verificationCodeLogin){
        try {
            ResultUtil<SignInToRegisterWarpper> resultUtil = appUserService.verificationCodeLogin(verificationCodeLogin);
            return ResponseWarpper.success(resultUtil);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
    
 
    @ResponseBody
    @PostMapping("/base/appUser/queryNearbyDrivers")
    @ApiOperation(value = "获取附近的司机", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "经度", name = "lon", required = true, dataType = "string"),
            @ApiImplicitParam(value = "纬度", name = "lat", required = true, dataType = "string"),
    })
    public ResponseWarpper<List<NearbyDriverWarpper>> queryNearbyDrivers(String lon, String lat){
        if(ToolUtil.isEmpty(lat)){
            return ResponseWarpper.success(ResultUtil.paranErr("lat"));
        }
        if(ToolUtil.isEmpty(lon)){
            return ResponseWarpper.success(ResultUtil.paranErr("lon"));
        }
        try {
            List<NearbyDriverWarpper> list = driverService.queryDriverPosition(lon, lat, 5D);
            return ResponseWarpper.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/appUser/setEmergencyContact")
    @ApiOperation(value = "设置紧急联系人", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "姓名", name = "name", required = true, dataType = "string"),
            @ApiImplicitParam(value = "电话", name = "phone", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper setEmergencyContact(String name, String phone){
        if(ToolUtil.isEmpty(name)){
            return ResponseWarpper.success(ResultUtil.paranErr("name"));
        }
        if(ToolUtil.isEmpty(phone)){
            return ResponseWarpper.success(ResultUtil.paranErr("phone"));
        }
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            AppUser appUser = appUserService.selectById(uid);
            appUser.setEmergencyContact(name);
            appUser.setEmergencyPhone(phone);
            appUserService.updateById(appUser);
            return ResponseWarpper.success();
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/appUser/queryUserInfo")
    @ApiOperation(value = "获取个人信息", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "经度", name = "lon", required = true, dataType = "string"),
            @ApiImplicitParam(value = "纬度", name = "lat", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<UserInfoWarpper> queryUserInfo(String lon, String lat){
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            AppUser appUser = appUserService.selectById(uid);
            UserInfoWarpper userInfoWarpper = new UserInfoWarpper();
            BeanUtils.copyProperties(appUser, userInfoWarpper);
 
            District geocode = MapUtil.geocode(lon, lat);
            TBranchOfficeArea branchOfficeArea = branchOfficeAreaService.selectOne(new EntityWrapper<TBranchOfficeArea>().eq("areaCode", geocode.getDistrictCode())
                    .last("LIMIT 1"));
            if(null == branchOfficeArea){
                SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 7));
                if(null != systemConfig){
                    JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
                    userInfoWarpper.setServiceCell(jsonObject.getString("num1"));
                }
            }else{
                SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 8).eq("companyId", branchOfficeArea.getBranchOfficeId()));
                if(null != systemConfig){
                    JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
                    userInfoWarpper.setServiceCell(jsonObject.getString("num2"));
                }
            }
            return ResponseWarpper.success(userInfoWarpper);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/appUser/uploadImg")
    @ApiOperation(value = "上传头像图片", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "图片文件", name = "file", required = true, dataType = "file"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<String> uploadImg(MultipartFile file){
        try {
            InputStream inputStream = file.getInputStream();
            String name = file.getOriginalFilename();
            name = UUIDUtil.getRandomCode() + name.substring(name.lastIndexOf("."));
//            String s = OBSUtil.putObjectToBucket(inputStream, name);
//            String s = OssUploadUtil.ossUpload(file);
            String bucketName = qianYunTongConfig.getBucketName();
            Bucket grjyTest = NCOSSUtil.getBucketInfo(bucketName);
            if (null == grjyTest) {
                //创建桶
                Boolean bucket = NCOSSUtil.createBucket(bucketName);
                if (!bucket) {
                    throw new RuntimeException("创建存储桶失败");
                }
                //设置桶策略
                String policyText = "{\"Version\":\"2025-06-23\",\"Statement\":[{\"Sid\":\"Stmt20250623\",\"Action\":[\"GetObject\"],\"Effect\":\"Allow\",\"Resource\":\"" + bucketName + "/*\",\"Principal\":\"*\"}]}";
                Boolean bucketPolicy = NCOSSUtil.setBucketPolicy(bucketName, policyText);
                if (!bucketPolicy) {
                    throw new RuntimeException("设置桶策略失败");
                }
            }
            //上传对象
            String key = "imgs/daijia/user/" + name;
            String object = NCOSSUtil.putObject(bucketName, key, inputStream);
            if (null == object) {
                throw new RuntimeException("上传图片失败");
            }
            return ResponseWarpper.success("https://traffic.qytzt.cn/v1/AUTH_" + qianYunTongConfig.getAccount() + "/" + bucketName + "/" + key);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/appUser/updateUserInfo")
    @ApiOperation(value = "修改个人信息", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper updateUserInfo(UserInfo userInfo){
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            ResultUtil resultUtil = appUserService.updateUserInfo(uid, userInfo);
            return ResponseWarpper.success(resultUtil);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
 
    @ResponseBody
    @PostMapping("/api/appUser/queryPriceRules")
    @ApiOperation(value = "获取价格表", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<PriceRulesWarpper> queryPriceRules(@RequestParam("cityCode") String cityCode){
        try {
            PriceRulesWarpper priceRulesWarpper = systemConfigService.queryPriceRules(cityCode);
            return ResponseWarpper.success(priceRulesWarpper);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/appUser/queryTopUpPrompt")
    @ApiOperation(value = "获取充值优惠提示", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<String> queryTopUpPrompt(){
        try {
            SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 6));
            if(null != systemConfig){
                JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
                return ResponseWarpper.success("充值满" + jsonObject.getDouble("num2") + "元,下单享9.5折优惠!");
            }
            return ResponseWarpper.success();
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/appUser/rechargeBalance")
    @ApiOperation(value = "充值操作", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "充值金额", name = "amount", required = true, dataType = "double"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper rechargeBalance(Double amount){
        if(null == amount){
            return ResponseWarpper.success(ResultUtil.paranErr("amount"));
        }
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            ResultUtil resultUtil = appUserService.rechargeBalance(uid, amount);
            return ResponseWarpper.success(resultUtil);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/base/appUser/rechargeBalanceCallback")
    public  String rechargeBalanceCallback(@RequestBody JSONObject req){
        try {
            System.err.println("充值回调"+req);
            // 验签
            Map<String, Object> params = req.toJavaObject(Map.class);
            //验证异步通知请求签名
            Boolean verify = StrUtil.verify(params, MiniAppPay.MD5_KEY);
            if (verify) {
 
                String code = (String) params.get("mchOrderNo");
                String state = (String) params.get("state");
 
                if (2 != Integer.parseInt(state)) {
                    return "false";
                }
                if (2 == Integer.parseInt(state)) {
                    appUserService.rechargeBalanceCallback(code);
                    return "success";
                }
//
//                JSONObject jsonObject = JSON.parseObject(interfaceResponse.getResult());
//                String merOrderId = jsonObject.getString("merOrderId");
//                String orderId = jsonObject.getString("parameter1");
//                appUserService.rechargeBalanceCallback(orderId, merOrderId);
//                response.setStatus(200);
//                PrintWriter out = response.getWriter();
//                out.print("OK");
//                out.flush();
//                out.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return "false";
    }
 
 
    @ResponseBody
    @PostMapping("/api/appUser/queryMyCouponsCheck")
    @ApiOperation(value = "获取车检优惠券列表", tags = {"用户端-个人中心(车检)"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "状态(1=未使用,2=已使用,3=已过期)", name = "state", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "pageSize", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<List<CheckCouponsWarpper>> queryMyCouponsCheck(Integer state, Integer pageNum, Integer pageSize){
        if(null == state){
            return ResponseWarpper.success(ResultUtil.paranErr("state"));
        }
        if(null == pageNum){
            return ResponseWarpper.success(ResultUtil.paranErr("pageNum"));
        }
        if(null == pageSize){
            return ResponseWarpper.success(ResultUtil.paranErr("pageSize"));
        }
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            List<CheckCouponsWarpper> couponsWarppers = userCouponService.queryMyCoupons(uid, state, pageNum, pageSize);
            return ResponseWarpper.success(couponsWarppers);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
    @ResponseBody
    @PostMapping("/api/appUser/queryCheckUsedCouponNum")
    @ApiOperation(value = "获取已使用车检优惠券数量", tags = {"用户端-个人中心(车检)"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<Integer> queryCheckUsedCouponNum(){
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            Integer integer = userCouponService.queryUsedCouponNum(uid);
            return ResponseWarpper.success(integer);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/appUser/queryMyCoupons")
    @ApiOperation(value = "获取优惠券列表", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "状态(1=未使用,2=已使用,3=已过期)", name = "state", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "pageSize", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<List<CouponsWarpper>> queryMyCoupons(Integer state, Integer pageNum, Integer pageSize){
        if(null == state){
            return ResponseWarpper.success(ResultUtil.paranErr("state"));
        }
        if(null == pageNum){
            return ResponseWarpper.success(ResultUtil.paranErr("pageNum"));
        }
        if(null == pageSize){
            return ResponseWarpper.success(ResultUtil.paranErr("pageSize"));
        }
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            List<CouponsWarpper> couponsWarppers = userToCouponService.queryMyCoupons(uid, state, pageNum, pageSize);
            return ResponseWarpper.success(couponsWarppers);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/appUser/queryUsedCouponNum")
    @ApiOperation(value = "获取已使用优惠券数量", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<Integer> queryUsedCouponNum(){
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            Integer integer = userToCouponService.queryUsedCouponNum(uid);
            return ResponseWarpper.success(integer);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/appUser/queryBalanceDetails")
    @ApiOperation(value = "获取余额明细", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "统计时间", name = "time", required = true, dataType = "string"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "pageSize", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper<List<BalanceDetailsWarpper>> queryBalanceDetails(String time, Integer pageNum, Integer pageSize){
        if(ToolUtil.isEmpty(time)){
            return ResponseWarpper.success(ResultUtil.paranErr("time"));
        }
        if(null == pageNum){
            return ResponseWarpper.success(ResultUtil.paranErr("pageNum"));
        }
        if(null == pageSize){
            return ResponseWarpper.success(ResultUtil.paranErr("pageSize"));
        }
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            List<BalanceDetailsWarpper> balanceDetailsWarppers = accountChangeDetailService.queryBalanceDetails(uid, time, pageNum, pageSize);
            return ResponseWarpper.success(balanceDetailsWarppers);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/appUser/cancelAccount")
    @ApiOperation(value = "注销账号", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper cancelAccount(){
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            AppUser appUser = appUserService.selectById(uid);
            appUser.setStatus(3);
            appUserService.updateById(appUser);
            return ResponseWarpper.success();
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/appUser/feedback")
    @ApiOperation(value = "投诉反馈", tags = {"用户端-首页", "用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", required = false, dataType = "int"),
            @ApiImplicitParam(value = "反馈内容", name = "content", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper feedback(Integer orderId, String content){
        if(null == content){
            return ResponseWarpper.success(ResultUtil.paranErr("content"));
        }
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            complaintService.feedback(uid, orderId, content);
            return ResponseWarpper.success();
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
    @Autowired
    private ALiSendSms aLiSendSms;
 
 
    @ResponseBody
    @PostMapping("/base/appUser/getVerificationCode")
    @ApiOperation(value = "获取短信验证码", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "国家代码+86", name = "receiver", required = true, dataType = "string"),
            @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "string"),
    })
    public ResponseWarpper getVerificationCode(String receiver, String phone){
        if(ToolUtil.isEmpty(receiver)){
            return ResponseWarpper.success(ResultUtil.paranErr("receiver"));
        }
        if(ToolUtil.isEmpty(phone)){
            return ResponseWarpper.success(ResultUtil.paranErr("phone"));
        }
        try {
            String numberRandom = UUIDUtil.getNumberRandom(4);
            SendSmsRequest request = new SendSmsRequest();
            request.setDestAddress(phone);
            request.setTemplateId("TPL202410290001");
            Map<String, String> templateParams = new HashMap<>();
            templateParams.put("code", numberRandom);
            request.setTemplateParams(templateParams);
            request.setCode("code");
            request.setSpId("T8d5hdfg");
            SMSUtil.sendSms(request);
            redisUtil.setStrValue(receiver + phone, numberRandom, 300);//5分钟有效期
            return ResponseWarpper.success(ResultUtil.success());
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/appUser/verifySMSCode")
    @ApiOperation(value = "验证短信验证码", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "String"),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper verifySMSCode(String phone, String code){
        if(ToolUtil.isEmpty(phone)){
            return ResponseWarpper.success(ResultUtil.paranErr("phone"));
        }
        if(ToolUtil.isEmpty(phone)){
            return ResponseWarpper.success(ResultUtil.paranErr("code"));
        }
        try {
            ResultUtil resultUtil = ResultUtil.success();
            phone = phone.indexOf("+86") < 0 ? "+86" + phone : phone;
            String value = redisUtil.getValue(phone);
            if(ToolUtil.isEmpty(value) || !value.equals(code)){
                return ResponseWarpper.success(ResultUtil.error("验证码无效"));
            }
            redisUtil.remove(phone);
            return ResponseWarpper.success(resultUtil);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/user/driverRegister")
    @ApiOperation(value = "注册司机", tags = {"用户端-登录注册"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResponseWarpper driverRegister(DriverRegisterWarpper driverRegisterWarpper){
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            ResultUtil resultUtil = driverService.driverRegister(uid, driverRegisterWarpper);
            return ResponseWarpper.success(resultUtil);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/user/getCheckCoupon")
    @ApiOperation(value = "用户获取车检优惠券", tags = {"用户端-首页(车检)"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "活动id", name = "activityId", required = true, dataType = "Integer"),
    })
    public ResponseWarpper<GetCheckCouponWarpper> getCheckCoupon(Integer activityId){
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            GetCheckCouponWarpper warpper = new GetCheckCouponWarpper();
 
            TCheckCarActivity tCheckCarActivity = checkCarActivityService.selectById(activityId);
            if(null == tCheckCarActivity){
                return ResponseWarpper.success(ResultUtil.error("活动不存在"));
            }
            warpper.setExplainContent(tCheckCarActivity.getExplainContent());
            int count = userCouponService.selectCount(new EntityWrapper<TUserCoupon>().eq("userId", uid).eq("activityId", activityId));
            if(count==0){
                // 未领取
                warpper.setState(0);
            }else {
                // 已领取
                warpper.setState(1);
            }
            if(tCheckCarActivity.getStartTime().getTime()>System.currentTimeMillis() && tCheckCarActivity.getEndTime().getTime()<System.currentTimeMillis() && tCheckCarActivity.getPauseFlag()==0 && tCheckCarActivity.getAuditStatus()==1 && tCheckCarActivity.getIsDelete()==0){
                warpper.setActivityState(1);
            }else if(tCheckCarActivity.getStartTime().getTime()>System.currentTimeMillis()){
                warpper.setActivityState(2);
            }else if(tCheckCarActivity.getEndTime().getTime()<System.currentTimeMillis()){
                warpper.setActivityState(3);
            }else if(tCheckCarActivity.getPauseFlag()==1){
                warpper.setActivityState(4);
            }
            return ResponseWarpper.success(warpper);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/user/sendCheckCoupon")
    @ApiOperation(value = "用户领取车检优惠券", tags = {"用户端-首页(车检)"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "活动id", name = "activityId", required = true, dataType = "Integer"),
    })
    public ResponseWarpper sendCheckCoupon(String lat,String lon,Integer activityId){
        try {
            Integer uid = appUserService.getUserByRequest();
            if(null == uid){
                return ResponseWarpper.success(ResultUtil.tokenErr());
            }
            TCheckCarActivity tCheckCarActivity = checkCarActivityService.selectById(activityId);
            if(null == tCheckCarActivity){
                return ResponseWarpper.success(ResultUtil.error("活动不存在"));
            }
            int count = userCouponService.selectCount(new EntityWrapper<TUserCoupon>().eq("userId", uid).eq("activityId", activityId));
            if(count>0){
                return ResponseWarpper.success(ResultUtil.error("你已领取该优惠券"));
            }
            if(tCheckCarActivity.getStartTime().getTime()>System.currentTimeMillis()){
                return ResponseWarpper.success(ResultUtil.error("活动未开始"));
            }
            if(tCheckCarActivity.getEndTime().getTime()<System.currentTimeMillis()){
                return ResponseWarpper.success(ResultUtil.error("活动已结束"));
            }
            if(tCheckCarActivity.getPauseFlag()==1){
                return ResponseWarpper.success(ResultUtil.error("活动已暂停"));
            }
            if(tCheckCarActivity.getStartTime().getTime()>System.currentTimeMillis() && tCheckCarActivity.getEndTime().getTime()<System.currentTimeMillis() && tCheckCarActivity.getPauseFlag()==0 && tCheckCarActivity.getAuditStatus()==1 && tCheckCarActivity.getIsDelete()==0){
                // 领取
                TUserCoupon tUserCoupon = new TUserCoupon();
                tUserCoupon.setUserId(uid);
                tUserCoupon.setActivityId(activityId);
                tUserCoupon.setProvinceCode(tCheckCarActivity.getProvinceCode());
                tUserCoupon.setCityCode(tCheckCarActivity.getCityCode());
                tUserCoupon.setAreaCode(tCheckCarActivity.getDistrictCode());
                tUserCoupon.setCouponName(tCheckCarActivity.getCouponName());
                tUserCoupon.setMoney(tCheckCarActivity.getCouponAmount());
                // 当前时间 +tCheckCarActivity.getDuration()天
                tUserCoupon.setExpireTime(new Date(System.currentTimeMillis()+tCheckCarActivity.getDuration()*24*60*60*1000));
                userCouponService.insert(tUserCoupon);
                tCheckCarActivity.setReceivedNum(tCheckCarActivity.getReceivedNum()+1);
                checkCarActivityService.updateById(tCheckCarActivity);
            }else {
                return ResponseWarpper.success(ResultUtil.error("活动已结束"));
            }
            return ResponseWarpper.success(ResultUtil.success());
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
}