xiaoyong931011
2020-06-08 f97a701a3cceed8cb86fce14124c1c67a0f59ae0
src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java
@@ -13,6 +13,8 @@
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.common.system.dto.RegisterDto;
import com.xcong.excoin.common.system.service.CommonService;
import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao;
import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange;
import com.xcong.excoin.modules.member.dao.*;
import com.xcong.excoin.modules.member.entity.*;
import com.xcong.excoin.modules.member.parameter.dto.MemberAddCoinAddressDto;
@@ -23,11 +25,28 @@
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.MemberSubmitCoinApplyDto;
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.dto.MemberUpdateTradersPwdTimeDto;
import com.xcong.excoin.modules.member.parameter.vo.*;
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;
@@ -59,6 +78,9 @@
    @Resource
    private MemberWalletAgentDao memberWalletAgentDao;
    @Resource
    MemberAccountMoneyChangeDao memberAccountMoneyChangeDao;
    @Resource
    private MemberWalletContractDao memberWalletContractDao;
@@ -82,10 +104,16 @@
    PlatformSymbolsCoinDao platformSymbolsCoinDao;
    
    @Resource
    PlatformFeeSettingDao platformFeeSettingDao;
    @Resource
    MemberCoinAddressDao memberCoinAddressDao;
    
    @Resource
    private CommonService commonservice;
    @Resource
    MemberCoinWithdrawDao memberCoinWithdrawDao;
    @Resource
    private MemberWalletContractSimulateDao memberWalletContractSimulateDao;
@@ -435,7 +463,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);
@@ -444,7 +471,6 @@
      memberPaymentMethodEntity.setPaymentQrcode(paymentQrcode);
      memberPaymentMethodEntity.setPaymentType(paymentType);
      memberPaymentMethodEntity.setSubBank(subBank);
      memberPaymentMethodEntity.setIsDefualt(isDefualt);
      memberPaymentMethodDao.insert(memberPaymentMethodEntity);
      return Result.ok(MessageSourceUtils.getString("member_service_0024"));
    }
@@ -650,6 +676,104 @@
   }
   @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);
      }else {
         memberPersonCenterInfoVo.setPhone(0);
      }
      if(StrUtil.isNotEmpty(member.getEmail())) {
         memberPersonCenterInfoVo.setEmail(1);
      }else {
         memberPersonCenterInfoVo.setEmail(0);
      }
      if(StrUtil.isNotEmpty(member.getTradePassword())) {
         memberPersonCenterInfoVo.setTradePassword(1);
      }else {
         memberPersonCenterInfoVo.setTradePassword(0);
      }
      Integer tradeAgingSetting = member.getTradeAgingSetting();
      if(tradeAgingSetting != null && tradeAgingSetting == MemberPersonCenterInfoVo.PWD_NEED_FORVER) {
         memberPersonCenterInfoVo.setTradeAgingSetting(MemberPersonCenterInfoVo.PWD_NEED_FORVER);
      }else {
         memberPersonCenterInfoVo.setTradeAgingSetting(MemberPersonCenterInfoVo.PWD_NEED_NO);
      }
      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);
        if(ObjectUtil.isEmpty(feeSetting)) {
           return Result.fail(MessageSourceUtils.getString("member_service_0087"));
        }
        memberAvivableCoinInfoVo.setFee(feeSetting.getFeePrice());
        return Result.ok(memberAvivableCoinInfoVo);
    }
   @Override
   public NeedMoneyMemberVo selectFriendRelationUserByMemberId(Long memberId){
      return memberDao.selectFriendRelationUserByMemberId(memberId);
   }
@@ -664,5 +788,111 @@
      return memberDao.selectMemberInfoByInviteId(inviteId);
   }
   @Override
   @Transactional
   public Result memberUpdateTradersPwdTime(MemberUpdateTradersPwdTimeDto memberUpdateTradersPwdTimeDto) {
      //获取用户ID
      Long memberId = LoginUserUtils.getAppLoginUser().getId();
      MemberEntity member = memberDao.selectById(memberId);
      member.setTradeAgingSetting(memberUpdateTradersPwdTimeDto.getTradeAgingSetting());
      memberDao.updateById(member);
      return Result.ok("success");
   }
   @Override
   public Result memberSubmitCoinApply(@Valid MemberSubmitCoinApplyDto memberSubmitCoinApplyDto) {
      //获取用户ID
      Long memberId = LoginUserUtils.getAppLoginUser().getId();
      MemberEntity member = memberDao.selectById(memberId);
                    if (member.getCertifyStatus() != MemberEntity.CERTIFY_STATUS_Y) {
                        return Result.fail(MessageSourceUtils.getString("member_service_0077"));
                    }
                    if (StrUtil.isEmpty(member.getTradePassword())) {
                        return Result.fail(MessageSourceUtils.getString("member_service_0081"));
                    }
                    if(member.getTradePassword() == null) {
                       return Result.fail(MessageSourceUtils.getString("member_service_0082"));
                    }
                    if (!member.getTradePassword().equals(SecureUtil.md5(memberSubmitCoinApplyDto.getTradePassword()))) {
                        return Result.fail(MessageSourceUtils.getString("member_service_0082"));
                    }
                  boolean flag = commonservice.verifyCode(memberSubmitCoinApplyDto.getAccount(), memberSubmitCoinApplyDto.getCode());
                    if (flag) {
                       MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, memberSubmitCoinApplyDto.getSymbol());
                       BigDecimal availableBalance = walletCoin.getAvailableBalance();
                       BigDecimal coinNumber = memberSubmitCoinApplyDto.getCoinNumber().add(memberSubmitCoinApplyDto.getFeeAmount());
                       if(availableBalance.compareTo(BigDecimal.ZERO) > 0
                             && availableBalance.compareTo(coinNumber) > 0) {
                          //新增提币记录
                          MemberCoinWithdrawEntity memberCoinWithdrawEntity = new MemberCoinWithdrawEntity();
                          memberCoinWithdrawEntity.setAddress(memberSubmitCoinApplyDto.getAddress());
                          memberCoinWithdrawEntity.setAmount(coinNumber);
                          memberCoinWithdrawEntity.setFeeAmount(memberSubmitCoinApplyDto.getFeeAmount());
                          memberCoinWithdrawEntity.setSymbol(memberSubmitCoinApplyDto.getSymbol());
                          memberCoinWithdrawEntity.setMemberId(memberId);
                          memberCoinWithdrawEntity.setStatus(MemberCoinWithdrawEntity.STATUS_DOING);
                          Map<String,Object> columnMap = new HashMap<>();
                          columnMap.put("symbol", memberSubmitCoinApplyDto.getSymbol());
                          columnMap.put("address", memberSubmitCoinApplyDto.getAddress());
                          List<MemberCoinAddressEntity> selectByMap = memberCoinAddressDao.selectByMap(columnMap);
                          if(CollUtil.isEmpty(selectByMap)) {
                             memberCoinWithdrawEntity.setIsInside(MemberCoinWithdrawEntity.ISINSIDE_NO);
                          }else {
                             memberCoinWithdrawEntity.setIsInside(MemberCoinWithdrawEntity.ISINSIDE_YES);
                          }
                          memberCoinWithdrawDao.insert(memberCoinWithdrawEntity);
                          BigDecimal subtract = walletCoin.getAvailableBalance().subtract(coinNumber);
                          walletCoin.setAvailableBalance(subtract);
                          BigDecimal add = walletCoin.getFrozenBalance().add(coinNumber);
                            walletCoin.setFrozenBalance(add);
                            memberWalletCoinDao.updateById(walletCoin);
                            MemberAccountMoneyChange accountRecord = new MemberAccountMoneyChange();
                            accountRecord.setContent("提币");
                            accountRecord.setMemberId(memberId);
                            accountRecord.setAmount(memberSubmitCoinApplyDto.getCoinNumber());
                            accountRecord.setStatus(MemberAccountMoneyChange.STATUS_WAIT_INTEGER);
                            accountRecord.setSymbol(memberSubmitCoinApplyDto.getSymbol());
                            accountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_COIN);
                            memberAccountMoneyChangeDao.insert(accountRecord);
                         /**
                          *  TODO dingtalk
                      Constant.excutor.execute(new Runnable() {
                         @Override
                         public void run() {
                            DingTalkUtils.sendActionCard(3);
                         }
                      });
                      */
                            return Result.ok(MessageSourceUtils.getString("member_service_0086"));
                       }else {
                          return Result.fail(MessageSourceUtils.getString("order_service_0040"));
                       }
                    }else {
                       return Result.fail(MessageSourceUtils.getString("member_service_0039"));
                    }
        }
   @Override
   public Result getMemberAccountInfo(String account,int type) {
      Map<String, Object> hashMap = new HashMap<>();
      if(type == 1) {
         hashMap.put("phone", account);
      }else {
         hashMap.put("email", account);
      }
      List<MemberEntity> member = memberDao.selectByMap(hashMap);
      if (CollUtil.isEmpty(member)) {
            return Result.fail(MessageSourceUtils.getString("home_service_0003"));
        }
      return Result.ok("");
   }
}