订单支付成功时,事务化写入 USDT 收入流水。

归集明细成功时,事务化写入 USDT 支出流水。
使用唯一幂等键防止订单重扫、归集重试产生重复流水。
新增按应用、币种、时间范围以及日/月/年维度的统计接口。
管理员和商户接口均改为只读,移除流水新增、修改、删除入口。
商户查询由后端强制限定当前用户。
This commit is contained in:
lu7213 committed 2026-10-13 10:32:18 -04:00
1 parent 8cc7bd0c17
commit 0ff174e872
15 files changed
+377 -254

No files matched your search

@@ -49,6 +49,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectUsdtOrdersVo"/>
where id = #{id}
</select>
<select id="selectByIdForUpdate" resultType="com.ruoyi.system.domain.UsdtOrdersPlus">
select id, trade_id, order_id, block_transaction_id, actual_amount, amount, token,
status, notify_url, redirect_url, callback_num, callback_confirm, created_at,
updated_at, deleted_at, app_id, settlement_status, user_id, order_type
from orders
where id = #{id}
for update
</select>
<select id="countPaidByTransactionId" resultType="int">
select count(1)
from orders
where block_transaction_id = #{transactionId}
and status = 2
and id != #{excludeOrderId}
</select>
<update id="markOrderPaid">
update orders
set block_transaction_id = #{transactionId}, status = 2, updated_at = #{updatedAt}
where id = #{id} and status = 1
</update>
<insert id="insertUsdtOrders" parameterType="UsdtOrders" useGeneratedKeys="true" keyProperty="id">
insert into orders
@@ -129,4 +152,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
</mapper>
</mapper>
@@ -86,7 +86,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="errorMessage != null and errorMessage != ''"> and error_message = #{errorMessage}</if>
<if test="createdAt != null "> and created_at = #{createdAt}</if>
<if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
<if test="params.beginTime != null and params.beginTime != ''">
and created_at &gt;= #{params.beginTime}
</if>
<if test="params.endTime != null and params.endTime != ''">
and created_at &lt;= #{params.endTime}
</if>
</where>
order by created_at desc, id desc
</select>
<select id="selectWalletAddressLedgerById" parameterType="Long" resultMap="WalletAddressLedgerResult">
@@ -174,6 +181,61 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
</insert>
<insert id="insertSystemLedgerIgnoreDuplicate" parameterType="WalletAddressLedger">
insert into wallet_address_ledger
(trade_no, idempotency_key, app_id, user_id, wallet_address_id,
wallet_address, counterparty_address, currency, business_type, direction,
amount, order_id, merchant_order_id, trade_id, aggregation_task_id,
aggregation_item_id, transaction_id, status, source_type, remark,
created_at, updated_at)
values
(#{tradeNo}, #{idempotencyKey}, #{appId}, #{userId}, #{walletAddressId},
#{walletAddress}, #{counterpartyAddress}, #{currency}, #{businessType}, #{direction},
#{amount}, #{orderId}, #{merchantOrderId}, #{tradeId}, #{aggregationTaskId},
#{aggregationItemId}, #{transactionId}, #{status}, #{sourceType}, #{remark},
#{createdAt}, #{updatedAt})
on duplicate key update id = id
</insert>
<sql id="statisticsConditions">
status = 1
<if test="appId != null">and app_id = #{appId}</if>
<if test="userId != null">and user_id = #{userId}</if>
<if test="currency != null and currency != ''">and currency = #{currency}</if>
<if test="beginTime != null">and created_at &gt;= #{beginTime}</if>
<if test="endTime != null">and created_at &lt;= #{endTime}</if>
</sql>
<select id="selectStatisticsSummary" resultType="com.ruoyi.system.domain.vo.WalletLedgerSummaryVo">
select currency,
coalesce(sum(case when direction = 1 then amount else 0 end), 0) as incomeAmount,
coalesce(sum(case when direction = 2 then amount else 0 end), 0) as expenseAmount,
coalesce(sum(case when direction = 1 then amount else -amount end), 0) as netAmount,
count(1) as count
from wallet_address_ledger
where <include refid="statisticsConditions"/>
group by currency
order by currency
</select>
<select id="selectStatisticsTrend" resultType="com.ruoyi.system.domain.vo.WalletLedgerTrendVo">
select
<choose>
<when test="granularity == 'YEAR'">date_format(created_at, '%Y')</when>
<when test="granularity == 'MONTH'">date_format(created_at, '%Y-%m')</when>
<otherwise>date_format(created_at, '%Y-%m-%d')</otherwise>
</choose> as period,
currency,
coalesce(sum(case when direction = 1 then amount else 0 end), 0) as incomeAmount,
coalesce(sum(case when direction = 2 then amount else 0 end), 0) as expenseAmount,
coalesce(sum(case when direction = 1 then amount else -amount end), 0) as netAmount,
count(1) as count
from wallet_address_ledger
where <include refid="statisticsConditions"/>
group by period, currency
order by period, currency
</select>
<update id="updateWalletAddressLedger" parameterType="WalletAddressLedger">
update wallet_address_ledger
<trim prefix="SET" suffixOverrides=",">
@@ -227,4 +289,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
</mapper>
</mapper>