| | |
| | | package com.xcong.excoin.modules.coin.service.impl;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.*;
|
| | | import javax.annotation.Resource;
|
| | | import javax.validation.Valid;
|
| | |
|
| | | import cn.hutool.core.util.RandomUtil;
|
| | | import cn.hutool.core.date.DateUtil;
|
| | | import com.xcong.excoin.modules.coin.dao.ZhiYaRecordDao;
|
| | | import com.xcong.excoin.modules.coin.entity.ZhiYaRecordEntity;
|
| | | import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
| | | MemberAccountMoneyChangeDao memberAccountMoneyChangeDao;
|
| | | @Resource
|
| | | MemberWalletAgentDao memberWalletAgentDao;
|
| | | @Resource
|
| | | ZhiYaRecordDao zhiYaRecordDao;
|
| | | @Resource
|
| | | RedisUtils redisUtils;
|
| | |
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public Result usdtToGusd(BigDecimal balance, Integer transfertype) {
|
| | | public Result usdtToGusd(BigDecimal balance) {
|
| | | //获取用户ID
|
| | | Long memberId = LoginUserUtils.getAppLoginUser().getId();
|
| | | if (balance.compareTo(BigDecimal.ZERO) <= 0) {
|
| | |
| | |
|
| | | BigDecimal available = availableBalance.subtract(balance);
|
| | | if (available.compareTo(BigDecimal.ZERO) < 0) {
|
| | | return Result.fail(MessageSourceUtils.getString("member_service_0008"));
|
| | | return Result.fail(MessageSourceUtils.getString("member_service_0005"));
|
| | | }
|
| | | BigDecimal total = totalBalance.subtract(balance);
|
| | | if (total.compareTo(BigDecimal.ZERO) < 0) {
|
| | | return Result.fail(MessageSourceUtils.getString("member_service_0008"));
|
| | | return Result.fail(MessageSourceUtils.getString("member_service_0005"));
|
| | | }
|
| | |
|
| | | memberWalletCoinEntity.setAvailableBalance(available);
|
| | |
| | | memberAccountRecord.setAmount(balance);
|
| | | memberAccountMoneyChangeDao.insert(memberAccountRecord);
|
| | |
|
| | | return Result.ok(MessageSourceUtils.getString("member_service_0006"));
|
| | | return Result.ok(MessageSourceUtils.getString("member_service_0024"));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Result zhiYaGusd(BigDecimal balance) {
|
| | | //获取用户ID
|
| | | Long memberId = LoginUserUtils.getAppLoginUser().getId();
|
| | | if (balance.compareTo(new BigDecimal(100)) < 0) {
|
| | | return Result.fail(MessageSourceUtils.getString("member_service_0005"));
|
| | | }
|
| | | //质押Gusd,质押数量进入冻结余额,
|
| | | String gusdName = CoinTypeEnum.GUSD.name();
|
| | | MemberWalletCoinEntity gusdMemberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, gusdName);
|
| | | BigDecimal gusdAvailableBalance = gusdMemberWalletCoinEntity.getAvailableBalance();
|
| | | BigDecimal gusdTotalBalance = gusdMemberWalletCoinEntity.getTotalBalance();
|
| | | BigDecimal gusdfrozenBalance = gusdMemberWalletCoinEntity.getFrozenBalance();
|
| | |
|
| | | BigDecimal available = gusdAvailableBalance.subtract(balance);
|
| | | if (available.compareTo(BigDecimal.ZERO) < 0) {
|
| | | return Result.fail(MessageSourceUtils.getString("member_service_0005"));
|
| | | }
|
| | | BigDecimal total = gusdTotalBalance.subtract(balance);
|
| | | if (total.compareTo(BigDecimal.ZERO) < 0) {
|
| | | return Result.fail(MessageSourceUtils.getString("member_service_0005"));
|
| | | }
|
| | | gusdMemberWalletCoinEntity.setFrozenBalance(gusdfrozenBalance.add(gusdfrozenBalance));
|
| | | gusdMemberWalletCoinEntity.setAvailableBalance(gusdAvailableBalance.subtract(balance));
|
| | |
|
| | | int updateById = memberWalletCoinDao.updateById(gusdMemberWalletCoinEntity);
|
| | | if (updateById < 1) {
|
| | | return Result.fail(MessageSourceUtils.getString("member_service_0095"));
|
| | | }
|
| | | //产生质押单,当前有的话,累加质押数量
|
| | | ZhiYaRecordEntity zhiYaRecord = zhiYaRecordDao.selectByMemberIdAndOrderStatus(memberId,1);
|
| | | if(ObjectUtil.isEmpty(zhiYaRecord)){
|
| | | //产生一条质押记录
|
| | | ZhiYaRecordEntity zhiYaRecordEntity = new ZhiYaRecordEntity();
|
| | | zhiYaRecordEntity.setMemberId(memberId);
|
| | | zhiYaRecordEntity.setOrderNo(generateSimpleSerialno(memberId.toString()));
|
| | | zhiYaRecordEntity.setSymbol(gusdName);
|
| | | zhiYaRecordEntity.setZhiyaCnt(balance);
|
| | | zhiYaRecordEntity.setOrderStatus(1);
|
| | | Date date = new Date();
|
| | | Date newDate = DateUtil.offsetDay(date, 1);
|
| | | zhiYaRecordEntity.setEffectDate(newDate);
|
| | | zhiYaRecordDao.insert(zhiYaRecordEntity);
|
| | | }else{
|
| | | zhiYaRecord.setZhiyaCnt(zhiYaRecord.getZhiyaCnt().add(balance));
|
| | | Date date = new Date();
|
| | | Date newDate = DateUtil.offsetDay(date, 1);
|
| | | zhiYaRecord.setEffectDate(newDate);
|
| | | zhiYaRecordDao.updateById(zhiYaRecord);
|
| | | }
|
| | |
|
| | | return Result.ok(MessageSourceUtils.getString("member_service_0024"));
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Result shuhuiGusd(BigDecimal balance) {
|
| | | //获取用户ID
|
| | | Long memberId = LoginUserUtils.getAppLoginUser().getId();
|
| | | if (balance.compareTo(BigDecimal.ZERO) <= 0) {
|
| | | return Result.fail(MessageSourceUtils.getString("order_service_0010"));
|
| | | }
|
| | | //质押Gusd,质押数量进入冻结余额,
|
| | | String gusdName = CoinTypeEnum.GUSD.name();
|
| | | MemberWalletCoinEntity gusdMemberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, gusdName);
|
| | | BigDecimal gusdAvailableBalance = gusdMemberWalletCoinEntity.getAvailableBalance();
|
| | | BigDecimal gusdTotalBalance = gusdMemberWalletCoinEntity.getTotalBalance();
|
| | | BigDecimal gusdfrozenBalance = gusdMemberWalletCoinEntity.getFrozenBalance();
|
| | |
|
| | | BigDecimal frozen = gusdfrozenBalance.subtract(balance);
|
| | | if (frozen.compareTo(BigDecimal.ZERO) < 0) {
|
| | | return Result.fail(MessageSourceUtils.getString("zhiya_service_0001"));
|
| | | }
|
| | | BigDecimal total = gusdTotalBalance.subtract(balance);
|
| | | if (total.compareTo(BigDecimal.ZERO) < 0) {
|
| | | return Result.fail(MessageSourceUtils.getString("member_service_0005"));
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public String generateSimpleSerialno(String userId) {
|
| | | StringBuilder sb = new StringBuilder();
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
| | | SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd");
|
| | | Date now = new Date();
|
| | | sb.append(sd.format(now));
|
| | | Calendar calendar = new GregorianCalendar();
|
| | | calendar.setTime(now);
|
| | | calendar.add(calendar.DATE, 1);
|
| | | Date nextDate = calendar.getTime();
|
| | | if (StrUtil.isNotEmpty(userId)) {
|
| | | sb.append(userId);
|
| | | }
|
| | | sb.append(RandomUtil.randomInt(2));
|
| | | long count = zhiYaRecordDao.getOrderCountByToday(sdf.format(now), sdf.format(nextDate));
|
| | | count++;
|
| | | int size = 4;
|
| | | for (int i = 0; i < size - String.valueOf(count).length(); i++) {
|
| | | sb.append("0");
|
| | | }
|
| | | sb.append(count);
|
| | | return sb.toString();
|
| | | }
|
| | |
|
| | | }
|