| | |
| | | package com.xcong.excoin.modules.member.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.crypto.asymmetric.Sign; |
| | | import cn.hutool.crypto.asymmetric.SignAlgorithm; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.excoin.modules.member.dao.MemberDao; |
| | | import com.xcong.excoin.modules.member.entity.MemberEntity; |
| | | import com.xcong.excoin.common.contants.AppContants; |
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum; |
| | | import com.xcong.excoin.common.enumerates.SymbolEnum; |
| | | import com.xcong.excoin.common.response.Result; |
| | | import com.xcong.excoin.common.system.dto.RegisterDto; |
| | | import com.xcong.excoin.modules.member.dao.*; |
| | | import com.xcong.excoin.modules.member.entity.*; |
| | | import com.xcong.excoin.modules.member.service.MemberService; |
| | | import com.xcong.excoin.utils.ShareCodeUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2020-05-18 |
| | | **/ |
| | | @Service |
| | | public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService { |
| | | |
| | | @Resource |
| | | private MemberDao memberDao; |
| | | |
| | | @Resource |
| | | private MemberWalletAgentDao memberWalletAgentDao; |
| | | |
| | | @Resource |
| | | private MemberWalletContractDao memberWalletContractDao; |
| | | |
| | | @Resource |
| | | private MemberWalletCoinDao memberWalletCoinDao; |
| | | |
| | | @Resource |
| | | private MemberLevelRateDao memberLevelRateDao; |
| | | |
| | | @Transactional() |
| | | @Override |
| | | public Result register(RegisterDto registerDto) { |
| | | // 查询是否存在该账号用户 |
| | | MemberEntity member = memberDao.selectMemberInfoByAccount(registerDto.getAccount()); |
| | | if (member == null) { |
| | | return Result.fail("账号已存在"); |
| | | } |
| | | |
| | | member = new MemberEntity(); |
| | | Sign sign = SecureUtil.sign(SignAlgorithm.MD5withRSA); |
| | | byte[] signByte = sign.sign(registerDto.getPassword().getBytes()); |
| | | member.setPassword(new String(signByte)); |
| | | |
| | | // 判断账号类型 |
| | | if (MemberEntity.ACCOUNT_TYPE_PHONE == registerDto.getType()) { |
| | | member.setPhone(registerDto.getAccount()); |
| | | } else if (MemberEntity.ACCOUNT_TYPE_EMAIL == registerDto.getType()) { |
| | | member.setEmail(registerDto.getAccount()); |
| | | } else { |
| | | return Result.fail("账号类型错误"); |
| | | } |
| | | |
| | | // 判断是否拥有推荐人,若为空则默认系统 |
| | | if (StrUtil.isBlank(registerDto.getRefererId())) { |
| | | registerDto.setRefererId(AppContants.SYSTEM_REFERER); |
| | | } |
| | | |
| | | member.setRefererId(registerDto.getRefererId()); |
| | | member.setAccountStatus(MemberEntity.ACCOUNT_STATUS_ENABLE); |
| | | member.setAccountType(registerDto.getType()); |
| | | member.setAgentLevel(MemberEntity.ACCOUNT_AGENT_LEVEL); |
| | | member.setCertifyStatus(MemberEntity.CERTIFY_STATUS_ING); |
| | | member.setIsForce(0); |
| | | member.setIsProfit(0); |
| | | memberDao.insert(member); |
| | | |
| | | String inviteId = ShareCodeUtil.toSerialCode(member.getId()); |
| | | member.setInviteId(inviteId); |
| | | |
| | | boolean flag = false; |
| | | String parentId = member.getRefererId(); |
| | | String ids = ""; |
| | | while (!flag) { |
| | | ids += ("," + parentId); |
| | | MemberEntity parentMember = memberDao.selectMemberInfoByRefererId(parentId); |
| | | if (parentMember == null) { |
| | | break; |
| | | } |
| | | parentId = parentMember.getRefererId(); |
| | | if (parentMember.getRefererId().equals(parentMember.getInviteId())) { |
| | | flag = true; |
| | | } |
| | | } |
| | | member.setRefererIds(ids); |
| | | memberDao.updateById(member); |
| | | |
| | | //初始化合约钱包 |
| | | MemberWalletContractEntity walletContract = new MemberWalletContractEntity(); |
| | | walletContract.setMemberId(member.getId()); |
| | | walletContract.setAvailableBalance(AppContants.INIT_MONEY); |
| | | walletContract.setFrozenBalance(AppContants.INIT_MONEY); |
| | | walletContract.setTotalBalance(AppContants.INIT_MONEY); |
| | | walletContract.setBorrowedFund(AppContants.INIT_MONEY); |
| | | walletContract.setWalletCode(CoinTypeEnum.USDT.name()); |
| | | memberWalletContractDao.insert(walletContract); |
| | | |
| | | |
| | | // 初始化币币钱包 |
| | | for (CoinTypeEnum coinTypeEnum : CoinTypeEnum.values()) { |
| | | MemberWalletCoinEntity walletCoin = new MemberWalletCoinEntity(); |
| | | walletCoin.setWalletCode(coinTypeEnum.name()); |
| | | walletCoin.setMemberId(member.getId()); |
| | | walletCoin.setAvailableBalance(AppContants.INIT_MONEY); |
| | | walletCoin.setFrozenBalance(AppContants.INIT_MONEY); |
| | | walletCoin.setTotalBalance(AppContants.INIT_MONEY); |
| | | walletCoin.setBorrowedFund(AppContants.INIT_MONEY); |
| | | memberWalletCoinDao.insert(walletCoin); |
| | | } |
| | | |
| | | // 初始化代理佣金钱包 |
| | | MemberWalletAgentEntity walletAgent = new MemberWalletAgentEntity(); |
| | | walletAgent.setMemberId(member.getId()); |
| | | walletAgent.setWalletCode(CoinTypeEnum.USDT.name()); |
| | | memberWalletAgentDao.insert(walletAgent); |
| | | |
| | | // 初始化杠杆 |
| | | for(SymbolEnum symbolEnum : SymbolEnum.values()) { |
| | | MemberLevelRateEntity levelRate = new MemberLevelRateEntity(); |
| | | levelRate.setMemberId(member.getId()); |
| | | levelRate.setSymbol(symbolEnum.getValue()); |
| | | memberLevelRateDao.insert(levelRate); |
| | | } |
| | | |
| | | |
| | | return Result.ok("success"); |
| | | } |
| | | |
| | | } |