admin
2019-01-08 c84d8ecd97d111b01db9cfd807300d0491a95bc8
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
<?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.HongBaoV2CountMapper">
 
    <sql id="Column_DateType">
        <if test="dateType == 1">
            DATE_FORMAT(t.`hb_create_time`,'%Y-%m-%d') AS 'showDate'
        </if>
        <if test="dateType == 2">
            DATE_FORMAT(t.`hb_create_time`,'%m') AS 'showDate'
        </if>
        <if test="dateType == 3">
            DATE_FORMAT(t.`hb_create_time`,'%Y') AS 'showDate'
        </if>
    </sql>
 
    <sql id="Count_Select_DateType">
        <if test="startTime != null and startTime != '' ">
            AND DATE_FORMAT(t.`hb_create_time`,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
        </if>
        <if test="endTime != null and endTime != '' ">
            AND DATE_FORMAT(t.`hb_create_time`,'%Y-%m-%d') <![CDATA[ <= ]]>'${endTime}'
        </if>
        <if test="year != null and year != '' ">
            AND DATE_FORMAT(t.`hb_create_time`,'%Y') = '${year}'
        </if>
    </sql>
 
    <sql id="Count_Group_DateType">
        <if test="dateType == 1">
            GROUP BY DATE_FORMAT(t.`hb_create_time`,'%Y-%m-%d')
        </if>
        <if test="dateType == 2">
            GROUP BY DATE_FORMAT(t.`hb_create_time`,'%Y-%m')
        </if>
        <if test="dateType == 3">
            GROUP BY DATE_FORMAT(t.`hb_create_time`,'%Y')
        </if>
    </sql>
    <sql id="Count_Select_State">
        <if test="state != null and state == 1">  <!-- 未到账 -->
            AND (th.hb_state = 1 or th.hb_state = 2)
        </if>
        <if test="state != null and state == 2"> <!-- 已到账 -->
            AND th.hb_state = 3
        </if>
        <if test="state != null and state == 3">  <!-- 红包已失效 -->
            AND th.hb_state =4
        </if>
    </sql>
    <select id="countHongBaoMoney" resultType="java.util.HashMap">
        SELECT CAST(SUM(t.`hb_money`)AS DECIMAL(19,2)) AS total,<include refid="Column_DateType"/>
        FROM yeshi_ec_hongbao_v2 t
        <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 t.`hb_uid`=a.uid 
        </if>
        WHERE t.`hb_uid` IS NOT NULL AND (t.`hb_type`=1 OR t.`hb_type`=20) <include refid="Count_Select_DateType"/> 
            <include refid="Count_Select_State"/>
        <include refid="Count_Group_DateType"/>
        ORDER BY t.`hb_create_time`
    </select>
    
    <select id="countHongBaoNum" resultType="java.util.HashMap">
        SELECT COUNT(t.`hb_id`)AS total,<include refid="Column_DateType"/>
        FROM yeshi_ec_hongbao_v2 t 
        <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 t.`hb_uid`=a.uid 
        </if>
        WHERE t.`hb_uid` IS NOT NULL AND (t.`hb_type`=1 OR h.`hb_type`=20) <include refid="Count_Select_DateType"/> 
            <include refid="Count_Select_State"/>
        <include refid="Count_Group_DateType"/>
        ORDER BY t.`hb_create_time`
    </select>
    
 
</mapper>