huliguo
2025-04-23 f2070facdb5715e7349df69cfe257289c680d292
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
package com.ruoyi.account.controller;
 
 
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.account.api.model.*;
import com.ruoyi.account.dto.ApplyForAdmissionDTO;
import com.ruoyi.account.dto.ChangeAppUserInfo;
import com.ruoyi.account.mapper.AppUserMapper;
import com.ruoyi.account.service.*;
import com.ruoyi.account.util.ObsUploadUtil;
import com.ruoyi.account.util.weChat.EnvVersion;
import com.ruoyi.account.util.weChat.WeChatUtil;
import com.ruoyi.account.vo.*;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.feignClient.OrderClient;
import com.ruoyi.order.feignClient.RemoteOrderGoodsClient;
import com.ruoyi.order.model.Order;
import com.ruoyi.other.api.domain.Shop;
import com.ruoyi.other.api.feignClient.ShopClient;
import com.ruoyi.system.api.domain.SysConfig;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysConfigClient;
import com.ruoyi.system.api.feignClient.SysUserClient;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-21
 */
@Api(tags = {"用户端-小程序"})
@RestController
@RequestMapping("/app-user")
@Slf4j
public class AppUserController extends BaseController {
    
    @Resource
    private TokenService tokenService;
    @Resource
    private AppUserService appUserService;
    @Resource
    private AppUserMapper appUserMapper;
    @Resource
    private ShopClient shopClient;
    @Resource
    private RemoteOrderGoodsClient remoteOrderGoodsClient;
    @Resource
    private SysUserClient sysUserClient;
    @Resource
    private OrderClient orderClient;
    @Resource
    private SysConfigClient sysConfigClient;
    @Resource
    private AppUserShopService appUserShopService;
    
    @Resource
    private UserCancellationLogService userCancellationLogService;
    @Resource
    private RedisService redisService;
 
    @Resource
    private WeChatUtil weChatUtil;
 
    @Value("${file.upload.location}")
    private String filePath;
 
 
    @ResponseBody
    @PostMapping("/mobileLogin")
    @ApiOperation(value = "手机号登录")
    public R<LoginVo> mobileLogin(@RequestBody MobileLogin mobileLogin) {
        return appUserService.mobileLogin(mobileLogin);
    }
 
 
    @GetMapping("/logout")
    @ApiOperation(value = "登出")
    public R logout() {
        Long userId = tokenService.getLoginUserApplet().getUserid();
        loginout(userId);
        return R.ok();
    }
 
 
    @ResponseBody
    @PostMapping("/appletLogin")
    @ApiOperation(value = "小程序一键登录")
    public R<LoginVo> appletLogin(@RequestBody AppletLogin appletLogin) {
        return appUserService.appletLogin(appletLogin);
    }
 
 
    @PostMapping("/getAppUserById")
    public AppUser getAppUserById(@RequestParam("id") Long id) {
        System.out.println("根据id获取用户:"+id);
        return appUserService.getById(id);
    }
 
    @PostMapping("/getBaseUserById")
    public R<Map<String, Object>> getBaseUserById(@RequestParam("id") Long id) {
        AppUser appUser = appUserService.getById(id);
        Map<String, Object> map = new HashMap<>();
        map.put("id", appUser.getId());
        map.put("name", appUser.getName());
        map.put("phone", appUser.getPhone());
        return R.ok(map);
    }
 
 
    @ResponseBody
    @PostMapping("/editAppUserById")
    public R<Void> editAppUserById(@RequestBody AppUser appUser) {
        appUserService.updateById(appUser);
        appUserService.update(new LambdaUpdateWrapper<AppUser>().eq(AppUser::getId, appUser.getId())
                .set(AppUser::getLastShopTime, appUser.getLastShopTime()));
        return R.ok();
 
    }
 
 
 
 
 
    @ResponseBody
    @PostMapping("/getSMSCode")
    @ApiOperation(value = "获取短信验证码")
    public R getSMSCode(@RequestBody SMSCode smsCode) {
        return appUserService.getSMSCode(smsCode);
    }
 
 
 
 
 
    @ResponseBody
    @GetMapping("/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());
        userCancellationLogService.save(userCancellationLog);
        user.setStatus(3);
        appUserService.updateById(user);
        return R.ok();
    }
 
    @ResponseBody
    @GetMapping("/getServicePhone")
    @ApiOperation(value = "获取客服电话", tags = {"小程序-个人中心首页-客服"})
    public R getServicePhone() {
        SysConfig data = sysConfigClient.getInfo(7L).getData();
        List<String> phoneList = null;
        if (data != null) {
            phoneList = Arrays.stream(data.getConfigValue().split(";"))
                    .map(String::trim)  // 去除每个号码前后的空格
                    .filter(s -> !s.isEmpty())  // 过滤空字符串
                    .collect(Collectors.toList());
        }
        return R.ok(phoneList);
    }
 
 
 
 
 
 
 
    @GetMapping("/index")
    @ApiOperation(value = "个人信息", tags = {"小程序-个人中心首页"})
    public R<AppUser> index() {
        return R.ok(appUserService.index());
    }
 
 
 
 
    
    
 
 
 
    @PostMapping("/index/change")
    @ApiOperation(value = "修改个人资料", tags = {"小程序-个人中心首页"})
    public R<AppUser> indexchange(@RequestBody ChangeAppUserInfo changeAppInfo) {
        Long userId = tokenService.getLoginUserApplet().getUserid();
        //当前用户信息
        AppUser user = appUserService.getById(userId);
        if (null != changeAppInfo.getName()){
            user.setName(changeAppInfo.getName());
        }
        if (null != changeAppInfo.getAvatar()){
            user.setAvatar(changeAppInfo.getAvatar());
        }
        appUserService.updateById(user);
        return R.ok();
    }
 
 
 
    /**
     * 根据用户名称模糊搜索用户列表
     *
     * @param name
     * @return
     */
    @PostMapping("/getAppUserByName")
    public R<List<AppUser>> getAppUserByName(@RequestParam("name") String name) {
        List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1)
                .like(AppUser::getName, name));
        return R.ok(list);
    }
    /**
     * 根据用户名称模糊搜索用户列表,不过滤状态
     */
    @GetMapping("/getAppUserByNameNoFilter")
    public R<List<AppUser>> getAppUserByNameNoFilter(@RequestParam("name") String name) {
        List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>()
                .like(AppUser::getName, name));
        return R.ok(list);
    }
 
 
    /**
     * 根据用户电话模糊搜索用户列表
     *
     * @param phone
     * @return
     */
    @PostMapping("/getAppUserByPhone")
    public R<List<AppUser>> getAppUserByPhone(@RequestParam("phone") String phone) {
        List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1)
                .like(AppUser::getPhone, phone));
        return R.ok(list);
    }
 
    /**
     * 更具用户电话模糊查询用户列表,不过滤状态
     */
    @GetMapping("/getAppUserByPhoneNoFilter")
    public R<List<AppUser>> getAppUserByPhoneNoFilter(@RequestParam("phone") String phone) {
        List<AppUser> list = appUserService.getAppUserByPhoneNoFilter(phone);
        return R.ok(list);
    }
 
 
    @GetMapping("/getUserPointsPage")
    @ApiOperation(value = "用户列表", tags = {"管理后台"})
    public R<IPage<AppUser>> getUserPointsPage(@ApiParam("页码") @RequestParam Integer pageNum,
                                            @ApiParam("每一页数据大小") Integer pageSize,
                                            AppUser appUser) {
 
        Long userId = tokenService.getLoginUser().getUserid();
        SysUser data = sysUserClient.getSysUser(userId).getData();
 
        QueryWrapper<AppUser> queryWrapper = new QueryWrapper<>();
        if (data.getRoleType() == 2) {
            Integer shopId = data.getObjectId();
            List<Order> orders = orderClient.getRedeemedOrdersByShop(shopId).getData();
            List<Long> userIds = orders.stream().map(Order::getAppUserId).collect(Collectors.toList());
            //门店作为服务商的用户
           /* Set<Long> shopServerUser = getShopServerUser(shopId);
            userIds.addAll(shopServerUser);*/
            queryWrapper.in(!CollectionUtils.isEmpty(userIds), "id", userIds)
                    .like(StringUtils.isNotEmpty( appUser.getName()),"name", appUser.getName());
        }
        queryWrapper.eq("del_flag", 0);
        queryWrapper.ne("status", 3);
 
        List<AppUser> appUserList = appUserService.list(queryWrapper);
        Page<AppUser> objectPage = Page.of(pageNum, pageSize);
        objectPage.setRecords(appUserList);
        return R.ok(objectPage);
 
    }
 
    /**
     * 获取用户列表
     */
    @GetMapping("/getAppuserPage")
    public R<IPage<AppUser>> getAppuserPage(@ApiParam("页码") @RequestParam Integer pageNum,
                                               @ApiParam("每一页数据大小") Integer pageSize,
                                               AppUser appUser){
        Integer shopId = null;
        Set<Long> userId = null;
        IPage<AppUser> appuserPage = appUserService.getAppuserPage(pageNum, pageSize, appUser, shopId, userId);
 
        return R.ok(appuserPage);
    }
 
 
    /**
     * 获取用户积分列表
     */
    @GetMapping("/getUserPotPage")
    public R<IPage<AppUser>> getUserPotPage(@ApiParam("页码") @RequestParam Integer pageNum,
                                               @ApiParam("每一页数据大小") Integer pageSize,
                                               AppUser appUser) {
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
        Integer shopId = null;
        Set<Long> userId = null;
        if(sysUser.getRoleType() == 2){
            shopId = sysUser.getObjectId();
            userId = orderClient.getAppUserByShoppingShop(shopId).getData();
        }
        IPage<AppUser> appuserPage = appUserService.getAppuserPage(pageNum, pageSize, appUser, shopId, userId);
        for (AppUser record : appuserPage.getRecords()) {
           /* if (record.getInviteUserId() != null) {
                AppUser byId1 = appUserService.getById(record.getInviteUserId());
                if (byId1!=null) {
                    record.setInviteUserName(byId1.getName());
                }
            }*/
            if (record.getShopId()!=null){
                R<Shop> shopById = shopClient.getShopById(record.getShopId());
                if (shopById.getData()!=null){
                    record.setShopName(shopById.getData().getName());
                }
            }
 
        }
        return R.ok(appuserPage);
    }
 
 
    @GetMapping("/shop/getAppuserPage")
    @ApiOperation(value = "用户列表-在门店下过单的", tags = {"门店后台"})
    public R<IPage<AppUser>> shopGetAppuserPage(@ApiParam("页码") @RequestParam Integer pageCurr,
                                                @ApiParam("每一页数据大小") Integer pageSize,
                                                AppUser appUser) {
        Long userid = tokenService.getLoginUser().getUserid();
        R<SysUser> sysUserR = sysUserClient.getSysUser(userid);
        SysUser sysUser = sysUserR.getData();
 
        List<Long> userIds = new ArrayList<>();
        userIds.add(-1L);
        //获取在该本店下单的用户ids
        Integer objectId = sysUser.getObjectId();
        R<List<Order>> listR = remoteOrderGoodsClient.byShopId(objectId);
        if (listR.getData()!=null){
            for (Order datum : listR.getData()) {
                userIds.add(datum.getAppUserId());
            }
           /* Set<Long> shopServerUser = getShopServerUser(objectId);
            userIds.addAll(shopServerUser);*/
        }
        IPage<AppUser> appuserPage = appUserService.getAppuserPage1(pageCurr, pageSize, appUser, userIds);
        return R.ok(appuserPage);
    }
 
 
 
    @GetMapping("/frozen")
    @ApiOperation(value = "用户列表-冻结解冻", tags = {"管理后台"})
    public R frozen(Long id, @ApiParam("1=正常,2=冻结") Integer status) {
        AppUser byId = appUserService.getById(id);
        byId.setStatus(status);
        appUserService.updateById(byId);
        if (status == 2){
            loginout(id);
        }
        return R.ok();
    }
 
    private void loginout(Long userId) {
        // 获取所有符合模式的缓存键
        Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
        if (CollectionUtils.isEmpty(keys)) {
            return; // 如果没有匹配的键,直接返回
        }
 
        // 遍历所有键并删除与指定用户ID相关的登录信息
        for (String key : keys) {
            LoginUser user = redisService.getCacheObject(key);
            if (user != null && userId.equals(user.getUserid())) {
                redisService.deleteObject(key);
            }
        }
    }
    
    @GetMapping("/change/shop")
    @ApiOperation(value = "用户列表-更换门店", tags = {"管理后台"})
    public R<AppUser> shop(Long id, Integer shopId) {
        AppUser byId = appUserService.getById(id);
        byId.setShopId(shopId);
        appUserService.updateById(byId);
        return R.ok();
    }
 
 
 
 
    @GetMapping("/detail")
    @ApiOperation(value = "用户列表-详情", tags = {"管理后台"})
    public R<AppUser> detail(Long id) {
        AppUser byId = appUserService.getById(id);
        //获取店铺名称
        List<String> shopNames=shopClient.getServiceProvider(byId.getId()).getData();
        if(null != shopNames){
            byId.setShopNames(shopNames);
        }
        //消费总金额
        Integer customPoint =(byId.getExchangePoint()==null?0:byId.getExchangePoint())+
                (byId.getTransferableOutPoint()==null?0:byId.getTransferableOutPoint())-
                (byId.getCancelPoint()==null?0:byId.getCancelPoint());
        byId.setCustomPoint(customPoint);
 
        return R.ok(byId);
    }
 
 
 
    @GetMapping("/orders")
    @ApiOperation(value = "用户列表-订单列表", tags = {"管理后台"})
    public R<JSONObject> orders(Long id,Integer pageNum, Integer pageSize) {
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
        Integer shopId = -1;
        if(sysUser.getRoleType() == 2){
            shopId = sysUser.getObjectId();
        }
        R<List<Order>> listR = remoteOrderGoodsClient.byUserId(id,shopId);
        List<Order> data = listR.getData();
        Integer total = data.size();
        // 手动分页
        if (data != null && data.size() > 0) {
            if (pageNum == null || pageNum == 0) {
                pageNum = 1;
            }
            if (pageSize == null || pageSize == 0) {
                pageSize = 10;
            }
            data = data.stream()
                    .skip((pageNum - 1) * pageSize)
                    .limit(pageSize)
                    .collect(Collectors.toList());
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("records", data);
        jsonObject.put("total", total);
        jsonObject.put("size", pageSize);
        jsonObject.put("current", pageNum);
        return R.ok(jsonObject);
    }
 
 
    @PostMapping("/listByIds")
    public List<AppUser> listByIds(@RequestParam("ids") List<Long> ids) {
        if(ids.size() == 0){
            return new ArrayList<>();
        }
        List<AppUser> appUsers = appUserService.listByIds(ids);
        return appUsers;
    }
 
 
    @PostMapping("/getAppUserByPhone1")
    public R<AppUser> getAppUserByPhone1(@RequestParam("phone") String phone) {
        AppUser appUser = appUserService.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).ne(AppUser::getStatus, 3)
                .eq(AppUser::getPhone, phone));
        return R.ok(appUser);
    }
 
 
 
 
    /**
     * 工作台-顶部
     */
    @GetMapping("/statistics")
    @ApiOperation(value = "统计", tags = {"后台-工作台-顶部"})
    public R<UserStatistics> statistics() {
        QueryWrapper<AppUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del_flag", 0);
        queryWrapper.ne("status", 3);//没有注销的
 
        List<AppUser> appUserList = appUserService.list(queryWrapper);
        long consumerUser = appUserList.stream()
                .filter(user -> user.getLastShopTime() != null)
                .count();//消费者总数
 
        UserStatistics userStatistics = new UserStatistics();
        userStatistics.setTotalUser(appUserList.size());//总用户数
        userStatistics.setConsumerUser((int) consumerUser);//消费过的用户
 
        //用户类型统计门店
        long shopUserCount = appUserList.stream()
                .filter(appUser -> appUser.getUserType() == 2)
                .count();
        userStatistics.setShopUser((int) shopUserCount);
 
        //门店总数
        long shopNum = shopClient.getAllShop().getData().size();
        userStatistics.setShopNum((int) shopNum);
        return R.ok(userStatistics);
    }
 
    /**
     * 工作台-用户分析
     */
    @GetMapping("/homeStatistics/userAnalysis")
    @ApiOperation(value = "用户分析", tags = {"后台-工作台-用户分析"})
    public R<UserStatisticsDetail> userAnalysis(@ApiParam(value = "用户id") @RequestParam(value = "userId",required = false) Long userId) {
        UserStatisticsDetail userStatistics = new UserStatisticsDetail();
 
        QueryWrapper<AppUser> queryWrapper = new QueryWrapper<>();
        // 条件构造  统计充值积分
        queryWrapper.select("SUM(recharge_point) as total_points");
        queryWrapper.eq("del_flag", 0);//未删除的
        queryWrapper.ne("status", 3);//未注销的
        if (userId != null) {
            queryWrapper.eq("id", userId);
        }
        //统计充值积分
        Map<String, Object> result = appUserService.getMap(queryWrapper);
        if (result == null || result.get("total_points") == null) {
            userStatistics.setTotalScore(0L);
        }else {
            userStatistics.setTotalScore((Long) result.get("total_points"));
        }
 
        //统计消费积分和现金支付数
        Map<String, Object> data = orderClient.getConsumeScoreAndPayAmount(userId).getData();
 
        if (data == null || data.get("total_points") == null) {
            userStatistics.setConsumeScore(0L);
        }else {
            userStatistics.setConsumeScore(Long.valueOf(data.get("total_points").toString()) );
        }
 
        if (data == null || data.get("payment_amounts") == null) {
            userStatistics.setShopAmount(BigDecimal.ZERO);
        }else {
            userStatistics.setShopAmount(new BigDecimal(data.get("payment_amounts").toString()));
        }
 
 
        return R.ok(userStatistics);
    }
 
    /**
     * 用户统计详情
     */
    @GetMapping("/statistics/detail")
    @ApiOperation(value = "用户统计详情", tags = {"管理后台-首页统计-用户统计详情"})
    public R<UserStatisticsDetail> statisticsDetail(@ApiParam(value = "用户id") Long userId) {
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser data = sysUserClient.getSysUser(userid).getData();
        Integer shopId = null;
        Set<Long> userIds = null;
        if(null != userId){
            userIds = new HashSet<>();
            userIds.add(userId);
        }
        if(data.getRoleType() == 2){
            shopId = data.getObjectId();
            if(null == userId){
                userIds = orderClient.getAppUserByShoppingShop(shopId).getData();
              /*  Set<Long> shopServerUser = getShopServerUser(shopId);
                userIds.addAll(shopServerUser);*/
            }else{
                userIds = new HashSet<>();
                userIds.add(userId);
            }
            
        }
        UserStatisticsDetail userStatisticsDetail = appUserMapper.getUserStatisticsDetail(null, userIds);
        return R.ok(userStatisticsDetail);
    }
 
 
    
    /**
     * 上传图片
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public R upload(MultipartFile file){
        String s = null;
        try {
            s = ObsUploadUtil.obsUpload(file);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return R.ok(s);
    }
    
    
 
    /**
     * 清空绑定门店的用户门店数据
     * @param shopId
     * @return
     */
    @PostMapping("/clearBindShop")
    public R clearBindShop(@RequestParam("shopId") Integer shopId){
        appUserService.update(new LambdaUpdateWrapper<AppUser>().eq(AppUser::getShopId, shopId).set(AppUser::getShopId, null)
                .set(AppUser::getUserType,1));
        return R.ok();
    }
 
 
    /**
     * 获取所有用户积分列表
     */
    @ResponseBody
    @GetMapping("/getUserPointPageList")
    @ApiOperation(value = "所有用户积分列表", tags = "后台-财务统计-用户积分统计")
    public R<PageInfo<UserPointStatisticsVO>> getUserPointPageList(@RequestParam(value = "name",required = false) String name,
                                                                   @ApiParam("当前页")@RequestParam("pageCurr") Integer pageCurr,
                                                                   @ApiParam("分页大小")@RequestParam("pageSize") Integer pageSize) {
        PageInfo<UserPointStatisticsVO> pageInfo=appUserService.getUserPointPageList(name,pageCurr,pageSize);
 
        return R.ok(pageInfo);
    }
 
    /**
     * 导出用户积分列表
     */
    @ResponseBody
    @GetMapping("/exportUserPoint")
    @ApiOperation(value = "导出用户积分列表", tags = "后台-财务统计-用户积分统计")
    public void exportUserPoint(HttpServletResponse response, @RequestParam(value = "name",required = false) String name) {
 
        List<UserPointStatisticsVO> exportList=appUserMapper.exportUserPoint(name);
        ExcelUtil<UserPointStatisticsVO> util = new ExcelUtil<UserPointStatisticsVO>(UserPointStatisticsVO.class);
        util.exportExcel(response, exportList, "用户积分汇总");
    }
 
 
    @PostMapping("/saveOrUpdateAppUser")
    Long saveOrUpdateAppUser(@RequestBody AppUser appuser){
        if (appuser.getId() == null) {
            //保存用户
            appUserService.save(appuser);
        }else {
            appUserService.updateById(appuser);
        }
        return appuser.getId();
 
    }
 
    @GetMapping("/getAllUser")
    @ApiOperation(value = "获取所有用户")
    public R<List<AppUser>> getAllUser() {
        LambdaQueryWrapper<AppUser> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.select(AppUser::getId,AppUser::getName);
        queryWrapper.eq(AppUser::getDelFlag,0);//未删除的
        queryWrapper.ne(AppUser::getStatus, 3);//未注销的
        List<AppUser> list = appUserService.list(queryWrapper);
        return R.ok(list);
    }
 
}