| | |
| | | import com.ruoyi.other.api.domain.*; |
| | | import com.ruoyi.other.api.domain.TCoupon; |
| | | import com.ruoyi.other.api.domain.TVip; |
| | | import com.ruoyi.other.api.dto.ExchangeCodeBindDTO; |
| | | import com.ruoyi.other.api.dto.ExchangeCodeUseRecordQuery; |
| | | import com.ruoyi.other.api.dto.UnitListQueryDto; |
| | | import com.ruoyi.other.api.feignClient.IntegralRuleClient; |
| | | import com.ruoyi.other.api.feignClient.OtherClient; |
| | | import com.ruoyi.other.api.vo.ExchangeCodeBindResultVO; |
| | | import com.ruoyi.other.api.domain.TExchangeCodeUseRecord; |
| | | import com.ruoyi.other.api.feignClient.VipClient; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import com.ruoyi.system.api.model.LoginUserApplet; |
| | |
| | | if (page.getRecords().isEmpty()){ |
| | | return R.ok(page); |
| | | } |
| | | List<Long> pageUserIds = page.getRecords().stream().map(TAppUser::getId).collect(Collectors.toList()); |
| | | Map<Long, BigDecimal> exchangeCodeBalanceMap = otherClient.getExchangeCodeBalanceMap(pageUserIds).getData(); |
| | | if (exchangeCodeBalanceMap == null) { |
| | | exchangeCodeBalanceMap = new HashMap<>(); |
| | | } |
| | | List<Integer> vipIds = new ArrayList<>(); |
| | | // vipIds = page.getRecords().stream().map(TAppUser::getVipId).collect(Collectors.toList()); |
| | | //获取会员map |
| | | R<Map<Integer, String>> vipMap = otherClient.getVipMap(vipIds); |
| | | //循环处理 |
| | | for (TAppUser appUser : page.getRecords()) { |
| | | appUser.setExchangeCodeBalance(exchangeCodeBalanceMap.getOrDefault(appUser.getId(), BigDecimal.ZERO)); |
| | | //拿到最新的tagId |
| | | TAppUserTag one = appUserTagService.lambdaQuery().eq(TAppUserTag::getAppUserId, appUser.getId()).orderByDesc(TAppUserTag::getCreateTime).last("limit 1").one(); |
| | | if (one!=null) { |
| | |
| | | } |
| | | |
| | | return R.ok(page); |
| | | |
| | | |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/appUser/select", "/vipList/select"}, logical = Logical.OR) |
| | | @ApiOperation(value = "用户详情余额明细", tags = {"后台-用户管理-用户列表"}) |
| | | @PostMapping(value = "/user/balance/page") |
| | | public R<Page<TExchangeCodeUseRecord>> adminBalanceDetail(@RequestBody ExchangeCodeUseRecordQuery queryDto) { |
| | | return otherClient.exchangeCodeUseRecordPage(queryDto); |
| | | } |
| | | |
| | | @ApiOperation(value = "余额明细", tags = {"小程序-个人中心"}) |
| | | @PostMapping(value = "/user/balance/page1") |
| | | public R<Page<TExchangeCodeUseRecord>> balanceDetail(@RequestBody ExchangeCodeUseRecordQuery queryDto) { |
| | | if (queryDto.getUserId() == null) { |
| | | queryDto.setUserId(tokenService.getLoginUserApplet().getUserId()); |
| | | } |
| | | return otherClient.exchangeCodeUseRecordPage(queryDto); |
| | | } |
| | | |
| | | @ApiOperation(value = "余额明细详情", tags = {"小程序-个人中心"}) |
| | | @GetMapping(value = "/user/balance/detail") |
| | | public R<TExchangeCodeUseRecord> balanceDetail(@RequestParam("id") Long id) { |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | return otherClient.exchangeCodeUseRecordDetail(id, userId); |
| | | } |
| | | |
| | | @ApiOperation(value = "兑换余额", tags = {"小程序-个人中心"}) |
| | | @PostMapping(value = "/user/balance/exchange") |
| | | public R<BigDecimal> exchangeBalance(@RequestBody ExchangeCodeBindDTO dto) { |
| | | LoginUserApplet loginUser = tokenService.getLoginUserApplet(); |
| | | TAppUser appUser = appUserService.getById(loginUser.getUserId()); |
| | | R<ExchangeCodeBindResultVO> bindResult = otherClient.bindExchangeCode(dto, appUser.getId(), appUser.getPhone()); |
| | | if (bindResult.getData() == null) { |
| | | return R.fail(bindResult.getMsg()); |
| | | } |
| | | Map<Long, BigDecimal> balanceMap = otherClient.getExchangeCodeBalanceMap(Collections.singletonList(appUser.getId())).getData(); |
| | | BigDecimal totalExchangeBalance = balanceMap == null ? BigDecimal.ZERO : balanceMap.getOrDefault(appUser.getId(), BigDecimal.ZERO); |
| | | BigDecimal oldBalance = defaultBalance(appUser.getBalance()); |
| | | BigDecimal exchangeAmount = totalExchangeBalance.subtract(oldBalance); |
| | | if (exchangeAmount.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return R.fail("兑换金额异常"); |
| | | } |
| | | BigDecimal newBalance = oldBalance.add(exchangeAmount); |
| | | appUser.setBalance(newBalance); |
| | | appUserService.updateById(appUser); |
| | | |
| | | return R.ok(exchangeAmount); |
| | | } |
| | | |
| | | @ApiOperation(value = "积分详情", tags = {"小程序-个人中心"}) |
| | |
| | | appUserInfoDto.setUserCars(list); |
| | | appUserInfoDto.setFirstAdd(byId.getFirstAdd()!=null?byId.getFirstAdd():0); |
| | | appUserInfoDto.setPoints(byId.getPoints()==null?0:byId.getPoints()); |
| | | appUserInfoDto.setBalance(byId.getBalance()==null?BigDecimal.ZERO:byId.getBalance()); |
| | | return R.ok(appUserInfoDto); |
| | | } |
| | | |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | private BigDecimal defaultBalance(BigDecimal balance) { |
| | | return balance == null ? BigDecimal.ZERO : balance; |
| | | } |
| | | |
| | | } |
| | | |