lisy
2023-07-10 e51685798c47fc3fb3c73e5b78dc426f688b660c
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
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.util.ResultUtil;
import com.dsh.account.util.TokenUtil;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
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;
 
    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.setUserImage(tAppUser.getHeadImg());
                detailsVo.setUserName(tAppUser.getName());
                detailsVo.setUserPhone(tAppUser.getPhone());
                detailsVo.setSex(tAppUser.getGender() == 1 ? "男" : "女");
                detailsVo.setBirthday(format1.format(tAppUser.getBirthday()));
                detailsVo.setAddress(tAppUser.getProvince()+tAppUser.getCity());
                detailsVo.setMemberLifespan(format1.format(tAppUser.getVipEndTime()));
            }
            return ResultUtil.success(detailsVo);
        }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 = true, dataType = "int"),
    })
    public ResultUtil<BillingDetailsVo> 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 = true, dataType = "string"),
            @ApiImplicitParam(value = "记录(1充值 2扣除)", name = "recordId", required = true, dataType = "int"),
    })
    public ResultUtil<RechargeDetailsVo> wpGoldRechargeRecord(String yearMonth, Integer recordId){
        try {
            Integer appUserId = tokenUtil.getUserIdFormRedis();
            if(null == appUserId){
                return ResultUtil.tokenErr();
            }
            return ResultUtil.success(rechargeRService.getAppUserRechargeRecord(yearMonth,recordId,appUserId));
        }catch (Exception e){
            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){
            return ResultUtil.runErr();
        }
 
    }
 
 
 
}