<?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.hc.business.mapper.OrderRefundMapper">

    <resultMap type="com.hc.business.model.OrderRefund" id="OrderRefundMap">
        <result property="refundId" column="refund_id" jdbcType="INTEGER"/>
        <result property="orderId" column="order_id" jdbcType="INTEGER"/>
        <result property="totoalAmount" column="totoal_amount" jdbcType="NUMERIC"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="INTEGER"/>
        <result property="yewuTime" column="yewu_time" jdbcType="INTEGER"/>
        <result property="fincalTime" column="fincal_time" jdbcType="INTEGER"/>
        <result property="yewuNote" column="yewu_note" jdbcType="VARCHAR"/>
        <result property="fincalNote" column="fincal_note" jdbcType="VARCHAR"/>
        <result property="classId" column="class_id" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
            refund_id,
           order_id,
           totoal_amount,
           status,
           create_time,
           yewu_time,
           fincal_time,
           yewu_note,
           fincal_note,
           class_id,
           reason,
           remarks,
           refund_no
    </sql>
 <!-- 状态0审核中(新退费订单)，1拒绝，2通过，3处理完毕 4已处理订单（拒绝，通过，处理完毕） 5（2，3） null查全部 -->
    <select id="queryAll" resultType="com.hc.business.dto.OrderRefundEntityDto">
        SELECT
       a.refund_id,
        a.order_id,
        a.totoal_amount,
        a.status,
        a.create_time,
        a.yewu_time,
        a.fincal_time,
        a.yewu_note,
        a.fincal_note,
        a.class_id,
        cc.class_name,
        a.reason,
        a.remarks,
        a.refund_no,
        b.type  as payType
        FROM order_refund a
            join orders b on a.order_id=b.orders_id
        join class_config cc on b.class_id = cc.class_config_id
        where 1=1  and b.is_de = 1
        <if test="orderNo != null and orderNo!=''" >
            AND b.order_no = #{orderNo}
        </if>
        <if test="orderId != null">
            AND a.order_id = #{orderId}
        </if>
        <if test="begin != null">
            AND a.create_time  &gt;= #{begin}
        </if>
        <if test="end != null">
            AND a.create_time &lt;= #{end}
        </if>
        <if test="status != null and status!=4">
            AND status = #{status}
        </if>
        <if test="status != null and status==4">
            AND (status =2 or status=3)
        </if>
        <if test="status != null and status==5">
            AND (status =1 or status=2)
        </if>
        <if test="payType != null">
            AND b.type = #{payType}
        </if>
        <if test="classId != null">
            AND a.class_id = #{classId}
        </if>
        order by a.create_time desc
    </select>

    <!-- 状态0审核中(新退费订单)，1拒绝，2通过，3处理完毕 4已处理订单（拒绝，通过，处理完毕） 5（2，3） null查全部 -->
    <select id="queryHighAll" resultType="com.hc.business.dto.OrderRefundAllDto">
        SELECT
        b.order_no as orderNo,
        b.total_amount as orderAmount,
        b.create_time as payTime,
        b.type as payType,
        a.refund_no as refundNo,
        a.totoal_amount as refundAmount,
        a.create_time as refundTime,
        a.reason as refundReason,
        e.user_name as  userName,
        e.user_company as  userCompany,
        e.user_mobile as  userMobile,
        c.sync_status as syncStatus,
        c.tax_no as taxNo,
        c.tax_no_red as taxNoRed,
        a.fincal_time as fincalTime,
        d.class_name as className,
        a.status,a.remarks
        FROM order_refund a
        join orders b on a.order_id=b.orders_id
        join `user` e on b.user_id = e.user_id
        join class_config d on b.class_id =d.class_config_id
        left join user_invoices c on b.orders_id=c.order_id
        where 1=1 and b.is_de = 1
        <if test="orderNo != null and orderNo!=''" >
            AND b.order_no = #{orderNo}
        </if>
        <if test="orderId != null">
            AND a.order_id = #{orderId}
        </if>
        <if test="begin != null">
            AND a.create_time  &gt;= #{begin}
        </if>
        <if test="end != null">
            AND a.create_time &lt;= #{end}
        </if>
        <if test="status != null and status!=4">
            AND a.status = #{status}
        </if>
        <if test="status != null and status==4">
            AND (a.status =2 or a.status=3)
        </if>
        <if test="status != null and status==5">
            AND (a.status =1 or a.status=2)
        </if>
        <if test="payType != null">
            AND b.type = #{payType}
        </if>
        <if test="classId != null">
            AND a.class_id = #{classId}
        </if>
        order by a.create_time desc
    </select>

</mapper>
