| | |
| | | package cc.mrbird.febs.mall.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.enumerates.AgentLevelEnum; |
| | | import cc.mrbird.febs.common.enumerates.DataDictionaryEnum; |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum; |
| | | import cc.mrbird.febs.common.enumerates.*; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.*; |
| | | import cc.mrbird.febs.mall.conversion.MallGoodsConversion; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public FebsResponse register(RegisterDto registerDto) { |
| | | MallMember mallMember = this.baseMapper.selectInfoByAccount(registerDto.getAccount()); |
| | | if (mallMember != null) { |
| | | throw new FebsException("该账号已被占用"); |
| | | } |
| | | |
| | | List<MallMember> mallMembers = this.baseMapper.selectMemberByName(registerDto.getName()); |
| | | if (CollUtil.isNotEmpty(mallMembers)) { |
| | | MallRegisterAppeal registerAppeal = mallRegisterAppealMapper.selectByPhoneAndName(registerDto.getName(), registerDto.getAccount()); |
| | | if (registerAppeal == null || registerAppeal.getStatus() != 1) { |
| | | return new FebsResponse().code(HttpStatus.ACCEPTED).message("用户名已存在"); |
| | | } |
| | | } |
| | | |
| | | String account = registerDto.getAccount(); |
| | | if (!"admin".equals(registerDto.getRegistType())) { |
| | | String code = registerDto.getCode(); |
| | | MallMember mallMember = this.baseMapper.selectInfoByAccount(account); |
| | | if (mallMember != null) { |
| | | throw new FebsException("账号已注册"); |
| | | } |
| | | String code = registerDto.getCode(); |
| | | if(!AppContants.PUBLIC_CODE.equals(code)){ |
| | | boolean flags = commonService.verifyCode(account, code); |
| | | if (!flags) { |
| | | throw new FebsException("验证码错误"); |
| | | } |
| | | } |
| | | |
| | | mallMember = new MallMember(); |
| | | mallMember.setAccountLogin(account); |
| | | mallMember.setPassword(SecureUtil.md5(registerDto.getPassword())); |
| | | |
| | | // 判断账号类型 |
| | | if (AppContants.ACCOUNT_TYPE_MOBILE.equals(registerDto.getType())) { |
| | | mallMember.setPhone(registerDto.getAccount()); |
| | | } else { |
| | | mallMember.setEmail(registerDto.getAccount()); |
| | | } |
| | | |
| | | Integer count = this.baseMapper.selectCount(null); |
| | | if (count != null && count != 0) { |
| | | MallMember inviteMember = this.baseMapper.selectInfoByInviteId(registerDto.getInviteId()); |
| | | if (inviteMember == null) { |
| | | throw new FebsException("邀请码不存在"); |
| | | } |
| | | |
| | | mallMember.setReferrerId(registerDto.getInviteId()); |
| | | |
| | | } |
| | | mallMember.setName(registerDto.getName()); |
| | | mallMember.setPhone(registerDto.getAccount()); |
| | | mallMember.setEmail(registerDto.getAccount()); |
| | | mallMember.setName(account); |
| | | mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE); |
| | | mallMember.setAccountType(MallMember.ACCOUNT_TYPE_NORMAL); |
| | | mallMember.setLevel(AgentLevelEnum.ZERO_LEVEL.getCode()); |
| | | mallMember.setSex("男"); |
| | | mallMember.setBindPhone(registerDto.getAccount()); |
| | | |
| | | mallMember.setBindPhone(account); |
| | | // String inviteId = ShareCodeUtil.toSerialCode(mallMember.getId()); |
| | | // mallMember.setInviteId(inviteId); |
| | | this.baseMapper.insert(mallMember); |
| | | |
| | | String inviteId = ShareCodeUtil.toSerialCode(mallMember.getId()); |
| | | mallMember.setInviteId(inviteId); |
| | | |
| | | //推荐人和推荐人链 |
| | | boolean flag = false; |
| | | String parentId = mallMember.getReferrerId(); |
| | | if (StrUtil.isBlank(parentId)) { |
| | | flag = true; |
| | | } |
| | | String ids = ""; |
| | | while (!flag) { |
| | | if (StrUtil.isBlank(ids)) { |
| | | ids += parentId; |
| | | } else { |
| | | ids += ("," + parentId); |
| | | } |
| | | MallMember parentMember = this.baseMapper.selectInfoByInviteId(parentId); |
| | | if (parentMember == null) { |
| | | break; |
| | | } |
| | | parentId = parentMember.getReferrerId(); |
| | | if (StrUtil.isBlank(parentMember.getReferrerId())) { |
| | | flag = true; |
| | | } |
| | | } |
| | | |
| | | if (StrUtil.isNotBlank(ids)) { |
| | | mallMember.setReferrerIds(ids); |
| | | } |
| | | this.baseMapper.updateById(mallMember); |
| | | |
| | | MallMemberWallet wallet = new MallMemberWallet(); |
| | | wallet.setBalance(BigDecimal.ZERO); |
| | | wallet.setMemberId(mallMember.getId()); |
| | | mallMemberWalletMapper.insert(wallet); |
| | | return new FebsResponse().success().message("注册成功"); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | MallMember mallMember = this.baseMapper.selectInfoByAccountAndPwd(loginDto.getAccount(), md5Pwd); |
| | | if (mallMember == null) { |
| | | throw new FebsException("用户不存在或账号密码错误"); |
| | | throw new FebsException("账号密码错误"); |
| | | } |
| | | |
| | | if (MallMember.ACCOUNT_STATUS_DISABLED.equals(mallMember.getAccountStatus())) { |
| | |
| | | |
| | | @Override |
| | | public FebsResponse forgetPwd(ForgetPwdDto forgetPwdDto) { |
| | | MallMember mallMember = this.baseMapper.selectInfoByAccount(forgetPwdDto.getPhone()); |
| | | // MallMember mallMember = this.baseMapper.selectInfoByAccount(forgetPwdDto.getAccount()); |
| | | Long id = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember mallMember = this.baseMapper.selectById(id); |
| | | |
| | | if (mallMember == null) { |
| | | throw new FebsException("账号不存在"); |
| | | } |
| | | |
| | | boolean b = commonService.verifyCode(forgetPwdDto.getAccount(), forgetPwdDto.getCode()); |
| | | boolean b = commonService.verifyCode(mallMember.getPhone(), forgetPwdDto.getCode()); |
| | | if (!b) { |
| | | throw new FebsException("验证码错误"); |
| | | } |
| | |
| | | mallMember.setPassword(pwd); |
| | | |
| | | this.baseMapper.updateById(mallMember); |
| | | return new FebsResponse().success().message("重置成功"); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse logout() { |
| | | Long id = LoginUserUtil.getLoginUser().getId(); |
| | | redisUtils.del(AppContants.APP_LOGIN_PREFIX + id); |
| | | return new FebsResponse().success().message("退出登录"); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse findMemberInfo() { |
| | | Long id = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember mallMember = this.baseMapper.selectById(id); |
| | | |
| | | MallMemberVo mallMemberVo = MallMemberConversion.INSTANCE.entityToVo(mallMember); |
| | | |
| | | MallMember referMember = this.baseMapper.selectInfoByInviteId(mallMember.getReferrerId()); |
| | | if (referMember != null) { |
| | | mallMemberVo.setReferrerName(referMember.getName()); |
| | | } |
| | | |
| | | if (StrUtil.isNotBlank(mallMember.getTradePassword())) { |
| | | mallMemberVo.setHasTradePwd(1); |
| | | } |
| | | |
| | | MallMemberPayment payment = mallMemberPaymentMapper.selectByMemberId(id); |
| | | if (payment != null) { |
| | | mallMemberVo.setHasPayment(1); |
| | | } |
| | | |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.AGENT_LEVEL, mallMember.getLevel()); |
| | | if (dic != null) { |
| | | mallMemberVo.setLevelName(dic.getDescription()); |
| | | } |
| | | MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(mallMemberVo.getId()); |
| | | mallMemberVo.setBalance(wallet.getBalance()); |
| | | mallMemberVo.setScore(wallet.getScore()); |
| | | mallMemberVo.setPrizeScore(wallet.getPrizeScore()); |
| | | mallMemberVo.setTotalCost(mallOrderInfoMapper.selectTotalAmount(id)); |
| | | return new FebsResponse().success().data(mallMemberVo); |
| | | } |
| | | |
| | |
| | | if (mallMember == null) { |
| | | throw new FebsException("用户不存在"); |
| | | } |
| | | Integer insideWith = mallMember.getInsideWith() == null ? 2 :mallMember.getInsideWith(); |
| | | if (1 != insideWith) { |
| | | throw new FebsException("功能升级中"); |
| | | } |
| | | |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember loginMember = this.baseMapper.selectById(memberId); |
| | |
| | | public BigDecimal canMoney() { |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); |
| | | BigDecimal profit = mallMoneyFlowMapper.selectProfitByDateAndMemberId(memberId); |
| | | |
| | | BigDecimal canMoney = wallet.getCommission(); |
| | | if (profit != null) { |
| | | if(canMoney.compareTo(BigDecimal.ZERO) > 0) { |
| | | canMoney = canMoney.subtract(profit); |
| | | } |
| | | } |
| | | BigDecimal canMoney = wallet.getBalance(); |
| | | return canMoney; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(id); |
| | | commissionVo.setCommission(wallet.getCommission()); |
| | | commissionVo.setCommission(wallet.getBalance()); |
| | | commissionVo.setToday(mallMoneyFlowMapper.selectCommissionIncome(1, new Date(), id)); |
| | | commissionVo.setMonth(mallMoneyFlowMapper.selectCommissionIncome(2, new Date(), id)); |
| | | commissionVo.setTotal(mallMoneyFlowMapper.selectCommissionIncome(null, null, id)); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void addRegisterAppeal(RegisterAppealDto registerAppeal) { |
| | | MallRegisterAppeal isExist = mallRegisterAppealMapper.selectByPhoneAndName(registerAppeal.getName(), registerAppeal.getPhone()); |
| | | if (isExist != null) { |
| | | throw new FebsException("申诉已存在"); |
| | | } |
| | | |
| | | isExist = new MallRegisterAppeal(); |
| | | isExist.setName(registerAppeal.getName()); |
| | | isExist.setPhone(registerAppeal.getPhone()); |
| | | isExist.setStatus(2); |
| | | |
| | | mallRegisterAppealMapper.insert(isExist); |
| | | } |
| | | |
| | | @Override |
| | | public CashOutSettingVo cashOutSetting() { |
| | | CashOutSettingVo cashOutSettingVo = new CashOutSettingVo(); |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.CASHOUT_SETTING.getType(), DataDictionaryEnum.CASHOUT_SETTING.getCode()); |
| | | if (dic != null) { |
| | | cashOutSettingVo = JSONObject.parseObject(dic.getValue(), CashOutSettingVo.class); |
| | | } |
| | | DataDictionaryCustom voucherOnOffDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | GreenScoreEnum.VOUCHER_ON_OFF.getType(), GreenScoreEnum.VOUCHER_ON_OFF.getCode()); |
| | | if(ObjectUtil.isNotEmpty(voucherOnOffDic)){ |
| | | cashOutSettingVo.setVoucherOnOff(voucherOnOffDic.getValue()); |
| | | DataDictionaryCustom voucherPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | GreenScoreEnum.VOUCHER_PERCENT.getType(), GreenScoreEnum.VOUCHER_PERCENT.getCode()); |
| | | if(ObjectUtil.isNotEmpty(voucherPercentDic)){ |
| | | cashOutSettingVo.setVoucherPercent(new BigDecimal(voucherPercentDic.getValue())); |
| | | } |
| | | } |
| | | |
| | | return cashOutSettingVo; |
| | | } |
| | | |
| | |
| | | MallMemberBank mallMemberBank = MallMemberBankConversion.INSTANCE.dtoToentity(addMemberBankDto); |
| | | mallMemberBank.setMemberId(member.getId()); |
| | | mallMemberBankMapper.insert(mallMemberBank); |
| | | return new FebsResponse().success(); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | Long id = updateMemberBankDto.getId(); |
| | | MallMemberBank mallMemberBank = mallMemberBankMapper.selectById(id); |
| | | mallMemberBank.setName(updateMemberBankDto.getName()); |
| | | mallMemberBank.setIdType(updateMemberBankDto.getIdType()); |
| | | mallMemberBank.setIdCardNum(updateMemberBankDto.getIdCardNum()); |
| | | mallMemberBank.setBankNo(updateMemberBankDto.getBankNo()); |
| | | mallMemberBank.setPhone(updateMemberBankDto.getPhone()); |
| | |
| | | mallMemberBankMapper.deleteById(id); |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse findBankName() { |
| | | List<String> bankNameList = new ArrayList<>(); |
| | | List<DataDictionaryCustom> typeBank = dataDictionaryCustomMapper.selectDicByType("TYPE_BANK"); |
| | | if(CollUtil.isNotEmpty(typeBank)){ |
| | | bankNameList = typeBank.stream().map(DataDictionaryCustom::getValue).collect(Collectors.toList()); |
| | | } |
| | | return new FebsResponse().success().data(bankNameList); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse pwdForget(ForgetPwdDto forgetPwdDto) { |
| | | MallMember mallMember = this.baseMapper.selectInfoByAccount(forgetPwdDto.getAccount()); |
| | | if(ObjectUtil.isEmpty(mallMember)){ |
| | | throw new FebsException("账号不存在"); |
| | | } |
| | | |
| | | boolean b = commonService.verifyCode(forgetPwdDto.getAccount(), forgetPwdDto.getCode()); |
| | | if (!b) { |
| | | throw new FebsException("验证码错误"); |
| | | } |
| | | |
| | | String pwd = SecureUtil.md5(forgetPwdDto.getPassword()); |
| | | mallMember.setPassword(pwd); |
| | | |
| | | this.baseMapper.updateById(mallMember); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | } |