nickchange
2023-10-31 986989a2b7a49353598fda317e3bdaed59f09abc
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
package com.dsh.account.controller;
 
 
import com.dsh.account.entity.TAppUser;
import com.dsh.account.feignclient.other.SysLogClient;
import com.dsh.account.model.vo.userBenefitDetail.*;
import com.dsh.account.service.RechargeRecordsService;
import com.dsh.account.service.TAppUserService;
import com.dsh.account.service.UserIntegralChangesService;
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 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 java.text.SimpleDateFormat;
import java.util.List;
 
/**
 * 使用福利 控制器
 */
 
@RestController
@RequestMapping("")
public class UseBenefitsController {
 
 
    @Autowired
    private TAppUserService tauService;
 
    @Autowired
    private TokenUtil tokenUtil;
 
    @Resource
    private SysLogClient slClient;
 
    @Autowired
    private RechargeRecordsService rechargeRService;
 
    @Autowired
    private UserIntegralChangesService uicService;
 
    private final SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/indexOfAppUser")
    @ApiOperation(value = "福利主页", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<IndexOfUserBenefirVo> queryAppUserUser(){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(tauService.queryBenefitDetails(appUserId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/userDetails")
    @ApiOperation(value = "用户个人信息", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<AppUserDetailsVo> queryAppUserDetails(){
        try {
            AppUserDetailsVo detailsVo = new AppUserDetailsVo();
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            TAppUser tAppUser = tauService.getBaseMapper().selectById(appUserId);
            if (null != tAppUser){
                detailsVo.setUserId(appUserId);
                detailsVo.setUserImage(tAppUser.getHeadImg());
                detailsVo.setUserName(tAppUser.getName());
                detailsVo.setUserPhone(tAppUser.getPhone());
                detailsVo.setIsVip(tAppUser.getIsVip());
                if(tAppUser.getGender()!=null){
                    detailsVo.setSex(tAppUser.getGender() == 1 ? "男" : "女");
                }
                System.out.println("============="+tAppUser);
 
                if (tAppUser.getBirthday()!=null){
                detailsVo.setBirthday(format1.format(tAppUser.getBirthday()));
                }
                detailsVo.setAddress(tAppUser.getProvince()+tAppUser.getCity());
                if(tAppUser.getVipEndTime()!=null){
 
                    detailsVo.setMemberLifespan(format1.format(tAppUser.getVipEndTime()));
                }
            }
            return ResultUtil.success(detailsVo);
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/uploadImage")
    @ApiOperation(value = "上传用户头像", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "userImage",value = "用户头像连接",dataType = "string")
    })
    public ResultUtil uploadAppUserProfile(String userImage){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            TAppUser byId = tauService.getById(appUserId);
            if (ToolUtil.isNotEmpty(userImage)){
                byId.setHeadImg(userImage);
                tauService.updateById(byId);
            }else {
                ResultUtil.error("头像不能为空!");
            }
            return ResultUtil.success();
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/cancellation")
    @ApiOperation(value = "个人信息-注销账号", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil cancellationAccount(){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
//            变更账号的状态为删除
            tauService.cancellation(appUserId);
//            增加一条注销账号的日志
            slClient.cancellation(appUserId);
//            删除redis中用户key
            tokenUtil.logout();
            return ResultUtil.success();
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/logOut")
    @ApiOperation(value = "个人信息-退出登录", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil logOutAccount(){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            //            增加一条退出账号的日志
            slClient.logOut(appUserId);
            //            删除redis中用户key
            tokenUtil.logout();
            return ResultUtil.success();
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/userBilling")
    @ApiOperation(value = "账单", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "年月", name = "yearMonth", required = true, dataType = "string"),
            @ApiImplicitParam(value = "记录(1充值 2扣除)", name = "recordId", required = false, dataType = "int"),
    })
    public ResultUtil<List<ConsumeDetail>> getUserBillingDetails(String yearMonth,Integer recordId){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(tauService.queryUserBillingDetails(yearMonth,recordId,appUserId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/voucherDetail")
    @ApiOperation(value = "充值明细", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "年月", name = "yearMonth", required = false, dataType = "string"),
            @ApiImplicitParam(value = "页码", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "每页数量", name = "pageSize", required = true, dataType = "int"),
            @ApiImplicitParam(value = "记录(1充值 2扣除)", name = "recordId", required = false, dataType = "int"),
    })
    public ResultUtil<List<RechargesDetail>> wpGoldRechargeRecord(String yearMonth, Integer recordId,Integer pageNum,Integer pageSize){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(rechargeRService.getAppUserRechargeRecord(yearMonth,recordId,appUserId,pageNum,pageSize));
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/voucherCenter")
    @ApiOperation(value = "充值中心", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<List<RechargeCentVo>> rechargeCenterConfig(){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(tauService.getSysRechargeConfig(appUserId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
    /**
     * 充值中心-支付
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/payment")
    @ApiOperation(value = "充值中心-支付", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil rechargeCenPayment(RechargePayRequest request){
        try {
            Integer userIdFormRedis = tokenUtil.getUserIdFormRedis();
            if(null == userIdFormRedis){
                return ResultUtil.tokenErr();
            }
            return rechargeRService.rechargeCenPayment(userIdFormRedis,request);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
 
    }
 
 
    /**
     * 积分商城
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/integralMallList")
    @ApiOperation(value = "积分商城", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public ResultUtil<List<Goods>> pointsMallList(MallRequest request){
//        try {
        System.out.println("======request========"+request);
            return ResultUtil.success(tauService.queryAppUserIntegral(request));
//        }catch (Exception e){
//            return ResultUtil.runErr();
//        }
    }
 
 
    /**
     * 商品详情
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/goodsDetails")
    @ApiOperation(value = "积分商城-商品详情", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "商品id", name = "goodId", required = true, dataType = "int"),
            @ApiImplicitParam(value = "商品类型 1实物 2课包 3门票 4优惠券", name = "goodsType", required = true, dataType = "int"),
    })
    public ResultUtil<ProductDetailsVo> productDetails(Integer goodId, Integer goodsType){
        try {
            return ResultUtil.success(tauService.productDetails(goodId,goodsType));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/useBenefit/goodsDetailsOne")
    @ApiOperation(value = "积分商城-商品详情", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "商品id", name = "goodId", required = true, dataType = "int"),
    })
    public ResultUtil<ProductDetailsVo> goodsDetailsOne(Integer goodId){
        try {
            return ResultUtil.success(tauService.goodsDetailsOne(goodId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
    /**
     * 实体、门票、优惠券为默认门店|课包为默认学员
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/goodsOfCourseStore")
    @ApiOperation(value = "积分商城-实体、门票、优惠券为默认门店|课包为默认学员", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "纬度", name = "lat", required = false, dataType = "String"),
            @ApiImplicitParam(value = "经度", name = "lon", required = false, dataType = "String"),
            @ApiImplicitParam(value = "是否为课包商品(1=是 2=否)", name = "isCourse", required = true, dataType = "int"),
            @ApiImplicitParam(value = "商品id", name = "pointsMerId", required = true, dataType = "int"),
    })
    public ResultUtil<StuAndStoreResponse> goodsOfCourseStore(String lat, String lon,Integer isCourse,Integer pointsMerId){
        try {
            Integer userIdFormRedis = tokenUtil.getUserIdFormRedis();
            if(null == userIdFormRedis){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(tauService.queryAppUserDefaultStuAndStore(userIdFormRedis,pointsMerId,lat,lon,isCourse));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 兑换详情(实体、门票、优惠券)中的门店列表
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/exchangeStoreIds")
    @ApiOperation(value = "积分商城-兑换详情(实体、门票、优惠券)中的门店列表", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "商品类型 1实物 2课包 3门票 4优惠券", name = "goodsType", required = true, dataType = "String"),
            @ApiImplicitParam(value = "商品id", name = "pointsMerId", required = true, dataType = "int"),
    })
    public ResultUtil<List<StoreResponse>> getExchangeStoreIds( Integer goodsType,Integer pointsMerId){
        try {
            return ResultUtil.success(tauService.queryStoresOfExchange(goodsType,pointsMerId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
    /**
     * 商品兑换
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/productRedemptionOperation")
    @ApiOperation(value = "积分商城-商品兑换", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    public synchronized ResultUtil productRedemptionOperation(GoodsExchangeVo exchangeType){
        try {
            Integer userIdFormRedis = tokenUtil.getUserIdFormRedis();
            if(null == userIdFormRedis){
                return ResultUtil.tokenErr();
            }
            return tauService.productRedemptionOperation(userIdFormRedis,exchangeType);
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 积分明细
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/integralDetails")
    @ApiOperation(value = "积分商城-积分明细", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "年月", name = "yearMonth", required = false, dataType = "string"),
            @ApiImplicitParam(value = "记录(1充值 2扣除)", name = "recordId", required = false, dataType = "int"),
    })
    public ResultUtil<List<IntegralsData>> pointDetails(String yearMonth, Integer recordId){
        try {
            Integer userIdFormRedis = tokenUtil.getUserIdFormRedis();
            if(null == userIdFormRedis){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(uicService.queryUserPointsDetails(yearMonth,recordId,userIdFormRedis));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 兑换记录
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/exchangeRecords")
    @ApiOperation(value = "积分商城-兑换记录", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "使用状态 (1已使用 2未使用)", name = "useType", required = false, dataType = "string"),
            @ApiImplicitParam(value = "商品类型  1实物 2课包 3门票 4优惠券", name = "goodType", required = false, dataType = "int"),
            @ApiImplicitParam(value = "page", name = "页数", required = true, dataType = "int"),
            @ApiImplicitParam(value = "size", name = "size", required = true, dataType = "int"),
    })
    public ResultUtil<List<ExchangeDetailsResponse>> exchangeRecordsDetails(Integer useType, Integer goodType,Integer page,Integer size){
        try {
            if(page==null || size==null){
                page=1;
                size=10;
            }
            Integer userIdFormRedis = tokenUtil.getUserIdFormRedis();
            if(null == userIdFormRedis){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(uicService.queryExchangeGoodsdetails1(userIdFormRedis,useType,goodType,page,size));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 兑换记录详情
     */
    @ResponseBody
    @PostMapping("/api/useBenefit/redemptionDetails")
    @ApiOperation(value = "积分商城-兑换记录详情", tags = {"APP-使用福利"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(value = "记录id", name = "detailsId", required = true, dataType = "string"),
    })
    public ResultUtil<PointDetailsVo> redemptionDetails(Long detailsId){
        try {
            return ResultUtil.success(uicService.queryRedemptionDetails(detailsId));
        }catch (Exception e){
            return ResultUtil.runErr();
        }
    }
 
 
 
}