fix
Helius
2022-09-22 5a8bb0c1dde052c6c95d545f53ae27d42338529d
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
<?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.MallMemberMapper">
 
    <select id="selectMallMemberListInPage" resultType="cc.mrbird.febs.mall.entity.MallMember">
        SELECT m.*,a.name referrerName,IFNULL(c.balance,0) balance,IFNULL(c.score,0) score,IFNULL(c.prize_score,0) prizeScore,IFNULL(c.commission,0) commission
        ,d.description levelName
        FROM mall_member m
        left join mall_member a on m.referrer_id = a.invite_id
        LEFT JOIN mall_member_wallet c on c.member_id = m.id
        LEFT JOIN data_dictionary_custom d on d.code = m.level and type='AGENT_LEVEL'
        <where>
            <if test="record != null" >
                <if test="record.name!=null and record.name!=''">
                    and m.name like concat('%',  #{record.name},'%')
                </if>
                <if test="record.account!=null and record.account!=''">
                    and (
                        m.phone like concat('%',  #{record.account},'%')
                        or m.email like concat('%',  #{record.account},'%')
                        or m.bind_phone like concat('%',  #{record.account},'%')
                        or m.invite_id like concat('%',  #{record.account},'%')
                        )
                </if>
                <if test="record.accountStatus!=null">
                    and m.account_status = #{record.accountStatus}
                </if>
                <if test="record.accountType != null" >
                    and m.account_type = #{record.accountType}
                </if>
                <if test="record.level!=null and record.level!=''">
                    and m.level=#{record.level}
                </if>
            </if>
        </where>
        GROUP BY m.id order by m.CREATED_TIME desc
    </select>
 
    <select id="getMallMemberInfoById" resultType="cc.mrbird.febs.mall.vo.MallMemberVo">
        SELECT a.id,
               a.name,
               a.phone,
               a.email,
               a.sex,
               a.invite_id,
               a.level,
               a.account_status,
               a.CREATED_TIME,
               IFNULL(c.balance,0) balance,
               IFNULL(c.score,0) score,
               IFNULL(c.prize_score,0) prizeScore,
               d.description levelName,
               b.name
               FROM mall_member a
            LEFT JOIN mall_member b on a.referrer_id = b.invite_id
            LEFT JOIN mall_member_wallet c on c.member_id = a.id
            LEFT JOIN data_dictionary_custom d on d.code = a.level
            where a.id = #{id}
            GROUP BY a.id
    </select>
 
    <select id="selectInfoByAccount" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member where phone=#{account} or email=#{account} or invite_id=#{account}
    </select>
 
    <select id="selectInfoByInviteId" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member where invite_id=#{inviteId}
    </select>
 
    <select id="selectInfoByAccountAndPwd" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member where (phone=#{account} or email=#{account}) and password=#{password}
    </select>
 
    <select id="selectTeamListByInviteId" resultType="cc.mrbird.febs.mall.vo.TeamListVo">
        select
            a.id,
            a.name,
            a.phone,
            a.invite_id,
            2 isCurrent,
            a.created_time,
            p.prize_score,
            u.description levelName,
            (select sum(e.amount)
             from mall_order_info e
                      inner join mall_member b on e.member_id=b.ID
                      inner join mall_order_item c on e.id = c.order_id -- and c.is_normal=2
             where e.status in (2, 3, 4) and e.order_type=1 and (b.invite_id=a.invite_id or b.referrer_id=a.invite_id)) amount,
            (select count(1) from mall_member e
                      inner join mall_order_info b on e.id=b.member_id and b.status in (2, 3, 4)
             where find_in_set(a.invite_id, e.referrer_ids)) orderCnt,
            (select count(1) from mall_member x where find_in_set(a.invite_id, x.referrer_ids)) cnt
        from mall_member a
        inner join mall_member_wallet p on a.id=p.member_id
        left join data_dictionary_custom u on a.level=u.code and u.type='AGENT_LEVEL'
        where a.referrer_id=#{inviteId}
    </select>
 
    <select id="selectOwnOrderAmountByInviteId" resultType="java.math.BigDecimal">
        select
            IFNULL(sum(b.amount),0)
        from mall_member e
          inner join mall_order_info b on e.id=b.member_id and b.status in (2, 3, 4)
        where e.invite_id=#{inviteId} or e.referrer_id=#{inviteId}
    </select>
 
    <select id="selectOwnCntByInviteId" resultType="java.lang.Integer">
        select IFNULL(count(1),0) from mall_member x where x.referrer_id=#{inviteId}
    </select>
 
    <select id="selectOwnOrderCntByInviteId" resultType="java.lang.Integer">
        select
            IFNULL(count(1),0)
        from mall_member e
                 inner join mall_order_info b on e.id=b.member_id and b.status in (2, 3, 4)
        where e.invite_id=#{inviteId} or e.referrer_id=#{inviteId}
    </select>
 
    <select id="selectByRefererId" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member
        where referrer_id=#{inviteId}
    </select>
 
    <select id="selectChildAgentList" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member
        where (find_in_set(#{inviteId}, referrer_ids) or invite_id=#{inviteId}) and level=#{agentLevel}
    </select>
 
    <select id="selectByInviteIds" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member
        where  invite_id IN
        <foreach collection = "list" item = "item"  separator=","  open = "(" close = ")" >
            #{item}
        </foreach >
        order by id desc
    </select>
 
    <select id="getAgentListInPage" resultType="cc.mrbird.febs.mall.vo.AdminAgentVo">
 
        SELECT m.*,a.description levelName,
        ifnull((
        SELECT
        sum(b.amount)
        FROM
        mall_member e
        INNER JOIN mall_order_info b ON e.id = b.member_id
        AND b. STATUS = 4
        WHERE
        e.invite_id = m.invite_id
        OR e.referrer_id = m.invite_id
        or find_in_set(m.invite_id, e.referrer_ids)
        ),0) amount
        FROM mall_member m
        left join data_dictionary_custom a on a.code = m.level
        <where>
            <if test="record != null" >
                <if test="record.name!=null and record.name!=''">
                    and m.name like concat('%',  #{record.name},'%')
                </if>
                <if test="record.level!=null and record.level!=''">
                    and m.level = #{record.level}
                </if>
                <if test="record.account!=null and record.account!=''">
                    and m.phone like concat('%',  #{record.account},'%')
                </if>
            </if>
        </where>
        group by m.id
        order by m.CREATED_TIME desc
    </select>
 
    <select id="selectChildAgentListByInviteId" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member where  referrer_id = #{inviteId}
    </select>
 
    <select id="selectAllChildAgentListByInviteId" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member where  find_in_set(#{inviteId}, referrer_ids)
    </select>
 
    <select id="selectMemberParentAgentList" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member
        where level not in  ('ZERO_LEVEL', 'FIRST_LEVEL') and invite_id!=#{refererId} and invite_id IN
        <foreach collection = "list" item = "item"  separator=","  open = "(" close = ")" >
            #{item}
        </foreach >
        order by id desc
    </select>
 
    <select id="getAgentLevelListInPage" resultType="cc.mrbird.febs.mall.vo.AdminAgentLevelVo">
        SELECT
            a.id,b.description name
        FROM
            data_dictionary_custom a
                left JOIN data_dictionary_custom b on a.code = b.code
        where a.type = 'AGENT_LEVEL_REQUIRE'
        GROUP BY a.id
        ORDER BY
            a.CREATED_TIME DESC
    </select>
 
    <select id="getAgentChildInPage" resultType="cc.mrbird.febs.mall.vo.AdminAgentMemberVo">
        select m.*,a.description levelName from mall_member m
            left join data_dictionary_custom a on a.code = m.level
        where  find_in_set(#{record.inviteId}, m.referrer_ids)
        GROUP BY m.id
        ORDER BY
            m.CREATED_TIME DESC
    </select>
 
    <select id="getRankAwardListInPage" resultType="cc.mrbird.febs.mall.vo.AdminRankAwardVo">
        select a.* from data_dictionary_custom a where a.type = 'RANK_AWARD' or a.type = 'RANK_AWARD_SETTING'
    </select>
 
 
    <select id="getAgentTeamAmountByInviteId" resultType="java.math.BigDecimal">
            SELECT
                ifnull(sum(b.amount),0)
            FROM
                mall_member e
                    INNER JOIN mall_order_info b ON e.id = b.member_id
                    AND b. STATUS = 4
            WHERE
                e.invite_id = #{inviteId}
               OR e.referrer_id = #{inviteId}
               or find_in_set(#{inviteId}, e.referrer_ids)
    </select>
 
    <select id="getAppVersionListInPage" resultType="cc.mrbird.febs.mall.entity.AppVersion">
        select a.* from app_version a
    </select>
 
    <select id="selectByIdAndNoLevel" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member where level != #{level}
        <if test="refererId != null and refererId != ''">
            and referrer_id=#{refererId}
        </if>
    </select>
 
    <select id="selectMallMemberByInviteIdAndLevel" resultType="cc.mrbird.febs.mall.entity.MallMember">
        SELECT
            m.*, b.
            VALUE
 
        FROM
            mall_member m
                LEFT JOIN data_dictionary_custom b ON m. LEVEL = b. CODE
        WHERE
            find_in_set(#{inviteId}, m.referrer_ids)
          AND b.type = 'AGENT_LEVEL'
          AND b.VALUE > (
            SELECT
                VALUE
            FROM
                data_dictionary_custom a
            WHERE
                a. CODE = #{level}
              AND a.type = 'AGENT_LEVEL'
        )
        GROUP BY
            m.id
    </select>
 
 
 
    <select id="getAgentLevelSetInfoByMemberId" resultType="cc.mrbird.febs.mall.vo.AdminAgentLevelSetInfoVo">
        SELECT a.id,d.code levelCode
        FROM mall_member a
                 LEFT JOIN data_dictionary_custom d on d.code = a.level
        where a.id = #{id} and d.type = 'AGENT_LEVEL'
        GROUP BY a.id
    </select>
 
    <select id="getMallDataListInPage" resultType="cc.mrbird.febs.mall.vo.MallDataVo">
        SELECT
            DATE_FORMAT(a.CREATED_TIME, '%Y-%m-%d') createdTime,
            IFNULL(t1.tol, 0) *- 1 AS payMoney,
            IFNULL(t2.to2, 0) AS refundMoney,
            IFNULL(t3.to3, 0) *- 1 AS rewordMoney,
            (
                    (IFNULL(t1.tol, 0)*- 1) - (IFNULL(t2.to2, 0)) + (IFNULL(t3.to3, 0)*- 1)
                ) AS surplusMoney
        FROM
            mall_money_flow a
                LEFT JOIN (
                SELECT
                    b.CREATED_TIME,
                    IFNULL(SUM(b.amount), 0) AS tol
                FROM
                    mall_money_flow b
                WHERE
                    b.type = 3
                GROUP BY
                    DATE_FORMAT(b.CREATED_TIME, '%Y-%m-%d')
            ) t1 ON DATE_FORMAT(t1.CREATED_TIME, '%Y-%m-%d') = DATE_FORMAT(a.CREATED_TIME, '%Y-%m-%d')
                LEFT JOIN (
                SELECT
                    c.CREATED_TIME,
                    IFNULL(SUM(c.amount), 0) AS to2
                FROM
                    mall_money_flow c
                WHERE
                    c.type = 4
                GROUP BY
                    DATE_FORMAT(c.CREATED_TIME, '%Y-%m-%d')
            ) t2 ON DATE_FORMAT(t2.CREATED_TIME, '%Y-%m-%d') = DATE_FORMAT(a.CREATED_TIME, '%Y-%m-%d')
                LEFT JOIN (
                SELECT
                    d.CREATED_TIME,
                    IFNULL(SUM(d.amount), 0) AS to3
                FROM
                    mall_money_flow d
                WHERE
                    d.type IN (1, 2)
                GROUP BY
                    DATE_FORMAT(d.CREATED_TIME, '%Y-%m-%d')
            ) t3 ON DATE_FORMAT(t3.CREATED_TIME, '%Y-%m-%d') = DATE_FORMAT(a.CREATED_TIME, '%Y-%m-%d')
        GROUP BY
            DATE_FORMAT(a.CREATED_TIME, '%Y-%m-%d')
        ORDER BY
            DATE_FORMAT(a.CREATED_TIME, '%Y-%m-%d') DESC
    </select>
 
<!--    <select id="selectRankListInPage" resultType="cc.mrbird.febs.mall.entity.MallMember">-->
<!--        select a.*, b.*-->
<!--        from mall_member a-->
<!--            inner join (-->
<!--                select b.referrer_id refererId, sum(a.amount) amount, max(a.order_time) orderTime-->
<!--                    from mall_order_info a-->
<!--                    inner join mall_member b on a.member_id=b.ID-->
<!--                    inner join mall_order_item c on a.id = c.order_id and c.is_normal=2-->
<!--                where a.status in (2, 3, 4) and a.order_type=1-->
<!--                &lt;!&ndash; 月 &ndash;&gt;-->
<!--                <if test="record.query == '2'">-->
<!--                    and date_format(#{record.createdTime},'%Y-%m') = date_format(b.order_time,'%Y-%m')-->
<!--                </if>-->
<!--                group by b.referrer_id-->
<!--            ) b  on a.invite_id=b.refererId-->
<!--        order by b.amount desc, b.orderTime desc-->
<!--    </select>-->
 
    <select id="selectRankListInPage" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select a.*, b.*
        from mall_member a
            inner join (
                select b.referrer_id refererId, sum(a.amount) amount, max(a.pay_time) orderTime
                from mall_achieve_record a
                    inner join mall_member b on a.member_id=b.ID
                where 1=1
                <!-- 月 -->
                <if test="record.query == '2'">
                    and date_format(#{record.createdTime},'%Y-%m') = date_format(a.achieve_time,'%Y-%m')
                </if>
                group by b.referrer_id
            ) b  on a.invite_id=b.refererId
        order by b.amount desc, b.orderTime desc
    </select>
 
    <select id="selectAchieveByMemberId" resultType="java.math.BigDecimal">
        select IFNULL(sum(IFNULL(a.amount, 0)), 0)
        from mall_achieve_record a
             inner join mall_member b on a.member_id=b.ID
        where 1=1
        <if test="type == 1">
            and b.invite_id=#{inviteId}
        </if>
        <if test="type == 2">
            and find_in_set(#{inviteId}, b.referrer_ids)
        </if>
    </select>
 
    <select id="selectMemberByName" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member
        where name=#{name}
    </select>
 
    <select id="selectMemberListHasChild" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select distinct a.* from mall_member a, mall_member b
        where a.invite_id=b.referrer_id
    </select>
 
    <select id="selectMemberDirectForHasLevel" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member
        where referrer_id=#{inviteId} and level != 'ZERO_LEVEL'
    </select>
 
    <select id="selectDirectorsOrStoreMaster" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member
        <where>
            1=1
            <if test="type == 1">
                and director = 1
            </if>
            <if test="type == 2">
                and store_master = 1
            </if>
        </where>
    </select>
 
    <select id="selectMemberWithLevel" resultType="cc.mrbird.febs.mall.entity.MallMember">
        select * from mall_member
        where level=#{level}
    </select>
 
    <select id="selectMemberByOpenId" resultType="cc.mrbird.febs.mall.entity.MallMember">
        SELECT a.*
        FROM mall_member a
        where a.open_id = #{openId} limit 1
    </select>
 
</mapper>