<?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.fuxi.ws.data.dao.WGiftcardMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WGiftcard">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    <id column="GiftCardID" jdbcType="INTEGER" property="giftcardid" />
    <result column="CardName" jdbcType="NVARCHAR" property="cardname" />
    <result column="BackGroundImg" jdbcType="VARCHAR" property="backgroundimg" />
    <result column="BeginTime" jdbcType="TIMESTAMP" property="begintime" />
    <result column="EndTime" jdbcType="TIMESTAMP" property="endtime" />
    <result column="Type" jdbcType="TINYINT" property="type" />
    <result column="CardValue" jdbcType="DECIMAL" property="cardvalue" />
    <result column="GuidGain" jdbcType="INTEGER" property="guidgain" />
    <result column="PringNum" jdbcType="INTEGER" property="pringnum" />
    <result column="SendNum" jdbcType="INTEGER" property="sendnum" />
    <result column="ActiveNum" jdbcType="INTEGER" property="activenum" />
    <result column="LimitNum" jdbcType="INTEGER" property="limitnum" />
    <result column="VipType" jdbcType="VARCHAR" property="viptype" />
    <result column="ShareImg" jdbcType="VARCHAR" property="shareimg" />
    <result column="ShareTitle" jdbcType="VARCHAR" property="sharetitle" />
    <result column="ShareDec" jdbcType="VARCHAR" property="sharedec" />
    <result column="FirstShareID" jdbcType="BIGINT" property="firstshareid" />
    <result column="SecondShareID" jdbcType="BIGINT" property="secondshareid" />
    <result column="ThirdShareID" jdbcType="BIGINT" property="thirdshareid" />
    <result column="Deposit" jdbcType="DECIMAL" property="deposit" />
    <result column="Validity" jdbcType="TINYINT" property="validity" />
    <result column="Created" jdbcType="TIMESTAMP" property="created" />
    <result column="Creater" jdbcType="VARCHAR" property="creater" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    GiftCardID, CardName, BackGroundImg, BeginTime, EndTime, Type, CardValue, GuidGain, 
    PringNum, SendNum, ActiveNum, LimitNum, VipType, ShareImg, ShareTitle, ShareDec, 
    FirstShareID, SecondShareID, ThirdShareID, Deposit, Validity, Created, Creater
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WGiftcardExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'true' as QUERYID,
    <include refid="Base_Column_List" />
    from W_GiftCard
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_GiftCard
    where GiftCardID = #{giftcardid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    delete from W_GiftCard
    where GiftCardID = #{giftcardid,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.fuxi.ws.data.entity.WGiftcardExample">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    delete from W_GiftCard
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WGiftcard">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    insert into W_GiftCard (GiftCardID, CardName, BackGroundImg, 
      BeginTime, EndTime, Type, 
      CardValue, GuidGain, PringNum, 
      SendNum, ActiveNum, LimitNum, 
      VipType, ShareImg, ShareTitle, 
      ShareDec, FirstShareID, SecondShareID, 
      ThirdShareID, Deposit, Validity, 
      Created, Creater)
    values (#{giftcardid,jdbcType=INTEGER}, #{cardname,jdbcType=NVARCHAR}, #{backgroundimg,jdbcType=VARCHAR}, 
      #{begintime,jdbcType=TIMESTAMP}, #{endtime,jdbcType=TIMESTAMP}, #{type,jdbcType=TINYINT}, 
      #{cardvalue,jdbcType=DECIMAL}, #{guidgain,jdbcType=INTEGER}, #{pringnum,jdbcType=INTEGER}, 
      #{sendnum,jdbcType=INTEGER}, #{activenum,jdbcType=INTEGER}, #{limitnum,jdbcType=INTEGER}, 
      #{viptype,jdbcType=VARCHAR}, #{shareimg,jdbcType=VARCHAR}, #{sharetitle,jdbcType=VARCHAR}, 
      #{sharedec,jdbcType=VARCHAR}, #{firstshareid,jdbcType=BIGINT}, #{secondshareid,jdbcType=BIGINT}, 
      #{thirdshareid,jdbcType=BIGINT}, #{deposit,jdbcType=DECIMAL}, #{validity,jdbcType=TINYINT}, 
      #{created,jdbcType=TIMESTAMP}, #{creater,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WGiftcard">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    insert into W_GiftCard
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="giftcardid != null">
        GiftCardID,
      </if>
      <if test="cardname != null">
        CardName,
      </if>
      <if test="backgroundimg != null">
        BackGroundImg,
      </if>
      <if test="begintime != null">
        BeginTime,
      </if>
      <if test="endtime != null">
        EndTime,
      </if>
      <if test="type != null">
        Type,
      </if>
      <if test="cardvalue != null">
        CardValue,
      </if>
      <if test="guidgain != null">
        GuidGain,
      </if>
      <if test="pringnum != null">
        PringNum,
      </if>
      <if test="sendnum != null">
        SendNum,
      </if>
      <if test="activenum != null">
        ActiveNum,
      </if>
      <if test="limitnum != null">
        LimitNum,
      </if>
      <if test="viptype != null">
        VipType,
      </if>
      <if test="shareimg != null">
        ShareImg,
      </if>
      <if test="sharetitle != null">
        ShareTitle,
      </if>
      <if test="sharedec != null">
        ShareDec,
      </if>
      <if test="firstshareid != null">
        FirstShareID,
      </if>
      <if test="secondshareid != null">
        SecondShareID,
      </if>
      <if test="thirdshareid != null">
        ThirdShareID,
      </if>
      <if test="deposit != null">
        Deposit,
      </if>
      <if test="validity != null">
        Validity,
      </if>
      <if test="created != null">
        Created,
      </if>
      <if test="creater != null">
        Creater,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="giftcardid != null">
        #{giftcardid,jdbcType=INTEGER},
      </if>
      <if test="cardname != null">
        #{cardname,jdbcType=NVARCHAR},
      </if>
      <if test="backgroundimg != null">
        #{backgroundimg,jdbcType=VARCHAR},
      </if>
      <if test="begintime != null">
        #{begintime,jdbcType=TIMESTAMP},
      </if>
      <if test="endtime != null">
        #{endtime,jdbcType=TIMESTAMP},
      </if>
      <if test="type != null">
        #{type,jdbcType=TINYINT},
      </if>
      <if test="cardvalue != null">
        #{cardvalue,jdbcType=DECIMAL},
      </if>
      <if test="guidgain != null">
        #{guidgain,jdbcType=INTEGER},
      </if>
      <if test="pringnum != null">
        #{pringnum,jdbcType=INTEGER},
      </if>
      <if test="sendnum != null">
        #{sendnum,jdbcType=INTEGER},
      </if>
      <if test="activenum != null">
        #{activenum,jdbcType=INTEGER},
      </if>
      <if test="limitnum != null">
        #{limitnum,jdbcType=INTEGER},
      </if>
      <if test="viptype != null">
        #{viptype,jdbcType=VARCHAR},
      </if>
      <if test="shareimg != null">
        #{shareimg,jdbcType=VARCHAR},
      </if>
      <if test="sharetitle != null">
        #{sharetitle,jdbcType=VARCHAR},
      </if>
      <if test="sharedec != null">
        #{sharedec,jdbcType=VARCHAR},
      </if>
      <if test="firstshareid != null">
        #{firstshareid,jdbcType=BIGINT},
      </if>
      <if test="secondshareid != null">
        #{secondshareid,jdbcType=BIGINT},
      </if>
      <if test="thirdshareid != null">
        #{thirdshareid,jdbcType=BIGINT},
      </if>
      <if test="deposit != null">
        #{deposit,jdbcType=DECIMAL},
      </if>
      <if test="validity != null">
        #{validity,jdbcType=TINYINT},
      </if>
      <if test="created != null">
        #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="creater != null">
        #{creater,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WGiftcardExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    select count(*) from W_GiftCard
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    update W_GiftCard
    <set>
      <if test="record.giftcardid != null">
        GiftCardID = #{record.giftcardid,jdbcType=INTEGER},
      </if>
      <if test="record.cardname != null">
        CardName = #{record.cardname,jdbcType=NVARCHAR},
      </if>
      <if test="record.backgroundimg != null">
        BackGroundImg = #{record.backgroundimg,jdbcType=VARCHAR},
      </if>
      <if test="record.begintime != null">
        BeginTime = #{record.begintime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.endtime != null">
        EndTime = #{record.endtime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.type != null">
        Type = #{record.type,jdbcType=TINYINT},
      </if>
      <if test="record.cardvalue != null">
        CardValue = #{record.cardvalue,jdbcType=DECIMAL},
      </if>
      <if test="record.guidgain != null">
        GuidGain = #{record.guidgain,jdbcType=INTEGER},
      </if>
      <if test="record.pringnum != null">
        PringNum = #{record.pringnum,jdbcType=INTEGER},
      </if>
      <if test="record.sendnum != null">
        SendNum = #{record.sendnum,jdbcType=INTEGER},
      </if>
      <if test="record.activenum != null">
        ActiveNum = #{record.activenum,jdbcType=INTEGER},
      </if>
      <if test="record.limitnum != null">
        LimitNum = #{record.limitnum,jdbcType=INTEGER},
      </if>
      <if test="record.viptype != null">
        VipType = #{record.viptype,jdbcType=VARCHAR},
      </if>
      <if test="record.shareimg != null">
        ShareImg = #{record.shareimg,jdbcType=VARCHAR},
      </if>
      <if test="record.sharetitle != null">
        ShareTitle = #{record.sharetitle,jdbcType=VARCHAR},
      </if>
      <if test="record.sharedec != null">
        ShareDec = #{record.sharedec,jdbcType=VARCHAR},
      </if>
      <if test="record.firstshareid != null">
        FirstShareID = #{record.firstshareid,jdbcType=BIGINT},
      </if>
      <if test="record.secondshareid != null">
        SecondShareID = #{record.secondshareid,jdbcType=BIGINT},
      </if>
      <if test="record.thirdshareid != null">
        ThirdShareID = #{record.thirdshareid,jdbcType=BIGINT},
      </if>
      <if test="record.deposit != null">
        Deposit = #{record.deposit,jdbcType=DECIMAL},
      </if>
      <if test="record.validity != null">
        Validity = #{record.validity,jdbcType=TINYINT},
      </if>
      <if test="record.created != null">
        Created = #{record.created,jdbcType=TIMESTAMP},
      </if>
      <if test="record.creater != null">
        Creater = #{record.creater,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    update W_GiftCard
    set GiftCardID = #{record.giftcardid,jdbcType=INTEGER},
      CardName = #{record.cardname,jdbcType=NVARCHAR},
      BackGroundImg = #{record.backgroundimg,jdbcType=VARCHAR},
      BeginTime = #{record.begintime,jdbcType=TIMESTAMP},
      EndTime = #{record.endtime,jdbcType=TIMESTAMP},
      Type = #{record.type,jdbcType=TINYINT},
      CardValue = #{record.cardvalue,jdbcType=DECIMAL},
      GuidGain = #{record.guidgain,jdbcType=INTEGER},
      PringNum = #{record.pringnum,jdbcType=INTEGER},
      SendNum = #{record.sendnum,jdbcType=INTEGER},
      ActiveNum = #{record.activenum,jdbcType=INTEGER},
      LimitNum = #{record.limitnum,jdbcType=INTEGER},
      VipType = #{record.viptype,jdbcType=VARCHAR},
      ShareImg = #{record.shareimg,jdbcType=VARCHAR},
      ShareTitle = #{record.sharetitle,jdbcType=VARCHAR},
      ShareDec = #{record.sharedec,jdbcType=VARCHAR},
      FirstShareID = #{record.firstshareid,jdbcType=BIGINT},
      SecondShareID = #{record.secondshareid,jdbcType=BIGINT},
      ThirdShareID = #{record.thirdshareid,jdbcType=BIGINT},
      Deposit = #{record.deposit,jdbcType=DECIMAL},
      Validity = #{record.validity,jdbcType=TINYINT},
      Created = #{record.created,jdbcType=TIMESTAMP},
      Creater = #{record.creater,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WGiftcard">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    update W_GiftCard
    <set>
      <if test="cardname != null">
        CardName = #{cardname,jdbcType=NVARCHAR},
      </if>
      <if test="backgroundimg != null">
        BackGroundImg = #{backgroundimg,jdbcType=VARCHAR},
      </if>
      <if test="begintime != null">
        BeginTime = #{begintime,jdbcType=TIMESTAMP},
      </if>
      <if test="endtime != null">
        EndTime = #{endtime,jdbcType=TIMESTAMP},
      </if>
      <if test="type != null">
        Type = #{type,jdbcType=TINYINT},
      </if>
      <if test="cardvalue != null">
        CardValue = #{cardvalue,jdbcType=DECIMAL},
      </if>
      <if test="guidgain != null">
        GuidGain = #{guidgain,jdbcType=INTEGER},
      </if>
      <if test="pringnum != null">
        PringNum = #{pringnum,jdbcType=INTEGER},
      </if>
      <if test="sendnum != null">
        SendNum = #{sendnum,jdbcType=INTEGER},
      </if>
      <if test="activenum != null">
        ActiveNum = #{activenum,jdbcType=INTEGER},
      </if>
      <if test="limitnum != null">
        LimitNum = #{limitnum,jdbcType=INTEGER},
      </if>
      <if test="viptype != null">
        VipType = #{viptype,jdbcType=VARCHAR},
      </if>
      <if test="shareimg != null">
        ShareImg = #{shareimg,jdbcType=VARCHAR},
      </if>
      <if test="sharetitle != null">
        ShareTitle = #{sharetitle,jdbcType=VARCHAR},
      </if>
      <if test="sharedec != null">
        ShareDec = #{sharedec,jdbcType=VARCHAR},
      </if>
      <if test="firstshareid != null">
        FirstShareID = #{firstshareid,jdbcType=BIGINT},
      </if>
      <if test="secondshareid != null">
        SecondShareID = #{secondshareid,jdbcType=BIGINT},
      </if>
      <if test="thirdshareid != null">
        ThirdShareID = #{thirdshareid,jdbcType=BIGINT},
      </if>
      <if test="deposit != null">
        Deposit = #{deposit,jdbcType=DECIMAL},
      </if>
      <if test="validity != null">
        Validity = #{validity,jdbcType=TINYINT},
      </if>
      <if test="created != null">
        Created = #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="creater != null">
        Creater = #{creater,jdbcType=VARCHAR},
      </if>
    </set>
    where GiftCardID = #{giftcardid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WGiftcard">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Dec 02 15:58:11 CST 2019.
    -->
    update W_GiftCard
    set CardName = #{cardname,jdbcType=NVARCHAR},
      BackGroundImg = #{backgroundimg,jdbcType=VARCHAR},
      BeginTime = #{begintime,jdbcType=TIMESTAMP},
      EndTime = #{endtime,jdbcType=TIMESTAMP},
      Type = #{type,jdbcType=TINYINT},
      CardValue = #{cardvalue,jdbcType=DECIMAL},
      GuidGain = #{guidgain,jdbcType=INTEGER},
      PringNum = #{pringnum,jdbcType=INTEGER},
      SendNum = #{sendnum,jdbcType=INTEGER},
      ActiveNum = #{activenum,jdbcType=INTEGER},
      LimitNum = #{limitnum,jdbcType=INTEGER},
      VipType = #{viptype,jdbcType=VARCHAR},
      ShareImg = #{shareimg,jdbcType=VARCHAR},
      ShareTitle = #{sharetitle,jdbcType=VARCHAR},
      ShareDec = #{sharedec,jdbcType=VARCHAR},
      FirstShareID = #{firstshareid,jdbcType=BIGINT},
      SecondShareID = #{secondshareid,jdbcType=BIGINT},
      ThirdShareID = #{thirdshareid,jdbcType=BIGINT},
      Deposit = #{deposit,jdbcType=DECIMAL},
      Validity = #{validity,jdbcType=TINYINT},
      Created = #{created,jdbcType=TIMESTAMP},
      Creater = #{creater,jdbcType=VARCHAR}
    where GiftCardID = #{giftcardid,jdbcType=INTEGER}
  </update>

	<!-- 读取礼品卡列表信息 -->
	<select id="giftcardlist" resultType="java.util.LinkedHashMap">
		SELECT GiftCardID,CardName,case when BeginTime is null then '' else
		convert(varchar(10),BeginTime,121) + '<![CDATA[<br/>]]>'
		+ convert(varchar(8),BeginTime,108) end as BeginTime,
		case when EndTime is null then '' else convert(varchar(10),EndTime,121) + '<![CDATA[<br/>]]>'
		+ convert(varchar(8),EndTime,108) end as EndTime,CardValue, PringNum, SendNum,Type, ActiveNum,
		case Type when 1 then '电子卡' when 2 then '实物卡' else '' end as cardType,Deposit
		FROM W_GiftCard WITH (NOLOCK)
		where 1=1
		<if test="status == 1 ">
			and BeginTime&gt;getdate()
		</if>
		<if test="status == 2 ">
			and BeginTime<![CDATA[<=]]>getdate()
			and EndTime &gt;= getdate()
		</if>
		<if test="status == 3 ">
			and EndTime<![CDATA[<]]>getdate()
		</if>
		order by BeginTime desc
	</select>

	<!-- 读取礼品卡列表信息 -->
	<select id="giftcardviplist" resultType="java.util.LinkedHashMap">
		SELECT a.GiftCardNo, a.GiftCardID, a.GainValue, a.ActivePWD,
		case when a.BuyTime is null then '' else
		convert(varchar(10),a.BuyTime,121) + '<![CDATA[<br/>]]>'
		+ convert(varchar(8),a.BuyTime,108) end as BuyTime,
		b.VIP, b.MobilePhone, c.Name, c.MobilPhone AS EmpMobile,
		d.VIP AS RecomVIP, d.MobilePhone AS RecomMobile,a.GuidGain,
		case a.Status when 0 then '未销售' when 1 then '已销售' when 2 then '已激活' end as Status
		FROM W_GiftCardVip AS a WITH (NOLOCK) LEFT OUTER JOIN
		VIP AS d WITH (NOLOCK) ON a.RecomVipid = d.VIPID LEFT OUTER JOIN
		Employee AS c WITH (NOLOCK) ON a.EmployeeID = c.EmployeeID LEFT OUTER JOIN
		VIP AS b WITH (NOLOCK) ON a.Vipid = b.VIPID
		<if test="conditions != null and conditions != ''">
			where
			${conditions}
		</if>
		order by a.BuyTime desc
	</select>

	<!-- 读取礼品卡列表导出 -->
	<select id="outputgiftcard" parameterType="java.util.HashMap" resultType="java.util.LinkedHashMap">
		SELECT a.GiftCardID,a.GiftCardNo,a.GainValue, a.ActivePWD,
		isnull(Convert(varchar(19),a.BuyTime,121),'') BuyTime,
		isnull(b.VIP,'') VIP,isnull(b.MobilePhone,'') MobilePhone,
		isnull(c.Name,'') Name,isnull(c.MobilPhone,'') AS EmpMobile,
		isnull(d.VIP,'') AS RecomVIP, isnull(d.MobilePhone,'') AS RecomMobile,a.GuidGain,
		case a.Status when 0 then '未销售' when 1 then '未激活' when 2 then '已激活' end as Status
		FROM W_GiftCardVip AS a WITH (NOLOCK) LEFT OUTER
		JOIN
		VIP AS d WITH (NOLOCK) ON a.RecomVipid = d.VIPID LEFT OUTER JOIN
		Employee AS c WITH (NOLOCK) ON a.EmployeeID = c.EmployeeID LEFT OUTER JOIN
		VIP AS b WITH (NOLOCK) ON a.Vipid = b.VIPID
		<if test="conditions != null and conditions != ''">
			where
			${conditions}
		</if>
		order by a.BuyTime desc
	</select>

	<!-- 读取礼品卡列表导出 -->
	<select id="guidgainlist" parameterType="java.util.HashMap" resultType="java.util.LinkedHashMap">
		SELECT b.Code, b.Name,sum(a.GuidGain) AllGain,
		sum(case a.HandOut when 1 then a.GuidGain else 0 end) HandOutGain,
		sum(case a.HandOut when 0 then a.GuidGain else 0 end) NoGain
		FROM W_GiftCardVip AS a INNER JOIN
		Employee AS b ON a.EmployeeID = b.EmployeeID
		where a.Status in (1,2) 
		<if test="conditions != null and conditions != ''">			
			and ${conditions}
		</if>		
		group by b.Code, b.Name
	</select>
	
	<!-- 读取可发放提成额 -->
	<select id="guidgainCount" parameterType="java.util.HashMap" resultType="java.lang.Integer">
		select case when exists(SELECT *
		FROM W_GiftCardVip AS a 
		where a.Status in (1,2) and a.HandOut=0 and a.EmployeeID<![CDATA[<>]]>'' and a.EmployeeID is not null
		<if test="conditions != null and conditions != ''">			
			and ${conditions}
		</if>
		) then 1 else 0 end
	</select>
	
	<update id="guidgainchk" parameterType="java.lang.String">
		update W_GiftCardVip set HandOut = 1
		where Status in (1,2) and EmployeeID<![CDATA[<>]]>'' and HandOut=0 and EmployeeID is not null and ${conditions}
	</update>
</mapper>