| | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | 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.conditions.query.LambdaQueryChainWrapper; |
| | |
| | | @PostMapping("/getCouponCount") |
| | | public R<Long> getCouponCount(@RequestParam("userId") Long userId, @RequestParam("couponId") Integer couponId) { |
| | | LambdaQueryChainWrapper<UserCoupon> chainWrapper = userCouponService.lambdaQuery().eq(UserCoupon::getCouponId, couponId); |
| | | if(null != userId && -1 == userId){ |
| | | if(null != userId && -1 != userId){ |
| | | chainWrapper.eq(UserCoupon::getAppUserId, userId); |
| | | } |
| | | Long count = chainWrapper.count(); |
| | |
| | | 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()); |
| | | 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") |
| | | @ApiOperation(value = "用户列表", tags = {"管理后台"}) |
| | | public R<IPage<AppUser>> getAppuserPage(@ApiParam("页码") @RequestParam Integer pageNum, |
| | | @ApiParam("每一页数据大小") Integer pageSize, |
| | | AppUser appUser) { |
| | | @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(); |
| | | } |
| | | appUser.setExcludeStatus(3); |
| | | 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()); |
| | | } |
| | | } |
| | | record.setTotalPoint(record.getUserTotalPoint()); |
| | | } |
| | | 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; |
| | |
| | | record.setShopName(shopById.getData().getName()); |
| | | } |
| | | } |
| | | record.setTotalPoint(record.getUserTotalPoint()); |
| | | } |
| | | return R.ok(appuserPage); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/shop/getAppuserPage") |
| | | @ApiOperation(value = "用户列表", tags = {"门店后台"}) |
| | |
| | | @GetMapping("/statistics") |
| | | @ApiOperation(value = "用户统计", tags = {"管理后台-首页统计-用户统计"}) |
| | | public R<UserStatistics> statistics() { |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | SysUser data = sysUserClient.getSysUser(userid).getData(); |
| | | Integer shopId = null; |
| | | Set<Long> userId = null; |
| | | if(data.getRoleType() == 2){ |
| | | shopId = data.getObjectId(); |
| | | userId = orderClient.getAppUserByShoppingShop(shopId).getData(); |
| | | 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()); |
| | | queryWrapper.in(!CollectionUtils.isEmpty(userIds), "id", userIds); // userIds 不为空时,查询 id 在 userIds 中 |
| | | } |
| | | UserStatistics userStatistics = appUserMapper.getUserStatistics(shopId, userId); |
| | | List<Shop> shopList = shopClient.getAllShop().getData(); |
| | | if (CollectionUtil.isNotEmpty(shopList)){ |
| | | long count = shopList.stream().map(Shop::getAppUserId).distinct().count(); |
| | | userStatistics.setShopUser((int) count); |
| | | }else { |
| | | userStatistics.setShopUser(0); |
| | | } |
| | | queryWrapper.eq("del_flag", 0); |
| | | queryWrapper.ne("status", 3); |
| | | List<AppUser> appUserList = appUserService.list(queryWrapper); |
| | | |
| | | Map<Integer, Long> vipIdCountMap = appUserList.stream() |
| | | .collect(Collectors.groupingBy(AppUser::getVipId, Collectors.counting())); |
| | | |
| | | UserStatistics userStatistics = new UserStatistics(); |
| | | userStatistics.setTotalUser(appUserList.size()); |
| | | userStatistics.setConsumerUser(vipIdCountMap.getOrDefault(0, 0L).intValue() + |
| | | vipIdCountMap.getOrDefault(1, 0L).intValue() + |
| | | vipIdCountMap.getOrDefault(2, 0L).intValue() + |
| | | vipIdCountMap.getOrDefault(3, 0L).intValue()); |
| | | userStatistics.setCommonUser(vipIdCountMap.getOrDefault(1, 0L).intValue()); |
| | | userStatistics.setGoldUser(vipIdCountMap.getOrDefault(2, 0L).intValue()); |
| | | userStatistics.setDiamondUser(vipIdCountMap.getOrDefault(3, 0L).intValue()); |
| | | userStatistics.setEntrepreneurUser(vipIdCountMap.getOrDefault(4, 0L).intValue() + |
| | | vipIdCountMap.getOrDefault(5, 0L).intValue() + |
| | | vipIdCountMap.getOrDefault(6, 0L).intValue() + |
| | | vipIdCountMap.getOrDefault(7, 0L).intValue()); |
| | | userStatistics.setProxyUser(vipIdCountMap.getOrDefault(4, 0L).intValue()); |
| | | userStatistics.setAgentUser(vipIdCountMap.getOrDefault(5, 0L).intValue()); |
| | | userStatistics.setTotalAgentUser(vipIdCountMap.getOrDefault(6, 0L).intValue()); |
| | | userStatistics.setPartnerUser(vipIdCountMap.getOrDefault(7, 0L).intValue()); |
| | | |
| | | long shopUserCount = appUserList.stream() |
| | | .filter(appUser -> appUser.getUserType() == 2) |
| | | .count(); |
| | | userStatistics.setShopUser((int) shopUserCount); |
| | | |
| | | return R.ok(userStatistics); |
| | | } |
| | | |