Helius
2021-06-16 4e51778362c2130598a4c73ec4cebe6629dbc53f
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
<?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.xzx.gc.order.mapper.RedPaperMapper">
    <select id="getOne" resultType="com.xzx.gc.entity.RedPaper">
        select
            id,
            create_time "createTime",
            receive_user_id "receiveUserId",
            receive_flag "receiveFlag",
            receive_time "receiveTime",
            money,
            rule_id "ruleId",
            total_amount "totalAmount",
            `code`
         from  xzx_user_redpaper_info where receive_user_id is null and rule_id=#{ruleId} limit 1
    </select>
 
    <select id="redPaperList" resultType="com.xzx.gc.model.admin.XzxUserRedpaperInfoModel">
        select a.code ,a.receive_user_id ,a.rule_id,a.receive_time,
        (select nick_name from xzx_user_info where user_id =receive_user_id ) as name,
        (select mobile_phone from xzx_user_info where user_id =receive_user_id ) as mobilePhone,
        a.receive_time,a.money,a.receive_flag
        from xzx_user_redpaper_info a
        where 1=1
 
        <if test="startTime != null and startTime != ''">
            AND  a.receive_time>= #{startTime}
        </if>
 
        <if test="endTime != null and endTime != ''">
            AND  a.receive_time&lt;= #{endTime}
        </if>
 
        <if test="receiveFlag != null  and receiveFlag != ''">
            AND  a.receive_flag= #{receiveFlag}
        </if>
        <if test="partnerId != null and partnerId != ''">
            AND  a.create_user_id= #{partnerId}
        </if>
        <if test="partnerId==null or partnerId == ''">
            AND a.create_user_id is NULL
        </if>
        <if test=" partnerIds != null and partnerIds.size() != 0">
            AND  a.create_user_id in
            <foreach collection="partnerIds" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>
    <select id="redPaperTotal" resultType="java.util.Map">
        select IFNULL(sum(a.money),0) as money,IFNULL(count(a.id),0) as count
        from xzx_user_redpaper_info a
        where 1=1 and a.receive_flag is not null
        <if test="startTime != null and startTime != ''">
            AND  a.receive_time>= #{startTime}
        </if>
 
        <if test="endTime != null and endTime != ''">
            AND  a.receive_time&lt;= #{endTime}
        </if>
 
        <if test="receiveFlag != null">
            AND  a.receive_flag= #{receiveFlag}
        </if>
 
        <if test=" partnerIds != null and partnerIds.size() != 0">
            AND  a.create_user_id in
            <foreach collection="partnerIds" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>
    <insert id="batchInsertPaperInfo">
        insert  xzx_user_redpaper_info (code,create_time,
        money,rule_id,total_amount,create_user_id)  values
 
        <foreach collection="list" index="index" item="info"  separator=",">
 
            <trim prefix="(" suffix=")" suffixOverrides=",">
                #{info.code},#{info.createTime}  ,#{info.money} ,#{info.ruleId} ,#{info.totalAmount} ,#{info.createUserId}
            </trim>
        </foreach>
    </insert>
    <select id="queryRuleByDay" resultType="com.xzx.gc.entity.RedPaperRule">
        select * from xzx_user_redpaper_rule where del_flag=0
 
        <if test="partnerId!= null and partnerId != ''">
            AND  partner_id= #{partnerId}
        </if>
 
        <if test="day != null and day != ''">
            AND  end_time&lt;#{day}
        </if>
 
        <if test="type != null and type != ''">
            AND  rule_type=#{type}
        </if>
    </select>
    <select id="queryMoneyByRuleId" resultType="java.lang.String">
        select IFNULL(sum(a.money),0) from  xzx_user_redpaper_info a
            left join xzx_user_redpaper_rule b on a.rule_id=b.id
        where a.rule_id=#{ruleId}
 
              and a.receive_user_id is null
    </select>
    <delete id="deletePaperByRuleId">
        update xzx_user_redpaper_info set receive_flag=2 where rule_id=#{ruleId} and receive_flag=1
    </delete>
    <delete id="deleteJtRuleId">
        update xzx_rebate_rule_price set del_flag=1 where rule_id=#{ruleId}
    </delete>
</mapper>