nickchange
2023-11-21 41b60f3df5f3054aad44307c13a26b14f3b32ac0
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
package com.dsh.account.controller;
 
import com.alibaba.nacos.common.utils.Md5Utils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dsh.account.dto.BindDto;
import com.dsh.account.dto.IntroduceUserQuery;
import com.dsh.account.dto.SelectDto;
import com.dsh.account.dto.UpdateInfoDto;
import com.dsh.account.entity.*;
import com.dsh.account.model.*;
import com.dsh.account.model.query.appUserQuery.QueryAppUser;
import com.dsh.account.model.vo.QueryAppUserVO;
import com.dsh.account.service.*;
import com.dsh.account.util.PayMoneyUtil;
import com.dsh.account.util.ResultUtil;
import com.dsh.account.util.TokenUtil;
import com.dsh.account.util.ToolUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @author zhibing.pu
 * @date 2023/6/14 15:30
 */
@RestController
@RequestMapping("")
public class AppUserController {
 
    @Autowired
    private TAppUserService appUserService;
 
    @Autowired
    private PayMoneyUtil payMoneyUtil;
 
    @Autowired
    private IVipPaymentService vipPaymentService;
 
    @Autowired
    private TokenUtil tokenUtil;
 
    @Autowired
    private TCourseInfoRecordService courseInfoRecordService;
 
    @Autowired
    private TAppGiftService appGiftService;
    /**
     * 根据介绍有礼id查询当前活动参与次数
     */
    @ResponseBody
    @PostMapping("/base/appUser/getActivityPeoples")
    public Integer getActivityPeoples(@RequestBody Integer activityId){
        int activityId1 = appGiftService.list(new QueryWrapper<TAppGift>().eq("activityId", activityId))
                .size();
        return activityId1;
    }
    /**
     * 介绍有礼 -- 参与用户列表
     */
    @ResponseBody
    @PostMapping("/base/appUser/queryIntroduceAll")
    public List<IntroduceUser> queryIntroduceAll(@RequestBody IntroduceUserQuery query){
        return appGiftService.queryIntroduceAll(query);
    }
    /**
     * 获取所有用户
     */
    @ResponseBody
    @PostMapping("/base/appUser/queryAppUserList")
    public List<TAppUser> queryAppUserList(@RequestBody AppUserByNameAndPhoneDTO dto){
        return appUserService.queryAPPUserByNameAndPhone(dto);
    }
 
    /**
     * 根据用户姓名和电话模糊查询
     */
    @ResponseBody
    @PostMapping("/base/appUser/queryAPPUserByNameAndPhone")
    public List<TAppUser> queryAPPUserByNameAndPhone(@RequestBody AppUserByNameAndPhoneDTO dto){
        return appUserService.queryAPPUserByNameAndPhone(dto);
    }
    /**
     * 根据用户id获取用户信息
     * @param appUserId
     * @return
     */
    @ResponseBody
    @PostMapping("/base/appUser/queryAppUser1")
    public TAppUser queryAppUser1(@RequestBody Integer appUserId){
         TAppUser appUser = appUserService.getById(appUserId);
         return appUser;
    }
    /**
     * 冻结/解冻 1=解冻 2=冻结
     */
    @RequestMapping("/base/appUser/changeState")
    public Object changeState(@RequestBody AdvertisementChangeStateDTO dto){
        return appUserService.changeState(dto);
    }
    /**
     *  后台添加
     */
    @RequestMapping("/base/appUser/addAppUser1")
    public Object addAppUser1(@RequestBody TAppUser query){
        // 修改
        if (query.getId()!=null){
            TAppUser phone = appUserService.getOne(new QueryWrapper<TAppUser>().eq("phone", query.getPhone()).ne("id",query.getId()));
            if (null != phone){
                return 5001;
            }
        }else {
            TAppUser phone = appUserService.getOne(new QueryWrapper<TAppUser>().eq("phone", query.getPhone()));
            if (null != phone){
                return 5001;
            }
        }
        query.setIsVip(0);
        query.setInsertTime(new Date());
        return appUserService.saveOrUpdate(query);
    }
 
    /**
     * 获取用户信息列表数据
     */
    @ResponseBody
    @RequestMapping("/base/appUser/listAll")
    public List<QueryAppUserVO> listAll(@RequestBody QueryAppUser query){
        List<QueryAppUserVO> queryAppUserVOS = appUserService.listAll(query);
        ArrayList<QueryAppUserVO> res = new ArrayList<>();
 
        if (query.getUserIds()!=null && query.getUserIds().size()!=0){
            List<QueryAppUserVO> queryAppUserVOS1 = appUserService.listAll1(query);
            queryAppUserVOS.addAll(queryAppUserVOS1);
        }
        List<QueryAppUserVO> collect = queryAppUserVOS.stream().distinct().collect(Collectors.toList());
        for (QueryAppUserVO vo : collect) {
            // 会员到期时间小于当前时间或者会员到期时间为null 则会员过期
            if (vo.getVipEndTime()!=null && vo.getVipEndTime().after(new Date())){
                vo.setIsVip(1);
            }else{
                vo.setIsVip(0);
            }
            if (query.getIsVip() != null && (!query.getIsVip().equals("")) ){
                if (vo.getIsVip() == query.getIsVip()){
                    res.add(vo);
                }
            }else{
                res.add(vo);
            }
        }
        return res;
    }
 
    /**
     * 根据用户手机号获取用户id
     */
    @ResponseBody
    @GetMapping("/base/appUser/getAppUserByPhone/{phone}")
    public TAppUser getAppUserByPhone(@PathVariable("phone") String phone){
        TAppUser appUser = appUserService.getOne(new QueryWrapper<TAppUser>().eq("phone", phone));
        return appUser;
    }
 
    @ResponseBody
    @PostMapping("/base/appUser/getSMSCode")
    @ApiOperation(value = "获取短信验证码", tags = {"APP-登录注册"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "类型(1:登录,2:注册,3:修改密码,4:忘记密码)", name = "type", dataType = "int", required = true),
            @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true)
    })
    public ResultUtil getSMSCode(Integer type, String phone){
        if(ToolUtil.isEmpty(phone)){
            return ResultUtil.paranErr("phone");
        }
        if(ToolUtil.isEmpty(type)){
            return ResultUtil.paranErr("type");
        }
        try {
            ResultUtil smsCode = appUserService.getSMSCode(type, phone);
            return smsCode;
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @Autowired
    private TStudentService studentService;
    @ResponseBody
    @PostMapping("/base/appUser/logOff")
    @ApiOperation(value = "注销", tags = {"注销"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "账号id", name = "appId", dataType = "int", required = true)
    })
    public ResultUtil<String> logOff(Integer appId){
        try {
 
            appUserService.removeById(appId);
            studentService.remove(new QueryWrapper<TStudent>().eq("appUserId",appId));
 
            return ResultUtil.success("注销成功");
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/appUser/addAppUser")
    @ApiOperation(value = "注册用户", tags = {"APP-登录注册"})
    @ApiImplicitParams({
    })
    public ResultUtil addAppUser(AddAppUserVo addAppUserVo){
        try {
            return appUserService.addAppUser(addAppUserVo);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/appUser/loginPassword")
    @ApiOperation(value = "账号密码登录", tags = {"APP-登录注册"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true),
            @ApiImplicitParam(value = "登录密码", name = "password", dataType = "string", required = true)
    })
    public ResultUtil<String> loginPassword(String phone, String password){
        if(ToolUtil.isEmpty(phone)){
            return ResultUtil.paranErr("phone");
        }
        if(ToolUtil.isEmpty(password)){
            return ResultUtil.paranErr("password");
        }
        try {
            return appUserService.loginPassword(phone, password);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/base/appUser/loginSMSCode")
    @ApiOperation(value = "短信验证码登录", tags = {"APP-登录注册"})
    @ApiImplicitParams({
    })
    public ResultUtil<String> loginSMSCode(LoginSMSCodeVo loginSMSCodeVo){
        try {
            return appUserService.loginSMSCode(loginSMSCodeVo);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
    @ResponseBody
    @PostMapping("/base/appUser/bind")
    @ApiOperation(value = "微信登录绑定手机号", tags = {"APP-登录注册"})
    @ApiImplicitParams({
    })
    public ResultUtil bind(BindDto dto){
        try {
            return appUserService.bind(dto);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/appUser/loginWeChat")
    @ApiOperation(value = "微信登录", tags = {"APP-登录注册"})
    @ApiImplicitParams({
    })
    public ResultUtil<String> loginWeChat(LoginWeChatVo loginWeChatVo){
        try {
            return appUserService.loginWechat(loginWeChatVo);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/appUser/updateInfo")
    @ApiOperation(value = "修改个人信息", tags = {"APP-登录注册"})
    @ApiImplicitParams({
    })
    public ResultUtil<String> updateInfo(UpdateInfoDto dto){
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return appUserService.updateInfo(dto,uid);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
 
 
    @ResponseBody
    @PostMapping("/base/appUser/updatePassword")
    @ApiOperation(value = "修改密码", tags = {"APP-登录注册"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true),
            @ApiImplicitParam(value = "短信验证码", name = "code", dataType = "string", required = true),
            @ApiImplicitParam(value = "新密码", name = "password", dataType = "string", required = true)
    })
    public ResultUtil updatePassword(String phone, String code, String password){
        if(ToolUtil.isEmpty(phone)){
            return ResultUtil.paranErr("phone");
        }
        if(ToolUtil.isEmpty(code)){
            return ResultUtil.paranErr("code");
        }
        if(ToolUtil.isEmpty(password)){
            return ResultUtil.paranErr("password");
        }
        try {
            return appUserService.updatePassword(phone, code, password);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/appUser/forgetPassword")
    @ApiOperation(value = "忘记密码", tags = {"APP-登录注册"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true),
            @ApiImplicitParam(value = "短信验证码", name = "code", dataType = "string", required = true),
            @ApiImplicitParam(value = "新密码", name = "password", dataType = "string", required = true)
    })
    public ResultUtil forgetPassword(String phone, String code, String password){
        if(ToolUtil.isEmpty(phone)){
            return ResultUtil.paranErr("phone");
        }
        if(ToolUtil.isEmpty(code)){
            return ResultUtil.paranErr("code");
        }
        if(ToolUtil.isEmpty(password)){
            return ResultUtil.paranErr("password");
        }
        try {
            return appUserService.updatePassword(phone, code, password);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/appUser/queryJoinPlayPai")
    @ApiOperation(value = "获取加入玩湃首页数据", tags = {"APP-加入玩湃"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "经度", name = "lon", dataType = "string", required = false),
            @ApiImplicitParam(value = "纬度", name = "lat", dataType = "string", required = false),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<JoinPlayPaiVo> queryJoinPlayPai(String lon, String lat){
        
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            JoinPlayPaiVo joinPlayPaiVo = appUserService.queryJoinPlayPai(uid, lon, lat);
            return ResultUtil.success(joinPlayPaiVo);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
 
    @ResponseBody
    @PostMapping("/api/appUser/addVipPayment")
    @ApiOperation(value = "购买年度会员", tags = {"APP-成为会员"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "支付方式(1=微信,2=支付宝)", name = "payType", dataType = "int", required = true),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil addVipPayment(Integer payType){
        if(ToolUtil.isEmpty(payType)){
            return ResultUtil.paranErr("payType");
        }
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return vipPaymentService.addVipPayment(uid, payType);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
 
 
    /**
     * 购买年度会员支付微信回调
     * @param request
     * @param response
     */
    @ResponseBody
    @PostMapping("/base/appUser/addVipPaymentWeChatCallback")
    public void addVipPaymentWeChatCallback(HttpServletRequest request, HttpServletResponse response){
        try {
            Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
            if(null != map){
                String out_trade_no = map.get("out_trade_no");
                String transaction_id = map.get("transaction_id");
                String result = map.get("result");
                ResultUtil resultUtil = vipPaymentService.addVipPaymentCallback(out_trade_no, transaction_id);
                if(resultUtil.getCode() == 200){
                    PrintWriter out = response.getWriter();
                    out.write(result);
                    out.flush();
                    out.close();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
 
    /**
     * 购买年度会员支付支付宝回调
     * @param request
     * @param response
     */
    @ResponseBody
    @PostMapping("/base/appUser/addVipPaymentAliCallback")
    public void addVipPaymentAliCallback(HttpServletRequest request, HttpServletResponse response){
        try {
            System.err.println("==============购买优惠卷回调=========");
            Map<String, String> map = payMoneyUtil.alipayCallback(request);
            if(null != map){
                String out_trade_no = map.get("out_trade_no");
                String trade_no = map.get("trade_no");
                ResultUtil resultUtil = vipPaymentService.addVipPaymentCallback(out_trade_no, trade_no);
                if(resultUtil.getCode() == 200){
                    PrintWriter out = response.getWriter();
                    out.write("success");
                    out.flush();
                    out.close();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
 
    /**
     * 根据用户id获取用户信息
     * @param appUserId
     * @return
     */
    @ResponseBody
    @PostMapping("/base/appUser/queryAppUser")
    public TAppUser queryAppUser(@RequestBody Integer appUserId){
        try {
            TAppUser appUser = appUserService.getById(appUserId);
            return appUser;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
 
 
    @Autowired
    private UserIntegralChangesService userIntegralChangesService;
    /**
     * 修改用户信息
     * @param appUser
     */
    @ResponseBody
    @PostMapping("/base/appUser/updateAppUser")
    public void updateAppUser(@RequestBody TAppUser appUser){
        try {
            appUserService.updateById(appUser);
            UserIntegralChanges userIntegralChanges = new UserIntegralChanges();
            userIntegralChanges.setAppUserId(appUser.getId());
            userIntegralChanges.setOldIntegral(appUser.getIntegral()+appUser.getPoints());
            userIntegralChanges.setType(5);
            userIntegralChanges.setNewIntegral(appUser.getIntegral());
            userIntegralChanges.setInsertTime(new Date());
            userIntegralChanges.setCategory(2);
            userIntegralChangesService.save(userIntegralChanges);
 
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
 
    @PostMapping("/base/appUser/getAllUser")
    @ResponseBody
    public List<TAppUser> getAllUser(){
        try {
            return appUserService.list();
        }catch (Exception e){
            e.printStackTrace();
            return new ArrayList<>();
        }
    }
 
    @PostMapping("/base/appUser/queryByNamePhone")
    public List<TAppUser> queryByNamePhone(@RequestBody QueryByNamePhone queryByNamePhone){
        try {
            LambdaQueryWrapper<TAppUser> tAppUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
            if(ToolUtil.isNotEmpty(queryByNamePhone.getName())){
                tAppUserLambdaQueryWrapper.like(TAppUser::getName,queryByNamePhone.getName());
            }
            if(ToolUtil.isNotEmpty(queryByNamePhone.getPhone())){
                tAppUserLambdaQueryWrapper.like(TAppUser::getPhone,queryByNamePhone.getPhone());
            }
            List<TAppUser> list = appUserService.list(tAppUserLambdaQueryWrapper);
            return list;
        }catch (Exception e){
            e.printStackTrace();
            return new ArrayList<>();
        }
    }
 
    @PostMapping("/base/appUser/queryById")
    public TAppUser queryById(@RequestBody Integer appUserId){
        try {
            return appUserService.getById(appUserId);
        }catch (Exception e){
            e.printStackTrace();
            return new TAppUser();
        }
    }
 
 
    /**
     * 根据名称模糊搜索用户
     * @param name
     * @return
     */
    @ResponseBody
    @PostMapping("/appUser/queryAppUserListByName")
    public List<TAppUser> queryAppUserListByName(@RequestBody String name){
        return appUserService.list(new QueryWrapper<TAppUser>().eq("state", 1).like("name", name));
    }
 
 
 
    @PostMapping("/appUser/addCourseInfoRecord")
    public Boolean addCourseInfoRecord(@RequestBody TCourseInfoRecord tCourseInfoRecord){
        boolean save = courseInfoRecordService.save(tCourseInfoRecord);
        return save;
    }
 
    @PostMapping("/appUser/getSelects")
    public List<SelectDto> getSelects(@RequestBody List<Integer> studentIds){
        List<SelectDto> selectDtos =    appUserService.getSelects(studentIds);
        System.out.println("=======selectDtos======>"+selectDtos);
        return selectDtos;
    }
}