fix some bug and problem and add agent return
11 files modified
4 files added
| | |
| | | return FebsUtil.view("dapp/return-ratio"); |
| | | } |
| | | |
| | | |
| | | @GetMapping(value = "agentReturn") |
| | | @RequiresPermissions("agentReturn:view") |
| | | public String agentReturn() { |
| | | return FebsUtil.view("dapp/agent-return"); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package cc.mrbird.febs.dapp.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-04-02 |
| | | **/ |
| | | @Data |
| | | @TableName("dapp_agent_return_flow") |
| | | public class DappAgentReturnFlowEntity { |
| | | |
| | | @TableId(value = "id",type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | private Date createTime; |
| | | |
| | | private Long memberId; |
| | | |
| | | private Long agentMemberId; |
| | | |
| | | private BigDecimal amount; |
| | | |
| | | private Integer isReturn; |
| | | } |
New file |
| | |
| | | package cc.mrbird.febs.dapp.mapper; |
| | | |
| | | import cc.mrbird.febs.dapp.entity.DappAgentReturnFlowEntity; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | public interface DappAgentReturnFlowDao extends BaseMapper<DappAgentReturnFlowEntity> { |
| | | |
| | | BigDecimal selectTotalAmountByMemberId(@Param("memberId") Long memberId, @Param("isReturn") Integer isReturn); |
| | | } |
| | |
| | | IPage<DappMemberEntity> selectInPage(@Param("record") DappMemberEntity member, Page<DappMemberEntity> page); |
| | | |
| | | List<DappMemberEntity> selectAllMemberForInCome(); |
| | | |
| | | List<DappMemberEntity> selectAgentMemberList(@Param("list") List<String> inviteIds, @Param("size") Integer size); |
| | | } |
| | |
| | | int deleteByUserIds(@Param("list") List<String> id); |
| | | |
| | | DappUserMemberRelateEntity selectByUserId(@Param("userId") Long userId); |
| | | |
| | | DappUserMemberRelateEntity selectByInviteId(@Param("inviteId") String inviteId); |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | public interface DappWalletMineDao extends BaseMapper<DappWalletMineEntity> { |
| | | |
| | | DappWalletMineEntity selectByMemberId(@Param("memberId") Long memberId); |
| | | |
| | | IPage<DappWalletMineEntity> selectInPage(@Param("record") DappWalletMineEntity walletMine, Page<DappWalletMineEntity> page); |
| | | |
| | | int updateBalance(@Param("totalAmount") BigDecimal totalAmount, @Param("availableAmount") BigDecimal availableAmount, @Param("memberId") Long memberId); |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void add(User user) { |
| | | User currentUser = FebsUtil.getCurrentUser(); |
| | | DappMemberEntity member = dappMemberDao.selectMemberInfoByInviteId(user.getInviteId()); |
| | | if(member == null) { |
| | | throw new FebsException("邀请码错误"); |
| | | } |
| | | |
| | | if (currentUser.getDeptId() == null) { |
| | | DappUserMemberRelateEntity relate = dappUserMemberRelateDao.selectByUserId(currentUser.getUserId()); |
| | | if (!relate.getInviteId().equals(member.getRefererId())) { |
| | | throw new FebsException("该用户不是直推"); |
| | | } |
| | | } |
| | | |
| | | DappUserMemberRelateEntity userMemberRelate = dappUserMemberRelateDao.selectByInviteId(user.getInviteId()); |
| | | if (userMemberRelate != null) { |
| | | throw new FebsException("邀请码用户已存在"); |
| | | } |
| | | |
| | | user.setCreateTime(new Date()); |
| | |
| | | userRole.setUserId(user.getUserId()); |
| | | userRoleMapper.insert(userRole); |
| | | |
| | | User currentUser = FebsUtil.getCurrentUser(); |
| | | DappUserMemberRelateEntity relate = new DappUserMemberRelateEntity(); |
| | | relate.setMemberId(member.getId()); |
| | | relate.setUserId(user.getUserId()); |
| | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | |
| | | private DappAccountMoneyChangeDao dappAccountMoneyChangeDao; |
| | | @Autowired |
| | | private DappWalletMineDao dappWalletMineDao; |
| | | @Autowired |
| | | private DappAgentReturnFlowDao dappAgentReturnFlowDao; |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | |
| | | walletMine.setAvailableAmount(walletMine.getAvailableAmount().add(ethIncome)); |
| | | walletMine.setTotalAmount(walletMine.getTotalAmount().add(ethIncome)); |
| | | dappWalletMineDao.updateById(walletMine); |
| | | |
| | | // 计算代理返多少 |
| | | calAgentMoney(member, ethIncome); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | returnMoney(); |
| | | } |
| | | |
| | | int[] ratios = {8, 4, 4, 2, 2}; |
| | | BigDecimal returnRatio = new BigDecimal("20"); |
| | | |
| | | /** |
| | | * 代理返利 |
| | | * |
| | | * @param member |
| | | * @param amount |
| | | */ |
| | | private void calAgentMoney(DappMemberEntity member, BigDecimal amount) { |
| | | if (StrUtil.isBlank(member.getRefererIds())) { |
| | | return; |
| | | } |
| | | |
| | | List<DappMemberEntity> agents = dappMemberDao.selectAgentMemberList(StrUtil.split(member.getRefererIds(), ','), 5); |
| | | |
| | | for (int i = 0; i < agents.size(); i++) { |
| | | DappMemberEntity agent = agents.get(i); |
| | | BigDecimal balance = ChainService.INSTANCE.balanceOf(agent.getAddress()); |
| | | if (balance.compareTo(BigDecimal.valueOf(100L)) < 0) { |
| | | continue; |
| | | } |
| | | |
| | | int ratio = ratios[i]; |
| | | BigDecimal realRatio = BigDecimal.valueOf(ratio).divide(returnRatio, 2, RoundingMode.HALF_DOWN); |
| | | BigDecimal returnMoney = amount.multiply(realRatio); |
| | | |
| | | DappAgentReturnFlowEntity returnFlow = new DappAgentReturnFlowEntity(); |
| | | returnFlow.setCreateTime(new Date()); |
| | | returnFlow.setMemberId(member.getId()); |
| | | returnFlow.setAgentMemberId(agent.getId()); |
| | | returnFlow.setAmount(returnMoney); |
| | | returnFlow.setIsReturn(2); |
| | | dappAgentReturnFlowDao.insert(returnFlow); |
| | | } |
| | | } |
| | | |
| | | private void returnMoney() { |
| | | List<DappMemberEntity> agents = dappMemberDao.selectAgentMemberList(null, null); |
| | | if (CollUtil.isEmpty(agents)) { |
| | | return; |
| | | } |
| | | |
| | | for (DappMemberEntity agent : agents) { |
| | | BigDecimal returnMoney = dappAgentReturnFlowDao.selectTotalAmountByMemberId(agent.getId(), 2); |
| | | if (returnMoney.compareTo(BigDecimal.ZERO) <= 0) { |
| | | continue; |
| | | } |
| | | |
| | | DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(agent.getId()); |
| | | dappWalletMineDao.updateBalance(returnMoney, returnMoney, agent.getId()); |
| | | |
| | | // 流水 |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(agent.getId(), returnMoney, 4, null, null); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | |
| | | String content = "代理返利:" + returnMoney.toPlainString(); |
| | | DappAccountMoneyChangeEntity accountMoneyChange = new DappAccountMoneyChangeEntity(agent.getId(), walletMine.getAvailableAmount(), returnMoney, walletMine.getAvailableAmount().add(returnMoney), content, 4); |
| | | dappAccountMoneyChangeDao.insert(accountMoneyChange); |
| | | } |
| | | } |
| | | } |
| | |
| | | username: sys_dapp |
| | | password: sys_dapp!@#123 |
| | | driver-class-name: com.mysql.cj.jdbc.Driver |
| | | url: jdbc:mysql://127.0.0.1:3306/sys-dapp?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b9 |
| | | url: jdbc:mysql://127.0.0.1:3306/sys_dapp?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b9 |
| | | |
| | | redis: |
| | | # Redis数据库索引(默认为 0) |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="cc.mrbird.febs.dapp.mapper.DappAgentReturnFlowDao"> |
| | | |
| | | <select id="selectTotalAmountByMemberId" resultType="java.math.BigDecimal"> |
| | | select IFNULL(sum(amount),0) |
| | | from dapp_agent_return_flow |
| | | where agent_member_id=#{memberId} |
| | | <if test="isReturn!=null"> |
| | | and is_return=#{isReturn} |
| | | </if> |
| | | </select> |
| | | |
| | | </mapper> |
| | |
| | | select * from dapp_member |
| | | where account_status=1 |
| | | </select> |
| | | |
| | | <select id="selectAgentMemberList" resultType="cc.mrbird.febs.dapp.entity.DappMemberEntity"> |
| | | select * from dapp_member a |
| | | inner join dapp_user_member_relate b on a.id=b.member_id |
| | | <where> |
| | | 1=1 |
| | | <if test="list != null"> |
| | | and a.invite_id in |
| | | <foreach collection="list" close=")" open="(" item="item" separator=","> |
| | | ${item} |
| | | </foreach> |
| | | </if> |
| | | </where> |
| | | <if test="size != null"> |
| | | limit ${size} |
| | | </if> |
| | | </select> |
| | | </mapper> |
| | |
| | | select * from dapp_user_member_relate |
| | | where user_id=#{userId} |
| | | </select> |
| | | |
| | | <select id="selectByInviteId" resultType="cc.mrbird.febs.dapp.entity.DappUserMemberRelateEntity"> |
| | | select * from dapp_user_member_relate |
| | | where invite_id=#{inviteId} |
| | | </select> |
| | | </mapper> |
| | |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | <update id="updateBalance"> |
| | | update dapp_wallet_mine |
| | | set total_amount = total_amount + #{totalAmount}, |
| | | available_amount = available_amount + #{availableAmount} |
| | | where member_id=#{memberId} |
| | | </update> |
| | | </mapper> |
New file |
| | |
| | | <div class="layui-fluid layui-anim febs-anim" id="febs-agent-return" lay-title="代理返利"> |
| | | <div class="layui-row febs-container"> |
| | | <div class="layui-col-md12"> |
| | | <div class="layui-card"> |
| | | <div class="layui-card-body febs-table-full"> |
| | | <form class="layui-form layui-table-form" lay-filter="withdraw-table-form"> |
| | | <div class="layui-row"> |
| | | <div class="layui-col-md10"> |
| | | <div class="layui-form-item"> |
| | | <div class="layui-inline"> |
| | | <div class="layui-input-inline"> |
| | | <input type="text" name="address" autocomplete="off" placeholder="输入地址或邀请码" class="layui-input"> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area"> |
| | | <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query"> |
| | | <i class="layui-icon"></i> |
| | | </div> |
| | | <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset"> |
| | | <i class="layui-icon"></i> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </form> |
| | | <table lay-filter="agentReturnTable" lay-data="{id: 'agentReturnTable'}"></table> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <style> |
| | | .layui-table-cell { |
| | | height: auto !important; |
| | | } |
| | | </style> |
| | | <script data-th-inline="none" type="text/javascript"> |
| | | layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'treeSelect'], function () { |
| | | var $ = layui.jquery, |
| | | laydate = layui.laydate, |
| | | febs = layui.febs, |
| | | form = layui.form, |
| | | table = layui.table, |
| | | dropdown = layui.dropdown, |
| | | $view = $('#febs-agent-return'), |
| | | $query = $view.find('#query'), |
| | | $reset = $view.find('#reset'), |
| | | $searchForm = $view.find('form'), |
| | | sortObject = {field: 'createTime', type: null}, |
| | | tableIns; |
| | | |
| | | form.render(); |
| | | |
| | | initTable(); |
| | | |
| | | table.on('tool(agentReturnTable)', function (obj) { |
| | | var data = obj.data, |
| | | layEvent = obj.event; |
| | | }); |
| | | |
| | | table.on('sort(agentReturnTable)', function (obj) { |
| | | sortObject = obj; |
| | | tableIns.reload({ |
| | | initSort: obj, |
| | | where: $.extend(getQueryParams(), { |
| | | field: obj.field, |
| | | order: obj.type |
| | | }) |
| | | }); |
| | | }); |
| | | |
| | | $query.on('click', function () { |
| | | var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type}); |
| | | tableIns.reload({where: params, page: {curr: 1}}); |
| | | }); |
| | | |
| | | $reset.on('click', function () { |
| | | $searchForm[0].reset(); |
| | | tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject}); |
| | | }); |
| | | |
| | | function initTable() { |
| | | tableIns = febs.table.init({ |
| | | elem: $view.find('table'), |
| | | id: 'agentReturnTable', |
| | | url: ctx + 'flow/fundFlow?type=4', |
| | | cols: [[ |
| | | {field: 'address', title: '地址', minWidth: 130}, |
| | | {field: 'createTime', title: '创建时间', minWidth: 180}, |
| | | {field: 'amount', title: '返利金额(ETH)', minWidth: 130} |
| | | ]] |
| | | }); |
| | | } |
| | | |
| | | function getQueryParams() { |
| | | return { |
| | | address: $searchForm.find('input[name="address"]').val().trim(), |
| | | invalidate_ie_cache: new Date() |
| | | }; |
| | | } |
| | | }) |
| | | </script> |
| | |
| | | <option value="1">兑换</option> |
| | | <option value="2">提现</option> |
| | | <option value="3">采矿</option> |
| | | <option value="4">代理返利</option> |
| | | </select> |
| | | </div> |
| | | </div> |
| | |
| | | var type = { |
| | | 1: {title: '兑换'}, |
| | | 2: {title: '提现'}, |
| | | 3: {title: '采矿'} |
| | | 3: {title: '采矿'}, |
| | | 4: {title: '代理返利'} |
| | | }[d.type]; |
| | | }} |
| | | <span>{{ type.title }}</span> |