jiangqs
2023-06-27 046d7ac5bbef4cbb6c6b64f3589e2722d13a07a5
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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
<?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="com.ruoyi.member.mapper.member.MemberMapper">
 
    <resultMap type="com.ruoyi.system.api.domain.poji.member.Member" id="MemberResult">
        <result property="userId"    column="user_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="memberId"    column="member_id"    />
        <result property="memberNo"    column="member_no"    />
        <result property="wxOpenid"    column="wx_openid"    />
        <result property="miniOpenid"    column="mini_openid"    />
        <result property="wxUnionid"    column="wx_unionid"    />
        <result property="relationShopId"    column="relation_shop_id"    />
        <result property="nickName"    column="nick_name"    />
        <result property="realName"    column="real_name"    />
        <result property="mobile"    column="mobile"    />
        <result property="gender"    column="gender"    />
        <result property="referrer"    column="referrer"    />
        <result property="customerSource"    column="customer_source"    />
        <result property="level"    column="level"    />
        <result property="birthday"    column="birthday"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateUserId"    column="update_user_id"    />
        <result property="userTags"    column="user_tags"    />
        <result property="avatar"    column="avatar"    />
        <result property="bindingFlag"    column="binding_flag"    />
        <result property="goodsType"    column="goods_type"    />
        <result property="relationShopName"    column="relation_shop_name"    />
    </resultMap>
 
    <sql id="selectMemberVo">
        select user_id, del_flag, member_id, member_no, wx_openid, mini_openid, wx_unionid, relation_shop_id, nick_name, real_name, mobile, gender, referrer, customer_source, level, birthday, create_time, update_time, update_user_id, user_tags, avatar, binding_flag, goods_type from t_member
    </sql>
 
    <select id="selectMemberList" parameterType="com.ruoyi.system.api.domain.poji.member.Member" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        <where>
            <if test="memberId != null  and memberId != ''"> and member_id = #{memberId}</if>
            <if test="memberNo != null  and memberNo != ''"> and member_no = #{memberNo}</if>
            <if test="wxOpenid != null  and wxOpenid != ''"> and wx_openid = #{wxOpenid}</if>
            <if test="miniOpenid != null  and miniOpenid != ''"> and mini_openid = #{miniOpenid}</if>
            <if test="wxUnionid != null  and wxUnionid != ''"> and wx_unionid = #{wxUnionid}</if>
            <if test="relationShopId != null "> and relation_shop_id = #{relationShopId}</if>
            <if test="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="gender != null "> and gender = #{gender}</if>
            <if test="referrer != null  and referrer != ''"> and referrer = #{referrer}</if>
            <if test="customerSource != null  and customerSource != ''"> and customer_source = #{customerSource}</if>
            <if test="level != null  and level != ''"> and level = #{level}</if>
            <if test="birthday != null  and birthday != ''"> and birthday = #{birthday}</if>
            <if test="updateUserId != null "> and update_user_id = #{updateUserId}</if>
        </where>
    </select>
 
    <select id="selectMemberByUserId" parameterType="Long" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        where user_id = #{userId}
    </select>
 
    <select id="selectMemberByMobile" parameterType="Long" resultMap="MemberResult">
        <include refid="selectMemberVo"/>
        where mobile = #{mobile}
    </select>
 
    <insert id="insertMember" parameterType="com.ruoyi.system.api.domain.poji.member.Member">
        insert into t_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="memberId != null">member_id,</if>
            <if test="memberNo != null">member_no,</if>
            <if test="wxOpenid != null">wx_openid,</if>
            <if test="miniOpenid != null">mini_openid,</if>
            <if test="wxUnionid != null">wx_unionid,</if>
            <if test="relationShopId != null">relation_shop_id,</if>
            <if test="realName != null">real_name,</if>
            <if test="mobile != null">mobile,</if>
            <if test="gender != null">gender,</if>
            <if test="referrer != null">referrer,</if>
            <if test="customerSource != null">customer_source,</if>
            <if test="level != null">level,</if>
            <if test="birthday != null">birthday,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateUserId != null">update_user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="memberId != null">#{memberId},</if>
            <if test="memberNo != null">#{memberNo},</if>
            <if test="wxOpenid != null">#{wxOpenid},</if>
            <if test="miniOpenid != null">#{miniOpenid},</if>
            <if test="wxUnionid != null">#{wxUnionid},</if>
            <if test="relationShopId != null">#{relationShopId},</if>
            <if test="realName != null">#{realName},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="gender != null">#{gender},</if>
            <if test="referrer != null">#{referrer},</if>
            <if test="customerSource != null">#{customerSource},</if>
            <if test="level != null">#{level},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateUserId != null">#{updateUserId},</if>
        </trim>
    </insert>
 
    <update id="updateMember" parameterType="com.ruoyi.system.api.domain.poji.member.Member">
        update t_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="memberId != null">member_id = #{memberId},</if>
            <if test="memberNo != null">member_no = #{memberNo},</if>
            <if test="wxOpenid != null">wx_openid = #{wxOpenid},</if>
            <if test="miniOpenid != null">mini_openid = #{miniOpenid},</if>
            <if test="wxUnionid != null">wx_unionid = #{wxUnionid},</if>
            <if test="relationShopId != null">relation_shop_id = #{relationShopId},</if>
            <if test="realName != null">real_name = #{realName},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="referrer != null">referrer = #{referrer},</if>
            <if test="customerSource != null">customer_source = #{customerSource},</if>
            <if test="level != null">level = #{level},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateUserId != null">update_user_id = #{updateUserId},</if>
        </trim>
        where user_id = #{userId}
    </update>
 
    <delete id="deleteMemberByUserId" parameterType="Long">
        delete from t_member where user_id = #{userId}
    </delete>
 
    <delete id="deleteMemberByUserIds" parameterType="String">
        delete from t_member where user_id in
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
 
 
    <select id="getOneByMiniOpenid" resultType="com.ruoyi.system.api.domain.poji.member.Member">
        SELECT * FROM t_member WHERE del_flag = 0 AND mini_openid = #{miniOpenid}
    </select>
 
    <select id="pageMerMember" resultType="com.ruoyi.member.domain.vo.MerMemberPageVo">
        SELECT
        tm.user_id userId,
        tm.nick_name nickName,
        tm.avatar avatar,
        CASE tm.gender WHEN 0 THEN '男' WHEN 1 THEN '女' ELSE '未知' END gender,
        tm.mobile mobile,
        tm.referrer referrer,
        0 recommendNum,
        0 surpNum,
        tm.birthday birthday,
        tm.user_tags userTags,
        tm.goods_type goodsType
        FROM t_member tm
        WHERE tm.relation_shop_id = #{param.shopId}
        <if test="param.memberGender != null and param.memberGender != ''">
            AND tm.gender = #{param.memberGender}
        </if>
        <if test="param.memberTag != null and param.memberTag != ''">
            AND FIND_IN_SET(#{param.memberTag},tm.user_tags) &gt; 0
        </if>
        <if test="param.startMemberDate!=null and param.startMemberDate!=''">
            AND tm.create_time &gt;= #{param.startMemberDate}
        </if>
        <if test="param.endMemberDate!=null and param.endMemberDate!=''">
            AND tm.create_time &lt;= #{param.endMemberDate}
        </if>
        <if test="param.keyword != null and param.keyword != ''">
            AND (tm.real_name LIKE CONCAT('%',#{param.keyword},'%') OR tm.mobile LIKE CONCAT('%',#{param.keyword},'%') OR tm.referrer LIKE CONCAT('%',#{param.keyword},'%'))
        </if>
        ORDER BY tm.create_time DESC
    </select>
 
    <select id="pageMerCashMember" resultType="com.ruoyi.member.domain.vo.MerCashMemberPageVo">
        SELECT
        tm.user_id userId,
        tm.nick_name nickName,
        tm.mobile mobile
        FROM t_member tm
        WHERE tm.relation_shop_id = #{param.shopId}
        <if test="param.keyword != null and param.keyword != ''">
            AND (tm.real_name LIKE CONCAT('%',#{param.keyword},'%') OR tm.mobile LIKE CONCAT('%',#{param.keyword},'%'))
        </if>
        ORDER BY tm.create_time DESC
    </select>
 
    <select id="pageMgtMember" resultType="com.ruoyi.member.domain.vo.MgtMemberPageVo">
        SELECT
        tm.member_id memberId,
        tm.user_id userId,
        tm.relation_shop_id relationShopId,
        tm.member_no memberNo,
        tm.real_name realName,
        tm.nick_name nickName,
        tm.mobile mobile,
        CASE tm.gender WHEN 0 THEN "男" WHEN 1 THEN "女" ELSE "未知" END gender,
        (YEAR(CURRENT_DATE) - YEAR(tm.birthday)) - (RIGHT(CURRENT_DATE, 5) &lt; RIGHT(tm.birthday, 5)) age,
        tm.user_tags memberTags,
        tm.belong_district belongDistrict,
        CASE tm.binding_flag WHEN 0 THEN "否" WHEN 1 THEN "是" ELSE "否" END memberFlag,
        tm.create_time createTime,
        tmt.last_pay_time lastPayTime,
        tm.goods_type goodsType,
        tm.relation_shop_name relationShopName,
        tmt.total_integral integral,
        tm.referrer referrer,
        tm.customer_source memberFrom,
        tmt.total_pay_money totalPayMoney,
        tmt.total_activity_count activityTotal
        FROM t_member tm
        LEFT JOIN t_member_total tmt ON tm.member_id = tmt.member_id
        WHERE tm.del_flag = 0
        <if test="param.keyword != null and param.keyword != ''">
            AND (tm.member_no LIKE CONCAT('%',#{param.keyword},'%') OR tm.mobile LIKE CONCAT('%',#{param.keyword},'%') OR tm.real_name LIKE CONCAT('%',#{param.keyword},'%') OR tm.nick_name LIKE CONCAT('%',#{param.keyword},'%') OR FIND_IN_SET(#{param.keyword},tm.member_nurse) &gt; 0)
        </if>
        <if test="param.belongDistrict != null and param.belongDistrict != ''">
            AND tm.belong_district = #{param.belongDistrict}
        </if>
        <if test="param.createTime != null and param.createTime != ''">
            AND tm.create_time = #{param.createTime}
        </if>
        <if test="param.lastPayTime != null and param.lastPayTime != ''">
            AND tmt.last_pay_time = #{param.lastPayTime}
        </if>
        <if test="param.memberFlag != null and param.memberFlag != ''">
            AND tmt.binding_flag = #{param.memberFlag}
        </if>
        <if test="param.goodsType != null and param.goodsType != ''">
            AND FIND_IN_SET(#{param.goodsType},tm.goods_type) &gt; 0
        </if>
        <if test="param.relationShopId != null and param.relationShopId != ''">
            AND tm.relation_shop_id = #{param.relationShopId}
        </if>
        <if test="param.memberFrom != null and param.memberFrom != ''">
            AND tm.customer_source = #{param.memberFrom}
        </if>
        <if test="param.referrer != null and param.referrer != ''">
            AND tm.referrer = #{param.referrer}
        </if>
        <if test="param.gender != null">
            AND tm.gender = #{param.gender}
        </if>
        <if test="param.startBirthday != null and param.startBirthday != ''">
            AND tm.birthday &gt;= #{param.startBirthday}
        </if>
        <if test="param.endBirthday != null and param.endBirthday != ''">
            AND tm.birthday &lt;= #{param.endBirthday}
        </if>
        <if test="param.startIntegral != null and param.startIntegral != ''">
            AND tmt.total_integral &gt;= #{param.startIntegral}
        </if>
        <if test="param.endIntegral != null and param.endIntegral != ''">
            AND tmt.total_integral &lt;= #{param.endIntegral}
        </if>
        <if test="param.actStartDate != null and param.actStartDate != ''">
            AND tmt.last_pay_time &gt;= #{param.actStartDate}
        </if>
        <if test="param.actEndDate != null and param.actEndDate != ''">
            AND tmt.last_pay_time &lt;= #{param.actEndDate}
        </if>
        <if test="param.startPayCount != null and param.startPayCount != ''">
            AND tmt.total_pay_count &gt;= #{param.startPayCount}
        </if>
        <if test="param.endPayCount != null and param.endPayCount != ''">
            AND tmt.total_pay_count &lt;= #{param.endPayCount}
        </if>
        <if test="param.memberTags != null and param.memberTags != ''">
            AND tm.user_tags REGEXP #{param.memberTags}
        </if>
        ORDER BY tm.create_time DESC
    </select>
 
    <update id="deleteMemberTag">
        UPDATE t_member SET user_tags = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', user_tags, ','), CONCAT(',',#{memberTag},','), ','))
        WHERE FIND_IN_SET(#{memberTag}, user_tags) &gt; 0
    </update>
 
    <select id="listIdBySendType" resultType="java.lang.Long">
        SELECT
        tm.user_id
        FROM t_member tm
        WHERE tm.del_flag = 0
        <if test="sendType != null and sendType == 3">
            AND tm.binding_flag = 1
        </if>
        <if test="sendType != null and sendType == 4">
            AND tm.binding_flag = 0
        </if>
    </select>
 
    <select id="listSimpleVoByIds" resultType="com.ruoyi.system.api.domain.vo.MgtSimpleMemberVo">
        SELECT
            tm.user_id userId,
            tm.real_name realName,
            tm.nick_name nickName,
            tm.mobile mobile
        FROM t_member tm
        WHERE tm.del_flag = 0 AND FIND_IN_SET(tm.user_id, #{userIds}) &gt; 0
    </select>
 
    <select id="getUserIdByKeyword" resultType="java.lang.Long">
        SELECT
            tm.user_id
        FROM t_member tm tm.del_flag = 0
        <if test="param.keyword != null and param.keyword != ''">
            AND (tm.mobile LIKE CONCAT('%',#{param.keyword},'%') OR tm.real_name LIKE CONCAT('%',#{param.keyword},'%') OR tm.nick_name LIKE CONCAT('%',#{param.keyword},'%'))
        </if>
    </select>
 
    <select id="memberTotal" resultType="java.lang.Integer">
        SELECT COUNT(user_id) FROM t_member WHERE del_flag = 0
    </select>
 
    <select id="memberToday" resultType="java.lang.Integer">
        SELECT COUNT(user_id) FROM t_member WHERE del_flag = 0 AND create_time = CURDATE()
    </select>
 
    <select id="getTotalMemberTotal" resultType="com.ruoyi.member.domain.vo.MgtTotalMemberTotalVo">
        SELECT
            COUNT(member_id) memberTotal,
            SUM(CASE WHEN customer_source = "小程序" THEN 1 ELSE 0 END) onlineTotal,
            SUM(CASE WHEN customer_source = "小程序" THEN 0 ELSE 1 END) offlineTotal,
            0 introduceTotal,
            SUM(CASE WHEN goods_type LIKE "%周期%" THEN 1 ELSE 0 END) cycleTotal,
            SUM(CASE WHEN goods_type LIKE "%体验%" THEN 1 ELSE 0 END) experienceTotal,
            SUM(CASE WHEN goods_type LIKE "%服务%" THEN 1 ELSE 0 END) serviceTotal
        FROM t_member WHERE del_flag = 0 AND binding_flag = 1
        <if test="param.shopId != null and param.shopId != ''">
            AND relation_shop_id = #{param.shopId}
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND create_time &lt;= #{param.endDate}
        </if>
    </select>
 
    <select id="getTotalMemberTotal" resultType="com.ruoyi.member.domain.vo.MgtTotalMemberTotalVo">
        SELECT
        COUNT(member_id) memberTotal,
        SUM(CASE WHEN customer_source = "小程序" THEN 1 ELSE 0 END) onlineTotal,
        SUM(CASE WHEN customer_source = "小程序" THEN 0 ELSE 1 END) offlineTotal,
        0 introduceTotal,
        SUM(CASE WHEN goods_type LIKE "%周期%" THEN 1 ELSE 0 END) cycleTotal,
        SUM(CASE WHEN goods_type LIKE "%体验%" THEN 1 ELSE 0 END) experienceTotal,
        SUM(CASE WHEN goods_type LIKE "%服务%" THEN 1 ELSE 0 END) serviceTotal
        FROM t_member WHERE del_flag = 0 AND binding_flag = 1
        <if test="param.shopId != null and param.shopId != ''">
            AND relation_shop_id = #{param.shopId}
        </if>
    </select>
 
    <select id="getTotalMemberTotalAge" resultType="com.ruoyi.member.domain.vo.MgtAgeTotalVo">
        SELECT
        SUM(CASE WHEN gender = 0 THEN 1 ELSE 0 END) manTotal,
        SUM(CASE WHEN gender = 1 THEN 1 ELSE 0 END) womenTotal,
        SUM(CASE WHEN TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 1 AND 20 THEN 1 ELSE 0 END) AS tenAge,
        SUM(CASE WHEN TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 21 AND 30 THEN 1 ELSE 0 END) AS twentyAge,
        SUM(CASE WHEN TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 31 AND 40 THEN 1 ELSE 0 END) AS ThirtyAge,
        SUM(CASE WHEN TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 41 AND 50 THEN 1 ELSE 0 END) AS fortyAge,
        SUM(CASE WHEN TIMESTAMPDIFF(YEAR, birthday, CURDATE()) &gt;= 51 THEN 1 ELSE 0 END) AS fiftyAge
        FROM t_member WHERE del_flag = 0 AND binding_flag = 1
        <if test="param.shopId != null and param.shopId != ''">
            AND relation_shop_id = #{param.shopId}
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND create_time &lt;= #{param.endDate}
        </if>
    </select>
 
    <select id="getTotalMemberTotalNurse" resultType="com.ruoyi.system.api.domain.vo.MgtMapTotalVo">
        SELECT member_nurse mapKey, COUNT(*) mapValue
        FROM (
            SELECT member_id, SUBSTRING_INDEX(SUBSTRING_INDEX(member_nurse, ',', numbers.n), ',', -1) member_nurse
            FROM (SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10) numbers
            INNER JOIN t_member ON CHAR_LENGTH(member_nurse) - CHAR_LENGTH(REPLACE(member_nurse, ',', '')) >= numbers.n - 1
            <if test="param.shopId != null and param.shopId != ''">
                AND relation_shop_id = #{param.shopId}
            </if>
            <if test="param.startDate!=null and param.startDate!=''">
                AND create_time &gt;= #{param.startDate}
            </if>
            <if test="param.endDate!=null and param.endDate!=''">
                AND create_time &lt;= #{param.endDate}
            </if>
            ) x
        WHERE member_nurse != ''
        GROUP BY member_nurse
    </select>
 
    <select id="getTotalMemberTotalGoodsType" resultType="com.ruoyi.system.api.domain.vo.MgtMapTotalVo">
        SELECT goods_type mapKey, COUNT(*) mapValue
        FROM (
        SELECT member_id, SUBSTRING_INDEX(SUBSTRING_INDEX(goods_type, ',', numbers.n), ',', -1) goods_type
        FROM (SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) numbers
        INNER JOIN t_member ON CHAR_LENGTH(goods_type) - CHAR_LENGTH(REPLACE(goods_type, ',', '')) >= numbers.n - 1
        <if test="param.shopId != null and param.shopId != ''">
            AND relation_shop_id = #{param.shopId}
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND create_time &lt;= #{param.endDate}
        </if>
        ) x
        WHERE goods_type != ''
        GROUP BY goods_type
    </select>
 
    <select id="getTotalMemberTotalActiveness" resultType="java.lang.Integer">
        SELECT
            COUNT(tm.member_id)
        FROM t_member tm
        LEFT JOIN t_member_total tmt ON tm.member_id = tmt.member_id
        WHERE tm.del_Flag = 0
        <if test="shopId != null and shopId != ''">
            AND tm.relation_shop_id = #{shopId}
        </if>
        <if test="actStartDate != null and actStartDate != ''">
            AND tmt.last_pay_time &gt;= #{actStartDate}
        </if>
        <if test="actEndDate != null and actEndDate != ''">
            AND tmt.last_pay_time &lt;= #{actEndDate}
        </if>
    </select>
 
    <select id="getTotalMemberRankPay" resultType="com.ruoyi.system.api.domain.vo.MgtMapTotalVo">
        SELECT
        tm.nick_name mapKey,
        tmt.total_pay_count mapValue
        FROM t_member tm WHERE tm.del_flag = 0
        INNER JOIN t_member_total tmt ON tm.member_id = tmt.member_id
        <if test="param.shopId != null and param.shopId != ''">
            AND tm.relation_shop_id = #{param.shopId}
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND tm.create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND tm.create_time &lt;= #{param.endDate}
        </if>
        ORDER BY tmt.total_pay_count DESC LIMIT 15
    </select>
 
    <select id="getTotalMemberRankCustomerSource" resultType="com.ruoyi.system.api.domain.vo.MgtMapTotalVo">
        SELECT
        tm.customer_source mapKey,
        COUNT(tm.user_id) mapValue
        FROM t_member tm WHERE tm.del_flag = 0
        <if test="param.shopId != null and param.shopId != ''">
            AND tm.relation_shop_id = #{param.shopId}
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND tm.create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND tm.create_time &lt;= #{param.endDate}
        </if>
        GROUP BY tm.customer_source
        ORDER BY COUNT(tm.user_id) DESC LIMIT 15
    </select>
 
    <select id="listUserIdByAge" resultType="java.lang.Long">
        SELECT user_id
        FROM t_member
        WHERE del_flag = 0
        <if test="param.ageType != null and param.ageType ==1">
            AND TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 1 AND 20
        </if>
        <if test="param.ageType != null and param.ageType ==2">
            AND TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 21 AND 30
        </if>
        <if test="param.ageType != null and param.ageType ==3">
            AND TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 31 AND 40
        </if>
        <if test="param.ageType != null and param.ageType ==4">
            AND TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 41 AND 50
        </if>
        <if test="param.ageType != null and param.ageType ==5">
            AND TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 1 AND 20
        </if>
        <if test="param.userIds != null">
            AND user_id IN
            <foreach collection="param.userIds" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>
 
    <select id="getPlTotalMemberTotal" resultType="com.ruoyi.system.api.domain.vo.MgtPlTotalMemberTotalVo">
        SELECT
        COUNT(*) AS memberTotal,
        COUNT(CASE WHEN DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY) THEN 1 END) AS memberYesterday,
        COUNT(CASE WHEN create_time BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE() THEN 1 END) AS memberSeven
        FROM t_member WHERE del_flag = 0 AND binding_flag = 1
    </select>
 
    <select id="getPlTotalMemberTotalAge" resultType="com.ruoyi.member.domain.vo.MgtAgeTotalVo">
        SELECT
        SUM(CASE WHEN gender = 0 THEN 1 ELSE 0 END) manTotal,
        SUM(CASE WHEN gender = 1 THEN 1 ELSE 0 END) womenTotal,
        SUM(CASE WHEN TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 1 AND 20 THEN 1 ELSE 0 END) AS tenAge,
        SUM(CASE WHEN TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 21 AND 30 THEN 1 ELSE 0 END) AS twentyAge,
        SUM(CASE WHEN TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 31 AND 40 THEN 1 ELSE 0 END) AS ThirtyAge,
        SUM(CASE WHEN TIMESTAMPDIFF(YEAR, birthday, CURDATE()) BETWEEN 41 AND 50 THEN 1 ELSE 0 END) AS fortyAge,
        SUM(CASE WHEN TIMESTAMPDIFF(YEAR, birthday, CURDATE()) &gt;= 51 THEN 1 ELSE 0 END) AS fiftyAge
        FROM t_member WHERE del_flag = 0 AND binding_flag = 1
        <if test="param.shopIdList != null and param.shopIdList != ''">
            AND relation_shop_id IN
            <foreach collection="param.shopIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND create_time &lt;= #{param.endDate}
        </if>
    </select>
 
    <select id="getPlTotalMemberTotalNurse" resultType="com.ruoyi.system.api.domain.vo.MgtMapTotalVo">
        SELECT member_nurse mapKey, COUNT(*) mapValue
        FROM (
        SELECT member_id, SUBSTRING_INDEX(SUBSTRING_INDEX(member_nurse, ',', numbers.n), ',', -1) member_nurse
        FROM (SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10) numbers
        INNER JOIN t_member ON CHAR_LENGTH(member_nurse) - CHAR_LENGTH(REPLACE(member_nurse, ',', '')) >= numbers.n - 1
        <if test="param.shopIdList != null and param.shopIdList != ''">
            AND relation_shop_id IN
            <foreach collection="param.shopIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND create_time &lt;= #{param.endDate}
        </if>
        ) x
        WHERE member_nurse != ''
        GROUP BY member_nurse
    </select>
 
    <select id="getPlTotalMemberTotalGoodsType" resultType="com.ruoyi.system.api.domain.vo.MgtMapTotalVo">
        SELECT goods_type mapKey, COUNT(*) mapValue
        FROM (
        SELECT member_id, SUBSTRING_INDEX(SUBSTRING_INDEX(goods_type, ',', numbers.n), ',', -1) goods_type
        FROM (SELECT 1 n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) numbers
        INNER JOIN t_member ON CHAR_LENGTH(goods_type) - CHAR_LENGTH(REPLACE(goods_type, ',', '')) >= numbers.n - 1
        <if test="param.shopIdList != null and param.shopIdList != ''">
            AND relation_shop_id IN
            <foreach collection="param.shopIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND create_time &lt;= #{param.endDate}
        </if>
        ) x
        WHERE goods_type != ''
        GROUP BY goods_type
    </select>
 
    <select id="getPlTotalMemberTotalActiveness" resultType="java.lang.Integer">
        SELECT
        COUNT(tm.member_id)
        FROM t_member tm
        INNER JOIN t_member_total tmt ON tm.member_id = tmt.member_id
        WHERE tm.del_Flag = 0
        <if test="shopIdList != null and shopIdList != ''">
            AND tm.relation_shop_id IN
            <foreach collection="shopIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="actStartDate != null and actStartDate != ''">
            AND tmt.last_pay_time &gt;= #{actStartDate}
        </if>
        <if test="actEndDate != null and actEndDate != ''">
            AND tmt.last_pay_time &lt;= #{actEndDate}
        </if>
    </select>
 
    <select id="getPlTotalMemberRankPay" resultType="com.ruoyi.system.api.domain.vo.MgtMapTotalVo">
        SELECT
        tm.nick_name mapKey,
        tmt.total_pay_count mapValue
        FROM t_member tm WHERE del_flag = 0
        INNER JOIN t_member_total tmt ON tm.member_id = tmt.member_id
        <if test="param.shopIdList != null and shopIdList != ''">
            AND tm.relation_shop_id IN
            <foreach collection="param.shopIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND tm.create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND tm.create_time &lt;= #{param.endDate}
        </if>
        ORDER BY tmt.total_pay_count DESC LIMIT 15
    </select>
 
    <select id="getTotalMemberRankCustomerSource" resultType="com.ruoyi.system.api.domain.vo.MgtMapTotalVo">
        SELECT
        tm.customer_source mapKey,
        COUNT(tm.user_id) mapValue
        FROM t_member tm WHERE tm.del_flag = 0
        <if test="shopIdList != null and shopIdList != ''">
            AND tm.relation_shop_id IN
            <foreach collection="param.shopIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND tm.create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND tm.create_time &lt;= #{param.endDate}
        </if>
        GROUP BY tm.customer_source
        ORDER BY COUNT(tm.user_id) DESC LIMIT 15
    </select>
 
    <select id="getPlTotalMemberRank" resultType="com.ruoyi.system.api.domain.vo.MgtMapTotalVo">
        SELECT
        tm.relation_shop_name mapKey,
        COUNT(tm.user_id) mapValue
        FROM t_member tm WHERE tm.del_flag = 0
        <if test="shopIdList != null and shopIdList != ''">
            AND tm.relation_shop_id IN
            <foreach collection="param.shopIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="param.startDate!=null and param.startDate!=''">
            AND tm.create_time &gt;= #{param.startDate}
        </if>
        <if test="param.endDate!=null and param.endDate!=''">
            AND tm.create_time &lt;= #{param.endDate}
        </if>
        GROUP BY tm.relation_shop_name
        ORDER BY COUNT(tm.user_id) DESC LIMIT 15
    </select>
 
 
    <select id="listUserIdByShopId" resultType="java.lang.Long">
        SELECT user_id
        FROM t_member
        WHERE del_flag = 0
        <if test="param.userIds != null">
            AND relation_shop_id IN
            <foreach collection="shopIdList" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>
</mapper>