| | |
| | | package com.ruoyi.account.controller; |
| | | |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | 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.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | @Api(tags = {"登录注册-小程序"}) |
| | | @RestController |
| | | @RequestMapping("/app-user") |
| | | @Slf4j |
| | | public class AppUserController extends BaseController { |
| | | |
| | | @Resource |
| | |
| | | if(StringUtils.isEmpty(user.getQrCode())){ |
| | | //获取微信推广二维码 |
| | | String fileName = UUID.randomUUID() + ".jpg"; |
| | | String getwxacodeunlimit = weChatUtil.getwxacodeunlimit("pages/login/login", "id=" + user.getId(), EnvVersion.RELEASE, filePath + fileName); |
| | | String getwxacodeunlimit = weChatUtil.getwxacodeunlimit("pages/start/start", "id=" + user.getId(), EnvVersion.RELEASE, filePath + fileName); |
| | | user.setQrCode(getwxacodeunlimit); |
| | | appUserService.updateById(user); |
| | | } |
| | |
| | | public R<AppUser> change(@ApiParam("换绑用户手机号") String phone) { |
| | | Long userId1 = tokenService.getLoginUserApplet().getUserid(); |
| | | AppUser byId = appUserService.getById(userId1); |
| | | List<AppUser> appUserList = appUserService.list(new LambdaQueryWrapper<AppUser>() |
| | | .eq(AppUser::getInviteUserId, userId1) |
| | | .eq(AppUser::getPhone, phone)); |
| | | if (!CollectionUtils.isEmpty(appUserList)){ |
| | | return R.fail("绑定关系已存在!"); |
| | | } |
| | | //获取绑定门店 |
| | | AppUser user = appUserService.lambdaQuery().eq(AppUser::getPhone, phone).one(); |
| | | if (user == null) { |
| | |
| | | Long userId = tokenService.getLoginUserApplet().getUserid(); |
| | | //当前用户信息 |
| | | AppUser user = appUserService.getById(userId); |
| | | if(StringUtils.isEmpty(user.getQrCode())){ |
| | | //获取微信推广二维码 |
| | | String fileName = UUID.randomUUID() + ".jpg"; |
| | | String getwxacodeunlimit = weChatUtil.getwxacodeunlimit("pages/start/start", "id=" + user.getId(), EnvVersion.RELEASE, filePath + fileName); |
| | | user.setQrCode(getwxacodeunlimit); |
| | | appUserService.updateById(user); |
| | | } |
| | | |
| | | //当前用户的推荐人信息 |
| | | if (user.getInviteUserId() != null) { |
| | | AppUser inviteUser = appUserService.getById(user.getInviteUserId()); |
| | |
| | | } |
| | | return R.ok(user); |
| | | } |
| | | |
| | | |
| | | public void getUserAncestorList(AppUser user,List<Long> userIds, List<AppUser> children,List<AppUser> list) { |
| | | children = list.stream().filter(u -> userIds.contains(u.getInviteUserId()) || userIds.contains(u.getTopInviteId())).collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(children)){ |
| | |
| | | .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); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据用户电话模糊搜索用户列表 |
| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | AppUser byId = appUserService.getById(id); |
| | | byId.setStatus(status); |
| | | appUserService.updateById(byId); |
| | | loginout(id); |
| | | if (status == 2){ |
| | | loginout(id); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | if (!CollectionUtils.isEmpty(keys)) { |
| | | for (String key : keys) { |
| | | LoginUser user = redisService.getCacheObject(key); |
| | | if (user == null || user.getUserid() == null) { |
| | | continue; |
| | | } |
| | | if (user.getUserid().equals(userId)) { |
| | | redisService.deleteObject(key); |
| | | break; |
| | |
| | | if (userId.equals(inviteId)) { |
| | | return R.fail("不能选择自己为绑定人。"); |
| | | } |
| | | |
| | | List<AppUser> appUserList = appUserService.list(new LambdaQueryWrapper<AppUser>() |
| | | .eq(AppUser::getInviteUserId, id) |
| | | .eq(AppUser::getId, inviteId)); |
| | | if (!CollectionUtils.isEmpty(appUserList)){ |
| | | return R.fail("绑定关系已存在!"); |
| | | } |
| | | |
| | | byId.setInviteUserId(inviteId); |
| | | byId.setTopInviteId(getTop(inviteId)); |
| | | appUserService.updateById(byId); |
| | |
| | | |
| | | @GetMapping("/detail") |
| | | @ApiOperation(value = "用户列表-详情", tags = {"管理后台"}) |
| | | public R<AppUser> detail(Long id, Integer shopId, Integer pageNum, Integer pageSize) { |
| | | public R<AppUser> detail(Long id, Integer shopId) { |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserClient.getSysUser(userid).getData(); |
| | | AppUser byId = appUserService.getById(id); |
| | |
| | | if (lastOrder.getData() != null) { |
| | | byId.setLastOrderTime(lastOrder.getData().getCreateTime()); |
| | | } |
| | | Page<AppUser> page = appUserService.page(Page.of(pageNum, pageSize), new LambdaQueryWrapper<AppUser>().eq(AppUser::getInviteUserId, id)); |
| | | byId.setBottomUsersPage(page); |
| | | List<AppUser> list = appUserService.lambdaQuery().eq(AppUser::getInviteUserId, id).list(); |
| | | byId.setBottomUsers(list); |
| | | //消费总金额 |
| | | if(null == shopId || 1 == sysUser.getRoleType()){ |
| | | shopId = -1; |
| | |
| | | } |
| | | return R.ok(byId); |
| | | } |
| | | |
| | | /** |
| | | * 获取指定用户的下级用户 |
| | | */ |
| | | @GetMapping("/bottom/list") |
| | | @ApiOperation(value = "用户列表-下级用户", tags = {"管理后台"}) |
| | | public R<Page<AppUser>> bottom(Integer pageNum, Integer pageSize, Long userId){ |
| | | Page<AppUser> page = appUserService.page(Page.of(pageNum, pageSize), new LambdaQueryWrapper<AppUser>() |
| | | .eq(AppUser::getInviteUserId, userId)); |
| | | return R.ok(page); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | byId.setVipId(vipId); |
| | | appUserService.updateById(byId); |
| | | return R.ok(); |
| | | |
| | | } |
| | | |
| | | @GetMapping("/bottom") |
| | | @ApiOperation(value = "用户列表-绑定下级列表", tags = {"管理后台"}) |
| | | public R<Page<AppUser>> bottom(Long id, Integer pageNum, Integer pageSize) { |
| | | //绑定下级 |
| | | Page<AppUser> page = appUserService.lambdaQuery().eq(AppUser::getInviteUserId, id).page(Page.of(pageNum, pageSize)); |
| | | Page<AppUser> page = appUserService.lambdaQuery() |
| | | .eq(AppUser::getInviteUserId, id) |
| | | .eq(AppUser::getDelFlag, 0) |
| | | .eq(AppUser::getStatus, 1) |
| | | .page(Page.of(pageNum, pageSize)); |
| | | return R.ok(page); |
| | | |
| | | } |
| | | |
| | | @GetMapping("/orders") |
| | | @ApiOperation(value = "用户列表-订单列表", tags = {"管理后台"}) |
| | | public R<List<Order>> orders(Long id) { |
| | | public R<JSONObject> orders(Long id,Integer pageNum, Integer pageSize) { |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserClient.getSysUser(userid).getData(); |
| | | Integer shopId = -1; |
| | |
| | | shopId = sysUser.getObjectId(); |
| | | } |
| | | R<List<Order>> listR = remoteOrderGoodsClient.byUserId(id,shopId); |
| | | return R.ok(listR.getData()); |
| | | |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | if (cd.getStartTime().isAfter(cd.getEndTime())) { |
| | | return R.fail("开始时间不能大于结束时间"); |
| | | } |
| | | Long userid = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserClient.getSysUser(userid).getData(); |
| | | Map<String, Map<Integer, BigDecimal>> dailyVipCommissions = new TreeMap<>(); |
| | | getDatesBetween(cd.getStartTime(), cd.getEndTime()).forEach(date -> { |
| | | for (int i = 1; i < 8; i++){ |
| | | List<BalanceChangeRecord> list = balanceChangeRecordService.list(new LambdaQueryWrapper<BalanceChangeRecord>() |
| | | LambdaQueryWrapper<BalanceChangeRecord> queryWrapper = new LambdaQueryWrapper<BalanceChangeRecord>() |
| | | .between(BalanceChangeRecord::getCreateTime, date, date.plusDays(1)) |
| | | .eq(BalanceChangeRecord::getChangeType,4) |
| | | .eq(BalanceChangeRecord::getVipId, i)); |
| | | .eq(BalanceChangeRecord::getChangeType, 4) |
| | | .eq(BalanceChangeRecord::getVipId, i); |
| | | if(sysUser.getRoleType() == 2){ |
| | | Integer objectId = sysUser.getObjectId(); |
| | | List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getShopId, objectId).eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1)); |
| | | List<Long> appUserIds = list.stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | Set<Long> data = orderClient.getAppUserByShoppingShop(objectId).getData(); |
| | | if(null != data){ |
| | | appUserIds.addAll(data); |
| | | } |
| | | if(appUserIds.size() == 0){ |
| | | appUserIds.add(-1L); |
| | | } |
| | | queryWrapper.in(BalanceChangeRecord::getAppUserId, appUserIds); |
| | | } |
| | | List<BalanceChangeRecord> list = balanceChangeRecordService.list(queryWrapper); |
| | | BigDecimal reduce = list.stream().map(BalanceChangeRecord::getChangeAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | String dateKey = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | dailyVipCommissions.computeIfAbsent(dateKey, k -> new HashMap<>()) |
| | |
| | | } |
| | | |
| | | for (int i = 1; i < 4; i++){ |
| | | R<List<ShopBalanceStatement>> r = shopBalanceStatementClient.getShopBalanceStatementList2(i, date); |
| | | Integer objectId = 0; |
| | | if(sysUser.getRoleType() == 2){ |
| | | objectId = sysUser.getObjectId(); |
| | | } |
| | | R<List<ShopBalanceStatement>> r = shopBalanceStatementClient.getShopBalanceStatementList2(i, objectId, date); |
| | | if (!CollectionUtils.isEmpty(r.getData())){ |
| | | List<ShopBalanceStatement> list = r.getData(); |
| | | BigDecimal reduce = list.stream().map(ShopBalanceStatement::getVariableAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | |
| | | } |
| | | } |
| | | }); |
| | | Integer objectId = 0; |
| | | if(sysUser.getRoleType() == 2){ |
| | | objectId = sysUser.getObjectId(); |
| | | } |
| | | |
| | | |
| | | R<Map<String, BigDecimal>> shopStatistics = shopClient.getShopStatistics(); |
| | | R<Map<String, BigDecimal>> shopStatistics = shopClient.getShopStatistics(objectId); |
| | | Map<String, BigDecimal> data = shopStatistics.getData(); |
| | | BigDecimal totalServiceFee = BigDecimal.ZERO; |
| | | BigDecimal totalUserCommission = BigDecimal.ZERO; |
| | |
| | | totalPartnerCommission = totalPartnerCommission.add(dailyCommissions.getOrDefault(7, BigDecimal.ZERO)); |
| | | |
| | | // 用户分销总金额 |
| | | |
| | | BigDecimal add = commissionDate.getNormalCommission().add(commissionDate.getGoldCommission()).add(commissionDate.getDiamondCommission()).add(commissionDate.getAgentCommission()) |
| | | .add(commissionDate.getSuperAgentCommission()).add(commissionDate.getTopAgentCommission()).add(commissionDate.getPartnerCommission()); |
| | | commissionDate.setTotalCommission(add); |