<?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.superdesk.uniorder.dao.mapper.operationCenter.accounting.UnifiedAccountingOrderCreditMapperEx">
    <sql id="EXCEL_COLUMN">
        t.goods_id goodsId,
    </sql>
    <sql id="Count_Order_Credit_Column">
        t.id,
    t.order_sn orderSn ,
      t.biz_platform_name bizPlatformName,
    t1.operator_name operatorName,
    t1.buyer_id buyerId,
    t1.buyer_name buyerName,
    t1.buyer_mobile buyerMobile,
    t.order_type_name orderTypeName,
     t.biz_type_id orderBizTypeId,
    t.order_create_time orderCreateTime,
    t.trading_time tradingTime,
    t.finish_time finishTime,

     t.goods_id goodsId,
    t.goods_type_id goodsTypeId,
    t.goods_name goodsName,
    t.order_amount orderAmount,

    t.is_settlement isSettlement,

    t1.transaction_status_id transactionStatusId,

    t1.platform_pay_type platformPayType,

    t.integral_type_name integralTypeName,
    t.batch,

    t.org_name orgName,
    t.enterprise_name enterpriseName,
    t1.refund_origin_order_sn refundOriginOrderSn,
    t.accounting_status accountingStatus,



    t.accounting_order_sn_operator accountingOrderSnOperator,
        t1.operator_id operatorId,
        t1.org_id orgId,
        t1.enterprise_id enterpriseId,
        t1.biz_platform_code bizPlatformCode,
        t1.order_type_code order_type_code,
        t1.platform_pay_type_id  platformPayTypeId,
    t.update_time updateTime
    </sql>

    <sql id="COUNT_CREDIT_LIST_COLUMN">
        count(1) countRows,
    SUM(IFNULL(t.order_amount,0)) orderAmountCount
    </sql>

    <select id="getOrderCreditList"
            parameterType="cn.superdesk.uniorder.dto.param.operationCenter.order.OperationCenterOrderParam"
            resultType="cn.superdesk.uniorder.dto.vo.operationCenter.accounting.UnifiedAccountingOrderInfoVo">
        SELECT
        <choose>
            <!--  查询统计-->
            <when test="1 == flag">
                <include refid="COUNT_CREDIT_LIST_COLUMN"/>
            </when>

            <!--  默认查询列表-->
            <otherwise>
                <include refid="Count_Order_Credit_Column"/>
            </otherwise>

        </choose>

        FROM
        unified_accounting_order_credit t
        INNER JOIN
        unified_accounting_order t1
        ON
        t.order_sn =t1.order_sn
        where
        t1.deleted=0
        <!-- 对账状态  去掉 不对账 含未对账/对账中/已对账 -->
        and  t.accounting_status != 4
        <!-- 商品类型  商品和运费-->
        and   t.goods_type_id in (1,2)
        <include refid="cn.superdesk.uniorder.dao.mapper.operationCenter.accounting.UnifiedAccountingOrderGoodsMapperEx.getOpCenterOderListConditions"/>



        <!--    供应商过滤    -->
        <if test="supplierIds !=null and supplierIds != '' and supplierList !=null and supplierList.size>0">
            and (

            <foreach collection="supplierList" index="index" item="supplier" open="(" close=")" separator="or">
                t1.supplier_id=#{supplier.saleId} and t1.biz_platform_code=#{supplier.bizPlatformCode}

            </foreach>

            )
        </if>


        <choose>

            <!--  查询excel-->
            <when test="2 == flag">
                order by t.order_create_time
            </when>
            <!--  默认查询列表-->
            <otherwise>
                order by t.order_create_time desc
            </otherwise>

        </choose>
    </select>

</mapper>