xiaoyong931011
2023-08-17 e203174b7798c223e2a568ff9493b492cdc4b413
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?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.DappFundFlowDao">
 
    <select id="selectInPage" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select a.*, b.address address from dapp_fund_flow 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.type != null">
                and a.type = #{record.type}
            </if>
            <if test="record.status != null">
                and a.status = #{record.status}
            </if>
            <if test="record.address != '' and record.address != null">
                and b.address = #{record.address}
            </if>
            <if test="record.memberId != null">
                and a.member_id=#{record.memberId}
            </if>
            <if test="record.fromHash != '' and record.fromHash != null">
                and a.from_hash = #{record.fromHash}
            </if>
            <if test="record.systemProfitId != '' and record.systemProfitId != null">
                and a.system_profit_id = #{record.systemProfitId}
            </if>
        </where>
        order by a.create_time desc, a.id desc
    </select>
 
    <select id="selectVoInPage" resultType="cc.mrbird.febs.dapp.vo.DappFundFlowVo">
        select
               a.amount amount,
               a.type type,
               a.from_hash fromAddress,
               a.to_hash toAddress,
               date_format(a.create_time, '%Y-%m-%d %H:%i:%s') createTime
        from dapp_fund_flow a
        <where>
            member_id = #{record.memberId}
            <if test="record.type != null">
                and a.type = #{record.type}
            </if>
            <if test="record.status != null">
                and a.status = #{record.status}
            </if>
            <if test="record.flowType != null">
                and a.flow_type = #{record.flowType}
            </if>
        </where>
        order by a.create_time desc
    </select>
 
    <select id="selectListForMemberAndDay" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select * from dapp_fund_flow
        where member_id=#{memberId} and date_format(create_time, '%Y-%m-%d') = date_format(now(), '%Y-%m-%d')
        and type=#{type}
          <if test="type != 3">
              and status!=3
          </if>
    </select>
 
    <select id="selectByFromHash" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select * from dapp_fund_flow
        where from_hash = #{txHash}
          <if test="status != null">
              and status = #{status}
          </if>
    </select>
 
    <select id="selectFundFlowListByAddress" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select * from dapp_fund_flow a, dapp_member b
        where b.address=#{address}
        <if test="status != null">
            and a.status=#{status}
        </if>
        order by a.id desc
    </select>
 
    <select id="selectAmountTotalByType" resultType="java.util.HashMap">
        select
            IFNULL(MAX(if(type = 1, a.amount, 0)),0) buy
             , IFNULL(MAX(if(type = 2, a.amount, 0)),0) sale
             , IFNULL(MAX(if(type = 3, a.amount, 0)),0) mine
             , IFNULL(MAX(if(type = 4, a.amount, 0)),0) teamReward
        from (select type, sum(amount) amount
                 from dapp_fund_flow
                 where member_id=#{memberId}
                 group by type
            ) a
    </select>
 
    <select id="selectProfitAmountByMemberId" resultType="java.math.BigDecimal">
        select ifnull(sum(amount), 0) from dapp_fund_flow
        where member_id=#{memberId} and type in (2,3)
    </select>
 
    <select id="selectNewestFundFlow" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select * from dapp_fund_flow
        where member_id=#{memberId} and type = #{type}
        order by id desc
        limit 1
    </select>
 
    <select id="selectSumAmountByMemberIdAndTypeAndStatus" resultType="java.math.BigDecimal">
        select ifnull(sum(amount), 0) from dapp_fund_flow
        where member_id = #{memberId}
          and type = #{type}
        and status = #{status}
    </select>
 
    <select id="selectInfoById" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select a.* from dapp_fund_flow a
        where a.id = #{id}
    </select>
 
    <update id="updateStatusById">
        update dapp_fund_flow
        set status = #{status},
            version = version + 1
    where id = #{id}
        and version = 1
        and status = 1
    </update>
 
    <select id="selectByStateAndVersionAndFromHashLimitOne" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select * from dapp_fund_flow
        where status = #{status}
          and version = #{version}
          and from_hash is null
          and is_return = 2
          and type in (2,3,27)
        ORDER BY
            id ASC
            LIMIT 1
    </select>
 
    <select id="selectByStateAndVersionAndFromHashTwoLimitOne" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select * from dapp_fund_flow
        where status = #{status}
          and from_hash is null
          and is_return = 2
          and type in (5,6,34)
        ORDER BY
            id ASC
            LIMIT 1
    </select>
 
    <select id="selectBymemberIdAndType" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select * from dapp_fund_flow
        where member_id = #{memberId}
          and type = #{type}
          and status = #{status}
    </select>
 
    <select id="selectListByState" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select *
        from dapp_fund_flow
        where status = #{status}
          and version = 1
        and type != 1
        and type != 6
    </select>
 
    <select id="selectSumAmountByType" resultType="java.math.BigDecimal">
        select ifnull(sum(amount), 0) from dapp_fund_flow
        where  type = #{type}
    </select>
 
    <select id="selectOrderMoneyFlowInPage" resultType="cc.mrbird.febs.dapp.vo.AdminMallMoneyFlowVo">
        select
            a.create_time createTime,
            a.amount amount,
            a.type type,
            b.address address
        from dapp_fund_flow a
                 left join dapp_member b on a.member_id = b.id
        where a.system_profit_id = #{record.id}
        order by a.CREATE_TIME desc
    </select>
 
    <select id="selectListByMemberIdAndTypeAndDate" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select * from dapp_fund_flow
        where
              member_id = #{memberId}
          and date_format(create_time, '%Y-%m-%d') = date_format(#{dateStr}, '%Y-%m-%d')
          and type = #{type}
          and status = 2
    </select>
 
    <select id="selectListByTypeAndDate" resultType="cc.mrbird.febs.dapp.entity.DappFundFlowEntity">
        select member_id as memberId,ifnull(sum(amount), 0) as amount
        from dapp_fund_flow
        where date_format(create_time, '%Y-%m-%d') = date_format(#{dateStr}, '%Y-%m-%d')
          and type = #{type}
          and status = 2
        group by member_id
    </select>
</mapper>