From fd7b8fb7c89832c28a838b0449bbb8a392433ee2 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期二, 22 四月 2025 14:33:02 +0800 Subject: [PATCH] 将华为云短信替换成阿里云短信 --- ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java | 1905 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 1,440 insertions(+), 465 deletions(-) diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java index ce599a6..69105c6 100644 --- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java @@ -1,50 +1,63 @@ package com.ruoyi.account.controller; +import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -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.api.model.UserSignRecord; -import com.ruoyi.account.service.AppUserService; -import com.ruoyi.account.service.UserCancellationLogService; -import com.ruoyi.account.service.UserCouponService; -import com.ruoyi.account.service.UserSignRecordService; +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; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.account.api.model.*; import com.ruoyi.account.dto.DangerInfoDto; +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.bean.BeanUtils; -import com.ruoyi.common.core.web.domain.AjaxResult; +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.domain.ShopBalanceStatement; import com.ruoyi.other.api.domain.VipSetting; +import com.ruoyi.other.api.feignClient.ShopBalanceStatementClient; import com.ruoyi.other.api.feignClient.ShopClient; -import com.ruoyi.other.api.feignClient.StoreClient; import com.ruoyi.other.api.feignClient.VipSettingClient; +import com.ruoyi.system.api.domain.SysUser; +import com.ruoyi.system.api.feignClient.SysUserClient; +import com.ruoyi.system.api.model.LoginUser; import io.swagger.annotations.*; -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 lombok.extern.slf4j.Slf4j; +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 java.io.IOException; +import java.math.BigDecimal; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; - -import com.ruoyi.account.vo.*; -import com.ruoyi.common.core.web.controller.BaseController; -import com.ruoyi.common.core.web.page.TableDataInfo; -import org.springframework.web.bind.annotation.*; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * <p> - * 前端控制器 + * 前端控制器 * </p> * * @author luodangjia @@ -53,481 +66,1443 @@ @Api(tags = {"登录注册-小程序"}) @RestController @RequestMapping("/app-user") +@Slf4j public class AppUserController extends BaseController { + + @Resource + private TokenService tokenService; + @Resource + private AppUserService appUserService; + @Resource + private UserCouponService userCouponService; + + @Resource + private UserSignRecordService userSignRecordService; + @Resource + private VipSettingClient vipSettingClient; + @Resource + private UserPointService userPointService; + @Resource + private AppUserMapper appUserMapper; + @Resource + private ShopClient shopClient; + @Resource + private RemoteOrderGoodsClient remoteOrderGoodsClient; + @Resource + private SysUserClient sysUserClient; + @Resource + private OrderClient orderClient; + @Resource + private ShopBalanceStatementClient shopBalanceStatementClient; + @Resource + private UserCancellationLogService userCancellationLogService; + @Resource + private BalanceChangeRecordService balanceChangeRecordService; + @Resource + private BalanceChangeRecordCopyService balanceChangeRecordCopyService; + @Resource + private UserChangeLogService userChangeLogService; + @Resource + private RedisService redisService; + + @Resource + private WeChatUtil weChatUtil; + + @Resource + private IAppUserGiveawayTemporaryService appUserGiveawayTemporaryService; + + @Value("${file.upload.location}") + private String filePath; + + + @ResponseBody + @PostMapping("/mobileLogin") + @ApiOperation(value = "手机号登录") + public R<LoginVo> mobileLogin(@RequestBody MobileLogin mobileLogin) { + return appUserService.mobileLogin(mobileLogin); + } + + + @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("/getTopUsers") + public R<List<AppUser>> getTopUsers(@RequestBody AppUser appUser) { + List<Integer> vipIds = new ArrayList<>(); + vipIds.add(5); + vipIds.add(6); + vipIds.add(7); + List<AppUser> list = appUserService.lambdaQuery().in(AppUser::getVipId, vipIds).list(); + return R.ok(list); + + } + + @ResponseBody + @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){ + chainWrapper.eq(UserCoupon::getAppUserId, userId); + } + Long count = chainWrapper.count(); + return R.ok(count); + } + + @ResponseBody + @PostMapping("/getVipCount") + public R<Long> getVipCount(@RequestParam("userId") Long userId, @RequestParam("vipId") Integer vipId) { + Long count = 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 R<PageInfo<NearbyReferrerVo>> getNearbyReferrer(NearbyReferrer nearbyReferrer) { + return R.ok(appUserService.getNearbyReferrer(nearbyReferrer)); + } + + + @ResponseBody + @PostMapping("/info") + @ApiOperation(value = "我的资料", tags = {"小程序-个人中心首页-我的资料"}) + public R<AppUser> info() { + 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); + } + return R.ok(user); + } - @Resource - private TokenService tokenService; - @Resource - private AppUserService appUserService; - @Resource - private StoreClient storeClient; - @Resource - private UserCouponService userCouponService; + @ResponseBody + @GetMapping("/unregis") + @ApiOperation(value = "注销", tags = {"小程序-个人中心首页-我的资料"}) + public R unregis() { + Long userId = tokenService.getLoginUserApplet().getUserid(); + AppUser user = appUserService.getById(userId); - @Resource - private UserSignRecordService userSignRecordService; - @Resource - private VipSettingClient vipSettingClient; - @Resource - private UserPointService userPointService; - @Resource - private VipSettingService vipSettingService; + //添加注销记录 + UserCancellationLog userCancellationLog = new UserCancellationLog(); + userCancellationLog.setAppUserId(user.getId()); + userCancellationLog.setVipId(user.getVipId()); + userCancellationLogService.save(userCancellationLog); + user.setStatus(3); + appUserService.updateById(user); + + List<AppUser> subUserList = appUserService.list(new LambdaQueryWrapper<AppUser>() + .eq(AppUser::getInviteUserId, userId)); + for (AppUser appUser : subUserList) { + Long inviteUserId = user.getInviteUserId(); + appUser.setInviteUserId(inviteUserId); + } + appUserService.updateBatchById(subUserList); + return R.ok(); + } - @ResponseBody - @PostMapping("/mobileLogin") - @ApiOperation(value = "手机号登录") - public R<LoginVo> mobileLogin(@RequestBody MobileLogin mobileLogin){ - return appUserService.mobileLogin(mobileLogin); - } - - - - - - - @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(@RequestBody AppUser appUser) { - appUserService.updateById(appUser); - return R.ok(); - - } - - @ResponseBody - @PostMapping("/getTopUsers") - public R<List<AppUser>> getTopUsers(@RequestBody AppUser appUser) { - List<Integer> vipIds = new ArrayList<>(); - vipIds.add(5); - vipIds.add(6); - vipIds.add(7); - List<AppUser> list = appUserService.lambdaQuery().in(AppUser::getVipId, vipIds).list(); - return R.ok(list); - - } - - @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 ){ - Long count = 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 - @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()); - userCancellationLog.setVipId(user.getVipId()); - userCancellationLogService.save(userCancellationLog); - - - return R.ok(); - } - - - - @ResponseBody - @GetMapping("/recommend") - @ApiOperation(value = "推广中心", tags = {"小程序-推广中心"}) - public R<AppUser> recommend(){ - Long userId = tokenService.getLoginUserApplet().getUserid(); - //获取绑定门店 - AppUser user = appUserService.getById(userId); - if (user.getShopId()!=null){ - R<Shop> storeById = storeClient.getStoreById(user.getShopId()); - if (storeById.getData()!=null){ - user.setShopName(storeById.getData().getName()); - user.setShopCover(storeById.getData().getHomePicture()); - user.setShopAddress(storeById.getData().getAddress()); - } - } - - //获取绑定上级 - if (user.getInviteUserId()!=null) { - AppUser byId = appUserService.getById(user.getInviteUserId()); - user.setTopUser(byId); - } - //获取绑定下级列表 - List<AppUser> list = appUserService.lambdaQuery().eq(AppUser::getInviteUserId, user.getInviteUserId()).list(); - for (AppUser appUser : list) { - 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(); - appUser.setCount1(count1); - appUser.setCount2(count2); - appUser.setCount3(count3); - appUser.setCount4(count4); - appUser.setCount5(count5); - appUser.setCount6(count6); - appUser.setCount7(count7); - } - user.setBottomUsers(list); - - return R.ok(user); - } - - @ResponseBody - @GetMapping("/change") - @ApiOperation(value = "推广中心", tags = {"小程序-推广中心"}) - public R<AppUser> change(@ApiParam("换绑用户手机号") String phone){ - Long userId1 = tokenService.getLoginUserApplet().getUserid(); - AppUser byId = appUserService.getById(userId1); + @ResponseBody + @GetMapping("/recommend") + @ApiOperation(value = "推广中心", tags = {"小程序-推广中心"}) + public R<AppUser> recommend() { + Long userId = tokenService.getLoginUserApplet().getUserid(); //获取绑定门店 - AppUser user = appUserService.lambdaQuery().eq(AppUser::getPhone,phone).one(); - if (user==null){ - return R.fail("当前手机号未注册"); - } - byId.setInviteUserId(user.getId()); - appUserService.updateById(byId); - return R.ok(); - } + AppUser user = appUserService.getById(userId); + + //当前用户的推荐人信息(指导老师) + List<AppUser> allSuperiors = getAllSuperiors(userId); + //当前绑定门店的店铺信息 + for (AppUser allSuperior : allSuperiors) { + List<Shop> shopList = shopClient.getShopByUserId(allSuperior.getId()).getData(); + if (!CollectionUtils.isEmpty(shopList)){ + user.setShopName(shopList.get(0).getName()); + user.setShopCover(shopList.get(0).getHomePicture()); + user.setShopAddress(shopList.get(0).getAddress()); + break; + } + } + + if (user.getShopName() == null){ + user.setShopName(""); + } + if (user.getShopCover() == null){ + user.setShopCover(""); + } + if (user.getShopAddress() == null){ + user.setShopAddress(""); + } + + //指导老师 + allSuperiors.stream() + .filter(superiors -> superiors.getVipId() != null && superiors.getVipId() > 3) + .findFirst() + .ifPresent(superiors -> { + user.setTeacher(superiors.getName()); + user.setTeacherPhone(superiors.getPhone()); + }); + + if (user.getTeacher() == null){ + user.setTeacher(""); + } + if (user.getTeacherPhone() == null){ + user.setTeacherPhone(""); + } + + + + + //获取绑定上级 + if (user.getInviteUserId() != null) { + AppUser byId = appUserService.getById(user.getInviteUserId()); + if(null != byId){ + user.setTopUser(byId); + }else{ + user.setTopUser(new AppUser()); + } + }else { + AppUser topUser = new AppUser(); + user.setTopUser(topUser); + } + //获取绑定下级列表 + List<AppUser> list = appUserService.lambdaQuery() + .eq(AppUser::getInviteUserId, user.getId()) + .eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3) + .list(); + + Long vip1Count1 =0L; + Long vip1Count2 =0L; + Long vip1Count3 =0L; + Long vip1Count4 =0L; + Long vip1Count5 =0L; + Long vip1Count6 =0L; + Long vip1Count7 =0L; + for (AppUser appUser : list) { + if (appUser.getVipId() == 1){ + vip1Count1++; + } + if (appUser.getVipId() == 2){ + vip1Count2++; + } + if (appUser.getVipId() == 3){ + vip1Count3++; + } + if (appUser.getVipId() == 4){ + vip1Count4++; + } + if (appUser.getVipId() == 5){ + vip1Count5++; + } + if (appUser.getVipId() == 6){ + vip1Count6++; + } + if (appUser.getVipId() == 7){ + vip1Count7++; + } + + Long count1 = appUserService.lambdaQuery() + .eq(AppUser::getVipId, 1) + .eq(AppUser::getInviteUserId, appUser.getId()) + .eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3) + .count(); + + Long count2 = appUserService.lambdaQuery() + .eq(AppUser::getVipId, 2) + .eq(AppUser::getInviteUserId, appUser.getId()) + .eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3) + .count(); + Long count3 = appUserService.lambdaQuery() + .eq(AppUser::getVipId, 3) + .eq(AppUser::getInviteUserId, appUser.getId()) + .eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3) + .count(); + Long count4 = appUserService.lambdaQuery() + .eq(AppUser::getVipId, 4) + .eq(AppUser::getInviteUserId, appUser.getId()) + .eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3) + .count(); + Long count5 = appUserService.lambdaQuery() + .eq(AppUser::getVipId, 5) + .eq(AppUser::getInviteUserId, appUser.getId()) + .eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3) + .count(); + Long count6 = appUserService.lambdaQuery() + .eq(AppUser::getVipId, 6) + .eq(AppUser::getInviteUserId, appUser.getId()) + .eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3) + .count(); + Long count7 = appUserService.lambdaQuery() + .eq(AppUser::getVipId, 7) + .eq(AppUser::getInviteUserId, appUser.getId()) + .eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3) + .count(); + appUser.setCount1(count1); + appUser.setCount2(count2); + appUser.setCount3(count3); + appUser.setCount4(count4); + appUser.setCount5(count5); + appUser.setCount6(count6); + appUser.setCount7(count7); + } + + user.setBottomUsers(list); + user.setCount1(vip1Count1); + user.setCount2(vip1Count2); + user.setCount3(vip1Count3); + user.setCount4(vip1Count4); + user.setCount5(vip1Count5); + user.setCount6(vip1Count6); + user.setCount7(vip1Count7); + return R.ok(user); + } + + @ResponseBody + @GetMapping("/change") + @ApiOperation(value = "推广中心", tags = {"小程序-推广中心"}) + 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) + .eq(AppUser::getDelFlag, 0) + .eq(AppUser::getStatus, 1) + .one(); + + + // 获取当前用户的所有下级 + List<AppUser> allSubordinates = getAllSubordinates(byId.getId()); + long count = allSubordinates.stream().filter(appUser -> appUser.getId().equals(user.getId())).count(); + if (count > 0) { + return R.fail("绑定关系已存在!"); + } + + if (user == null) { + return R.fail("当前手机号未注册"); + } + + Long userId = user.getId(); + if (userId.equals(byId.getId())) { + return R.fail("不能选择自己为绑定人。"); + } + + byId.setInviteUserId(user.getId()); + appUserService.updateById(byId); + return R.ok(); + } @GetMapping("/index") - @ApiOperation(value = "个人中心首页", tags = {"小程序-个人中心首页"}) - public R<AppUser> index(){ - System.err.println("=-===="); + @ApiOperation(value = "个人中心首页", tags = {"小程序-个人中心首页"}) + public R<AppUser> index() { 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); + //当前用户信息 + 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); + } + + //指导老师 + List<AppUser> allSuperiors = getAllSuperiors(userId); + allSuperiors.stream() + .filter(superiors -> superiors.getVipId() != null && superiors.getVipId() > 3) + .findFirst() + .ifPresent(superiors -> { + user.setTeacher(superiors.getName()); + }); + + Shop shop1 = shopClient.getServiceProvider(userId).getData(); + if(null != shop1){ + user.setShopName(shop1.getName()); + user.setShopId(shop1.getId()); + } - List<UserSignRecord> list = userSignRecordService.lambdaQuery().eq(UserSignRecord::getSignDay, LocalDate.now()).list(); - if (!list.isEmpty()){ + ArrayList<Long> userIds = new ArrayList<>(); + userIds.add(userId); + // 获取当前用户的所有下级 + List<AppUser> allSubordinates = appUserService.list(new LambdaQueryWrapper<AppUser>() + .eq(AppUser::getInviteUserId, user.getId()).eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3)); + Long count1 = allSubordinates.stream().filter(s->s.getVipId() == 1).count(); + user.setCount1(count1); + Long count2 = allSubordinates.stream().filter(s->s.getVipId() == 2).count(); + user.setCount2(count2); + Long count3 = allSubordinates.stream().filter(s->s.getVipId() == 3).count(); + user.setCount3(count3); + Long count4 = allSubordinates.stream().filter(s->s.getVipId() == 4).count(); + user.setCount4(count4); + Long count5 = allSubordinates.stream().filter(s->s.getVipId() == 5).count(); + user.setCount5(count5); + Long count6 = allSubordinates.stream().filter(s->s.getVipId() == 6).count(); + user.setCount6(count6); + Long count7 = allSubordinates.stream().filter(s->s.getVipId() == 7).count(); + user.setCount7(count7); + List<UserSignRecord> list = userSignRecordService.lambdaQuery().eq(UserSignRecord::getSignDay, LocalDate.now()) + .eq(UserSignRecord::getAppUserId,userId).list(); + if (!list.isEmpty()) { user.setIsSign(1); - }else { + } else { user.setIsSign(0); } - return R.ok(user); + + List<AppUserGiveawayTemporary> temporaryList = appUserGiveawayTemporaryService.list(new LambdaQueryWrapper<AppUserGiveawayTemporary>() + .eq(AppUserGiveawayTemporary::getAppUserId, userId)); + + user.setLavePoint(temporaryList.stream().mapToInt(AppUserGiveawayTemporary::getTotalPoint).sum() + user.getTotalPoint()); + return R.ok(user); + } - } + public List<AppUser> getAllSuperiors(Long userId) { + List<AppUser> allSuperiors = new ArrayList<>(); - @GetMapping("/index/change") - @ApiOperation(value = "修改个人资料", tags = {"小程序-个人中心首页"}) - public R<AppUser> indexchange(String avatar,String name){ - Long userId = tokenService.getLoginUserApplet().getUserid(); - //当前用户信息 - AppUser user = appUserService.getById(userId); - user.setName(name); - user.setAvatar(avatar); - appUserService.updateById(user); - return R.ok(); - } - /** - * 获取用户的祖籍列表 - */ - @GetMapping("/getUserAncestorList") - public R<List<AppUser>> getUserAncestorList(Long id){ - List<AppUser> list = appUserService.getUserAncestorList(id,null); - return R.ok(list); - } + // 获取当前用户的直接上级 + AppUser currentUser = appUserService.getById(userId); + if (currentUser != null && currentUser.getInviteUserId() != null) { + AppUser superior = appUserService.getById(currentUser.getInviteUserId()); + if (superior != null) { + allSuperiors.add(superior); // 添加直接上级 + allSuperiors.addAll(getAllSuperiors(superior.getId())); // 递归添加上级的上级 + } + } - /** - * 获取用户的直帮上级用户 - */ - @ResponseBody - @PostMapping("/getSuperiorLeader") - @ApiOperation(value = "获取用户的直帮上级用户") - public R<AppUser> getSuperiorLeader(@RequestParam("id") Long id) { - AppUser superiorLeader = appUserService.getSuperiorLeader(id); - return R.ok(superiorLeader); - } - - - - @ResponseBody - @PostMapping("/onlineRecord") - @ApiOperation(value = "10分钟定时任务调用,记录用户在线时长", tags = {"小程序-个人中心首页"}) - public R onlineRecord(){ - appUserService.onlineRecord(); - 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); - } - - /** - * 根据用户电话模糊搜索用户列表 - * @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("/getAppuserPage") - @ApiOperation(value = "用户列表", tags = {"管理后台"}) - public R<IPage<AppUser>> getAppuserPage(@ApiParam("页码") @RequestParam Integer pageNum, - @ApiParam("每一页数据大小") Integer pageSize, - AppUser appUser) - { - IPage<AppUser> appuserPage = appUserService.getAppuserPage(pageNum, pageSize, appUser); - return R.ok(appuserPage); - } - - @GetMapping("/danger/info") - @ApiOperation(value = "用户列表-保级条件详情", tags = {"管理后台"}) - public R<DangerInfoDto> dangerinfo(Long id) - { - AppUser byId = appUserService.getById(id); - LocalDate now = LocalDate.now(); - R<VipSetting> vipSetting = vipSettingClient.getVipSetting(byId.getVipId()); - VipSetting data = vipSetting.getData(); - DangerInfoDto dangerInfoDto = new DangerInfoDto(); - BeanUtils.copyProperties(data,dangerInfoDto); - List<UserPoint> list1 = userPointService.lambdaQuery().eq(UserPoint::getType,1).ge(UserPoint::getCreateTime, now.minusDays(data.getKeepBuyDay())).list(); - List<UserPoint> list2 = userPointService.lambdaQuery().eq(UserPoint::getType,2).ge(UserPoint::getCreateTime, now.minusDays(data.getKeepBuyDay())).list(); - List<UserPoint> list3 = userPointService.lambdaQuery().eq(UserPoint::getType,5).ge(UserPoint::getCreateTime, now.minusDays(data.getKeepBuyDay())).list(); - Integer userKeepBuyPoint = 0; - for (UserPoint userPoint : list1) { - userKeepBuyPoint = userPoint.getVariablePoint()+userKeepBuyPoint; - } - Integer userKeepSharePoint = 0; - for (UserPoint userPoint : list2) { - userKeepSharePoint = userPoint.getVariablePoint()+userKeepSharePoint; - } - Integer userKeepShopPoint = 0; - for (UserPoint userPoint : list3) { - userKeepShopPoint = userPoint.getVariablePoint()+userKeepShopPoint; - } - dangerInfoDto.setUserKeepBuyPoint(userKeepBuyPoint); - dangerInfoDto.setUserKeepSharePoint(userKeepSharePoint); - dangerInfoDto.setUserKeepShopPoint(userKeepShopPoint); - return R.ok(dangerInfoDto); - } + return allSuperiors; + } - @GetMapping("/danger/down") - @ApiOperation(value = "用户列表-保级条件降级", tags = {"管理后台"}) - public R down(Long id) - { - AppUser byId = appUserService.getById(id); - byId.setVipId(byId.getVipId()-1); - appUserService.updateById(byId); - //执行降级标记代码 - new Thread(new Runnable() { - @Override - public void run() { - { - vipSettingService.downUsers(); - } - } - } - ).start(); - return R.ok(); - } - @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); - return R.ok(); - } - @Resource - private ShopClient shopClient; - @Resource - private RemoteOrderGoodsClient remoteOrderGoodsClient; + + // 递归获取指定用户的所有下级 + public List<AppUser> getAllSubordinates(Long userId) { + List<AppUser> allSubordinates = new ArrayList<>(); - @GetMapping("/detail") - @ApiOperation(value = "用户列表-详情", tags = {"管理后台"}) - public R<AppUser> detail(Long id) - { - AppUser byId = appUserService.getById(id); - if (byId.getShopId()!=null) { - R<Shop> shopById = shopClient.getShopById(Integer.parseInt(String.valueOf(byId.getShopId()))); - if (shopById.getData()!=null) { - byId.setShopName(shopById.getData().getName()); - } - } - R<List<Shop>> shopByUserId = shopClient.getShopByUserId(id); - if (shopByUserId.getData()!=null) { - List<String> shopName = new ArrayList<>(); - for (Shop datum : shopByUserId.getData()) { - shopName.add(datum.getName()); - } - byId.setShopNames(shopName); - } - //推广人 - if (byId.getInviteUserId()!=null) { - AppUser byId1 = appUserService.getById(byId.getInviteUserId()); - byId1.setInviteUserName(byId1.getInviteUserName()); - } - //最后下单时间 - R<Order> lastOrder = remoteOrderGoodsClient.getLastOrder(id); - if (lastOrder.getData()!=null){ - byId.setLastOrderTime(lastOrder.getData().getCreateTime()); - } - return R.ok(byId); - } - @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)); - return R.ok(page); + List<AppUser> directChildren = appUserService.list(new LambdaQueryWrapper<AppUser>() + .eq(AppUser::getInviteUserId, userId)); - } + for (AppUser child : directChildren) { + allSubordinates.add(child); // 添加直接下级 + allSubordinates.addAll(getAllSubordinates(child.getId())); // 递归添加间接下级 + } + return allSubordinates; + } + + + /** + * 获取门店作为服务商的所有用户 + * @param shopId + * @return + */ + public Set<Long> getShopServerUser(Integer shopId){ + Shop shop = shopClient.getShopById(shopId).getData(); + List<Shop> shopList = shopClient.getAllShop().getData(); + List<Long> appUserIds = shopList.stream().map(Shop::getAppUserId).collect(Collectors.toList()); + Long appUserId = shop.getAppUserId(); + //所有未开店的用户 + List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3).notIn(AppUser::getId, appUserIds)); + Set<Long> ids = new HashSet<>(); + getShopServerUser(appUserId, list, ids); + return ids; + } + + + + public void getShopServerUser(Long appUserId, List<AppUser> appUserList, Set<Long> ids){ + List<AppUser> collect = appUserList.stream().filter(s->s.getInviteUserId().equals(appUserId)).collect(Collectors.toList()); + if(collect.size() == 0){ + return; + } + Set<Long> appUserSet = collect.stream().map(AppUser::getId).collect(Collectors.toSet()); + if(ids.containsAll(appUserSet)){ + return; + } + ids.addAll(appUserSet); + for (AppUser appUser : collect) { + getShopServerUser(appUser.getId(), appUserList, ids); + } + } + + + + @GetMapping("/index/change") + @ApiOperation(value = "修改个人资料", tags = {"小程序-个人中心首页"}) + public R<AppUser> indexchange(String avatar, String name) { + Long userId = tokenService.getLoginUserApplet().getUserid(); + //当前用户信息 + AppUser user = appUserService.getById(userId); + user.setName(name); + user.setAvatar(avatar); + appUserService.updateById(user); + return R.ok(); + } + + /** + * 获取用户的祖籍列表 + */ + @GetMapping("/getUserAncestorList") + public R<List<AppUser>> getUserAncestorList(Long id) { + List<AppUser> list = appUserService.getUserAncestorList(id, null); + return R.ok(list); + } + + /** + * 获取用户的直帮上级用户 + */ + @ResponseBody + @PostMapping("/getSuperiorLeader") + @ApiOperation(value = "获取用户的直帮上级用户") + public R<AppUser> getSuperiorLeader(@RequestParam("id") Long id) { + AppUser superiorLeader = appUserService.getSuperiorLeader(id); + return R.ok(superiorLeader); + } + + + @ResponseBody + @PostMapping("/onlineRecord") + @ApiOperation(value = "10分钟定时任务调用,记录用户在线时长", tags = {"小程序-个人中心首页"}) + public R onlineRecord() { + appUserService.onlineRecord(); + 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){ + + 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()) { + List<AppUserGiveawayTemporary> list = appUserGiveawayTemporaryService.list(new LambdaQueryWrapper<AppUserGiveawayTemporary>().eq(AppUserGiveawayTemporary::getAppUserId, record.getId())); + int sum = list.stream().mapToInt(AppUserGiveawayTemporary::getTotalPoint).sum(); + if (record.getInviteUserId() != null) { + AppUser byId1 = appUserService.getById(record.getInviteUserId()); + if (byId1!=null) { + record.setInviteUserName(byId1.getName()); + } + } + Shop shop1 = shopClient.getServiceProvider(record.getId()).getData(); + if(null != shop1){ + record.setShopName(shop1.getName()); + record.setShopId(shop1.getId()); + } + record.setTotalPoint(record.getUserTotalPoint() + sum); + } + 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()); + } + } + record.setTotalPoint(record.getUserTotalPoint()); + } + 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("/danger/info") + @ApiOperation(value = "用户列表-保级条件详情", tags = {"管理后台"}) + public R<DangerInfoDto> dangerinfo(Long id) { + AppUser byId = appUserService.getById(id); + LocalDate now = LocalDate.now(); + R<VipSetting> vipSetting = vipSettingClient.getVipSetting(byId.getVipId()); + VipSetting data = vipSetting.getData(); + DangerInfoDto dangerInfoDto = new DangerInfoDto(); + BeanUtils.copyProperties(data, dangerInfoDto); + List<UserPoint> list1 = userPointService.lambdaQuery().eq(UserPoint::getAppUserId,id).eq(UserPoint::getType, 1).ge(UserPoint::getCreateTime, now.minusDays(data.getKeepBuyDay())).list(); + List<UserPoint> list2 = userPointService.lambdaQuery().eq(UserPoint::getAppUserId,id).eq(UserPoint::getType, 2).ge(UserPoint::getCreateTime, now.minusDays(data.getKeepBuyDay())).list(); + List<UserPoint> list3 = userPointService.lambdaQuery().eq(UserPoint::getAppUserId,id).eq(UserPoint::getType, 8).ge(UserPoint::getCreateTime, now.minusDays(data.getKeepBuyDay())).list(); + Integer userKeepBuyPoint = 0; + for (UserPoint userPoint : list1) { + userKeepBuyPoint = userPoint.getVariablePoint() + userKeepBuyPoint; + } + Integer userKeepSharePoint = 0; + for (UserPoint userPoint : list2) { + userKeepSharePoint = userPoint.getVariablePoint() + userKeepSharePoint; + } + Integer userKeepShopPoint = 0; + for (UserPoint userPoint : list3) { + userKeepShopPoint = userPoint.getVariablePoint() + userKeepShopPoint; + } + dangerInfoDto.setUserKeepBuyPoint(userKeepBuyPoint); + dangerInfoDto.setUserKeepSharePoint(userKeepSharePoint); + dangerInfoDto.setUserKeepShopPoint(userKeepShopPoint); + return R.ok(dangerInfoDto); + } + + + @GetMapping("/danger/down") + @ApiOperation(value = "用户列表-保级条件降级", tags = {"管理后台"}) + public R down(Long id) { + AppUser appUser = appUserService.getById(id); + UserChangeLog userChangeLog = new UserChangeLog(); + userChangeLog.setDelFlag(0); + userChangeLog.setCreateTime(LocalDateTime.now()); + userChangeLog.setAppUserId(id); + userChangeLog.setBeforeVipId(appUser.getVipId()); + userChangeLog.setAfterVipId(appUser.getVipId() - 1); + userChangeLog.setChangeType(0); + userChangeLogService.save(userChangeLog); + appUser.setVipId(appUser.getVipId() - 1); + appUser.setIsDanger(0); + //检查是否达标,不达标继续标红 + VipSetting vipSetting = vipSettingClient.getVipSetting(appUser.getVipId()).getData(); + //消费积分 + List<UserPoint> list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 1).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepBuyDay() + " DAY) <= create_time")); + int sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum(); + if(sum < vipSetting.getKeepBuyPoint()){ + appUser.setIsDanger(1); + } + //返佣积分 + list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 2).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepShareDay() + " DAY) <= create_time")); + sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum(); + if(sum < vipSetting.getKeepSharePoint()){ + appUser.setIsDanger(1); + } + //门店业绩 + list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 8).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepShopDay() + " DAY) <= create_time")); + sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum(); + if(sum < vipSetting.getKeepShopPoint()){ + appUser.setIsDanger(1); + } + appUserService.updateById(appUser); + return R.ok(); + } + + @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("/select") + @ApiOperation(value = "用户列表-查询绑定人", tags = {"管理后台"}) + public R<AppUser> select(String phone) { + AppUser byId = appUserService.lambdaQuery() + .eq(AppUser::getPhone, phone) + .eq(AppUser::getDelFlag,0) + .eq(AppUser::getStatus,1) + .one(); + if (byId == null) { + return R.fail("搜索失败,手机号错误。"); + } + return R.ok(byId); + } + + @GetMapping("/change/bind") + @ApiOperation(value = "用户列表-更换绑定人", tags = {"管理后台"}) + public R<AppUser> select(Long id, Long inviteId) { + AppUser byId = appUserService.getById(id); + Long userId = byId.getId(); + 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); + return R.ok(); + } + + @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(); + } + + + public Long getTop(Long inviteId) { + AppUser byId = appUserService.getById(inviteId); + if (byId != null) { + return getTop(byId.getInviteUserId()); + } else { + return inviteId; + } + } + @GetMapping("/detail") + @ApiOperation(value = "用户列表-详情", tags = {"管理后台"}) + public R<AppUser> detail(Long id, Integer shopId) { + Long userid = tokenService.getLoginUser().getUserid(); + SysUser sysUser = sysUserClient.getSysUser(userid).getData(); + AppUser byId = appUserService.getById(id); + Shop shop1 = shopClient.getServiceProvider(byId.getId()).getData(); + if(null != shop1){ + byId.setShopName(shop1.getName()); + byId.setShopId(shop1.getId()); + } + R<List<Shop>> shopByUserId = shopClient.getShopByUserId(id); + if (shopByUserId.getData() != null) { + List<String> shopName = new ArrayList<>(); + for (Shop datum : shopByUserId.getData()) { + shopName.add(datum.getName()); + } + byId.setShopNames(shopName); + } + //推广人 + if (byId.getInviteUserId() != null) { + AppUser appUser = appUserService.getById(byId.getInviteUserId()); + if(null != appUser){ + byId.setInviteUserName(appUser.getName()); + } + } + //最后下单时间 + R<Order> lastOrder = remoteOrderGoodsClient.getLastOrder(id); + if (lastOrder.getData() != null) { + byId.setLastOrderTime(lastOrder.getData().getCreateTime()); + } + List<AppUser> list = appUserService.lambdaQuery().eq(AppUser::getInviteUserId, id).list(); + byId.setBottomUsers(list); + //消费总金额 + if(null == shopId || 1 == sysUser.getRoleType()){ + shopId = -1; + } + if(null == shopId && 2 == sysUser.getRoleType()){ + shopId = sysUser.getObjectId(); + } + R<List<Order>> orderR = remoteOrderGoodsClient.byUserId(id, shopId); + List<Order> orderList = orderR.getData(); + if (!CollectionUtils.isEmpty(orderList)){ + BigDecimal paymentAmount = orderList.stream().map(Order::getPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); + byId.setShopAmount(paymentAmount); + }else { + byId.setShopAmount(BigDecimal.ZERO); + } + 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); + } - @GetMapping("/listByIds") - List<AppUser> listByIds(List<String> list){ - return appUserService.listByIds(list); - } - - - - @PostMapping("/getAppUserByPhone1") - public R<AppUser> getAppUserByPhone1(@RequestParam("phone") String phone){ - AppUser appUser = appUserService.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1) - .eq(AppUser::getPhone, phone)); - return R.ok(appUser); - } + + + + + @GetMapping("/change/vip") + @ApiOperation(value = "用户列表-修改会员等级", tags = {"管理后台"}) + public R<Page<AppUser>> changevip(Long id, Integer vipId) { + AppUser byId = appUserService.getById(id); + + UserChangeLog userChangeLog = new UserChangeLog(); + userChangeLog.setCreateTime(LocalDateTime.now()); + userChangeLog.setAppUserId(byId.getId()); + userChangeLog.setBeforeVipId(byId.getVipId()); + userChangeLog.setAfterVipId(vipId); + if (userChangeLog.getBeforeVipId() > userChangeLog.getAfterVipId()) { + userChangeLog.setChangeType(0); + } else { + userChangeLog.setChangeType(1); + } + userChangeLogService.save(userChangeLog); + 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) + .eq(AppUser::getDelFlag, 0) + .eq(AppUser::getStatus, 1) + .page(Page.of(pageNum, pageSize)); + return R.ok(page); + + } + + @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); + } + + + /** + * 设置指定用户的下级用户绑定门店 + */ + @PostMapping("/setLowerUserShop") + public R<Void> setLowerUserShop(@RequestParam("userId") Long userId,@RequestParam("shopId") Integer shopId) { + appUserService.update(new LambdaUpdateWrapper<AppUser>() + .set(AppUser::getShopId,shopId) + .eq(AppUser::getInviteUserId, userId)); + return R.ok(); + } + + + /** + * 用户统计 + */ + @GetMapping("/statistics") + @ApiOperation(value = "用户统计", tags = {"管理后台-首页统计-用户统计"}) + public R<UserStatistics> statistics() { + 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); + if(userIds.size() == 0){ + userIds.add(-1L); + } + queryWrapper.in(!CollectionUtils.isEmpty(userIds), "id", userIds); // userIds 不为空时,查询 id 在 userIds 中 + } + 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); + } + + /** + * 用户统计详情 + */ + @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 = 0; + Set<Long> userIds = new HashSet<>(); + 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); + List<Order> orderList = orderClient.getOrderByAppUserIdsAndWriteOffShop(shopId, userIds).getData(); + BigDecimal shopAmount = orderList.stream().map(Order::getPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); + userStatisticsDetail.setShopAmount(shopAmount); + return R.ok(userStatisticsDetail); + } + + + /** + * 分佣统计明细 + */ + @GetMapping("/commissionDetail") + @ApiOperation(value = "分佣统计", tags = "管理后台-首页统计") + public R<CommissionDetail> commissionDetail(CommissionDetail cd) { + if (cd.getStartTime() == null || cd.getEndTime() == null) { + return R.fail("请选择时间"); + } + 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++){ + LambdaQueryWrapper<BalanceChangeRecord> queryWrapper = new LambdaQueryWrapper<BalanceChangeRecord>() + .between(BalanceChangeRecord::getCreateTime, date, date.plusDays(1)) + .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).ne(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); + for (BalanceChangeRecord balanceChangeRecord : list) { + balanceChangeRecord.setChangeAmount(balanceChangeRecord.getChangeAmount().multiply(new BigDecimal(balanceChangeRecord.getChangeDirection()))); + } + + LambdaQueryWrapper<BalanceChangeRecordCopy> queryWrapper1 = new LambdaQueryWrapper<BalanceChangeRecordCopy>() + .between(BalanceChangeRecordCopy::getCreateTime, date, date.plusDays(1)) + .eq(BalanceChangeRecordCopy::getChangeType, 4) + .eq(BalanceChangeRecordCopy::getVipId, i); + if(sysUser.getRoleType() == 2){ + Integer objectId = sysUser.getObjectId(); + List<AppUser> list1 = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getShopId, objectId).eq(AppUser::getDelFlag, 0).ne(AppUser::getStatus, 1)); + List<Long> appUserIds = list1.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); + } + queryWrapper1.in(BalanceChangeRecordCopy::getAppUserId, appUserIds); + } + List<BalanceChangeRecordCopy> list2 = balanceChangeRecordCopyService.list(queryWrapper1); + for (BalanceChangeRecordCopy balanceChangeRecordCopy : list2) { + BalanceChangeRecord balanceChangeRecord = new BalanceChangeRecord(); + BeanUtils.copyProperties(balanceChangeRecordCopy, balanceChangeRecord); + balanceChangeRecord.setChangeAmount(balanceChangeRecord.getChangeAmount().multiply(new BigDecimal(balanceChangeRecord.getChangeDirection()))); + list.add(balanceChangeRecord); + } + + 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<>()) + .merge(i, reduce, BigDecimal::add); + } + + for (int i = 1; i < 4; i++){ + 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); + String dateKey = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + int type; + if (i == 1){ + type = 8; + }else if (i == 2){ + type = 9; + }else { + type = 10; + } + dailyVipCommissions.computeIfAbsent(dateKey, k -> new HashMap<>()) + .merge(type, reduce, BigDecimal::add); + } + } + }); + Integer objectId = 0; + if(sysUser.getRoleType() == 2){ + objectId = sysUser.getObjectId(); + } + + R<Map<String, BigDecimal>> shopStatistics = shopClient.getShopStatistics(objectId); + Map<String, BigDecimal> data = shopStatistics.getData(); + BigDecimal totalServiceFee = BigDecimal.ZERO; + BigDecimal totalUserCommission = BigDecimal.ZERO; + if (data != null){ + totalServiceFee = data.get("serverGiveawayMoney"); + totalUserCommission = data.get("giveawayMoney"); + } + + BigDecimal totalCommission = BigDecimal.ZERO; + BigDecimal totalNormalCommission = BigDecimal.ZERO; + + BigDecimal totalGoldCommission = BigDecimal.ZERO; + + BigDecimal totalDiamondCommission = BigDecimal.ZERO; + + BigDecimal totalAgentCommission = BigDecimal.ZERO; + + BigDecimal totalSuperAgentCommission = BigDecimal.ZERO; + + BigDecimal totalTopAgentCommission = BigDecimal.ZERO; + + BigDecimal totalPartnerCommission = BigDecimal.ZERO; + + Set<String> keySet = dailyVipCommissions.keySet(); + List<CommissionDate> commissionDateList = new ArrayList<>(); + for (String key : keySet) { + CommissionDate commissionDate = new CommissionDate(); + commissionDate.setDate(key); + Map<Integer, BigDecimal> dailyCommissions = dailyVipCommissions.get(key); + commissionDate.setNormalCommission(dailyCommissions.getOrDefault(1, BigDecimal.ZERO)); + totalNormalCommission = totalNormalCommission.add(dailyCommissions.getOrDefault(1, BigDecimal.ZERO)); + + commissionDate.setGoldCommission(dailyCommissions.getOrDefault(2, BigDecimal.ZERO)); + totalGoldCommission = totalGoldCommission.add(dailyCommissions.getOrDefault(2, BigDecimal.ZERO)); + + commissionDate.setDiamondCommission(dailyCommissions.getOrDefault(3, BigDecimal.ZERO)); + totalDiamondCommission = totalDiamondCommission.add(dailyCommissions.getOrDefault(3, BigDecimal.ZERO)); + + commissionDate.setAgentCommission(dailyCommissions.getOrDefault(4, BigDecimal.ZERO)); + totalAgentCommission = totalAgentCommission.add(dailyCommissions.getOrDefault(4, BigDecimal.ZERO)); + + commissionDate.setSuperAgentCommission(dailyCommissions.getOrDefault(5, BigDecimal.ZERO)); + totalSuperAgentCommission = totalSuperAgentCommission.add(dailyCommissions.getOrDefault(5, BigDecimal.ZERO)); + + commissionDate.setTopAgentCommission(dailyCommissions.getOrDefault(6, BigDecimal.ZERO)); + totalTopAgentCommission = totalTopAgentCommission.add(dailyCommissions.getOrDefault(6, BigDecimal.ZERO)); + + commissionDate.setPartnerCommission(dailyCommissions.getOrDefault(7, 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); + + commissionDate.setServiceChargeCommission(dailyCommissions.getOrDefault(10, BigDecimal.ZERO)); + commissionDate.setAssociatedUserCommission(dailyCommissions.getOrDefault(8, BigDecimal.ZERO)); + commissionDate.setBindLowerLevelStoresCommission(dailyCommissions.getOrDefault(9, BigDecimal.ZERO)); + commissionDateList.add(commissionDate); + } + + + + CommissionDetail commissionDetail = new CommissionDetail(); + commissionDetail.setTotalServiceFee(totalServiceFee); + commissionDetail.setTotalUserCommission(totalUserCommission); + commissionDetail.setTotalNormalCommission(totalNormalCommission); + commissionDetail.setTotalGoldCommission(totalGoldCommission); + commissionDetail.setTotalDiamondCommission(totalDiamondCommission); + commissionDetail.setTotalAgentCommission(totalAgentCommission); + commissionDetail.setTotalSuperAgentCommission(totalSuperAgentCommission); + commissionDetail.setTotalTopAgentCommission(totalTopAgentCommission); + commissionDetail.setTotalPartnerCommission(totalPartnerCommission); + totalCommission = totalNormalCommission.add(totalGoldCommission).add(totalDiamondCommission).add(totalAgentCommission) + .add(totalSuperAgentCommission).add(totalTopAgentCommission).add(totalPartnerCommission); + commissionDetail.setTotalCommission(totalCommission); + commissionDetail.setCommissionDateList(commissionDateList); + + return R.ok(commissionDetail); + } + + + /** + * 获取指定时间段内每一天的列表 + * + * @param startDate 开始日期时间 + * @param endDate 结束日期时间 + * @return 包含每天日期时间的列表 + */ + private static List<LocalDateTime> getDatesBetween(LocalDateTime startDate, LocalDateTime endDate) { + // 计算开始日期和结束日期之间的天数差(忽略时间部分) + long daysBetween = ChronoUnit.DAYS.between(startDate.toLocalDate(), endDate.toLocalDate()); + + // 使用Stream.iterate从开始日期开始迭代,每次增加一天,直到达到天数差+1 + return Stream.iterate(startDate, date -> date.plus(1, ChronoUnit.DAYS)) + .limit(daysBetween + 1) + .collect(Collectors.toList()); + } + + + + /** + * 上传图片 + * @param file + * @return + */ + @PostMapping("/upload") + public String upload(MultipartFile file){ + String s = null; + try { + s = ObsUploadUtil.obsUpload(file); + } catch (IOException e) { + throw new RuntimeException(e); + } + return s; + } + + + /** + * 检查会员等级变更 + * @param appUserId + */ + @PostMapping("/vipUpgrade") + public void vipUpgrade(@RequestParam("appUserId") Long appUserId){ + appUserService.vipUpgrade(appUserId); + } + + @PostMapping("/vipConsumption") + public void vipConsumption(@RequestParam("appUserId") Long appUserId){ + appUserService.vipConsumption(appUserId); + } + + /** + * 检查会员降级 + * @param appUserId + */ + @PostMapping("/vipDemotion") + public void vipDemotion(@RequestParam("appUserId") Long appUserId){ + appUserService.vipDemotion(appUserId); + } + + + + /** + * 用户降级检测 + */ + @PostMapping("/demotionDetection") + public void demotionDetection(){ + appUserService.demotionDetection(); + } + + + /** + * 清空绑定门店的用户门店数据 + * @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(); + } } -- Gitblit v1.7.1