From 821fc2f632f8b974a2c0fc37630e13c5fbe6086c Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期五, 26 九月 2025 17:26:16 +0800
Subject: [PATCH] 修改bug

---
 ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/UserCouponRecordMapper.xml | 2913 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 1,460 insertions(+), 1,453 deletions(-)

diff --git a/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/UserCouponRecordMapper.xml b/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/UserCouponRecordMapper.xml
index f4b413c..ca07752 100644
--- a/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/UserCouponRecordMapper.xml
+++ b/ManagementIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/UserCouponRecordMapper.xml
@@ -1,1457 +1,1464 @@
 <?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.UserCouponRecordMapper">
-	
-	<!-- 通用查询映射结果 -->
-	<resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.UserCouponRecord">
-		<id column="id" property="id"/>
-		<result column="money" property="money"/>
-		<result column="fullMoney" property="fullMoney"/>
-		<result column="expirationTime" property="expirationTime"/>
-		<result column="insertTime" property="insertTime"/>
-		<result column="companyId" property="companyId"/>
-		<result column="state" property="state"/>
-		<result column="endTime" property="endTime"/>
-		<result column="couponUseType" property="couponUseType"/>
-		<result column="couponType" property="couponType"/>
-		<result column="userId" property="userId"/>
-		<result column="couponId" property="couponId"/>
-		<result column="couponActivityId" property="couponActivityId"/>
-		<result column="activityType" property="activityType"/>
-	</resultMap>
-	
-	<!-- 通用查询结果列 -->
-	<sql id="Base_Column_List">
-		id
-		, money, fullMoney, expirationTime, insertTime, companyId, state, couponUseType, couponType, userId, couponId, couponActivityId, activityType
-	</sql>
-	
-	<select id="getList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
-		SELECT
-		c.id,
-		c.money,
-		c.fullMoney,
-		c.expirationTime,
-		c.insertTime,
-		c.companyId,
-		c.state,
-		c.couponUseType,
-		c.couponType,
-		c.userId,
-		c.couponId,
-		c.couponActivityId,
-		c.activityType,
-		u.nickName,
-		u.phone,
-		if(a.id is null, if(b.id is null, if(d.id is null, if(e.id is null, '', e.endServiceTime), d.endServiceTime),
-		b.endServiceTime), a.endServiceTime) as useTime
-		FROM
-		t_user_coupon_record c
-		LEFT JOIN t_user u ON c.userId = u.id
-		left join t_order_private_car a on (a.couponId = c.id)
-		left join t_order_taxi b on (b.couponId = c.id)
-		left join t_order_cross_city d on (d.couponId = c.id)
-		left join t_order_logistics e on (e.couponId = c.id)
-		WHERE 1=1
-		<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
-			and (c.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
-		</if>
-		<if test="userName != null and userName !=''">
-			and u.nickName like CONCAT('%',#{userName},'%')
-		</if>
-		<if test="activityType != null and activityType !=''">
-			and c.activityType=#{activityType}
-		</if>
-		<if test="userPhone != null and userPhone !=''">
-			and u.phone like CONCAT('%',#{userPhone},'%')
-		</if>
-		<if test="couponActivityId != null">
-			and c.couponActivityId=#{couponActivityId}
-		</if>
-		<if test="state != null and state !=''">
-			and c.state=#{state}
-		</if>
-	</select>
-	<select id="getRedList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
-		SELECT
-		c.id,
-		c.money,
-		c.endTime as expirationTime,
-		c.insertTime,
-		c.companyId,
-		c.state,
-		c.userId,
-		c.redPacketActivityId,
-		u.nickName,
-		u.phone,
-		if(a.id is null, if(b.id is null, if(d.id is null, if(e.id is null, '', e.endServiceTime), d.endServiceTime),
-		b.endServiceTime), a.endServiceTime) as useTime
-		FROM
-		t_user_red_packet_record c
-		LEFT JOIN t_user u ON c.userId = u.id
-		left join t_order_private_car a on (a.redPacketId = c.id)
-		left join t_order_taxi b on (b.redPacketId = c.id)
-		left join t_order_cross_city d on (d.redPacketId = c.id)
-		left join t_order_logistics e on (e.redPacketId = c.id)
-		WHERE 1=1
-		<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
-			and (c.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
-		</if>
-		<if test="userName != null and userName !=''">
-			and u.nickName like CONCAT('%',#{userName},'%')
-		</if>
-		<if test="userPhone != null and userPhone !=''">
-			and u.phone like CONCAT('%',#{userPhone},'%')
-		</if>
-		<if test="couponActivityId != null and couponActivityId !=''">
-			and c.redPacketActivityId=#{couponActivityId}
-		</if>
-		<if test="state != null and state !=''">
-			and c.state=#{state}
-		</if>
-	</select>
-	<select id="getCouponStatic" resultType="map">
-		select
-		IFNULL(SUM(aa.money), 0) money,
-		IFNULL(SUM(aa.useMoney), 0) useMoney,
-		COUNT(aa.userId) as number
-		from (
-		SELECT
-		IFNULL(SUM(money), 0) money,
-		IFNULL(SUM(CASE WHEN state = 2 THEN money ELSE 0 END), 0) useMoney,
-		userId
-		FROM t_user_coupon_record WHERE activityType = #{activityType} AND couponActivityId = #{activityId}
-		<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
-			and (insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
-		</if>
-		group by userId
-		) as aa
-	</select>
-	<select id="getRedStatic" resultType="map">
-		SELECT
-		IFNULL(SUM(aa.money), 0) money,
-		IFNULL(SUM(aa.useMoney), 0) useMoney,
-		COUNT(aa.userId) number
-		FROM
-		(
-		SELECT
-		IFNULL(SUM(money), 0) money,
-		IFNULL(SUM(CASE WHEN state = 2 THEN money ELSE 0 END ), 0) useMoney,
-		userId
-		FROM
-		t_user_red_packet_record
-		WHERE redPacketActivityId = #{activityId}
-		<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
-			and (insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
-		</if>
-		group by userId
-		) as aa group by aa.userId
-	</select>
-	<select id="getDiscountStatic" resultType="map">
-		SELECT IFNULL(SUM(aa.money), 0) money, COUNT(aa.userId) number
-		FROM (select IFNULL(SUM(discountMoney), 0) money, userId
-		      from t_order_private_car
-		      WHERE activityId = #{activityId}
-		      group by userId) as aa
-	</select>
-	<select id="getDiscountStatic1" resultType="map">
-		SELECT IFNULL(SUM(aa.money), 0) money, COUNT(aa.userId) number
-		FROM (select IFNULL(SUM(discountMoney), 0) money, userId
-		      from t_order_logistics
-		      WHERE activityId = #{activityId}
-		      group by userId) as aa
-	</select>
-	<select id="getRegStatic" resultType="map">
-		SELECT
-		IFNULL(SUM(r.money), 0) money,
-		IFNULL(
-		SUM(
-		CASE
-		WHEN r.state = 2 THEN
-		r.money
-		ELSE
-		0
-		END
-		),
-		0
-		) useMoney,
-		COUNT(r.id) number
-		FROM
-		t_user_coupon_record r
-		LEFT JOIN t_user_activity_balance u ON u.id = r.couponActivityId
-		WHERE
-		u.userActivityId = #{activityId} and r.activityType =4
-		<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
-			and (r.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
-		</if>
-	</select>
-	<select id="getBlanceList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
-		SELECT
-		b.id,
-		b.money,
-		c1.number,c1.useMoney,c1.useNumber,
-		c2.number speNumber,c2.useMoney speUserMoney,c2.useNumber speUseNumber,
-		c3.number taxiNumber,c3.useMoney taxiUserMoney,c3.useNumber taxiUseNumber,
-		c4.number intercityNumber,c4.useMoney intercityUserMoney,c4.useNumber intercityUseNumber
-		FROM
-		t_user_activity_balance b
-		LEFT JOIN (
-		SELECT
-		couponActivityId,
-		IFNULL(
-		SUM(
-		CASE
-		WHEN r.state = 2 THEN
-		r.money
-		ELSE
-		0
-		END
-		),
-		0
-		) useMoney,
-		IFNULL(
-		SUM(
-		CASE
-		WHEN r.state = 2 THEN
-		1
-		ELSE
-		0
-		END
-		),
-		0
-		) useNumber,
-		COUNT(r.id) number
-		FROM
-		t_user_coupon_record r
-		WHERE
-		r.activityType = 4 AND r.couponUseType=0
-		<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
-			and (r.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
-		</if>
-		GROUP BY couponActivityId
-		) c1 ON c1.couponActivityId=b.id
-		LEFT JOIN (
-		SELECT
-		couponActivityId,
-		IFNULL(
-		SUM(
-		CASE
-		WHEN r.state = 2 THEN
-		r.money
-		ELSE
-		0
-		END
-		),
-		0
-		) useMoney,
-		IFNULL(
-		SUM(
-		CASE
-		WHEN r.state = 2 THEN
-		1
-		ELSE
-		0
-		END
-		),
-		0
-		) useNumber,
-		COUNT(r.id) number
-		FROM
-		t_user_coupon_record r
-		WHERE
-		r.activityType = 4 AND r.couponUseType=1
-		<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
-			and (r.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
-		</if>
-		GROUP BY couponActivityId
-		) c2 ON c2.couponActivityId=b.id
-		LEFT JOIN (
-		SELECT
-		couponActivityId,
-		IFNULL(
-		SUM(
-		CASE
-		WHEN r.state = 2 THEN
-		r.money
-		ELSE
-		0
-		END
-		),
-		0
-		) useMoney,
-		IFNULL(
-		SUM(
-		CASE
-		WHEN r.state = 2 THEN
-		1
-		ELSE
-		0
-		END
-		),
-		0
-		) useNumber,
-		COUNT(r.id) number
-		FROM
-		t_user_coupon_record r
-		WHERE
-		r.activityType = 4 AND r.couponUseType=2
-		<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
-			and (r.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
-		</if>
-		GROUP BY couponActivityId
-		) c3 ON c3.couponActivityId=b.id
-		LEFT JOIN (
-		SELECT
-		couponActivityId,
-		IFNULL(
-		SUM(
-		CASE
-		WHEN r.state = 2 THEN
-		r.money
-		ELSE
-		0
-		END
-		),
-		0
-		) useMoney,
-		IFNULL(
-		SUM(
-		CASE
-		WHEN r.state = 2 THEN
-		1
-		ELSE
-		0
-		END
-		),
-		0
-		) useNumber,
-		COUNT(r.id) number
-		FROM
-		t_user_coupon_record r
-		WHERE
-		r.activityType = 4 AND r.couponUseType=4
-		<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
-			and (r.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
-		</if>
-		GROUP BY couponActivityId
-		) c4 ON c4.couponActivityId=b.id
-		WHERE
-		b.userActivityId = #{activityId}
-	</select>
-	
-	
-	<select id="queryCouponRegister" resultType="map">
-		select
-		da.time,
-		sum(da.receivePeople) as receivePeople,
-		sum(da.giving) as giving,
-		(sum(da.receivePeople) + sum(da.giving)) as receive,
-		sum(da.receiveMoney) as receiveMoney,
-		sum(da.usePeople) as usePeople,
-		sum(da.`use`) as `use`,
-		sum(da.useMoney) as useMoney
-		from (
-		select
-		aa.time,
-		count(aa.userId) as receivePeople,
-		0 as giving,
-		sum(aa.receiveMoney) as receiveMoney,
-		0 as usePeople,
-		0 as `use`,
-		0 as useMoney
-		from (
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d') as time,
-		a.userId,
-		count(a.id) as receive,
-		sum(a.money) as receiveMoney
-		from t_user_coupon_record a
-		<if test="2 == type">
-			left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		<if test="3 == type">
-			left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		<if test="4 == type">
-			left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		where a.activityType = #{type}
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(insertTime, '%Y-%m-%d'),userId
-		) as aa GROUP BY aa.time
-		
-		union all
-		
-		select
-		aa.time,
-		0,
-		0,
-		0,
-		count(aa.userId) as usePeople,
-		sum(aa.receive) as `use`,
-		sum(aa.receiveMoney) as useMoney
-		from (
-		select
-		DATE_FORMAT(a.endTime, '%Y-%m-%d') as time,
-		a.userId,
-		count(a.id) as receive,
-		sum(a.money) as receiveMoney
-		from t_user_coupon_record a
-		<if test="2 == type">
-			left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		<if test="3 == type">
-			left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		<if test="4 == type">
-			left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		where a.activityType = #{type} and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.endTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.endTime, '%Y-%m-%d'),userId
-		) as aa GROUP BY aa.time
-		
-		<if test="2 == type">
-			union all
-			
-			select
-			aa.time,
-			0,
-			count(aa.userId) as giving,
-			sum(aa.receiveMoney) as receiveMoney,
-			0 as usePeople,
-			0 as `use`,
-			0 as useMoney
-			from (
-			select
-			DATE_FORMAT(a.insertTime, '%Y-%m-%d') as time,
-			a.userId,
-			count(a.id) as receive,
-			sum(a.money) as receiveMoney
-			from t_user_coupon_record a
-			left join t_sys_coupon_record b on (a.couponActivityId = b.id and a.activityType = 1)
-			where a.activityType = 1
-			<if test="null != name and '' != name">
-				and b.`name` like CONCAT('%', #{name}, '%')
-			</if>
-			<if test="null != start and '' != start and null != end and '' != end">
-				and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-			</if>
-			<if test="null != companyId">
-				and b.companyId = #{companyId}
-			</if>
-			GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d'),userId
-			) as aa GROUP BY aa.time
-			
-			union all
-			
-			select
-			aa.time,
-			0,
-			0,
-			0,
-			count(aa.userId) as usePeople,
-			sum(aa.receive) as `use`,
-			sum(aa.receiveMoney) as useMoney
-			from (
-			select
-			DATE_FORMAT(a.endTime, '%Y-%m-%d') as time,
-			a.userId,
-			count(a.id) as receive,
-			sum(a.money) as receiveMoney
-			from t_user_coupon_record a
-			left join t_sys_coupon_record b on (a.couponActivityId = b.id and a.activityType = 1)
-			where a.activityType = 1 and a.state = 2
-			<if test="null != name and '' != name">
-				and b.`name` like CONCAT('%', #{name}, '%')
-			</if>
-			<if test="null != start and '' != start and null != end and '' != end">
-				and DATE_FORMAT(a.endTime, '%Y-%m-%d') between #{start} and #{end}
-			</if>
-			<if test="null != companyId">
-				and b.companyId = #{companyId}
-			</if>
-			GROUP BY DATE_FORMAT(a.endTime, '%Y-%m-%d'),userId
-			) as aa GROUP BY aa.time
-		</if>
-		) as da GROUP BY da.time order by da.time desc
-		<if test="null != offset and null != limit">
-			limit #{offset}, #{limit}
-		</if>
-	</select>
-	
-	
-	<select id="queryCouponRegisterCount" resultType="int">
-		select count(time) from (
-		select
-		count(da.time) as time
-		from (
-		select
-		aa.time,
-		count(aa.userId) as receivePeople,
-		0 as giving,
-		sum(aa.receiveMoney) as receiveMoney,
-		0 as usePeople,
-		0 as `use`,
-		0 as useMoney
-		from (
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d') as time,
-		a.userId,
-		count(a.id) as receive,
-		sum(a.money) as receiveMoney
-		from t_user_coupon_record a
-		<if test="2 == type">
-			left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		<if test="3 == type">
-			left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		<if test="4 == type">
-			left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		where activityType = #{type}
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(insertTime, '%Y-%m-%d'),userId
-		) as aa GROUP BY aa.time
-		
-		union all
-		
-		select
-		aa.time,
-		0,
-		0,
-		0,
-		count(aa.userId) as usePeople,
-		sum(aa.receive) as `use`,
-		sum(aa.receiveMoney) as useMoney
-		from (
-		select
-		DATE_FORMAT(a.endTime, '%Y-%m-%d') as time,
-		a.userId,
-		count(a.id) as receive,
-		sum(a.money) as receiveMoney
-		from t_user_coupon_record a
-		<if test="2 == type">
-			left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		<if test="3 == type">
-			left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		<if test="4 == type">
-			left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		where a.activityType = #{type} and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.endTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(endTime, '%Y-%m-%d'),userId
-		) as aa GROUP BY aa.time
-		
-		<if test="2 == type">
-			union all
-			
-			select
-			aa.time,
-			0,
-			count(aa.userId) as giving,
-			sum(aa.receiveMoney) as receiveMoney,
-			0 as usePeople,
-			0 as `use`,
-			0 as useMoney
-			from (
-			select
-			DATE_FORMAT(a.insertTime, '%Y-%m-%d') as time,
-			a.userId,
-			count(a.id) as receive,
-			sum(a.money) as receiveMoney
-			from t_user_coupon_record a
-			left join t_sys_coupon_record b on (a.couponActivityId = b.id and a.activityType = 1)
-			where a.activityType = 1
-			<if test="null != name and '' != name">
-				and b.`name` like CONCAT('%', #{name}, '%')
-			</if>
-			<if test="null != start and '' != start and null != end and '' != end">
-				and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-			</if>
-			<if test="null != companyId">
-				and b.companyId = #{companyId}
-			</if>
-			GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d'),userId
-			) as aa GROUP BY aa.time
-			
-			union all
-			
-			select
-			aa.time,
-			0,
-			0,
-			0,
-			count(aa.userId) as usePeople,
-			sum(aa.receive) as `use`,
-			sum(aa.receiveMoney) as useMoney
-			from (
-			select
-			DATE_FORMAT(a.endTime, '%Y-%m-%d') as time,
-			a.userId,
-			count(a.id) as receive,
-			sum(a.money) as receiveMoney
-			from t_user_coupon_record a
-			left join t_sys_coupon_record b on (a.couponActivityId = b.id and a.activityType = 1)
-			where a.activityType = 1 and a.state = 2
-			<if test="null != name and '' != name">
-				and b.`name` like CONCAT('%', #{name}, '%')
-			</if>
-			<if test="null != start and '' != start and null != end and '' != end">
-				and DATE_FORMAT(a.endTime, '%Y-%m-%d') between #{start} and #{end}
-			</if>
-			<if test="null != companyId">
-				and b.companyId = #{companyId}
-			</if>
-			GROUP BY DATE_FORMAT(a.endTime, '%Y-%m-%d'),userId
-			) as aa GROUP BY aa.time
-		</if>
-		) as da GROUP BY da.time
-		) as w
-	</select>
-	
-	
-	<select id="queryCouponRegisterInfo" resultType="map">
-		select
-		a.id as id,
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		d.nickName as userName,
-		d.phone as phone,
-		a.money as money,
-		DATE_FORMAT(a.expirationTime, '%Y-%m-%d %H:%i:%s') as expirationTime,
-		if(a.couponType = 1, '抵扣券', '满减券') as couponType,
-		if(a.state = 1, '未使用', if(a.state = 2, '已使用', '已过期')) as state,
-		DATE_FORMAT(a.endTime, '%Y-%m-%d %H:%i:%s') as endTime
-		from t_user_coupon_record a
-		<if test="2 == type">
-			left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		<if test="3 == type">
-			left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		left join t_user d on (a.userId = d.id)
-		where a.activityType = #{type}
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		order by a.insertTime desc
-		<if test="null != offset and null != limit">
-			limit #{offset}, #{limit}
-		</if>
-	</select>
-	
-	
-	<select id="queryCouponRegisterInfoCount" resultType="int">
-		select
-		count(a.id)
-		from t_user_coupon_record a
-		<if test="2 == type">
-			left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		<if test="3 == type">
-			left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
-			left join t_user_activity c on (b.userActivityId = c.id)
-		</if>
-		left join t_user d on (a.userId = d.id)
-		where a.activityType = #{type}
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-	</select>
-	
-	
-	<select id="queryCouponRegisterInfo1" resultType="map">
-		select
-		aa.time,
-		aa.userId,
-		any_value(aa.userName) as userName,
-		any_value(aa.phone) as phone,
-		sum(aa.amount) as amount,
-		sum(aa.tyNum) as tyNum,
-		sum(aa.tyUseNum) as tyUseNum,
-		sum(aa.tyUseMoney) as tyUseMoney,
-		sum(aa.zcNum) as zcNum,
-		sum(aa.zcUseNum) as zcUseNum,
-		sum(aa.zcUseMoney) as zcUseMoney,
-		sum(aa.czcNum) as czcNum,
-		sum(aa.czcUseNum) as czcUseNum,
-		sum(aa.czcUseMoney) as czcUseMoney,
-		sum(aa.kcNum) as kcNum,
-		sum(aa.kcUseNum) as kcUseNum,
-		sum(aa.kcUseMoney) as kcUseMoney,
-		sum(aa.xjNum) as xjNum,
-		sum(aa.xjUseNum) as xjUseNum,
-		sum(aa.xjUseMoney) as xjUseMoney
-		from (
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		sum(e.amount) as amount,
-		count(a.id) as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney,
-		0 as xjNum,
-		0 as xjUseNum,
-		0 as xjUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 0
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		count(a.id) as tyUseNum,
-		sum(a.money) as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney,
-		0 as xjNum,
-		0 as xjUseNum,
-		0 as xjUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 0 and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		count(a.id) as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney,
-		0 as xjNum,
-		0 as xjUseNum,
-		0 as xjUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 1
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		count(a.id) as zcUseNum,
-		sum(a.money) as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney,
-		0 as xjNum,
-		0 as xjUseNum,
-		0 as xjUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 1 and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		count(a.id) as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney,
-		0 as xjNum,
-		0 as xjUseNum,
-		0 as xjUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		count(a.id) as czcUseNum,
-		sum(a.money) as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney,
-		0 as xjNum,
-		0 as xjUseNum,
-		0 as xjUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 2 and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		count(a.id) as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney,
-		0 as xjNum,
-		0 as xjUseNum,
-		0 as xjUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 3
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		count(a.id) as kcUseNum,
-		sum(a.money) as kcUseMoney,
-		0 as xjNum,
-		0 as xjUseNum,
-		0 as xjUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 3 and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney,
-		count(a.id) as xjNum,
-		0 as xjUseNum,
-		0 as xjUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 4
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney,
-		0 as xjNum,
-		count(a.id) as xjUseNum,
-		sum(a.money) as xjUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 4 and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		) as aa GROUP BY aa.time,aa.userId order by aa.time desc
-		<if test="null != offset and null != limit">
-			limit #{offset}, #{limit}
-		</if>
-	</select>
-	
-	
-	<select id="queryCouponRegisterInfo1Count" resultType="int">
-		select
-		count(w.time)
-		from (
-		select
-		aa.time as time
-		from (
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		sum(e.amount) as amount,
-		count(a.id) as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 0
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		count(a.id) as tyUseNum,
-		sum(a.money) as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 0 and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		count(a.id) as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 1
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		count(a.id) as zcUseNum,
-		sum(a.money) as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 1 and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		count(a.id) as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		count(a.id) as czcUseNum,
-		sum(a.money) as czcUseMoney,
-		0 as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 2 and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		count(a.id) as kcNum,
-		0 as kcUseNum,
-		0 as kcUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 3
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		
-		union all
-		
-		select
-		DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
-		a.userId as userId,
-		d.nickName as userName,
-		d.phone as phone,
-		0 as amount,
-		0 as tyNum,
-		0 as tyUseNum,
-		0 as tyUseMoney,
-		0 as zcNum,
-		0 as zcUseNum,
-		0 as zcUseMoney,
-		0 as czcNum,
-		0 as czcUseNum,
-		0 as czcUseMoney,
-		0 as kcNum,
-		count(a.id) as kcUseNum,
-		sum(a.money) as kcUseMoney
-		from t_user_coupon_record a
-		left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
-		left join t_user_activity c on (b.userActivityId = c.id)
-		left join t_user d on (a.userId = d.id)
-		left join t_payment_record e on (a.paymentRecordId = e.id)
-		where a.activityType = 4 and a.couponUseType = 3 and a.state = 2
-		<if test="null != name and '' != name">
-			and c.`name` like CONCAT('%', #{name}, '%')
-		</if>
-		<if test="null != start and '' != start and null != end and '' != end">
-			and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
-		</if>
-		<if test="null != companyId">
-			and c.companyId = #{companyId}
-		</if>
-		GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
-		) as aa GROUP BY aa.time,aa.userId
-		) w
-	</select>
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.UserCouponRecord">
+        <id column="id" property="id"/>
+        <result column="money" property="money"/>
+        <result column="fullMoney" property="fullMoney"/>
+        <result column="expirationTime" property="expirationTime"/>
+        <result column="insertTime" property="insertTime"/>
+        <result column="companyId" property="companyId"/>
+        <result column="state" property="state"/>
+        <result column="endTime" property="endTime"/>
+        <result column="couponUseType" property="couponUseType"/>
+        <result column="couponType" property="couponType"/>
+        <result column="userId" property="userId"/>
+        <result column="couponId" property="couponId"/>
+        <result column="couponActivityId" property="couponActivityId"/>
+        <result column="activityType" property="activityType"/>
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id
+        , money, fullMoney, expirationTime, insertTime, companyId, state, couponUseType, couponType, userId, couponId,
+        couponActivityId, activityType
+    </sql>
+
+    <select id="getList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
+        SELECT
+        c.id,
+        c.money,
+        c.fullMoney,
+        c.expirationTime,
+        c.insertTime,
+        c.companyId,
+        c.state,
+        c.couponUseType,
+        c.couponType,
+        c.userId,
+        c.couponId,
+        c.couponActivityId,
+        c.activityType,
+        u.nickName,
+        u.phone,
+        if(a.id is null, if(b.id is null, if(d.id is null, if(e.id is null, '', e.endServiceTime), d.endServiceTime),
+        b.endServiceTime), a.endServiceTime) as useTime
+        FROM
+        t_user_coupon_record c
+        LEFT JOIN t_user u ON c.userId = u.id
+        left join t_order_private_car a on (a.couponId = c.id)
+        left join t_order_taxi b on (b.couponId = c.id)
+        left join t_order_cross_city d on (d.couponId = c.id)
+        left join t_order_logistics e on (e.couponId = c.id)
+        WHERE 1=1
+        <if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
+            and (c.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
+        </if>
+        <if test="userName != null and userName !=''">
+            and u.nickName like CONCAT('%',#{userName},'%')
+        </if>
+        <if test="activityType != null and activityType !=''">
+            and c.activityType=#{activityType}
+        </if>
+        <if test="userPhone != null and userPhone !=''">
+            and u.phone like CONCAT('%',#{userPhone},'%')
+        </if>
+        <if test="couponActivityId != null">
+            and c.couponActivityId=#{couponActivityId}
+        </if>
+        <if test="state != null and state !=''">
+            and c.state=#{state}
+        </if>
+    </select>
+    <select id="getRedList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
+        SELECT
+        c.id,
+        c.money,
+        c.endTime as expirationTime,
+        c.insertTime,
+        c.companyId,
+        c.state,
+        c.userId,
+        c.redPacketActivityId,
+        u.nickName,
+        u.phone,
+        if(a.id is null, if(b.id is null, if(d.id is null, if(e.id is null, '', e.endServiceTime), d.endServiceTime),
+        b.endServiceTime), a.endServiceTime) as useTime
+        FROM
+        t_user_red_packet_record c
+        LEFT JOIN t_user u ON c.userId = u.id
+        left join t_order_private_car a on (a.redPacketId = c.id)
+        left join t_order_taxi b on (b.redPacketId = c.id)
+        left join t_order_cross_city d on (d.redPacketId = c.id)
+        left join t_order_logistics e on (e.redPacketId = c.id)
+        WHERE 1=1
+        <if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
+            and (c.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
+        </if>
+        <if test="userName != null and userName !=''">
+            and u.nickName like CONCAT('%',#{userName},'%')
+        </if>
+        <if test="userPhone != null and userPhone !=''">
+            and u.phone like CONCAT('%',#{userPhone},'%')
+        </if>
+        <if test="couponActivityId != null and couponActivityId !=''">
+            and c.redPacketActivityId=#{couponActivityId}
+        </if>
+        <if test="state != null and state !=''">
+            and c.state=#{state}
+        </if>
+    </select>
+    <select id="getCouponStatic" resultType="map">
+        select
+        IFNULL(SUM(aa.money), 0) money,
+        IFNULL(SUM(aa.useMoney), 0) useMoney,
+        COUNT(aa.userId) as number
+        from (
+        SELECT
+        IFNULL(SUM(money), 0) money,
+        IFNULL(SUM(CASE WHEN state = 2 THEN money ELSE 0 END), 0) useMoney,
+        userId
+        FROM t_user_coupon_record WHERE activityType = #{activityType} AND couponActivityId = #{activityId}
+        <if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
+            and (insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
+        </if>
+        group by userId
+        ) as aa
+    </select>
+    <select id="getRedStatic" resultType="map">
+        SELECT
+        IFNULL(SUM(aa.money), 0) money,
+        IFNULL(SUM(aa.useMoney), 0) useMoney,
+        COUNT(aa.userId) number
+        FROM
+        (
+        SELECT
+        IFNULL(SUM(money), 0) money,
+        IFNULL(SUM(CASE WHEN state = 2 THEN money ELSE 0 END ), 0) useMoney,
+        userId
+        FROM
+        t_user_red_packet_record
+        WHERE redPacketActivityId = #{activityId}
+        <if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
+            and (insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
+        </if>
+        group by userId
+        ) as aa group by aa.userId
+    </select>
+    <select id="getDiscountStatic" resultType="map">
+        select count(aa.userId) as number, IFNULL(SUM(aa.money), 0) money from (
+            select
+            a.userId, IFNULL(SUM(a.discountMoney), 0) money
+            from (
+                select userId, discountMoney
+                from t_order_private_car WHERE activityId = #{activityId}
+                union all
+                select userId, discountMoney
+                from t_order_logistics WHERE activityId = #{activityId}
+            ) as a group by a.userId
+        ) as aa
+    </select>
+    <select id="getDiscountStatic1" resultType="map">
+        SELECT IFNULL(SUM(aa.money), 0) money, COUNT(aa.userId) number
+        FROM (select IFNULL(SUM(discountMoney), 0) money, userId
+        from t_order_logistics
+        WHERE activityId = #{activityId}
+        group by userId) as aa
+    </select>
+    <select id="getRegStatic" resultType="map">
+        SELECT
+        IFNULL(SUM(r.money), 0) money,
+        IFNULL(
+        SUM(
+        CASE
+        WHEN r.state = 2 THEN
+        r.money
+        ELSE
+        0
+        END
+        ),
+        0
+        ) useMoney,
+        COUNT(r.id) number
+        FROM
+        t_user_coupon_record r
+        LEFT JOIN t_user_activity_balance u ON u.id = r.couponActivityId
+        WHERE
+        u.userActivityId = #{activityId} and r.activityType =4
+        <if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
+            and (r.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
+        </if>
+    </select>
+    <select id="getBlanceList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
+        SELECT
+        b.id,
+        b.money,
+        c1.number,c1.useMoney,c1.useNumber,
+        c2.number speNumber,c2.useMoney speUserMoney,c2.useNumber speUseNumber,
+        c3.number taxiNumber,c3.useMoney taxiUserMoney,c3.useNumber taxiUseNumber,
+        c4.number intercityNumber,c4.useMoney intercityUserMoney,c4.useNumber intercityUseNumber
+        FROM
+        t_user_activity_balance b
+        LEFT JOIN (
+        SELECT
+        couponActivityId,
+        IFNULL(
+        SUM(
+        CASE
+        WHEN r.state = 2 THEN
+        r.money
+        ELSE
+        0
+        END
+        ),
+        0
+        ) useMoney,
+        IFNULL(
+        SUM(
+        CASE
+        WHEN r.state = 2 THEN
+        1
+        ELSE
+        0
+        END
+        ),
+        0
+        ) useNumber,
+        COUNT(r.id) number
+        FROM
+        t_user_coupon_record r
+        WHERE
+        r.activityType = 4 AND r.couponUseType=0
+        <if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
+            and (r.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
+        </if>
+        GROUP BY couponActivityId
+        ) c1 ON c1.couponActivityId=b.id
+        LEFT JOIN (
+        SELECT
+        couponActivityId,
+        IFNULL(
+        SUM(
+        CASE
+        WHEN r.state = 2 THEN
+        r.money
+        ELSE
+        0
+        END
+        ),
+        0
+        ) useMoney,
+        IFNULL(
+        SUM(
+        CASE
+        WHEN r.state = 2 THEN
+        1
+        ELSE
+        0
+        END
+        ),
+        0
+        ) useNumber,
+        COUNT(r.id) number
+        FROM
+        t_user_coupon_record r
+        WHERE
+        r.activityType = 4 AND r.couponUseType=1
+        <if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
+            and (r.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
+        </if>
+        GROUP BY couponActivityId
+        ) c2 ON c2.couponActivityId=b.id
+        LEFT JOIN (
+        SELECT
+        couponActivityId,
+        IFNULL(
+        SUM(
+        CASE
+        WHEN r.state = 2 THEN
+        r.money
+        ELSE
+        0
+        END
+        ),
+        0
+        ) useMoney,
+        IFNULL(
+        SUM(
+        CASE
+        WHEN r.state = 2 THEN
+        1
+        ELSE
+        0
+        END
+        ),
+        0
+        ) useNumber,
+        COUNT(r.id) number
+        FROM
+        t_user_coupon_record r
+        WHERE
+        r.activityType = 4 AND r.couponUseType=2
+        <if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
+            and (r.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
+        </if>
+        GROUP BY couponActivityId
+        ) c3 ON c3.couponActivityId=b.id
+        LEFT JOIN (
+        SELECT
+        couponActivityId,
+        IFNULL(
+        SUM(
+        CASE
+        WHEN r.state = 2 THEN
+        r.money
+        ELSE
+        0
+        END
+        ),
+        0
+        ) useMoney,
+        IFNULL(
+        SUM(
+        CASE
+        WHEN r.state = 2 THEN
+        1
+        ELSE
+        0
+        END
+        ),
+        0
+        ) useNumber,
+        COUNT(r.id) number
+        FROM
+        t_user_coupon_record r
+        WHERE
+        r.activityType = 4 AND r.couponUseType=4
+        <if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
+            and (r.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
+        </if>
+        GROUP BY couponActivityId
+        ) c4 ON c4.couponActivityId=b.id
+        WHERE
+        b.userActivityId = #{activityId}
+    </select>
+
+
+    <select id="queryCouponRegister" resultType="map">
+        select
+        da.time,
+        sum(da.receivePeople) as receivePeople,
+        sum(da.giving) as giving,
+        (sum(da.receivePeople) + sum(da.giving)) as receive,
+        sum(da.receiveMoney) as receiveMoney,
+        sum(da.usePeople) as usePeople,
+        sum(da.`use`) as `use`,
+        sum(da.useMoney) as useMoney
+        from (
+        select
+        aa.time,
+        count(aa.userId) as receivePeople,
+        0 as giving,
+        sum(aa.receiveMoney) as receiveMoney,
+        0 as usePeople,
+        0 as `use`,
+        0 as useMoney
+        from (
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d') as time,
+        a.userId,
+        count(a.id) as receive,
+        sum(a.money) as receiveMoney
+        from t_user_coupon_record a
+        <if test="2 == type">
+            left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        <if test="3 == type">
+            left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        <if test="4 == type">
+            left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        where a.activityType = #{type}
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(insertTime, '%Y-%m-%d'),userId
+        ) as aa GROUP BY aa.time
+
+        union all
+
+        select
+        aa.time,
+        0,
+        0,
+        0,
+        count(aa.userId) as usePeople,
+        sum(aa.receive) as `use`,
+        sum(aa.receiveMoney) as useMoney
+        from (
+        select
+        DATE_FORMAT(a.endTime, '%Y-%m-%d') as time,
+        a.userId,
+        count(a.id) as receive,
+        sum(a.money) as receiveMoney
+        from t_user_coupon_record a
+        <if test="2 == type">
+            left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        <if test="3 == type">
+            left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        <if test="4 == type">
+            left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        where a.activityType = #{type} and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.endTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.endTime, '%Y-%m-%d'),userId
+        ) as aa GROUP BY aa.time
+
+        <if test="2 == type">
+            union all
+
+            select
+            aa.time,
+            0,
+            count(aa.userId) as giving,
+            sum(aa.receiveMoney) as receiveMoney,
+            0 as usePeople,
+            0 as `use`,
+            0 as useMoney
+            from (
+            select
+            DATE_FORMAT(a.insertTime, '%Y-%m-%d') as time,
+            a.userId,
+            count(a.id) as receive,
+            sum(a.money) as receiveMoney
+            from t_user_coupon_record a
+            left join t_sys_coupon_record b on (a.couponActivityId = b.id and a.activityType = 1)
+            where a.activityType = 1
+            <if test="null != name and '' != name">
+                and b.`name` like CONCAT('%', #{name}, '%')
+            </if>
+            <if test="null != start and '' != start and null != end and '' != end">
+                and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+            </if>
+            <if test="null != companyId">
+                and b.companyId = #{companyId}
+            </if>
+            GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d'),userId
+            ) as aa GROUP BY aa.time
+
+            union all
+
+            select
+            aa.time,
+            0,
+            0,
+            0,
+            count(aa.userId) as usePeople,
+            sum(aa.receive) as `use`,
+            sum(aa.receiveMoney) as useMoney
+            from (
+            select
+            DATE_FORMAT(a.endTime, '%Y-%m-%d') as time,
+            a.userId,
+            count(a.id) as receive,
+            sum(a.money) as receiveMoney
+            from t_user_coupon_record a
+            left join t_sys_coupon_record b on (a.couponActivityId = b.id and a.activityType = 1)
+            where a.activityType = 1 and a.state = 2
+            <if test="null != name and '' != name">
+                and b.`name` like CONCAT('%', #{name}, '%')
+            </if>
+            <if test="null != start and '' != start and null != end and '' != end">
+                and DATE_FORMAT(a.endTime, '%Y-%m-%d') between #{start} and #{end}
+            </if>
+            <if test="null != companyId">
+                and b.companyId = #{companyId}
+            </if>
+            GROUP BY DATE_FORMAT(a.endTime, '%Y-%m-%d'),userId
+            ) as aa GROUP BY aa.time
+        </if>
+        ) as da GROUP BY da.time order by da.time desc
+        <if test="null != offset and null != limit">
+            limit #{offset}, #{limit}
+        </if>
+    </select>
+
+
+    <select id="queryCouponRegisterCount" resultType="int">
+        select count(time) from (
+        select
+        count(da.time) as time
+        from (
+        select
+        aa.time,
+        count(aa.userId) as receivePeople,
+        0 as giving,
+        sum(aa.receiveMoney) as receiveMoney,
+        0 as usePeople,
+        0 as `use`,
+        0 as useMoney
+        from (
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d') as time,
+        a.userId,
+        count(a.id) as receive,
+        sum(a.money) as receiveMoney
+        from t_user_coupon_record a
+        <if test="2 == type">
+            left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        <if test="3 == type">
+            left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        <if test="4 == type">
+            left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        where activityType = #{type}
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(insertTime, '%Y-%m-%d'),userId
+        ) as aa GROUP BY aa.time
+
+        union all
+
+        select
+        aa.time,
+        0,
+        0,
+        0,
+        count(aa.userId) as usePeople,
+        sum(aa.receive) as `use`,
+        sum(aa.receiveMoney) as useMoney
+        from (
+        select
+        DATE_FORMAT(a.endTime, '%Y-%m-%d') as time,
+        a.userId,
+        count(a.id) as receive,
+        sum(a.money) as receiveMoney
+        from t_user_coupon_record a
+        <if test="2 == type">
+            left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        <if test="3 == type">
+            left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        <if test="4 == type">
+            left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        where a.activityType = #{type} and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.endTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(endTime, '%Y-%m-%d'),userId
+        ) as aa GROUP BY aa.time
+
+        <if test="2 == type">
+            union all
+
+            select
+            aa.time,
+            0,
+            count(aa.userId) as giving,
+            sum(aa.receiveMoney) as receiveMoney,
+            0 as usePeople,
+            0 as `use`,
+            0 as useMoney
+            from (
+            select
+            DATE_FORMAT(a.insertTime, '%Y-%m-%d') as time,
+            a.userId,
+            count(a.id) as receive,
+            sum(a.money) as receiveMoney
+            from t_user_coupon_record a
+            left join t_sys_coupon_record b on (a.couponActivityId = b.id and a.activityType = 1)
+            where a.activityType = 1
+            <if test="null != name and '' != name">
+                and b.`name` like CONCAT('%', #{name}, '%')
+            </if>
+            <if test="null != start and '' != start and null != end and '' != end">
+                and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+            </if>
+            <if test="null != companyId">
+                and b.companyId = #{companyId}
+            </if>
+            GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d'),userId
+            ) as aa GROUP BY aa.time
+
+            union all
+
+            select
+            aa.time,
+            0,
+            0,
+            0,
+            count(aa.userId) as usePeople,
+            sum(aa.receive) as `use`,
+            sum(aa.receiveMoney) as useMoney
+            from (
+            select
+            DATE_FORMAT(a.endTime, '%Y-%m-%d') as time,
+            a.userId,
+            count(a.id) as receive,
+            sum(a.money) as receiveMoney
+            from t_user_coupon_record a
+            left join t_sys_coupon_record b on (a.couponActivityId = b.id and a.activityType = 1)
+            where a.activityType = 1 and a.state = 2
+            <if test="null != name and '' != name">
+                and b.`name` like CONCAT('%', #{name}, '%')
+            </if>
+            <if test="null != start and '' != start and null != end and '' != end">
+                and DATE_FORMAT(a.endTime, '%Y-%m-%d') between #{start} and #{end}
+            </if>
+            <if test="null != companyId">
+                and b.companyId = #{companyId}
+            </if>
+            GROUP BY DATE_FORMAT(a.endTime, '%Y-%m-%d'),userId
+            ) as aa GROUP BY aa.time
+        </if>
+        ) as da GROUP BY da.time
+        ) as w
+    </select>
+
+
+    <select id="queryCouponRegisterInfo" resultType="map">
+        select
+        a.id as id,
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        d.nickName as userName,
+        d.phone as phone,
+        a.money as money,
+        DATE_FORMAT(a.expirationTime, '%Y-%m-%d %H:%i:%s') as expirationTime,
+        if(a.couponType = 1, '抵扣券', '满减券') as couponType,
+        if(a.state = 1, '未使用', if(a.state = 2, '已使用', '已过期')) as state,
+        DATE_FORMAT(a.endTime, '%Y-%m-%d %H:%i:%s') as endTime
+        from t_user_coupon_record a
+        <if test="2 == type">
+            left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        <if test="3 == type">
+            left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        left join t_user d on (a.userId = d.id)
+        where a.activityType = #{type}
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        order by a.insertTime desc
+        <if test="null != offset and null != limit">
+            limit #{offset}, #{limit}
+        </if>
+    </select>
+
+
+    <select id="queryCouponRegisterInfoCount" resultType="int">
+        select
+        count(a.id)
+        from t_user_coupon_record a
+        <if test="2 == type">
+            left join t_user_activity_registered b on (a.couponActivityId = b.id and a.activityType = 2)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        <if test="3 == type">
+            left join t_user_activity_invite b on (a.couponActivityId = b.id and a.activityType = 3)
+            left join t_user_activity c on (b.userActivityId = c.id)
+        </if>
+        left join t_user d on (a.userId = d.id)
+        where a.activityType = #{type}
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+    </select>
+
+
+    <select id="queryCouponRegisterInfo1" resultType="map">
+        select
+        aa.time,
+        aa.userId,
+        any_value(aa.userName) as userName,
+        any_value(aa.phone) as phone,
+        sum(aa.amount) as amount,
+        sum(aa.tyNum) as tyNum,
+        sum(aa.tyUseNum) as tyUseNum,
+        sum(aa.tyUseMoney) as tyUseMoney,
+        sum(aa.zcNum) as zcNum,
+        sum(aa.zcUseNum) as zcUseNum,
+        sum(aa.zcUseMoney) as zcUseMoney,
+        sum(aa.czcNum) as czcNum,
+        sum(aa.czcUseNum) as czcUseNum,
+        sum(aa.czcUseMoney) as czcUseMoney,
+        sum(aa.kcNum) as kcNum,
+        sum(aa.kcUseNum) as kcUseNum,
+        sum(aa.kcUseMoney) as kcUseMoney,
+        sum(aa.xjNum) as xjNum,
+        sum(aa.xjUseNum) as xjUseNum,
+        sum(aa.xjUseMoney) as xjUseMoney
+        from (
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        sum(e.amount) as amount,
+        count(a.id) as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney,
+        0 as xjNum,
+        0 as xjUseNum,
+        0 as xjUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 0
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        count(a.id) as tyUseNum,
+        sum(a.money) as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney,
+        0 as xjNum,
+        0 as xjUseNum,
+        0 as xjUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 0 and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        count(a.id) as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney,
+        0 as xjNum,
+        0 as xjUseNum,
+        0 as xjUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 1
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        count(a.id) as zcUseNum,
+        sum(a.money) as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney,
+        0 as xjNum,
+        0 as xjUseNum,
+        0 as xjUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 1 and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        count(a.id) as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney,
+        0 as xjNum,
+        0 as xjUseNum,
+        0 as xjUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        count(a.id) as czcUseNum,
+        sum(a.money) as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney,
+        0 as xjNum,
+        0 as xjUseNum,
+        0 as xjUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 2 and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        count(a.id) as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney,
+        0 as xjNum,
+        0 as xjUseNum,
+        0 as xjUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 3
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        count(a.id) as kcUseNum,
+        sum(a.money) as kcUseMoney,
+        0 as xjNum,
+        0 as xjUseNum,
+        0 as xjUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 3 and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney,
+        count(a.id) as xjNum,
+        0 as xjUseNum,
+        0 as xjUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 4
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney,
+        0 as xjNum,
+        count(a.id) as xjUseNum,
+        sum(a.money) as xjUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 4 and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+        ) as aa GROUP BY aa.time,aa.userId order by aa.time desc
+        <if test="null != offset and null != limit">
+            limit #{offset}, #{limit}
+        </if>
+    </select>
+
+
+    <select id="queryCouponRegisterInfo1Count" resultType="int">
+        select
+        count(w.time)
+        from (
+        select
+        aa.time as time
+        from (
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        sum(e.amount) as amount,
+        count(a.id) as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 0
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        count(a.id) as tyUseNum,
+        sum(a.money) as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 0 and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        count(a.id) as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 1
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        count(a.id) as zcUseNum,
+        sum(a.money) as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 1 and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        count(a.id) as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        count(a.id) as czcUseNum,
+        sum(a.money) as czcUseMoney,
+        0 as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 2 and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        count(a.id) as kcNum,
+        0 as kcUseNum,
+        0 as kcUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 3
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+
+        union all
+
+        select
+        DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s') as time,
+        a.userId as userId,
+        d.nickName as userName,
+        d.phone as phone,
+        0 as amount,
+        0 as tyNum,
+        0 as tyUseNum,
+        0 as tyUseMoney,
+        0 as zcNum,
+        0 as zcUseNum,
+        0 as zcUseMoney,
+        0 as czcNum,
+        0 as czcUseNum,
+        0 as czcUseMoney,
+        0 as kcNum,
+        count(a.id) as kcUseNum,
+        sum(a.money) as kcUseMoney
+        from t_user_coupon_record a
+        left join t_user_activity_balance b on (a.couponActivityId = b.id and a.activityType = 4)
+        left join t_user_activity c on (b.userActivityId = c.id)
+        left join t_user d on (a.userId = d.id)
+        left join t_payment_record e on (a.paymentRecordId = e.id)
+        where a.activityType = 4 and a.couponUseType = 3 and a.state = 2
+        <if test="null != name and '' != name">
+            and c.`name` like CONCAT('%', #{name}, '%')
+        </if>
+        <if test="null != start and '' != start and null != end and '' != end">
+            and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{start} and #{end}
+        </if>
+        <if test="null != companyId">
+            and c.companyId = #{companyId}
+        </if>
+        GROUP BY DATE_FORMAT(a.insertTime, '%Y-%m-%d %H:%i:%s'),a.userId
+        ) as aa GROUP BY aa.time,aa.userId
+        ) w
+    </select>
 </mapper>

--
Gitblit v1.7.1