<?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.iocoder.yudao.module.delivery.mapper.OrderExtMapper">

    <!--发货方,客户是否有订单判断-->
    <select id="IsHavingOrderConsignor" resultType="java.lang.Integer">
        SELECT count(*)
        FROM ecw_order o
        LEFT JOIN ecw_order_consignor r ON o.order_id = r.order_id
        and r.deleted = 0
        where o.deleted = 0
        and r.customer_id = #{customerId}
        and o.status >= 5
        <!--订单已取消88,有可能包含在类,暂时未做处理-->
    </select>

    <!--收货方客户,是否有已入仓订单-->
    <select id="IsHavingOrderConsignee" resultType="java.lang.Integer">
        SELECT count(*)
        FROM ecw_order o
                 LEFT JOIN ecw_order_consignee r ON o.order_id = r.order_id
            and r.deleted = 0
        where o.deleted = 0
          and r.customer_id = #{customerId}
          and o.status >= 5

    </select>


    <select id="IsHavingOrder" resultType="java.lang.Integer">
        SELECT COUNT(*)
        from (
                 select id as id
                 from ecw_target_log
                 where deleted = 0
                   and customer_id = #{customerId}
                 UNION
                 SELECT order_id as id
                 from ecw_order
                 where deleted = 0
                   and customer_id = #{customerId}) as a

    </select>


</mapper>