src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
@@ -180,13 +180,14 @@ BigDecimal closingPrice = price.multiply(amount).multiply(tradeSetting.getCoinFeeRatio()); //总费用 = 成交价*数量+手续费 BigDecimal totalPayPrice = price.multiply(amount).add(closingPrice); BigDecimal totalPayPricCoin = nowPrice.multiply(amount).add(closingPrice); String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue(); MemberWalletCoinEntity walletCoinUsdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode); if (OrderCoinsEntity.ORDERTYPE_BUY.equals(type)) { //买入,所需总费用跟用户USDT金额进行比较 BigDecimal availableBalance = walletCoinUsdt.getAvailableBalance(); if (totalPayPrice.compareTo(availableBalance) > 0) { if (totalPayPrice.compareTo(availableBalance) > 0 || totalPayPricCoin.compareTo(availableBalance) > 0) { return Result.fail(MessageSourceUtils.getString("order_service_0010")); } } else { @@ -252,7 +253,7 @@ totalPayPrice = nowPrice.multiply(amount).add(closingPrice); price = nowPrice; } order.setDealPrice(price); order.setDealPrice(nowPrice); order.setDealAmount(totalPayPrice); order.setOrderStatus(OrderCoinsEntity.ORDERSTATUS_DONE); order.setTradeType(tradeType); @@ -268,7 +269,7 @@ detail.setSymbol(symbol); detail.setSymbolCnt(amount); detail.setEntrustPrice(nowPriceinBigDecimal); detail.setDealPrice(price); detail.setDealPrice(nowPrice); detail.setDealAmount(totalPayPrice); detail.setFeeAmount(closingPrice); detail.setOrderStatus(OrderCoinsDealEntity.ORDERSTATUS_DONE); src/main/java/com/xcong/excoin/modules/member/dao/AgentReturnDao.java
@@ -2,9 +2,16 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.xcong.excoin.modules.member.entity.AgentReturnEntity; import org.apache.ibatis.annotations.Param; import java.util.List; /** * @author helius */ public interface AgentReturnDao extends BaseMapper<AgentReturnEntity> { List<AgentReturnEntity> selectAllNeedMoneyReturn(); int updateAgentReturnStatusByRefererId(@Param("isReturn") int isReturn, @Param("refererId") Long refererId); } src/main/java/com/xcong/excoin/modules/member/entity/AgentReturnEntity.java
@@ -29,6 +29,16 @@ */ public static final int ORDER_TYPE_HOLD = 3; /** * 是否已返佣 0-否 */ public static final int IS_RETURN_N = 0; /** * 是否已返佣 1-是 */ public static final int IS_RETURN_Y = 1; private Long memberId; private Long orderId; src/main/java/com/xcong/excoin/modules/member/entity/MemberCoinAddressEntity.java
@@ -37,7 +37,7 @@ */ private String isBiyict; public static final String IS_BIYICT_YES = "1"; public static final String IS_BIYICT_NO = "0"; public static final String IS_BIYICT_NO = "2"; /** * */ src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java
@@ -684,7 +684,7 @@ MemberCoinAddressEntity memberCoinAddressEntity = new MemberCoinAddressEntity(); memberCoinAddressEntity.setAddress(address); memberCoinAddressEntity.setMemberId(memberId); memberCoinAddressEntity.setIsBiyict(isBiyict); memberCoinAddressEntity.setIsBiyict(MemberCoinAddressEntity.IS_BIYICT_NO); memberCoinAddressEntity.setSymbolscoinId(symbolscoinId); memberCoinAddressEntity.setLabel(remark); memberCoinAddressEntity.setSymbol(platformSymbolsCoinEntity.getName()); @@ -900,6 +900,7 @@ Map<String, Object> columnMap = new HashMap<>(); columnMap.put("symbol", memberSubmitCoinApplyDto.getSymbol()); columnMap.put("address", memberSubmitCoinApplyDto.getAddress()); columnMap.put("is_biyict", MemberCoinAddressEntity.IS_BIYICT_YES); List<MemberCoinAddressEntity> selectByMap = memberCoinAddressDao.selectByMap(columnMap); if (CollUtil.isEmpty(selectByMap)) { memberCoinWithdrawEntity.setIsInside(MemberCoinWithdrawEntity.ISINSIDE_NO); src/main/resources/application.yml
@@ -7,9 +7,9 @@ profiles: active: dev datasource: url: jdbc:mysql://120.27.238.55:3306/kss_framework?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8 username: ct_test password: 123456 url: jdbc:mysql://rm-bp151tw8er79ig9kb5o.mysql.rds.aliyuncs.com:3306/db_biue?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8 username: ctcoin_data password: ctcoin_123 driver-class-name: com.mysql.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource druid: src/main/resources/mapper/member/AgentReturnDao.xml
@@ -2,4 +2,17 @@ <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.xcong.excoin.modules.member.dao.AgentReturnDao"> <select id="selectAllNeedMoneyReturn" resultType="com.xcong.excoin.modules.member.entity.AgentReturnEntity"> select referer_id, sum(return_amount) return_amount from agent_return where is_return=0 group by referer_id </select> <update id="updateAgentReturnStatusByRefererId"> update agent_return set is_return=#{isReturn} where referer_id=#{refererId} </update> </mapper> src/main/resources/mapper/member/MemberCoinAddressDao.xml
@@ -40,7 +40,7 @@ <select id="selectCoinAddressListByMap" resultType="com.xcong.excoin.modules.member.entity.MemberCoinAddressEntity"> select * from member_coin_address <where> is_biyict = 1 is_biyict = 2 and symbolscoin_id IS NOT NULL <if test="memberId != null and memberId != ''"> and member_id = #{memberId} src/test/java/com/xcong/excoin/ReturnMoneyTest.java
@@ -1,17 +1,27 @@ package com.xcong.excoin; import cn.hutool.core.collection.CollUtil; import jnr.ffi.annotations.IgnoreError; import com.xcong.excoin.modules.coin.dao.MemberAccountMoneyChangeDao; import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange; import com.xcong.excoin.modules.contract.dao.ContractOrderDao; import com.xcong.excoin.modules.contract.entity.ContractOrderEntity; import com.xcong.excoin.modules.contract.service.impl.OrderWebsocketServiceImpl; import com.xcong.excoin.modules.member.dao.AgentReturnDao; import com.xcong.excoin.modules.member.dao.MemberWalletAgentDao; import com.xcong.excoin.modules.member.entity.AgentReturnEntity; import com.xcong.excoin.modules.member.entity.MemberWalletAgentEntity; import com.xcong.excoin.utils.SpringContextHolder; import com.xcong.excoin.utils.ThreadPoolUtils; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.List; /** * @author wzy @@ -23,11 +33,55 @@ @Resource private ContractOrderDao contractOrderDao; @Resource private AgentReturnDao agentReturnDao; @Resource private MemberWalletAgentDao memberWalletAgentDao; @Resource private MemberAccountMoneyChangeDao memberAccountMoneyChangeDao; @Test /*@Test public void returnTest() { ContractOrderEntity entity = contractOrderDao.selectById(667L); OrderWebsocketServiceImpl orderWebsocketService = SpringContextHolder.getBean(OrderWebsocketServiceImpl.class); orderWebsocketService.calYj(19L, new BigDecimal(4.18004236), entity, AgentReturnEntity.ORDER_TYPE_OPEN); }*/ @Test @Transactional(rollbackFor = Exception.class) public void moneyReturnTest() { List<AgentReturnEntity> list = agentReturnDao.selectAllNeedMoneyReturn(); log.info("返佣条数:{}", list.size()); if (CollUtil.isNotEmpty(list)) { for (AgentReturnEntity agentReturn : list) { BigDecimal needReturn = agentReturn.getReturnAmount(); Long refererId = agentReturn.getRefererId(); MemberWalletAgentEntity walletAgent = memberWalletAgentDao.selectWalletAgentBymIdAndCode(refererId, "USDT"); if (walletAgent == null) { continue; } log.info("用户ID:{}, 当前余额:{},总金额:{}, 返佣金额:{}", refererId, walletAgent.getAvailableBalance().toPlainString(), walletAgent.getTotalBalance().toPlainString(), needReturn); walletAgent.setAvailableBalance(walletAgent.getAvailableBalance().add(needReturn)); walletAgent.setTotalBalance(walletAgent.getTotalBalance().add(needReturn)); MemberAccountMoneyChange moneyChange = new MemberAccountMoneyChange(); moneyChange.setAmount(needReturn); moneyChange.setContent("佣金到账"); moneyChange.setType(MemberAccountMoneyChange.TYPE_WALLET_AGENT); moneyChange.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER); moneyChange.setMemberId(refererId); moneyChange.setSymbol("USDT"); // // 更新代理钱包金额 // memberWalletAgentDao.updateById(walletAgent); // // 更新返佣明细中状态 // agentReturnDao.updateAgentReturnStatusByRefererId(AgentReturnEntity.IS_RETURN_Y, refererId); // // 插入财务流水记录 // memberAccountMoneyChangeDao.insert(moneyChange); } } } }