| | |
| | | package cc.mrbird.febs.mall.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.enumerates.RunVipDataDictionaryEnum; |
| | | import cc.mrbird.febs.common.enumerates.RunVipMoneyFlowTypeEnum; |
| | | import cc.mrbird.febs.common.enumerates.YesOrNoEnum; |
| | | import cc.mrbird.febs.common.enumerates.*; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.MallUtils; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | .orderByDesc(RunVipGrow::getId) |
| | | ).stream().findFirst().orElse(null); |
| | | if(runVipGrow != null){ |
| | | BigDecimal amountNow = runVipGrow.getAmountNow(); |
| | | reduceAmount = reduceAmount.add(amountNow); |
| | | reduceAmount = runVipGrow.getAmountNow(); |
| | | } |
| | | presentAmount = presentAmount.subtract(reduceAmount); |
| | | if(BigDecimal.ZERO.compareTo(presentAmount) >= 0){ |
| | | throw new FebsException("支付异常,请刷新页面重试"); |
| | | } |
| | | |
| | | Long addressId = apiGoChargeDto.getAddressId(); |
| | | MallMemberPayment mallMemberPayment = mallMemberPaymentMapper.selectById(addressId); |
| | |
| | | .orderByDesc(RunVipGrow::getId) |
| | | ).stream().findFirst().orElse(null); |
| | | if(runVipGrow != null){ |
| | | BigDecimal amountNow = runVipGrow.getAmountNow(); |
| | | reduceAmount = reduceAmount.add(amountNow); |
| | | reduceAmount = runVipGrow.getAmountNow(); |
| | | } |
| | | presentAmount = presentAmount.subtract(reduceAmount); |
| | | if(BigDecimal.ZERO.compareTo(presentAmount) >= 0){ |
| | | throw new FebsException("支付异常,请刷新页面重试"); |
| | | } |
| | | |
| | | MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); |
| | | if(mallMemberWallet.getCommission().compareTo(BigDecimal.ZERO) <= 0){ |
| | |
| | | BigDecimal subtract = amountAll.subtract(amountNow); |
| | | |
| | | if(subtract.compareTo(amount) <= 0){ |
| | | runVipGrow.setAmountNow(amountAll); |
| | | |
| | | mallCharge.setVipCode(runVipGrow.getLevelNext()); |
| | | }else{ |
| | | runVipGrow.setAmountNow(amountNow.add(amount).setScale(2, RoundingMode.DOWN)); |
| | | |
| | | mallCharge.setVipCode(memberLevel); |
| | | } |
| | | runVipGrow.setAmount(amount); |
| | | runVipGrowMapper.updateById(runVipGrow); |
| | | }else{ |
| | | runVipGrow = new RunVipGrow(); |
| | | runVipGrow.setMemberId(memberId); |
| | | runVipGrow.setLevelNow(memberLevel); |
| | | runVipGrow.setLevelNext(runVipNext.getVipCode()); |
| | | runVipGrow.setAmountAll(runVipNext.getPresentPrice()); |
| | | runVipGrow.setAmount(amount); |
| | | runVipGrow.setAmountNow(amount); |
| | | runVipGrowMapper.insert(runVipGrow); |
| | | |
| | | if(runVipGrow.getAmountAll().compareTo(amount) <= 0){ |
| | | mallCharge.setVipCode(runVipGrow.getLevelNext()); |
| | | BigDecimal presentPrice = runVip.getPresentPrice(); |
| | | BigDecimal add = presentPrice.add(amount); |
| | | |
| | | BigDecimal presentPriceNext = runVipNext.getPresentPrice(); |
| | | if(presentPriceNext.compareTo(add) <= 0){ |
| | | mallCharge.setVipCode(runVipNext.getVipCode()); |
| | | } |
| | | } |
| | | mallChargeMapper.insert(mallCharge); |
| | |
| | | mallCharge.setVipCode(runVipGrow.getLevelNext()); |
| | | } |
| | | }else{ |
| | | if(runVipNext.getPresentPrice().compareTo(amount) <= 0){ |
| | | BigDecimal add = runVip.getPresentPrice().add(amount); |
| | | if(runVipNext.getPresentPrice().compareTo(add) <= 0){ |
| | | mallCharge.setVipCode(runVipNext.getVipCode()); |
| | | } |
| | | } |
| | |
| | | ).stream().findFirst().orElse(null); |
| | | if(runVipGrow != null){ |
| | | BigDecimal amountNow = runVipGrow.getAmountNow(); |
| | | reduceAmount = reduceAmount.add(amountNow); |
| | | reduceAmount = amountNow; |
| | | } |
| | | apiReduceAmountVo.setReduceAmount(reduceAmount); |
| | | return new FebsResponse().success().data(apiReduceAmountVo); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse goChargeUSDT(ApiGoChargeUSDTDto apiGoChargeDto) { |
| | | |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | |
| | | ApiGoChargeVo apiGoChargeVo = new ApiGoChargeVo(); |
| | | |
| | | BigDecimal amount = apiGoChargeDto.getAmount(); |
| | | if(BigDecimal.ZERO.compareTo(amount) >= 0){ |
| | | throw new FebsException("金额异常"); |
| | | } |
| | | |
| | | MallMember mallMember = mallMemberMapper.selectById(memberId); |
| | | if (StrUtil.isBlank(mallMember.getTradePassword())) { |
| | | throw new FebsException("未设置资金密码"); |
| | | } |
| | | |
| | | if (!mallMember.getTradePassword().equals(SecureUtil.md5(apiGoChargeDto.getTradeWord()))) { |
| | | throw new FebsException("资金密码错误"); |
| | | } |
| | | |
| | | Long addressId = apiGoChargeDto.getAddressId(); |
| | | MallMemberPayment mallMemberPayment = mallMemberPaymentMapper.selectById(addressId); |
| | | if(ObjectUtil.isEmpty(mallMemberPayment)){ |
| | | return new FebsResponse().fail().message("请先绑定你的地址"); |
| | | } |
| | | |
| | | //判断系统的充值地址 |
| | | String trcType = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | RunVipDataDictionaryEnum.CHARGE_TYPE_TRC.getType(), |
| | | RunVipDataDictionaryEnum.CHARGE_TYPE_TRC.getCode() |
| | | ).getValue(); |
| | | String sysAddress = ""; |
| | | if(trcType.equals(mallMemberPayment.getBankNo())){ |
| | | sysAddress = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | RunVipDataDictionaryEnum.CHARGE_SYS_ADDRESS_TRC.getType(), |
| | | RunVipDataDictionaryEnum.CHARGE_SYS_ADDRESS_TRC.getCode() |
| | | ).getValue(); |
| | | }else{ |
| | | sysAddress = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | RunVipDataDictionaryEnum.CHARGE_SYS_ADDRESS_BSC.getType(), |
| | | RunVipDataDictionaryEnum.CHARGE_SYS_ADDRESS_BSC.getCode() |
| | | ).getValue(); |
| | | } |
| | | String failMinutes = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | RunVipDataDictionaryEnum.CHARGE_SYS_FAIL_TIME.getType(), |
| | | RunVipDataDictionaryEnum.CHARGE_SYS_FAIL_TIME.getCode() |
| | | ).getValue(); |
| | | DateTime failTime = DateUtil.offsetMinute(DateUtil.date(), Integer.parseInt(failMinutes)); |
| | | |
| | | MallCharge mallCharge = new MallCharge(); |
| | | String orderNo = MallUtils.getOrderNum("C"); |
| | | mallCharge.setMemberId(memberId); |
| | | mallCharge.setOrderNo(orderNo); |
| | | mallCharge.setState(YesOrNoEnum.ING.getValue()); |
| | | mallCharge.setType(mallMemberPayment.getBankNo()); |
| | | mallCharge.setAddress(mallMemberPayment.getBank()); |
| | | mallCharge.setFailTime(failTime); |
| | | mallCharge.setSysAddress(sysAddress); |
| | | |
| | | mallCharge.setAmount(amount); |
| | | mallCharge.setVipName(RunVipMoneyFlowTypeEnum.COMMISSION_PAY_CHARGE.getTypeDec()); |
| | | mallChargeMapper.insert(mallCharge); |
| | | |
| | | apiGoChargeVo.setFailTime(mallCharge.getFailTime()); |
| | | apiGoChargeVo.setAddress(mallCharge.getAddress()); |
| | | apiGoChargeVo.setAmount(mallCharge.getAmount()); |
| | | apiGoChargeVo.setSysAddress(mallCharge.getSysAddress()); |
| | | apiGoChargeVo.setSysAddressType(mallCharge.getType()); |
| | | |
| | | /** |
| | | * 充值接口调用后,发送一个延时队列 |
| | | * 功能:延迟时间为【failMinutes】后,更新充值记录为失败。 |
| | | */ |
| | | ApiMemberChargeFailDto apiMemberChargeFailDto = new ApiMemberChargeFailDto(); |
| | | apiMemberChargeFailDto.setChargeId(mallCharge.getId()); |
| | | apiMemberChargeFailDto.setFailTime(Integer.parseInt(failMinutes) * 60L* 1000L); |
| | | agentProducer.sendMemberChargeFailMsg(apiMemberChargeFailDto); |
| | | return new FebsResponse().success().data(apiGoChargeVo); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse goChargeUSDTInfo(ApiGoChargeInfoDto apiGoChargeInfoDto) { |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | String orderNo = apiGoChargeInfoDto.getOrderNo(); |
| | | |
| | | LambdaQueryWrapper<MallCharge> objectLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | objectLambdaQueryWrapper.eq(MallCharge::getMemberId,memberId); |
| | | objectLambdaQueryWrapper.eq(MallCharge::getOrderNo,orderNo); |
| | | MallCharge mallCharge = mallChargeMapper.selectOne(objectLambdaQueryWrapper); |
| | | |
| | | ApiGoChargeVo apiGoChargeVo = new ApiGoChargeVo(); |
| | | if(null == mallCharge){ |
| | | throw new FebsException("记录不存在"); |
| | | } |
| | | apiGoChargeVo.setFailTime(mallCharge.getFailTime()); |
| | | apiGoChargeVo.setAddress(mallCharge.getAddress()); |
| | | apiGoChargeVo.setAmount(mallCharge.getAmount()); |
| | | apiGoChargeVo.setSysAddress(mallCharge.getSysAddress()); |
| | | apiGoChargeVo.setSysAddressType(mallCharge.getType()); |
| | | return new FebsResponse().success().data(apiGoChargeVo); |
| | | } |
| | | } |