add
yj
2024-12-05 b9900893177c78fc559223521fe839aa21000017
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
<?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.iotechn.unimall.data.mapper.CouponMapper">
 
    <update id="decCoupon">
        update unimall_coupon set surplus = surplus - 1 where id = #{couponId}
    </update>
 
    <select id="getUserCouponsCount" resultType="com.dobbinsoft.fw.support.model.KVModel">
        SELECT
            coupon_id AS `key`,
            count( coupon_id ) AS `value`
        FROM
            unimall_coupon_user
        WHERE
            coupon_id IN
        <foreach open="(" close=")" collection="couponIds" separator="," item="cid">
            #{cid}
        </foreach>
            AND user_id = #{userId}
        GROUP BY
            coupon_id;
    </select>
 
 
    <select id="getAdminCouponList" resultType="com.iotechn.unimall.data.dto.CouponAdminDTO">
        SELECT
          c.id AS id,
          c.title AS title,
          c.`type` AS `type`,
          c.is_vip AS isVip,
          c.description AS description,
          c.total AS total,
          c.surplus AS surplus,
          c.`limit` AS `limit`,
          c.discount AS discount,
          c.min AS min,
          c.status AS status,
          g.title as categoryTitle,
          c.category_id as categoryId,
          c.days AS days,
          c.gmt_start as gmtStart,
          c.gmt_end as gmtEnd
        FROM
          unimall_coupon c
        LEFT JOIN unimall_category g on c.category_id = g.id
        <where>
            <if test="title != null">
                AND c.title like concat("%",#{title},"%")
            </if>
            <if test="type != null">
                AND c.type = #{type}
            </if>
            <if test="status != null">
                <if test="status >= 0">
                    AND c.status = #{status} AND (unix_timestamp(c.gmt_end) &gt; unix_timestamp(#{now}) or c.days is not null)
                </if>
                <if test="status &lt; 0">
                    AND unix_timestamp(c.gmt_end) &lt; unix_timestamp(#{now})
                </if>
            </if>
        </where>
        ORDER BY c.id DESC
    </select>
 
    <select id="getActiveCoupons" resultType="com.iotechn.unimall.data.dto.CouponDTO">
        SELECT
            c.id,
            c.title,
            c.type,
            c.description,
            c.total,
            c.surplus,
            c.`limit`,
            c.discount,
            c.`min`,
            c.`status`,
            c.is_vip AS isVip,
            c.category_id AS categoryId,
            c.days,
            c.gmt_start AS gmtStart,
            c.gmt_end AS gmtEnd,
            c.gmt_update AS gmtUpdate,
            c.gmt_create AS gmtCreate,
            y.title AS categoryTitle
        FROM
            unimall_coupon AS c
        LEFT JOIN unimall_category AS y ON y.id = c.category_id
        WHERE
            c.`status` = 1
            AND (c.gmt_end IS NULL OR ( unix_timestamp(c.gmt_start) &lt; unix_timestamp(now( )) AND unix_timestamp(c.gmt_end) &gt; unix_timestamp(now( )) ))
    </select>
 
 
</mapper>