xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
<?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.stylefeng.guns.modular.system.dao.UserMerchantCouponMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.UserMerchantCoupon">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="userType" property="userType"/>
        <result column="userId" property="userId"/>
        <result column="merchantActivityId" property="merchantActivityId"/>
        <result column="merchantCouponId" property="merchantCouponId"/>
        <result column="endTime" property="endTime"/>
        <result column="status" property="status"/>
        <result column="writeOffTime" property="writeOffTime"/>
        <result column="writeOffUserType" property="writeOffUserType"/>
        <result column="writeOffUserId" property="writeOffUserId"/>
        <result column="state" property="state"/>
        <result column="createTime" property="createTime"/>
    </resultMap>
 
 
    <select id="getUserMerchantCoupon" resultType="com.stylefeng.guns.modular.system.warpper.UserMerchantCouponWapper">
        select
        u.id,
        u.`code`,
        a.`name`,
        a.type,
        a.content,
        a.fullAmount,
        a.discount,
        b.totalNum,
        c.receive,
        d.writeOff,
        DATE_FORMAT(u.endTime, '%Y-%m-%d %H:%i:%s') as endTime,
        u.`status`,
        if(u.userType = 1, ifnull(e.name, e.nickName), f.name) as userName,
        if(u.userType = 1, e.phone, f.phone) as phone,
        g.name as merchantName
        from t_user_merchant_coupon u
        left join t_merchant_coupon a on (u.merchantCouponId = a.id)
        left join (select sum(totalNumber) as totalNum, merchantCouponId from t_merchant_activity_slave group by merchantCouponId) b on (a.id = b.merchantCouponId)
        left join (select count(1) as receive, merchantCouponId from t_user_merchant_coupon where state != 3 group by merchantCouponId) c on (a.id = c.merchantCouponId)
        left join (select count(1) as writeOff, merchantCouponId from t_user_merchant_coupon where state != 3 and `status` = 2 group by merchantCouponId) d on (a.id = d.merchantCouponId)
        left join t_user e on (u.userType = 1 and u.userId = e.id)
        left join t_driver f on (u.userType = 2 and u.userId = f.id)
        left join t_merchant g on (a.merchantId = g.id)
        where u.state = 1 and u.`code` = #{code}
    </select>
 
 
 
    <select id="getWriteOffHistory" resultType="map">
        select
        a.id,
        if(a.userType = 1, ifnull(b.name, b.nickName), c.`name`) as `name`,
        if(a.userType = 1, b.phone, c.phone) as phone,
        DATE_FORMAT(a.writeOffTime, '%Y/%m/%d/%H:%i') as writeOffTime
        from t_user_merchant_coupon a
        left join t_user b on (a.userType = 1 and a.userId = b.id)
        left join t_driver c on (a.userType = 2 and a.userId = c.id)
        where a.`status` = 2 and a.merchantActivityId = #{activityId} and a.merchantCouponId = #{id} order by a.writeOffTime desc limit #{pageNum}, #{size}
    </select>
 
 
    <select id="getMyMerchantCoupon" resultType="com.stylefeng.guns.modular.system.warpper.MerchantCouponWarpper">
        select
        a.id,
        b.`name`,
        b.type,
        b.content,
        b.fullAmount,
        b.discount,
        DATE_FORMAT(a.endTime, '%Y-%m-%d %H:%i:%s') as endTime,
        b.merchantId,
        c.`name` as merchantName,
        c.headImg,
        c.address,
        c.contactName,
        c.contactPhone,
        a.`code`
        from t_user_merchant_coupon a
        left join t_merchant_coupon b on (a.merchantCouponId = b.id)
        left join t_merchant c on (b.merchantId = c.id)
        where a.state = 1 and a.userType = 2 and a.userId = #{uid}
        <if test="null != type and 1 == type">
            and a.`status` = 1
        </if>
        <if test="null != type and 2 == type">
            and a.`status` != 1
        </if>
        order by a.createTime desc
    </select>
 
 
    <update id="updateExpired">
        update t_user_merchant_coupon set `status` = 3 where `status` = 1 and state = 1 and userType = 2 and now() > endTime
    </update>
</mapper>