From cc1098fc00a50cb1591d182f04bc37066ff0a9e2 Mon Sep 17 00:00:00 2001
From: 罗元桥 <2376770955@qq.com>
Date: 星期四, 05 八月 2021 15:12:39 +0800
Subject: [PATCH] Merge branch 'test' into 'master'

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActUserWalletServiceImpl.java |  186 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 131 insertions(+), 55 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActUserWalletServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActUserWalletServiceImpl.java
index 3376892..579f159 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActUserWalletServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActUserWalletServiceImpl.java
@@ -1,25 +1,29 @@
 package com.panzhihua.service_community.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.panzhihua.common.constants.Constants;
 import com.panzhihua.common.model.dtos.community.wallet.ComActWalletDetailDTO;
+import com.panzhihua.common.model.dtos.community.wallet.ComActWalletSettlementAdminDTO;
+import com.panzhihua.common.model.dtos.community.wallet.PageComActWalletAdminDTO;
 import com.panzhihua.common.model.dtos.community.wallet.PageComActWalletTradeDTO;
 import com.panzhihua.common.model.vos.R;
 import com.panzhihua.common.model.vos.community.wallet.ComActWalletVO;
+import com.panzhihua.common.utlis.StringUtils;
 import com.panzhihua.service_community.dao.ComActEasyPhotoActivityMapper;
 import com.panzhihua.service_community.dao.ComActEasyPhotoDAO;
+import com.panzhihua.service_community.dao.ComActEasyPhotoRewardMapper;
 import com.panzhihua.service_community.dao.ComActUserWalletMapper;
-import com.panzhihua.service_community.model.dos.ComActEasyPhotoActivityDO;
-import com.panzhihua.service_community.model.dos.ComActEasyPhotoDO;
-import com.panzhihua.service_community.model.dos.ComActUserWalletDO;
-import com.panzhihua.service_community.model.dos.ComActUserWalletTradeDO;
+import com.panzhihua.service_community.model.dos.*;
 import com.panzhihua.service_community.service.ComActUserWalletChangeService;
 import com.panzhihua.service_community.service.ComActUserWalletService;
 import com.panzhihua.service_community.service.ComActUserWalletTradeService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
@@ -45,6 +49,8 @@
     private ComActUserWalletTradeService comActUserWalletTradeService;
     @Resource
     private ComActUserWalletChangeService comActUserWalletChangeService;
+    @Resource
+    private ComActEasyPhotoRewardMapper comActEasyPhotoRewardMapper;
 
     /**
      * 查询用户钱包信息
@@ -70,11 +76,25 @@
             this.baseMapper.insert(userWalletDO);
         }
         BeanUtils.copyProperties(userWalletDO,comActWalletVO);
-        Map<String,String> resultMap = this.baseMapper.getCommunityName(walletDetailDTO.getCommunityId());
+        Map<String,String> resultMap = this.baseMapper.getCommunityName(walletDetailDTO.getCommunityId(),5);
         if(!resultMap.isEmpty()){
             comActWalletVO.setCommunityName(resultMap.get("name"));
-            comActWalletVO.setAgreement(resultMap.get("content"));
+            if(StringUtils.isEmpty(resultMap.get("content"))){
+                this.baseMapper.insertSysAgreement(Constants.PROFIT_EXPLAIN,"收益说明",walletDetailDTO.getCommunityId(),5);
+                comActWalletVO.setAgreement(Constants.PROFIT_EXPLAIN);
+            }else{
+                comActWalletVO.setAgreement(resultMap.get("content"));
+            }
+
         }
+
+        Integer easyCount = 0;
+        //查询用户发布随手拍数量
+        easyCount = comActEasyPhotoDAO.selectCount(new QueryWrapper<ComActEasyPhotoDO>().lambda()
+                .eq(ComActEasyPhotoDO::getSponsorId,walletDetailDTO.getUserId())
+                .eq(ComActEasyPhotoDO::getCommunityId,walletDetailDTO.getCommunityId()));
+        comActWalletVO.setEasyCount(easyCount);
+
         return R.ok(comActWalletVO);
     }
 
@@ -93,7 +113,7 @@
      * @param easyPhotoId   随手拍id
      */
     @Override
-    public void examineAddMoney(Integer activityType,Long easyPhotoId,Long userId){
+    public void examineAddMoney(Integer activityType,Long easyPhotoId,Long userId,BigDecimal amount){
 
         //查询随手拍信息
         ComActEasyPhotoDO easyPhotoDO = comActEasyPhotoDAO.selectById(easyPhotoId);
@@ -108,63 +128,51 @@
         }
 
         //查询随手拍活动
-        ComActEasyPhotoActivityDO photoActivityDO = comActEasyPhotoActivityMapper.selectById(easyPhotoDO.getActivityId());
-        if(photoActivityDO == null){
-            log.error("给用户添加收益失败,原因:未查到活动记录,活动id:" + easyPhotoDO.getActivityId());
-            return;
+//        ComActEasyPhotoActivityDO photoActivityDO = comActEasyPhotoActivityMapper.selectById(easyPhotoDO.getActivityId());
+//        if(photoActivityDO == null){
+//            log.error("给用户添加收益失败,原因:未查到活动记录,活动id:" + easyPhotoDO.getActivityId());
+//            return;
+//        }
+
+//        if(photoActivityDO.getStatus() != ComActEasyPhotoActivityDO.status.jxz){
+//            log.error("给用户添加收益失败,原因:活动未在进行中,活动id:" + easyPhotoDO.getActivityId());
+//            return;
+//        }
+
+
+//        Date nowDate = new Date();
+        //查询用户钱包
+        ComActUserWalletDO userWalletDO = comActUserWalletMapper.selectOne(new QueryWrapper<ComActUserWalletDO>()
+                .lambda().eq(ComActUserWalletDO::getUserId,easyPhotoDO.getSponsorId()).eq(ComActUserWalletDO::getCommunityId,easyPhotoDO.getCommunityId()));
+        if(userWalletDO == null){
+            userWalletDO = new ComActUserWalletDO();
+            userWalletDO.setIncomeAmount(BigDecimal.ZERO);
+            userWalletDO.setAvailableAmount(BigDecimal.ZERO);
+            userWalletDO.setSettlementAmount(BigDecimal.ZERO);
+            userWalletDO.setUserId(easyPhotoDO.getSponsorId());
+            userWalletDO.setCommunityId(easyPhotoDO.getCommunityId());
+            userWalletDO.setEasyCount(0);
+            userWalletDO.setCreateAt(new Date());
+            this.baseMapper.insert(userWalletDO);
         }
 
-        if(photoActivityDO.getStatus() != ComActEasyPhotoActivityDO.status.jxz){
-            log.error("给用户添加收益失败,原因:活动未在进行中,活动id:" + easyPhotoDO.getActivityId());
+        if(amount.compareTo(BigDecimal.ZERO) == 0){
+            log.error("此次参加活动的随手拍收益为0,不记录本次交易");
             return;
-        }
-
-        Date nowDate = new Date();
-        //活动正在进行中,需要给用户计算收益
-        if(nowDate.getTime() - photoActivityDO.getActivityStartAt().getTime() > 0 && nowDate.getTime() - photoActivityDO.getActivityEndAt().getTime() < 0){
-            //查询用户钱包
-            ComActUserWalletDO userWalletDO = comActUserWalletMapper.selectOne(new QueryWrapper<ComActUserWalletDO>()
-                    .lambda().eq(ComActUserWalletDO::getUserId,easyPhotoDO.getSponsorId()).eq(ComActUserWalletDO::getCommunityId,easyPhotoDO.getCommunityId()));
-            if(userWalletDO == null){
-                userWalletDO = new ComActUserWalletDO();
-                userWalletDO.setIncomeAmount(BigDecimal.ZERO);
-                userWalletDO.setAvailableAmount(BigDecimal.ZERO);
-                userWalletDO.setSettlementAmount(BigDecimal.ZERO);
-                userWalletDO.setUserId(easyPhotoDO.getSponsorId());
-                userWalletDO.setCommunityId(easyPhotoDO.getCommunityId());
-                userWalletDO.setEasyCount(0);
-                userWalletDO.setCreateAt(new Date());
-                this.baseMapper.insert(userWalletDO);
-            }
-
-            //计算收益
-            BigDecimal profitAmount = BigDecimal.ZERO;
-            if(activityType.equals(ComActEasyPhotoDO.activityType.yz)){
-                profitAmount = photoActivityDO.getGoodReward();
-            }else if(activityType.equals(ComActEasyPhotoDO.activityType.jl)){
-                profitAmount = photoActivityDO.getExcellentReward();
-            }else if(activityType.equals(ComActEasyPhotoDO.activityType.pt)){
-                profitAmount = photoActivityDO.getOrdinaryReward();
-            }
-
-            if(profitAmount.equals(BigDecimal.ZERO)){
-                log.error("此次参加活动的随手拍收益为0,不记录本次交易");
-                return;
-            }
-
+        }else{
             //记录钱包变动前金额
             BigDecimal oldIncomeAmount = userWalletDO.getIncomeAmount();
             BigDecimal oldAvailableAmount = userWalletDO.getAvailableAmount();
             BigDecimal oldSettlementAmount = userWalletDO.getSettlementAmount();
 
             //更新钱包金额
-            userWalletDO.setIncomeAmount(userWalletDO.getIncomeAmount().add(profitAmount));
-            userWalletDO.setAvailableAmount(userWalletDO.getAvailableAmount().add(profitAmount));
+            userWalletDO.setIncomeAmount(userWalletDO.getIncomeAmount().add(amount));
+            userWalletDO.setAvailableAmount(userWalletDO.getAvailableAmount().add(amount));
             comActUserWalletMapper.updateById(userWalletDO);
 
             //新增钱包资金交易记录
             Long tradeId = comActUserWalletTradeService.addWalletTrade(easyPhotoDO.getSponsorId(),easyPhotoDO.getCommunityId()
-                    ,easyPhotoDO.getId(),profitAmount, ComActUserWalletTradeDO.type.fb,"发布随手拍"
+                    ,easyPhotoDO.getId(),amount, ComActUserWalletTradeDO.type.fb,"发布随手拍"
                     ,userId,userWalletDO.getId(),ComActUserWalletTradeDO.changeType.add);
 
             //新增钱包资金变动记录
@@ -172,10 +180,78 @@
                     ,oldIncomeAmount,userWalletDO.getIncomeAmount(),oldAvailableAmount,userWalletDO.getAvailableAmount()
                     ,oldSettlementAmount,userWalletDO.getSettlementAmount(),tradeId);
 
-            //更新随手拍活动信息
-            easyPhotoDO.setActivityType(activityType);
-            easyPhotoDO.setActivityAmount(profitAmount);
-            comActEasyPhotoDAO.updateById(easyPhotoDO);
+            //查询用户未读奖励金额
+            ComActEasyPhotoRewardDO easyPhotoRewardDO = comActEasyPhotoRewardMapper.selectOne(new QueryWrapper<ComActEasyPhotoRewardDO>().lambda()
+                    .eq(ComActEasyPhotoRewardDO::getCommunityId,easyPhotoDO.getCommunityId())
+                    .eq(ComActEasyPhotoRewardDO::getUserId,easyPhotoDO.getSponsorId())
+                    .eq(ComActEasyPhotoRewardDO::getIsRead,ComActEasyPhotoRewardDO.isRead.no));
+            if(easyPhotoRewardDO == null){
+                easyPhotoRewardDO = new ComActEasyPhotoRewardDO();
+                easyPhotoRewardDO.setCommunityId(easyPhotoDO.getCommunityId());
+                easyPhotoRewardDO.setUserId(easyPhotoDO.getSponsorId());
+                easyPhotoRewardDO.setIsRead(ComActEasyPhotoRewardDO.isRead.no);
+                easyPhotoRewardDO.setCreateAt(new Date());
+                easyPhotoRewardDO.setAmount(amount);
+                comActEasyPhotoRewardMapper.insert(easyPhotoRewardDO);
+            }else{
+                easyPhotoRewardDO.setAmount(easyPhotoRewardDO.getAmount().add(amount));
+                easyPhotoRewardDO.setUpdateAt(new Date());
+                comActEasyPhotoRewardMapper.updateById(easyPhotoRewardDO);
+            }
+        }
+        //更新随手拍活动信息
+        easyPhotoDO.setActivityType(activityType);
+        easyPhotoDO.setActivityAmount(amount);
+        comActEasyPhotoDAO.updateById(easyPhotoDO);
+    }
+
+    /**
+     * 分页查询收益结算列表
+     * @param pageWalletAdminDTO    请求参数
+     * @return  收益结算列表
+     */
+    @Override
+    public R pageUserWalletAdmin(PageComActWalletAdminDTO pageWalletAdminDTO){
+        return R.ok(this.baseMapper.getUserWalletList(new Page(pageWalletAdminDTO.getPageNum(),pageWalletAdminDTO.getPageSize()),pageWalletAdminDTO));
+    }
+
+    /**
+     * 用户结算收益
+     * @param settlementAdminDTO    请求参数
+     * @return  结算结果
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R userWalletSettlementAdmin(ComActWalletSettlementAdminDTO settlementAdminDTO){
+        //查询用户钱包
+        ComActUserWalletDO userWalletDO = this.baseMapper.selectById(settlementAdminDTO.getId());
+        if(userWalletDO == null){
+            return R.fail("未查询到用户钱包");
+        }
+        if(userWalletDO.getAvailableAmount().compareTo(settlementAdminDTO.getSettlementAmount()) < 0){
+            return R.fail("结算金额不能高于钱包可结算金额");
+        }
+        try {
+            BigDecimal oldIncomeAmount = userWalletDO.getIncomeAmount();
+            BigDecimal oldAvailableAmount = userWalletDO.getAvailableAmount();
+            BigDecimal oldSettlementAmount = userWalletDO.getSettlementAmount();
+            userWalletDO.setAvailableAmount(userWalletDO.getAvailableAmount().subtract(settlementAdminDTO.getSettlementAmount()));
+            userWalletDO.setSettlementAmount(userWalletDO.getSettlementAmount().add(settlementAdminDTO.getSettlementAmount()));
+            userWalletDO.setUpdateAt(new Date());
+            this.baseMapper.updateById(userWalletDO);
+            //添加钱包交易记录
+            Long tradeServiceId = comActUserWalletTradeService.addWalletTrade(userWalletDO.getUserId(),userWalletDO.getCommunityId()
+                    ,null,settlementAdminDTO.getSettlementAmount(),ComActUserWalletTradeDO.type.js
+                    ,settlementAdminDTO.getRemark(),settlementAdminDTO.getUserId(),userWalletDO.getId(),ComActUserWalletTradeDO.changeType.reduce);
+            //添加钱包变动记录
+            comActUserWalletChangeService.addWalletChange(userWalletDO.getUserId(),userWalletDO.getCommunityId(),userWalletDO.getId()
+                    ,oldIncomeAmount,userWalletDO.getIncomeAmount(),oldAvailableAmount,userWalletDO.getAvailableAmount()
+                    ,oldSettlementAmount,userWalletDO.getSettlementAmount(),tradeServiceId);
+
+            return R.ok();
+        }catch (Exception e){
+            log.error("给用户结算收益失败,原因:" + e.getMessage());
+            return R.fail("结算失败");
         }
     }
 

--
Gitblit v1.7.1