<?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="cn.com.xingxi.store.data.mapper.WxaStorePopuCostsMapper">


    <select id="selectPopuCostsByUserId" resultType="CommissionMoneyMonthDTO">
        SELECT t_commission_money_month.*
        FROM t_commission_money_month
        WHERE t_commission_money_month.delFlag = '0'
          AND t_commission_money_month.commissionYear = #{y}
          AND t_commission_money_month.referrerId = #{userId}
          AND t_commission_money_month.sellerId = #{mercId}
        ORDER BY t_commission_money_month.commissionMonth asc
    </select>

    <select id="selectUserTotalPopuCostsByUserId" resultType="BigDecimal">
        SELECT IFNULL(SUM(t_commission_money_month.commissionAmount), 0)
        FROM t_commission_money_month
        WHERE t_commission_money_month.delFlag = '0'
          AND t_commission_money_month.referrerId = #{userId}
          AND t_commission_money_month.sellerId =#{mercId}
    </select>

    <select id="selectUserYearPopuCostsByUserId" resultType="BigDecimal">
        SELECT IFNULL(SUM(t_commission_money_month.commissionAmount), 0)
        FROM t_commission_money_month
        WHERE t_commission_money_month.delFlag = '0'
          AND t_commission_money_month.commissionYear = #{y}
          AND t_commission_money_month.referrerId = #{userId}
          AND t_commission_money_month.sellerId = #{mercId}
    </select>

    <select id="selectPopuCostsDetail" resultType="CommissionOrderDTO">
        SELECT t_commission_order.*
        FROM t_commission_order
        WHERE t_commission_order.delFlag = '0'
          AND t_commission_order.referrerId = #{userId}
          AND t_commission_order.sellerId = #{mercId}
          AND date_format(t_commission_order.orderTime, '%Y%m') = #{ym}
        ORDER BY t_commission_order.orderTime DESC
    </select>


</mapper>
