<?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.gree.mall.manager.commonmapper.WebsitSalesRetCMapper">


    <select id="pageV2" resultType="com.gree.mall.manager.bean.websit.WebsitSalesRetVO">
        select
        ${ex.selected}
        from
        websit_sales_ret a LEFT JOIN storage b ON a.storage_id = b.storage_id
        ${ex.query}

        <if test="companyWechatIds != null and companyWechatIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
                #{item}
            </foreach>

        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND (
            a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
            )
        </if>

        <if test="ex.orderBy == null or ex.orderBy ==''">
            order by a.create_time desc
        </if>
        ${ex.orderBy}
    </select>
    <select id="pagePartsRetV2" resultType="com.gree.mall.manager.bean.websit.WebsitPartsRetVO">
        select
        ${ex.selected}
        from
        websit_parts_ret a LEFT JOIN storage b ON a.storage_id = b.storage_id
        ${ex.query}

        <if test="companyWechatIds != null and companyWechatIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
                #{item}
            </foreach>

        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND (
            a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
            )
        </if>

        <if test="ex.orderBy == null or ex.orderBy ==''">
            order by a.create_time desc
        </if>
        ${ex.orderBy}
    </select>
    <select id="pageSettletV2" resultType="com.gree.mall.manager.bean.websit.SettlementOrderLogicVO">
        select
        ${ex.selected}
        from
        settlement_order a
        ${ex.query}

        <if test="companyWechatIds != null and companyWechatIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            order by a.create_time desc
        </if>
        ${ex.orderBy}
    </select>
    <select id="pageWithdrawalV2" resultType="com.gree.mall.manager.bean.websit.WithdrawalOrderVO">
        select
        ${ex.selected}
        from
        withdrawal_order a
        ${ex.query}

        <if test="companyWechatIds != null and companyWechatIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
                #{item}
            </foreach>


        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            order by a.create_time desc
        </if>
        ${ex.orderBy}
    </select>
    <select id="workerSettlementPageV2" resultType="com.gree.mall.manager.bean.websit.WorkerSettlementVO">
        SELECT
        ${ex.selected}
        FROM worker_settlement a
        ${ex.query}
        and a.type = 'OTHER'
        and a.pay_type = 'WECHAT'
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND (
            a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
            )
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="pageLineSettlementV2" resultType="com.gree.mall.manager.bean.websit.WorkerSettlementLineVO">
        SELECT
        ${ex.selected}
        FROM worker_settlement a
        ${ex.query}
        and a.type = 'OTHER'
        and a.pay_type = 'LINE'
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND (
            a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
            )
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY a.create_time DESC
        </if>
        ${ex.orderBy}
    </select>
    <select id="pagePartsFactoryRetV2" resultType="com.gree.mall.manager.bean.websit.WebsitPartsFactoryRetVO">
        select
        ${ex.selected}
        from
        websit_parts_ret a LEFT JOIN storage b ON a.storage_id = b.storage_id
        ${ex.query}
        and a.type = 'FACTORY'
        <if test="companyWechatIds != null and companyWechatIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
                #{item}
            </foreach>


        </if>

        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        <if test="ex.orderBy == null or ex.orderBy ==''">
            order by a.create_time desc
        </if>
        ${ex.orderBy}
    </select>

    <select id="pgOrderList" resultType="com.gree.mall.manager.bean.worker.SettlementPgOrderVO">
        SELECT
        d.belong_company,
        d.belong_company_code,
        d.websit_id,
        d.`name` as websit_name,
        d.link_name,
        d.link_mobile,
        b.worker_name,
        b.worker_number,
        b.worker_mobile,
        a.order_small_type_text
        FROM
        pg_order_worker b
        JOIN admin_websit d on  b.websit_id = d.websit_id
        JOIN pg_order_base a ON b.order_base_id = a.id and b.is_master = true   and a.order_status in ("YWG","GCSZX","WDWG","YWGO","YJS","LRCD")
        ${ex.query}
        <if test="overTime != null and overTime !=''">
            AND a.create_time between  #{overTime} and #{overEndTime}
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND d.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        GROUP BY
          b.worker_number,a.order_small_type,b.websit_id
    </select>
    <select id="pageV3" resultType="com.gree.mall.manager.bean.settle.SettlementWorkerLogicVO">
        select
        ${ex.selected}
        from
        settlement_order a
        join settlement_order_item b on a.settlement_order_id = b.settlement_order_id and b.charge_type != 'SERV'
        ${ex.query}

        <if test="value != null and value !=''">
            AND  (a.worker_name like concat('%',#{value},'%') or a.worker_mobile like concat('%',#{value},'%')
            or a.worker_number like concat('%',#{value},'%')
             )
        </if>

        <if test="companyWechatIds != null and companyWechatIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        <if test="orderBaseIds != null and orderBaseIds.size > 0">
            AND a.worker_order_id IN
            <foreach item="item" index="index" collection="orderBaseIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.orderBy == null or ex.orderBy ==''">
            order by a.create_time desc
        </if>
        ${ex.orderBy}
    </select>
    <select id="pageV4" resultType="com.gree.mall.manager.bean.settle.SettlementWorkerOrderVO">
        select
        a.websit_id,
        a.websit_name,
        a.worker_number,
        a.worker_name,
        a.worker_mobile,
        b.goods_name,
        SUM(b.total_amount) as all_total_amount,
        SUM(b.num) as all_num
        from
        settlement_order a
        join settlement_order_item b on a.settlement_order_id = b.settlement_order_id and b.charge_type != 'SERV'
        ${ex.query}

        <if test="value != null and value !=''">
            AND  (a.worker_name like concat('%',#{value},'%') or a.worker_mobile like concat('%',#{value},'%')
            or a.worker_number like concat('%',#{value},'%')
            )
        </if>

        <if test="companyWechatIds != null and companyWechatIds.size > 0">
            AND a.company_wechat_id IN
            <foreach item="item" index="index" collection="companyWechatIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>

        <if test="orderBaseIds != null and orderBaseIds.size > 0">
            AND a.worker_order_id IN
            <foreach item="item" index="index" collection="orderBaseIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="ex.adminWebsitIds != null and ex.adminWebsitIds.size > 0">
            AND a.websit_id IN
            <foreach item="item" index="index" collection="ex.adminWebsitIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        GROUP BY a.websit_id,a.worker_id,b.goods_name
        <if test="ex.orderBy == null or ex.orderBy ==''">
            order by a.create_time desc
        </if>
        ${ex.orderBy}
    </select>
</mapper>