Administrator
2018-10-30 c0c91fbda1ba601c4c8cb6d12fd43dfbe02eea5d
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
<?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.yeshi.fanli.dao.mybatis.UserInfoMapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.UserInfo">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="identifycode" property="openid" jdbcType="VARCHAR" />
        <result column="login_type" property="loginType" jdbcType="INTEGER" />
        <result column="wx_open_id" property="wxOpenId" jdbcType="VARCHAR" />
        <result column="wx_union_id" property="wxUnionId" jdbcType="VARCHAR" />
        <result column="nick_name" property="nickName" jdbcType="VARCHAR" />
        <result column="tbName" property="tbName" jdbcType="VARCHAR" />
        <result column="tbPic" property="tbPic" jdbcType="VARCHAR" />
        <result column="wxName" property="wxName" jdbcType="VARCHAR" />
        <result column="wxPic" property="wxPic" jdbcType="VARCHAR" />
        <result column="portrait" property="portrait" jdbcType="VARCHAR" />
        <result column="createtime" property="createtime" jdbcType="BIGINT" />
        <result column="last_logintime" property="lastLoginTime"
            jdbcType="BIGINT" />
        <result column="loginip" property="lastLoginIp" jdbcType="VARCHAR" />
        <result column="tuiguang_code" property="tuiGuangCode"
            jdbcType="VARCHAR" />
        <result column="appid" property="appId" jdbcType="VARCHAR" />
        <result column="my_hongBao" property="myHongBao" jdbcType="DECIMAL" />
        <result column="pay_password" property="payPassword" jdbcType="VARCHAR" />
        <result column="rank" property="rank" jdbcType="INTEGER" />
        <result column="phone" property="phone" jdbcType="VARCHAR" />
        <result column="state" property="state" jdbcType="INTEGER" />
        <result column="state_desc" property="stateDesc" jdbcType="VARCHAR" />
        <!-- <association property="system" column="sid" resultMap="com.yeshi.fanli.dao.mybatis.SystemMapper.BaseResultMap" 
            /> -->
 
 
    </resultMap>
    <sql id="Base_Column_List">id,identifycode,login_type,wx_open_id,wx_union_id,nick_name,tbName,tbPic,wxName,wxPic,portrait,createtime,last_logintime,loginip,tuiguang_code,appid,my_hongBao,pay_password,sid,rank,phone,state,state_desc
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where id = #{id,jdbcType=BIGINT} and `state`=0
    </select>
    
    <select id="selectByPKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where id = #{id,jdbcType=BIGINT} 
    </select>
    
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where id = #{id,jdbcType=BIGINT} for update
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_user where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.UserInfo"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user
        (id,identifycode,login_type,wx_open_id,wx_union_id,nick_name,tbName,tbPic,wxName,wxPic,portrait,createtime,last_logintime,loginip,tuiguang_code,appid,my_hongBao,pay_password,sid,rank,phone,state,state_desc)
        values
        (#{id,jdbcType=BIGINT},#{openid,jdbcType=VARCHAR},#{loginType,jdbcType=INTEGER},#{wxOpenId,jdbcType=VARCHAR},#{wxUnionId,jdbcType=VARCHAR},#{nickName,jdbcType=VARCHAR},#{tbName,jdbcType=VARCHAR},#{tbPic,jdbcType=VARCHAR},#{wxName,jdbcType=VARCHAR},#{wxPic,jdbcType=VARCHAR},#{portrait,jdbcType=VARCHAR},#{createtime,jdbcType=BIGINT},#{lastLoginTime,jdbcType=BIGINT},#{lastLoginIp,jdbcType=VARCHAR},#{tuiGuangCode,jdbcType=VARCHAR},#{appId,jdbcType=VARCHAR},#{myHongBao,jdbcType=DECIMAL},#{payPassword,jdbcType=VARCHAR},#{system.id,jdbcType=BIGINT},#{rank,jdbcType=INTEGER},#{phone,jdbcType=VARCHAR},#{state,jdbcType=INTEGER},#{stateDesc,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.UserInfo"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="openid != null">identifycode,</if>
            <if test="loginType != null">login_type,</if>
            <if test="wxOpenId != null">wx_open_id,</if>
            <if test="wxUnionId != null">wx_union_id,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="tbName != null">tbName,</if>
            <if test="tbPic != null">tbPic,</if>
            <if test="wxName != null">wxName,</if>
            <if test="wxPic != null">wxPic,</if>
            <if test="portrait != null">portrait,</if>
            <if test="createtime != null">createtime,</if>
            <if test="lastLoginTime != null">last_logintime,</if>
            <if test="lastLoginIp != null">loginip,</if>
            <if test="tuiGuangCode != null">tuiguang_code,</if>
            <if test="appId != null">appid,</if>
            <if test="myHongBao != null">my_hongBao,</if>
            <if test="payPassword != null">pay_password,</if>
            <if test="system != null">sid,</if>
            <if test="rank != null">rank,</if>
            <if test="phone != null">phone,</if>
            <if test="state != null">state,</if>
            <if test="stateDesc != null">state_desc,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="openid != null">#{openid,jdbcType=VARCHAR},</if>
            <if test="loginType != null">#{loginType,jdbcType=INTEGER},</if>
            <if test="wxOpenId != null">#{wxOpenId,jdbcType=VARCHAR},</if>
            <if test="wxUnionId != null">#{wxUnionId,jdbcType=VARCHAR},</if>
            <if test="nickName != null">#{nickName,jdbcType=VARCHAR},</if>
            <if test="tbName != null">#{tbName,jdbcType=VARCHAR},</if>
            <if test="tbPic != null">#{tbPic,jdbcType=VARCHAR},</if>
            <if test="wxName != null">#{wxName,jdbcType=VARCHAR},</if>
            <if test="wxPic != null">#{wxPic,jdbcType=VARCHAR},</if>
            <if test="portrait != null">#{portrait,jdbcType=VARCHAR},</if>
            <if test="createtime != null">#{createtime,jdbcType=BIGINT},</if>
            <if test="lastLoginTime != null">#{lastLoginTime,jdbcType=BIGINT},</if>
            <if test="lastLoginIp != null">#{lastLoginIp,jdbcType=VARCHAR},</if>
            <if test="tuiGuangCode != null">#{tuiGuangCode,jdbcType=VARCHAR},</if>
            <if test="appId != null">#{appId,jdbcType=VARCHAR},</if>
            <if test="myHongBao != null">#{myHongBao,jdbcType=DECIMAL},</if>
            <if test="payPassword != null">#{payPassword,jdbcType=VARCHAR},</if>
            <if test="system != null">#{system.id,jdbcType=BIGINT},</if>
            <if test="rank != null">#{rank,jdbcType=INTEGER},</if>
            <if test="phone != null">#{phone,jdbcType=VARCHAR},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="stateDesc != null">#{stateDesc,jdbcType=VARCHAR}</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.user.UserInfo">update
        yeshi_ec_user set identifycode = #{openid,jdbcType=VARCHAR},login_type
        = #{loginType,jdbcType=INTEGER},wx_open_id =
        #{wxOpenId,jdbcType=VARCHAR},wx_union_id =
        #{wxUnionId,jdbcType=VARCHAR},nick_name =
        #{nickName,jdbcType=VARCHAR},tbName = #{tbName,jdbcType=VARCHAR},tbPic
        = #{tbPic,jdbcType=VARCHAR},wxName = #{wxName,jdbcType=VARCHAR},wxPic
        = #{wxPic,jdbcType=VARCHAR},portrait =
        #{portrait,jdbcType=VARCHAR},createtime =
        #{createtime,jdbcType=BIGINT},last_logintime =
        #{lastLoginTime,jdbcType=BIGINT},loginip =
        #{lastLoginIp,jdbcType=VARCHAR},tuiguang_code =
        #{tuiGuangCode,jdbcType=VARCHAR},appid =
        #{appId,jdbcType=VARCHAR},my_hongBao =
        #{myHongBao,jdbcType=DECIMAL},pay_password =
        #{payPassword,jdbcType=VARCHAR},sid =
        #{system.id,jdbcType=BIGINT},rank = #{rank,jdbcType=INTEGER} ,phone
        =#{phone,jdbcType=VARCHAR} ,state =#{state,jdbcType=INTEGER}
        ,state_desc =#{stateDesc,jdbcType=VARCHAR} where id =
        #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.UserInfo">
        update yeshi_ec_user
        <set>
            <if test="openid != null">identifycode=#{openid,jdbcType=VARCHAR},</if>
            <if test="loginType != null">login_type=#{loginType,jdbcType=INTEGER},</if>
            <if test="wxOpenId != null">wx_open_id=#{wxOpenId,jdbcType=VARCHAR},</if>
            <if test="wxUnionId != null">wx_union_id=#{wxUnionId,jdbcType=VARCHAR},</if>
            <if test="nickName != null">nick_name=#{nickName,jdbcType=VARCHAR},</if>
            <if test="tbName != null">tbName=#{tbName,jdbcType=VARCHAR},</if>
            <if test="tbPic != null">tbPic=#{tbPic,jdbcType=VARCHAR},</if>
            <if test="wxName != null">wxName=#{wxName,jdbcType=VARCHAR},</if>
            <if test="wxPic != null">wxPic=#{wxPic,jdbcType=VARCHAR},</if>
            <if test="portrait != null">portrait=#{portrait,jdbcType=VARCHAR},</if>
            <if test="createtime != null">createtime=#{createtime,jdbcType=BIGINT},</if>
            <if test="lastLoginTime != null">last_logintime=#{lastLoginTime,jdbcType=BIGINT},</if>
            <if test="lastLoginIp != null">loginip=#{lastLoginIp,jdbcType=VARCHAR},</if>
            <if test="tuiGuangCode != null">tuiguang_code=#{tuiGuangCode,jdbcType=VARCHAR},</if>
            <if test="appId != null">appid=#{appId,jdbcType=VARCHAR},</if>
            <if test="myHongBao != null">my_hongBao=#{myHongBao,jdbcType=DECIMAL},</if>
            <if test="payPassword != null">pay_password=#{payPassword,jdbcType=VARCHAR},</if>
            <if test="system != null">sid=#{system.id,jdbcType=BIGINT},</if>
            <if test="rank != null">rank=#{rank,jdbcType=INTEGER},</if>
            <if test="phone !=null">phone =#{phone,jdbcType=VARCHAR},</if>
            <if test="state !=null">state =#{state,jdbcType=INTEGER},</if>
            <if test="stateDesc !=null">state_desc =#{stateDesc,jdbcType=VARCHAR},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="subHongBaoByUid">update yeshi_ec_user set my_hongBao=
        my_hongBao-#{money,jdbcType=DECIMAL} where id = #{uid,jdbcType=BIGINT}
    </update>
    <update id="addHongBaoByUid">update yeshi_ec_user set my_hongBao=
        my_hongBao+#{money,jdbcType=DECIMAL} where id = #{uid,jdbcType=BIGINT}
    </update>
    <!-- 清除手势密码 -->
    <delete id="cleanPassword">DELETE FROM `yeshi_ec_extract_record` WHERE uid =
        #{id};
    </delete>
    <!-- 查询新人红包 -->
    <select id="getNewPeopleHB" resultType="BigDecimal">SELECT sum(hb.`money`)
        FROM `yeshi_ec_hongbao` hb WHERE hb.`uid` = #{id} AND hb.`type` = '4';
    </select>
    <!-- 查询我的红包 -->
    <select id="getMyHB" resultType="BigDecimal">SELECT SUM(hb.`money`) FROM
        `yeshi_ec_hongbao` hb WHERE hb.`uid` = #{id};
    </select>
    <!-- 根据AppId与微信unionID获取用户 -->
    <select id="getUserInfoByAppIdAndWXUnionId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where appid=#{appId} and wx_union_id=#{unionId}
        limit 1
    </select>
    <!-- 根据AppId与淘宝OpenId获取用户 -->
    <select id="getUserInfoByAppIdAndTaoBaoOpenId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where appid=#{appId} and identifycode=#{openId}
        limit 1
    </select>
    <!-- 根据AppId与电话号码获取用户 -->
    <select id="getUserInfoByAppIdAndPhone" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where appid=#{appId} and phone=#{phone} limit 1
    </select>
    <select id="getMaxUid" resultType="java.lang.Long">select max(id) from
        yeshi_ec_user
    </select>
    <!-- 两个账号的业务融合 -->
    <select id="connectUser" >
     call procedure_connect_user(#{mainUid},#{lessUid})
    </select>
    
    <select id="query"  resultMap="BaseResultMap">
           SELECT u.*
           <if test="orderField != null and orderField != 5 and orderField != 6">
           ,(SELECT COUNT(hb.id) FROM `yeshi_ec_hongbao` hb 
                   WHERE hb.uid = u.id AND TYPE IN (1,2)
               <if test="orderMode == 2">
                <!-- AND  TO_DAYS(FROM_UNIXTIME(hb.`createtime`/1000)) = TO_DAYS(NOW()) -->
                AND DATE_FORMAT( FROM_UNIXTIME(hb.`createtime`/1000), '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
            </if>
           )AS total
           </if>
               <if test="orderMode == 3">
                ,(SELECT COUNT(tr.`id`) FROM `yeshi_ec_threesale` tr 
                     WHERE  tr.`boss_id`=u.id AND tr.state = 1) AS totalThree
             </if>
           
           FROM yeshi_ec_user u 
               LEFT JOIN yeshi_ec_binding_account  b ON u.`id` = b.`uid`  
           where  1=1  
                <if test="key != null and key !='' ">
                   AND    (u.id LIKE '%${key}%' OR u.`phone` LIKE '%${key}%' OR b.`account` LIKE '%${key}%')
                </if>
                <if test="startTime != null and startTime !='' ">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) >= '${startTime}' ]]>  
                </if>
                <if test="endTime != null and endTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) < '${endTime}'  ]]>  
                </if>
                   <if test="userType != null">
                   AND u.rank = #{userType}
                </if>
                  <if test="days != null">
                <!--  时间   -->
                    AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) <= FROM_UNIXTIME(createtime/1000)]]> 
            </if>
              
              ORDER BY 
              <if test="orderField == 1">
                  total,
              </if>
              <if test="orderField == 2">
                  total DESC,
              </if>
               <if test="orderField == 3">
                  total,
              </if>
              <if test="orderField == 4">
                  total DESC,
              </if>
              <if test="orderField == 5">
                  totalThree,
              </if>
              <if test="orderField == 6">
                  totalThree DESC,
              </if>
              
              createtime DESC  LIMIT ${start},${count}
              
    </select>
    
    <select id="queryCount" resultType="java.lang.Long">
           SELECT count(u.id) FROM yeshi_ec_user u 
               LEFT JOIN yeshi_ec_binding_account  b ON u.`id` = b.`uid`  
           where <![CDATA[ 1>0 ]]>  
                <if test="key != null and key !='' ">
                   AND    (u.id LIKE '%${key}%' OR u.`phone` LIKE '%${key}%' OR b.`account` LIKE '%${key}%')
                </if>
                <if test="startTime != null and startTime !='' ">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) >= '${startTime}' ]]>  
                </if>
                <if test="endTime != null and endTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) < '${endTime}'  ]]>  
                </if>
                   <if test="userType != null">
                   AND u.rank = #{userType}
                </if>
                  <if test="days != null">
                <!--  时间   -->
                    AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) <= FROM_UNIXTIME(createtime/1000)]]> 
            </if>
             
    </select>
    
    <select id="querySumMoney" resultType="java.lang.Double">
           SELECT COALESCE(sum(u.my_hongBao),0) FROM yeshi_ec_user u 
               LEFT JOIN yeshi_ec_binding_account  b ON u.`id` = b.`uid`  
           where <![CDATA[ 1>0 ]]>  
                <if test="key != null and key !='' ">
                   AND    (u.id LIKE '%${key}%' OR u.`phone` LIKE '%${key}%' OR b.`account` LIKE '%${key}%')
                </if>
                <if test="startTime != null and startTime !='' ">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) >= '${startTime}' ]]>  
                </if>
                <if test="endTime != null and endTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) < '${endTime}'  ]]>  
                </if>
                   <if test="userType != null">
                   AND u.rank = #{userType}
                </if>
                  <if test="days != null">
                <!--  时间   -->
                    AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) <= FROM_UNIXTIME(createtime/1000)]]> 
            </if>
    </select>
    
    
    <select id="countNewUser" resultType="java.lang.Long">
       <!--  自购订单 -->
           SELECT COALESCE(count(id),0) FROM `yeshi_ec_user` 
            WHERE 1 > 0
                <if test="isToday != null and isToday == 1">
                AND  TO_DAYS(FROM_UNIXTIME(createtime/1000)) = TO_DAYS(NOW())
            </if>
            <if test="isMonth != null and isMonth == 1">
                AND DATE_FORMAT( FROM_UNIXTIME(createtime/1000), '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
            </if>
    </select>
    
    <select id="countRank" resultType="java.lang.Long">
       <!--  等级统计 -->
           SELECT COALESCE(count(id),0) FROM `yeshi_ec_user` WHERE rank = #{rank}
    </select>
    
    <select id="countAllMoney" resultType="java.lang.Double">
       <!--  金额统计 -->
           SELECT COALESCE(sum(my_hongBao),0) FROM `yeshi_ec_user` 
           WHERE 1=1 
               <if test="minMoney != null">
              AND <![CDATA[ my_hongBao >= #{minMoney}]]> 
            </if>
    </select>
    
    <select id="countShareAndInviteMoney" resultMap="BaseResultMap">
        SELECT IFNULL(SUM(h.`money`),0),h.`uid` FROM `yeshi_ec_hongbao` h 
        WHERE  DATE_FORMAT(FROM_UNIXTIME(h.`createtime`/1000), '%Y-%m-%d' )= '2018-08-02'
        <![CDATA[AND h.state <>4]]> 
         AND ( h.`type` =5 OR  h.`type` =6 OR h.`type` =7 OR  h.`type` =20 OR h.`type` =21 OR h.`type` =22 )
        GROUP BY h.`uid` 
        ORDER BY SUM(h.`money`) DESC
         LIMIT ${start},${count}
    </select>
    
    <select id="longTimeNoLogin"  resultType="java.lang.Long">
    
        SELECT u.`id` FROM `yeshi_ec_user` u 
        WHERE  u.`id` IN <foreach item="item" collection="list" open="(" separator=","
            close=")">#{item}</foreach>
        AND <![CDATA[ (DATE_SUB(CURDATE(), INTERVAL ${daysNum} DAY) > DATE(FROM_UNIXTIME(u.`last_logintime`/1000))  
            OR (u.`last_logintime` IS NULL 
                AND DATE_SUB(CURDATE(), INTERVAL ${daysNum} DAY) > DATE(FROM_UNIXTIME(u.`createTime`/1000)))) ]]>
    </select>
    
    
</mapper>