xiaoyong931011
2023-10-30 4b42548bdeee0035497839403941d32fe13210c0
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
<?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.mall.mapper.ChatUserMapper">
 
    <select id="selectUserListInPage" resultType="cc.mrbird.febs.mall.vo.AdminChatUserVo">
        select
        a.user_id userId,
        a.nick_name nickName,
        a.chat_no chatNo,
        a.model_type modelType,
        a.create_group createGroup,
        a.phone phone,
        a.status status,
        a.invite_id inviteId,
        a.is_robot isRobot,
        date_format(a.create_time, '%Y-%m-%d %H:%m:%s') createTime,
        IFNULL(sum(b.total_amount), 0) totalAmount,
        IFNULL(sum(b.ava_amount), 0) avaAmount
        from chat_user a
        left join chat_wallet b on b.user_id = a.user_id and type = 'USDT'
        <where>
            <if test="record != null">
                <if test="record.phone != null and record.phone != ''">
                    and a.phone like CONCAT('%', CONCAT(#{record.phone}, '%'))
                </if>
                <if test="record.nickName != null and record.nickName != ''">
                    and a.nick_name like CONCAT('%', CONCAT(#{record.nickName}, '%'))
                </if>
                <if test="record.inviteId != null and record.inviteId != ''">
                    and a.invite_id = #{record.inviteId}
                </if>
                <if test="record.status != null and record.status != ''">
                    and a.status = #{record.status}
                </if>
            </if>
        </where>
        group by a.user_id
        order by a.create_time desc
    </select>
 
    <select id="selectUserPerkListInPage" resultType="cc.mrbird.febs.mall.vo.AdminChatUserPerkVo">
        select
        a.user_id userId,
        a.nick_name nickName,
        a.chat_no chatNo,
        a.get_boom getBoom,
        a.phone phone,
        a.invite_id inviteId,
        a.is_robot isRobot,
        date_format(a.create_time, '%Y-%m-%d %H:%m:%s') createTime,
        IFNULL(sum(b.total_amount), 0) totalAmount,
        IFNULL(sum(b.ava_amount), 0) avaAmount,
        (
            SELECT
                COUNT(c.id)
            FROM chat_red_bag c
            where c.from_user_id = a.user_id
                AND c.msg_type = 'GROUP'
        ) groupRedBagNum,
        (
            select IFNULL(sum(IFNULL(d.amount,0)),0)
            from chat_amount_flow d
            where (d.type = 7 or d.type = 9)
            and d.user_id = a.user_id
        ) teamPerkAmount
        from chat_user a
        left join chat_wallet b on b.user_id = a.user_id and b.type = 'USDT'
        <where>
            a.is_robot = 0
            <if test="record.phone != null and record.phone != ''">
                and a.phone like CONCAT('%', CONCAT(#{record.phone}, '%'))
            </if>
            <if test="record.nickName != null and record.nickName != ''">
                and a.nick_name like CONCAT('%', CONCAT(#{record.nickName}, '%'))
            </if>
            <if test="record.inviteId != null and record.inviteId != ''">
                and (find_in_set(#{record.inviteId}, referrer_ids) or invite_id = #{record.inviteId})
            </if>
            <if test="record.isRobot != null">
                and a.is_robot = #{record.isRobot}
            </if>
        </where>
        group by a.user_id
        HAVING teamPerkAmount > 0
        order by
        a.user_id asc ,a.create_time asc
    </select>
 
    <select id="selectByUserId" resultType="cc.mrbird.febs.mall.entity.ChatUser">
        select
        a.*
        from chat_user a
        where a.user_id = #{userId}
    </select>
 
    <update id="updateStatusByUserId">
        update chat_user
        set
            status = #{status}
        where user_id = #{userId}
    </update>
 
    <select id="selectTotalAmountByUserIdAndType" resultType="cc.mrbird.febs.mall.vo.AdminChatWalletVo">
        select
            a.user_id id,
            a.total_amount balance
        from chat_wallet a
        where a.user_id = #{userId}
            and a.type = 'USDT'
    </select>
 
    <update id="updateBalanceByUserId">
        update chat_wallet
        set
            total_amount = total_amount + #{addBalance},
            ava_amount = ava_amount + #{addBalance}
        where user_id = #{userId}
          and type = 'USDT'
    </update>
 
    <select id="selectAmountFlowListInPage" resultType="cc.mrbird.febs.mall.vo.AdminChatAmountFlowVo">
        select
        a.type type,
        a.amount amount,
        b.nick_name nickName,
        b.phone phone,
        date_format(a.create_time, '%Y-%m-%d %H:%m:%s') createTime,
        a.ava_amount avaAmount,
        a.state state,
        a.remark remark
        from chat_amount_flow a
        inner join chat_user b on b.user_id = a.user_id
        <where>
            <if test="record != null">
                <if test="record.phone != null and record.phone != ''">
                    and b.phone like CONCAT('%', CONCAT(#{record.phone}, '%'))
                </if>
                <if test="record.nickName != null and record.nickName != ''">
                    and b.nick_name = #{record.nickName}
                </if>
                <if test="record.type != null and record.type != ''">
                    and a.type = #{record.type}
                </if>
            </if>
        </where>
        order by a.create_time desc
    </select>
 
    <select id="selectChargeListInPage" resultType="cc.mrbird.febs.mall.vo.AdminChatCahrgeVo">
        select
        date_format(a.created_time, '%Y-%m-%d %H:%m:%s') createdTime,
        b.nick_name nickName,
        b.phone phone,
        a.amount amount,
        a.last_amount lastAmount,
        a.status status,
        a.symbol symbol,
        a.tag tag,
        a.hash hash,
        a.address address
        from member_coin_charge a
        left join chat_user b on b.user_id = a.user_id
        <where>
            <if test="record != null">
                <if test="record.phone != null and record.phone != ''">
                    and b.phone like CONCAT('%', CONCAT(#{record.phone}, '%'))
                </if>
                <if test="record.nickName != null and record.nickName != ''">
                    and b.nick_name like CONCAT('%', CONCAT(#{record.nickName}, '%'))
                </if>
                <if test="record.address != null and record.address != ''">
                    and a.address = #{record.address}
                </if>
            </if>
        </where>
        order by a.created_time desc
    </select>
 
    <select id="selectWithdrawListInPage" resultType="cc.mrbird.febs.mall.vo.AdminChatWithDrawVo">
        select
        date_format(a.created_time, '%Y-%m-%d %H:%m:%s') createdTime,
        b.nick_name nickName,
        b.phone phone,
        a.id id,
        (a.amount - a.fee) amount,
        a.type type,
        a.address address,
        a.address_type addressType,
        a.state state
        from member_coin_withdraw a
        left join chat_user b on b.user_id = a.user_id
        <where>
            <if test="record != null">
                <if test="record.phone != null and record.phone != ''">
                    and b.phone like CONCAT('%', CONCAT(#{record.phone}, '%'))
                </if>
                <if test="record.nickName != null and record.nickName != ''">
                    and b.nick_name like CONCAT('%', CONCAT(#{record.nickName}, '%'))
                </if>
                <if test="record.address != null and record.address != ''">
                    and a.address = #{record.address}
                </if>
                <if test="record.state != null and record.state != ''">
                    and a.state = #{record.state}
                </if>
                <if test="record.type != null and record.type != ''">
                    and a.type = #{record.type}
                </if>
            </if>
        </where>
        order by a.created_time desc
    </select>
 
    <select id="selectWithdrawInfoById" resultType="cc.mrbird.febs.mall.entity.MemberCoinWithdraw">
        select * from member_coin_withdraw a where a.id = #{id}
    </select>
 
    <update id="updateWithdrawStateById">
        update member_coin_withdraw set state = #{state} where id = #{id}
    </update>
 
    <update id="updateAmountFlowListByWithdrawId">
        update chat_amount_flow set state = #{state} where user_id = #{userId} and relation_id = #{id}
    </update>
 
    <update id="updateIsRobotByUserId">
        update chat_user
        set
            is_robot = #{isRobot}
        where user_id = #{userId}
    </update>
 
    <update id="updateModelTypeByUserId">
        update chat_user
        set
            model_type = #{modelType}
        where user_id = #{userId}
    </update>
 
    <select id="selectDicDataByTypeAndCode" resultType="cc.mrbird.febs.mall.entity.DataDictionary">
        select * from data_dictionary a
        where a.type=#{type} and a.code=#{code}
    </select>
 
    <select id="selectGroupListInPage" resultType="cc.mrbird.febs.mall.vo.AdminGroupVo">
        select
        a.id id,
        a.use_robot useRobot,
        a.name name,
        a.model_type modelType,
        a.amount_min amountMin,
        a.amount_max amountMax,
        a.red_bag_cnt redBagCnt,
        a.auto_send autoSend,
        b.phone phone,
        b.nick_name nickName,
        a.create_time createTime
        from chat_group a
        left join chat_user b on b.user_id = a.master
        <where>
            <if test="record != null">
                <if test="record.name != null and record.name != ''">
                    and a.name like CONCAT('%', CONCAT(#{record.name}, '%'))
                </if>
            </if>
        </where>
        order by a.create_time desc
    </select>
 
    <select id="selectVersionListInPage" resultType="cc.mrbird.febs.mall.vo.AdminVersionVo">
        select
        a.*
        from chat_version a
    </select>
 
    <update id="updateIsRobotByGroupId">
        update chat_group
        set
            use_robot = #{useRobot}
        where id = #{id}
    </update>
 
    <select id="getGroupInfoById" resultType="cc.mrbird.febs.mall.vo.AdminGroupInfoVo">
        select
        a.id id,
        a.name name,
        b.phone phone,
        a.model_type modelType,
        b.nick_name nickName,
        a.use_robot useRobot,
        a.amount_min amountMin,
        a.amount_max amountMax,
        a.red_bag_cnt redBagCnt
        from chat_group a
        left join chat_user b on b.user_id = a.master
        where id = #{id}
    </select>
 
    <select id="getVersionInfoById" resultType="cc.mrbird.febs.mall.vo.AdminVersionVo">
        select
            a.*
        from chat_version a
        where id = #{id}
    </select>
 
    <update id="updateAutoSendByGroupId">
        update chat_group
        set
            auto_send = #{autoSend}
        where id = #{id}
    </update>
 
    <select id="selectRedBagListInPage" resultType="cc.mrbird.febs.mall.vo.AdminRedBagVo">
        select
        a.*,
        b.nick_name nickName,
        b.is_robot isRobot,
        c.name groupName
        from chat_red_bag a
        left join chat_user b on b.user_id = a.from_user_id
        left join chat_group c on c.id = a.to_user_id
        <where>
            a.msg_type = 'GROUP'
            <if test="record != null">
                <if test="record.name != null and record.name != ''">
                    and c.name like CONCAT('%', CONCAT(#{record.name}, '%'))
                </if>
                <if test="record.nickName != null and record.nickName != ''">
                    and b.nick_name like CONCAT('%', CONCAT(#{record.nickName}, '%'))
                </if>
                <if test="record.isRobot != null">
                    and b.is_robot = #{record.isRobot}
                </if>
            </if>
        </where>
        order by a.create_time desc
    </select>
 
    <update id="updateCreateGroupByUserId">
        update chat_user
        set
            create_group = #{createGroup}
        where user_id = #{userId}
    </update>
 
    <update id="updateNicknameById">
        update chat_user
        set
            nick_name = #{nickName}
        where user_id = #{userId}
    </update>
 
    <select id="selectListByIsRobot" resultType="cc.mrbird.febs.mall.entity.ChatUser">
        select
            a.*
        from chat_user a
        where is_robot = #{isRobot}
    </select>
 
    <select id="selectTotalAmount" resultType="java.math.BigDecimal">
        select IFNULL(sum(IFNULL(total_amount,0)),0)
        from chat_wallet
        where type = 'USDT'
    </select>
 
    <select id="selectTotalType" resultType="java.math.BigDecimal">
        select IFNULL(sum(IFNULL(amount,0)),0)
        from chat_amount_flow
        where type = #{type}
        <if test='dateType == "D"'>
            and date_format(create_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d');
        </if>
        <if test='dateType == "M"'>
            and date_format(create_time, '%Y-%m') = date_format(#{date}, '%Y-%m');
        </if>
    </select>
 
 
    <select id="selectTotalTypeByUserId" resultType="java.math.BigDecimal">
        select IFNULL(sum(IFNULL(amount,0)),0)
        from chat_amount_flow
        where type = #{type}
          and user_id = #{userId}
        <if test='dateType == "D"'>
            and date_format(create_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d');
        </if>
        <if test='dateType == "M"'>
            and date_format(create_time, '%Y-%m') = date_format(#{date}, '%Y-%m');
        </if>
    </select>
 
    <select id="selectUserList" resultType="cc.mrbird.febs.mall.entity.ChatUser">
        select
        a.*
        from chat_user a
        where is_robot = #{isRobot}
        <if test='dateType == "D"'>
            and date_format(create_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d');
        </if>
        <if test='dateType == "M"'>
            and date_format(create_time, '%Y-%m') = date_format(#{date}, '%Y-%m');
        </if>
    </select>
 
    <select id="selectListByMsgType" resultType="cc.mrbird.febs.mall.vo.AdminChatRedBagVo">
        select
               a.*
        from chat_red_bag a
        where a.msg_type = #{msgType}
        <if test='date != "" and date != null'>
            and date_format(a.create_time, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
        </if>
        and a.from_user_id = #{userId}
    </select>
 
    <select id="selectByOverDueStatueAndTime" resultType="cc.mrbird.febs.mall.vo.AdminChatRedBagVo">
        select *
        from chat_red_bag
        where overdue_state = #{overdueState}
          and #{overdueTime} > overdue_time
        order by id asc
            limit 500
    </select>
 
 
    <update id="updateOverdueStatusById">
        update chat_red_bag
        set
            overdue_state = #{overdueState}
        where id = #{id}
    </update>
 
    <update id="updatePortraitById">
        update chat_user
        set
            portrait = #{portrait}
        where user_id = #{userId}
    </update>
 
    <update id="updateGetBoomByUserId">
        update chat_user
        set
            get_boom = #{getBoom}
        where user_id = #{userId}
    </update>
 
 
</mapper>