package cc.mrbird.febs.mall.service.impl; 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.exception.FebsException; import cc.mrbird.febs.common.utils.LoginUserUtil; import cc.mrbird.febs.common.utils.MallUtils; import cc.mrbird.febs.mall.dto.*; import cc.mrbird.febs.mall.entity.*; import cc.mrbird.febs.mall.entity.MallNewsInfo; import cc.mrbird.febs.mall.mapper.*; import cc.mrbird.febs.mall.service.IAdminMallMemberService; import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; import cc.mrbird.febs.mall.service.IMallMoneyFlowService; import cc.mrbird.febs.mall.vo.*; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.SecureUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.xmlbeans.impl.store.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.Date; import java.util.List; /** * @author wzy * @date 2021-09-16 **/ @Slf4j @Service @RequiredArgsConstructor @Transactional public class AdminMallMemberServiceImpl extends ServiceImpl implements IAdminMallMemberService { private final MallMemberMapper mallMemberMapper; private final MallMemberWalletMapper mallMemberWalletMapper; private final MallMoneyFlowMapper mallMoneyFlowMapper; private final MallMemberPaymentMapper mallMemberPaymentMapper; private final DataDictionaryCustomMapper dataDictionaryCustomMapper; private final IApiMallMemberWalletService iApiMallMemberWalletService; private final AppVersionMapper appVersionMapper; private final MallNewsInfoMapper mallNewsInfoMapper; private final MallShopApplyMapper mallShopApplyMapper; private final IMallMoneyFlowService mallMoneyFlowService; @Override public IPage getMallMemberList(MallMember mallMember, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage mallMembers = this.baseMapper.selectMallMemberListInPage(page, mallMember); return mallMembers; } @Override @Transactional public FebsResponse closeAccount(Long id) { MallMember mallMember = mallMemberMapper.selectById(id); if(ObjectUtil.isEmpty(mallMember)) { return new FebsResponse().fail().message("会员信息不存在"); } mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_DISABLED); mallMemberMapper.updateById(mallMember); return new FebsResponse().success(); } @Override @Transactional public FebsResponse openAccount(Long id) { MallMember mallMember = mallMemberMapper.selectById(id); if(ObjectUtil.isEmpty(mallMember)) { return new FebsResponse().fail().message("会员信息不存在"); } mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE); mallMemberMapper.updateById(mallMember); return new FebsResponse().success(); } @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 { throw new FebsException("参数错误"); } this.baseMapper.updateById(mallMember); } @Override public MallMemberVo getMallMemberInfoById(long id) { MallMemberVo mallMemberVo = mallMemberMapper.getMallMemberInfoById(id); return mallMemberVo; } @Override public IPage moneyFlow(QueryRequest request, MallMember mallMember) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminMallMoneyFlowVos = mallMoneyFlowMapper.selectMoneyFlowInPage(page, mallMember); return adminMallMoneyFlowVos; } @Override public IPage getMoneyFlowListInPage(MoneyFlowListDto moneyFlowListDto, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminMoneyFlowListVos = mallMoneyFlowMapper.getMoneyFlowListInPage(page, moneyFlowListDto); return adminMoneyFlowListVos; } @Override public IPage getMoneyChargeListInPage(MoneyChargeListDto moneyChargeListDto, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminMoneyChargeListVos = mallMoneyFlowMapper.getMoneyChargeListInPage(page, moneyChargeListDto); return adminMoneyChargeListVos; } @Override @Transactional public FebsResponse chargeAgree(Long id) { MallMoneyFlow mallMoneyFlow = mallMoneyFlowMapper.selectById(id); if(ObjectUtil.isEmpty(mallMoneyFlow)){ return new FebsResponse().fail().message("系统繁忙,请刷新后重试"); } if(1 != mallMoneyFlow.getStatus()){ return new FebsResponse().fail().message("当前状态不是提现中"); } mallMoneyFlow.setStatus(2); mallMoneyFlowMapper.updateById(mallMoneyFlow); return new FebsResponse().success(); } @Override @Transactional public FebsResponse chargeDisagree(Long id) { MallMoneyFlow mallMoneyFlow = mallMoneyFlowMapper.selectById(id); if(ObjectUtil.isEmpty(mallMoneyFlow)){ return new FebsResponse().fail().message("系统繁忙,请刷新后重试"); } if(1 != mallMoneyFlow.getStatus()){ return new FebsResponse().fail().message("当前状态不是提现中"); } mallMoneyFlow.setStatus(3); mallMoneyFlowMapper.updateById(mallMoneyFlow); //用户钱包增加对应的余额 iApiMallMemberWalletService.addBalance(mallMoneyFlow.getAmount().negate(),mallMoneyFlow.getMemberId()); 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()); if(ObjectUtil.isNotEmpty(adminMallMemberPaymentVoa)){ adminMallMemberPaymentVo = adminMallMemberPaymentVoa; } return adminMallMemberPaymentVo; } @Override public IPage getAgentList(AgentDto agentDto, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminAgentVos = this.baseMapper.getAgentListInPage(page, agentDto); List records = adminAgentVos.getRecords(); if(CollUtil.isNotEmpty(records)){ for(AdminAgentVo adminAgentVo : records){ String inviteId = adminAgentVo.getInviteId(); //直接下级 List mallMembers = mallMemberMapper.selectChildAgentListByInviteId(inviteId); adminAgentVo.setMemberNum(CollUtil.isEmpty(mallMembers) ? 0 : mallMembers.size()); //获取总数 List allMallMembers =mallMemberMapper.selectAllChildAgentListByInviteId(inviteId); adminAgentVo.setAllMemberNum(CollUtil.isEmpty(allMallMembers) ? 0 : allMallMembers.size()); } } return adminAgentVos; } @Override public IPage getAgentLevelList(AgentLevelDto agentLevelDto, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminAgentVos = this.baseMapper.getAgentLevelListInPage(page, agentLevelDto); return adminAgentVos; } @Override public AdminAgentLevelUpdateInfoVo getAgentLevelUpdateInfoById(long id) { DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectById(id); String value = dataDictionaryCustom.getValue(); //{"directIncome":36,"lastCnt":3,"orderCnt":500,"orderType":2,"teamIncome":6,"teamIncomeType":2} AdminAgentLevelUpdateInfoVo adminAgentLevelUpdateInfoVo = JSONObject.parseObject(value, AdminAgentLevelUpdateInfoVo.class); adminAgentLevelUpdateInfoVo.setId(id); return adminAgentLevelUpdateInfoVo; } @Override public FebsResponse agentLevelUpdate(AgentLevelUpdateDto agentLevelUpdateDto) { DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectById(agentLevelUpdateDto.getId()); agentLevelUpdateDto.setId(null); dataDictionaryCustom.setValue(JSONObject.toJSONString(agentLevelUpdateDto)); dataDictionaryCustomMapper.updateById(dataDictionaryCustom); return new FebsResponse().success(); } @Override public List getAgentLevelOption() { return dataDictionaryCustomMapper.getAgentLevelOption(); } @Override public IPage agentChild(QueryRequest request, MallMember mallMember) { Long memberId = mallMember.getId(); mallMember = mallMemberMapper.selectById(memberId); Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminAgentMemberVos = this.baseMapper.getAgentChildInPage(page, mallMember); List records = adminAgentMemberVos.getRecords(); if(CollUtil.isNotEmpty(records)){ for(AdminAgentMemberVo agentMemberVo : records){ String inviteId = agentMemberVo.getInviteId(); BigDecimal amount = mallMemberMapper.getAgentTeamAmountByInviteId(inviteId); agentMemberVo.setAmount(amount); } } return adminAgentMemberVos; } @Override public IPage getRankAwardList(RankAwardDto rankAwardDto, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminRankAwardVos = this.baseMapper.getRankAwardListInPage(page, rankAwardDto); return adminRankAwardVos; } @Override public AdminRankAwardUpdateInfoVo getRankAwardUpdateInfoById(long id) { AdminRankAwardUpdateInfoVo adminRankAwardUpdateInfoVo = dataDictionaryCustomMapper.getRankAwardUpdateInfoById(id); return adminRankAwardUpdateInfoVo; } @Override public FebsResponse rankAwardUpdate(RankAwardUpdateDto rankAwardUpdateDto) { DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectById(rankAwardUpdateDto.getId()); dataDictionaryCustom.setValue(rankAwardUpdateDto.getValue()); dataDictionaryCustom.setDescription(rankAwardUpdateDto.getDescription()); dataDictionaryCustomMapper.updateById(dataDictionaryCustom); return new FebsResponse().success(); } @Override public IPage getAppVersionList(AppVersion appVersion, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage appVersions = this.baseMapper.getAppVersionListInPage(page, appVersion); return appVersions; } @Override public FebsResponse delCategary(Long id) { AppVersion appVersion = appVersionMapper.selectById(id); if(ObjectUtil.isEmpty(appVersion)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } appVersionMapper.deleteById(id); return new FebsResponse().success(); } @Override public FebsResponse addAppVersion(AppVersion appVersion) { appVersion.setCreatetime(new Date()); appVersionMapper.insert(appVersion); return new FebsResponse().success(); } @Override public AppVersion getAppVersionInfoById(long id) { return appVersionMapper.selectById(id); } @Override public FebsResponse updateAppVersion(AppVersion appVersion) { AppVersion appVersionBefore = appVersionMapper.selectById(appVersion.getId()); if(ObjectUtil.isEmpty(appVersionBefore)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } appVersion.setCreatetime(new Date()); appVersionMapper.updateById(appVersion); return new FebsResponse().success(); } @Override public FebsResponse activateAccount(Long id) { MallMember mallMember = mallMemberMapper.selectById(id); if(ObjectUtil.isEmpty(mallMember)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } String level = mallMember.getLevel(); if(StrUtil.isEmpty(level) || !AgentLevelEnum.ZERO_LEVEL.name().equals(mallMember.getLevel())){ return new FebsResponse().fail().message("该用户无法激活"); } mallMember.setLevel(AgentLevelEnum.FIRST_LEVEL.name()); mallMemberMapper.updateById(mallMember); return new FebsResponse().success(); } @Override @Transactional public FebsResponse updateSystemPay(MallSystemPayDto mallSystemPayDto) { Long memberId = mallSystemPayDto.getId(); MallMember mallMember = mallMemberMapper.selectById(memberId); if(ObjectUtil.isEmpty(mallMember)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } BigDecimal bigDecimal = mallSystemPayDto.getAddBalance(); boolean isReduce = false; if(bigDecimal.compareTo(BigDecimal.ZERO) <= 0){ isReduce = true; } 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("参数错误"); } if (isReduce) { iApiMallMemberWalletService.reduce(mallSystemPayDto.getAddBalance().negate(), mallSystemPayDto.getId(), filedType); } else { iApiMallMemberWalletService.add(mallSystemPayDto.getAddBalance(), mallSystemPayDto.getId(), filedType); } mallMoneyFlowService.addMoneyFlow(memberId, bigDecimal, MoneyFlowTypeEnum.SYSTEM.getValue(), null, type); return new FebsResponse().success(); } @Override public AdminAgentLevelSetInfoVo getAgentLevelSetInfoByMemberId(long id) { AdminAgentLevelSetInfoVo adminAgentLevelSetInfoVo = mallMemberMapper.getAgentLevelSetInfoByMemberId(id); return adminAgentLevelSetInfoVo; } @Override public FebsResponse agentLevelSetUpdate(AgentLevelSetUpdateDto agentLevelSetUpdateDto) { Long memberId = agentLevelSetUpdateDto.getId(); MallMember mallMember = mallMemberMapper.selectById(memberId); if(ObjectUtil.isEmpty(mallMember)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } mallMember.setLevel(agentLevelSetUpdateDto.getLevelCode()); mallMemberMapper.updateById(mallMember); return new FebsResponse().success(); } @Override public FebsResponse resetPwd(Long id) { MallMember mallMember = this.baseMapper.selectById(id); if (mallMember == null) { throw new FebsException("用户不存在"); } String pwd = SecureUtil.md5("a123456"); mallMember.setPassword(pwd); this.baseMapper.updateById(mallMember); return new FebsResponse().success().message("重置成功"); } @Override public void resetPwd(String ids, Integer type) { if (StrUtil.isEmpty(ids)) { throw new FebsException("参数错误"); } List 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("654321"); member.setTradePassword(payPwd); // 重置登录密码 } else { String pwd = SecureUtil.md5("a123456"); member.setPassword(pwd); } this.baseMapper.updateById(member); } } @Override public IPage getMallDataList(MallMember mallMember, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage mallDataVos = this.baseMapper.getMallDataListInPage(page, mallMember); return mallDataVos; } @Override public IPage findShopApplyListInPage(MallShopApply mallShopApply, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); return mallShopApplyMapper.selectShopApplyInPage(mallShopApply, page); } @Override public MallShopApply findShopApplyById(Long id) { return mallShopApplyMapper.selectById(id); } @Override public void applyCheckAgree(Long id) { MallShopApply apply = mallShopApplyMapper.selectById(id); if (!MallShopApply.APPLY_ING.equals(apply.getStatus())) { throw new FebsException("申请已审核, 请勿重复操作"); } apply.setStatus(MallShopApply.APPLY_AGREE); mallShopApplyMapper.updateById(apply); } @Override public void applyCheckDisAgree(Long id) { MallShopApply apply = mallShopApplyMapper.selectById(id); if (!MallShopApply.APPLY_ING.equals(apply.getStatus())) { throw new FebsException("申请已审核, 请勿重复操作"); } apply.setStatus(MallShopApply.APPLY_DISAGREE); mallShopApplyMapper.updateById(apply); } @Override @Transactional public FebsResponse updateMemberInfo(MallUpdateMemberInfoDto mallUpdateMemberInfoDto) { Long memberId = mallUpdateMemberInfoDto.getId(); MallMember mallMember = mallMemberMapper.selectById(memberId); if(ObjectUtil.isEmpty(mallMember)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } String phone = mallUpdateMemberInfoDto.getPhone(); if(StrUtil.isEmpty(phone)){ throw new FebsException("请输入手机号码"); } if(!phone.equals(mallMember.getPhone())){ QueryWrapper objectQueryWrapper = new QueryWrapper<>(); objectQueryWrapper.eq("phone",phone); List mallMembers = this.baseMapper.selectList(objectQueryWrapper); if(CollUtil.isNotEmpty(mallMembers)){ throw new FebsException("手机号码已绑定过账号"); } } mallMember.setPhone(phone); mallMember.setBindPhone(phone); mallMember.setLevel(mallUpdateMemberInfoDto.getLevelCode()); mallMemberMapper.updateById(mallMember); if(mallUpdateMemberInfoDto.getBalance() == null){ throw new FebsException("请输入正确的余额"); } if(mallUpdateMemberInfoDto.getScore() == null){ throw new FebsException("请输入正确的赠送积分"); } if(mallUpdateMemberInfoDto.getPrizeScore() == null){ throw new FebsException("请输入正确的竞猜积分"); } BigDecimal balance = mallUpdateMemberInfoDto.getBalance(); if(BigDecimal.ZERO.compareTo(balance) > 0){ throw new FebsException("请输入正确的余额"); } BigDecimal score = mallUpdateMemberInfoDto.getScore(); if(BigDecimal.ZERO.compareTo(score) > 0){ throw new FebsException("请输入正确的赠送积分"); } BigDecimal prizeScore = mallUpdateMemberInfoDto.getPrizeScore(); if(BigDecimal.ZERO.compareTo(prizeScore) > 0){ throw new FebsException("请输入正确的竞猜积分"); } MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); mallMemberWallet.setBalance(balance); mallMemberWallet.setScore(score); mallMemberWallet.setPrizeScore(prizeScore); 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 childs = this.baseMapper.selectByRefererId(member.getInviteId()); if (CollUtil.isEmpty(childs)) { return; } for (MallMember child : childs) { child.setReferrerIds(member.getInviteId() + "," + refererIds); this.baseMapper.updateById(child); } } 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; } }