xiaoyong931011
2023-04-24 d7f57903262d8a0db7239fde71a8b7abc48df852
src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java
@@ -2,9 +2,7 @@
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
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.enumerates.*;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.common.utils.LoginUserUtil;
import cc.mrbird.febs.common.utils.MallUtils;
@@ -16,6 +14,8 @@
import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.mall.vo.*;
import cc.mrbird.febs.pay.model.SinglePayDto;
import cc.mrbird.febs.pay.service.UnipayService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
@@ -58,11 +58,14 @@
    private final IApiMallMemberWalletService iApiMallMemberWalletService;
    private final AppVersionMapper appVersionMapper;
    private final MallMemberWithdrawMapper mallMemberWithdrawMapper;
    private final MallNewsInfoMapper mallNewsInfoMapper;
    private final MallShopApplyMapper mallShopApplyMapper;
    private final IMallMoneyFlowService mallMoneyFlowService;
    private final UnipayService unipayService;
    private final MallMemberBankMapper mallMemberBankMapper;
    @Override
    public IPage<MallMember> getMallMemberList(MallMember mallMember, QueryRequest request) {
@@ -96,6 +99,26 @@
    }
    @Override
    public void changeIdentity(Integer type, Long id, Integer value) {
        MallMember mallMember = mallMemberMapper.selectById(id);
        if(mallMember == null) {
            throw new FebsException("参数错误");
        }
        if (type == 1) {
            mallMember.setDirector(value);
        } else if (type == 2){
            mallMember.setStoreMaster(value);
        }else if (type == 3){
            mallMember.setPartner(value);
        } else {
            throw new FebsException("参数错误");
        }
        this.baseMapper.updateById(mallMember);
    }
    @Override
    public MallMemberVo getMallMemberInfoById(long id) {
        MallMemberVo mallMemberVo = mallMemberMapper.getMallMemberInfoById(id);
        return mallMemberVo;
@@ -125,41 +148,85 @@
    @Override
    @Transactional
    public FebsResponse chargeAgree(Long id) {
        MallMoneyFlow mallMoneyFlow = mallMoneyFlowMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallMoneyFlow)){
        MallMemberWithdraw mallMemberWithdraw = mallMemberWithdrawMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallMemberWithdraw)){
            return new FebsResponse().fail().message("系统繁忙,请刷新后重试");
        }
        if(1 != mallMoneyFlow.getStatus()){
        if(1 != mallMemberWithdraw.getStatus()){
            return new FebsResponse().fail().message("当前状态不是提现中");
        }
        mallMoneyFlow.setStatus(2);
        mallMoneyFlowMapper.updateById(mallMoneyFlow);
        Long wtihdrawTypeId = mallMemberWithdraw.getWtihdrawTypeId();
        MallMemberBank mallMemberBank = mallMemberBankMapper.selectById(wtihdrawTypeId);
        if(ObjectUtil.isEmpty(mallMemberBank)){
            return new FebsResponse().fail().message("提现银行卡已删除");
        }
        mallMemberWithdraw.setStatus(2);
        mallMemberWithdrawMapper.updateById(mallMemberWithdraw);
        QueryWrapper<MallMoneyFlow> flowQueryWrapper = new QueryWrapper<>();
        flowQueryWrapper.eq("order_no",mallMemberWithdraw.getWithdrawNo());
        flowQueryWrapper.eq("type",MoneyFlowTypeEnum.WITHDRAWAL.getValue());
        MallMoneyFlow mallMoneyFlow = mallMoneyFlowMapper.selectOne(flowQueryWrapper);
        if(ObjectUtil.isNotEmpty(mallMoneyFlow)){
            mallMoneyFlow.setStatus(2);
            mallMoneyFlowMapper.updateById(mallMoneyFlow);
        }
        /**
         * 调用汇聚代付
         */
//        SinglePayDto singlePayDto = new SinglePayDto();
//        singlePayDto.setMerchantOrderNo(mallMemberWithdraw.getWithdrawNo());
//        singlePayDto.setReceiverAccountNoEncBankNo(mallMemberBank.getBankNo());
//        singlePayDto.setReceiverAccountNoEncName(mallMemberBank.getName());
//        singlePayDto.setReceiverAccountType("201");
//        BigDecimal paidAmount = mallMemberWithdraw.getAmount().subtract(mallMemberWithdraw.getAmountFee()).setScale(2, BigDecimal.ROUND_DOWN);
//        singlePayDto.setPaidAmount(paidAmount);
//        singlePayDto.setCurrency("201");
//        singlePayDto.setIsChecked("202");
//        singlePayDto.setPaidDesc("用户提现");
//        singlePayDto.setPaidUse("202");
//        String singlePayRep = unipayService.singlePay(singlePayDto);
//        if(!mallMemberWithdraw.getWithdrawNo().equals(singlePayRep)){
//            return new FebsResponse().fail().message("提现失败,请稍后查看错误信息一览");
//        }
        return new FebsResponse().success();
    }
    @Override
    @Transactional
    public FebsResponse chargeDisagree(Long id) {
        MallMoneyFlow mallMoneyFlow = mallMoneyFlowMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallMoneyFlow)){
        MallMemberWithdraw mallMemberWithdraw = mallMemberWithdrawMapper.selectById(id);
        if(ObjectUtil.isEmpty(mallMemberWithdraw)){
            return new FebsResponse().fail().message("系统繁忙,请刷新后重试");
        }
        if(1 != mallMoneyFlow.getStatus()){
        if(1 != mallMemberWithdraw.getStatus()){
            return new FebsResponse().fail().message("当前状态不是提现中");
        }
        mallMemberWithdraw.setStatus(3);
        mallMemberWithdrawMapper.updateById(mallMemberWithdraw);
        QueryWrapper<MallMoneyFlow> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("order_no",mallMemberWithdraw.getWithdrawNo());
        objectQueryWrapper.eq("type",MoneyFlowTypeEnum.WITHDRAWAL.getValue());
        MallMoneyFlow mallMoneyFlow = mallMoneyFlowMapper.selectOne(objectQueryWrapper);
        mallMoneyFlow.setStatus(3);
        mallMoneyFlowMapper.updateById(mallMoneyFlow);
        //用户钱包增加对应的余额
        iApiMallMemberWalletService.addBalance(mallMoneyFlow.getAmount().negate(),mallMoneyFlow.getMemberId());
        //用户增加对应的余额
        iApiMallMemberWalletService.add(mallMemberWithdraw.getAmount(),mallMemberWithdraw.getMemberId(),"balance");
        return new FebsResponse().success();
    }
    @Override
    public AdminMallMemberPaymentVo getMallMemberPaymentInfoByFlowId(long id) {
        AdminMallMemberPaymentVo adminMallMemberPaymentVo = new AdminMallMemberPaymentVo();
        MallMoneyFlow mallMoneyFlow = mallMoneyFlowMapper.selectById(id);
        AdminMallMemberPaymentVo adminMallMemberPaymentVoa = mallMemberPaymentMapper.getMallMemberPaymentInfoByMemberId(mallMoneyFlow.getMemberId());
        MallMemberWithdraw mallMemberWithdraw = mallMemberWithdrawMapper.selectById(id);
        AdminMallMemberPaymentVo adminMallMemberPaymentVoa = mallMemberPaymentMapper.getMallMemberPaymentInfoByMemberId(mallMemberWithdraw.getMemberId());
        if(ObjectUtil.isNotEmpty(adminMallMemberPaymentVoa)){
            adminMallMemberPaymentVo = adminMallMemberPaymentVoa;
        }
@@ -215,6 +282,15 @@
    @Override
    public List<AdminAgentLevelOptionTreeVo> getAgentLevelOption() {
        List<AdminAgentLevelOptionTreeVo> agentLevelOption = dataDictionaryCustomMapper.getAgentLevelOption();
        AdminAgentLevelOptionTreeVo adminAgentLevelOptionTreeVo = new AdminAgentLevelOptionTreeVo();
        adminAgentLevelOptionTreeVo.setId(MemberLevelEnum.NORMAL.getType());
        adminAgentLevelOptionTreeVo.setName("普通会员");
        agentLevelOption.add(adminAgentLevelOptionTreeVo);
        AdminAgentLevelOptionTreeVo adminAgentLevelOptionTreeVos = new AdminAgentLevelOptionTreeVo();
        adminAgentLevelOptionTreeVos.setId(MemberLevelEnum.V_DIRECTOR.getType());
        adminAgentLevelOptionTreeVos.setName("董事");
        agentLevelOption.add(adminAgentLevelOptionTreeVos);
        return dataDictionaryCustomMapper.getAgentLevelOption();
    }
@@ -322,15 +398,33 @@
        }
        BigDecimal bigDecimal = mallSystemPayDto.getAddBalance();
        boolean isReduce = false;
        if(bigDecimal.compareTo(BigDecimal.ZERO) <= 0){
            return new FebsResponse().fail().message("拨付数目需要大于0");
            isReduce = true;
        }
        MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
        mallMemberWallet.setBalance(mallMemberWallet.getBalance().add(bigDecimal));
        mallMemberWalletMapper.updateBalanceWithId(mallMemberWallet);
        Integer type = mallSystemPayDto.getType();
        String filedType = "";
        if (type == 1) {
            filedType = "balance";
        } else if (type == 2) {
            filedType = "score";
        } else if (type == 3) {
            filedType = "prizeScore";
        } else {
            throw new FebsException("参数错误");
        }
        mallMoneyFlowService.addMoneyFlow(memberId, bigDecimal, MoneyFlowTypeEnum.SYSTEM.getValue(), null, FlowTypeEnum.BALANCE.getValue());
        if (isReduce) {
            int i = iApiMallMemberWalletService.reduce(mallSystemPayDto.getAddBalance().negate(), mallSystemPayDto.getId(), filedType);
            if (i == 2) {
                throw new FebsException("剩余数量不足");
            }
        } else {
            iApiMallMemberWalletService.add(mallSystemPayDto.getAddBalance(), mallSystemPayDto.getId(), filedType);
        }
        mallMoneyFlowService.addMoneyFlow(memberId, bigDecimal, MoneyFlowTypeEnum.SYSTEM.getValue(), null, type);
        return new FebsResponse().success();
    }
@@ -366,6 +460,32 @@
    }
    @Override
    public void resetPwd(String ids, Integer type) {
        if (StrUtil.isEmpty(ids)) {
            throw new FebsException("参数错误");
        }
        List<String> idList = StrUtil.split(ids, ',');
        for (String s : idList) {
            Long id = Long.parseLong(s);
            MallMember member = new MallMember();
            member.setId(id);
            member.setCreatedTime(null);
            // 重置交易密码
            if (type == 1) {
                String payPwd = SecureUtil.md5("123456");
                member.setTradePassword(payPwd);
                // 重置登录密码
            } else {
                String pwd = SecureUtil.md5("a123456");
                member.setPassword(pwd);
            }
            this.baseMapper.updateById(member);
        }
    }
    @Override
    public IPage<MallDataVo> getMallDataList(MallMember mallMember, QueryRequest request) {
        Page<MallDataVo> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<MallDataVo> mallDataVos = this.baseMapper.getMallDataListInPage(page, mallMember);
@@ -390,6 +510,10 @@
        if (!MallShopApply.APPLY_ING.equals(apply.getStatus())) {
            throw new FebsException("申请已审核, 请勿重复操作");
        }
        MallMember member = mallMemberMapper.selectById(apply.getMemberId());
        member.setStoreMaster(1);
        mallMemberMapper.updateById(member);
        apply.setStatus(MallShopApply.APPLY_AGREE);
        mallShopApplyMapper.updateById(apply);
@@ -458,4 +582,91 @@
        mallMemberWalletMapper.updateById(mallMemberWallet);
        return new FebsResponse().success();
    }
    @Override
    public MallMember findByInviteId(String inviteId) {
        return this.baseMapper.selectInfoByInviteId(inviteId);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void modifyReferer(MallMember member) {
        MallMember referer = this.baseMapper.selectInfoByInviteId(member.getReferrerId());
        if (referer == null) {
            throw new FebsException("推荐人不存在");
        }
        String refererId = member.getReferrerId();
        member = this.baseMapper.selectById(member.getId());
        String beforeReferer = member.getReferrerId();
        member.setReferrerId(refererId);
        String refererIds = refererIds(refererId);
        member.setReferrerIds(refererIds);
        this.baseMapper.updateById(member);
        List<MallMember> childs = this.baseMapper.selectByRefererId(member.getInviteId());
        if (CollUtil.isEmpty(childs)) {
            return;
        }
        for (MallMember child : childs) {
            child.setReferrerIds(member.getInviteId() + "," + refererIds);
            this.baseMapper.updateById(child);
        }
    }
    @Override
    public void updateShopApply(MallShopApply apply) {
        MallShopApply mallShopApply = mallShopApplyMapper.selectById(apply.getId());
        mallShopApply.setName(apply.getName());
        mallShopApply.setPhone(apply.getPhone());
        mallShopApply.setIdcard(apply.getIdcard());
        mallShopApply.setBusinessLicense(apply.getBusinessLicense());
        mallShopApply.setSaleArea(apply.getSaleArea());
        mallShopApply.setShopName(apply.getShopName());
        mallShopApplyMapper.updateById(mallShopApply);
    }
    @Override
    public AdminMallMemberPaymentVo getMallBankInfoById(long id) {
        MallMemberWithdraw mallMemberWithdraw = mallMemberWithdrawMapper.selectById(id);
        Long wtihdrawTypeId = mallMemberWithdraw.getWtihdrawTypeId();
        MallMemberBank mallMemberBank = mallMemberBankMapper.selectById(wtihdrawTypeId);
        AdminMallMemberPaymentVo adminMallMemberPaymentVo = new AdminMallMemberPaymentVo();
        if(ObjectUtil.isNotEmpty(mallMemberBank)){
            adminMallMemberPaymentVo.setBankNo(mallMemberBank.getBankNo());
            adminMallMemberPaymentVo.setName(mallMemberBank.getName());
            adminMallMemberPaymentVo.setBankName(mallMemberBank.getBankName());
            adminMallMemberPaymentVo.setBankNameS(mallMemberBank.getBankNameS());
        }
        return adminMallMemberPaymentVo;
    }
    private String refererIds(String parentId) {
        boolean flag = false;
        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;
            }
        }
        return ids;
    }
}