admin
2019-07-30 573c491b4a1ba60e12a5678a01c1546c0077c1ee
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
<?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>
    
    <resultMap id="BaseResultMapVO" type="com.yeshi.fanli.vo.user.UserInfoVO">
        <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" />
        
        <result column="ur_id" property="rankId" jdbcType="BIGINT" />
        <result column="ur_name" property="rankName"    jdbcType="VARCHAR" />
        <result column="ur_picture" property="rankPicture"    jdbcType="VARCHAR" />
        
        <result column="totalOrder" property="totalOrder"    jdbcType="BIGINT" />
        <result column="monthOrder" property="monthOrder"    jdbcType="BIGINT" />
        
        <result column="taoBaoUid" property="taoBaoUid"    jdbcType="VARCHAR" />
        
        <result column="wxUnionIdInvalid" property="wxUnionIdInvalid"    jdbcType="VARCHAR" />
        <result column="taobaoUidInvalid" property="taobaoUidInvalid"    jdbcType="VARCHAR" />
        <result column="phoneInvalid" property="phoneInvalid"    jdbcType="VARCHAR" />
        <result column="alipayAccountInvalid" property="alipayAccountInvalid"    jdbcType="VARCHAR" />
        
    </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="listByAppIdAndWXUnionId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where appid=#{appId} and wx_union_id=#{unionId}
    </select>
    <!-- 根据AppId与淘宝OpenId获取用户 -->
    <select id="listByAppIdAndTaoBaoOpenId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where appid=#{appId} and identifycode=#{openId}
    </select>
    <!-- 根据AppId与电话号码获取用户 -->
    <select id="listByAppIdAndPhone" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where appid=#{appId} and phone=#{phone} 
    </select>
    
    <!-- 根据AppId与电话号码获取用户 -->
    <select id="getEffectiveUserInfoByPhone" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" /> from yeshi_ec_user 
        where phone=#{phone} AND state = 0 
        LIMIT 1 
    </select>
    
    <!-- 根据AppId与电话号码获取用户 -->
    <select id="getEffectiveUserInfoByWXUnionId" resultMap="BaseResultMap">
        select <include refid="Base_Column_List" /> from yeshi_ec_user 
        where wx_union_id=#{unionId} AND state = 0 
        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="BaseResultMapVO">
           SELECT *
           ,(SELECT COUNT(hb.hb_id) FROM `yeshi_ec_hongbao_v2` hb 
                   WHERE hb.hb_uid = u.id AND hb.hb_type = 1 )AS totalOrder <!-- 累计订单 -->
           ,(SELECT COUNT(hb.hb_id) FROM `yeshi_ec_hongbao_v2` hb 
                   WHERE hb.hb_uid = u.id AND hb.hb_type = 1
                   AND DATE_FORMAT(hb.`hb_create_time`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m'))AS monthOrder <!-- 累计本月订单 -->
        ,(SELECT COUNT(tr.`id`) FROM `yeshi_ec_threesale` tr  <!-- 队员 -->
             WHERE  tr.`boss_id`=u.id AND tr.state = 1) AS totalPlayers 
           FROM yeshi_ec_user u 
               LEFT JOIN yeshi_ec_binding_account  b ON u.`id` = b.`uid`  
               LEFT JOIN yeshi_ec_user_info_extra  ext ON u.`id` = ext.uie_uid
               LEFT JOIN yeshi_ec_user_rank rak ON rak.ur_id = ext.uie_rank_id
               LEFT JOIN yeshi_ec_user_info_extra_taobao tb ON  tb.`uiet_uid` = u.id
        
        <if test="userState == 2">
               LEFT JOIN 
                (SELECT A.uid AS buid,MAX(A.f_wxUnionId) AS wxUnionIdInvalid ,MAX(A.f_taobaoUid) AS taobaoUidInvalid,MAX(A.f_phone) AS phoneInvalid,MAX(A.f_alipayAccount) AS alipayAccountInvalid FROM 
                    (SELECT u.`id`AS uid,b.account AS alipayAccount,b.name AS alipayAccountName,fu.* FROM yeshi_ec_user u 
                LEFT JOIN yeshi_ec_binding_account b ON b.`uid` = u.`id`
                LEFT JOIN yeshi_ec_user_info_extra_taobao tb ON  tb.`uiet_uid` = u.id
                LEFT JOIN (SELECT fc.fuc_effective,IF(fc.`fuc_type` = 'wxUnionId',fc.`fuc_identify_code`,NULL)AS f_wxUnionId,
                    IF(fc.`fuc_type` = 'taobaoUid',fc.`fuc_identify_code`,NULL)AS f_taobaoUid,
                    IF(fc.`fuc_type` = 'phone',fc.`fuc_identify_code`,NULL)AS f_phone,
                    IF(fc.`fuc_type` = 'alipayAccount',fc.`fuc_identify_code`,NULL)AS f_alipayAccount
                FROM yeshi_ec_forbidden_user_identify_code fc WHERE fc.fuc_effective = 1 )fu ON (fu.f_wxUnionId = u.`wx_union_id` OR fu.f_taobaoUid = tb.`uiet_taobao_uid` OR fu.f_phone = u.`phone` OR fu.f_alipayAccount = b.`account`)
                WHERE u.`state` =2  
            )A GROUP BY A.uid) B ON u.id= B.buid 
           </if>
           
           where 1=1
               <if test="userState == 1">
                   AND u.`state` <![CDATA[<>]]> 2 <!--  正常用户 -->
               </if>
               <if test="userState == 2">
                    AND u.`state` =2   <!-- 封禁用户 -->
               </if>
               <if test="startTime != null and startTime !='' ">
                   AND DATE_FORMAT(FROM_UNIXTIME(u.createtime/1000),'%Y%m%d')<![CDATA[>=]]> DATE_FORMAT(#{startTime},'%Y%m%d')
               </if>
               <if test="endTime != null and endTime !=''">
                   AND DATE_FORMAT(FROM_UNIXTIME(u.createtime/1000),'%Y%m%d')<![CDATA[<=]]> DATE_FORMAT(#{endTime},'%Y%m%d') 
               </if>
                  <if test="userRank != null">
                   AND rak.ur_name = #{userRank}
               </if>
               <if test="days != null">
                    <!--  注册时间   -->
                    AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) <= FROM_UNIXTIME(u.createtime/1000)]]> 
            </if>
               <if test="key != null and key !='' ">
                   <if test="keyType == 1">
                       AND    u.id  = #{key}
                   </if>
                   <if test="keyType == 2">
                       AND    u.`nick_name` LIKE '%${key}%'
                   </if>
                   <if test="keyType == 3">
                       AND    u.`phone` = #{key}
                   </if>
                   <if test="keyType == 4">
                       AND    b.`account` = #{key}
                   </if>
               </if>
              
              ORDER BY 
              <if test="orderField == 1">
                  totalOrder,
              </if>
              <if test="orderField == 2">
                  totalOrder DESC,
              </if>
              <if test="orderField == 3">
                  monthOrder,
              </if>
              <if test="orderField == 4">
                  monthOrder DESC,
              </if>
              <if test="orderField == 5">
                  totalPlayers,
              </if>
              <if test="orderField == 6">
                  totalPlayers DESC,
              </if>
              u.createtime DESC  
              
              LIMIT ${start},${count}
    </select>
    
    <select id="queryCount" resultType="java.lang.Long">
           SELECT IFNULL(count(u.id),0) FROM yeshi_ec_user u 
               LEFT JOIN yeshi_ec_binding_account  b ON u.`id` = b.`uid`  
               LEFT JOIN yeshi_ec_user_info_extra  ext ON u.`id` = ext.uie_uid
               LEFT JOIN yeshi_ec_user_rank rak ON rak.ur_id = ext.uie_rank_id
           where 1=1
           
                <if test="userState == 1">
                   AND u.`state` <![CDATA[<>]]> 2 <!--  正常用户 -->
               </if>
               <if test="userState == 2">
                    AND u.`state` =2   <!-- 封禁用户 -->
               </if>
                <if test="startTime != null and startTime !='' ">
                   AND DATE_FORMAT(FROM_UNIXTIME(u.createtime/1000),'%Y%m%d')<![CDATA[>=]]> DATE_FORMAT(#{startTime},'%Y%m%d')
                </if>
                <if test="endTime != null and endTime !=''">
                   AND DATE_FORMAT(FROM_UNIXTIME(u.createtime/1000),'%Y%m%d')<![CDATA[<=]]> DATE_FORMAT(#{endTime},'%Y%m%d') 
                </if>
                   <if test="userRank != null">
                   AND rak.ur_name = #{userRank}
                </if>
                <if test="days != null">  <!--  注册时间   -->
                    AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) <= FROM_UNIXTIME(u.createtime/1000)]]> 
             </if>
             
             <if test="key != null and key !='' ">
                   <if test="keyType == 1">
                       AND    u.id  = #{key}
                   </if>
                   <if test="keyType == 2">
                       AND    u.`nick_name` LIKE '%${key}%'
                   </if>
                   <if test="keyType == 3">
                       AND    u.`phone` = #{key}
                   </if>
                   <if test="keyType == 4">
                       AND    b.`account` = #{key}
                   </if>
               </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 u.`wxName` LIKE '%${key}%'
                   OR u.`nick_name` LIKE '%${key}%'  OR u.`tbName` 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=1
                <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.math.BigDecimal">
       <!--  金额统计 -->
           SELECT CAST(SUM(my_hongBao)AS DECIMAL(19,2)) 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>
    
    
    <select id="countLoseUser" resultType="java.lang.Long">
        SELECT  COUNT(DISTINCT t.`id` ) FROM `yeshi_ec_user` t 
        LEFT JOIN `yeshi_ec_user_money_detail` d ON d.`umd_uid` = t.`id` 
        WHERE DATE_SUB(CURDATE(), INTERVAL ${num} DAY)<![CDATA[> ]]> DATE(FROM_UNIXTIME( t.`last_logintime`/1000)) 
               AND DATE_SUB(CURDATE(), INTERVAL ${num} DAY) <![CDATA[> ]]> DATE(d.`umd_createtime`)
    </select>
    
    <select id="countHasOrderUser" resultType="java.lang.Long">
        SELECT COUNT(DISTINCT h.`hb_uid`) FROM yeshi_ec_hongbao_v2 h 
        WHERE (h.`hb_type`=1 or  h.`hb_type`=2 or h.`hb_type`= 20)
    </select>
    
    
    <select id="countNewUserByDate" resultType="java.util.HashMap">
        SELECT COUNT(DISTINCT h.`id`) AS showValue,
            <if test="type == 1">
                 FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d') AS 'showDate'
            </if>
            <if test="type == 2">
                 FROM_UNIXTIME(h.`createtime`/1000,'%m') AS 'showDate'
            </if>
            <if test="type == 3">
                 FROM_UNIXTIME(h.`createtime`/1000,'%Y') AS 'showDate'
            </if>
        FROM yeshi_ec_user h 
            <if test="channel != null and  channel != 'all' ">
                left join (SELECT a.`lua_uid` AS uid FROM `yeshi_ec_log_user_active`  a 
                WHERE a.`lua_channel`='${channel}' GROUP BY a.`lua_uid`)a ON h.`id`=a.uid 
            </if>
        WHERE 1=1
            <if test="channel != null and  channel != 'all' ">
                AND a.uid is not null
            </if>
            <if test="startTime != null and startTime != '' ">
                 AND FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
            </if>
            <if test="endTime != null and endTime != '' ">
                 AND FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d') <![CDATA[ <= ]]> '${endTime}'
            </if>
            <if test="years != null and years != '' ">
                 AND FROM_UNIXTIME(h.`createtime`/1000,'%Y') = '${years}'
            </if>
        <if test="type == 1">
            GROUP BY FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d') 
        </if>
        <if test="type == 2">
             GROUP BY FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m') 
        </if>
        <if test="type == 3">
             GROUP BY FROM_UNIXTIME(h.`createtime`/1000,'%Y') 
        </if>        
        ORDER BY h.`createtime`
    </select>
    
    <select id="getTodayHasOrder" resultType="java.util.HashMap">
        SELECT COALESCE(COUNT(DISTINCT u.`id`),0) AS 'showValue', 
            <if test="type == 1">
                 FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') AS 'showDate'
            </if>
            <if test="type == 2">
                 FROM_UNIXTIME(u.`createtime`/1000,'%m') AS 'showDate'
            </if>
            <if test="type == 3">
                 FROM_UNIXTIME(u.`createtime`/1000,'%Y') AS 'showDate'
            </if>
        
        FROM  yeshi_ec_user u     
        <if test="channel != null and channel != 'all' ">
            LEFT JOIN  (SELECT a.`lua_uid` AS uid FROM `yeshi_ec_log_user_active`  a 
                WHERE a.`lua_channel`='${channel}' GROUP BY a.`lua_uid`) a ON u.`id`=a.uid
        </if>
        LEFT JOIN `yeshi_ec_hongbao_v2` h ON h.`hb_uid`= u.`id`
        WHERE (h.`hb_type`=1 OR h.`hb_type`=20) 
            <if test="channel != null and  channel != 'all' ">
                AND a.uid is not null
            </if>
            <!-- 当日下单 -->
            AND FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') = DATE_FORMAT(h.hb_create_time,'%Y-%m-%d')
            
            <if test="startTime != null and startTime != '' ">
                 AND FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
            </if>
            <if test="endTime != null and endTime != '' ">
                 AND FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') <![CDATA[ <= ]]> '${endTime}'
            </if>
            <if test="years != null and years != '' ">
                 AND FROM_UNIXTIME(u.`createtime`/1000,'%Y') = '${years}'
            </if>
        <if test="type == 1">
            GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') 
        </if>
        <if test="type == 2">
             GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m') 
        </if>
        <if test="type == 3">
             GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y') 
        </if>        
        ORDER BY u.`createtime`
    </select>
    
    
    
    <select id="getWeekHasOrder" resultType="java.util.HashMap">
        SELECT COUNT(DISTINCT hb.uid) AS showValue,FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') AS 'showDate'
        FROM (SELECT COUNT(v2.`hb_id`) AS num,v2.hb_uid  AS uid
              FROM yeshi_ec_hongbao_v2 v2
              WHERE   (v2.`hb_type`=1 OR v2.`hb_type`=20) 
                  AND DATE_FORMAT(v2.`hb_create_time`,'%Y-%m-%d') <![CDATA[ >= ]]>'${startTime}'
                 AND DATE_FORMAT(v2.`hb_create_time`,'%Y-%m-%d') <![CDATA[ <= ]]>'${endTime}'
              GROUP BY v2.hb_uid HAVING num >= ${orderNum})hb
        LEFT JOIN yeshi_ec_user u  ON u.id = hb.uid        
        <if test="channel != null and channel != 'all' ">
            LEFT JOIN  (SELECT a.`lua_uid` AS uid FROM `yeshi_ec_log_user_active`  a 
                WHERE a.`lua_channel`='${channel}' GROUP BY a.`lua_uid`) a ON u.`id`=a.uid
        </if>
        WHERE FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') = '${startTime}'
            <if test="channel != null and  channel != 'all' ">
               AND a.uid is not null
            </if>
            GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') 
        ORDER BY u.`createtime`
    </select>
    
    <select id="getInfoByPhoneOrInviteCode" resultMap="BaseResultMap">
        SELECT * FROM yeshi_ec_user u 
        LEFT JOIN yeshi_ec_user_info_extra uf ON uf.`uie_uid` = u.`id`
        WHERE uf.`uie_invite_code` IS NOT NULL  
              AND (u.`phone` =#{phone} OR uf.`uie_invite_code` = #{inviteCode})
        LIMIT 1
    </select>
 
</mapper>