select aul.`id` AS `userId`,aul.username AS `phone`,IFNULL(aud.realname,aud.nickname) AS `name` from ( select `id`,`username` from `app_user_login` where `isdel`=0 and `id` IN
select `parent_id` as `parentId`,`user_id`as `userId`,`bind_time` as `bindTime` from `app_user_relation` where `parent_id`=#{leaderId} and `is_del`=0 order by `bind_time` DESC
</select>
<selectid="countByParentId"resultType="Integer">
select count(*) from `app_user_relation` where
`parent_id`=#{parentId} and `is_del`=0
<iftest="bindTime!='' and bindTime!=null and bindTime>0">
select * from `app_user_relation` as `aur` inner join `app_user_login` as `aul` on aul.id=aur.user_id where aur.is_del=0 and aul.isdel=0 and aur.parent_id=#{userId}
( IFNULL(auswu.upIncome,0) - IFNULL(auswd.dowIncome,0) ) AS `income`
FROM
( SELECT IFNULL(SUM( commission ),0) AS upIncome FROM `app_user_selling_water` WHERE STATUS = 0 AND waiting=1 AND `user_id` = #{userId} ) AS `auswu`,
( SELECT IFNULL(SUM( commission ),0) AS `dowIncome` FROM `app_user_selling_water` WHERE STATUS = 1 AND waiting=1 AND `user_id` = #{userId} ) AS `auswd`;
( SELECT * FROM `app_user_selling_water` WHERE STATUS = 0 and user_id=313 ) AS `a`
INNER JOIN ( SELECT order_no, IFNULL( SUM( commission ), 0 ) AS `incommission` FROM `app_user_selling_water` WHERE `status` = 0 and user_id=313 GROUP BY `order_no` ) AS `b` ON a.order_no = b.order_no
) AS `e`
LEFT JOIN (
SELECT
c.order_no,
d.outcommission,
1 AS `sellerStatus`,
c.crt_time AS `cancelTime`
FROM
( SELECT * FROM `app_user_selling_water` WHERE STATUS = 1 and user_id=313 ) AS `c`
INNER JOIN ( SELECT order_no,IFNULL( SUM( commission ), 0 ) AS `outcommission` FROM `app_user_selling_water` WHERE `status` = 1 and user_id=313 GROUP BY `order_no` ) AS `d` ON c.order_no = d.order_no
) AS `f` ON e.order_no = f.order_no
-->
SELECT w.*,o.commission as commission ,<!--o.type--> CASE
WHEN fcommission>0 THEN
(CASE
WHEN o.commission=0 THEN 1
ELSE 0 END )
ELSE 0 END AS `sellerStatus` FROM (
SELECT t.order_no,IFNULL(SUM(t.z),0)-IFNULL(SUM(t.f),0) as commission,<!--IF(SUM(t.f)>0,'1',0)as type -->
IFNULL(SUM(t.f), 0) as fcommission
FROM (
SELECT order_no,commission as z,0 as f FROM app_user_selling_water WHERE user_id=#{userId}
AND `status`=0 and commission>0
UNION
SELECT order_no,0 as z,commission as f FROM app_user_selling_water WHERE user_id=#{userId}
AND `status`=1 and commission>0
) as t
GROUP BY t.order_no
) o LEFT JOIN ( SELECT order_no,user_id,source_id,order_type,img,price,title,waiting,`crt_time` FROM
app_user_selling_water WHERE
id IN ( SELECT MAX( id ) FROM app_user_selling_water GROUP BY order_no)) w
select `id`,`member_level` as `memberLevel`,`member_name` as `memberName`,`rent_free_days` as `rentFreeDays`,`total_number` as `totalNumber`,`username`,`status`,`crt_name` as `crtName`,`crt_time`as `crtTime` from `base_user_member_export`
where `is_del`=0 and source = 0
<iftest="username != null and username != ''">
and `username`=#{username}
</if>
<iftest="startTime != null and endTime != null">
and `crt_time` between #{startTime} and #{endTime}
</if>
<iftest="startTime != null and endTime == null">
and <![CDATA[`crt_time` >= #{startTime}]]>
</if>
<iftest="startTime == null and endTime !=null">
and <![CDATA[ `crt_time` <= #{endTime}]]>
</if> order by `crt_time` DESC
</select>
<updateid="updateUserMemberExportDataStatusById">
update `base_user_member_export` set `is_del`=#{status} where `id`=#{id}