xiaoyong931011
2023-02-17 e929e795be5dad7487e6e483a361b0bc27b34216
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
@@ -16,6 +16,7 @@
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.service.IMallMoneyFlowService;
import cc.mrbird.febs.mall.vo.*;
import cc.mrbird.febs.pay.model.BrandWCPayRequestData;
import cc.mrbird.febs.pay.service.IXcxPayService;
@@ -66,6 +67,8 @@
    private final MallRegisterAppealMapper mallRegisterAppealMapper;
    private final MallTeamLeaderMapper mallTeamLeaderMapper;
    private final SpringContextHolder springContextHolder;
    private final MallAgentRecordMapper mallAgentRecordMapper;
    private final IMallMoneyFlowService mallMoneyFlowService;
    @Value("${spring.profiles.active}")
@@ -254,13 +257,18 @@
        mallMemberVo.setPrizeScore(wallet.getPrizeScore());
        mallMemberVo.setTotalCost(mallOrderInfoMapper.selectTotalAmount(id));
        //用户是否是团长
        List<MallTeamLeader> mallTeamLeaders = mallTeamLeaderMapper.selectListByMemberIdAndState(mallMember.getId(), MallTeamLeader.STATE_YES);
        if(CollUtil.isNotEmpty(mallTeamLeaders)){
            mallMemberVo.setIsTeamLeader(1);
        }else{
            mallMemberVo.setIsTeamLeader(2);
        //代理状态
        MallAgentRecord mallAgentRecordIng = mallAgentRecordMapper.selectByMemberIdAndState(id, MallAgentRecord.APPLY_ING);
        MallAgentRecord mallAgentRecordAgree = mallAgentRecordMapper.selectByMemberIdAndState(id, MallAgentRecord.APPLY_AGREE);
        MallAgentRecord mallAgentRecordDisagree = mallAgentRecordMapper.selectByMemberIdAndState(id, MallAgentRecord.APPLY_DISAGREE);
        if(ObjectUtil.isNotEmpty(mallAgentRecordIng)){
            mallMemberVo.setIsAgent(1);
        }else if(ObjectUtil.isNotEmpty(mallAgentRecordAgree)){
            mallMemberVo.setIsAgent(2);
        }else if(ObjectUtil.isNotEmpty(mallAgentRecordDisagree)){
            mallMemberVo.setIsAgent(3);
        }
        return new FebsResponse().success().data(mallMemberVo);
    }
@@ -428,7 +436,7 @@
        Long id = LoginUserUtil.getLoginUser().getId();
        MallMember member = this.baseMapper.selectById(id);
        member.setBindPhone(accountAndCodeDto.getAccount());
        member.setPhone(accountAndCodeDto.getAccount());
        this.baseMapper.updateById(member);
    }
@@ -640,7 +648,7 @@
        if(StrUtil.isNotEmpty(avatarUrl)){
            mallMember.setAvatar(avatarUrl);
        }
        mallMember.setSex(apiXcxSaveInfoDto.getGender() == 1 ? "女" : "男");
//        mallMember.setSex(1 == apiXcxSaveInfoDto.getGender() ? "女" : "男");
        this.baseMapper.updateById(mallMember);
        return new FebsResponse().success();
    }
@@ -735,6 +743,19 @@
        if(BigDecimal.ZERO.compareTo(amount)>0){
            return new FebsResponse().fail().message("请输入正确的充值金额");
        }
        Integer type = apiRechargeWalletDto.getType();
        if(2 == type){
            //成为合伙人的充值金额
            DataDictionaryCustom agentPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.PRICE_AMOUNT.getType(),
                    DataDictionaryEnum.PRICE_AMOUNT.getCode());
            String agentPrice = agentPriceDic.getValue();
            BigDecimal price = new BigDecimal(agentPrice);
            if(price.compareTo(amount) != 0){
                return new FebsResponse().fail().message("成为合伙人的金额为"+agentPrice);
            }
        }
        String rechargeNo = "CZ_"+MallUtils.getOrderNum();
        apiRechargeWalletDto.setRechargeNo(rechargeNo);
        apiRechargeWalletDto.setMemberId(memberId);
        BrandWCPayRequestData brandWCPayRequestData = null;
        try {
@@ -742,6 +763,14 @@
        } catch (Exception e) {
            throw new FebsException("支付失败");
        }
        mallMoneyFlowService.addMoneyFlow(
                memberId,
                amount,
                MoneyFlowTypeEnum.RECHARGE.getValue(),
                rechargeNo,
                FlowTypeEnum.BALANCE.getValue(),
                "余额充值",1);
        String wxResultStr = JSONUtil.toJsonStr(brandWCPayRequestData);
        String payResultStr = brandWCPayRequestData.getPrepay_id();
        Map<String, Object> map = new HashMap<>();
@@ -750,6 +779,27 @@
        return new FebsResponse().success().data(map).message("充值即将到账");
    }
    @Override
    public void updateMemberAgent(Long memberId) {
        mallAgentRecordMapper.updateStateByMemberId(memberId);
        //更新用户表中的LEVEL
        MallMember mallMember = this.baseMapper.selectById(memberId);
        mallMember.setLevel(AgentLevelEnum.FIRST_LEVEL.name());
        this.baseMapper.updateById(mallMember);
    }
    @Override
    public FebsResponse agentDetail() {
        DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.AGENT_DETAILS.getType(), DataDictionaryEnum.AGENT_DETAILS.getCode());
        Map<String, Object> map = new HashMap<>();
        if(ObjectUtil.isNotEmpty(dataDictionaryCustom)){
            map.put("agentDetail", dataDictionaryCustom.getValue());
        }
        return new FebsResponse().success().data(map);
    }
    private  String getXcxLoginUrl(String code) {
        String wechatLoginUrl =xcxProperties.getWecharLoginUrl();
        return String.format(wechatLoginUrl, xcxProperties.getXcxAppid(), xcxProperties.getXcxSecret(), code);