update 新增系统钱包功能,用于记录手续费
This commit is contained in:
76
src/main/java/com/m2pool/lease/entity/LeaseSystemWallet.java
Normal file
76
src/main/java/com/m2pool/lease/entity/LeaseSystemWallet.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package com.m2pool.lease.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统钱包表
|
||||
* </p>
|
||||
*
|
||||
* @author yyb
|
||||
* @since 2026-02-02
|
||||
*/
|
||||
@Builder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("lease_system_wallet")
|
||||
public class LeaseSystemWallet implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 卖家地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 币种名称
|
||||
*/
|
||||
private String symbol;
|
||||
|
||||
/**
|
||||
* 余额
|
||||
*/
|
||||
private BigDecimal balance;
|
||||
|
||||
/**
|
||||
* 冻结余额
|
||||
*/
|
||||
private BigDecimal blcokBalance;
|
||||
|
||||
/**
|
||||
* 链名称
|
||||
*/
|
||||
private String chain;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除字段
|
||||
*/
|
||||
private Boolean del;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.m2pool.lease.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统钱包交易信息表(提现+卖家的手续费收款记录)
|
||||
* </p>
|
||||
*
|
||||
* @author yyb
|
||||
* @since 2026-02-02
|
||||
*/
|
||||
@Builder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("lease_system_wallet_transaction")
|
||||
public class LeaseSystemWalletTransaction implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 消息ID
|
||||
*/
|
||||
private String queueId;
|
||||
|
||||
/**
|
||||
* 卖家地址
|
||||
*/
|
||||
private String sellerAddress;
|
||||
|
||||
/**
|
||||
* 买家地址
|
||||
*/
|
||||
private String buyerAddress;
|
||||
|
||||
/**
|
||||
* 系统地址(手续费入账地址)
|
||||
*/
|
||||
private String systemAddress;
|
||||
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
private String orderId;
|
||||
|
||||
/**
|
||||
* 卖方--商铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 买方--邮箱
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 卖方--手续费率
|
||||
*/
|
||||
private BigDecimal feeRate;
|
||||
|
||||
/**
|
||||
* 卖方--收款金额(未扣手续费)
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 卖方--实收金额(已扣手续费)
|
||||
*/
|
||||
private BigDecimal receivedAmount;
|
||||
|
||||
/**
|
||||
* 卖方--手续费
|
||||
*/
|
||||
private BigDecimal fee;
|
||||
|
||||
/**
|
||||
* 币种名称
|
||||
*/
|
||||
private String symbol;
|
||||
|
||||
/**
|
||||
* 链名称
|
||||
*/
|
||||
private String chain;
|
||||
|
||||
/**
|
||||
* 交易id
|
||||
*/
|
||||
private String txHash;
|
||||
|
||||
/**
|
||||
* 支付时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 逻辑删除字段
|
||||
*/
|
||||
private Boolean del;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.m2pool.lease.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.m2pool.lease.entity.LeaseSystemWallet;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统钱包 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yyb
|
||||
* @since 2026-02-02
|
||||
*/
|
||||
@Mapper
|
||||
public interface LeaseSystemWalletMapper extends BaseMapper<LeaseSystemWallet> {
|
||||
|
||||
/**
|
||||
* 根据地址、币种和链查询系统钱包
|
||||
* @param address 地址
|
||||
* @param symbol 币种
|
||||
* @param chain 链
|
||||
* @return 系统钱包
|
||||
*/
|
||||
LeaseSystemWallet selectByAddressAndSymbolAndChain(@Param("address") String address,
|
||||
@Param("symbol") String symbol,
|
||||
@Param("chain") String chain);
|
||||
|
||||
/**
|
||||
* 批量更新系统钱包余额
|
||||
* @param list 系统钱包更新列表
|
||||
* @return 更新数量
|
||||
*/
|
||||
int updateBalanceById(@Param("list") List<LeaseSystemWallet> list);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.m2pool.lease.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.m2pool.lease.entity.LeaseSystemWalletTransaction;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统钱包交易信息表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yyb
|
||||
* @since 2026-02-02
|
||||
*/
|
||||
@Mapper
|
||||
public interface LeaseSystemWalletTransactionMapper extends BaseMapper<LeaseSystemWalletTransaction> {
|
||||
|
||||
/**
|
||||
* 批量插入系统手续费交易记录
|
||||
* @param list 交易记录列表
|
||||
* @return 插入数量
|
||||
*/
|
||||
int insertBatch(@Param("list") List<LeaseSystemWalletTransaction> list);
|
||||
}
|
||||
@@ -765,9 +765,9 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
return Result.fail("购买的ASIC商品中,存在可售数量不足的商品!");
|
||||
}
|
||||
boolean isGpuPass = checkGpuMachine(gpuMachines);
|
||||
if (!isGpuPass){
|
||||
return Result.fail("购买的GPU商品中,存在客户端不在线的矿机!");
|
||||
}
|
||||
//if (!isGpuPass){
|
||||
// return Result.fail("购买的GPU商品中,存在客户端不在线的矿机!");
|
||||
//}
|
||||
//存储相同链和币种的map集合
|
||||
Map<String, Map<String, List<OrderInfoVo>>> chainAndCoinMap = new HashMap<>();
|
||||
Map<Long, LeaseMachinePrice> orderTotalPriceGroupByChainAndCoin = leaseMachinePriceMapper.getOrderTotalPriceGroupByChainAndCoin(orderInfoVoList);
|
||||
@@ -960,9 +960,9 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
if (i != machineIds.size()){
|
||||
throw new OrderException("订单中已有商品售出,请刷新购物车删除已售出商品,重新结算生成订单");
|
||||
}
|
||||
if(!checkGpuMachine(gpuMachines)){
|
||||
throw new OrderException("购买的GPU商品中,存在客户端不在线的矿机!");
|
||||
}
|
||||
//if(!checkGpuMachine(gpuMachines)){
|
||||
// throw new OrderException("购买的GPU商品中,存在客户端不在线的矿机!");
|
||||
//}
|
||||
//gpu矿机处理 发送消息
|
||||
sendMessageToClientAndInsertPurchasedMachine(SecurityUtils.getUserId(),userEmail,gpuMachines,orderMiningInfoDtoList,endMiningMap,machineOrderIdMap,machineOrderItemIdMap);
|
||||
|
||||
@@ -1112,7 +1112,7 @@ public class LeaseOrderInfoServiceImpl extends ServiceImpl<LeaseOrderInfoMapper,
|
||||
.authId(authId)
|
||||
.coin(coin)
|
||||
.algorithm(algo)
|
||||
.poolUrl(poolUrl)
|
||||
.poolUrl(miningConfigDto.getPool())
|
||||
.pool(poolName)
|
||||
.poolUser(poolUser)
|
||||
.workerId(poolWorkerId)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.m2pool.lease.strategy.hashrate;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.m2pool.lease.dto.v2.PurchasedMachineListDto;
|
||||
import com.m2pool.lease.dto.v2.RealHashrateInfoDto;
|
||||
|
||||
@@ -76,7 +77,7 @@ public interface HashrateFetchStrategy {
|
||||
if (hashrateList == null || hashrateList.isEmpty()) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
System.out.println("yyb-实时算力列表"+ JSONUtil.toJsonPrettyStr(hashrateList) +BigDecimal.valueOf(getDataPoints()));
|
||||
BigDecimal totalPracticalPower = BigDecimal.ZERO;
|
||||
for (RealHashrateInfoDto realHashrateInfoDto : hashrateList) {
|
||||
totalPracticalPower = totalPracticalPower.add(realHashrateInfoDto.getPower());
|
||||
|
||||
@@ -98,6 +98,10 @@ public class OrderAndPayTask {
|
||||
private RedisService redisService;
|
||||
@Resource
|
||||
private com.m2pool.lease.strategy.hashrate.HashrateStrategyFactory hashrateStrategyFactory;
|
||||
@Resource
|
||||
private LeaseSystemWalletMapper leaseSystemWalletMapper;
|
||||
@Resource
|
||||
private LeaseSystemWalletTransactionMapper leaseSystemWalletTransactionMapper;
|
||||
|
||||
/**
|
||||
* 检查钱包半年内是否有 支付,充值,提现操作
|
||||
@@ -894,7 +898,8 @@ public class OrderAndPayTask {
|
||||
//修改买家和卖家账户余额
|
||||
int buyerUpdate = leaseUserWalletDataMapper.updateBalanceAndBlockBalanceById(buyerUpdateRecords);
|
||||
int sellerUpdate = leaseShopConfigMapper.updateBalanceById(sellerUpdateRecords);
|
||||
|
||||
//系统手续费交易记录(每个订单一条记录) 和系统钱包余额增加(所有订单实收金额总和)
|
||||
handleSystemFeeTransaction(reocrdList);
|
||||
redisService.deleteCacheMapValue7(redisMapKeyFiled);
|
||||
if (buyerUpdate > 0 || sellerUpdate > 0){
|
||||
for (LeasePayRecordMessage item : reocrdList) {
|
||||
@@ -992,6 +997,93 @@ public class OrderAndPayTask {
|
||||
return sellerWallets;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理系统手续费交易记录和系统钱包余额更新
|
||||
* @param recordList 支付记录列表
|
||||
*/
|
||||
private void handleSystemFeeTransaction(List<LeasePayRecordMessage> recordList) {
|
||||
if (recordList == null || recordList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取系统钱包列表
|
||||
List<LeaseSystemWallet> systemWalletList = leaseSystemWalletMapper.selectList(new LambdaQueryWrapper<LeaseSystemWallet>()
|
||||
.eq(LeaseSystemWallet::getDel, false));
|
||||
if (systemWalletList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 构建系统钱包Map:key = symbol_chain
|
||||
Map<String, LeaseSystemWallet> systemWalletMap = systemWalletList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
wallet -> wallet.getSymbol() + "_" + wallet.getChain(),
|
||||
Function.identity()
|
||||
));
|
||||
|
||||
// 1. 为每个订单创建系统手续费交易记录
|
||||
List<LeaseSystemWalletTransaction> systemTransactions = new ArrayList<>();
|
||||
Map<Long, LeaseSystemWallet> walletIdToUpdateMap = new HashMap<>();
|
||||
|
||||
for (LeasePayRecordMessage record : recordList) {
|
||||
// 计算手续费:实收金额 - 手续费 = 卖家实收金额
|
||||
// 卖家收款金额(未扣手续费)= record.getRealAmount()
|
||||
// 卖家实收金额(已扣手续费)= record.getReceivedAmount()
|
||||
// 手续费 = record.getRealAmount() - record.getReceivedAmount()
|
||||
BigDecimal fee = record.getRealAmount().subtract(record.getReceivedAmount());
|
||||
|
||||
if (fee.compareTo(BigDecimal.ZERO) > 0) {
|
||||
// 查找对应的系统钱包
|
||||
String walletKey = record.getFromSymbol() + "_" + record.getFromChain();
|
||||
LeaseSystemWallet systemWallet = systemWalletMap.get(walletKey);
|
||||
|
||||
if (systemWallet != null) {
|
||||
// 构建系统手续费交易记录
|
||||
LeaseSystemWalletTransaction transaction = LeaseSystemWalletTransaction.builder()
|
||||
.queueId(record.getQueueId())
|
||||
.sellerAddress(record.getToAddress())
|
||||
.buyerAddress(record.getFromAddress())
|
||||
.systemAddress(systemWallet.getAddress())
|
||||
.orderId(record.getOrderId())
|
||||
.shopId(record.getShopId())
|
||||
.userId(record.getUserId())
|
||||
.feeRate(record.getFeeRate())
|
||||
.amount(record.getRealAmount())
|
||||
.receivedAmount(record.getReceivedAmount())
|
||||
.fee(fee)
|
||||
.symbol(record.getFromSymbol())
|
||||
.chain(record.getFromChain())
|
||||
.txHash(record.getTxHash())
|
||||
.build();
|
||||
systemTransactions.add(transaction);
|
||||
|
||||
// 累计需要更新的系统钱包余额
|
||||
walletIdToUpdateMap.compute(systemWallet.getId(), (id, wallet) -> {
|
||||
if (wallet == null) {
|
||||
return LeaseSystemWallet.builder()
|
||||
.id(systemWallet.getId())
|
||||
.balance(fee)
|
||||
.build();
|
||||
} else {
|
||||
wallet.setBalance(wallet.getBalance().add(fee));
|
||||
return wallet;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 批量插入系统手续费交易记录
|
||||
if (!systemTransactions.isEmpty()) {
|
||||
leaseSystemWalletTransactionMapper.insertBatch(systemTransactions);
|
||||
}
|
||||
|
||||
// 3. 批量更新系统钱包余额
|
||||
if (!walletIdToUpdateMap.isEmpty()) {
|
||||
List<LeaseSystemWallet> systemWalletsToUpdate = new ArrayList<>(walletIdToUpdateMap.values());
|
||||
leaseSystemWalletMapper.updateBalanceById(systemWalletsToUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录日志
|
||||
* @param item
|
||||
|
||||
35
src/main/resources/mapper/lease/LeaseSystemWalletMapper.xml
Normal file
35
src/main/resources/mapper/lease/LeaseSystemWalletMapper.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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="com.m2pool.lease.mapper.LeaseSystemWalletMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.m2pool.lease.entity.LeaseSystemWallet">
|
||||
<id column="id" property="id" />
|
||||
<result column="address" property="address" />
|
||||
<result column="symbol" property="symbol" />
|
||||
<result column="balance" property="balance" />
|
||||
<result column="blcok_balance" property="blcokBalance" />
|
||||
<result column="chain" property="chain" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="del" property="del" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectByAddressAndSymbolAndChain" resultMap="BaseResultMap">
|
||||
SELECT * FROM lease_system_wallet
|
||||
WHERE address = #{address}
|
||||
AND symbol = #{symbol}
|
||||
AND chain = #{chain}
|
||||
AND del = 0
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<update id="updateBalanceById">
|
||||
<foreach collection="list" item="item" separator=";">
|
||||
UPDATE lease_system_wallet
|
||||
SET balance = balance + #{item.balance}
|
||||
WHERE id = #{item.id}
|
||||
AND del = 0
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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="com.m2pool.lease.mapper.LeaseSystemWalletTransactionMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.m2pool.lease.entity.LeaseSystemWalletTransaction">
|
||||
<id column="id" property="id" />
|
||||
<result column="queue_id" property="queueId" />
|
||||
<result column="seller_address" property="sellerAddress" />
|
||||
<result column="buyer_address" property="buyerAddress" />
|
||||
<result column="system_address" property="systemAddress" />
|
||||
<result column="order_id" property="orderId" />
|
||||
<result column="shop_id" property="shopId" />
|
||||
<result column="user_id" property="userId" />
|
||||
<result column="fee_rate" property="feeRate" />
|
||||
<result column="amount" property="amount" />
|
||||
<result column="received_amount" property="receivedAmount" />
|
||||
<result column="fee" property="fee" />
|
||||
<result column="symbol" property="symbol" />
|
||||
<result column="chain" property="chain" />
|
||||
<result column="tx_hash" property="txHash" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="del" property="del" />
|
||||
</resultMap>
|
||||
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO lease_system_wallet_transaction (
|
||||
queue_id, seller_address, buyer_address, system_address, order_id, shop_id, user_id,
|
||||
fee_rate, amount, received_amount, fee, symbol, chain
|
||||
) VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(
|
||||
#{item.queueId}, #{item.sellerAddress}, #{item.buyerAddress}, #{item.systemAddress},
|
||||
#{item.orderId}, #{item.shopId}, #{item.userId}, #{item.feeRate}, #{item.amount},
|
||||
#{item.receivedAmount}, #{item.fee}, #{item.symbol}, #{item.chain}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user