From ee64a79830f6bad4107301c31f1fed3d8ab190c4 Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Tue, 01 Mar 2022 10:46:03 +0800 Subject: [PATCH] 20222223 --- src/main/resources/mapper/walletCoinOrder/ZhiYaRecordDao.xml | 31 +++ src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ZhiyaRewardRecordsTypePageDto.java | 22 ++ src/main/java/com/xcong/excoin/modules/coin/parameter/vo/ZhiyaRewardVo.java | 3 src/main/java/com/xcong/excoin/modules/member/parameter/vo/MemberTeamVo.java | 20 + src/main/java/com/xcong/excoin/modules/member/parameter/vo/TeamVo.java | 25 ++ src/main/java/com/xcong/excoin/modules/coin/controller/ZhiyaController.java | 11 + src/main/java/com/xcong/excoin/modules/coin/dao/ZhiYaRecordDao.java | 14 + src/main/java/com/xcong/excoin/modules/coin/service/impl/ZhiyaServiceImpl.java | 217 ++++++++++++++++++++--- src/main/java/com/xcong/excoin/modules/coin/entity/ZhiyaRewardEntity.java | 4 src/main/java/com/xcong/excoin/quartz/job/ZhiyarRewardJob.java | 5 src/main/java/com/xcong/excoin/modules/coin/service/ZhiyaService.java | 3 src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java | 52 +++++ src/main/resources/mapper/member/MemberDao.xml | 22 ++ src/main/java/com/xcong/excoin/modules/coin/entity/ZhiYaTeam.java | 48 +++++ src/main/java/com/xcong/excoin/modules/coin/dao/ZhiyaTeamDao.java | 7 src/main/java/com/xcong/excoin/modules/member/dao/MemberDao.java | 12 + 16 files changed, 444 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/xcong/excoin/modules/coin/controller/ZhiyaController.java b/src/main/java/com/xcong/excoin/modules/coin/controller/ZhiyaController.java index d8a5f7a..967b898 100644 --- a/src/main/java/com/xcong/excoin/modules/coin/controller/ZhiyaController.java +++ b/src/main/java/com/xcong/excoin/modules/coin/controller/ZhiyaController.java @@ -107,4 +107,15 @@ public Result getZhiyaReward(@RequestBody @Valid ZhiyaRewardRecordsPageDto recordsPageDto) { return zhiyaService.getZhiyaReward(recordsPageDto); } + + /** + * 获取质押GUSD奖励返佣记录 + * @return + */ + @ApiOperation(value="获取质押GUSD奖励返佣记录", notes="获取质押GUSD奖励返佣记录") + @ApiResponses({@ApiResponse( code = 200, message = "success", response = ZhiyaRewardVo.class)}) + @PostMapping(value="/getZhiyaRewardTypeTo") + public Result getZhiyaRewardTypeTo(@RequestBody @Valid ZhiyaRewardRecordsTypePageDto recordsPageDto) { + return zhiyaService.getZhiyaRewardTypeTo(recordsPageDto); + } } diff --git a/src/main/java/com/xcong/excoin/modules/coin/dao/ZhiYaRecordDao.java b/src/main/java/com/xcong/excoin/modules/coin/dao/ZhiYaRecordDao.java index 71da7f4..0ceeb59 100644 --- a/src/main/java/com/xcong/excoin/modules/coin/dao/ZhiYaRecordDao.java +++ b/src/main/java/com/xcong/excoin/modules/coin/dao/ZhiYaRecordDao.java @@ -3,10 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.xcong.excoin.modules.coin.entity.OrderCoinsEntity; -import com.xcong.excoin.modules.coin.entity.ZhiYaEntity; -import com.xcong.excoin.modules.coin.entity.ZhiYaRecordEntity; -import com.xcong.excoin.modules.coin.entity.ZhiyaRewardEntity; +import com.xcong.excoin.modules.coin.entity.*; import com.xcong.excoin.modules.coin.parameter.vo.ZhiyaInfoVo; import com.xcong.excoin.modules.coin.parameter.vo.ZhiyaRewardVo; import org.apache.ibatis.annotations.Param; @@ -32,5 +29,14 @@ Long selectTotalGusdByStatueAndTime(@Param("orderStatus")int i, @Param("now")Date date); + ZhiYaTeam selectZhiyaTeamRecordByMemberId(@Param("memberId")Long id); + + List<ZhiyaRewardEntity> selectZhiyaTeamRecordByMemberIdAndOrderNo(@Param("orderNo")String orderNo, @Param("memberId")Long memberId,@Param("now")Date date); + // void selectZhiYaRewardByStatueAndTime(@Param("orderStatus")int i, @Param("now")Date date); + Long selectSumZhiyaCntByMemberIdAndOrderStatus(@Param("memberId")Long memberId,@Param("orderStatus") Integer orderStatus); + + Long selectSumRewardCntByMemberId(@Param("memberId")Long zhiShuMemberId); + + IPage<ZhiyaRewardVo> selectZhiyaRewardTypeToByMemberIdInPage(Page<ZhiyaRewardVo> page, @Param("record")ZhiyaRewardEntity zhiyaRewardEntity); } diff --git a/src/main/java/com/xcong/excoin/modules/coin/dao/ZhiyaTeamDao.java b/src/main/java/com/xcong/excoin/modules/coin/dao/ZhiyaTeamDao.java new file mode 100644 index 0000000..c6f2770 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/coin/dao/ZhiyaTeamDao.java @@ -0,0 +1,7 @@ +package com.xcong.excoin.modules.coin.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xcong.excoin.modules.coin.entity.ZhiYaTeam; + +public interface ZhiyaTeamDao extends BaseMapper<ZhiYaTeam> { +} diff --git a/src/main/java/com/xcong/excoin/modules/coin/entity/ZhiYaTeam.java b/src/main/java/com/xcong/excoin/modules/coin/entity/ZhiYaTeam.java new file mode 100644 index 0000000..2c4dc23 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/coin/entity/ZhiYaTeam.java @@ -0,0 +1,48 @@ +package com.xcong.excoin.modules.coin.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.xcong.excoin.common.system.base.BaseEntity; +import lombok.Data; + +import java.math.BigDecimal; + +@Data +@TableName("zhiya_Team") +public class ZhiYaTeam extends BaseEntity { + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * 会员ID + */ + private Long memberId; + + /** + * 是否是代理 1:是 0:否 + */ + private Integer isAgent; + + /** + * 上级 + */ + private String refererId; + + /** + * 上级链 + */ + private String refererIds; + + /** + * 团队委托总量(不包含自己质押的算力) + */ + private BigDecimal zhiyaCnt; + + /** + * 团队总收益(不包含自己质押的算力) + */ + private BigDecimal rewardCnt; + + +} diff --git a/src/main/java/com/xcong/excoin/modules/coin/entity/ZhiyaRewardEntity.java b/src/main/java/com/xcong/excoin/modules/coin/entity/ZhiyaRewardEntity.java index ef3a7d9..ba4d9fd 100644 --- a/src/main/java/com/xcong/excoin/modules/coin/entity/ZhiyaRewardEntity.java +++ b/src/main/java/com/xcong/excoin/modules/coin/entity/ZhiyaRewardEntity.java @@ -34,5 +34,9 @@ * 奖励金额 */ private BigDecimal rewardAmout; + /** + * 1:返回用户2:返回代理 + */ + private Integer type; } diff --git a/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ZhiyaRewardRecordsTypePageDto.java b/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ZhiyaRewardRecordsTypePageDto.java new file mode 100644 index 0000000..8067025 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ZhiyaRewardRecordsTypePageDto.java @@ -0,0 +1,22 @@ +package com.xcong.excoin.modules.coin.parameter.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +@Data +@ApiModel(value = "ZhiyaRewardRecordsTypePageDto", description = "参数接受类") +public class ZhiyaRewardRecordsTypePageDto { + + @NotNull + @Min(1) + @ApiModelProperty(value = "第几页", example = "1") + private int pageNum; + + @NotNull + @ApiModelProperty(value = "每页数量", example = "10") + private int pageSize; +} diff --git a/src/main/java/com/xcong/excoin/modules/coin/parameter/vo/ZhiyaRewardVo.java b/src/main/java/com/xcong/excoin/modules/coin/parameter/vo/ZhiyaRewardVo.java index 61f79be..b8eda60 100644 --- a/src/main/java/com/xcong/excoin/modules/coin/parameter/vo/ZhiyaRewardVo.java +++ b/src/main/java/com/xcong/excoin/modules/coin/parameter/vo/ZhiyaRewardVo.java @@ -17,6 +17,9 @@ */ @ApiModelProperty(value = "质押编号") private String recordNo; + + @ApiModelProperty(value = "1:空白 2:返佣") + private Integer type; /** * 奖励金额 */ diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/ZhiyaService.java b/src/main/java/com/xcong/excoin/modules/coin/service/ZhiyaService.java index 4e0e95a..5c797f9 100644 --- a/src/main/java/com/xcong/excoin/modules/coin/service/ZhiyaService.java +++ b/src/main/java/com/xcong/excoin/modules/coin/service/ZhiyaService.java @@ -5,6 +5,7 @@ import com.xcong.excoin.modules.coin.entity.ZhiYaEntity; import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto; import com.xcong.excoin.modules.coin.parameter.dto.ZhiyaRewardRecordsPageDto; +import com.xcong.excoin.modules.coin.parameter.dto.ZhiyaRewardRecordsTypePageDto; import java.math.BigDecimal; @@ -25,4 +26,6 @@ void grantZhiyaAmount(); Result getZhiyaReward(ZhiyaRewardRecordsPageDto recordsPageDto); + + Result getZhiyaRewardTypeTo(ZhiyaRewardRecordsTypePageDto recordsPageDto); } diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/impl/ZhiyaServiceImpl.java b/src/main/java/com/xcong/excoin/modules/coin/service/impl/ZhiyaServiceImpl.java index b6f8df9..06520d9 100644 --- a/src/main/java/com/xcong/excoin/modules/coin/service/impl/ZhiyaServiceImpl.java +++ b/src/main/java/com/xcong/excoin/modules/coin/service/impl/ZhiyaServiceImpl.java @@ -9,24 +9,22 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xcong.excoin.common.LoginUserUtils; +import com.xcong.excoin.common.enumerates.CoinTypeEnum; import com.xcong.excoin.common.enumerates.MemberWalletCoinEnum; import com.xcong.excoin.common.response.Result; -import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao; -import com.xcong.excoin.modules.coin.dao.ZhiYaDao; -import com.xcong.excoin.modules.coin.dao.ZhiYaRecordDao; -import com.xcong.excoin.modules.coin.dao.ZhiyaRewardDao; -import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange; -import com.xcong.excoin.modules.coin.entity.ZhiYaEntity; -import com.xcong.excoin.modules.coin.entity.ZhiYaRecordEntity; -import com.xcong.excoin.modules.coin.entity.ZhiyaRewardEntity; +import com.xcong.excoin.modules.coin.dao.*; +import com.xcong.excoin.modules.coin.entity.*; import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto; import com.xcong.excoin.modules.coin.parameter.dto.ZhiyaRewardRecordsPageDto; +import com.xcong.excoin.modules.coin.parameter.dto.ZhiyaRewardRecordsTypePageDto; import com.xcong.excoin.modules.coin.parameter.vo.MemberGusdInfoVo; import com.xcong.excoin.modules.coin.parameter.vo.UsdtToGusdVo; import com.xcong.excoin.modules.coin.parameter.vo.ZhiyaInfoVo; import com.xcong.excoin.modules.coin.parameter.vo.ZhiyaRewardVo; import com.xcong.excoin.modules.coin.service.ZhiyaService; +import com.xcong.excoin.modules.member.dao.MemberDao; import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao; +import com.xcong.excoin.modules.member.entity.MemberEntity; import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; import com.xcong.excoin.utils.MessageSourceUtils; import com.xcong.excoin.utils.RedisUtils; @@ -36,10 +34,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; +import java.util.*; @Service public class ZhiyaServiceImpl extends ServiceImpl<ZhiYaDao, ZhiYaEntity> implements ZhiyaService { @@ -54,6 +49,10 @@ ZhiyaRewardDao zhiyaRewardDao; @Resource ZhiYaDao zhiYaDao; + @Resource + ZhiyaTeamDao zhiyaTeamDao; + @Resource + MemberDao memberdao; @Resource RedisUtils redisUtils; @Override @@ -219,8 +218,47 @@ // zhiYaRecordDao.updateById(zhiYaRecord); // } //更新团队算力表 - //只计算直属团队的算力信息 - + MemberEntity memberEntity = memberdao.selectById(memberId); + String refererIds = memberEntity.getRefererIds(); + if(StrUtil.isNotEmpty(refererIds)){ + BigDecimal gricetoagent = new BigDecimal(redisUtils.getString("GRICETOAGENT")); + String[] split = refererIds.split(","); + List<String> strings = Arrays.asList(split); + if(CollUtil.isNotEmpty(Arrays.asList(split))){ + for(String str : strings){ + if(StrUtil.isNotEmpty(str)){ + BigDecimal isAgent = BigDecimal.ZERO; + MemberEntity memberShangJi = memberdao.selectMemberInfoByInviteId(str); + ZhiYaTeam zhiyaTeamByMemberId = zhiYaRecordDao.selectZhiyaTeamRecordByMemberId(memberShangJi.getId()); + if(ObjectUtil.isNotEmpty(zhiyaTeamByMemberId)){ + //更新数据 + zhiyaTeamByMemberId.setZhiyaCnt(zhiyaTeamByMemberId.getZhiyaCnt().add(balance)); + if(isAgent.compareTo(gricetoagent) >= 0){ + zhiyaTeamByMemberId.setIsAgent(1); + } + zhiyaTeamDao.updateById(zhiyaTeamByMemberId); + }else{ + //新增数据 + ZhiYaTeam zhiYaTeam = new ZhiYaTeam(); + zhiYaTeam.setRefererId(memberShangJi.getRefererId()); + zhiYaTeam.setRefererIds(memberShangJi.getRefererIds()); + zhiYaTeam.setMemberId(memberShangJi.getId()); + if(ObjectUtil.isNotEmpty(zhiyaTeamByMemberId)){ + zhiYaTeam.setZhiyaCnt(zhiyaTeamByMemberId.getZhiyaCnt().add(balance)); + isAgent = zhiyaTeamByMemberId.getZhiyaCnt().add(balance); + }else{ + zhiYaTeam.setZhiyaCnt(balance); + isAgent = balance; + } + if(isAgent.compareTo(gricetoagent) >= 0){ + zhiYaTeam.setIsAgent(1); + } + zhiyaTeamDao.insert(zhiYaTeam); + } + } + } + } + } return Result.ok(MessageSourceUtils.getString("member_service_0024")); } @@ -268,6 +306,49 @@ zhiya.setFrozenBalance(gusdfrozenBalance.subtract(balance)); zhiya.setAvailableBalance(gusdAvailableBalance.add(balance)); zhiYaDao.updateById(zhiya); + //更新团队算力表 + MemberEntity memberEntity = memberdao.selectById(memberId); + String refererIds = memberEntity.getRefererIds(); + if(StrUtil.isNotEmpty(refererIds)){ + BigDecimal gricetoagent = new BigDecimal(redisUtils.getString("GRICETOAGENT")); + String[] split = refererIds.split(","); + List<String> strings = Arrays.asList(split); + if(CollUtil.isNotEmpty(Arrays.asList(split))){ + for(String str : strings){ + if(StrUtil.isNotEmpty(str)){ + BigDecimal isAgent = BigDecimal.ZERO; + MemberEntity memberShangJi = memberdao.selectMemberInfoByInviteId(str); + ZhiYaTeam zhiyaTeamByMemberId = zhiYaRecordDao.selectZhiyaTeamRecordByMemberId(memberShangJi.getId()); + if(ObjectUtil.isNotEmpty(zhiyaTeamByMemberId)){ + //更新数据 + zhiyaTeamByMemberId.setZhiyaCnt(zhiyaTeamByMemberId.getZhiyaCnt().subtract(balance)); + isAgent = zhiyaTeamByMemberId.getZhiyaCnt().subtract(balance); + if(isAgent.compareTo(gricetoagent) >= 0){ + zhiyaTeamByMemberId.setIsAgent(1); + } + zhiyaTeamDao.updateById(zhiyaTeamByMemberId); + }else{ + //新增数据 + ZhiYaTeam zhiYaTeam = new ZhiYaTeam(); + zhiYaTeam.setRefererId(memberShangJi.getRefererId()); + zhiYaTeam.setRefererIds(memberShangJi.getRefererIds()); + zhiYaTeam.setMemberId(memberShangJi.getId()); + if(ObjectUtil.isNotEmpty(zhiyaTeamByMemberId)){ + zhiYaTeam.setZhiyaCnt(zhiyaTeamByMemberId.getZhiyaCnt().subtract(balance)); + isAgent = zhiyaTeamByMemberId.getZhiyaCnt().subtract(balance); + }else{ + zhiYaTeam.setZhiyaCnt(balance); + isAgent = balance; + } + if(isAgent.compareTo(gricetoagent) >= 0){ + zhiYaTeam.setIsAgent(1); + } + zhiyaTeamDao.insert(zhiYaTeam); + } + } + } + } + } return Result.ok(MessageSourceUtils.getString("member_service_0024")); } @@ -311,14 +392,10 @@ @Override @Transactional public void grantZhiyaAmount() { - //获取每日总产出 + //获取GUSD质押比例 BigDecimal gusdReward = new BigDecimal(redisUtils.getString("GUSDREWARD")); - //静态算力 = 每日总产出的80% BigDecimal fixedGusdReward = gusdReward.multiply(new BigDecimal(0.8)); - //获取每日全网总算力 - Long totalGusd = zhiYaRecordDao.selectTotalGusdByStatueAndTime(1,new Date()); - BigDecimal totalGusdBigDecimal = new BigDecimal(totalGusd); - if(totalGusdBigDecimal.compareTo(BigDecimal.ZERO) > 0){ + if(fixedGusdReward.compareTo(BigDecimal.ZERO) > 0){ //获取今天之前满足发放奖励的全部质押单 //生效时间小于当前时间 //状态为生效中 @@ -326,14 +403,83 @@ if(CollUtil.isNotEmpty(lists)){ for(ZhiYaRecordEntity zhiYaRecordEntity : lists){ ZhiyaRewardEntity zhiyaRewardEntity = new ZhiyaRewardEntity(); - zhiyaRewardEntity.setRecordId(zhiYaRecordEntity.getId()); - zhiyaRewardEntity.setRecordNo(zhiYaRecordEntity.getOrderNo()); - zhiyaRewardEntity.setMemberId(zhiYaRecordEntity.getMemberId()); - //(个人算力/每日全网总算力)*静态算力 - BigDecimal divide1 = zhiYaRecordEntity.getZhiyaCnt().divide(totalGusdBigDecimal, 2, BigDecimal.ROUND_HALF_UP); - BigDecimal multiply = divide1.multiply(fixedGusdReward); - zhiyaRewardEntity.setRewardAmout(multiply); - zhiyaRewardDao.insert(zhiyaRewardEntity); + //查询今天有没有发送过了 + String orderNo = zhiYaRecordEntity.getOrderNo(); + Long memberId = zhiYaRecordEntity.getMemberId(); + Date date = new Date(); + List<ZhiyaRewardEntity> zhiyaRewardEntityDone = zhiYaRecordDao.selectZhiyaTeamRecordByMemberIdAndOrderNo(orderNo,memberId,date); + if(ObjectUtil.isEmpty(zhiyaRewardEntityDone)){ + zhiyaRewardEntity.setRecordId(zhiYaRecordEntity.getId()); + zhiyaRewardEntity.setRecordNo(zhiYaRecordEntity.getOrderNo()); + zhiyaRewardEntity.setMemberId(zhiYaRecordEntity.getMemberId()); + zhiyaRewardEntity.setType(1); + MemberEntity member = memberdao.selectById(zhiYaRecordEntity.getMemberId()); + //获取当前人的上两级 + BigDecimal multiplyReward = BigDecimal.ZERO; + MemberEntity memberEntity = memberdao.selectMemberInfoByInviteId(member.getRefererId()); + if(ObjectUtil.isNotEmpty(memberEntity)){ + //以及1代理的比例 + BigDecimal agetShangji = new BigDecimal(redisUtils.getString("GUSDREWARDAGENTONE")); + BigDecimal multiply = zhiYaRecordEntity.getZhiyaCnt().multiply(gusdReward).multiply(agetShangji); + multiplyReward = (zhiYaRecordEntity.getZhiyaCnt().multiply(gusdReward).subtract(multiply)); + ZhiyaRewardEntity zhiyaRewardEntitySJ = new ZhiyaRewardEntity(); + zhiyaRewardEntitySJ.setRecordId(zhiYaRecordEntity.getId()); + zhiyaRewardEntitySJ.setRecordNo(zhiYaRecordEntity.getOrderNo()); + zhiyaRewardEntitySJ.setMemberId(memberEntity.getId()); + zhiyaRewardEntitySJ.setType(2); + zhiyaRewardEntitySJ.setRewardAmout(multiply); + zhiyaRewardDao.insert(zhiyaRewardEntitySJ); + + MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberEntity.getId(), CoinTypeEnum.GRICE.toString()); + memberWalletCoinEntity.setAvailableBalance(memberWalletCoinEntity.getAvailableBalance().add(multiply)); + memberWalletCoinEntity.setTotalBalance(memberWalletCoinEntity.getAvailableBalance().add(multiply)); + memberWalletCoinDao.updateById(memberWalletCoinEntity); + + MemberEntity memberEntitySSJ = memberdao.selectMemberInfoByInviteId(memberEntity.getRefererId()); + if(ObjectUtil.isNotEmpty(memberEntitySSJ)){ + BigDecimal agetSSJ = new BigDecimal(redisUtils.getString("GUSDREWARDAGENTTWO")); + BigDecimal multiplySSJ = zhiYaRecordEntity.getZhiyaCnt().multiply(gusdReward).multiply(agetSSJ); + multiplyReward = (zhiYaRecordEntity.getZhiyaCnt().multiply(gusdReward).subtract(multiply).subtract(multiplySSJ)); + + MemberWalletCoinEntity memberWalletCoinEntitySSJ = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberEntity.getId(), CoinTypeEnum.GRICE.toString()); + memberWalletCoinEntitySSJ.setAvailableBalance(memberWalletCoinEntitySSJ.getAvailableBalance().add(multiply)); + memberWalletCoinEntitySSJ.setTotalBalance(memberWalletCoinEntitySSJ.getAvailableBalance().add(multiply)); + memberWalletCoinDao.updateById(memberWalletCoinEntitySSJ); + + ZhiyaRewardEntity zhiyaRewardEntitySSJ = new ZhiyaRewardEntity(); + zhiyaRewardEntitySSJ.setRecordId(zhiYaRecordEntity.getId()); + zhiyaRewardEntitySSJ.setRecordNo(zhiYaRecordEntity.getOrderNo()); + zhiyaRewardEntitySSJ.setMemberId(memberEntitySSJ.getId()); + zhiyaRewardEntitySSJ.setType(2); + zhiyaRewardEntitySSJ.setRewardAmout(multiplySSJ); + zhiyaRewardDao.insert(zhiyaRewardEntitySSJ); + } + }else{ + multiplyReward = (zhiYaRecordEntity.getZhiyaCnt().multiply(gusdReward)); + } + zhiyaRewardEntity.setRewardAmout(multiplyReward); + zhiyaRewardDao.insert(zhiyaRewardEntity); + + String refererIds = member.getRefererIds(); + if(StrUtil.isNotEmpty(refererIds)){ + String[] split = refererIds.split(","); + List<String> strings = Arrays.asList(split); + if(CollUtil.isNotEmpty(strings)){ + for(String str : strings){ + if(StrUtil.isNotEmpty(str)){ + MemberEntity memberShangJi = memberdao.selectMemberInfoByInviteId(str); + ZhiYaTeam zhiyaTeamByMemberId = zhiYaRecordDao.selectZhiyaTeamRecordByMemberId(memberShangJi.getId()); + if(ObjectUtil.isNotEmpty(zhiyaTeamByMemberId)){ + //更新数据 + zhiyaTeamByMemberId.setRewardCnt( + (zhiyaTeamByMemberId.getRewardCnt() == null ? BigDecimal.ZERO:zhiyaTeamByMemberId.getRewardCnt()).add(multiplyReward)); + zhiyaTeamDao.updateById(zhiyaTeamByMemberId); + } + } + } + } + } + } } } } @@ -353,7 +499,20 @@ return Result.ok(lists); } - public String generateSimpleSerialno(String userId) { + @Override + public Result getZhiyaRewardTypeTo(ZhiyaRewardRecordsTypePageDto recordsPageDto) { + + //获取用户ID + Long memberId = LoginUserUtils.getAppLoginUser().getId(); + + Page<ZhiyaRewardVo> page = new Page<>(recordsPageDto.getPageNum(), recordsPageDto.getPageSize()); + ZhiyaRewardEntity zhiyaRewardEntity = new ZhiyaRewardEntity(); + zhiyaRewardEntity.setMemberId(memberId); + IPage<ZhiyaRewardVo> lists = zhiYaRecordDao.selectZhiyaRewardTypeToByMemberIdInPage(page, zhiyaRewardEntity); + return Result.ok(lists); + } + + public String generateSimpleSerialno(String userId) { StringBuilder sb = new StringBuilder(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd"); diff --git a/src/main/java/com/xcong/excoin/modules/member/dao/MemberDao.java b/src/main/java/com/xcong/excoin/modules/member/dao/MemberDao.java index c0e85fa..d1c18ee 100644 --- a/src/main/java/com/xcong/excoin/modules/member/dao/MemberDao.java +++ b/src/main/java/com/xcong/excoin/modules/member/dao/MemberDao.java @@ -3,9 +3,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.xcong.excoin.modules.coin.parameter.vo.ZhiyaInfoVo; +import com.xcong.excoin.modules.coin.entity.ZhiYaTeam; import com.xcong.excoin.modules.member.entity.MemberEntity; -import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; import com.xcong.excoin.modules.member.parameter.vo.MemberTeamVo; import com.xcong.excoin.modules.member.parameter.vo.NeedMoneyMemberVo; import org.apache.ibatis.annotations.Param; @@ -26,4 +25,13 @@ public List<NeedMoneyMemberVo> selectAllNeedMoneyMember(@Param("list") List<String> list); IPage<MemberTeamVo> selectAllTeamByInviteIdInPage(Page<MemberTeamVo> page, @Param("record")MemberEntity memberEntity); + + List<MemberEntity> selectMemberInfoByRefererId(@Param("inviteId") String inviteId); + + ZhiYaTeam selectZhiYaTeamRecordByMemberId(@Param("memberId")Long zhiShuMemberId); + + int selectMemberCountByInvitedId(@Param("inviteId")String inviteId); + + MemberTeamVo selectAllTeamByInviteIdInPage(@Param("memberId")Long memberId, @Param("inviteId")String inviteId); + } diff --git a/src/main/java/com/xcong/excoin/modules/member/parameter/vo/MemberTeamVo.java b/src/main/java/com/xcong/excoin/modules/member/parameter/vo/MemberTeamVo.java index d64bd18..b55d891 100644 --- a/src/main/java/com/xcong/excoin/modules/member/parameter/vo/MemberTeamVo.java +++ b/src/main/java/com/xcong/excoin/modules/member/parameter/vo/MemberTeamVo.java @@ -1,21 +1,27 @@ package com.xcong.excoin.modules.member.parameter.vo; -import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.*; -import java.util.Date; +import java.math.BigDecimal; @Data @ApiModel(value = "MemberTeamVo", description = "返回参数") public class MemberTeamVo { - @ApiModelProperty(value = "账号") - private String account; + @ApiModelProperty(value = "团队总人数") + private Integer teamCnt; - @ApiModelProperty(value = "注册时间") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - private Date createTime; + @ApiModelProperty(value = "质押总数") + private BigDecimal zhiyaCnt; + + @ApiModelProperty(value = "收益总数") + private BigDecimal rewardCnt; + + @ApiModelProperty(value = "团队详情") + private List<TeamVo> teamVo; + } diff --git a/src/main/java/com/xcong/excoin/modules/member/parameter/vo/TeamVo.java b/src/main/java/com/xcong/excoin/modules/member/parameter/vo/TeamVo.java new file mode 100644 index 0000000..c697858 --- /dev/null +++ b/src/main/java/com/xcong/excoin/modules/member/parameter/vo/TeamVo.java @@ -0,0 +1,25 @@ +package com.xcong.excoin.modules.member.parameter.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +@Data +@ApiModel(value = "TeamVo", description = "返回参数") +public class TeamVo { + + @ApiModelProperty(value = "账号") + private String account; + + @ApiModelProperty(value = "团队总人数") + private Integer teamCnt; + + @ApiModelProperty(value = "质押总数") + private BigDecimal zhiyaCnt; + + @ApiModelProperty(value = "收益总数") + private BigDecimal rewardCnt; + +} diff --git a/src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java b/src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java index a6addc9..301e739 100644 --- a/src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java +++ b/src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java @@ -17,8 +17,11 @@ import com.xcong.excoin.common.system.service.CommonService; import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao; import com.xcong.excoin.modules.coin.dao.ZhiYaDao; +import com.xcong.excoin.modules.coin.dao.ZhiYaRecordDao; import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange; import com.xcong.excoin.modules.coin.entity.ZhiYaEntity; +import com.xcong.excoin.modules.coin.entity.ZhiYaRecordEntity; +import com.xcong.excoin.modules.coin.entity.ZhiYaTeam; import com.xcong.excoin.modules.coin.parameter.vo.ZhiyaInfoVo; import com.xcong.excoin.modules.member.dao.*; import com.xcong.excoin.modules.member.entity.*; @@ -39,6 +42,7 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.web3j.abi.datatypes.Int; import java.math.BigDecimal; import java.util.ArrayList; @@ -59,6 +63,9 @@ @Resource private MemberDao memberDao; + + @Resource + private ZhiYaRecordDao zhiYaRecordDao; @Resource private MemberWalletAgentDao memberWalletAgentDao; @@ -1031,12 +1038,45 @@ //获取用户ID Long memberId = LoginUserUtils.getAppLoginUser().getId(); MemberEntity member = memberDao.selectById(memberId); - Page<MemberTeamVo> page = new Page<>(memberTeamRecordsPageDto.getPageNum(), memberTeamRecordsPageDto.getPageSize()); - MemberEntity memberEntity = new MemberEntity(); - memberEntity.setId(memberId); - memberEntity.setInviteId(member.getInviteId()); - IPage<MemberTeamVo> lists = memberDao.selectAllTeamByInviteIdInPage(page, memberEntity); - return Result.ok(lists); + MemberTeamVo memberTeamVo = memberDao.selectAllTeamByInviteIdInPage(memberId,member.getInviteId()); + List<TeamVo> teamVos = new ArrayList<>(); + if(ObjectUtil.isEmpty(memberTeamVo)){ + MemberTeamVo memberTeamVoNull = new MemberTeamVo(); + Integer teamCnt = memberDao.selectMemberCountByInvitedId(member.getInviteId()); + memberTeamVoNull.setTeamCnt(teamCnt); + memberTeamVoNull.setZhiyaCnt(BigDecimal.ZERO); + memberTeamVoNull.setRewardCnt(BigDecimal.ZERO); + memberTeamVoNull.setTeamVo(teamVos); + return Result.ok(memberTeamVoNull); + } + //直属会员 + List<MemberEntity> memberZhiShu = memberDao.selectMemberInfoByRefererId(member.getInviteId()); + if(CollUtil.isNotEmpty(memberZhiShu)){ + for(MemberEntity zhishu : memberZhiShu){ + Long zhiShuMemberId = zhishu.getId(); + ZhiYaTeam zhiYaTeam = memberDao.selectZhiYaTeamRecordByMemberId(zhiShuMemberId); + TeamVo teamVo = new TeamVo(); + String phone = zhishu.getPhone(); + if(StrUtil.isNotEmpty(phone)){ + String result = phone.substring(phone.length()-4,phone.length()); + teamVo.setAccount(result); + } + int memberCnt = memberDao.selectMemberCountByInvitedId(zhishu.getInviteId()); + teamVo.setTeamCnt(memberCnt); + + Long aLong = zhiYaRecordDao.selectSumZhiyaCntByMemberIdAndOrderStatus(zhiShuMemberId, 1); + Long rLong = zhiYaRecordDao.selectSumRewardCntByMemberId(zhiShuMemberId); + teamVo.setZhiyaCnt(new BigDecimal(aLong)); + teamVo.setRewardCnt(new BigDecimal(rLong)); + if(ObjectUtil.isNotEmpty(zhiYaTeam)){ + teamVo.setZhiyaCnt((zhiYaTeam.getZhiyaCnt() == null ? BigDecimal.ZERO : zhiYaTeam.getZhiyaCnt()).add(new BigDecimal(aLong))); + teamVo.setRewardCnt(zhiYaTeam.getRewardCnt() == null ?BigDecimal.ZERO : zhiYaTeam.getRewardCnt().add(new BigDecimal(rLong))); + } + teamVos.add(teamVo); + } + memberTeamVo.setTeamVo(teamVos); + } + return Result.ok(memberTeamVo); } } diff --git a/src/main/java/com/xcong/excoin/quartz/job/ZhiyarRewardJob.java b/src/main/java/com/xcong/excoin/quartz/job/ZhiyarRewardJob.java index 92172e7..3fac1d5 100644 --- a/src/main/java/com/xcong/excoin/quartz/job/ZhiyarRewardJob.java +++ b/src/main/java/com/xcong/excoin/quartz/job/ZhiyarRewardJob.java @@ -21,11 +21,14 @@ /** * 质押奖励计算 */ - @Scheduled(cron = "0 0 0 * * ? ") + @Scheduled(cron = "0 * * * * ? ") +// @Scheduled(cron = "0 0 0 * * ? ") public void updateDoingPrice() { log.info("#质押奖励计算#"); try { + //静态算力 zhiyaService.grantZhiyaAmount(); + //todo -- 动态算力计算 } catch (Exception e) { log.error("#质押奖励计算错误#", e); } diff --git a/src/main/resources/mapper/member/MemberDao.xml b/src/main/resources/mapper/member/MemberDao.xml index aa15dbf..b3532e1 100644 --- a/src/main/resources/mapper/member/MemberDao.xml +++ b/src/main/resources/mapper/member/MemberDao.xml @@ -45,11 +45,27 @@ </foreach > </select> + <select id="selectMemberInfoByRefererId" resultType="com.xcong.excoin.modules.member.entity.MemberEntity"> + SELECT m.* FROM member m WHERE m.referer_id = #{inviteId} + </select> + + <select id="selectZhiYaTeamRecordByMemberId" resultType="com.xcong.excoin.modules.coin.entity.ZhiYaTeam"> + SELECT m.* FROM zhiya_Team m WHERE m.member_id = #{memberId} + </select> + + + <select id="selectMemberCountByInvitedId" resultType="integer"> + SELECT count(*) FROM member m where FIND_IN_SET(#{inviteId}, referer_ids) + </select> + + + <select id="selectAllTeamByInviteIdInPage" resultType="com.xcong.excoin.modules.member.parameter.vo.MemberTeamVo"> SELECT - m.phone account, - m.create_time createTime - FROM member m where m.referer_id = #{record.inviteId} + ifnull(m.zhiya_cnt,0) zhiyaCnt, + ifnull(m.reward_cnt,0) rewardCnt, + ifnull((SELECT count(*) FROM member b where FIND_IN_SET(#{inviteId}, referer_ids)),0) teamCnt + FROM zhiya_team m where m.member_id = #{memberId} order by m.create_time desc </select> </mapper> \ No newline at end of file diff --git a/src/main/resources/mapper/walletCoinOrder/ZhiYaRecordDao.xml b/src/main/resources/mapper/walletCoinOrder/ZhiYaRecordDao.xml index 45c778d..6553c73 100644 --- a/src/main/resources/mapper/walletCoinOrder/ZhiYaRecordDao.xml +++ b/src/main/resources/mapper/walletCoinOrder/ZhiYaRecordDao.xml @@ -55,4 +55,35 @@ SELECT ifnull(sum(a.zhiya_cnt),0) FROM zhiya_record a where a.order_status= #{orderStatus} and #{now} > a.effect_date </select> + <select id="selectZhiyaTeamRecordByMemberId" resultType="com.xcong.excoin.modules.coin.entity.ZhiYaTeam"> + SELECT a.* FROM zhiya_Team a where a.member_id= #{memberId} + </select> + + + <select id="selectZhiyaTeamRecordByMemberIdAndOrderNo" resultType="com.xcong.excoin.modules.coin.entity.ZhiyaRewardEntity"> + <![CDATA[ SELECT a.* FROM zhiya_reward a where a.member_id= #{memberId} and type = 1 + and DATE_FORMAT(a.create_time, '%Y-%m-%d') = DATE_FORMAT(#{now}, '%Y-%m-%d')]]> + </select> + + <select id="selectSumZhiyaCntByMemberIdAndOrderStatus" resultType="long"> + SELECT ifnull(sum(a.zhiya_cnt),0) FROM zhiya_record a where a.member_id= #{memberId} and a.order_status = #{orderStatus} + </select> + + <select id="selectSumRewardCntByMemberId" resultType="long"> + SELECT ifnull(sum(a.reward_amout),0) FROM zhiya_reward a where a.member_id= #{memberId} and type= 1 + </select> + + <select id="selectZhiyaRewardTypeToByMemberIdInPage" resultType="com.xcong.excoin.modules.coin.parameter.vo.ZhiyaRewardVo"> + select * from zhiya_reward + <if test="record != null"> + <where> + and type = 2 + <if test="record.memberId != null" > + and member_id=#{record.memberId} + </if> + </where> + </if> + order by id desc + </select> + </mapper> -- Gitblit v1.9.1