`auswu`.user_id, ( IFNULL(auswu.upIncome,0) - IFNULL(auswd.dowIncome,0) ) AS `commission`
`auswu`.user_id, ( IFNULL(auswu.upIncome,0) - IFNULL(auswd.dowIncome,0) ) AS `commission`
FROM
FROM
( SELECT `user_id` as `userId`, IFNULL(SUM( commission ),0) AS upIncome FROM `app_user_selling_water` where STATUS = 0 and waiting=1 <iftest="userIds!=null and userIds.size!=0">
( SELECT `user_id` as `userId`, IFNULL(SUM( commission ),0) AS upIncome FROM `app_user_selling_water` where STATUS = 0 and waiting=1
AND `crt_time` between #{startTime} and #{endTime}
<iftest="userIds!=null and userIds.size!=0">
AND `user_id` IN <foreachcollection="userIds"item="userId"open="("close=")"separator=",">
AND `user_id` IN <foreachcollection="userIds"item="userId"open="("close=")"separator=",">
#{userId}
#{userId}
</foreach>
</foreach>
</if> group by user_id) AS `auswu`
</if> group by user_id) AS `auswu`
left join
left join
( SELECT `user_id`,IFNULL(SUM( commission ),0) AS `dowIncome` FROM `app_user_selling_water` where STATUS = 1 and waiting=1 <iftest="userIds!=null and userIds.size!=0">
( SELECT `user_id`,IFNULL(SUM( commission ),0) AS `dowIncome` FROM `app_user_selling_water` where STATUS = 1 and waiting=1
and `crt_time` between #{startTime} and #{endTime}
<iftest="userIds!=null and userIds.size!=0">
AND `user_id` IN <foreachcollection="userIds"item="userId"open="("close=")"separator=",">
AND `user_id` IN <foreachcollection="userIds"item="userId"open="("close=")"separator=",">
select bo.id,bo.type,bo.status,bo.order_amount,bo.real_amount,bo.order_origin,bo.parent_user_id as `userId`,bo.parent_postion_id as `postionId`,
bo.has_pay,bo.pay_way,omd.memberLevel,IFNULL(IFNULL(orvd.start_company_id,otd.start_company_id),`parent_user_company_id`) AS `companyId`,orvd.deposit,orvd.cost_detail_extend AS `costDetailExtend` from (select `id`,`type`,`status`,`order_amount` AS `orderAmount`, `real_amount`AS
`realAmount`,`order_origin` AS `orderOrigin`, `has_pay` AS `hasPay`,
`pay_way` AS `payWay`
from `base_order` where 1=1
<iftest="hasPay!=null">
and `has_pay`=#{hasPay}
</if>
and (`crt_time` between #{startDate} and #{endDate} or `pay_time` between #{startDate} and #{endDate} ) and `type` IN <foreachcollection="types"
item="type"
open="("close=")"
separator=",">
#{type}
</foreach> ) AS `bo`
LEFT JOIN (select `order_id`,`start_company_id`,`deposit`,`cost_detail_extend` from `order_rent_vehicle_detail`) AS `orvd` ON
orvd.order_id=bo.id
LEFT JOIN (select `order_id`,`start_company_id` from `order_tour_detail`) AS `otd` ON otd.order_id=bo.id
LEFT JOIN (select `order_id`,`member_level` AS `memberLevel` from `order_member_detail`) AS `omd` ON