yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
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
<?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.hongbao.HongBaoMapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.HongBao">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="auctionId" property="auctionId" jdbcType="BIGINT" />
        <result column="payMoney" property="payMoney" jdbcType="DECIMAL" />
        <result column="money" property="money" jdbcType="DECIMAL" />
        <result column="param" property="param" jdbcType="VARCHAR" />
        <result column="type" property="type" jdbcType="INTEGER" />
        <result column="state" property="state" jdbcType="INTEGER" />
        <result column="createtime" property="createtime" jdbcType="BIGINT" />
        <result column="pre_get_time" property="preGettime" jdbcType="BIGINT" />
        <result column="get_time" property="getTime" jdbcType="BIGINT" />
        <result column="get_ip" property="getIp" jdbcType="VARCHAR" />
        <result column="beizhu" property="beizhu" jdbcType="VARCHAR" />
        <result column="order_id" property="orderId" jdbcType="VARCHAR" />
        <result column="order_item_id" property="orderItemId" jdbcType="BIGINT" />
        <result column="urank" property="urank" jdbcType="INTEGER" />
        <result column="hasChild" property="hasChild" jdbcType="BOOLEAN" />
        <result column="version" property="version" jdbcType="INTEGER" />
        <result column="balance_time" property="balanceTime" jdbcType="TIMESTAMP" />
        <association property="userInfo" column="uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="uid" property="id" jdbcType="BIGINT" />
        </association>
        <association property="parent" column="pid"
            javaType="com.yeshi.fanli.entity.bus.user.HongBao">
            <id column="pid" property="id" jdbcType="BIGINT" />
        </association>
        <association property="order" column="oid"
            select="com.yeshi.fanli.dao.mybatis.order.OrderMapper.selectByPrimaryKey">
        </association>
 
    </resultMap>
 
    <resultMap id="ResultMap" type="com.yeshi.fanli.entity.bus.user.HongBao">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="auctionId" property="auctionId" jdbcType="BIGINT" />
        <result column="payMoney" property="payMoney" jdbcType="DECIMAL" />
        <result column="money" property="money" jdbcType="DECIMAL" />
        <result column="param" property="param" jdbcType="VARCHAR" />
        <result column="type" property="type" jdbcType="INTEGER" />
        <result column="state" property="state" jdbcType="INTEGER" />
        <result column="createtime" property="createtime" jdbcType="BIGINT" />
        <result column="pre_get_time" property="preGettime" jdbcType="BIGINT" />
        <result column="get_time" property="getTime" jdbcType="BIGINT" />
        <result column="get_ip" property="getIp" jdbcType="VARCHAR" />
        <result column="beizhu" property="beizhu" jdbcType="VARCHAR" />
        <result column="order_id" property="orderId" jdbcType="VARCHAR" />
        <result column="order_item_id" property="orderItemId" jdbcType="BIGINT" />
        <result column="urank" property="urank" jdbcType="INTEGER" />
        <result column="hasChild" property="hasChild" jdbcType="BOOLEAN" />
        <result column="version" property="version" jdbcType="INTEGER" />
        <result column="balance_time" property="balanceTime" jdbcType="TIMESTAMP" />
        <result column="ShareAndInviteMoney" property="ShareAndInviteMoney"
            jdbcType="DECIMAL" />
 
        <association property="userInfo" column="uid"
            select="com.yeshi.fanli.dao.mybatis.UserInfoMapper.selectByPrimaryKey">
        </association>
 
        <association property="parent" column="pid"
            javaType="com.yeshi.fanli.entity.bus.user.HongBao">
            <id column="pid" property="id" jdbcType="BIGINT" />
        </association>
 
    </resultMap>
 
    <sql id="Base_Column_List">id,uid,auctionId,payMoney,pid,money,param,type,state,createtime,pre_get_time,get_time,get_ip,beizhu,order_id,order_item_id,oid,urank,hasChild,version,balance_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where id = #{id,jdbcType=BIGINT}
    </select>
 
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where id = #{id,jdbcType=BIGINT} for update
    </select>
 
 
    <select id="selectByUid" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where uid = #{0}
    </select>
 
 
    <select id="selectByUidAndType" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where uid = #{uid} and type=#{type}
    </select>
 
 
 
 
 
    <select id="selectByOrderId" resultMap="BaseResultMap"
        parameterType="java.lang.String">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where order_id = #{0}
    </select>
 
 
    <select id="selectByOrderIdWithoutChild" resultMap="BaseResultMap"
        parameterType="java.lang.String">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where order_id = #{0} and pid is null
    </select>
 
 
    <select id="selectChildHongBaoByPid" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where pid = #{0}
    </select>
 
 
 
 
 
    <select id="selectCanBalanceHongBaoCountByType" resultType="java.lang.Long"
        parameterType="java.lang.Integer">
        select
        count(*)
        from yeshi_ec_hongbao where `version`=2
        and type = #{type} and
        (state=1 or state=2) AND pre_get_time IS NOT
        NULL and
        pre_get_time&gt;0 and unix_timestamp()*1000&gt;=pre_get_time
    </select>
 
 
 
    <select id="selectCanBalanceHongBaoByType" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where `version`=2 and type = #{type} and
        (state=1 or state=2) AND pre_get_time IS NOT NULL and
        pre_get_time&gt;0 and unix_timestamp()*1000&gt;=pre_get_time limit
        #{count}
    </select>
 
 
    <select id="selectCanBalanceHongBaoByTypeAndUid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where uid=#{uid} and `version`=2 and type =
        #{type} and
        (state=1 or state=2) AND pre_get_time IS NOT NULL and
        pre_get_time&gt;0 and unix_timestamp()*1000&gt;=pre_get_time limit
        #{count}
    </select>
 
    <select id="selectCanBalanceHongBaoByChildHongBao" resultMap="BaseResultMap"
        parameterType="java.lang.Integer">select h.* from yeshi_ec_hongbao h right join (select
        distinct( `pid`) as pid from yeshi_ec_hongbao where (`type`=6 or
        `type`=7) and `version`=2 and (state=1 or state=2) and pre_get_time is
        not null and pre_get_time&gt;0 and
        unix_timestamp()*1000&gt;=pre_get_time limit #{0} ) s on s.pid=h.`id`
    </select>
 
 
    <select id="selectCanBalanceHongBaoByChildHongBaoAndUid"
        resultMap="BaseResultMap" parameterType="java.lang.Long">
        SELECT * FROM yeshi_ec_hongbao
        WHERE uid=#{0} and
        (`type`=6 OR
        `type`=7)
        AND `version`=2 AND (state=1 OR
        state=2) AND
        pre_get_time IS
        NOT NULL
        AND pre_get_time>0 AND
        UNIX_TIMESTAMP()*1000>=pre_get_time
    </select>
 
 
 
 
    <select id="selectUidCanBalanceHongBaoByChildHongBao"
        resultType="java.lang.Long">
        SELECT DISTINCT( `uid`) FROM yeshi_ec_hongbao WHERE
        (`type`=6 OR
        `type`=7)
        AND `version`=2 AND (state=1 OR state=2) AND
        pre_get_time IS
        NOT NULL
        AND pre_get_time>0 AND
        UNIX_TIMESTAMP()*1000>=pre_get_time
    </select>
 
    <select id="selectByOid" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where oid = #{0}
    </select>
    <select id="selectByOrderIdSortWithAucationIdAndPayMoney"
        resultMap="BaseResultMap" parameterType="java.lang.String">SELECT h. * FROM
        yeshi_ec_hongbao h LEFT JOIN yeshi_ec_order o ON h.`oid` =o.`id` WHERE
        o.`orderid` =#{0} ORDER BY h.`auctionId`, h.payMoney
    </select>
    <select id="selectMultiHongBaoOrder" resultType="java.lang.String">SELECT a.orderid
        FROM (SELECT COUNT(*) c,o.`orderid` AS orderid FROM yeshi_ec_hongbao h
        LEFT JOIN yeshi_ec_order o ON o.`id`=h.`oid` WHERE h.`version`=2 AND
        h.`type`=1 GROUP BY h.`oid` HAVING c&gt;0 ORDER BY h.id DESC) a limit
        10
    </select>
    <select id="findChildHongBaoList" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where pid = #{0}
    </select>
 
 
    <select id="getTotalTiChengMoney" resultType="java.math.BigDecimal"
        parameterType="java.lang.Long">
        SELECT IF(a.money IS NULL,0,a.money ) FROM (SELECT
        SUM(h.`money`) AS money FROM `yeshi_ec_hongbao` h WHERE h.`uid`=#{0}
        AND h.`state`=3 AND (h.`type`=20 OR h.`type`=21 OR h.`type`=22 OR
        h.`type`=6 OR h.`type`=7)) a
    </select>
 
    <select id="getTotalTiChengCount" resultType="java.lang.Integer"
        parameterType="java.lang.Long">
        SELECT
        count(*) FROM `yeshi_ec_hongbao` h
        WHERE
        h.`uid`=#{0} AND (h.`type`=20 OR h.`type`=21 OR h.`type`=22 OR
        h.`type`=6 OR h.`type`=7)
    </select>
 
 
    <select id="getUnGetTiChengMoney" resultType="java.math.BigDecimal"
        parameterType="java.lang.Long">
        SELECT IF(a.money IS NULL,0,a.money ) FROM (SELECT
        SUM(h.`money`) AS money FROM `yeshi_ec_hongbao` h WHERE h.`uid`=#{0}
        AND (h.`state`=1 OR h.state=2 )AND (h.`type`=20 OR h.`type`=21 OR
        h.`type`=22 OR h.`type`=6 OR h.`type`=7)) a
    </select>
 
 
    <select id="selectByIdOrPid" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao where id = #{0} or pid=#{0}
    </select>
 
 
 
 
 
 
 
 
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_hongbao where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.HongBao"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_hongbao
        (id,uid,auctionId,payMoney,pid,money,param,type,state,createtime,pre_get_time,get_time,get_ip,beizhu,order_id,order_item_id,oid,urank,hasChild,version,balance_time)
        values
        (#{id,jdbcType=BIGINT},#{userInfo.id,jdbcType=BIGINT},#{auctionId,jdbcType=BIGINT},#{payMoney,jdbcType=DECIMAL},#{parent.id,jdbcType=BIGINT},#{money,jdbcType=DECIMAL},#{param,jdbcType=VARCHAR},#{type,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{createtime,jdbcType=BIGINT},#{preGettime,jdbcType=BIGINT},#{getTime,jdbcType=BIGINT},#{getIp,jdbcType=VARCHAR},#{beizhu,jdbcType=VARCHAR},#{orderId,jdbcType=VARCHAR},#{orderItemId,jdbcType=BIGINT},#{order.id,jdbcType=BIGINT},#{urank,jdbcType=INTEGER},#{hasChild,jdbcType=BOOLEAN},#{version,jdbcType=INTEGER},#{balanceTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.HongBao"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_hongbao
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userInfo != null">uid,</if>
            <if test="auctionId != null">auctionId,</if>
            <if test="payMoney != null">payMoney,</if>
            <if test="parent != null">pid,</if>
            <if test="money != null">money,</if>
            <if test="param != null">param,</if>
            <if test="type != null">type,</if>
            <if test="state != null">state,</if>
            <if test="createtime != null">createtime,</if>
            <if test="preGettime != null">pre_get_time,</if>
            <if test="getTime != null">get_time,</if>
            <if test="getIp != null">get_ip,</if>
            <if test="beizhu != null">beizhu,</if>
            <if test="orderId != null">order_id,</if>
            <if test="orderItemId != null">order_item_id,</if>
            <if test="order != null">oid,</if>
            <if test="urank != null">urank,</if>
            <if test="hasChild != null">hasChild,</if>
            <if test="version != null">version,</if>
            <if test="balanceTime != null">balance_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="userInfo != null">#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="auctionId != null">#{auctionId,jdbcType=BIGINT},</if>
            <if test="payMoney != null">#{payMoney,jdbcType=DECIMAL},</if>
            <if test="parent != null">#{parent.id,jdbcType=BIGINT},</if>
            <if test="money != null">#{money,jdbcType=DECIMAL},</if>
            <if test="param != null">#{param,jdbcType=VARCHAR},</if>
            <if test="type != null">#{type,jdbcType=INTEGER},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="createtime != null">#{createtime,jdbcType=BIGINT},</if>
            <if test="preGettime != null">#{preGettime,jdbcType=BIGINT},</if>
            <if test="getTime != null">#{getTime,jdbcType=BIGINT},</if>
            <if test="getIp != null">#{getIp,jdbcType=VARCHAR},</if>
            <if test="beizhu != null">#{beizhu,jdbcType=VARCHAR},</if>
            <if test="orderId != null">#{orderId,jdbcType=VARCHAR},</if>
            <if test="orderItemId != null">#{orderItemId,jdbcType=BIGINT},</if>
            <if test="order != null">#{order.id,jdbcType=BIGINT},</if>
            <if test="urank != null">#{urank,jdbcType=INTEGER},</if>
            <if test="hasChild != null">#{hasChild,jdbcType=BOOLEAN},</if>
            <if test="version != null">#{version,jdbcType=INTEGER},</if>
            <if test="balanceTime != null">#{balanceTime,jdbcType=TIMESTAMP}</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.user.HongBao">update
        yeshi_ec_hongbao set uid = #{userInfo.id,jdbcType=BIGINT},auctionId =
        #{auctionId,jdbcType=BIGINT},payMoney =
        #{payMoney,jdbcType=DECIMAL},pid = #{parent.id,jdbcType=BIGINT},money
        = #{money,jdbcType=DECIMAL},param = #{param,jdbcType=VARCHAR},type =
        #{type,jdbcType=INTEGER},state = #{state,jdbcType=INTEGER},createtime
        = #{createtime,jdbcType=BIGINT},pre_get_time =
        #{preGettime,jdbcType=BIGINT},get_time =
        #{getTime,jdbcType=BIGINT},get_ip = #{getIp,jdbcType=VARCHAR},beizhu =
        #{beizhu,jdbcType=VARCHAR},order_id =
        #{orderId,jdbcType=VARCHAR},order_item_id =
        #{orderItemId,jdbcType=BIGINT},oid = #{order.id,jdbcType=BIGINT},urank
        = #{urank,jdbcType=INTEGER},hasChild =
        #{hasChild,jdbcType=BOOLEAN},version = #{version,jdbcType=INTEGER}
        ,balance_time =#{balanceTime,jdbcType=TIMESTAMP} where id =
        #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.HongBao">
        update yeshi_ec_hongbao
        <set>
            <if test="userInfo != null">uid=#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="auctionId != null">auctionId=#{auctionId,jdbcType=BIGINT},</if>
            <if test="payMoney != null">payMoney=#{payMoney,jdbcType=DECIMAL},</if>
            <if test="parent != null">pid=#{parent.id,jdbcType=BIGINT},</if>
            <if test="money != null">money=#{money,jdbcType=DECIMAL},</if>
            <if test="param != null">param=#{param,jdbcType=VARCHAR},</if>
            <if test="type != null">type=#{type,jdbcType=INTEGER},</if>
            <if test="state != null">state=#{state,jdbcType=INTEGER},</if>
            <if test="createtime != null">createtime=#{createtime,jdbcType=BIGINT},</if>
            <if test="preGettime != null">pre_get_time=#{preGettime,jdbcType=BIGINT},</if>
            <if test="getTime != null">get_time=#{getTime,jdbcType=BIGINT},</if>
            <if test="getIp != null">get_ip=#{getIp,jdbcType=VARCHAR},</if>
            <if test="beizhu != null">beizhu=#{beizhu,jdbcType=VARCHAR},</if>
            <if test="orderId != null">order_id=#{orderId,jdbcType=VARCHAR},</if>
            <if test="orderItemId != null">order_item_id=#{orderItemId,jdbcType=BIGINT},</if>
            <if test="order != null">oid=#{order.id,jdbcType=BIGINT},</if>
            <if test="urank != null">urank=#{urank,jdbcType=INTEGER},</if>
            <if test="hasChild != null">hasChild=#{hasChild,jdbcType=BOOLEAN},</if>
            <if test="version != null">version=#{version,jdbcType=INTEGER},</if>
            <if test="balanceTime !=null">balance_time =#{balanceTime,jdbcType=TIMESTAMP},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
 
    <select id="getCountOrder" resultType="java.lang.Long">
        SELECT count(id) FROM `yeshi_ec_hongbao`
        WHERE 1>0 and type NOT IN
        (3,4) AND uid =#{uid}
 
        <if test="createtime != null and createtime !=''">
               <![CDATA[ AND createtime <= '${createtime}' ]]>
        </if>
    </select>
 
    <select id="getCountCancelOrder" resultType="java.lang.Long">
        <!-- 用户的维权订单 -->
        SELECT count(id) FROM `yeshi_ec_hongbao` h
        WHERE h.`state` = 4 AND uid
        =#{uid}
        and (h.balance_time IS NOT NULL OR h.balance_time > 0 )
        <if test="createtime != null and createtime !='' ">
               <![CDATA[ AND createtime <= '${createtime}' ]]>
        </if>
    </select>
 
    <select id="selectOrderByUid" resultMap="BaseResultMap">
        SELECT * FROM `yeshi_ec_hongbao` WHERE uid =${uid}
        <if test="startTime != null and startTime !='' ">
                   <![CDATA[ AND FROM_UNIXTIME(get_time/1000) >= '${startTime}' ]]>
        </if>
        <if test="endTime != null and endTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(get_time/1000) <= '${endTime}'  ]]>
        </if>
        ORDER BY createtime DESC LIMIT #{start},#{count}
    </select>
 
    <select id="countOrderByUid" resultType="java.lang.Integer">
        SELECT COALESCE(count(id),0) FROM `yeshi_ec_hongbao` WHERE uid =${uid}
        <if test="startTime != null  and startTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(get_time/1000) >= '${startTime}' ]]>
        </if>
        <if test="endTime != null and endTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(get_time/1000) <= '${endTime}'  ]]>
        </if>
    </select>
 
    <select id="countProfitByUid" resultType="java.lang.Double">
        SELECT COALESCE(SUM(money),0) FROM `yeshi_ec_hongbao` WHERE uid
        =${uid} AND state = 3
        <if test="startTime != null and startTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(get_time/1000) >= '${startTime}' ]]>
        </if>
        <if test="endTime != null and endTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(get_time/1000) <= '${endTime}'  ]]>
        </if>
    </select>
 
 
 
 
    <select id="getCountCancelByUid" resultType="java.lang.Integer">
        SELECT
        COALESCE(count(id),0) FROM `yeshi_ec_hongbao`
        WHERE uid =#{uid} and
        state = 4
    </select>
 
 
    <select id="getCountByUid" resultType="java.lang.Integer">
        SELECT
        COALESCE(count(id),0) FROM `yeshi_ec_hongbao`
        WHERE uid =#{uid}
    </select>
 
 
    <select id="getCountByUidAndState" resultType="java.lang.Integer">
        SELECT
        COALESCE(count(id),0) FROM `yeshi_ec_hongbao`
        WHERE uid =#{uid} and
        state=#{state}
    </select>
 
    <select id="getCountByUidOrder" resultType="java.lang.Long">
        SELECT
        IFNULL(SUM(num) , 0)AS totalNum FROM (SELECT COUNT(id) AS num FROM
        `yeshi_ec_hongbao` h
        WHERE uid =#{uid} AND order_id IS NOT NULL GROUP
        BY h.order_id )A;
    </select>
 
    <!-- 统计已领取金额 账户历史总收益 -->
    <select id="countReceiveMoneysByUid" resultType="java.lang.Double">
        SELECT
        COALESCE(SUM(money),0) FROM `yeshi_ec_hongbao` WHERE state = 3 AND uid
        = ${uid};
    </select>
 
    <!-- 统计未领取金额 待入账收益 -->
    <select id="countForecastMoneysByUid" resultType="java.lang.Double">
        SELECT
        COALESCE(SUM(money),0) FROM `yeshi_ec_hongbao` WHERE state in (1,2)
        AND uid = #{uid};
    </select>
 
 
    <select id="queryByOrderIDAndPayMoney" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM `yeshi_ec_hongbao` h
        WHERE h.`order_id` =#{oid} AND h.`payMoney`=
        #{payMoney}
    </select>
 
    <select id="queryByOrderIDAndUid" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM `yeshi_ec_hongbao` h
        WHERE h.`order_id` =#{oid} AND h.`uid`=
        #{uid}
    </select>
 
 
    <select id="countByUidSelf" resultType="java.lang.Long">
        <!-- 自购订单 -->
        SELECT COALESCE(count(id),0) FROM `yeshi_ec_hongbao` hb
        WHERE uid
        =#{uid} and type in (1,2)  <![CDATA[AND hb.state <>4]]>
        <if test="isToday != null and isToday == 1">
            AND TO_DAYS(FROM_UNIXTIME(hb.`createtime`/1000)) =
            TO_DAYS(NOW())
        </if>
        <if test="isMonth != null and isMonth == 1">
            AND DATE_FORMAT( FROM_UNIXTIME(hb.`createtime`/1000),
            '%Y%m' ) =
            DATE_FORMAT( CURDATE( ) , '%Y%m' )
        </if>
    </select>
 
 
    <select id="getLastOrderTime" resultType="java.lang.Long">
        <!-- 最近一次下单时间 -->
        SELECT h.`createtime` FROM yeshi_ec_hongbao h WHERE h.`type` IN(1,2) 
           <![CDATA[AND h.state <>4]]>
        AND h.`uid` = #{uid,jdbcType=BIGINT}
        ORDER BY h.`createtime` DESC LIMIT
        1;
    </select>
 
 
    <select id="getMaxMoney" resultType="java.lang.Double">
        <!--查询前3天返利金额总额最高值 -->
        SELECT SUM(h.`money`)AS totalMoney FROM `yeshi_ec_hongbao` h
        WHERE <![CDATA[TO_DAYS(NOW()) - TO_DAYS(FROM_UNIXTIME(h.`createtime`/1000)) <= 3]]>
 
        <!-- DATE_FORMAT(FROM_UNIXTIME(h.`createtime`/1000), '%Y%m' ) = DATE_FORMAT(CURDATE() 
            , '%Y%m' ) -->
        
        <![CDATA[AND h.state <>4]]>
 
        AND h.`type` IN
        <foreach collection="typeArray" item="item" index="index"
            open="(" close=")" separator=",">
            #{item}
        </foreach>
 
        GROUP BY h.uid
        ORDER BY totalMoney DESC LIMIT 0,1
    </select>
 
 
 
    <select id="listShareAndInviteMoney" resultMap="ResultMap">
        SELECT IFNULL(SUM(h.`money`),0) as ShareAndInviteMoney,
        <include refid="Base_Column_List" />
        FROM `yeshi_ec_hongbao` h
        WHERE
        DATE_FORMAT(FROM_UNIXTIME(h.`createtime`/1000), '%Y-%m-%d' )= #{date}
        <![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="selectCountByTypeAndStateAndCreateTime" resultType="java.lang.Long">
        SELECT COUNT(h.`id`) FROM yeshi_ec_hongbao h WHERE uid=#{uid}
        <foreach collection="type" item="itemType" open="and ("
            separator=" or " close=")">
            h.`type`=#{itemType}
        </foreach>
 
 
        <foreach collection="state" item="itemState" open="and ("
            separator=" or " close=")">
            h.`state`=#{itemState}
        </foreach>
 
        AND FROM_UNIXTIME( h.`createtime`/1000)>=#{minTime} AND FROM_UNIXTIME(
        h.`createtime`/1000)
        <![CDATA[
        <
        ]]>
        #{maxTime};
    </select>
 
    <select id="count24HOderByChannel" resultType="java.util.HashMap">
        SELECT COALESCE(SUM(b.money*2),0) AS 'commision',
        COALESCE(COUNT(b.id),0) AS'countOrder',
        COALESCE(SUM(b.payMoney),0) AS 'payMoney',
        <if test="type == 1">
            FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') AS 'createDate'
        </if>
        <if test="type == 2">
            FROM_UNIXTIME(u.`createtime`/1000,'%m') AS 'createDate'
        </if>
        <if test="type == 3">
            FROM_UNIXTIME(u.`createtime`/1000,'%Y') AS 'createDate'
        </if>
        FROM
        (
        SELECT h.* FROM yeshi_ec_hongbao h
        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 a.uid=h.`uid` WHERE a.uid IS NOT NULL AND (h.`type`=1 OR h.`type`=20)
        ) b
        LEFT JOIN yeshi_ec_user u ON u.`id`=b.uid
        WHERE <![CDATA[b.createtime<u.`createtime`+1000*60*60*24 ]]>
        <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="countHistoryOderByChannel" resultType="java.util.HashMap">
 
        SELECT COALESCE(SUM(h.`money`)*2,0) AS 'commision',
        COALESCE(COUNT(h.id),0) AS 'countOrder',
        COALESCE(SUM(h.payMoney),0) AS 'payMoney',
        <if test="type == 1">
            FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d') AS 'createDate'
        </if>
        <if test="type == 2">
            FROM_UNIXTIME(h.`createtime`/1000,'%m') AS 'createDate'
        </if>
        <if test="type == 3">
            FROM_UNIXTIME(h.`createtime`/1000,'%Y') AS 'createDate'
        </if>
        FROM yeshi_ec_hongbao h
        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.`uid`=a.uid
        WHERE (h.`type`=1 OR h.`type`=20) AND a.uid IS NOT NULL
        <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>
 
 
</mapper>