<?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.IncomeMapper">
|
|
<!-- 通用查询映射结果 -->
|
<resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.Income">
|
<id column="id" property="id"/>
|
<result column="userType" property="userType"/>
|
<result column="objectId" property="objectId"/>
|
<result column="type" property="type"/>
|
<result column="incomeId" property="incomeId"/>
|
<result column="orderType" property="orderType"/>
|
<result column="money" property="money"/>
|
<result column="insertTime" property="insertTime"/>
|
</resultMap>
|
|
|
<select id="summaryOfIncomeDetailsList" resultType="map">
|
select * from (
|
select
|
DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime
|
from t_income where userType = 1 and money > 0
|
<if test="null != companyId">
|
and objectId = #{companyId}
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
group by DATE_FORMAT(insertTime, '%Y/%m/%d')
|
) as aa order by aa.insertTime desc
|
<if test="null != offset and null != limit">
|
limit #{offset}, #{limit}
|
</if>
|
</select>
|
|
|
<select id="summaryOfIncomeDetailsListCount" resultType="int">
|
select count(1) from (
|
select
|
DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime
|
from t_income where userType = 1 and money > 0
|
<if test="null != companyId">
|
and objectId = #{companyId}
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
group by DATE_FORMAT(insertTime, '%Y/%m/%d')
|
) as aa
|
</select>
|
|
|
<select id="summaryOfIncomeDetailsListSum" resultType="map">
|
select
|
'合计' as insertTime,
|
ifnull(ROUND(sum(aa.orderPayMoney), 2), 0) as orderPayMoney,
|
ifnull(ROUND(sum(aa.orderRevenue), 2), 0) as orderRevenue,
|
ifnull(ROUND(sum(aa.taxiCardRevenue), 2), 0) as taxiCardRevenue,
|
ifnull(ROUND(sum(aa.overtimeDeduction), 2), 0) as overtimeDeduction,
|
ifnull(ROUND(sum(aa.complaintDeductionProceeds), 2), 0) as complaintDeductionProceeds,
|
ifnull(ROUND(sum(aa.other), 2), 0) as other
|
from (
|
select a.money as orderRevenue, 0 as taxiCardRevenue, 0 as overtimeDeduction, 0 as complaintDeductionProceeds, 0 as other,
|
if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
|
if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone
|
from t_income a
|
left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
|
left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
|
left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
|
left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
|
left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
|
left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
|
left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
|
left join t_user u1 on (b.userId = u1.id)
|
left join t_user u2 on (c.userId = u2.id)
|
left join t_user u3 on (d.userId = u3.id)
|
left join t_user u4 on (e.userId = u4.id)
|
left join t_user u5 on (f.userId = u5.id)
|
left join t_user u6 on (g.userId = u6.id)
|
left join t_user u7 on (h.userId = u7.id)
|
where a.userType = 1 and a.money != 0 and a.type = 2
|
<if test="null != companyId">
|
and a.objectId = #{companyId}
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
|
<if test="null != orderType">
|
and a.orderType = #{orderType}
|
</if>
|
<if test="null != incomeType">
|
and a.type = #{incomeType}
|
</if>
|
|
union all
|
|
select 0 as orderRevenue, a.money as taxiCardRevenue, 0 as overtimeDeduction, 0 as complaintDeductionProceeds, 0 as other,
|
if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
|
if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone
|
from t_income a
|
left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
|
left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
|
left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
|
left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
|
left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
|
left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
|
left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
|
left join t_user u1 on (b.userId = u1.id)
|
left join t_user u2 on (c.userId = u2.id)
|
left join t_user u3 on (d.userId = u3.id)
|
left join t_user u4 on (e.userId = u4.id)
|
left join t_user u5 on (f.userId = u5.id)
|
left join t_user u6 on (g.userId = u6.id)
|
left join t_user u7 on (h.userId = u7.id)
|
where a.userType = 1 and a.money != 0 and a.type = 5
|
<if test="null != companyId">
|
and a.objectId = #{companyId}
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
<if test="null != orderType">
|
and a.orderType = #{orderType}
|
</if>
|
<if test="null != incomeType">
|
and a.type = #{incomeType}
|
</if>
|
|
union all
|
|
select 0 as orderRevenue, 0 as taxiCardRevenue, a.money as overtimeDeduction, 0 as complaintDeductionProceeds, 0 as other,
|
if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
|
if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone
|
from t_income a
|
left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
|
left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
|
left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
|
left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
|
left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
|
left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
|
left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
|
left join t_user u1 on (b.userId = u1.id)
|
left join t_user u2 on (c.userId = u2.id)
|
left join t_user u3 on (d.userId = u3.id)
|
left join t_user u4 on (e.userId = u4.id)
|
left join t_user u5 on (f.userId = u5.id)
|
left join t_user u6 on (g.userId = u6.id)
|
left join t_user u7 on (h.userId = u7.id)
|
where a.userType = 1 and a.money != 0 and a.type in (7, 9)
|
<if test="null != companyId">
|
and a.objectId = #{companyId}
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
<if test="null != orderType">
|
and a.orderType = #{orderType}
|
</if>
|
<if test="null != incomeType">
|
and a.type = #{incomeType}
|
</if>
|
|
union all
|
|
select 0 as orderRevenue, 0 as taxiCardRevenue, 0 as overtimeDeduction, a.money as complaintDeductionProceeds, 0 as other,
|
if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
|
if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone
|
from t_income a
|
left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
|
left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
|
left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
|
left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
|
left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
|
left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
|
left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
|
left join t_user u1 on (b.userId = u1.id)
|
left join t_user u2 on (c.userId = u2.id)
|
left join t_user u3 on (d.userId = u3.id)
|
left join t_user u4 on (e.userId = u4.id)
|
left join t_user u5 on (f.userId = u5.id)
|
left join t_user u6 on (g.userId = u6.id)
|
left join t_user u7 on (h.userId = u7.id)
|
where a.userType = 1 and a.money != 0 and a.type = 8
|
<if test="null != companyId">
|
and a.objectId = #{companyId}
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
<if test="null != orderType">
|
and a.orderType = #{orderType}
|
</if>
|
<if test="null != incomeType">
|
and a.type = #{incomeType}
|
</if>
|
|
union all
|
|
select 0 as orderRevenue, 0 as taxiCardRevenue, 0 as overtimeDeduction, 0 as complaintDeductionProceeds, a.money as other,
|
if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
|
if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone
|
from t_income a
|
left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
|
left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
|
left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
|
left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
|
left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
|
left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
|
left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
|
left join t_user u1 on (b.userId = u1.id)
|
left join t_user u2 on (c.userId = u2.id)
|
left join t_user u3 on (d.userId = u3.id)
|
left join t_user u4 on (e.userId = u4.id)
|
left join t_user u5 on (f.userId = u5.id)
|
left join t_user u6 on (g.userId = u6.id)
|
left join t_user u7 on (h.userId = u7.id)
|
where a.userType = 1 and a.money != 0 and a.type in (1, 3, 4, 6)
|
<if test="null != companyId">
|
and a.objectId = #{companyId}
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
<if test="null != orderType">
|
and a.orderType = #{orderType}
|
</if>
|
<if test="null != incomeType">
|
and a.type = #{incomeType}
|
</if>
|
|
) as aa where 1 = 1
|
<if test="null != name and '' != name">
|
and aa.nickName like CONCAT('%', #{name}, '%')
|
</if>
|
<if test="null != phone and '' != phone">
|
and aa.phone like CONCAT('%', #{phone}, '%')
|
</if>
|
</select>
|
|
|
|
<select id="summaryOfIncomeDetailsListGroupSum" resultType="map">
|
select * from (
|
select
|
aa.userType,
|
aa.objectId,
|
aa.type,
|
aa.orderType,
|
aa.insertTime,
|
ifnull(sum(aa.payMoney), 0) as payMoney,
|
aa.nickName,
|
aa.phone,
|
ifnull(sum(aa.overtimeDeduction), 0) as overtimeDeduction,
|
ifnull(sum(aa.money), 0) as money,
|
ifnull(sum(aa.complaint), 0) as complaint
|
from (
|
select
|
a.userType,
|
a.objectId,
|
a.type,
|
a.orderType,
|
DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
|
if(a.orderType = 1, b.payMoney, if(a.orderType = 2, c.payMoney, if(a.orderType = 3, d.payMoney, if(a.orderType = 4, e.payMoney, if(a.orderType = 5, f.payMoney, if(a.orderType = 6, 0, if(a.orderType = 7, h.payMoney, 0))))))) as payMoney,
|
if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
|
if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone,
|
0 as overtimeDeduction,
|
if(a.orderType = 1 and a.incomeId = b.id, a.money, if(a.orderType = 2 and a.incomeId = c.id, a.money, if(a.orderType = 3 and a.incomeId = d.id, a.money, if(a.orderType = 4 and a.incomeId = e.id, a.money, if(a.orderType = 5 and a.incomeId = f.id, a.money, if(a.orderType = 6 and a.incomeId = g.id, a.money, if(a.orderType = 7 and a.incomeId = h.id, a.money, 0))))))) as money,
|
0 as complaint
|
from t_income a
|
left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
|
left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
|
left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
|
left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
|
left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
|
left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
|
left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
|
left join t_user u1 on (b.userId = u1.id)
|
left join t_user u2 on (c.userId = u2.id)
|
left join t_user u3 on (d.userId = u3.id)
|
left join t_user u4 on (e.userId = u4.id)
|
left join t_user u5 on (f.userId = u5.id)
|
left join t_user u6 on (g.userId = u6.id)
|
left join t_user u7 on (h.userId = u7.id)
|
where a.type = 2
|
|
union all
|
|
select
|
a.userType,
|
a.objectId,
|
a.type,
|
a.orderType,
|
DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
|
0 as payMoney,
|
if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
|
if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone,
|
if(a.orderType = 1 and a.incomeId = b.id, a.money, if(a.orderType = 2 and a.incomeId = c.id, a.money, if(a.orderType = 3 and a.incomeId = d.id, a.money, if(a.orderType = 4 and a.incomeId = e.id, a.money, if(a.orderType = 5 and a.incomeId = f.id, a.money, if(a.orderType = 6 and a.incomeId = g.id, a.money, if(a.orderType = 7 and a.incomeId = h.id, a.money, 0))))))) as overtimeDeduction,
|
0 as money,
|
0 as complaint
|
from t_income a
|
left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
|
left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
|
left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
|
left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
|
left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
|
left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
|
left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
|
left join t_user u1 on (b.userId = u1.id)
|
left join t_user u2 on (c.userId = u2.id)
|
left join t_user u3 on (d.userId = u3.id)
|
left join t_user u4 on (e.userId = u4.id)
|
left join t_user u5 on (f.userId = u5.id)
|
left join t_user u6 on (g.userId = u6.id)
|
left join t_user u7 on (h.userId = u7.id)
|
where a.type = 7
|
|
union all
|
|
select
|
a.userType,
|
a.objectId,
|
a.type,
|
a.orderType,
|
DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
|
0 as payMoney,
|
'' as nickName,
|
'' as phone,
|
0 as overtimeDeduction,
|
0 as money,
|
a.money as complaint
|
from t_income a
|
where a.type = 8
|
) as aa group by aa.userType, aa.objectId, aa.type, aa.orderType, aa.insertTime, aa.nickName, aa.phone
|
) as datas where 1 = 1
|
<if test="null != userType">
|
and datas.userType = #{userType}
|
</if>
|
<if test="null != objectId">
|
and datas.objectId = #{objectId}
|
</if>
|
<if test="null != insertTime">
|
and datas.insertTime = #{insertTime}
|
</if>
|
order by datas.insertTime desc,datas.phone
|
</select>
|
|
|
|
<select id="summaryOfIncomeDetailsListGroupSum1" resultType="map">
|
select * from (
|
select
|
aa.userType,
|
aa.objectId,
|
aa.type,
|
aa.orderType,
|
aa.insertTime,
|
ifnull(sum(aa.orderMoney), 0) as orderMoney,
|
ifnull(sum(aa.payMoney), 0) as payMoney,
|
aa.nickName,
|
aa.phone,
|
ifnull(sum(aa.overtimeDeduction), 0) as overtimeDeduction,
|
ifnull(sum(aa.money), 0) as money,
|
ifnull(sum(aa.complaint), 0) as complaint,
|
ifnull(sum(aa.taxiCardRevenue), 0) as taxiCardRevenue,
|
ifnull(sum(aa.other), 0) as other
|
from (
|
select
|
b.userType,
|
b.objectId,
|
b.type,
|
b.orderType,
|
DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
|
a.orderMoney as orderMoney,
|
a.payMoney as payMoney,
|
u1.nickName as nickName,
|
u1.phone as phone,
|
0 as overtimeDeduction,
|
c.money as money,
|
0 as complaint,
|
0 as taxiCardRevenue,
|
0 as other
|
from (
|
select id, 1 as orderType, payMoney, userId, orderMoney,insertTime from t_order_private_car where state in (8, 9)
|
union all
|
select id, 2 as orderType, payMoney, userId, orderMoney,insertTime from t_order_taxi where state in (8, 9)
|
union all
|
select id, 3 as orderType, payMoney, userId, orderMoney,insertTime from t_order_cross_city where state in (8, 9)
|
union all
|
select id, type as orderType, payMoney, userId, orderMoney,insertTime from t_order_logistics where state in (6, 9)
|
) as a
|
left join t_income b on (a.orderType = b.orderType and a.id = b.incomeId and b.type = 2 and b.userType = 1)
|
left join t_income c on (c.type = b.type and c.incomeId = b.incomeId and b.orderType = c.orderType and c.userType = 2)
|
left join t_user u1 on (a.userId = u1.id)
|
where 1=1
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
group by a.id, a.orderType
|
|
union all
|
|
select
|
a.userType,
|
a.objectId,
|
a.type,
|
a.orderType,
|
DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
|
0 as orderMoney,
|
0 as payMoney,
|
if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
|
if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone,
|
if(a.orderType = 1 and a.incomeId = b.id, a.money, if(a.orderType = 2 and a.incomeId = c.id, a.money, if(a.orderType = 3 and a.incomeId = d.id, a.money, if(a.orderType = 4 and a.incomeId = e.id, a.money, if(a.orderType = 5 and a.incomeId = f.id, a.money, if(a.orderType = 6 and a.incomeId = g.id, a.money, if(a.orderType = 7 and a.incomeId = h.id, a.money, 0))))))) as overtimeDeduction,
|
0 as money,
|
0 as complaint,
|
0 as taxiCardRevenue,
|
0 as other
|
from t_income a
|
left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
|
left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
|
left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
|
left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
|
left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
|
left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
|
left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
|
left join t_user u1 on (b.userId = u1.id)
|
left join t_user u2 on (c.userId = u2.id)
|
left join t_user u3 on (d.userId = u3.id)
|
left join t_user u4 on (e.userId = u4.id)
|
left join t_user u5 on (f.userId = u5.id)
|
left join t_user u6 on (g.userId = u6.id)
|
left join t_user u7 on (h.userId = u7.id)
|
where a.type = 7 and a.money != 0
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
|
union all
|
|
select
|
a.userType,
|
a.objectId,
|
a.type,
|
a.orderType,
|
DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
|
0 as orderMoney,
|
0 as payMoney,
|
'' as nickName,
|
'' as phone,
|
0 as overtimeDeduction,
|
0 as money,
|
a.money as complaint,
|
0 as taxiCardRevenue,
|
0 as other
|
from t_income a
|
where a.type = 8 and a.money != 0
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
|
union all
|
|
select
|
a.userType,
|
a.objectId,
|
a.type,
|
a.orderType,
|
DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
|
0 as orderMoney,
|
0 as payMoney,
|
'' as nickName,
|
'' as phone,
|
0 as overtimeDeduction,
|
0 as money,
|
0 as complaint,
|
a.money as taxiCardRevenue,
|
0 as other
|
from t_income a
|
where a.type = 5 and a.money != 0
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
|
union all
|
|
select
|
a.userType,
|
a.objectId,
|
a.type,
|
a.orderType,
|
DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
|
0 as orderMoney,
|
0 as payMoney,
|
if(a.orderType = 1, u1.nickName, if(a.orderType = 2, u2.nickName, if(a.orderType = 3, u3.nickName, if(a.orderType = 4, u4.nickName, if(a.orderType = 5, u5.nickName, if(a.orderType = 6, u6.nickName, if(a.orderType = 2, u7.nickName, ''))))))) as nickName,
|
if(a.orderType = 1, u1.phone, if(a.orderType = 2, u2.phone, if(a.orderType = 3, u3.phone, if(a.orderType = 4, u4.phone, if(a.orderType = 5, u5.phone, if(a.orderType = 6, u6.phone, if(a.orderType = 2, u7.phone, ''))))))) as phone,
|
0 as overtimeDeduction,
|
0 as money,
|
0 as complaint,
|
0 as taxiCardRevenue,
|
a.money as other
|
from t_income a
|
left join t_order_private_car b on (a.orderType = 1 and a.incomeId = b.id)
|
left join t_order_taxi c on (a.orderType = 2 and a.incomeId = c.id)
|
left join t_order_cross_city d on (a.orderType = 3 and a.incomeId = d.id)
|
left join t_order_logistics e on (a.orderType = 4 and a.incomeId = e.id)
|
left join t_order_logistics f on (a.orderType = 5 and a.incomeId = f.id)
|
left join t_order_chartered_car g on (a.orderType = 6 and a.incomeId = g.id)
|
left join t_order_call h on (a.orderType = 7 and a.incomeId = h.id)
|
left join t_user u1 on (b.userId = u1.id)
|
left join t_user u2 on (c.userId = u2.id)
|
left join t_user u3 on (d.userId = u3.id)
|
left join t_user u4 on (e.userId = u4.id)
|
left join t_user u5 on (f.userId = u5.id)
|
left join t_user u6 on (g.userId = u6.id)
|
left join t_user u7 on (h.userId = u7.id)
|
where a.type in (3, 4) and a.money != 0
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
|
union all
|
|
select
|
a.userType,
|
a.objectId,
|
a.type,
|
a.orderType,
|
DATE_FORMAT(a.insertTime, '%Y/%m/%d') as insertTime,
|
0 as orderMoney,
|
0 as payMoney,
|
'' as nickName,
|
'' as phone,
|
0 as overtimeDeduction,
|
0 as money,
|
0 as complaint,
|
0 as taxiCardRevenue,
|
a.money as other
|
from t_income a
|
where a.type in (1, 6, 9) and a.money != 0
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(a.insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
|
) as aa group by aa.userType, aa.objectId, aa.type, aa.orderType, aa.insertTime, aa.nickName, aa.phone
|
) as datas where 1 = 1
|
<if test="null != userType">
|
and datas.userType = #{userType}
|
</if>
|
<if test="null != objectId">
|
and datas.objectId = #{objectId}
|
</if>
|
<if test="null != orderType">
|
and datas.orderType = #{orderType}
|
</if>
|
<if test="null != incomeType">
|
and datas.type = #{incomeType}
|
</if>
|
<if test="null != name and '' != name">
|
and datas.nickName like CONCAT('%', #{name}, '%')
|
</if>
|
<if test="null != phone and '' != phone">
|
and datas.phone like CONCAT('%', #{phone}, '%')
|
</if>
|
order by datas.insertTime desc,datas.phone
|
<if test="null != offset and null != limit">
|
limit #{offset}, #{limit}
|
</if>
|
</select>
|
|
|
|
|
<select id="getSumData" resultType="double">
|
select
|
ifnull(sum(aa.money), 0) as money
|
from (
|
select money,userType,objectId,DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime
|
from t_income where 1 = 1
|
<if test="null != userType">
|
and userType = #{userType}
|
</if>
|
<if test="null != objectId">
|
and objectId = #{objectId}
|
</if>
|
<if test="null != insertTime">
|
and DATE_FORMAT(insertTime, '%Y/%m/%d') = #{insertTime}
|
</if>
|
<if test="null != types">
|
and type in
|
<foreach collection="types" item="item" index="index" open="(" separator="," close=")">
|
#{item}
|
</foreach>
|
</if>
|
) as aa group by aa.userType,aa.objectId,aa.insertTime
|
</select>
|
|
|
<select id="summaryOfSpendingDetailsList" resultType="map">
|
select * from (
|
select
|
DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime
|
from t_income where userType = 2 and money > 0
|
<if test="null != companyId">
|
and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
group by DATE_FORMAT(insertTime, '%Y/%m/%d')
|
) as aa order by aa.insertTime desc
|
<if test="null != offset and null != limit">
|
limit #{offset}, #{limit}
|
</if>
|
</select>
|
|
|
<select id="summaryOfSpendingDetailsListCount" resultType="int">
|
select count(1) from (
|
select
|
DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime
|
from t_income where userType = 1 and money > 0
|
<if test="null != companyId">
|
and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
group by DATE_FORMAT(insertTime, '%Y/%m/%d')
|
) as aa
|
</select>
|
|
<select id="summaryOfSpendingDetailsListSum" resultType="map">
|
select
|
ifnull(ROUND(sum(aa.orderRevenue), 2), 0) as orderRevenue,
|
ifnull(ROUND(sum(aa.activityAward), 2), 0) as activityAward,
|
ifnull(ROUND(sum(aa.other), 2), 0) as other,
|
ROUND(ifnull(sum(aa.orderRevenue), 0) + ifnull(sum(aa.activityAward), 0) + ifnull(sum(aa.other), 0), 2) as `all`
|
from (
|
select objectId, money as orderRevenue, 0 as activityAward, 0 as other from t_income where userType = 2 and money > 0 and type = 2
|
<if test="null != companyId">
|
and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
<if test="null != orderType">
|
and orderType = #{orderType}
|
</if>
|
<if test="null != incomeType">
|
and type = #{incomeType}
|
</if>
|
|
union all
|
|
select objectId, 0 as orderRevenue, money as activityAward, 0 as other from t_income where userType = 2 and money > 0 and type = 1
|
<if test="null != companyId">
|
and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
<if test="null != orderType">
|
and orderType = #{orderType}
|
</if>
|
<if test="null != incomeType">
|
and type = #{incomeType}
|
</if>
|
|
union all
|
|
select objectId, 0 as orderRevenue, 0 as activityAward, money as other from t_income where userType = 2 and money > 0 and type in (6, 9)
|
<if test="null != companyId">
|
and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
<if test="null != orderType">
|
and orderType = #{orderType}
|
</if>
|
<if test="null != incomeType">
|
and type = #{incomeType}
|
</if>
|
|
) as aa
|
left join t_driver bb on (aa.objectId = bb.id)
|
where 1 = 1
|
<if test="null != name and '' != name">
|
and bb.name like CONCAT('%', #{name}, '%')
|
</if>
|
<if test="null != phone and '' != phone">
|
and bb.phone like CONCAT('%', #{phone}, '%')
|
</if>
|
</select>
|
|
|
<select id="summaryOfSpendingDetailsList1" resultType="map">
|
select * from (
|
select
|
aa.insertTime,
|
aa.orderType,
|
aa.type,
|
aa.incomeType,
|
bb.`name`,
|
bb.phone,
|
aa.objectId,
|
ROUND(sum(aa.orderRevenue), 2) as orderRevenue,
|
ROUND(sum(aa.activityAward), 2) as activityAward,
|
ROUND(sum(aa.other), 2) as other,
|
ROUND((sum(aa.orderRevenue) + sum(aa.activityAward) + sum(aa.other)), 2) as `all`
|
from (
|
select
|
DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
|
orderType,
|
'跑单收入' as type,
|
type as incomeType,
|
objectId,
|
money as orderRevenue,
|
0 as activityAward,
|
0 as other
|
from t_income where userType = 2 and type = 2
|
<if test="null != companyId">
|
and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
group by DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType,incomeId, objectId
|
|
union all
|
|
select
|
DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
|
orderType,
|
'活动收入' as type,
|
type as incomeType,
|
objectId,
|
0 as orderRevenue,
|
sum(money) as activityAward,
|
0 as other
|
from t_income where userType = 2 and type = 1
|
<if test="null != companyId">
|
and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
group by DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType, objectId
|
|
union all
|
|
select
|
DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
|
orderType,
|
'感谢费' as type,
|
type as incomeType,
|
objectId,
|
0 as orderRevenue,
|
0 as activityAward,
|
sum(money) as other
|
from t_income where userType = 2 and type = 6
|
<if test="null != companyId">
|
and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
group by DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType, objectId
|
|
union all
|
|
select
|
DATE_FORMAT(insertTime, '%Y/%m/%d') as insertTime,
|
orderType,
|
'小件物流超时退款' as type,
|
type as incomeType,
|
objectId,
|
0 as orderRevenue,
|
0 as activityAward,
|
sum(money) as other
|
from t_income where userType = 2 and type = 9
|
<if test="null != companyId">
|
and objectId in (select id from t_driver where authState = 2 and flag != 3 and companyId = #{companyId})
|
</if>
|
<if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
|
and DATE_FORMAT(insertTime, '%Y-%m-%d') between #{startTime} and #{endTime}
|
</if>
|
group by DATE_FORMAT(insertTime, '%Y/%m/%d'), orderType, objectId
|
) as aa
|
left join t_driver bb on (aa.objectId = bb.id)
|
group by aa.insertTime, aa.orderType, aa.type, aa.objectId
|
) as bb where 1 = 1
|
<if test="null != orderType">
|
and bb.orderType = #{orderType}
|
</if>
|
<if test="null != incomeType">
|
and bb.incomeType = #{incomeType}
|
</if>
|
<if test="null != name and '' != name">
|
and bb.name like CONCAT('%', #{name}, '%')
|
</if>
|
<if test="null != phone and '' != phone">
|
and bb.phone like CONCAT('%', #{phone}, '%')
|
</if>
|
order by bb.insertTime desc
|
<if test="null != offset and null != limit">
|
limit #{offset}, #{limit}
|
</if>
|
</select>
|
</mapper>
|