<?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.bofeng.dao.SubUserMapper">

    <select id="getSubUserByCurrentUserId" resultType="com.bofeng.entity.SubUser">
        select
          up.user_id,
          up.place_id,
          u.staff_name,
          uo.open_id,
          uo.head_img_url,
          p.place_name,
          0 as orderCount,
          0 as totalCommission
        from
          tb_user_place up
          left join tb_user u on(up.user_id=u.user_id)
          left join tb_user_open uo on(up.user_id=uo.user_id)
          left join tb_place p on (up.place_id=p.place_id)
        where
          up.higher_id=#{userId}
    </select>

    <select id="getSubUserCms" resultType="map">
select
  sum(oc2.cms_amount) as totalCommission, o.sale_user_id, count(o.order_id) as orderCount
from
  tb_order o
  inner join tb_order_cms oc2 on o.order_id=oc2.order_id
where
  oc2.sale_user_id=#{userId}
  and oc2.settle=0
  and oc2.be_active='Y'
group by
  o.sale_user_id
    </select>

</mapper>