Pu Zhibing
2025-09-26 47b901938213f609fc378d1e7666a516ff7c7ccf
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
<?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.ruoyi.goods.mapper.lottery.LotteryEventMapper">
 
 
    <select id="pageAppLotteryEvent" resultType="com.ruoyi.goods.domain.vo.AppLotteryEventPageVo">
        select *
        from (select a.id,
                     a.name,
                     a.activity_profile                             as activityProfile,
                     a.activity_type                                as activityType,
                     date_format(a.start_time, '%Y-%m-%d %H:%i:%s') as startTime,
                     date_format(a.end_time, '%Y-%m-%d %H:%i:%s')   as endTime,
                     a.cover_image                                  as coverImage,
                     if(ifnull(b.num, 0) = 0, false, true)          as participation,
                     CASE
                        WHEN NOW() > a.start_time and now() &lt;= a.end_time and ifnull(b.num, 0) = 0 THEN 1
                        WHEN NOW() > a.start_time and now() &lt;= a.end_time and ifnull(b.num, 0) > 0 THEN 2
                        WHEN NOW() &lt; a.start_time THEN 3
                        ELSE 4 END as sort
              from t_lottery_event a
              left join (
              select count(1) as num, lottery_event_id
              from t_user_lottery_event where user_id = #{userId} group by lottery_event_id
              ) b on a.id = b.lottery_event_id
              where a.del_flag = 0 and now() &lt; a.end_time and a.shop_id is null and (a.activity_type in (4, 5) or (a.activity_type in (1, 3) and id in (select lottery_event_id from t_lottery_event_user where user_id = #{userId})))
              ) as aa
        order by aa.sort, aa.startTime
    </select>
 
 
    <select id="getShopLotteryDrawList" resultType="com.ruoyi.goods.domain.vo.ShopLotteryDrawListVo">
        select id,
               `name`,
               activity_profile                          as activityProfile,
               cover_image                               as coverImage,
               DATE_FORMAT(start_time, '%Y-%m-%d %H:%i') as startTime,
               DATE_FORMAT(end_time, '%Y-%m-%d %H:%i')   as endTime,
               wx_mini_program_qr_code                   as wxMiniProgramQrCode
        from t_lottery_event
        where del_flag = 0 and shop_id = #{shopId}
        order by create_time desc
    </select>
    <select id="pageMgtLotteryEvent" resultType="com.ruoyi.goods.domain.vo.MgtLotteryEventPageVo">
        SELECT
        id,
        shop_id,
        name,
        activity_type,
        CONCAT(start_time,'-',end_time) activityTime,
        create_time,
        CASE
        WHEN NOW() &lt; start_time THEN 1 -- 未开始
        WHEN NOW() BETWEEN start_time AND end_time THEN 2 -- 进行中
        ELSE 3 -- 已结束
        END AS `status`,
        CASE
        WHEN NOW() BETWEEN start_time AND end_time THEN 1
        ELSE 0
        END AS flag
        FROM
        t_lottery_event
        where
        del_flag =0
        <choose>
            <when test="dto.status != null and dto.status == 0">
                -- 0-全部状态,不添加额外条件
            </when>
            <when test="dto.status != null and dto.status == 1">
                AND start_time &gt; NOW() -- 1-未开始
            </when>
            <when test="dto.status != null and dto.status == 2">
                AND start_time &lt;= NOW() AND end_time &gt;= NOW() -- 2-进行中
            </when>
            <when test="dto.status != null and dto.status == 3">
                AND end_time &lt; NOW() -- 3-已结束
            </when>
        </choose>
        <if test="null != dto.name and ''!= dto.name ">
            and `name` like concat('%',#{dto.name},'%')
        </if>
        <if test="null != dto.activityType and  dto.activityType!=0 and  dto.activityType!=6  ">
            and activity_type = #{dto.activityType}
        </if>
        <if test="dto.shopIds != null and dto.shopIds.size() > 0">
            <choose>
                <when test="dto.flag != null and dto.flag == 1">
                    AND (shop_id IN
                    <foreach collection="dto.shopIds" item="shopId" open="(" separator="," close=")">
                        #{shopId}
                    </foreach>
                    OR shop_id IS NULL)
                </when>
                <otherwise>
                    AND shop_id IN
                    <foreach collection="dto.shopIds" item="shopId" open="(" separator="," close=")">
                        #{shopId}
                    </foreach>
                </otherwise>
            </choose>
        </if>
        order by create_time desc
        limit #{dto.offset},#{dto.pageSize}
    </select>
    <select id="pageMgtLotteryEventCount" resultType="java.lang.Long">
        SELECT
        count(*)
        FROM
        t_lottery_event
        where
        del_flag =0
        <choose>
            <when test="dto.status != null and dto.status == 0">
                -- 0-全部状态,不添加额外条件
            </when>
            <when test="dto.status != null and dto.status == 1">
                AND start_time &gt; NOW() -- 1-未开始
            </when>
            <when test="dto.status != null and dto.status == 2">
                AND start_time &lt;= NOW() AND end_time &gt;= NOW() -- 2-进行中
            </when>
            <when test="dto.status != null and dto.status == 3">
                AND end_time &lt; NOW() -- 3-已结束
            </when>
        </choose>
        <if test="null != dto.name and ''!= dto.name ">
            and `name` like concat('%',#{dto.name},'%')
        </if>
        <if test="null != dto.activityType and  dto.activityType!=0 ">
            and activity_type = #{dto.activityType}
        </if>
        <if test="dto.shopIds != null and dto.shopIds.size() > 0">
            <choose>
                <when test="dto.flag != null and dto.flag == 1">
                    AND (shop_id IN
                    <foreach collection="dto.shopIds" item="shopId" open="(" separator="," close=")">
                        #{shopId}
                    </foreach>
                    OR shop_id IS NULL)
                </when>
                <otherwise>
                    AND shop_id IN
                    <foreach collection="dto.shopIds" item="shopId" open="(" separator="," close=")">
                        #{shopId}
                    </foreach>
                </otherwise>
            </choose>
        </if>
    </select>
</mapper>