xiaoyong931011
2023-08-22 ef552b45c7affb3b91c39d2451a0233c1da67814
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?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.DappWalletCoinDao">
 
    <select id="selectByMemberId" resultType="cc.mrbird.febs.dapp.entity.DappWalletCoinEntity">
        select * from dapp_wallet_coin where member_id=#{memberId}
    </select>
 
    <select id="selectInPage" resultType="cc.mrbird.febs.dapp.entity.DappWalletCoinEntity">
        select a.*, b.address address from dapp_wallet_coin a
        inner join dapp_member b on a.member_id=b.id
        <where>
            <if test="record.currentUser != null">
                and b.referer_id = (select invite_id from dapp_user_member_relate where user_id=#{record.currentUser})
            </if>
            <if test="record.address != '' and record.address != null">
                and b.address = #{record.address}
            </if>
        </where>
    </select>
 
    <update id="updateWithLock">
        update dapp_wallet_coin
            set total_amount=#{record.totalAmount},
                available_amount=#{record.availableAmount},
                frozen_amount=#{record.frozenAmount},
                version=version+1
        where id=#{record.id} and version=#{record.version}
    </update>
 
    <update id="addAvailableAndDelFrozenById">
        update dapp_wallet_coin
        set
            available_amount = available_amount + #{balance},
            frozen_amount = frozen_amount - #{balance}
        where
            id = #{id}
          and frozen_amount - #{balance} <![CDATA[ >= ]]> 0
    </update>
 
    <update id="addFrozenAndDelAvailableById">
        update dapp_wallet_coin
        set
            available_amount = available_amount - #{balance},
            frozen_amount = frozen_amount + #{balance}
        where
            id = #{id}
          and available_amount - #{balance} <![CDATA[ >= ]]> 0
    </update>
 
    <update id="delTotalAndDelFrozenById">
        update dapp_wallet_coin
        set
            total_amount = total_amount - #{balance},
            frozen_amount = frozen_amount - #{balance}
        where
            id = #{id}
          and total_amount - #{balance} <![CDATA[ >= ]]> 0
          and frozen_amount - #{balance} <![CDATA[ >= ]]> 0
    </update>
 
    <update id="addTotalAndaddAvailableById">
        update dapp_wallet_coin
        set
            total_amount = total_amount + #{balance},
            available_amount = available_amount + #{balance}
        where
            id = #{id}
    </update>
 
    <update id="delAvailableDelTotalById">
        update dapp_wallet_coin
        set
            total_amount = total_amount - #{balance},
            available_amount = available_amount - #{balance}
        where
            id = #{id}
          and total_amount - #{balance} <![CDATA[ >= ]]> 0
    </update>
 
 
    <select id="selectWalletCoinBymIdAndCode" resultType="cc.mrbird.febs.dapp.entity.DappWalletCoinEntity">
        select * from dapp_wallet_coin where member_id = #{memberId} and wallet_code = #{walletCode}
    </select>
 
    <update id="updateFrozenBalance" parameterType="map">
        UPDATE dapp_wallet_coin
        SET available_amount = available_amount - #{amount},
            frozen_amount = frozen_amount + #{amount}
        WHERE
            id = #{id}
          AND member_id = #{memberId}
    </update>
 
    <update id="subFrozenBalance" parameterType="map">
        UPDATE dapp_wallet_coin
        SET available_amount = available_amount + #{amount},
            frozen_amount = frozen_amount - #{amount}
        WHERE
            id = #{id}
          AND member_id = #{memberId}
    </update>
 
 
    <update id="updateBlockBalance">
        update dapp_wallet_coin
        set
            available_amount = IFNULL(available_amount, 0) + #{availableAmount},
            total_amount = IFNULL(total_amount, 0) + #{availableAmount},
            early_amount = IFNULL(early_amount, 0) + #{earlyAmount},
            block_number  = IFNULL(block_number, 0) + #{blockNumber}
        where id=#{id}
    </update>
 
    <update id="reduceFrozenBalance">
        update dapp_wallet_coin
        set frozen_amount = frozen_amount - #{amount},
            total_amount = total_amount - #{amount}
        where id=#{id}
    </update>
 
    <select id="selectTotalAmount" resultType="cc.mrbird.febs.dapp.entity.DappMemberEntity">
        select
            b.id,
            b.invite_id,
            b.referer_id,
            b.identity,
            b.referer_ids
        from
            dapp_wallet_coin a
                inner join dapp_member b on a.member_id = b.id
        where a.total_amount <![CDATA[ >= ]]> 51
    </select>
 
    <update id="addTotalAndaddAvailableByMemberId">
        update dapp_wallet_coin
        set
            total_amount = total_amount + #{balance},
            available_amount = available_amount + #{balance}
        where
            member_id = #{memberId}
    </update>
 
    <update id="reduceTotalAndAvailableByMemberId">
        update dapp_wallet_coin
        set
            total_amount = total_amount - #{balance},
            available_amount = available_amount - #{balance}
        where
            member_id = #{memberId}
    </update>
 
    <select id="selectAmountThanZero" resultType="cc.mrbird.febs.dapp.entity.DappWalletCoinEntity">
        select * from dapp_wallet_coin where available_amount > 0
    </select>
 
    <select id="selectTotal" resultType="java.math.BigDecimal">
        select IFNULL(sum(IFNULL(total_amount,0)),0)
        from dapp_wallet_coin
    </select>
 
    <select id="selectWithdrawAmountByType" resultType="java.math.BigDecimal">
        select IFNULL(sum(IFNULL(amount,0)),0)
        from member_coin_withdraw
        where 1=1
        <if test='type == "D"'>
            and date_format(CREATE_TIME, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d');
        </if>
    </select>
</mapper>