| | |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberService; |
| | | import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; |
| | | import cc.mrbird.febs.mall.service.ICommonService; |
| | | import cc.mrbird.febs.mall.vo.MallMemberVo; |
| | | import cc.mrbird.febs.mall.vo.MoneyFlowVo; |
| | | import cc.mrbird.febs.mall.vo.RankListVo; |
| | | import cc.mrbird.febs.mall.vo.TeamListVo; |
| | | import cc.mrbird.febs.mall.vo.*; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | private final IApiMallMemberWalletService walletService; |
| | | private final MallMemberPaymentMapper mallMemberPaymentMapper; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final MallShopApplyMapper mallShopApplyMapper; |
| | | private final MallRegisterAppealMapper mallRegisterAppealMapper; |
| | | |
| | | |
| | | @Value("${spring.profiles.active}") |
| | | private String active; |
| | |
| | | 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(); |
| | |
| | | mallMember.setReferrerId(registerDto.getInviteId()); |
| | | |
| | | } |
| | | mallMember.setName(registerDto.getAccount()); |
| | | mallMember.setName(registerDto.getName()); |
| | | mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE); |
| | | mallMember.setAccountType(MallMember.ACCOUNT_TYPE_NORMAL); |
| | | mallMember.setLevel(AgentLevelEnum.ZERO_LEVEL.name()); |
| | | mallMember.setLevel(AgentLevelEnum.FIRST_LEVEL.name()); |
| | | mallMember.setSex("男"); |
| | | mallMember.setBindPhone(registerDto.getAccount()); |
| | | |
| | | this.baseMapper.insert(mallMember); |
| | | |
| | |
| | | MallMember mallMember = this.baseMapper.selectById(memberId); |
| | | |
| | | List<TeamListVo> list = this.baseMapper.selectTeamListByInviteId(mallMember.getInviteId()); |
| | | BigDecimal ownAmount = this.baseMapper.selectOwnOrderAmountByInviteId(mallMember.getInviteId()); |
| | | // BigDecimal ownAmount = this.baseMapper.selectOwnOrderAmountByInviteId(mallMember.getInviteId()); |
| | | // TeamListVo own = new TeamListVo(); |
| | | // own.setCreatedTime(mallMember.getCreatedTime()); |
| | | // own.setAmount(ownAmount); |
| | | // own.setName(mallMember.getName()); |
| | | // own.setPhone(mallMember.getPhone()); |
| | | // own.setInviteId(mallMember.getInviteId()); |
| | | // own.setIsCurrent(1); |
| | | // own.setCnt(this.baseMapper.selectOwnCntByInviteId(mallMember.getInviteId())); |
| | | // own.setOrderCnt(this.baseMapper.selectOwnOrderCntByInviteId(mallMember.getInviteId())); |
| | | // own.setId(mallMember.getId()); |
| | | |
| | | TeamListVo own = new TeamListVo(); |
| | | own.setCreatedTime(mallMember.getCreatedTime()); |
| | | own.setAmount(ownAmount); |
| | | own.setName(mallMember.getName()); |
| | | own.setPhone(mallMember.getPhone()); |
| | | own.setInviteId(mallMember.getInviteId()); |
| | | own.setIsCurrent(1); |
| | | own.setCnt(this.baseMapper.selectOwnCntByInviteId(mallMember.getInviteId())); |
| | | own.setOrderCnt(this.baseMapper.selectOwnOrderCntByInviteId(mallMember.getInviteId())); |
| | | own.setId(mallMember.getId()); |
| | | list.add(0, own); |
| | | return new FebsResponse().success().data(list); |
| | | MyTeamVo myTeamVo = new MyTeamVo(); |
| | | myTeamVo.setTeam(list); |
| | | myTeamVo.setMyAchieve(this.baseMapper.selectAchieveByMemberId(mallMember.getInviteId(), 1)); |
| | | myTeamVo.setMyTeamAchieve(this.baseMapper.selectAchieveByMemberId(mallMember.getInviteId(), 2)); |
| | | myTeamVo.setMyTeamCnt(list.size()); |
| | | return new FebsResponse().success().data(myTeamVo); |
| | | } |
| | | |
| | | @Override |
| | | public MyTeamVo teamListForMine(TeamListDto teamListDto) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | walletService.addBalance(transferDto.getAmount(), mallMember.getId()); |
| | | this.addMoneyFlow(mallMember.getId(), transferDto.getAmount(), MoneyFlowTypeEnum.TRANSFER.getValue(), orderNo, null, null, memberId, null, FlowTypeEnum.BALANCE.getValue()); |
| | | } |
| | | |
| | | @Override |
| | | public void withdrawal(WithdrawalDto withdrawalDto) { |
| | | Long memberId = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember mallMember = this.baseMapper.selectById(memberId); |
| | | if (StrUtil.isBlank(mallMember.getTradePassword())) { |
| | | throw new FebsException("未设置支付密码"); |
| | | } |
| | | |
| | | if (!mallMember.getTradePassword().equals(SecureUtil.md5(withdrawalDto.getTradePwd()))) { |
| | | throw new FebsException("支付密码错误"); |
| | | } |
| | | |
| | | if (withdrawalDto.getAmount().compareTo(BigDecimal.valueOf(100)) < 0) { |
| | | throw new FebsException("最小提现金额为100"); |
| | | } |
| | | |
| | | // MallMemberPayment payment = mallMemberPaymentMapper.selectByMemberId(memberId); |
| | | // if (payment == null) { |
| | | // throw new FebsException("未设置收款方式"); |
| | | // } |
| | | |
| | | BigDecimal profit = mallMoneyFlowMapper.selectProfitByDateAndMemberId(memberId); |
| | | MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); |
| | | if (profit != null) { |
| | | // 可提现 |
| | | BigDecimal canMoney = wallet.getCommission().subtract(profit); |
| | | |
| | | if(withdrawalDto.getAmount().compareTo(canMoney) > 0) { |
| | | throw new FebsException("提现金额不足"); |
| | | } |
| | | } |
| | | |
| | | walletService.reduceCommission(withdrawalDto.getAmount(), memberId); |
| | | String orderNo = MallUtils.getOrderNum("W"); |
| | | this.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1, FlowTypeEnum.COMMISSION.getValue()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | public MallMember findMemberInfoByAccount(String phone) { |
| | | return this.baseMapper.selectInfoByAccount(phone); |
| | | } |
| | | |
| | | @Override |
| | | public MyCommissionVo myCommission() { |
| | | Long id = LoginUserUtil.getLoginUser().getId(); |
| | | MallMember mallMember = this.baseMapper.selectById(id); |
| | | |
| | | MyCommissionVo commissionVo = MallMemberConversion.INSTANCE.entityToCommissionVo(mallMember); |
| | | |
| | | MallMember referMember = this.baseMapper.selectInfoByInviteId(mallMember.getReferrerId()); |
| | | if (referMember != null) { |
| | | commissionVo.setReferrerName(referMember.getName()); |
| | | commissionVo.setAvatar(referMember.getAvatar()); |
| | | } |
| | | |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.AGENT_LEVEL, mallMember.getLevel()); |
| | | if (dic != null) { |
| | | commissionVo.setLevelName(dic.getDescription()); |
| | | } |
| | | |
| | | MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(id); |
| | | commissionVo.setCommission(wallet.getCommission()); |
| | | commissionVo.setToday(mallMoneyFlowMapper.selectCommissionIncome(1, new Date(), id)); |
| | | commissionVo.setMonth(mallMoneyFlowMapper.selectCommissionIncome(2, new Date(), id)); |
| | | commissionVo.setTotal(mallMoneyFlowMapper.selectCommissionIncome(null, null, id)); |
| | | commissionVo.setWaitCommission(BigDecimal.ZERO); |
| | | return commissionVo; |
| | | } |
| | | |
| | | @Override |
| | | public void shopApply(ShopApplyDto shopApplyDto) { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | |
| | | MallShopApply hasApply = mallShopApplyMapper.selectNewestApplyByMemberId(member.getId()); |
| | | if (hasApply != null) { |
| | | if (!hasApply.getStatus().equals(MallShopApply.APPLY_DISAGREE)) { |
| | | throw new FebsException("审核中或审核已通过"); |
| | | } |
| | | } |
| | | |
| | | MallShopApply mallShopApply = new MallShopApply(); |
| | | BeanUtil.copyProperties(shopApplyDto, mallShopApply); |
| | | |
| | | mallShopApply.setStatus(MallShopApply.APPLY_ING); |
| | | mallShopApply.setMemberId(member.getId()); |
| | | mallShopApplyMapper.insert(mallShopApply); |
| | | } |
| | | |
| | | @Override |
| | | public MallShopApply findNewestApply() { |
| | | MallMember member = LoginUserUtil.getLoginUser(); |
| | | |
| | | return mallShopApplyMapper.selectNewestApplyByMemberId(member.getId()); |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | } |