|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.common.entity.FebsResponse; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.AgentLevelEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum; | 
|---|
|  |  |  | import cc.mrbird.febs.common.exception.FebsException; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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.collection.CollUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.IdUtil; | 
|---|
|  |  |  | import cn.hutool.core.util.ObjectUtil; | 
|---|
|  |  |  | 
|---|
|  |  |  | private final IApiMallMemberWalletService walletService; | 
|---|
|  |  |  | private final MallMemberPaymentMapper mallMemberPaymentMapper; | 
|---|
|  |  |  | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${spring.profiles.active}") | 
|---|
|  |  |  | private String active; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, String description, String remark, Long rtMemberId, Integer status) { | 
|---|
|  |  |  | public void addMoneyFlow(Long memberId, BigDecimal amount, Integer type, String orderNo, String description, String remark, Long rtMemberId, Integer status, Integer flowType) { | 
|---|
|  |  |  | MallMoneyFlow flow = new MallMoneyFlow(); | 
|---|
|  |  |  | flow.setMemberId(memberId); | 
|---|
|  |  |  | flow.setAmount(amount); | 
|---|
|  |  |  | 
|---|
|  |  |  | flow.setRemark(remark); | 
|---|
|  |  |  | flow.setRtMemberId(rtMemberId); | 
|---|
|  |  |  | flow.setStatus(status); | 
|---|
|  |  |  | flow.setFlowType(flowType); | 
|---|
|  |  |  | mallMoneyFlowMapper.insert(flow); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | walletService.reduceBalance(transferDto.getAmount(), memberId); | 
|---|
|  |  |  | String orderNo = MallUtils.getOrderNum("T"); | 
|---|
|  |  |  | this.addMoneyFlow(memberId, transferDto.getAmount().negate(), MoneyFlowTypeEnum.TRANSFER.getValue(), orderNo, null, null, mallMember.getId(), null); | 
|---|
|  |  |  | this.addMoneyFlow(memberId, transferDto.getAmount().negate(), MoneyFlowTypeEnum.TRANSFER.getValue(), orderNo, null, null, mallMember.getId(), null, FlowTypeEnum.BALANCE.getValue()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | walletService.addBalance(transferDto.getAmount(), mallMember.getId()); | 
|---|
|  |  |  | this.addMoneyFlow(mallMember.getId(), transferDto.getAmount(), MoneyFlowTypeEnum.TRANSFER.getValue(), orderNo, null, null, memberId, null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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.getBalance().subtract(profit); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(withdrawalDto.getAmount().compareTo(canMoney) > 0) { | 
|---|
|  |  |  | throw new FebsException("提现金额不足"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | walletService.reduceBalance(withdrawalDto.getAmount(), memberId); | 
|---|
|  |  |  | String orderNo = MallUtils.getOrderNum("W"); | 
|---|
|  |  |  | this.addMoneyFlow(memberId, withdrawalDto.getAmount().negate(), MoneyFlowTypeEnum.WITHDRAWAL.getValue(), orderNo, null, null, null, 1); | 
|---|
|  |  |  | this.addMoneyFlow(mallMember.getId(), transferDto.getAmount(), MoneyFlowTypeEnum.TRANSFER.getValue(), orderNo, null, null, memberId, null, FlowTypeEnum.BALANCE.getValue()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | member.setCreatedTime(new Date()); | 
|---|
|  |  |  | IPage<MallMember> list = this.baseMapper.selectRankListInPage(page, member); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MallMember> records = list.getRecords(); | 
|---|
|  |  |  | if (CollUtil.isNotEmpty(records)) { | 
|---|
|  |  |  | BigDecimal amount = records.get(records.size() - 1).getAmount(); | 
|---|
|  |  |  | page.setSize(999); | 
|---|
|  |  |  | member.setAmount(amount); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | IPage<MallMember> amountList = this.baseMapper.selectRankListInPage(page, member); | 
|---|
|  |  |  | if (CollUtil.isNotEmpty(amountList.getRecords())) { | 
|---|
|  |  |  | Map<Long, Object> map = new HashMap<>(); | 
|---|
|  |  |  | for (MallMember record : records) { | 
|---|
|  |  |  | map.put(record.getId(), record); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (MallMember record : amountList.getRecords()) { | 
|---|
|  |  |  | if (map.get(record.getId()) == null) { | 
|---|
|  |  |  | records.add(record); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return records; | 
|---|
|  |  |  | return list.getRecords(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|