<?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.ai.da.mapper.primary.AffiliateIncomeMapper">
    
    <select id="getPersonalMonthlyIncome" resultType="java.util.Map">
        SELECT
            DATE_FORMAT(payment_time, '%m') as yearMonth,
            SUM(commission) AS totalCommission
        FROM
            t_affiliate_income
        WHERE
            YEAR(payment_time) = #{year}
          and affiliate_account_id = #{affiliateAccountId}
        GROUP BY
            yearMonth
        ORDER BY
            yearMonth
    </select>

    <select id="getMonthlyAffiliateIncome" resultType="java.util.Map">
        SELECT
            DATE_FORMAT(payment_time, '%m') as yearMonth,
            SUM(amount) AS totalAmount,
            SUM(commission) AS totalCommission
        FROM
            t_affiliate_income
        WHERE
            YEAR(payment_time) = #{year}
          and MONTH(payment_time) = #{month}
        GROUP BY
            yearMonth
        ORDER BY
            yearMonth
    </select>

</mapper>
