| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | return R.ok(page); |
| | | |
| | | |
| | | } |
| | | |
| | | @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 = {"小程序-个人中心"}) |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | private BigDecimal defaultBalance(BigDecimal balance) { |
| | | return balance == null ? BigDecimal.ZERO : balance; |
| | | } |
| | | |
| | | } |