| | |
| | | package com.xcong.excoin.modules.yunding.service.Impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.excoin.common.LoginUserUtils; |
| | | import com.xcong.excoin.common.response.Result; |
| | | import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao; |
| | | import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange; |
| | | import com.xcong.excoin.modules.member.dao.MemberDao; |
| | | import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao; |
| | | import com.xcong.excoin.modules.member.entity.MemberEntity; |
| | | import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; |
| | | import com.xcong.excoin.modules.yunding.dao.YdBasicLevelSettingDao; |
| | | import com.xcong.excoin.modules.yunding.dao.YdBasicSettingDao; |
| | | import com.xcong.excoin.modules.yunding.dao.YdOrderDao; |
| | | import com.xcong.excoin.modules.yunding.dao.YdProductDao; |
| | | import com.xcong.excoin.modules.yunding.dto.InsureChangeUsdtDto; |
| | | import com.xcong.excoin.modules.yunding.dto.PayProductDto; |
| | | import com.xcong.excoin.modules.yunding.dto.YdOrderListDto; |
| | | import com.xcong.excoin.modules.yunding.dto.YdProductListDto; |
| | | import com.xcong.excoin.modules.yunding.dto.*; |
| | | import com.xcong.excoin.modules.yunding.entity.YdBasicLevelSettingEntity; |
| | | import com.xcong.excoin.modules.yunding.entity.YdBasicSettingEntity; |
| | | import com.xcong.excoin.modules.yunding.entity.YdOrderEntity; |
| | | import com.xcong.excoin.modules.yunding.entity.YdProductEntity; |
| | | import com.xcong.excoin.modules.yunding.service.YunDingService; |
| | | import com.xcong.excoin.modules.yunding.vo.*; |
| | | import com.xcong.excoin.utils.LogRecordUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private YdOrderDao ydOrderDao; |
| | | @Resource |
| | | private MemberWalletCoinDao memberWalletCoinDao; |
| | | @Resource |
| | | private MemberAccountMoneyChangeDao memberAccountMoneyChangeDao; |
| | | @Resource |
| | | private YdBasicLevelSettingDao ydBasicLevelSettingDao; |
| | | @Resource |
| | | private MemberDao memberDao; |
| | | |
| | | @Override |
| | | public Result findAllInfo() { |
| | |
| | | ydOrderEntity.setEndTime(endTime); |
| | | ydOrderEntity.setReturnState(YdOrderEntity.RETURN_STATE_READY); |
| | | ydOrderDao.insert(ydOrderEntity); |
| | | //生成流水记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChangeWithId(memberId, "购买产品", multiplyUsdt, |
| | | "USDT", 1, 3, ydOrderEntity.getId()); |
| | | return Result.ok("支付成功"); |
| | | } |
| | | |
| | |
| | | |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | Long memberId = memberEntity.getId(); |
| | | // Long memberId = 28L; |
| | | // Long memberId = 442L; |
| | | OrderAllInfoVo orderAllInfoVo = new OrderAllInfoVo(); |
| | | DecimalFormat decimalFormat = new DecimalFormat("0.0000#"); |
| | | //历史总收益 |
| | |
| | | QueryWrapper<YdOrderEntity> powerReradyQuery = new QueryWrapper<>(); |
| | | powerReradyQuery.eq("member_id",memberId); |
| | | powerReradyQuery.eq("state",YdOrderEntity.ORDER_STATE_READY); |
| | | List<YdOrderEntity> PowerReradyQuery = ydOrderDao.selectList(powerNowQuery); |
| | | List<YdOrderEntity> PowerReradyQuery = ydOrderDao.selectList(powerReradyQuery); |
| | | if(CollUtil.isNotEmpty(PowerReradyQuery)){ |
| | | for(YdOrderEntity order : PowerReradyQuery){ |
| | | int quantity = order.getQuantity(); |
| | |
| | | } |
| | | } |
| | | orderAllInfoVo.setPowerReady(powerReady); |
| | | //昨日总收益 |
| | | BigDecimal lastdayProfit = BigDecimal.ZERO; |
| | | Date date = DateUtil.date(); |
| | | Date dateTime = DateUtil.offsetDay(date, 1); |
| | | QueryWrapper<MemberAccountMoneyChange> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("type",4); |
| | | queryWrapper.eq("member_id",memberId); |
| | | queryWrapper.eq("status",1); |
| | | queryWrapper.like("create_time",DateUtil.formatDate(dateTime)); |
| | | List<MemberAccountMoneyChange> memberAccountMoneyChanges = memberAccountMoneyChangeDao.selectList(queryWrapper); |
| | | if(CollUtil.isNotEmpty(memberAccountMoneyChanges)){ |
| | | for(MemberAccountMoneyChange memberAccountMoneyChange : memberAccountMoneyChanges){ |
| | | BigDecimal amount = memberAccountMoneyChange.getAmount(); |
| | | lastdayProfit = lastdayProfit.add(amount); |
| | | } |
| | | } |
| | | orderAllInfoVo.setLastdayProfit(decimalFormat.format(lastdayProfit)); |
| | | return Result.ok(orderAllInfoVo); |
| | | } |
| | | |
| | |
| | | log.info("转换成USDT"); |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | Long memberId = memberEntity.getId(); |
| | | // Long memberId = 442L; |
| | | ChangeVo changeVo = new ChangeVo(); |
| | | BigDecimal currentPrice = BigDecimal.ZERO; |
| | | Wrapper<YdBasicSettingEntity> queryWrapper = new QueryWrapper<>(); |
| | |
| | | @Override |
| | | @Transactional |
| | | public Result insureChangeUsdt(InsureChangeUsdtDto insureChangeUsdtdto) { |
| | | log.info("转换成USDT"); |
| | | log.info("确认转换成USDT"); |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | Long memberId = memberEntity.getId(); |
| | | |
| | | // Long memberId = 442L; |
| | | // MemberEntity memberEntity = memberDao.selectById(memberId); |
| | | /** |
| | | * 验证入参 |
| | | * |
| | | * USDT账户增加 |
| | | * XCH账户减少 |
| | | */ |
| | | String tradePassword = insureChangeUsdtdto.getTradePassword(); |
| | | if(StrUtil.isEmpty(tradePassword)){ |
| | | return Result.fail("请输入交易密码"); |
| | | } |
| | | String tradePasswordOwn = memberEntity.getTradePassword(); |
| | | if(StrUtil.isEmpty(tradePasswordOwn)){ |
| | | return Result.fail("请设置交易密码"); |
| | | } |
| | | String tradePasswords = SecureUtil.md5(tradePassword); |
| | | if(!StrUtil.equals(tradePasswordOwn,tradePasswords)){ |
| | | return Result.fail("请输入正确的交易密码"); |
| | | } |
| | | |
| | | BigDecimal xchNum = insureChangeUsdtdto.getXchNum(); |
| | | if(BigDecimal.ZERO.compareTo(xchNum) >= 0){ |
| | | return Result.fail("请输入正确的数量"); |
| | | } |
| | | BigDecimal currentPrice = insureChangeUsdtdto.getCurrentPrice(); |
| | | if(BigDecimal.ZERO.compareTo(currentPrice) >= 0){ |
| | | return Result.fail("XCH价格异常,请重试"); |
| | | } |
| | | |
| | | MemberWalletCoinEntity xch = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, "XCH"); |
| | | BigDecimal totalBalance = xch.getTotalBalance(); |
| | | BigDecimal subtractTotalBalance = totalBalance.subtract(xchNum); |
| | |
| | | xch.setAvailableBalance(subtractAvailableBalance); |
| | | memberWalletCoinDao.updateById(xch); |
| | | |
| | | BigDecimal currentPrice = BigDecimal.ZERO; |
| | | //获取当前价 |
| | | Wrapper<YdBasicSettingEntity> queryWrapper = new QueryWrapper<>(); |
| | | List<YdBasicSettingEntity> ydBasicSettingEntities = ydBasicSettingDao.selectList(queryWrapper); |
| | | if(CollUtil.isNotEmpty(ydBasicSettingEntities)){ |
| | | YdBasicSettingEntity ydBasicSettingEntity = ydBasicSettingEntities.get(0); |
| | | currentPrice = ydBasicSettingEntity.getCurrentPrice(); |
| | | } |
| | | //USDT账户增加 |
| | | BigDecimal multiply = xchNum.multiply(currentPrice); |
| | | MemberWalletCoinEntity usdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, "USDT"); |
| | | usdt.setTotalBalance(usdt.getTotalBalance().add(multiply)); |
| | | usdt.setAvailableBalance(usdt.getAvailableBalance().add(multiply)); |
| | | memberWalletCoinDao.updateById(usdt); |
| | | |
| | | //生成流水记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChangeWithId(memberId, "XCH兑换"+multiply+"USDT", xchNum, |
| | | "USDT", 1, 7, memberId); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result getAgentList(YdAgentDto ydAgentDto) { |
| | | log.info("获取代理级别列表"); |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | Long memberId = memberEntity.getId(); |
| | | // Long memberId = 442L; |
| | | Page<AgentVo> page = new Page<>(ydAgentDto.getPageNum(), ydAgentDto.getPageSize()); |
| | | YdBasicLevelSettingEntity ydBasicLevelSettingEntity = new YdBasicLevelSettingEntity(); |
| | | IPage<AgentVo> list = ydOrderDao.getAgentList(page, ydBasicLevelSettingEntity); |
| | | return Result.ok(list); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Result bugAgentLevel(BugAgentLeveldto bugAgentLeveldto) { |
| | | log.info("购买代理级别"); |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | Long memberId = memberEntity.getId(); |
| | | // Long memberId = 442L; |
| | | // MemberEntity memberEntity = memberDao.selectById(memberId); |
| | | |
| | | /** |
| | | * 获取代理级别(Level字段越小,级别越高) |
| | | * 不能向下购买代理级别 |
| | | * 不能购买同级别 |
| | | * 获取用户当前USDT余额 |
| | | * 减少用户的USDT余额 |
| | | * 更新用户的代理级别 |
| | | */ |
| | | |
| | | String tradePassword = bugAgentLeveldto.getTradePassword(); |
| | | if(StrUtil.isEmpty(tradePassword)){ |
| | | return Result.fail("请输入交易密码"); |
| | | } |
| | | String tradePasswordOwn = memberEntity.getTradePassword(); |
| | | if(StrUtil.isEmpty(tradePasswordOwn)){ |
| | | return Result.fail("请设置交易密码"); |
| | | } |
| | | String tradePasswords = SecureUtil.md5(tradePassword); |
| | | if(!StrUtil.equals(tradePasswordOwn,tradePasswords)){ |
| | | return Result.fail("请输入正确的交易密码"); |
| | | } |
| | | |
| | | Long id = bugAgentLeveldto.getId(); |
| | | YdBasicLevelSettingEntity ydBasicLevelSettingEntityTo = ydBasicLevelSettingDao.selectById(id); |
| | | if(ObjectUtil.isEmpty(ydBasicLevelSettingEntityTo)){ |
| | | return Result.fail("稍候再试"); |
| | | } |
| | | Integer levelTo = ydBasicLevelSettingEntityTo.getLevel(); |
| | | //获取当前代理级别 |
| | | Integer agentLevel = memberEntity.getAgentLevel(); |
| | | long agentId = Long.parseLong(agentLevel.toString()); |
| | | Integer levelNow = 0; |
| | | YdBasicLevelSettingEntity ydBasicLevelSettingEntityNow = ydBasicLevelSettingDao.selectById(agentId); |
| | | if(ObjectUtil.isNotEmpty(ydBasicLevelSettingEntityNow)){ |
| | | levelNow = ydBasicLevelSettingEntityNow.getLevel(); |
| | | if(levelTo >= levelNow){ |
| | | return Result.fail("无法购买"); |
| | | } |
| | | } |
| | | |
| | | BigDecimal salePrice = ydBasicLevelSettingEntityTo.getSalePrice(); |
| | | //用户如果已经有等级则减少差价 |
| | | if(levelNow != 0){ |
| | | salePrice = salePrice.subtract(ydBasicLevelSettingEntityNow.getSalePrice()); |
| | | } |
| | | //获取用户当前USDT余额 |
| | | MemberWalletCoinEntity usdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, "USDT"); |
| | | BigDecimal availableBalance = usdt.getAvailableBalance(); |
| | | if(salePrice.compareTo(availableBalance) > 0){ |
| | | return Result.fail("USDT数量不足"); |
| | | } |
| | | BigDecimal totalBalance = usdt.getTotalBalance(); |
| | | usdt.setAvailableBalance(availableBalance.subtract(salePrice)); |
| | | usdt.setTotalBalance(totalBalance.subtract(salePrice)); |
| | | memberWalletCoinDao.updateById(usdt); |
| | | //更新用户的代理级别 |
| | | ydOrderDao.updateAgentLevel(memberId,Integer.parseInt(id.toString())); |
| | | |
| | | LogRecordUtils.insertMemberAccountMoneyChangeWithId(memberId, "购买代理", salePrice, |
| | | "USDT", 1, 8, memberId); |
| | | return Result.ok("购买成功"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 去加减币币账户余额,减少产品的剩余数目 |
| | | * @param memberId |