xiaoyong931011
2020-05-31 9c8711046b00898717aa7a3b9f6dfee974d3f427
src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java
@@ -19,30 +19,39 @@
import com.xcong.excoin.modules.member.parameter.dto.MemberAuthenticationDto;
import com.xcong.excoin.modules.member.parameter.dto.MemberBindEmailDto;
import com.xcong.excoin.modules.member.parameter.dto.MemberBindPhoneDto;
import com.xcong.excoin.modules.member.parameter.dto.MemberDelCoinAddressDto;
import com.xcong.excoin.modules.member.parameter.dto.MemberDelPaymethodDto;
import com.xcong.excoin.modules.member.parameter.dto.MemberForgetPwdDto;
import com.xcong.excoin.modules.member.parameter.dto.MemberPaymethodDto;
import com.xcong.excoin.modules.member.parameter.dto.MemberUpdatePwdDto;
import com.xcong.excoin.modules.member.parameter.dto.MemberUpdateTradePwdDto;
import com.xcong.excoin.modules.member.parameter.vo.MemberAuthenticationInfoVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberAvivableCoinInfoVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberCoinAddressCountListVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberCoinAddressCountVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberCoinAddressListVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberCoinAddressVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberCoinInfoListVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberCoinInfoVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberInfoVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberPaymethodDetailListVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberPaymethodDetailVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberPersonCenterInfoVo;
import com.xcong.excoin.modules.member.parameter.vo.MemberSendCodeWayVo;
import com.xcong.excoin.modules.member.service.MemberService;
import com.xcong.excoin.modules.platform.dao.PlatformFeeSettingDao;
import com.xcong.excoin.modules.platform.dao.PlatformSymbolsCoinDao;
import com.xcong.excoin.modules.platform.entity.PlatformFeeSettingEntity;
import com.xcong.excoin.modules.platform.entity.PlatformSymbolsCoinEntity;
import com.xcong.excoin.utils.MessageSourceUtils;
import com.xcong.excoin.utils.RedisUtils;
import com.xcong.excoin.utils.ShareCodeUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -77,7 +86,7 @@
    @Resource
    MemberAuthenticationDao memberAuthenticationDao;
    
    @Autowired
    @Resource
    RedisUtils redisUtils;
    
    @Resource
@@ -87,11 +96,17 @@
    PlatformSymbolsCoinDao platformSymbolsCoinDao;
    
    @Resource
    PlatformFeeSettingDao platformFeeSettingDao;
    @Resource
    MemberCoinAddressDao memberCoinAddressDao;
    
    @Resource
    private CommonService commonservice;
    @Resource
    private MemberWalletContractSimulateDao memberWalletContractSimulateDao;
    @Transactional()
    @Override
    public Result register(RegisterDto registerDto) {
@@ -156,6 +171,15 @@
        walletContract.setBorrowedFund(AppContants.INIT_MONEY);
        walletContract.setWalletCode(CoinTypeEnum.USDT.name());
        memberWalletContractDao.insert(walletContract);
        MemberWalletContractSimulateEntity walletContractSimulate = new MemberWalletContractSimulateEntity();
        walletContractSimulate.setMemberId(member.getId());
      walletContractSimulate.setAvailableBalance(new BigDecimal(AppContants.INIT_SIMULATE_MONEY));
      walletContractSimulate.setTotalBalance(new BigDecimal(AppContants.INIT_SIMULATE_MONEY));
      walletContractSimulate.setFrozenBalance(AppContants.INIT_MONEY);
      walletContractSimulate.setBorrowedFund(AppContants.INIT_MONEY);
      walletContractSimulate.setWalletCode(CoinTypeEnum.USDT.name());
      memberWalletContractSimulateDao.insert(walletContractSimulate);
        // 初始化币币钱包
@@ -227,11 +251,6 @@
      }else {
         return Result.fail(MessageSourceUtils.getString("member_service_0045"));
      }
      if(type == 1) {
         redisUtils.del("SMS_" + account);
      }else {
         redisUtils.del("EMAIL_" + account);
      }
        return Result.ok(MessageSourceUtils.getString("member_service_0048"));
    }
   
@@ -253,11 +272,6 @@
         memberDao.updateById(memberEntity);
      }else {
         return Result.fail(MessageSourceUtils.getString("member_service_0041"));
      }
      if(type == 1) {
         redisUtils.del("SMS_" + phone);
      }else {
         redisUtils.del("EMAIL_" + email);
      }
        return Result.ok(MessageSourceUtils.getString("member_service_0040"));
    }
@@ -380,14 +394,9 @@
        if (flag) {
           memberEntity.setTradePassword(SecureUtil.md5(password));
           memberDao.updateById(memberEntity);
           if(MemberEntity.ACCOUNT_TYPE_PHONE.equals(type)) {
              redisUtils.del("SMS_" + phone);
           }else {
              redisUtils.del("EMAIL_" + email);
           }
           return Result.ok(MessageSourceUtils.getString("member_service_0051"));
        }
        return Result.fail(MessageSourceUtils.getString("member_service_0041"));
        return Result.fail(MessageSourceUtils.getString("member_service_0045"));
        
    }
@@ -399,15 +408,6 @@
      MemberEntity memberEntity = memberDao.selectById(memberId);
         if (ObjectUtil.isEmpty(memberEntity)) {
            return Result.fail(MessageSourceUtils.getString("member_service_0003")); 
         }
         String phone = memberEntity.getPhone();
         if(StrUtil.isEmpty(phone)) {
            redisUtils.del(memberEntity.getPhone());
         }
         String email = memberEntity.getEmail();
         if(StrUtil.isEmpty(email)) {
            redisUtils.del(memberEntity.getPhone());
         }
         
         return Result.ok(MessageSourceUtils.getString("member_service_0071"));
@@ -433,11 +433,6 @@
         return Result.fail(MessageSourceUtils.getString("member_service_0015"));
      }
      
      if(type == 1) {
         redisUtils.del("SMS_" + account);
      }else {
         redisUtils.del("EMAIL_" + account);
      }
        return Result.ok(MessageSourceUtils.getString("member_service_0068"));
    }
@@ -457,7 +452,6 @@
      String paymentQrcode = memberPaymethodDto.getPaymentQrcode();
      String paymentType = memberPaymethodDto.getPaymentType();
      String subBank = memberPaymethodDto.getSubBank();
      String isDefualt = memberPaymethodDto.getIsDefualt();
      MemberPaymentMethodEntity memberPaymentMethodEntity = new MemberPaymentMethodEntity();
      memberPaymentMethodEntity.setMemberId(memberId);
      memberPaymentMethodEntity.setAccount(account);
@@ -466,7 +460,6 @@
      memberPaymentMethodEntity.setPaymentQrcode(paymentQrcode);
      memberPaymentMethodEntity.setPaymentType(paymentType);
      memberPaymentMethodEntity.setSubBank(subBank);
      memberPaymentMethodEntity.setIsDefualt(isDefualt);
      memberPaymentMethodDao.insert(memberPaymentMethodEntity);
      return Result.ok(MessageSourceUtils.getString("member_service_0024"));
    }
@@ -513,6 +506,7 @@
      if(CollUtil.isNotEmpty(selectByMap)) {
         for(MemberPaymentMethodEntity memberPaymentMethodEntity : selectByMap) {
            MemberPaymethodDetailVo memberPaymethodDetailVo = new MemberPaymethodDetailVo();
            memberPaymethodDetailVo.setId(memberPaymentMethodEntity.getId());
            memberPaymethodDetailVo.setAccount(memberPaymentMethodEntity.getAccount());
            memberPaymethodDetailVo.setBank(memberPaymentMethodEntity.getBank());
            memberPaymethodDetailVo.setMemberId(memberId);
@@ -549,7 +543,6 @@
            }
            member.setPhone(phone);
            memberDao.updateById(member);
            redisUtils.del("SMS_" + member.getPhone());
            return Result.ok(MessageSourceUtils.getString("member_service_0014"));
        }
      
@@ -566,18 +559,13 @@
      String code = memberBindEmailDto.getCode();
            
      MemberEntity member = memberDao.selectById(memberId);
      String verifyCode = (String)redisUtils.get("EMAIL_" + email);
      boolean flag = commonservice.verifyCode(email, code);
      if (ObjectUtil.isNotEmpty(member)) {
         if (StringUtils.isBlank(verifyCode)) {
              return Result.fail(MessageSourceUtils.getString("member_service_0012"));
          if (flag) {
              member.setEmail(email);
              memberDao.updateById(member);
              return Result.ok(MessageSourceUtils.getString("member_service_0018"));
          }
          if (!code.equals(verifyCode)) {
              return Result.fail(MessageSourceUtils.getString("member_service_0039"));
          }
            member.setEmail(email);
            memberDao.updateById(member);
            redisUtils.del("EMAIL_" + member.getPhone());
            return Result.ok(MessageSourceUtils.getString("member_service_0018"));
        }
        return Result.fail(MessageSourceUtils.getString("member_service_0019"));
    }
@@ -635,16 +623,135 @@
      Long symbolscoinId = memberAddCoinAddressDto. getSymbolscoinId();
      String remark = memberAddCoinAddressDto.getRemark();
      
      PlatformSymbolsCoinEntity platformSymbolsCoinEntity = platformSymbolsCoinDao.selectById(symbolscoinId);
      MemberCoinAddressEntity memberCoinAddressEntity = new MemberCoinAddressEntity();
      memberCoinAddressEntity.setAddress(address);
      memberCoinAddressEntity.setMemberId(memberId);
      memberCoinAddressEntity.setIsBiyict(isBiyict);
      memberCoinAddressEntity.setSymbolscoinId(symbolscoinId);
      memberCoinAddressEntity.setLabel(remark);
      memberCoinAddressEntity.setSymbol(platformSymbolsCoinEntity.getName());
      
      memberCoinAddressDao.insert(memberCoinAddressEntity);
      
       return Result.ok(MessageSourceUtils.getString("member_service_0024"));
   }
   @Override
   public Result memberSendCodeWay() {
      //获取用户ID
      Long memberId = LoginUserUtils.getAppLoginUser().getId();
      MemberEntity member = memberDao.selectById(memberId);
      MemberSendCodeWayVo memberSendCodeWayVo = new MemberSendCodeWayVo();
      if(ObjectUtil.isNotEmpty(member)) {
         memberSendCodeWayVo.setPhone(member.getPhone());
         memberSendCodeWayVo.setEmail(member.getEmail());
      }
      return Result.ok(memberSendCodeWayVo);
   }
   @Override
   @Transactional
   public Result memberDelCoinAddress(@Valid MemberDelCoinAddressDto memberDelCoinAddressDto) {
      //获取用户ID
      Long memberId = LoginUserUtils.getAppLoginUser().getId();
      MemberEntity member = memberDao.selectById(memberId);
      if(ObjectUtil.isNotEmpty(member)) {
         Long id = memberDelCoinAddressDto.getId();
         memberCoinAddressDao.deleteById(id);
      }
      return Result.ok("success");
   }
   @Override
   public Result memberAuthenticationInfo() {
      //获取用户ID
      Long memberId = LoginUserUtils.getAppLoginUser().getId();
      MemberEntity member = memberDao.selectById(memberId);
      Map<String, Object> columnMap = new HashMap<>();
      columnMap.put("member_id", memberId);
      List<MemberAuthenticationEntity> selectByMap = memberAuthenticationDao.selectByMap(columnMap);
      MemberAuthenticationInfoVo memberAuthnticationInfoVo = new MemberAuthenticationInfoVo();
      memberAuthnticationInfoVo.setCertifyStatus(member.getCertifyStatus());
      if(CollUtil.isNotEmpty(selectByMap)) {
         for(MemberAuthenticationEntity memberAuthenticationEntity : selectByMap) {
            memberAuthnticationInfoVo.setFirstName(memberAuthenticationEntity.getFirstName());
            memberAuthnticationInfoVo.setSecondName(memberAuthenticationEntity.getSecondName());
            memberAuthnticationInfoVo.setNation(memberAuthenticationEntity.getNation());
            memberAuthnticationInfoVo.setIdCardNo(memberAuthenticationEntity.getIdcardNo());
         }
      }
      return Result.ok(memberAuthnticationInfoVo);
   }
   @Override
   public Result memberPersonCenterInfo() {
      //获取用户ID
      Long memberId = LoginUserUtils.getAppLoginUser().getId();
      MemberEntity member = memberDao.selectById(memberId);
      MemberPersonCenterInfoVo memberPersonCenterInfoVo = new MemberPersonCenterInfoVo();
      if(StrUtil.isNotEmpty(member.getPhone())) {
         memberPersonCenterInfoVo.setPhone(1);
      }
      memberPersonCenterInfoVo.setPhone(0);
      if(StrUtil.isNotEmpty(member.getEmail())) {
         memberPersonCenterInfoVo.setEmail(1);
      }
      memberPersonCenterInfoVo.setEmail(0);
      if(StrUtil.isNotEmpty(member.getTradePassword())) {
         memberPersonCenterInfoVo.setTradePassword(1);
      }
      memberPersonCenterInfoVo.setTradePassword(0);
      if(StrUtil.isNotEmpty(member.getTradeAgingSetting().toString())) {
         memberPersonCenterInfoVo.setTradeAgingSetting(MemberPersonCenterInfoVo.PWD_NEED_FORVER);
      }
      memberPersonCenterInfoVo.setTradeAgingSetting(MemberPersonCenterInfoVo.PWD_NEED_FORVER);
      return Result.ok(memberPersonCenterInfoVo);
   }
   @Override
   public Result memberCoinInfoList() {
      //获取用户ID
      Long memberId = LoginUserUtils.getAppLoginUser().getId();
      MemberCoinInfoListVo memberCoinInfoListVo = new MemberCoinInfoListVo();
      List<PlatformSymbolsCoinEntity> selectByMap = platformSymbolsCoinDao.selectByMap(new HashMap<>());
      List<MemberCoinInfoVo> arrayList = new ArrayList<>();
      if(CollUtil.isNotEmpty(selectByMap)) {
         for(PlatformSymbolsCoinEntity platformSymbolsCoinEntity : selectByMap) {
            MemberCoinInfoVo memberCoinInfoVo = new MemberCoinInfoVo();
            memberCoinInfoVo.setName(platformSymbolsCoinEntity.getName());
            arrayList.add(memberCoinInfoVo);
         }
      }
      memberCoinInfoListVo.setMemberCoinInfoVo(arrayList);
      return Result.ok(memberCoinInfoListVo);
   }
   @Override
   public Result memberAvivableCoinInfo(String symbol) {
      //获取用户ID
      Long memberId = LoginUserUtils.getAppLoginUser().getId();
        MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
        if (ObjectUtil.isEmpty(walletCoin)) {
             return Result.fail(MessageSourceUtils.getString("member_service_0087"));
        }
        MemberAvivableCoinInfoVo memberAvivableCoinInfoVo = new MemberAvivableCoinInfoVo();
        memberAvivableCoinInfoVo.setAvailableBalance(walletCoin.getAvailableBalance());
        PlatformFeeSettingEntity feeSetting = platformFeeSettingDao.getFeeSettingByTypeAndSymbol(2,symbol);
        memberAvivableCoinInfoVo.setFee(feeSetting.getFeePrice());
        return Result.ok(memberAvivableCoinInfoVo);
    }
}