From 7e6bbd05a75b07cb0717812d0b51aad128361012 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 19 May 2022 18:43:42 +0800
Subject: [PATCH] fix some problem

---
 src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java |  367 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 362 insertions(+), 5 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java
index 6423436..5399644 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallMemberServiceImpl.java
@@ -2,17 +2,33 @@
 
 import cc.mrbird.febs.common.entity.FebsResponse;
 import cc.mrbird.febs.common.entity.QueryRequest;
-import cc.mrbird.febs.mall.entity.MallMember;
-import cc.mrbird.febs.mall.mapper.MallMemberMapper;
+import cc.mrbird.febs.common.enumerates.AgentLevelEnum;
+import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
+import cc.mrbird.febs.common.exception.FebsException;
+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.vo.MallMemberVo;
+import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
+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.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.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
 
 /**
  * @author wzy
@@ -21,9 +37,25 @@
 @Slf4j
 @Service
 @RequiredArgsConstructor
+@Transactional
 public class AdminMallMemberServiceImpl extends ServiceImpl<MallMemberMapper, MallMember> 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;
 
     @Override
     public IPage<MallMember> getMallMemberList(MallMember mallMember, QueryRequest request) {
@@ -33,23 +65,25 @@
     }
 
     @Override
+    @Transactional
     public FebsResponse closeAccount(Long id) {
         MallMember mallMember = mallMemberMapper.selectById(id);
         if(ObjectUtil.isEmpty(mallMember)) {
             return new FebsResponse().fail().message("会员信息不存在");
         }
-        mallMember.setAccountStatus(MallMember.ACCOUNTSTATUS_N);
+        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.ACCOUNTSTATUS_Y);
+        mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE);
         mallMemberMapper.updateById(mallMember);
         return new FebsResponse().success();
     }
@@ -60,4 +94,327 @@
         return mallMemberVo;
     }
 
+    @Override
+    public IPage<AdminMallMoneyFlowVo> moneyFlow(QueryRequest request, MallMember mallMember) {
+        Page<AdminMallMoneyFlowVo> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<AdminMallMoneyFlowVo> adminMallMoneyFlowVos = mallMoneyFlowMapper.selectMoneyFlowInPage(page, mallMember);
+        return adminMallMoneyFlowVos;
+    }
+
+    @Override
+    public IPage<AdminMoneyFlowListVo> getMoneyFlowListInPage(MoneyFlowListDto moneyFlowListDto, QueryRequest request) {
+        Page<AdminMoneyFlowListVo> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<AdminMoneyFlowListVo> adminMoneyFlowListVos = mallMoneyFlowMapper.getMoneyFlowListInPage(page, moneyFlowListDto);
+        return adminMoneyFlowListVos;
+    }
+
+    @Override
+    public IPage<AdminMoneyChargeListVo> getMoneyChargeListInPage(MoneyChargeListDto moneyChargeListDto, QueryRequest request) {
+        Page<AdminMoneyChargeListVo> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<AdminMoneyChargeListVo> 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<AdminAgentVo> getAgentList(AgentDto agentDto, QueryRequest request) {
+        Page<AdminAgentVo> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<AdminAgentVo> adminAgentVos = this.baseMapper.getAgentListInPage(page, agentDto);
+        List<AdminAgentVo> records = adminAgentVos.getRecords();
+        if(CollUtil.isNotEmpty(records)){
+            for(AdminAgentVo adminAgentVo : records){
+                String inviteId = adminAgentVo.getInviteId();
+                //直接下级
+                List<MallMember> mallMembers = mallMemberMapper.selectChildAgentListByInviteId(inviteId);
+                adminAgentVo.setMemberNum(CollUtil.isEmpty(mallMembers) ? 0 : mallMembers.size());
+
+                //获取总数
+                List<MallMember> allMallMembers =mallMemberMapper.selectAllChildAgentListByInviteId(inviteId);
+                adminAgentVo.setAllMemberNum(CollUtil.isEmpty(allMallMembers) ? 0 : allMallMembers.size());
+            }
+        }
+        return adminAgentVos;
+    }
+
+    @Override
+    public IPage<AdminAgentLevelVo> getAgentLevelList(AgentLevelDto agentLevelDto, QueryRequest request) {
+        Page<AdminAgentLevelVo> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<AdminAgentLevelVo> adminAgentVos = this.baseMapper.getAgentLevelListInPage(page, agentLevelDto);
+        return adminAgentVos;
+    }
+
+    @Override
+    public AdminAgentLevelUpdateInfoVo getAgentLevelUpdateInfoById(long id) {
+        AdminAgentLevelUpdateInfoVo adminAgentLevelUpdateInfoVo = new AdminAgentLevelUpdateInfoVo();
+        DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectById(id);
+        String value = dataDictionaryCustom.getValue();
+        //{"directIncome":36,"lastCnt":3,"orderCnt":500,"orderType":2,"teamIncome":6,"teamIncomeType":2}
+        JSONObject jsonObject = JSONObject.parseObject(value);
+        adminAgentLevelUpdateInfoVo.setDirectIncome(new BigDecimal((jsonObject.get("directIncome")==null?0:jsonObject.get("directIncome")).toString()));
+        adminAgentLevelUpdateInfoVo.setLastCnt(Integer.parseInt((jsonObject.get("lastCnt")==null?0:jsonObject.get("lastCnt")).toString()));
+        adminAgentLevelUpdateInfoVo.setOrderCnt(Integer.parseInt((jsonObject.get("orderCnt")==null?0:jsonObject.get("orderCnt")).toString()));
+        adminAgentLevelUpdateInfoVo.setOrderType(Integer.parseInt(jsonObject.get("orderType").toString()));
+        adminAgentLevelUpdateInfoVo.setTeamIncome(new BigDecimal((jsonObject.get("teamIncome")==null?0:jsonObject.get("teamIncome")).toString()));
+        adminAgentLevelUpdateInfoVo.setTeamIncomeType(Integer.parseInt(jsonObject.get("orderType").toString()));
+        adminAgentLevelUpdateInfoVo.setId(id);
+        return adminAgentLevelUpdateInfoVo;
+    }
+
+    @Override
+    public FebsResponse agentLevelUpdate(AgentLevelUpdateDto agentLevelUpdateDto) {
+        DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectById(agentLevelUpdateDto.getId());
+        AgentLevelUpdateDto agentLevelUpdateDtoJson = new AgentLevelUpdateDto();
+        agentLevelUpdateDtoJson.setDirectIncome(agentLevelUpdateDto.getDirectIncome());
+        agentLevelUpdateDtoJson.setLastCnt(agentLevelUpdateDto.getLastCnt());
+        agentLevelUpdateDtoJson.setOrderCnt(agentLevelUpdateDto.getOrderCnt());
+        agentLevelUpdateDtoJson.setTeamIncome(agentLevelUpdateDto.getTeamIncome());
+        agentLevelUpdateDtoJson.setOrderType(agentLevelUpdateDto.getOrderType());
+        agentLevelUpdateDtoJson.setTeamIncomeType(agentLevelUpdateDto.getTeamIncomeType());
+        JSONObject jsonObject = (JSONObject)JSONObject.toJSON(agentLevelUpdateDtoJson);
+        dataDictionaryCustom.setValue(jsonObject.toString());
+        dataDictionaryCustomMapper.updateById(dataDictionaryCustom);
+        return new FebsResponse().success();
+    }
+
+    @Override
+    public List<AdminAgentLevelOptionTreeVo> getAgentLevelOption() {
+        return dataDictionaryCustomMapper.getAgentLevelOption();
+    }
+
+    @Override
+    public IPage<AdminAgentMemberVo> agentChild(QueryRequest request, MallMember mallMember) {
+        Long memberId = mallMember.getId();
+        mallMember = mallMemberMapper.selectById(memberId);
+        Page<AdminAgentMemberVo> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<AdminAgentMemberVo> adminAgentMemberVos = this.baseMapper.getAgentChildInPage(page, mallMember);
+        List<AdminAgentMemberVo> 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<AdminRankAwardVo> getRankAwardList(RankAwardDto rankAwardDto, QueryRequest request) {
+        Page<AdminRankAwardVo> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<AdminRankAwardVo> 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<AppVersion> getAppVersionList(AppVersion appVersion, QueryRequest request) {
+        Page<AppVersion> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<AppVersion> 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();
+        if(bigDecimal.compareTo(BigDecimal.ZERO) <= 0){
+            return new FebsResponse().fail().message("拨付数目需要大于0");
+        }
+
+        MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
+        mallMemberWallet.setBalance(mallMemberWallet.getBalance().add(bigDecimal));
+        mallMemberWalletMapper.updateBalanceWithId(mallMemberWallet);
+
+        MallMoneyFlow flow = new MallMoneyFlow();
+        flow.setMemberId(memberId);
+        flow.setAmount(bigDecimal);
+//        flow.setType(MoneyFlowTypeEnum.SYSTEM_PAY.getValue());
+        flow.setOrderNo("SYS"+MallUtils.getOrderNum());
+        flow.setStatus(2);
+        mallMoneyFlowMapper.insert(flow);
+        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 IPage<MallDataVo> getMallDataList(MallMember mallMember, QueryRequest request) {
+        Page<MallDataVo> page = new Page<>(request.getPageNum(), request.getPageSize());
+        IPage<MallDataVo> mallDataVos = this.baseMapper.getMallDataListInPage(page, mallMember);
+        return mallDataVos;
+    }
+
+    @Override
+    public IPage<MallShopApply> findShopApplyListInPage(MallShopApply mallShopApply, QueryRequest request) {
+        Page<MallShopApply> 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);
+    }
 }

--
Gitblit v1.9.1