<?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="org.jeecg.modules.shop.order.mapper.PartnerOrderMapper">

    <select id="queryPageList" resultType="org.jeecg.modules.shop.order.entity.vo.PartnerOrderVO">
        SELECT
            b.name as customerName,
            a.bill_no ,
            a.order_state,
            a.money,
            a.transportation_money,
            c.monney as commissionUsd,
            c.state as commissionState,
            c.give_time,
            a.jd_create_time
        FROM
            partner_order AS a
                INNER JOIN partner_customer AS b ON a.customer_id = b.id
                LEFT JOIN partner_commission AS c ON a.id = c.co_id
        <where>
            a.user_id = #{query.userId}
            <if test="query.orderState != null and query.orderState!=''">
                AND a.order_state = #{query.orderState}
            </if>
            <if test="query.commissionState != null and query.commissionState!=''">
                AND a.commission_state = #{query.commissionState}
            </if>
            <if test="query.name != null and query.name!=''">
                AND b.name like concat('%',#{query.name},'%')
            </if>
        </where>
    </select>
    <select id="getOrderCountByUserAndYear" resultType="java.lang.Integer">
        select count(b.id)
            from partner_customer as a
        inner join partner_order as b on a.id = b.customer_id
        where a.user_id = #{userId}
        and year(b.jd_create_time) = #{year}
    </select>

    <select id="getTakeOrderUserCountByUserAndYear" resultType="java.lang.Integer">
        select count(distinct (b.customer_id))
        from partner_customer as a
                 inner join partner_order as b on a.id = b.customer_id
        where a.user_id = #{userId}
          and year(b.jd_create_time) = #{year}
    </select>
</mapper>