<?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="cn.pluss.platform.mapper.MerchantMenberRechargeMapper">

	   	<insert id="saveMerchantMenberRecharge" parameterType="cn.pluss.platform.entity.MerchantMenberRecharge">
        	insert into tb_pluss_merchant_menber_recharge(merchantCode,merchantName,storeId,storeName,createDt,logo,memberCode,nickName,phone,rechargeMoney,giveMoney,payType,orderNumber)VALUES(#{merchantCode},#{merchantName},#{storeId},#{storeName},#{createDt},#{logo},#{memberCode},#{nickName},#{phone},#{rechargeMoney},#{giveMoney},#{payType},#{orderNumber})
    	</insert>

	   	<insert id="saveMerchantMenberRechargeBatch">
        	insert into tb_pluss_merchant_menber_recharge(merchantCode,merchantName,storeId,storeName,createDt,logo,memberCode,nickName,phone,rechargeMoney,giveMoney,payType) VALUES 
    			<foreach collection="list" item="item" index="index" separator=",">
			(#{merchantCode},#{merchantName},#{storeId},#{storeName},#{createDt},#{logo},#{memberCode},#{nickName},#{phone},#{rechargeMoney},#{giveMoney},#{payType}		)
				</foreach>
    	</insert>

		<select id="queryMerchantMenberRecharge" parameterType="cn.pluss.platform.entity.MerchantMenberRecharge" resultType="cn.pluss.platform.entity.MerchantMenberRecharge">
			SELECT * from tb_pluss_merchant_menber_recharge 
				<where> 
					<if test="id!= null"> 
					 	and id = #{id}
					 </if> 
					<if test="merchantCode!= null"> 
					 	and merchantCode = #{merchantCode}
					 </if> 
					<if test="merchantName!= null"> 
					 	and merchantName = #{merchantName}
					 </if> 
					<if test="storeId!= null"> 
					 	and storeId = #{storeId}
					 </if> 
					<if test="storeName!= null"> 
					 	and storeName = #{storeName}
					 </if> 
					<if test="createDt!= null"> 
					 	and createDt = #{createDt}
					 </if> 
					<if test="logo!= null"> 
					 	and logo = #{logo}
					 </if> 
					<if test="memberCode!= null"> 
					 	and memberCode = #{memberCode}
					 </if> 
					<if test="nickName!= null"> 
					 	and nickName = #{nickName}
					 </if> 
					<if test="phone!= null"> 
					 	and phone = #{phone}
					 </if> 
					<if test="rechargeMoney!= null"> 
					 	and rechargeMoney = #{rechargeMoney}
					 </if> 
					<if test="giveMoney!= null"> 
					 	and giveMoney = #{giveMoney}
					 </if> 
					<if test="payType!= null"> 
					 	and payType = #{payType}
					 </if> 
					<if test="orderNumber!= null"> 
					 	and orderNumber = #{orderNumber}
					 </if> 
				 </where> 
		</select>

		<select id="queryMerchantMenberRechargeList" parameterType="cn.pluss.platform.entity.MerchantMenberRecharge" resultType="cn.pluss.platform.entity.MerchantMenberRecharge">
			SELECT * from tb_pluss_merchant_menber_recharge 
				<where> 
					<if test="id!= null"> 
					 and 	id = #{id}
					 </if> 
					<if test="merchantCode!= null"> 
					 and 	merchantCode = #{merchantCode}
					 </if> 
					<if test="merchantName!= null"> 
					 and 	merchantName = #{merchantName}
					 </if> 
					<if test="storeId!= null"> 
					 and 	storeId = #{storeId}
					 </if> 
					<if test="storeName!= null"> 
					 and 	storeName = #{storeName}
					 </if> 
					<if test="createDt!= null"> 
					 and 	createDt = #{createDt}
					 </if> 
					<if test="logo!= null"> 
					 and 	logo = #{logo}
					 </if> 
					<if test="memberCode!= null"> 
					 and 	memberCode = #{memberCode}
					 </if> 
					<if test="nickName!= null"> 
					 and 	nickName = #{nickName}
					 </if> 
					<if test="phone!= null"> 
					 and 	phone = #{phone}
					 </if> 
					<if test="rechargeMoney!= null"> 
					 and 	rechargeMoney = #{rechargeMoney}
					 </if> 
					<if test="giveMoney!= null"> 
					 and 	giveMoney = #{giveMoney}
					 </if> 
					<if test="payType!= null"> 
					 and 	payType = #{payType}
					 </if>
					 <if test="orderNumber!= null"> 
                        and orderNumber = #{orderNumber}
                     </if> 
				 </where> 
		</select>

		<update id="updateMerchantMenberRecharge" parameterType="cn.pluss.platform.entity.MerchantMenberRecharge" >
			update tb_pluss_merchant_menber_recharge 
				  <set> 
					<if test="merchantCode!= null"> 
					 	merchantCode = #{merchantCode},
					 </if> 
					<if test="merchantName!= null"> 
					 	merchantName = #{merchantName},
					 </if> 
					<if test="storeId!= null"> 
					 	storeId = #{storeId},
					 </if> 
					<if test="storeName!= null"> 
					 	storeName = #{storeName},
					 </if> 
					<if test="createDt!= null"> 
					 	createDt = #{createDt},
					 </if> 
					<if test="logo!= null"> 
					 	logo = #{logo},
					 </if> 
					<if test="memberCode!= null"> 
					 	memberCode = #{memberCode},
					 </if> 
					<if test="nickName!= null"> 
					 	nickName = #{nickName},
					 </if> 
					<if test="phone!= null"> 
					 	phone = #{phone},
					 </if> 
					<if test="rechargeMoney!= null"> 
					 	rechargeMoney = #{rechargeMoney},
					 </if> 
					<if test="giveMoney!= null"> 
					 	giveMoney = #{giveMoney},
					 </if> 
					<if test="payType!= null"> 
					 	payType = #{payType},
					 </if> 
					 <if test="orderNumber!= null"> 
                         orderNumber = #{orderNumber}
                     </if>
				</set>
			where id=#{id} 
		</update>

		<delete id="deleteMerchantMenberRecharge" parameterType="cn.pluss.platform.entity.MerchantMenberRecharge" >
			DELETE FROM tb_pluss_merchant_menber_recharge where id=#{id}
		</delete>

		<select id="queryMerchantMenberRechargePage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.MerchantMenberRecharge">
			SELECT mr.* ,mbi.alias from tb_pluss_merchant_menber_recharge mr LEFT JOIN tb_pluss_merchant_base_info mbi on mbi.merchantCode= mr.merchantCode
				<where> 
					<if test="id!= null"> 
					and mr.id = #{id}
					 </if> 
					<if test="alias!= null"> 
					and mbi.alias = #{alias}
					 </if> 
					<if test="merchantCode!= null"> 
					and mr.merchantCode = #{merchantCode}
					 </if> 
					<if test="merchantName!= null"> 
					and mr.merchantName = #{merchantName}
					 </if> 
					<if test="storeId!= null"> 
					and mr.storeId = #{storeId}
					 </if> 
					<if test="storeName!= null"> 
					and mr.storeName = #{storeName}
					 </if> 
					<if test="createDt!= null"> 
					and mr.createDt = #{createDt}
					 </if> 
					<if test="logo!= null"> 
					and mr.logo = #{logo}
					 </if> 
					<if test="memberCode!= null"> 
					and mr.memberCode = #{memberCode}
					 </if> 
					<if test="nickName!= null"> 
					and mr.nickName = #{nickName}
					 </if> 
					<if test="phone!= null"> 
					and mr.phone = #{phone}
					 </if> 
					<if test="rechargeMoney!= null"> 
					and mr.rechargeMoney = #{rechargeMoney}
					 </if> 
					<if test="giveMoney!= null"> 
					and mr.giveMoney = #{giveMoney}
					 </if> 
					<if test="payType!= null"> 
					and mr.payType = #{payType}
					 </if> 
					 <if test="orderNumber!= null"> 
                        and mr.orderNumber = #{orderNumber}
                     </if>
				 </where> 
			order by id desc  limit #{pageSize}  offset  #{offset}  
		</select>
		
		
		<!-- 查询今日会员的充值记录 -->
		<select id="queryMerchantMenberRechargeListByTime" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.MerchantMenberRecharge">
			SELECT * from tb_pluss_merchant_menber_recharge 
				<where> 
					<if test="id!= null"> 
					and id = #{id}
					 </if> 
					<if test="merchantCode!= null"> 
					and merchantCode = #{merchantCode}
					 </if> 
					<if test="merchantName!= null"> 
					and merchantName = #{merchantName}
					 </if> 
					<if test="storeId!= null"> 
					and storeId = #{storeId}
					 </if> 
					<if test="storeName!= null"> 
					and storeName = #{storeName}
					 </if> 
					<if test="createDt!= null"> 
					and createDt = #{createDt}
					 </if> 
					<if test="logo!= null"> 
					and logo = #{logo}
					 </if> 
					<if test="memberCode!= null"> 
					and memberCode = #{memberCode}
					 </if> 
					<if test="nickName!= null"> 
					and nickName = #{nickName}
					 </if> 
					<if test="phone!= null"> 
					and phone = #{phone}
					 </if> 
					<if test="rechargeMoney!= null"> 
					and rechargeMoney = #{rechargeMoney}
					 </if> 
					<if test="giveMoney!= null"> 
					and giveMoney = #{giveMoney}
					 </if> 
					<if test="payType!= null"> 
					and payType = #{payType}
					 </if> 
					 <if test="orderNumber!= null"> 
                        and orderNumber = #{orderNumber}
                     </if>
                     <if test="startTime!= null"> 
                         <![CDATA[
                            and  DATE_FORMAT(createDt, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
                     </if> 
                    <if test="endTime!= null"> 
                         <![CDATA[
                            and  DATE_FORMAT(createDt, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
                     </if> 
				 </where> 
		</select>

		<select id="queryMerchantMenberRechargePageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
			SELECT count(*) from tb_pluss_merchant_menber_recharge mr LEFT JOIN tb_pluss_merchant_base_info mbi on mbi.merchantCode= mr.merchantCode
					<where> 
                    <if test="id!= null"> 
                    and mr.id = #{id}
                     </if> 
                    <if test="alias!= null"> 
                    and mbi.alias = #{alias}
                     </if> 
                    <if test="merchantCode!= null"> 
                    and mr.merchantCode = #{merchantCode}
                     </if> 
                    <if test="merchantName!= null"> 
                    and mr.merchantName = #{merchantName}
                     </if> 
                    <if test="storeId!= null"> 
                    and mr.storeId = #{storeId}
                     </if> 
                    <if test="storeName!= null"> 
                    and mr.storeName = #{storeName}
                     </if> 
                    <if test="createDt!= null"> 
                    and mr.createDt = #{createDt}
                     </if> 
                    <if test="logo!= null"> 
                    and mr.logo = #{logo}
                     </if> 
                    <if test="memberCode!= null"> 
                    and mr.memberCode = #{memberCode}
                     </if> 
                    <if test="nickName!= null"> 
                    and mr.nickName = #{nickName}
                     </if> 
                    <if test="phone!= null"> 
                    and mr.phone = #{phone}
                     </if> 
                    <if test="rechargeMoney!= null"> 
                    and mr.rechargeMoney = #{rechargeMoney}
                     </if> 
                    <if test="giveMoney!= null"> 
                    and mr.giveMoney = #{giveMoney}
                     </if> 
                    <if test="payType!= null"> 
                    and mr.payType = #{payType}
                     </if> 
                     <if test="orderNumber!= null"> 
                        and mr.orderNumber = #{orderNumber}
                     </if>
				</where>
		</select>

</mapper>
