luodangjia
2024-12-04 a981c07d34edd0975b9d556d97c1f851ce79974c
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
package com.ruoyi.account.controller;
import java.time.LocalDateTime;
 
 
import com.ruoyi.account.api.model.AppUser;
import com.ruoyi.account.api.model.UserCancellationLog;
import com.ruoyi.account.api.model.UserCoupon;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.service.UserCancellationLogService;
import com.ruoyi.account.service.UserCouponService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.Shop;
import com.ruoyi.other.api.feignClient.StoreClient;
import org.junit.Test;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
 
import javax.annotation.Resource;
import java.util.List;
import com.ruoyi.account.api.model.AppUser;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.vo.*;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-21
 */
@Api(tags = {"登录注册-小程序"})
@RestController
@RequestMapping("/app-user")
public class AppUserController extends BaseController {
 
 
 
    @Resource
    private TokenService tokenService;
    @Resource
    private AppUserService appUserService;
    @Resource
    private StoreClient storeClient;
    @Resource
    private UserCouponService userCouponService;
 
 
    @ResponseBody
    @PostMapping("/mobileLogin")
    @ApiOperation(value = "手机号登录")
    public AjaxResult<LoginVo> mobileLogin(@RequestBody MobileLogin mobileLogin){
        return appUserService.mobileLogin(mobileLogin);
    }
 
    @PostMapping("getAppUserById")
    AppUser getAppUserById(@RequestParam("id") Long id){
        return appUserService.getById(id);
    }
 
 
 
 
    @ResponseBody
    @PostMapping("/appletLogin")
    @ApiOperation(value = "小程序一键登录")
    public R<LoginVo> appletLogin(@RequestBody AppletLogin appletLogin){
        return appUserService.appletLogin(appletLogin);
    }
    
    
    @ResponseBody
    @PostMapping("/getAppUserById")
    public AppUser getAppUserById(@RequestParam("id") Long id){
        return appUserService.getById(id);
    }
 
    @ResponseBody
    @PostMapping("/editAppUserById")
    public R<Void> editAppUserById(@RequestParam("appUser") AppUser appUser){
        appUserService.updateById(appUser);
        return R.ok();
    @PostMapping("/mobileLogin")
    @ApiOperation(value = "手机号登录")
    public R<LoginVo> mobileLogin(@RequestBody MobileLogin mobileLogin){
        return appUserService.mobileLogin(mobileLogin);
    }
 
    @ResponseBody
    @PostMapping("/getCouponCount")
    public R<Long> getCouponCount(@RequestParam("userId")Long userId, @RequestParam("couponId") Integer couponId ){
        Long count = userCouponService.lambdaQuery().eq(UserCoupon::getAppUserId, userId).eq(UserCoupon::getCouponId, couponId).count();
        return R.ok(count);
    }
 
    @ResponseBody
    @PostMapping("/getVipCount")
    public R<Long> getVipCount(@RequestParam("userId")Long userId, @RequestParam("vipId") Integer vipId ){
        appUserService.lambdaQuery().eq(AppUser::getInviteUserId, userId).eq(AppUser::getVipId, vipId).count()
        return R.ok(count);
    }
 
 
    
    
    @ResponseBody
    @PostMapping("/getSMSCode")
    @ApiOperation(value = "获取短信验证码")
    public R getSMSCode(@RequestBody SMSCode smsCode){
        return appUserService.getSMSCode(smsCode);
    }
 
 
 
    @ResponseBody
    @PostMapping("/registerAccount")
    @ApiOperation(value = "注册新账号")
    public R<LoginVo> registerAccount(@RequestBody RegisterAccount registerAccount){
        return appUserService.registerAccount(registerAccount);
    }
 
 
    @ResponseBody
    @GetMapping("/getReferrer/{id}")
    @ApiOperation(value = "获取推荐人信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "推荐人id", required = true, dataType = "long")
    })
    public R<String> getReferrer(@PathVariable("id") Long id){
        AppUser appUser = appUserService.getById(id);
        String phone = appUser.getPhone();
        phone = phone.substring(0, 3) + "****" + phone.substring(7);
        return R.ok(appUser.getName() + "-" + phone);
    }
 
 
 
    @ResponseBody
    @GetMapping("/getNearbyReferrer")
    @ApiOperation(value = "获取附近推荐人列表")
    public TableDataInfo<NearbyReferrerVo> getNearbyReferrer(NearbyReferrer nearbyReferrer){
        startPage();
        List<NearbyReferrerVo> list = appUserService.getNearbyReferrer(nearbyReferrer);
        return getDataTable(list);
    }
 
 
    @ResponseBody
    @PostMapping("/info")
    @ApiOperation(value = "我的资料", tags = {"小程序-个人中心首页-我的资料"})
    public R<AppUser> info(){
        Long userId = tokenService.getLoginUserApplet().getUserid();
        AppUser user = appUserService.getById(userId);
        return R.ok(user);
    }
   @Resource
   private UserCancellationLogService userCancellationLogService;
 
    @ResponseBody
    @PostMapping("/unregis")
    @ApiOperation(value = "注销", tags = {"小程序-个人中心首页-我的资料"})
    public R unregis(){
        Long userId = tokenService.getLoginUserApplet().getUserid();
        AppUser user = appUserService.getById(userId);
 
        //添加注销记录
        UserCancellationLog userCancellationLog = new UserCancellationLog();
        userCancellationLog.setAppUserId(user.getId());
        userCancellationLog.setVipId(user.getVipId());
        userCancellationLogService.save(userCancellationLog);
 
 
        return R.ok();
    }
 
 
 
 
    @PostMapping("/index")
    @ApiOperation(value = "个人中心首页", tags = {"小程序-个人中心首页"})
    public R<AppUser> index(){
        System.err.println("=-====");
        Long userId = tokenService.getLoginUserApplet().getUserid();
        //当前用户信息
        AppUser user = appUserService.getById(userId);
        //当前用户的推荐人信息
        if (user.getInviteUserId()!=null){
            AppUser inviteUser = appUserService.getById(user.getInviteUserId());
            user.setInviteUserName(inviteUser.getName());
        }
        //当前绑定门店的店铺信息
        if (user.getShopId()!=null){
            R<Shop> storeById = storeClient.getStoreById(user.getShopId());
            if (storeById.getData()!=null){
                user.setShopName(storeById.getData().getName());
            }
        }
        Long count1 = appUserService.lambdaQuery().eq(AppUser::getVipId, 1).eq(AppUser::getTopInviteId, 1).count();
        Long count2 = appUserService.lambdaQuery().eq(AppUser::getVipId, 2).eq(AppUser::getTopInviteId, userId).count();
        Long count3 = appUserService.lambdaQuery().eq(AppUser::getVipId, 3).eq(AppUser::getTopInviteId, userId).count();
        Long count4 = appUserService.lambdaQuery().eq(AppUser::getVipId, 4).eq(AppUser::getTopInviteId, userId).count();
        Long count5 = appUserService.lambdaQuery().eq(AppUser::getVipId, 5).eq(AppUser::getTopInviteId, userId).count();
        Long count6 = appUserService.lambdaQuery().eq(AppUser::getVipId, 6).eq(AppUser::getTopInviteId, userId).count();
        Long count7 = appUserService.lambdaQuery().eq(AppUser::getVipId, 7).eq(AppUser::getTopInviteId, userId).count();
        user.setCount1(count1);
        user.setCount2(count2);
        user.setCount3(count3);
        user.setCount4(count4);
        user.setCount5(count5);
        user.setCount6(count6);
        user.setCount7(count7);
        return R.ok(user);
 
 
    }
 
    /**
     * 获取用户的祖籍列表
     */
    @GetMapping("/getUserAncestorList")
    public R<List<AppUser>> getUserAncestorList(Long id){
        List<AppUser> list = appUserService.getUserAncestorList(id,null);
        return R.ok(list);
    }
 
 
 
}