| <?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<= #{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<= #{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<#{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> |