apps流水逻辑

This commit is contained in:
lu7213 committed 2026-10-13 11:24:20 -04:00
1 parent 0ff174e872
commit 15cc537639
10 files changed
+256 -232

No files matched your search

@@ -62,7 +62,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="operatorId != null "> and operator_id = #{operatorId}</if>
<if test="requestId != null and requestId != ''"> and request_id = #{requestId}</if>
<if test="createdAt != null "> and created_at = #{createdAt}</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="selectAppsBalanceLedgerById" parameterType="Long" resultMap="AppsBalanceLedgerResult">
@@ -126,6 +129,60 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
</insert>
<insert id="insertSystemLedgerIgnoreDuplicate" parameterType="AppsBalanceLedger">
insert into apps_balance_ledger
(trade_no, idempotency_key, app_id, user_id, currency, balance_type,
business_type, direction, amount, balance_before, balance_after,
available_before, available_after, frozen_before, frozen_after,
order_id, merchant_order_id, transaction_id, remark, created_at)
values
(#{tradeNo}, #{idempotencyKey}, #{appId}, #{userId}, #{currency}, #{balanceType},
#{businessType}, #{direction}, #{amount}, #{balanceBefore}, #{balanceAfter},
#{availableBefore}, #{availableAfter}, #{frozenBefore}, #{frozenAfter},
#{orderId}, #{merchantOrderId}, #{transactionId}, #{remark}, #{createdAt})
on duplicate key update id = id
</insert>
<sql id="statisticsConditions">
1 = 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="businessType != null and businessType != ''">and business_type = #{businessType}</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 apps_balance_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 apps_balance_ledger
where <include refid="statisticsConditions"/>
group by period, currency
order by period, currency
</select>
<update id="updateAppsBalanceLedger" parameterType="AppsBalanceLedger">
update apps_balance_ledger
<trim prefix="SET" suffixOverrides=",">
@@ -167,4 +224,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
</mapper>
</mapper>
@@ -74,6 +74,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id} and deleted_at is null for update
</select>
<update id="updateAvailableBalances">
update apps
set usdt_balance = #{usdtBalance}, trx_balance = #{trxBalance}, updated_at = #{updatedAt}
where id = #{id} and deleted_at is null
</update>
<update id="updateKeyPair">
update apps
set public_key = #{publicKey}, private_key = #{privateKey}, updated_at = #{updatedAt}