Air
2024-11-04 a1f06d31b7b4cac569c34bdfbb68de77f2858ffe
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
<?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.nova.sankuai.infra.mapper.VipCardOrderLogMapper">
 
    <select id="getVipStatisticsList" resultType="com.nova.sankuai.domain.vo.VipStatisticsVo">
        select
        ci.id as id,
        ci.code as code,
        ci.name as name,
        ci.app_id as appId,
        sum(if((vcol.clickPayCount=0 and vcol.clickNoPayCount=0), vcol.clickTotalCount,0)) as clickTotalCount,
        sum(if((vcol.clickPayCount=0), vcol.clickNoPayCount,0)) as clickNoPayCount,
        sum(if((vcol.clickPayCount>0), vcol.clickPayCount,0)) as clickPayCount,
        sum(vcol.sumAmount) as sumAmount,
        #{visitDto.startDate} as startDate,
        #{visitDto.endDate} as endDate
        from (select
        sum(IF((status='0'),1,0)) as clickTotalCount,
        sum(IF((status='1'),1,0)) as clickNoPayCount,
        sum(IF((status='2'),1,0)) as clickPayCount,
        sum(IF((status='2'),selling_price,0)) as sumAmount,
        customer_user_id,
        channel_id from vip_card_order_log
        <where>
            vip_type = #{visitDto.vipType}
            <if test="visitDto.startDate != null">
                and creation_date &gt;= #{visitDto.startDate}
            </if>
            <if test="visitDto.endDate != null">
                and creation_date &lt;= #{visitDto.endDate}
            </if>
        </where>
        group by customer_user_id,channel_id) as vcol
        left join channel_info ci on vcol.channel_id = ci.id
        <where>
            1 = 1
            <if test="visitDto.code != null">
                and ci.code = #{visitDto.code}
            </if>
            <if test="visitDto.name != null and visitDto.name !=''">
                and ci.name like concat('%',#{visitDto.name},'%')
            </if>
        </where>
        group by vcol.channel_id
    </select>
 
    <select id="getNoOrderDetail" resultType="com.nova.sankuai.domain.vo.VipStatisticsDetailVo">
        select
        vl.customer_user_id as customerUserId,
        cu.phone as phone,
        cu.name as customerName,
        vl.creation_date as creationDate,
        vl.selling_price as sellingPrice,
        vl.marked_price as markedPrice
        from vip_card_order_log vl
        -- 根据日志筛选用户对应的状态
        inner join ( select
        sum(IF((status='0'),1,0)) as clickTotalCount,
        sum(IF((status='1'),1,0)) as clickNoPayCount,
        sum(IF((status='2'),1,0)) as clickPayCount,
        customer_user_id, channel_id from vip_card_order_log
        <where>
            channel_id = #{detailDto.channelId} and vip_type = #{detailDto.vipType}
            <if test="detailDto.startDate != null">
                and creation_date &gt;= #{detailDto.startDate}
            </if>
            <if test="detailDto.endDate != null">
                and creation_date &lt;= #{detailDto.endDate}
            </if>
        </where>
        group by customer_user_id,channel_id) as tmp
        on vl.customer_user_id = tmp.customer_user_id and vl.channel_id = tmp.channel_id
        left join customer_user cu on vl.customer_user_id = cu.id
        <where>
            vl.status = 0 and tmp.clickNoPayCount = 0 and tmp.clickPayCount = 0
            and vl.vip_type = #{detailDto.vipType}
            <if test="detailDto.startDate != null">
                and vl.creation_date &gt;= #{detailDto.startDate}
            </if>
            <if test="detailDto.endDate != null">
                and vl.creation_date &lt;= #{detailDto.endDate}
            </if>
            <if test="detailDto.customerName != null and detailDto.customerName !=''">
                and cu.name like concat('%',#{detailDto.customerName},'%')
            </if>
            <if test="detailDto.phone != null and detailDto.phone !=''">
                and cu.phone like concat('%',#{detailDto.phone},'%')
            </if>
        </where>
    </select>
 
    <select id="getOrderedDetail" resultType="com.nova.sankuai.domain.vo.VipStatisticsDetailVo">
        select
        vl.customer_user_id as customerUserId,
        cu.phone as phone,
        cu.name as customerName,
        vl.creation_date as creationDate,
        vl.selling_price as sellingPrice,
        vl.marked_price as markedPrice
        from vip_card_order_log vl
        -- 根据日志筛选用户对应的状态
        inner join ( select
        sum(IF((status='0'),1,0)) as clickTotalCount,
        sum(IF((status='1'),1,0)) as clickNoPayCount,
        sum(IF((status='2'),1,0)) as clickPayCount,
        customer_user_id, channel_id from vip_card_order_log
        <where>
            channel_id = #{detailDto.channelId} and vip_type = #{detailDto.vipType}
            <if test="detailDto.startDate != null">
                and creation_date &gt;= #{detailDto.startDate}
            </if>
            <if test="detailDto.endDate != null">
                and creation_date &lt;= #{detailDto.endDate}
            </if>
        </where>
        group by customer_user_id,channel_id) as tmp
        on vl.customer_user_id = tmp.customer_user_id and vl.channel_id = tmp.channel_id
        left join customer_user cu on vl.customer_user_id = cu.id
        <where>
            vl.status = 1 and tmp.clickNoPayCount > 0 and tmp.clickPayCount = 0
            and vl.vip_type = #{detailDto.vipType}
            <if test="detailDto.startDate != null">
                and vl.creation_date &gt;= #{detailDto.startDate}
            </if>
            <if test="detailDto.endDate != null">
                and vl.creation_date &lt;= #{detailDto.endDate}
            </if>
            <if test="detailDto.customerName != null and detailDto.customerName !=''">
                and cu.name like concat('%',#{detailDto.customerName},'%')
            </if>
            <if test="detailDto.phone != null and detailDto.phone !=''">
                and cu.phone like concat('%',#{detailDto.phone},'%')
            </if>
        </where>
    </select>
 
    <select id="getVipSuccessDetail" resultType="com.nova.sankuai.domain.vo.VipStatisticsDetailVo">
        select
        vl.customer_user_id as customerUserId,
        cu.phone as phone,
        cu.name as customerName,
        vl.creation_date as creationDate,
        vl.selling_price as sellingPrice,
        vl.marked_price as markedPrice
        from vip_card_order_log vl
        -- 根据日志筛选用户对应的状态
        inner join ( select
        sum(IF((status='0'),1,0)) as clickTotalCount,
        sum(IF((status='1'),1,0)) as clickNoPayCount,
        sum(IF((status='2'),1,0)) as clickPayCount,
        customer_user_id, channel_id from vip_card_order_log
        <where>
            channel_id = #{detailDto.channelId}
            and vip_type = #{detailDto.vipType}
            <if test="detailDto.startDate != null">
                and creation_date &gt;= #{detailDto.startDate}
            </if>
            <if test="detailDto.endDate != null">
                and creation_date &lt;= #{detailDto.endDate}
            </if>
        </where>
        group by customer_user_id,channel_id) as tmp
        on vl.customer_user_id = tmp.customer_user_id and vl.channel_id = tmp.channel_id
        left join customer_user cu on vl.customer_user_id = cu.id
        <where>
            vl.status = 2 and tmp.clickPayCount > 0 and vl.vip_type = #{detailDto.vipType}
            <if test="detailDto.startDate != null">
                and vl.creation_date &gt;= #{detailDto.startDate}
            </if>
            <if test="detailDto.endDate != null">
                and vl.creation_date &lt;= #{detailDto.endDate}
            </if>
            <if test="detailDto.customerName != null and detailDto.customerName !=''">
                and cu.name like concat('%',#{detailDto.customerName},'%')
            </if>
            <if test="detailDto.phone != null and detailDto.phone !=''">
                and cu.phone like concat('%',#{detailDto.phone},'%')
            </if>
        </where>
    </select>
</mapper>