| | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.BalanceChangeRecord; |
| | | import com.ruoyi.account.api.model.BalanceChangeRecordCopy; |
| | | import com.ruoyi.account.api.model.BalancePayment; |
| | | import com.ruoyi.account.service.*; |
| | | import com.ruoyi.account.util.payment.PaymentUtil; |
| | | import com.ruoyi.account.util.payment.model.UniPayCallbackResult; |
| | | import com.ruoyi.account.util.payment.model.UniPayResult; |
| | | import com.ruoyi.account.vo.UserPointDetailVO; |
| | | import com.ruoyi.account.vo.WalletVO; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.controller.BaseController; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.order.feignClient.RemoteOrderGoodsClient; |
| | | import com.ruoyi.order.model.Order; |
| | | import com.ruoyi.other.api.domain.BaseSetting; |
| | | import com.ruoyi.other.api.domain.VipSetting; |
| | | import com.ruoyi.other.api.feignClient.BaseSettingClient; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | @Resource |
| | | private BalanceChangeRecordService balanceChangeRecordService; |
| | | @Resource |
| | | private BalanceChangeRecordCopyService balanceChangeRecordCopyService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private WalletService walletService; |
| | |
| | | private BalancePaymentService balancePaymentService; |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | @Resource |
| | | private BaseSettingClient baseSettingClient; |
| | | |
| | | |
| | | |
| | |
| | | */ |
| | | @ApiOperation(value = "变更明细", notes = "变更明细") |
| | | @GetMapping("change") |
| | | public R<List<BalanceChangeRecord>> change(@ApiParam(value = "变更类型") |
| | | public R<IPage<BalanceChangeRecordCopy>> change(@ApiParam(value = "变更类型") |
| | | @RequestParam(required = false) Integer changeType, |
| | | @ApiParam(value = "创建时间") |
| | | Integer pageCurr, |
| | | Integer pageSize, |
| | | @ApiParam(value = "创建时间") |
| | | @RequestParam(required = false) |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | | LocalDate createTime) { |
| | |
| | | // 将最后一天转换为 LocalDateTime,并设置为当天的最后一秒 (23:59:59.999) |
| | | endTime = lastDayOfMonth.atTime(LocalTime.MAX); |
| | | } |
| | | |
| | | List<BalanceChangeRecord> list = balanceChangeRecordService.list(new LambdaQueryWrapper<BalanceChangeRecord>() |
| | | .eq(changeType != null, BalanceChangeRecord::getChangeType, changeType) |
| | | .between(startTime != null, BalanceChangeRecord::getCreateTime, startTime, endTime) |
| | | .eq(BalanceChangeRecord::getAppUserId, userId).orderByDesc(BalanceChangeRecord::getCreateTime)); |
| | | |
| | | List<Long> orderIds = list.stream().map(BalanceChangeRecord::getOrderId).collect(Collectors.toList()); |
| | | if (CollectionUtil.isNotEmpty(orderIds)){ |
| | | R<List<Order>> r = remoteOrderGoodsClient.getOrderListByIds(orderIds); |
| | | if (!R.isSuccess(r)){ |
| | | return R.fail(r.getMsg()); |
| | | } |
| | | List<Order> orderList = r.getData(); |
| | | list.forEach(bc -> { |
| | | orderList.stream().filter(o -> o.getId().equals(bc.getOrderId())).findFirst().ifPresent(o -> { |
| | | Long appUserId = o.getAppUserId(); |
| | | AppUser appUser = appUserService.getById(appUserId); |
| | | bc.setUserName(appUser.getName()); |
| | | bc.setAmount(o.getPaymentAmount()); |
| | | }); |
| | | |
| | | BigDecimal beforeAmount = bc.getBeforeAmount(); |
| | | BigDecimal afterAmount = bc.getAfterAmount(); |
| | | if (beforeAmount.compareTo(afterAmount) > 0){ |
| | | bc.setFlag(2); |
| | | }else { |
| | | bc.setFlag(1); |
| | | } |
| | | }); |
| | | } |
| | | return R.ok(list); |
| | | Page<BalanceChangeRecordCopy> pageInfo = new Page<>(pageCurr, pageSize); |
| | | IPage<BalanceChangeRecordCopy> change = balanceChangeRecordService.change(pageInfo, changeType, startTime, endTime, userId); |
| | | return R.ok(change); |
| | | } |
| | | |
| | | /** |
| | |
| | | @GetMapping("recharge") |
| | | @ApiOperation(value = "充值", notes = "钱包充值") |
| | | public R<String> recharge(@ApiParam(value = "充值金额", required = true) @RequestParam BigDecimal amount) { |
| | | |
| | | R<BaseSetting> baseSetting = baseSettingClient.getBaseSetting(7); |
| | | BaseSetting data = baseSetting.getData(); |
| | | if (data != null){ |
| | | String content = data.getContent(); |
| | | if (!content.equals("-1")){ |
| | | if (amount.compareTo(new BigDecimal(content)) > 0){ |
| | | return R.fail("充值金额不能大于" + content + "元"); |
| | | } |
| | | } |
| | | } |
| | | LoginUser loginUserApplet = tokenService.getLoginUserApplet(); |
| | | AppUser appUser = appUserService.getById(loginUserApplet.getUserid()); |
| | | BalancePayment balancePayment = new BalancePayment(); |
| | |
| | | long second = LocalDateTime.now().plusMinutes(15).toEpochSecond(ZoneOffset.UTC); |
| | | redisTemplate.opsForZSet().add("BalanceRecharge", balancePayment.getId(), second); |
| | | return R.ok(jsonObject.toJSONString()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取充值上限金额 |
| | | */ |
| | | @GetMapping("rechargeLimit") |
| | | public R<BigDecimal> rechargeLimit(){ |
| | | R<BaseSetting> baseSetting = baseSettingClient.getBaseSetting(7); |
| | | BaseSetting data = baseSetting.getData(); |
| | | if (data != null){ |
| | | String content = data.getContent(); |
| | | return R.ok(new BigDecimal(content)); |
| | | } |
| | | return R.ok(new BigDecimal("-1")); |
| | | } |
| | | |
| | | |
| | |
| | | balanceChangeRecord.setVipId(appUser.getVipId()); |
| | | balanceChangeRecord.setOrderId(balanceChangeRecord.getId()); |
| | | balanceChangeRecord.setChangeType(1); |
| | | balanceChangeRecord.setBeforeAmount(balance); |
| | | balanceChangeRecord.setChangeAmount(money); |
| | | balanceChangeRecord.setAfterAmount(appUser.getBalance()); |
| | | balanceChangeRecord.setDelFlag(0); |
| | | balanceChangeRecord.setCreateTime(LocalDateTime.now()); |
| | | balanceChangeRecord.setChangeDirection(1); |
| | | balanceChangeRecordService.save(balanceChangeRecord); |
| | | |
| | | balancePayment.setStatus(2); |
| | |
| | | out.flush(); |
| | | out.close(); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |