jiangqs
2023-06-08 6cca89c41aea52ae6b23909bb9fbd2834f0094d5
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
<?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.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
        FROM t_member tm
        INNER JOIN t_member_total tmt ON tm.member_id = tmt.member_id
        WHERE 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.memberTag != null and param.memberTag != ''">
            AND FIND_IN_SET(#{param.memberTag},tm.user_tags) &gt; 0
        </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>
</mapper>