<?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.style24.core.biz.dao.TscOrderChangeDao">

	<!-- 페이징을 위한 select절 상단 -->
	<sql id="selectForPagingHeader">
		SELECT *
		  FROM (
	</sql>

	<!-- 페이징을 위한 select절 하단 -->
	<sql id="selectForPagingFooter">
		) ORIGINAL
		WHERE NUMB BETWEEN #{pageable.startRow} AND #{pageable.endRow}
	</sql>

	<!-- 취소,반품,교환 대상목록 조회 -->
	<select id="getCancelRequestTargetList" parameterType="Order" resultType="Order">
		/* OrderChange.getCancelRequestTargetList */
		SELECT Y.*
		FROM (
		    SELECT Z.*
		         , DF.DELV_FEE
		      FROM (
		        SELECT OD.ORD_NO
		             , OD.ORD_DTL_NO
		             , OD.ORD_DTL_STAT
		             , FN_GET_CODE_NM('G013', OD.ORD_DTL_STAT)  AS ORD_DTL_STAT_NM
		             , CASE WHEN OD.ORD_DTL_STAT IN ('G013_20', 'G013_30', 'G013_40')
		                    THEN 'Y'
		                    ELSE 'N'
		               END                                      AS ALL_CAN_YN
		             , O.CUST_NO
		             , G1.GOODS_CD
		             , G1.GOODS_NM
		             , G1.GOODS_TYPE
		             , FN_GET_CODE_NM('G056', G1.GOODS_TYPE)    AS GOODS_TYPE_NM
		             , ODI.ORD_DTL_ITEM_SQ
		             , G2.GOODS_CD                              AS ITEM_CD
		             , G2.GOODS_NM                              AS ITEM_NM
		             , ODI.OPT_CD
		             , ODI.OPT_CD1
		             , ODI.OPT_CD2
		             , ODI.ITEM_QTY
		             , OD.ORD_QTY
		             , OD.CNCL_RTN_QTY
		             , CASE WHEN OCD.ORD_REQ_CHG_QTY IS NULL
		                    THEN 0
		                    ELSE OCD.ORD_REQ_CHG_QTY * ODI.ITEM_QTY
		               END                                      AS ORD_REQ_CHG_QTY
		             , ODI.ITEM_PRICE
		             , ODI.OPT_ADD_PRICE
		             , ODI.ORD_AMT
		             , ODI.CNCL_RTN_AMT
		             , ODI.CPN1_DC_AMT
		             , ODI.TMTB1_DC_AMT
		             , ODI.TMTB2_DC_AMT
		             , ODI.GOODS_CPN_DC_AMT
		             , ODI.CART_CPN_DC_AMT
		             , ODI.PNT_DC_AMT
		             , ODI.PRE_PNT_DC_AMT
		             , ODI.GFCD_USE_AMT
		             , ODI.REAL_ORD_AMT
		             , OD.SUPPLY_COMP_CD
		             , FN_GET_SUPPLY_COMP_NM(OD.SUPPLY_COMP_CD) AS SUPPLY_COMP_NM
		             , DFP.DELV_FEE_CRITE
		             , CASE DFP.DELV_FEE_CRITE WHEN 'G078_30' THEN 99999999
		                                       WHEN 'G078_20' THEN 0
		                                       ELSE DFP.MIN_ORD_AMT
		                END                                     AS MIN_ORD_AMT
		             , DFP.DELV_FEE                             AS ORG_DELV_FEE
		             , DFP.RTN_DELV_FEE
		             , DFP.RTN_DELV_FEE + DFP.RTN_DELV_FEE      AS EXC_DELV_FEE
		             , X.CHG_QTY                                AS ORD_CAN_CHG_QTY
		             , X.OPT_CD                                 AS ORD_CHG_OPT
		             , VS.OPT_CDS
		             , VS.OPT_CD2S
		             , VS.CURR_STOCK_QTYS
		             , G1.SELF_GOODS_YN
		             , CASE WHEN G1.SELF_GOODS_YN = 'Y'
		                    THEN 'WMS'
		                    ELSE OD.DELV_FEE_CD
		                     END DELV_FEE_CD
		             , X.CHG_GB
		          FROM TB_ORDER O
		         INNER JOIN TB_ORDER_DETAIL OD
		            ON O.ORD_NO = OD.ORD_NO
		         INNER JOIN TB_GOODS G1
		            ON OD.GOODS_CD = G1.GOODS_CD
		         INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		            ON OD.ORD_NO = ODI.ORD_NO
		           AND OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		         INNER JOIN TB_GOODS G2
		            ON ODI.ITEM_CD = G2.GOODS_CD
		          LEFT OUTER JOIN (
		              SELECT OD.ORD_DTL_NO
		                   , SUM(OCD.CHG_QTY) AS ORD_REQ_CHG_QTY
		                FROM TB_ORDER_CHANGE_DETAIL OCD
		               INNER JOIN TB_ORDER_DETAIL OD
		                  ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		               INNER JOIN TB_ORDER_CHANGE OC
		                  ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		               WHERE 1 = 1
		                 AND OD.ORD_NO = #{ordNo}
		                 AND OCD.DEL_YN = 'N'
		                 AND OCD.CHG_STAT IN ('G685_20', 'G685_21','G685_30', 'G685_31', 'G685_32', 'G685_33', 'G685_34', 'G685_50', 'G685_51')
		                 AND OC.WD_BF_SEND_YN = 'N'
		               GROUP BY OCD.ORD_DTL_NO
		          ) OCD
		            ON OD.ORD_DTL_NO = OCD.ORD_DTL_NO
		          LEFT OUTER JOIN TB_DELV_FEE_POLICY DFP
		            ON OD.DELV_FEE_CD = DFP.DELV_FEE_CD
		           AND OD.SUPPLY_COMP_CD = DFP.SUPPLY_COMP_CD
		           AND DFP.USE_YN = 'Y'
		          LEFT OUTER JOIN (
		              SELECT GOODS_CD
		                   , OPT_CD1
		                   , GROUP_CONCAT(OPT_CD ORDER BY DISP_ORD, OPT_CD2 SEPARATOR ',')                                 AS OPT_CDS
		                   , GROUP_CONCAT(OPT_CD2 ORDER BY DISP_ORD, OPT_CD2 SEPARATOR ',')                                AS OPT_CD2S
		                   , GROUP_CONCAT((CURR_STOCK_QTY - BASE_STOCK_QTY) ORDER BY DISP_ORD DESC, OPT_CD2 SEPARATOR ',') AS CURR_STOCK_QTYS
		                FROM VW_STOCK
		               WHERE GOODS_CD IN (SELECT ITEM_CD FROM TB_ORDER_DETAIL_ITEM WHERE ORD_NO = #{ordNo})
		               GROUP BY GOODS_CD
		                   , OPT_CD1
		          ) VS
		            ON ODI.ITEM_CD = VS.GOODS_CD
		           AND ODI.OPT_CD1 = VS.OPT_CD1
		          LEFT OUTER JOIN (
		              SELECT OCD.ORD_DTL_NO
		                   , OCD.CHG_QTY
		                   , ODI.OPT_CD
		                   , ODI.OPT_CD2
		                   , OC.CHG_GB
		                FROM TB_ORDER_CHANGE_DETAIL OCD
		               INNER JOIN TB_ORDER_CHANGE OC
		                  ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		               INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		                  ON OCD.ORD_DTL_NO = ODI.ORD_DTL_NO
		               WHERE OCD.DEL_YN = 'N'
		                 AND OCD.ORD_CHG_SQ = #{ordChgSq}
		          ) X
		            ON ODI.ORD_DTL_NO = X.ORD_DTL_NO
		           AND ODI.OPT_CD = X.OPT_CD
		         WHERE 1 = 1
		<if test="ordDtlStatArr != null and ordDtlStatArr != ''">
		           AND OD. ORD_DTL_STAT IN
			<foreach collection="ordDtlStatArr" item="item" index="index"  open="(" close=")" separator=",">
					#{item}
			</foreach>
		</if>
		<if test="ordDtlNoArr != null and ordDtlNoArr != ''">
		           AND OD.ORD_DTL_NO IN
			<foreach collection="ordDtlNoArr" item="item" index="index"  open="(" close=")" separator=",">
					#{item}
			</foreach>
		</if>
		           AND OD.ORD_NO = #{ordNo}
		<choose>
			<when test="chgGb == 'G680_30'">
		           AND OD.RETURNABLE_YN = 'Y'
			</when>
			<when test="chgGb == 'G680_40'">
		           AND OD.CHANGEABLE_YN = 'Y'
			</when>
		</choose>          
		    ) Z
		    INNER JOIN (
		        SELECT X.DELV_FEE_CD
		             , SUM(X.DELV_FEE) AS DELV_FEE
		          FROM TB_DELIVERY_FEE X
		         WHERE 1 = 1
		           AND X.ORD_NO = #{ordNo}
		           AND X.DELV_FEE_GB = 'G018_10'
		         GROUP BY X.DELV_FEE_CD
		    ) DF
		    ON Z.DELV_FEE_CD = DF.DELV_FEE_CD
		    AND Z.DELV_FEE_CD = #{delvFeeCdGrp}
		) Y
		 GROUP BY Y.ORD_NO, Y.ORD_DTL_NO, Y.ORD_DTL_STAT, Y.ORD_DTL_STAT_NM, Y.ALL_CAN_YN, Y.GOODS_CD, Y.GOODS_NM, Y.GOODS_TYPE, Y.GOODS_TYPE_NM
		        , Y.ORD_DTL_ITEM_SQ, Y.ITEM_CD, Y.ITEM_NM, Y.OPT_CD, Y.OPT_CD1, Y.OPT_CD2, Y.ITEM_QTY, Y.ORD_QTY, Y.CNCL_RTN_QTY, Y.ORD_REQ_CHG_QTY
		        , Y.ITEM_PRICE, Y.OPT_ADD_PRICE, Y.ORD_AMT, Y.CNCL_RTN_AMT, Y.CPN1_DC_AMT, Y.TMTB1_DC_AMT, Y.TMTB2_DC_AMT, Y.GOODS_CPN_DC_AMT
		        , Y.CART_CPN_DC_AMT, Y.PNT_DC_AMT, Y.PRE_PNT_DC_AMT, Y.GFCD_USE_AMT, Y.REAL_ORD_AMT, Y.DELV_FEE, Y.SUPPLY_COMP_CD, Y.SUPPLY_COMP_NM
		        , Y.DELV_FEE_CD, Y.DELV_FEE_CRITE, Y.MIN_ORD_AMT, Y.ORG_DELV_FEE, Y.RTN_DELV_FEE, Y.EXC_DELV_FEE, Y.ORD_CAN_CHG_QTY, Y.ORD_CHG_OPT
		        , Y.OPT_CD2S, Y.CURR_STOCK_QTYS, Y.SELF_GOODS_YN, Y.CHG_GB
		 ORDER BY Y.DELV_FEE_CD, Y.ORD_NO, Y.ORD_DTL_NO
	</select>

	<!-- 취소,반품,교환 대상목록 조회 -->
	<select id="getCancelRequestTargetList2" parameterType="Order" resultType="Order">
		/* OrderChange.getCancelRequestTargetList2 */
		SELECT Z.*
		     , DF.DELV_FEE
		FROM (
		    SELECT A.ORD_NO
		         , A.ORD_DTL_NO
		         , A.ORD_DTL_STAT
		         , A.ORD_DTL_STAT_NM
		         , A.ALL_CAN_YN
		         , A.GOODS_CD
		         , A.GOODS_NM
		         , A.GOODS_TYPE
		         , A.GOODS_TYPE_NM
		         , GROUP_CONCAT(A.ITEM_CD ORDER BY A.ORD_DTL_ITEM_SQ) AS ITEM_CD
		         , GROUP_CONCAT(A.ITEM_NM ORDER BY A.ORD_DTL_ITEM_SQ) AS ITEM_NM
		         , GROUP_CONCAT(A.OPT_CD ORDER BY A.ORD_DTL_ITEM_SQ) AS OPT_CD
		         , GROUP_CONCAT(A.OPT_CD1 ORDER BY A.ORD_DTL_ITEM_SQ) AS OPT_CD1
		         , GROUP_CONCAT(A.OPT_CD2 ORDER BY A.ORD_DTL_ITEM_SQ) AS OPT_CD2
		         , GROUP_CONCAT(A.ITEM_QTY ORDER BY A.ORD_DTL_ITEM_SQ) AS ITEM_QTYR
		         , GROUP_CONCAT(A.COLOR_NM ORDER BY A.ORD_DTL_ITEM_SQ) AS COLOR_NM
		         , A.LIST_PRICE
		         , A.CURR_PRICE
		         , SUM(A.OPT_ADD_PRICE) AS OPT_ADD_PRICE
		         , A.ORD_QTY
		         , A.CNCL_RTN_QTY
		         , A.ORD_REQ_CHG_QTY
		         , A.CPN1_DC_AMT
		         , A.ORD_AMT
		         , A.CNCL_RTN_AMT
		         , A.TMTB1_DC_AMT
		         , A.TMTB2_DC_AMT
		         , A.GOODS_CPN_DC_AMT
		         , A.CART_CPN_DC_AMT
		         , A.PRE_PNT_DC_AMT
		         , A.PNT_DC_AMT
		         , A.GFCD_USE_AMT
		         , A.REAL_ORD_AMT
		         , A.SUPPLY_COMP_CD
		         , A.SUPPLY_COMP_NM
		         , A.DELV_FEE_CRITE
		         , A.MIN_ORD_AMT
		         , A.ORG_DELV_FEE
		         , A.RTN_DELV_FEE
		         , A.EXC_DELV_FEE
		         , A.SELF_GOODS_YN
		         , A.DELV_FEE_CD
		         , A.ORD_CAN_CHG_QTY
		         , A.CHG_STAT
		         , A.WD_GB
		         , A.ADD_PAY_COST
		         , A.DELV_FAIL_REASON
		    FROM (
		        SELECT OD.ORD_NO
		             , OD.ORD_DTL_NO
		             , OD.ORD_DTL_STAT
		             , FN_GET_CODE_NM('G013', OD.ORD_DTL_STAT)  AS ORD_DTL_STAT_NM
		             , CASE WHEN OD.ORD_DTL_STAT IN ('G013_10', 'G013_20', 'G013_30')
		                    THEN 'Y'
		                    ELSE 'N'
		                    END  ALL_CAN_YN
		             , G1.GOODS_CD
		             , G1.GOODS_NM
		             , G1.GOODS_TYPE
		             , FN_GET_CODE_NM('G056', G1.GOODS_TYPE)    AS GOODS_TYPE_NM
		             , ODI.ORD_DTL_ITEM_SQ
		             , ODI.ITEM_CD
		             , G2.GOODS_NM AS ITEM_NM
		             , ODI.OPT_CD
		             , ODI.OPT_CD1
		             , ODI.OPT_CD2
		             , ODI.ITEM_QTY
		             , IFNULL((SELECT COLOR_KNM FROM TB_COLOR WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,'') , G1.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		             , OD.LIST_PRICE
		             , OD.CURR_PRICE
		             , ODI.OPT_ADD_PRICE
		             , OD.ORD_QTY
		             , OD.CNCL_RTN_QTY
		             , IFNULL(OCD.ORD_REQ_CHG_QTY, 0) AS ORD_REQ_CHG_QTY
		             , OD.CPN1_DC_AMT
		             , OD.ORD_AMT
		             , OD.CNCL_RTN_AMT
		             , OD.TMTB1_DC_AMT
		             , OD.TMTB2_DC_AMT
		             , OD.GOODS_CPN_DC_AMT
		             , OD.CART_CPN_DC_AMT
		             , OD.PRE_PNT_DC_AMT
		             , OD.PNT_DC_AMT
		             , OD.GFCD_USE_AMT
		             , OD.REAL_ORD_AMT
		             , OD.SUPPLY_COMP_CD
		             , FN_GET_SUPPLY_COMP_NM(OD.SUPPLY_COMP_CD) AS SUPPLY_COMP_NM
		             , DFP.DELV_FEE_CRITE
		             , CASE DFP.DELV_FEE_CRITE WHEN 'G078_30' THEN 99999999
		                                       WHEN 'G078_20' THEN 0
		                                       ELSE DFP.MIN_ORD_AMT
		                END AS MIN_ORD_AMT
		             , DFP.DELV_FEE AS ORG_DELV_FEE
		             , DFP.RTN_DELV_FEE
		             , DFP.RTN_DELV_FEE + DFP.RTN_DELV_FEE AS EXC_DELV_FEE
		             , G1.SELF_GOODS_YN
		             , CASE WHEN G1.SELF_GOODS_YN = 'Y'
		                    THEN 'WMS'
		                    ELSE OD.DELV_FEE_CD
		                    END  DELV_FEE_CD
		             , CASE WHEN X.CHG_STAT IS NOT NULL 
		                    THEN X.CHG_QTY
		                    ELSE Y.CNCL_RTN_QTY
		                    END ORD_CAN_CHG_QTY
		             , CASE WHEN X.CHG_STAT IS NOT NULL 
		                    THEN X.CHG_STAT
		                    ELSE Y.CHG_STAT
		                    END CHG_STAT
		             , Y.WD_GB
		             , Y.ADD_PAY_COST
		             , Y.DELV_FAIL_REASON
		        FROM   TB_ORDER_DETAIL OD
		        INNER  JOIN TB_GOODS G1
		        ON     OD.GOODS_CD = G1.GOODS_CD
		        INNER  JOIN TB_ORDER_DETAIL_ITEM ODI
		        ON     OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		        INNER  JOIN TB_GOODS G2
		        ON     ODI.ITEM_CD = G2.GOODS_CD
		        LEFT   OUTER JOIN (
		            SELECT OCD.ORD_DTL_NO
		                 , SUM(OCD.CHG_QTY) AS ORD_REQ_CHG_QTY
		            FROM   TB_ORDER_CHANGE_DETAIL OCD
		            INNER  JOIN TB_ORDER_DETAIL OD
		            ON     OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		            INNER  JOIN TB_ORDER_CHANGE OC
		            ON     OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		            WHERE  1=1
		            AND    OD.ORD_NO = #{ordNo}
		            AND    OCD.DEL_YN = 'N'
		            AND    OCD.CHG_STAT IN ('G685_10', 'G685_11','G685_20', 'G685_21', 'G685_30', 'G685_31', 'G685_32', 'G685_33', 'G685_50', 'G685_51')
		            AND    OC.WD_BF_SEND_YN = 'N'
		            GROUP  BY OCD.ORD_DTL_NO
		        ) OCD
		        ON     OD.ORD_DTL_NO = OCD.ORD_DTL_NO
		        LEFT   OUTER JOIN TB_DELV_FEE_POLICY DFP
		        ON     OD.DELV_FEE_CD = DFP.DELV_FEE_CD
		        AND    OD.SUPPLY_COMP_CD = DFP.SUPPLY_COMP_CD
		        AND    DFP.USE_YN = 'Y'
		        LEFT OUTER JOIN (
		            SELECT OCD.ORD_DTL_NO
		                 , OCD.CHG_QTY
		                 , OCD.CHG_STAT
		              FROM TB_ORDER_CHANGE_DETAIL OCD
		             WHERE OCD.DEL_YN = 'N'
		               AND OCD.ORD_CHG_SQ = #{ordChgSq}
		        ) X
		        ON OD.ORD_DTL_NO = X.ORD_DTL_NO
		        LEFT OUTER JOIN (
		            SELECT EDF.ORD_DTL_NO
		                 , EDF.CNCL_RTN_QTY
		                 , OCD.CHG_STAT
		                 , OC.WD_GB
		                 , OC.ADD_PAY_COST
		                 , EDF.DELV_FAIL_REASON
		              FROM TB_EXCHANGE_DELV_FAIL EDF
		             INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		                ON EDF.ORD_DTL_NO = OCD.CHG_ORD_DTL_NO
		             INNER JOIN TB_ORDER_CHANGE OC
		                ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		             WHERE OCD.DEL_YN = 'N'
		               AND OCD.ORD_CHG_SQ = #{ordChgSq}
		               AND EDF.DELV_CNCL_YN = 'N'
		        ) Y
		        ON OD.ORD_DTL_NO = Y.ORD_DTL_NO
		        WHERE  1=1
		        AND    OD.ORD_NO = #{ordNo}
		        <if test="ordDtlStatArr != null and ordDtlStatArr != ''">
		        AND OD. ORD_DTL_STAT IN
					<foreach collection="ordDtlStatArr" item="item" index="index"  open="(" close=")" separator=",">
		            #{item}
					</foreach>
				</if>
				<if test="ordDtlNoArr != null and ordDtlNoArr != ''">
		        AND OD.ORD_DTL_NO IN
					<foreach collection="ordDtlNoArr" item="item" index="index"  open="(" close=")" separator=",">
		            #{item}
					</foreach>
				</if>
				<choose>
					<when test="chgGb == 'G680_30'">
		        AND    OD.RETURNABLE_YN = 'Y'
					</when>
					<when test="chgGb == 'G680_40'">
		        AND    OD.CHANGEABLE_YN = 'Y'
					</when>
				</choose>
		    ) A
		    GROUP  BY A.ORD_NO
		         , A.ORD_DTL_NO
		         , A.ORD_DTL_STAT
		         , A.ORD_DTL_STAT_NM
		         , A.ALL_CAN_YN
		         , A.GOODS_CD
		         , A.GOODS_NM
		         , A.GOODS_TYPE
		         , A.GOODS_TYPE_NM
		         , A.LIST_PRICE
		         , A.CURR_PRICE
		         , A.ORD_QTY
		         , A.CNCL_RTN_QTY
		         , A.ORD_REQ_CHG_QTY
		         , A.CPN1_DC_AMT
		         , A.ORD_AMT
		         , A.CNCL_RTN_AMT
		         , A.TMTB1_DC_AMT
		         , A.TMTB2_DC_AMT
		         , A.GOODS_CPN_DC_AMT
		         , A.CART_CPN_DC_AMT
		         , A.PRE_PNT_DC_AMT
		         , A.PNT_DC_AMT
		         , A.GFCD_USE_AMT
		         , A.REAL_ORD_AMT
		         , A.SUPPLY_COMP_CD
		         , A.SUPPLY_COMP_NM
		         , A.DELV_FEE_CRITE
		         , A.MIN_ORD_AMT
		         , A.ORG_DELV_FEE
		         , A.RTN_DELV_FEE
		         , A.EXC_DELV_FEE
		         , A.SELF_GOODS_YN
		         , A.DELV_FEE_CD
		         , A.ORD_CAN_CHG_QTY
		         , A.CHG_STAT
		         , A.WD_GB
		         , A.ADD_PAY_COST
		         , A.DELV_FAIL_REASON
		) Z
		INNER  JOIN (
		    SELECT X.DELV_FEE_CD
		         , SUM(X.DELV_FEE) AS DELV_FEE
		    FROM   TB_DELIVERY_FEE X
		    WHERE  1=1
		    AND    X.ORD_NO = #{ordNo}
		    AND    X.DELV_FEE_GB = 'G018_10'
		    GROUP  BY X.DELV_FEE_CD
		) DF
		ON     Z.DELV_FEE_CD = DF.DELV_FEE_CD
		WHERE  1=1
		AND    Z.DELV_FEE_CD = #{delvFeeCdGrp}
		ORDER  BY Z.DELV_FEE_CD
		     , Z.ORD_NO
		     , Z.ORD_DTL_NO
	</select>

	<!-- 주문변경신청목록 조회 (취소, 반품, 교환) -->
	<select id="getOrderChangeDetailList" parameterType="Order" resultType="Order">
		/* order.getOrderChangeDetailList */
		SELECT OCD.ORD_CHG_SQ
		     , OCD.ORD_DTL_NO
		     , OC.CHG_GB
		     , FN_GET_CODE_NM('G680', OC.CHG_GB)       AS CHG_GB_NM
		     , OD.GOODS_CD
		     , OD.NPAY_ORD_DTL_NO
		     , ODI.OPT_CD1
		     , ODI.OPT_CD2
		     , OCD.CHG_STAT
		     , FN_GET_CODE_NM('G685', OCD.CHG_STAT)    AS CHG_STAT_NM
		     , OCD.CHG_QTY
		     , DATE_FORMAT(OCD.REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		     , OC.CHG_REASON
		     , CASE WHEN OC.CHG_GB = 'G680_20' THEN FN_GET_CODE_NM('G686', OC.CHG_REASON)
		            WHEN OC.CHG_GB = 'G680_30' THEN FN_GET_CODE_NM('G688', OC.CHG_REASON)
		            WHEN OC.CHG_GB = 'G680_40' THEN FN_GET_CODE_NM('G689', OC.CHG_REASON)
		            ELSE '결제전취소'
		       END                                     AS CHG_REASON_NM
		     , CASE WHEN OC.CHG_MEMO IS NULL
		            THEN ''
		            ELSE OC.CHG_MEMO
		            END                                AS CHG_MEMO
		     , OC.CHGER_NM
		     , OC.CHGER_PHNNO
		     , OC.CHGER_ZIPCODE
		     , OC.CHGER_BASE_ADDR
		     , OC.CHGER_DTL_ADDR
		     , OC.CHGER_RTN_MEMO
		     , OC.WD_INVOICE_SEND_YN
		     , OC.WD_INVOICE_NO
		     , OC.WD_GB
		     , OC.WD_BF_SEND_YN
		     , CASE WHEN OC.WD_SHIP_STATE = '12' AND WD_REASON_CD IN ('14', '16', '18', '21', '25') THEN 'Y'
		            ELSE 'N'
		        END                                    AS CAN_REQUEST_CANCEL_YN
		     , OC.NPAY_CHANGE_HOLD_YN
		  FROM TB_ORDER_CHANGE_DETAIL OCD
		 INNER JOIN TB_ORDER_CHANGE OC
		    ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		 INNER JOIN (
		      SELECT X.ORD_DTL_ITEM_SQ
		           , X.ORD_DTL_NO
		           , X.ITEM_CD
		           , X.OPT_CD
		           , X.OPT_CD1
		           , X.OPT_CD2
		        FROM TB_ORDER_DETAIL_ITEM X
		       WHERE X.ORD_NO = #{ordNo}
		       LIMIT 1
		 ) ODI
		 WHERE 1 = 1
		   AND OD.ORD_NO = #{ordNo}
		<if test='ordChgSq != null and ordChgSq != ""'>
		   AND OCD.ORD_CHG_SQ = #{ordChgSq}
		</if>
		   AND OCD.DEL_YN = 'N'
		 ORDER BY OC.ORD_CHG_SQ, OCD.ORD_DTL_NO 
	</select>

	<!-- 주문상세단품정보 수정 -->
	<update id="updateOrderDetailItem" parameterType="Order">
		/* OrderChange.updateOrderDetailItem */
		UPDATE TB_ORDER_DETAIL_ITEM
		   SET CNCL_RTN_AMT     = #{cnclRtnAmt}
		     , CPN1_DC_AMT      = #{cpn1DcAmt}
		     , TMTB1_DC_AMT     = #{tmtb1DcAmt}
		     , TMTB2_DC_AMT     = #{tmtb2DcAmt}
		     , GOODS_CPN_DC_AMT = #{goodsCpnDcAmt}
		     , CART_CPN_DC_AMT  = #{cartCpnDcAmt}
		     , PRE_PNT_DC_AMT   = #{prePntDcAmt}
		     , PNT_DC_AMT       = #{pntDcAmt}
		     , REAL_ORD_AMT     = #{realOrdAmt}
		     , GFCD_USE_AMT     = #{gfcdUseAmt}
		     , SAVE_PNT_AMT     = #{savePntAmt}
		     , UPD_NO           = #{updNo}
		     , UPD_DT           = NOW()
		 WHERE ORD_NO = #{ordNo}
		   AND ORD_DTL_NO = #{ordDtlNo}
		   AND ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
	</update>
	
	<!-- 2021.08.20 주문상세단품정보(교환결제완료용) 수정 -->
	<update id="updateOrderDetailItemExchPay" parameterType="Order">
		/* OrderChange.updateOrderDetailItemExchPay */
		UPDATE TB_ORDER_DETAIL_ITEM
		   SET ORD_AMT          = #{ordAmt}
		     , CNCL_RTN_AMT     = #{cnclRtnAmt}
		     , CPN1_DC_AMT      = #{cpn1DcAmt}
		     , TMTB1_DC_AMT     = #{tmtb1DcAmt}
		     , TMTB2_DC_AMT     = #{tmtb2DcAmt}
		     , GOODS_CPN_DC_AMT = #{goodsCpnDcAmt}
		     , CART_CPN_DC_AMT  = #{cartCpnDcAmt}
		     , PRE_PNT_DC_AMT   = #{prePntDcAmt}
		     , PNT_DC_AMT       = #{pntDcAmt}
		     , REAL_ORD_AMT     = #{realOrdAmt}
		     , GFCD_USE_AMT     = #{gfcdUseAmt}
		     , SAVE_PNT_AMT     = #{savePntAmt}
		     , UPD_NO           = #{updNo}
		     , UPD_DT           = NOW()
		 WHERE ORD_NO = #{ordNo}
		   AND ORD_DTL_NO = #{ordDtlNo}
		   AND ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
	</update>

	<!-- 주문상세단품정보 수정 -->
	<update id="updateOrderDetailItemForExchange" parameterType="Order">
		/* TscOrderChange.updateOrderDetailItemForExchange */
		UPDATE TB_ORDER_DETAIL_ITEM
		   SET CNCL_RTN_AMT     = CNCL_RTN_AMT + #{cnclRtnAmt}
			 , CPN1_DC_AMT      = CPN1_DC_AMT - #{cpn1DcAmt}
			 , TMTB1_DC_AMT     = TMTB1_DC_AMT - #{tmtb1DcAmt}
			 , TMTB2_DC_AMT     = TMTB2_DC_AMT - #{tmtb2DcAmt}
			 , GOODS_CPN_DC_AMT = GOODS_CPN_DC_AMT - #{goodsCpnDcAmt}
			 , CART_CPN_DC_AMT  = CART_CPN_DC_AMT - #{cartCpnDcAmt}
			 , PNT_DC_AMT       = PNT_DC_AMT - #{pntDcAmt}
			 , PRE_PNT_DC_AMT   = PRE_PNT_DC_AMT - #{prePntDcAmt}
			 , SAVE_PNT_AMT     = SAVE_PNT_AMT - #{savePntAmt}
			 , REAL_ORD_AMT     = REAL_ORD_AMT - #{realOrdAmt}
			 , GFCD_USE_AMT     = GFCD_USE_AMT - #{gfcdUseAmt}
			 , UPD_NO           = #{updNo}
			 , UPD_DT           = NOW()
		 WHERE ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
	</update>

	<!-- 주문상세단품이력정보 등록 -->
	<insert id="createOrderDetailItemHst" parameterType="Order">
		/* OrderChange.createOrderDetailItemHst */
		INSERT INTO TB_ORDER_DETAIL_ITEM_HST (
		       ORD_DTL_ITEM_SQ
		     , ORD_DTL_NO
		     , ORD_NO
		     , ORD_DTL_STAT
		     , ITEM_CD
		     , OPT_CD
		     , OPT_CD1
		     , OPT_CD2
		     , SKU_MODEL_NO
		     , PRODUCT_NO
		     , PRODUCT_CODE
		     , ITEM_QTY
		     , ITEM_PRICE
		     , OPT_ADD_PRICE
		     , DISP_ORD
		     , ORD_AMT
		     , ORD_QTY
		     , CNCL_RTN_AMT
		     , CNCL_RTN_QTY
		     , CPN1_DC_AMT
		     , TMTB1_DC_AMT
		     , TMTB2_DC_AMT
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_DC_AMT
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , ORD_CHG_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT ODI.ORD_DTL_ITEM_SQ
		     , ODI.ORD_DTL_NO
		     , ODI.ORD_NO
		     , #{ordDtlStat}
		     , ODI.ITEM_CD
		     , ODI.OPT_CD
		     , ODI.OPT_CD1
		     , ODI.OPT_CD2
		     , ODI.SKU_MODEL_NO
		     , ODI.PRODUCT_NO
		     , ODI.PRODUCT_CODE
		     , ODI.ITEM_QTY
		     , ODI.ITEM_PRICE
		     , ODI.OPT_ADD_PRICE
		     , ODI.DISP_ORD
		     , ODI.ORD_AMT
		     , OD.ORD_QTY
		     , #{cnclRtnAmt} - ODI.CNCL_RTN_AMT
		     , #{cnclRtnQty}
		     , ODI.CPN1_DC_AMT - #{cpn1DcAmt}
		     , ODI.TMTB1_DC_AMT - #{tmtb1DcAmt}
		     , ODI.TMTB2_DC_AMT - #{tmtb2DcAmt}
		     , ODI.GOODS_CPN_DC_AMT - #{goodsCpnDcAmt}
		     , ODI.CART_CPN_DC_AMT - #{cartCpnDcAmt}
		     , ODI.PNT_DC_AMT - #{pntDcAmt}
		     , ODI.PRE_PNT_DC_AMT - #{prePntDcAmt}
		     , ODI.SAVE_PNT_AMT - #{savePntAmt}
		     , ODI.REAL_ORD_AMT - #{realOrdAmt}
		     , ODI.GFCD_USE_AMT - #{gfcdUseAmt}
		     , #{ordChgSq}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL_ITEM ODI
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		 WHERE ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
	</insert>
	
	<!-- 상품옵션재고정보 등록 -->
	<update id="createSellQty" parameterType="OrderChange">
		/* OrderChange.createSellQty */
		INSERT INTO TB_SELL_QTY (
		       GOODS_CD
		     , OPT_CD
		     , SELL_GB
		     , ORD_DTL_NO
		     , ORD_CHG_SQ
		     , AGENT_ORDER_ID
		     , EXTMALL_ORDER_ID
		     , SELL_QTY
		     , REG_NO
		     , REG_DT
		)
		SELECT ODI.ITEM_CD
		     , ODI.OPT_CD
		     , #{sellGb}
		     , ODI.ORD_DTL_NO
		     , OCD.ORD_CHG_SQ
		     , OD.AGENT_ORDER_ID
		     , OD.EXTMALL_ORDER_ID
		     , OCD.CHG_QTY * ODI.ITEM_QTY AS SELL_QTY
		     , #{regNo}
		     , NOW()
		  FROM TB_ORDER_CHANGE_DETAIL OCD
		 INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		    ON OCD.ORD_DTL_NO = ODI.ORD_DTL_NO
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		 WHERE 1 = 1
		   AND ORD_CHG_SQ = #{ordChgSq}
	</update>
	
	<!-- 주문변경정보 등록 -->
	<insert id="createOrderChange" parameterType="OrderChange" keyProperty="ordChgSq">
		/* TscOrderChange.createOrderChange */
		INSERT INTO TB_ORDER_CHANGE (
		       CHG_GB
		     , CHG_REASON
		     , CHG_MEMO
		     , WD_GB
		     , WD_TARGET_YN
		     , CHGER_NM
		     , CHGER_PHNNO
		     , CHGER_TELNO
		     , CHGER_EMAIL
		     , CHGER_ZIPCODE
		     , CHGER_BASE_ADDR
		     , CHGER_DTL_ADDR
		     , CHGER_RTN_MEMO
		     , ADD_PAY_COST
		     , ADD_PAY_AMT
		     , WD_INVOICE_NO
		     , SHIP_COMP_CD
		     , WD_BF_SEND_YN
		     , NPAY_CHANGE_HOLD_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		) values (
		       #{chgGb}
		     , #{chgReason}
		     , #{chgMemo}
		     , #{wdGb}
		     , IFNULL(NULLIF(#{wdTargetYn}, ''), 'Y')
		     , #{chgerNm}
		     , #{chgerPhnno}
		     , #{chgerTelno}
		     , #{chgerEmail}
		     , #{chgerZipcode}
		     , #{chgerBaseAddr}
		     , #{chgerDtlAddr}
		     , #{chgerRtnMemo}
		     , #{addPayCost}
		     , #{addPayAmt}
		     , #{wdInvoiceNo}
		     , #{shipCompCd}
		     , IFNULL(NULLIF(#{wdBfSendYn}, ''), 'N')
		     , #{npayChangeHoldYn}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
	</insert>
	
	<!-- 주문변경상세정보 등록-->
	<insert id="createOrderChangeDetail" parameterType="OrderChange">
		/* OrderChange.createOrderChangeDetail */
		INSERT INTO TB_ORDER_CHANGE_DETAIL (
		       ORD_CHG_SQ
		     , ORD_DTL_NO
		     , CHG_QTY
		     , CHG_STAT
		     , CHG_ORD_DTL_NO
		     , COMPLETE_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		) VALUES (
		       #{ordChgSq}
		     , #{ordDtlNo}
		     , #{chgQty}
		     , #{chgStat}
		     , #{chgOrdDtlNo}
		     ,
		<choose>
			<when test="chgStat == 'G685_17' or chgStat == 'G685_18'">
		       NOW()
			</when>
			<otherwise>
		       NULL
			</otherwise>
		</choose>
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
	</insert>

	<!-- 주문변경상세정보이력 등록-->
	<insert id="createOrderChangeDetailHst" parameterType="OrderChange">
		/* OrderChange.createOrderChangeDetailHst */
		INSERT INTO TB_ORDER_CHANGE_DETAIL_HST (
		       ORD_CHG_SQ
		     , ORD_DTL_NO
		     , CHG_QTY
		     , CHG_STAT
		     , CHG_ORD_DTL_NO
		     , WH_MEMO
		     , COMPLETE_DT
		     , DEL_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT ORD_CHG_SQ
		     , ORD_DTL_NO
		     , CHG_QTY
		     , #{chgStat}
		     , CHG_ORD_DTL_NO
		     , WH_MEMO
		     , COMPLETE_DT
		     , DEL_YN
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER_CHANGE_DETAIL
		 WHERE ORD_CHG_SQ = #{ordChgSq}
		   AND ORD_DTL_NO = #{ordDtlNo}
	</insert>

	<!-- 주문상세단품정보 수정 -->
	<update id="updateOrderDetail" parameterType="Order">
		/* OrderChange.updateOrderDetail */
		UPDATE TB_ORDER_DETAIL OD
		   SET OD.ORD_DTL_STAT     = CASE WHEN OD.ORD_QTY > (OD.CNCL_RTN_QTY + #{ordCanChgQty}) THEN OD.ORD_DTL_STAT
		                                  ELSE #{ordDtlStat}
		                              END
		     , OD.CNCL_RTN_QTY     = OD.CNCL_RTN_QTY + #{ordCanChgQty}
		     , OD.CNCL_RTN_AMT     = OD.CNCL_RTN_AMT + #{cnclRtnAmt}
		     , OD.CPN1_DC_AMT      = OD.CPN1_DC_AMT - #{cpn1DcAmt}
		     , OD.TMTB1_DC_AMT     = OD.TMTB1_DC_AMT - #{tmtb1DcAmt}
		     , OD.TMTB2_DC_AMT     = OD.TMTB2_DC_AMT - #{tmtb2DcAmt}
		     , OD.GOODS_CPN_DC_AMT = OD.GOODS_CPN_DC_AMT - #{goodsCpnDcAmt}
		     , OD.CART_CPN_DC_AMT  = OD.CART_CPN_DC_AMT - #{cartCpnDcAmt}
		     , OD.PNT_DC_AMT       = OD.PNT_DC_AMT - #{pntDcAmt}
		     , OD.PRE_PNT_DC_AMT   = OD.PRE_PNT_DC_AMT - #{prePntDcAmt}
		     , OD.SAVE_PNT_AMT     = OD.SAVE_PNT_AMT - #{savePntAmt}
		     , OD.REAL_ORD_AMT     = OD.REAL_ORD_AMT - #{realOrdAmt}
		     , OD.GFCD_USE_AMT     = OD.GFCD_USE_AMT - #{gfcdUseAmt}
		     , OD.UPD_NO           = #{updNo}
		     , OD.UPD_DT           = NOW()
		 WHERE OD.ORD_NO = #{ordNo}
		   AND OD.ORD_DTL_NO = #{ordDtlNo}
	</update>

	<!-- 주문상세이력정보 (취소,반품) 등록 -->
	<insert id="createOrderDetailHstCnclRtn" parameterType="Order">
		/* OrderChange.createOrderDetailHstCnclRtn */
		INSERT INTO TB_ORDER_DETAIL_HST (
		       ORD_DTL_NO
		     , ORD_NO
		     , ORD_EXCH_GB
		     , ORD_DTL_STAT
		     , ORG_ORD_DTL_NO
		     , SUPPLY_COMP_CD
		     , GOODS_CD
		     , FORMAL_GB
		     , GOODS_TYPE
		     , LIST_PRICE
		     , CURR_PRICE
		     , DC_RATE
		     , OPT_ADD_PRICE
		     , ORD_QTY
		     , ORD_AMT
		     , CNCL_RTN_QTY
		     , CNCL_RTN_AMT
		     , CPN1_CPN_SQ
		     , CPN1_DC_AMT
		     , TMTB1_SQ
		     , TMTB1_DC_AMT
		     , TMTB2_SQ
		     , TMTB2_DC_AMT
		     , GOODS_CPN_SQ
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_SQ
		     , CART_CPN_DC_AMT
		     , BURDEN_RATE
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , VENDOR_ID
		     , EXTMALL_ID
		     , AGENT_ORDER_ID
		     , EXTMALL_ORDER_ID
		     , CHANGEABLE_YN
		     , CHANGE_FEE_FREE_YN
		     , RETURNABLE_YN
		     , RETURN_FEE_FREE_YN
		     , SOLDOUT_YN
		     , SOLDOUT_MEMO
		     , SOLDOUT_REG_NO
		     , SOLDOUT_REG_DT
		     , DELV_ADDR_SQ
		     , DELV_FEE_CD
		     , SHOT_DELV_YN
		     , GIFT_PACK_YN
		     , MAKE_GOODS_YN
		     , ENTRY_NO
		     , DELV_LOC_CD
		     , DELV_ASSIGN_DT
		     , DELV_ASSIGN_STAT
		     , DSTRBT_NOTE
		     , DELV_STDT
		     , DELV_EDDT
		     , SHIP_COMP_CD
		     , INVOICE_NO
		     , INVOICE_SEND_YN
		     , SELL_STORE_CD
		     , SELL_FEE_RATE
		     , AF_LINK_CD
		     , ITHR_CD
		     , CONTENTS_LOC
		     , PLAN_DTL_SQ
		     , SOCIAL_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT OD.ORD_DTL_NO
		     , OD.ORD_NO
		     , OD.ORD_EXCH_GB
		     , #{ordDtlStat}
		     , OD.ORG_ORD_DTL_NO
		     , OD.SUPPLY_COMP_CD
		     , OD.GOODS_CD
		     , OD.FORMAL_GB
		     , OD.GOODS_TYPE
		     , OD.LIST_PRICE
		     , OD.CURR_PRICE
		     , OD.DC_RATE
		     , OD.OPT_ADD_PRICE
		     , OD.ORD_QTY
		     , OD.ORD_AMT
		     , OD.CNCL_RTN_QTY
		     , OD.CNCL_RTN_AMT
		     , OD.CPN1_CPN_SQ
		     , OD.CPN1_DC_AMT
		     , OD.TMTB1_SQ
		     , OD.TMTB1_DC_AMT
		     , OD.TMTB2_SQ
		     , OD.TMTB2_DC_AMT
		     , OD.GOODS_CPN_SQ
		     , OD.GOODS_CPN_DC_AMT
		     , OD.CART_CPN_SQ
		     , OD.CART_CPN_DC_AMT
		     , OD.BURDEN_RATE
		     , OD.PNT_DC_AMT
		     , OD.PRE_PNT_DC_AMT
		     , OD.SAVE_PNT_AMT
		     , OD.REAL_ORD_AMT
		     , OD.GFCD_USE_AMT
		     , OD.VENDOR_ID
		     , OD.EXTMALL_ID
		     , OD.AGENT_ORDER_ID
		     , OD.EXTMALL_ORDER_ID
		     , OD.CHANGEABLE_YN
		     , OD.CHANGE_FEE_FREE_YN
		     , OD.RETURNABLE_YN
		     , OD.RETURN_FEE_FREE_YN
		     , OD.SOLDOUT_YN
		     , OD.SOLDOUT_MEMO
		     , OD.SOLDOUT_REG_NO
		     , OD.SOLDOUT_REG_DT
		     , OD.DELV_ADDR_SQ
		     , OD.DELV_FEE_CD
		     , OD.SHOT_DELV_YN
		     , OD.GIFT_PACK_YN
		     , OD.MAKE_GOODS_YN
		     , OD.ENTRY_NO
		     , OD.DELV_LOC_CD
		     , OD.DELV_ASSIGN_DT
		     , OD.DELV_ASSIGN_STAT
		     , OD.DSTRBT_NOTE
		     , OD.DELV_STDT
		     , OD.DELV_EDDT
		     , OD.SHIP_COMP_CD
		     , OD.INVOICE_NO
		     , OD.INVOICE_SEND_YN
		     , OD.SELL_STORE_CD
		     , OD.SELL_FEE_RATE
		     , OD.AF_LINK_CD
		     , OD.ITHR_CD
		     , OD.CONTENTS_LOC
		     , OD.PLAN_DTL_SQ
		     , OD.SOCIAL_SQ
		     , #{regNo}            AS REG_ID
		     , NOW()               AS REG_DT
		     , #{regNo}            AS REG_ID
		     , NOW()               AS UPD_DT
		  FROM TB_ORDER_DETAIL OD
		 WHERE OD.ORD_DTL_NO = #{ordDtlNo}
	</insert>

	<!-- 주문환불금액정보(PG) 등록 -->
	<insert id="createPayment" parameterType="Order" keyProperty="paySq">
		/* OrderChange.createPayment */
		INSERT INTO TB_PAYMENT (
		       ORD_NO
		     , PAY_DT
		     , PAY_MEANS
		     , PAY_AMT
		     , PG_CPN_AMT
		     , NPAY_PNT_AMT
		     , PAY_GB
		     , PAY_STAT
		     , PG_GB
		     , PG_TID
		     , PG_TRADE_NO
		     , PG_SHOP_ID
		     , CARD_TYPE
		     , CARD_KIND
		     , CARD_BANK
		     , CARD_NM
		     , CARD_MIPS
		     , CARD_PCABLE_YN
		     , VA_NO
		     , VA_NM
		     , VA_BANK
		     , VA_DEADLINE
		     , TELECOM
		     , ESCROW_YN
		     , ORD_CHG_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT ORD_NO
		     , NOW()
		     , PAY_MEANS
		     , #{payAmt}
		     , #{pgCpnAmt}
		     , #{npayPntAmt}
		     , PAY_GB
		     , #{payStat}
		     , PG_GB
		     , #{pgTid}
		     , #{pgTradeNo}
		     , PG_SHOP_ID
		     , CARD_TYPE
		     , CARD_KIND
		     , CARD_BANK
		     , CARD_NM
		     , CARD_MIPS
		     , CARD_PCABLE_YN
		     , #{vaNo}
		     , #{vaNm}
		     , #{vaBank}
		     , #{vaDeadline}
		     , TELECOM
		     , ESCROW_YN
		     , #{ordChgSq}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_PAYMENT
		 WHERE 1 = 1
		   AND ORD_NO = #{ordNo}
		   AND PAY_GB = 'O'
		   AND PAY_STAT = 'G016_30'
	</insert>
	
	<!-- 주문환불정보 등록 -->
	<insert id="createRefund" parameterType="Order">
		/* TscOrderChange.createRefund */
		INSERT INTO TB_REFUND (
		       ORD_NO
		     , PAY_SQ
		     , ORD_CHG_SQ
		     , REFUND_AMT
		     , DEPOSIT_AMT
		     , RA_NO
		     , RA_BANK
		     , RA_NM
		     , RF_CPN1_AMT
		     , RF_TMTB1_AMT
		     , RF_TMTB2_AMT
		     , RF_GOODS_CPN_AMT
		     , RF_CART_CPN_AMT
		     , RF_DELV_CPN_AMT
		     , RF_PNT_AMT
		     , RF_PRE_PNT_AMT
		     , RF_GFCD_USE_AMT
		     , RF_DELV_GFCD_USE_AMT
		     , RF_CNCL_AMT
		     , RF_DELIVERY_FEE
		     , RF_REAL_CNCL_AMT
		     , REG_NO
		     , REG_DT
		) VALUES (
		       #{ordNo}
		     , #{paySq}
		     , #{ordChgSq}
		     , #{refundAmt}
		     , #{depositAmt}
		     , #{raNo}
		     , #{raBank}
		     , #{raNm}
		     , #{rfCpn1Amt}
		     , #{rfTmtb1Amt}
		     , #{rfTmtb2Amt}
		     , #{rfGoodsCpnAmt}
		     , #{rfCartCpnAmt}
		     , #{rfDelvCpnAmt}
		     , #{rfPntAmt}
		     , #{rfPrePntAmt}
		     , #{rfGfcdUseAmt}
		     , #{rfDelvGfcdUseAmt}
		     , #{rfCnclAmt}
		     , #{rfDeliveryFee}
		     , #{rfRealCnclAmt}
		     , #{regNo}
		     , NOW()
		)
	</insert>

	<!-- 주문추가배송금액 등록 -->
	<insert id="createDeliveryFee" parameterType="Order">
		/* OrderChange.createDeliveryFee */
		INSERT INTO TB_DELIVERY_FEE ( 
		       PAY_SQ
		     , ORD_NO
		     , DELV_FEE_GB
		     , DELV_FEE_CD
		     , DELV_FEE
		     , DELV_CPN_SQ
		     , DELV_CPN_DC_AMT
		     , DELV_GFCD_USE_AMT
		     , REAL_DELV_AMT
		     , ORD_CHG_SQ
		     , SUPPLY_COMP_CD
		     , DELV_USAC_YN
		     , DELV_USAC_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		) VALUES (
		       #{paySq}
		     , #{ordNo}
		     , #{delvFeeGb}
		     , #{delvFeeCd}
		     , #{delvFee}
		     , #{delvCpnSq}
		     , #{delvCpnDcAmt}
		     , #{delvGfcdUseAmt}
		     , #{realDelvAmt}
		     , #{ordChgSq}
		     , #{supplyCompCd}
		     , 'N'
		     , null
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
	</insert>

	<!-- 배송비 환불금액 수정 -->
	<update id="updateDeliveryFee" parameterType="Order">
		/* OrderChange.updateDeliveryFee */
		UPDATE TB_DELIVERY_FEE
		   SET ORD_CHG_SQ = #{ordChgSq}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		 WHERE ORD_NO = #{ordNo}
		   AND ORD_CHG_SQ = #{orgOrdChgSq}
		   AND DELV_FEE_GB = #{delvFeeGb}
	</update>

	<!-- 주문사은품전체취소 -->
	<update id="updateOrdFreegiftDel" parameterType="Order">
		/* OrderChange.updateOrdFreegiftDel */
		UPDATE TB_ORD_FREEGIFT OFG
		 INNER JOIN TB_ORD_FREEGIFT_VAL OFGV
		    ON OFGV.ORD_FREEGIFT_SQ = OFG.ORD_FREEGIFT_SQ
		   SET OFG.DEL_YN= 'Y'
		     , OFG.UPD_NO = #{updNo}
		     , OFG.UPD_DT = NOW()
		 WHERE OFG.ORD_NO = #{ordNo}
	</update>

	<!-- 주문사은품전체취소(백업)
	<update id="updateOrdFreegiftDel" parameterType="Order">
		/* OrderChange.updateOrdFreegiftDel */
		UPDATE TB_ORD_FREEGIFT_VAL
		   SET DEL_YN= 'Y'
			 , UPD_NO = #{updNo}
			 , UPD_DT = NOW()
		 WHERE FREEGIFT_VAL_SQ IN (
			 SELECT Z.FREEGIFT_VAL_SQ
			   FROM (
				   SELECT OFRV.FREEGIFT_VAL_SQ
					 FROM TB_ORD_FREEGIFT OFR
					 INNER JOIN TB_ORD_FREEGIFT_VAL OFRV
					 ON OFR.ORD_FREEGIFT_SQ = OFRV.ORD_FREEGIFT_SQ
					WHERE 1 = 1
					  AND OFR.ORD_NO = (SELECT CASE WHEN SUM(X.ORD_QTY) > SUM(X.CNCL_RTN_QTY)
														THEN 0
													ELSE X.ORD_NO
											   END
										  FROM TB_ORDER_DETAIL X
										 WHERE 1 = 1
										   AND X.ORD_NO = #{ordNo})
			   ) Z
		 )
	</update>
	 -->

	<!-- 주문상세 > 주문취소 > 고객환불계좌정보 조회 -->
	<select id="getRefundAccount" parameterType="Order" resultType="Order">
		/* OrderChange.getRefundAccount */
		SELECT Z.ACCOUNT_NO
		     , Z.ACCOUNT_NM
		     , Z.BANK_CD
		     , FN_GET_CODE_NM('G940', Z.BANK_CD) AS BANK_NM
		     , Z.DEFAULT_YN
		     , Z.REG_DT
		  FROM (
		      SELECT CA.ACCOUNT_NO
		           , CA.ACCOUNT_NM
		           , CA.BANK_CD
		           , CA.DEFAULT_YN
		           , CA.REG_DT
		        FROM TB_ORDER O
		        LEFT OUTER JOIN TB_CUST_ACCOUNT CA
		          ON O.CUST_NO = CA.CUST_NO
		       WHERE 1 = 1
		<if test="custNo > 0">
		         AND O.CUST_NO = #{custNo}
		</if>
		<if test="ordNo > 0">
		         AND O.ORD_NO = #{ordNo}
		</if>
		       GROUP BY CA.ACCOUNT_NO, CA.ACCOUNT_NM, CA.BANK_CD, CA.DEFAULT_YN, CA.REG_DT
		       ORDER BY CA.DEFAULT_YN DESC, CA.REG_DT DESC
		  ) Z
	</select>
	
	<!-- 주문상세 > 주문취소 > 고객환불계좌정보 중복체크 -->
	<select id="getRefundAccountCheck" parameterType="Order" resultType="int">
		/* OrderChange.getRefundAccountCheck */
		SELECT COUNT(1)
		  FROM TB_CUST_ACCOUNT CA
		 WHERE 1 = 1
		   AND CA.ACCOUNT_NO = #{encodedAccountNo}
		   AND CA.ACCOUNT_NM = #{accountNm}
		   AND CA.BANK_CD = #{bankCd}
		   AND CA.DEL_YN = 'N'
	</select>
	
	<!-- 주문상세 > 주문취소 > 고객환불계좌정보 등록 -->
	<insert id="saveRefundAccount" parameterType="Order">
		/* OrderChange.saveRefundAccount */
		INSERT INTO TB_CUST_ACCOUNT (
		       CUST_NO
		     , BANK_CD
		     , ACCOUNT_NO
		     , ACCOUNT_NM
		     , DEFAULT_YN
		     , DEL_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		) VALUES (
		       #{custNo}
		     , #{bankCd}
		     , #{encodedAccountNo}
		     , #{accountNm}
		     , 'N'
		     , 'N'
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
	</insert>
	
	<!-- 고객환불계좌정보 존재유무 -->
	<select id="getCustAccountChk" parameterType="Order" resultType="int">
		/* OrderChange.getCustAccountChk */
		SELECT COUNT(1)
		  FROM TB_CUST_ACCOUNT CA
		 WHERE 1=1
		   AND CA.CUST_NO = #{custNo}
	</select>
	
	<!-- 고객환불계좌정보 수정 -->
	<update id="updateRefundAccount" parameterType="Order">
		/* OrderChange.updateRefundAccount */
		UPDATE TB_CUST_ACCOUNT CA
		SET    BANK_CD = #{bankCd}
		     , ACCOUNT_NO = #{encodedAccountNo}
		     , ACCOUNT_NM = #{accountNm}
		     , UPD_NO = #{regNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    CA.CUST_NO = #{custNo}
	</update>
	
	<!-- 고객환불계좌정보 삭제 -->
	<delete id="deleteRefundAccount" parameterType="Integer">
		/* OrderChange.deleteRefundAccount */
		DELETE FROM TB_CUST_ACCOUNT
		WHERE  CUST_NO = #{custNo}
	</delete>
	
	<!-- 주문변경상세정보 취소신청철회 -->
	<update id="updateOrderChangeDtlCancel" parameterType="Order">
		/* OrderChange.updateOrderChangeDtlCancel */
		UPDATE TB_ORDER_CHANGE_DETAIL
		   SET CHG_STAT = #{chgStat}
		     , DEL_YN   = #{delYn}
		     , UPD_NO   = #{updNo}
		     , UPD_DT   = NOW()
		 WHERE 1 = 1
		   AND ORD_CHG_SQ = #{ordChgSq}
	</update>
	
	<!-- 주문상세이력정보등록 취소신청철회 -->
	<insert id="createOrderDtlHstCancel" parameterType="Order">
		/* OrderChange.createOrderDtlHstCancel */
		INSERT INTO TB_ORDER_DETAIL_HST (
		       ORD_DTL_NO
		     , ORD_NO
		     , ORD_EXCH_GB
		     , ORD_DTL_STAT
		     , ORG_ORD_DTL_NO
		     , SUPPLY_COMP_CD
		     , GOODS_CD
		     , FORMAL_GB
		     , GOODS_TYPE
		     , LIST_PRICE
		     , CURR_PRICE
		     , DC_RATE
		     , OPT_ADD_PRICE
		     , ORD_QTY
		     , ORD_AMT
		     , CNCL_RTN_QTY
		     , CNCL_RTN_AMT
		     , CPN1_CPN_SQ
		     , CPN1_DC_AMT
		     , TMTB1_SQ
		     , TMTB1_DC_AMT
		     , TMTB2_SQ
		     , TMTB2_DC_AMT
		     , GOODS_CPN_SQ
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_SQ
		     , CART_CPN_DC_AMT
		     , BURDEN_RATE
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , VENDOR_ID
		     , EXTMALL_ID
		     , AGENT_ORDER_ID
		     , EXTMALL_ORDER_ID
		     , CHANGEABLE_YN
		     , CHANGE_FEE_FREE_YN
		     , RETURNABLE_YN
		     , RETURN_FEE_FREE_YN
		     , SOLDOUT_YN
		     , SOLDOUT_MEMO
		     , SOLDOUT_REG_NO
		     , SOLDOUT_REG_DT
		     , DELV_ADDR_SQ
		     , DELV_FEE_CD
		     , SHOT_DELV_YN
		     , GIFT_PACK_YN
		     , MAKE_GOODS_YN
		     , ENTRY_NO
		     , DELV_LOC_CD
		     , DELV_ASSIGN_DT
		     , DELV_ASSIGN_STAT
		     , DSTRBT_NOTE
		     , DELV_STDT
		     , DELV_EDDT
		     , SHIP_COMP_CD
		     , INVOICE_NO
		     , INVOICE_SEND_YN
		     , SELL_STORE_CD
		     , SELL_FEE_RATE
		     , AF_LINK_CD
		     , ITHR_CD
		     , CONTENTS_LOC
		     , PLAN_DTL_SQ
		     , SOCIAL_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT OD.ORD_DTL_NO
		     , OD.ORD_NO
		     , OD.ORD_EXCH_GB
		     , OD.ORD_DTL_STAT
		     , OD.ORG_ORD_DTL_NO
		     , OD.SUPPLY_COMP_CD
		     , OD.GOODS_CD
		     , OD.FORMAL_GB
		     , OD.GOODS_TYPE
		     , OD.LIST_PRICE
		     , OD.CURR_PRICE
		     , OD.DC_RATE
		     , OD.OPT_ADD_PRICE
		     , OD.ORD_QTY
		     , OD.ORD_AMT
		     , OCD.CHG_QTY
		     , OD.CNCL_RTN_AMT
		     , OD.CPN1_CPN_SQ
		     , OD.CPN1_DC_AMT
		     , OD.TMTB1_SQ
		     , OD.TMTB1_DC_AMT
		     , OD.TMTB2_SQ
		     , OD.TMTB2_DC_AMT
		     , OD.GOODS_CPN_SQ
		     , OD.GOODS_CPN_DC_AMT
		     , OD.CART_CPN_SQ
		     , OD.CART_CPN_DC_AMT
		     , OD.BURDEN_RATE
		     , OD.PNT_DC_AMT
		     , OD.PRE_PNT_DC_AMT
		     , OD.SAVE_PNT_AMT
		     , OD.REAL_ORD_AMT
		     , OD.GFCD_USE_AMT
		     , OD.VENDOR_ID
		     , OD.EXTMALL_ID
		     , OD.AGENT_ORDER_ID
		     , OD.EXTMALL_ORDER_ID
		     , OD.CHANGEABLE_YN
		     , OD.CHANGE_FEE_FREE_YN
		     , OD.RETURNABLE_YN
		     , OD.RETURN_FEE_FREE_YN
		     , OD.SOLDOUT_YN
		     , OD.SOLDOUT_MEMO
		     , OD.SOLDOUT_REG_NO
		     , OD.SOLDOUT_REG_DT
		     , OD.DELV_ADDR_SQ
		     , OD.DELV_FEE_CD
		     , OD.SHOT_DELV_YN
		     , OD.GIFT_PACK_YN
		     , OD.MAKE_GOODS_YN
		     , OD.ENTRY_NO
		     , OD.DELV_LOC_CD
		     , OD.DELV_ASSIGN_DT
		     , OD.DELV_ASSIGN_STAT
		     , OD.DSTRBT_NOTE
		     , OD.DELV_STDT
		     , OD.DELV_EDDT
		     , OD.SHIP_COMP_CD
		     , OD.INVOICE_NO
		     , OD.INVOICE_SEND_YN
		     , OD.SELL_STORE_CD
		     , OD.SELL_FEE_RATE
		     , OD.AF_LINK_CD
		     , OD.ITHR_CD
		     , OD.CONTENTS_LOC
		     , OD.PLAN_DTL_SQ
		     , OD.SOCIAL_SQ
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL OD
		 INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		    ON OD.ORD_DTL_NO = OCD.CHG_ORD_DTL_NO
		 WHERE 1 = 1
		   AND OCD.ORD_CHG_SQ = #{ordChgSq}
		   AND OD.ORD_NO = #{ordNo}
	</insert>

	<!-- 주문상세정보 생성 -->
	<insert id="createOrderDetailForExchange" parameterType="Order">
		/* order.createOrderDetailForExchange */
		<selectKey keyProperty="exchangeOrdDtlNo" resultType="int" order="AFTER">
		    SELECT LAST_INSERT_ID()
		</selectKey>

		INSERT INTO TB_ORDER_DETAIL(
		       ORD_NO
		     , ORD_EXCH_GB
		     , ORD_DTL_STAT
		     , ORG_ORD_DTL_NO
		     , FIRST_ORD_DTL_NO
		     , SUPPLY_COMP_CD
		     , GOODS_CD
		     , FORMAL_GB
		     , GOODS_TYPE
		     , LIST_PRICE
		     , CURR_PRICE
		     , DC_RATE
		     , OPT_ADD_PRICE
		     , ORD_QTY
		     , ORD_AMT
		     , CNCL_RTN_QTY
		     , CNCL_RTN_AMT
		     , CPN1_CPN_SQ
		     , CPN1_DC_AMT
		     , TMTB1_SQ
		     , TMTB1_DC_AMT
		     , TMTB2_SQ
		     , TMTB2_DC_AMT
		     , GOODS_CPN_SQ
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_SQ
		     , CART_CPN_DC_AMT
		     , BURDEN_RATE
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , VENDOR_ID
		     , EXTMALL_ID
		     , AGENT_ORDER_ID
		     , EXTMALL_ORDER_ID
		     , CHANGEABLE_YN
		     , CHANGE_FEE_FREE_YN
		     , RETURNABLE_YN
		     , RETURN_FEE_FREE_YN
		     , SOLDOUT_YN
		     , SOLDOUT_MEMO
		     , SOLDOUT_REG_NO
		     , SOLDOUT_REG_DT
		     , DELV_ADDR_SQ
		     , DELV_FEE_CD
		     , SHOT_DELV_YN
		     , GIFT_PACK_YN
		     , MAKE_GOODS_YN
		     , ENTRY_NO
		     , DELV_LOC_CD
		     , DELV_ASSIGN_DT
		     , DELV_ASSIGN_STAT
		     , DSTRBT_NOTE
		     , DELV_STDT
		     , DELV_EDDT
		     , SHIP_COMP_CD
		     , INVOICE_NO
		     , INVOICE_SEND_YN
		     , SELL_STORE_CD
		     , SELL_FEE_RATE
		     , AF_LINK_CD
		     , ITHR_CD
		     , CONTENTS_LOC
		     , PLAN_DTL_SQ
		     , SOCIAL_SQ
		     , NPAY_ORD_DTL_NO
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT ORD_NO
		     , 'E'
		     , #{ordDtlStat}
		     , ORD_DTL_NO
		     , FIRST_ORD_DTL_NO
		     , SUPPLY_COMP_CD
		     , GOODS_CD
		     , FORMAL_GB
		     , GOODS_TYPE
		     , LIST_PRICE
		     , CURR_PRICE
		     , DC_RATE
		     , OPT_ADD_PRICE
		     , #{chgQty}
		     , #{cnclRtnAmt}
		     , 0
		     , 0
		     , CPN1_CPN_SQ
		     , #{cpn1DcAmt}
		     , TMTB1_SQ
		     , #{tmtb1DcAmt}
		     , TMTB2_SQ
		     , #{tmtb2DcAmt}
		     , 0
		     , #{goodsCpnDcAmt}
		     , 0
		     , #{cartCpnDcAmt}
		     , BURDEN_RATE
		     , #{pntDcAmt}
		     , #{prePntDcAmt}
		     , #{savePntAmt}
		     , #{realOrdAmt}
		     , #{gfcdUseAmt}
		     , VENDOR_ID
		     , EXTMALL_ID
		     , AGENT_ORDER_ID
		     , EXTMALL_ORDER_ID
		     , CHANGEABLE_YN
		     , CHANGE_FEE_FREE_YN
		     , RETURNABLE_YN
		     , RETURN_FEE_FREE_YN
		     , SOLDOUT_YN
		     , SOLDOUT_MEMO
		     , SOLDOUT_REG_NO
		     , SOLDOUT_REG_DT
		     , #{delvAddrSq}
		     , DELV_FEE_CD
		     , SHOT_DELV_YN
		     , GIFT_PACK_YN
		     , MAKE_GOODS_YN
		     , ENTRY_NO
		     , NULL
		     , NULL
		     , 'P'
		     , NULL
		     , NULL
		     , NULL
		     , NULL
		     , NULL
		     , 'N'
		     , SELL_STORE_CD
		     , SELL_FEE_RATE
		     , AF_LINK_CD
		     , ITHR_CD
		     , CONTENTS_LOC
		     , PLAN_DTL_SQ
		     , SOCIAL_SQ
		     , NPAY_ORD_DTL_NO
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL
		 WHERE ORD_DTL_NO = #{ordDtlNo}
	</insert>

	<!-- 주문상세정보 이력 생성 -->
	<insert id="createOrderDetailHstForExchange" parameterType="Order">
		/* order.createOrderDetailHstForExchange */
		INSERT INTO TB_ORDER_DETAIL_HST (
		       ORD_DTL_NO
		     , ORD_NO
		     , ORD_EXCH_GB
		     , ORD_DTL_STAT
		     , ORG_ORD_DTL_NO
		     , SUPPLY_COMP_CD
		     , GOODS_CD
		     , FORMAL_GB
		     , GOODS_TYPE
		     , LIST_PRICE
		     , CURR_PRICE
		     , DC_RATE
		     , OPT_ADD_PRICE
		     , ORD_QTY
		     , ORD_AMT
		     , CNCL_RTN_QTY
		     , CNCL_RTN_AMT
		     , CPN1_CPN_SQ
		     , CPN1_DC_AMT
		     , TMTB1_SQ
		     , TMTB1_DC_AMT
		     , TMTB2_SQ
		     , TMTB2_DC_AMT
		     , GOODS_CPN_SQ
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_SQ
		     , CART_CPN_DC_AMT
		     , BURDEN_RATE
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , VENDOR_ID
		     , EXTMALL_ID
		     , AGENT_ORDER_ID
		     , EXTMALL_ORDER_ID
		     , CHANGEABLE_YN
		     , CHANGE_FEE_FREE_YN
		     , RETURNABLE_YN
		     , RETURN_FEE_FREE_YN
		     , SOLDOUT_YN
		     , SOLDOUT_MEMO
		     , SOLDOUT_REG_NO
		     , SOLDOUT_REG_DT
		     , DELV_ADDR_SQ
		     , DELV_FEE_CD
		     , SHOT_DELV_YN
		     , GIFT_PACK_YN
		     , MAKE_GOODS_YN
		     , ENTRY_NO
		     , DELV_LOC_CD
		     , DELV_ASSIGN_DT
		     , DELV_ASSIGN_STAT
		     , DSTRBT_NOTE
		     , DELV_STDT
		     , DELV_EDDT
		     , SHIP_COMP_CD
		     , INVOICE_NO
		     , INVOICE_SEND_YN
		     , SELL_STORE_CD
		     , SELL_FEE_RATE
		     , AF_LINK_CD
		     , ITHR_CD
		     , CONTENTS_LOC
		     , PLAN_DTL_SQ
		     , SOCIAL_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT ORD_DTL_NO
		     , ORD_NO
		     , ORD_EXCH_GB
		     , ORD_DTL_STAT
		     , ORG_ORD_DTL_NO
		     , SUPPLY_COMP_CD
		     , GOODS_CD
		     , FORMAL_GB
		     , GOODS_TYPE
		     , LIST_PRICE
		     , CURR_PRICE
		     , DC_RATE
		     , OPT_ADD_PRICE
		     , ORD_QTY
		     , ORD_AMT
		     , CNCL_RTN_QTY
		     , CNCL_RTN_AMT
		     , CPN1_CPN_SQ
		     , CPN1_DC_AMT
		     , TMTB1_SQ
		     , TMTB1_DC_AMT
		     , TMTB2_SQ
		     , TMTB2_DC_AMT
		     , GOODS_CPN_SQ
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_SQ
		     , CART_CPN_DC_AMT
		     , BURDEN_RATE
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , VENDOR_ID
		     , EXTMALL_ID
		     , AGENT_ORDER_ID
		     , EXTMALL_ORDER_ID
		     , CHANGEABLE_YN
		     , CHANGE_FEE_FREE_YN
		     , RETURNABLE_YN
		     , RETURN_FEE_FREE_YN
		     , SOLDOUT_YN
		     , SOLDOUT_MEMO
		     , SOLDOUT_REG_NO
		     , SOLDOUT_REG_DT
		     , DELV_ADDR_SQ
		     , DELV_FEE_CD
		     , SHOT_DELV_YN
		     , GIFT_PACK_YN
		     , MAKE_GOODS_YN
		     , ENTRY_NO
		     , DELV_LOC_CD
		     , DELV_ASSIGN_DT
		     , DELV_ASSIGN_STAT
		     , DSTRBT_NOTE
		     , DELV_STDT
		     , DELV_EDDT
		     , SHIP_COMP_CD
		     , INVOICE_NO
		     , INVOICE_SEND_YN
		     , SELL_STORE_CD
		     , SELL_FEE_RATE
		     , AF_LINK_CD
		     , ITHR_CD
		     , CONTENTS_LOC
		     , PLAN_DTL_SQ
		     , SOCIAL_SQ
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL
		 WHERE ORD_DTL_NO = #{exchangeOrdDtlNo} 
	</insert>

	<!-- 주문상세단품정보 생성 -->
	<insert id="createOrderDetailItemForExchange" parameterType="Order" keyProperty="exchangeOrdDtlItemSq">
		/* order.createOrderDetailItemForExchange */
		<selectKey keyProperty="exchangeOrdDtlItemSq" resultType="int" order="AFTER">
		    SELECT LAST_INSERT_ID()
		</selectKey>

		INSERT INTO TB_ORDER_DETAIL_ITEM (
		       ORD_DTL_NO
		     , ORD_NO
		     , ORD_DTL_STAT
		     , ITEM_CD
		     , OPT_CD
		     , OPT_CD1
		     , OPT_CD2
		     , SKU_MODEL_NO
		     , PRODUCT_NO
		     , PRODUCT_CODE
		     , ITEM_QTY
		     , ITEM_PRICE
		     , OPT_ADD_PRICE
		     , DISP_ORD
		     , ORD_AMT
		     , CNCL_RTN_AMT
		     , CPN1_DC_AMT
		     , TMTB1_DC_AMT
		     , TMTB2_DC_AMT
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_DC_AMT
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT #{ordDtlNo}
		     , ODI.ORD_NO
		     , #{ordDtlStat}
		     , ODI.ITEM_CD
		     , OP.OPT_CD
		     , OP.OPT_CD1
		     , OP.OPT_CD2
		     , OP.SKU_MODEL_NO
		     , OP.PRODUCT_NO
		     , OP.PRODUCT_CODE
		     , ODI.ITEM_QTY
		     , ODI.ITEM_PRICE
		     , ODI.OPT_ADD_PRICE
		     , ODI.DISP_ORD
		     , #{ordAmt}
		     , #{cnclRtnAmt}
		     , #{cpn1DcAmt}
		     , #{tmtb1DcAmt}
		     , #{tmtb2DcAmt}
		     , #{goodsCpnDcAmt}
		     , #{cartCpnDcAmt}
		     , #{pntDcAmt}
		     , #{prePntDcAmt}
		     , #{savePntAmt}
		     , #{realOrdAmt}
		     , #{gfcdUseAmt}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL_ITEM ODI
		 INNER JOIN TB_GOODS G
		    ON ODI.ITEM_CD = G.GOODS_CD
		 INNER JOIN TB_OPTION OP
		    ON G.GOODS_CD = OP.GOODS_CD
		   AND OP.OPT_CD = #{ordChgOpt}
		   AND OP.DISP_YN = 'Y'
		 WHERE ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
	</insert>

	<!-- 주문상세단품정보 이력 생성 -->
	<insert id="createOrderDetailItemHstForExchange" parameterType="Order">
		/* order.createOrderDetailItemHstForExchange */
		INSERT INTO TB_ORDER_DETAIL_ITEM_HST (
		       ORD_DTL_ITEM_SQ
		     , ORD_DTL_NO
		     , ORD_NO
		     , ORD_DTL_STAT
		     , ITEM_CD
		     , OPT_CD
		     , OPT_CD1
		     , OPT_CD2
		     , SKU_MODEL_NO
		     , PRODUCT_NO
		     , PRODUCT_CODE
		     , ITEM_QTY
		     , ITEM_PRICE
		     , OPT_ADD_PRICE
		     , DISP_ORD
		     , ORD_AMT
		     , ORD_QTY
		     , CNCL_RTN_AMT
		     , CNCL_RTN_QTY
		     , CPN1_DC_AMT
		     , TMTB1_DC_AMT
		     , TMTB2_DC_AMT
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_DC_AMT
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT ODI.ORD_DTL_ITEM_SQ
		     , ODI.ORD_DTL_NO
		     , ODI.ORD_NO
		     , #{ordDtlStat}
		     , ODI.ITEM_CD
		     , ODI.OPT_CD
		     , ODI.OPT_CD1
		     , ODI.OPT_CD2
		     , ODI.SKU_MODEL_NO
		     , ODI.PRODUCT_NO
		     , ODI.PRODUCT_CODE
		     , ODI.ITEM_QTY
		     , ODI.ITEM_PRICE
		     , ODI.OPT_ADD_PRICE
		     , ODI.DISP_ORD
		     , ODI.ORD_AMT
		     , OD.ORD_QTY
		     , ODI.CNCL_RTN_AMT
		     , OD.CNCL_RTN_QTY
		     , ODI.CPN1_DC_AMT
		     , ODI.TMTB1_DC_AMT
		     , ODI.TMTB2_DC_AMT
		     , ODI.GOODS_CPN_DC_AMT
		     , ODI.CART_CPN_DC_AMT
		     , ODI.PNT_DC_AMT
		     , ODI.PRE_PNT_DC_AMT
		     , ODI.SAVE_PNT_AMT
		     , ODI.REAL_ORD_AMT
		     , ODI.GFCD_USE_AMT
		     , ODI.REG_NO
		     , NOW()
		     , ODI.UPD_NO
		     , NOW()
		  FROM TB_ORDER_DETAIL_ITEM ODI
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OD.ORD_NO = ODI.ORD_NO
		   AND OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		 WHERE ODI.ORD_DTL_ITEM_SQ = #{exchangeOrdDtlItemSq} 
	</insert>

	<!-- 주문배송주소 등록 -->
	<insert id="createDeliveryAddr" parameterType="Order" keyProperty="delvAddrSq">
		/* order.createDeliveryAddr */
		INSERT INTO TB_DELIVERY_ADDR (
		       RECIP_NM
		     , RECIP_PHNNO
		     , RECIP_TELNO
		     , RECIP_ZIPCODE
		     , RECIP_BASE_ADDR
		     , RECIP_DTL_ADDR
		     , DELV_MEMO
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		) VALUES (
		       #{recipNm}
		     , #{recipPhnno}
		     , #{recipTelno}
		     , #{recipZipcode}
		     , #{recipBaseAddr}
		     , #{recipDtlAddr}
		     , #{delvMemo}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		)
	</insert>

	<!-- 교환상품옵션재고정보 등록 -->
	<update id="createSellQtyForExchange" parameterType="OrderChange">
		/* OrderChange.createSellQtyForExchange */
		INSERT INTO TB_SELL_QTY (
		       GOODS_CD
		     , OPT_CD
		     , SELL_GB
		     , ORD_DTL_NO
		     , ORD_CHG_SQ
		     , AGENT_ORDER_ID
		     , EXTMALL_ORDER_ID
		     , SELL_QTY
		     , REG_NO
		     , REG_DT
		)
		SELECT ODI.ITEM_CD
		     , ODI.OPT_CD
		     , #{sellGb}
		     , ODI.ORD_DTL_NO
		     , OCD.ORD_CHG_SQ
		     , OD.AGENT_ORDER_ID
		     , OD.EXTMALL_ORDER_ID
		     , OCD.CHG_QTY * ODI.ITEM_QTY AS SELL_QTY
		     , #{regNo}
		     , NOW()
		  FROM TB_ORDER_CHANGE_DETAIL OCD
		 INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		    ON OCD.CHG_ORD_DTL_NO = ODI.ORD_DTL_NO
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OCD.CHG_ORD_DTL_NO = OD.ORD_DTL_NO
		 WHERE 1 = 1
		   AND ORD_CHG_SQ = #{ordChgSq}
	</update>
	
	<!-- 교환 정보 조회 -->
	<select id="getExchangeInfo" parameterType="Order" resultType="Order">
		/* OrderChange.getExchangeInfo */
		SELECT OC.ORD_CHG_SQ
		     , OC.CHG_GB
		     , OCD.CHG_QTY
		     , OD.ORD_DTL_NO
		     , OD.ORD_DTL_STAT
		     , OD.DELV_ADDR_SQ
		     , ODI.ITEM_CD
		     , ODI.OPT_CD1
		     , ODI.OPT_CD2
		     , OC.CHGER_NM
		     , OC.CHGER_ZIPCODE
		     , OC.CHGER_BASE_ADDR
		     , OC.CHGER_DTL_ADDR
		     , OC.CHGER_TELNO
		     , OC.CHGER_PHNNO
		     , OC.CHGER_RTN_MEMO
		     , DA.RECIP_NM
		     , DA.RECIP_ZIPCODE
		     , DA.RECIP_BASE_ADDR
		     , DA.RECIP_DTL_ADDR
		     , DA.RECIP_TELNO
		     , DA.RECIP_PHNNO
		     , DA.DELV_MEMO
		     , OC.CHG_REASON
		     , CASE OC.CHG_GB WHEN 'G680_40' THEN FN_GET_CODE_NM('G689', OC.CHG_REASON)
		                      WHEN 'G680_30' THEN FN_GET_CODE_NM('G688', OC.CHG_REASON)
		        END AS CHG_REASON_NM
		     , OC.CHG_MEMO
		     , OC.ADD_PAY_COST
		     , OC.WD_GB
		  FROM TB_ORDER_CHANGE OC
		 INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		    ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OCD.CHG_ORD_DTL_NO = OD.ORD_DTL_NO
		 INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		    ON OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		 INNER JOIN TB_DELIVERY_ADDR DA
		    ON OD.DELV_ADDR_SQ = DA.DELV_ADDR_SQ
		 WHERE OC.ORD_CHG_SQ = #{ordChgSq}
	</select>
	
	<!-- 추가배송비 결제 여부 조회 -->
	<select id="getAddDeliveryFeePayment" parameterType="OrderChange" resultType="Order">
		/* OrderChange.getAddDeliveryFeePayment */
		SELECT OC.ORD_CHG_SQ
		     , P.PAY_AMT
		     , P.PAY_DT
		     , P.PAY_MEANS
		     , CASE P.PAY_MEANS WHEN 'G014_60' THEN CASE WHEN DATE_FORMAT(NOW(), '%m') <![CDATA[<>]]> DATE_FORMAT(P.PAY_DT, '%m') THEN 'N'
		                                                 ELSE 'Y'
		                                             END
		                        ELSE 'Y'
		        END AS CAN_DELIVERY_CANCEL_YN
		  FROM TB_ORDER_CHANGE OC
		 INNER JOIN TB_PAYMENT P
		    ON P.ORD_CHG_SQ = OC.ORD_CHG_SQ
		   AND P.PAY_STAT = 'G016_30'
		   AND P.PAY_GB = 'D'
		 WHERE OC.ORD_CHG_SQ = #{ordChgSq}
		   AND OC.ADD_PAY_COST > 0
	</select>
	
	<!-- 추가배송비 취소 처리 -->
	<insert id="createAddDeliveryFeeCancel" parameterType="OrderChange">
		/* TscOrderChange.createAddDeliveryFeeCancel */
		INSERT INTO TB_DELIVERY_FEE (
		       PAY_SQ
		     , ORD_NO
		     , DELV_FEE_GB
		     , DELV_FEE_CD
		     , DELV_FEE
		     , DELV_CPN_SQ
		     , DELV_CPN_DC_AMT
		     , REAL_DELV_AMT
		     , ORD_CHG_SQ
		     , SUPPLY_COMP_CD
		     , DELV_USAC_YN
		     , DELV_USAC_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT NULL                      AS PAY_SQ
		     , DF.ORD_NO
		     , DF.DELV_FEE_GB
		     , DF.DELV_FEE_CD
		     , DF.DELV_FEE * -1          AS DELV_FEE
		     , DF.DELV_CPN_SQ
		     , DF.DELV_CPN_DC_AMT * -1   AS DELV_CPN_DC_AMT
		     , DF.REAL_DELV_AMT * -1     AS REAL_DELV_AMT
		     , DF.ORD_CHG_SQ
		     , DF.SUPPLY_COMP_CD
		     , 'N'
		     , NULL
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_DELIVERY_FEE DF
		 INNER JOIN TB_PAYMENT P
		    ON P.ORD_CHG_SQ = DF.ORD_CHG_SQ
		   AND P.PAY_STAT = 'G016_30'
		   AND P.PAY_GB = 'D'
		 WHERE DF.ORD_CHG_SQ = #{ordChgSq}
	</insert>
	
	<!-- 추가배송비 결제 취소 정보 생성(사용안함) -->
	<insert id="createAddDeliveryFeeCancelPayment" parameterType="Order" keyProperty="paySq">
		/* OrderChange.createAddDeliveryFeeCancelPayment */
		INSERT INTO TB_PAYMENT (
		       ORD_NO
		     , PAY_DT
		     , PAY_MEANS
		     , PAY_AMT
		     , PG_CPN_AMT
		     , NPAY_PNT_AMT
		     , PAY_GB
		     , PAY_STAT
		     , PG_GB
		     , PG_TID
		     , PG_TRADE_NO
		     , PG_SHOP_ID
		     , CARD_TYPE
		     , CARD_KIND
		     , CARD_BANK
		     , CARD_NM
		     , CARD_MIPS
		     , CARD_PCABLE_YN
		     , VA_NO
		     , VA_NM
		     , VA_BANK
		     , VA_DEADLINE
		     , TELECOM
		     , ESCROW_YN
		     , ORD_CHG_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		) 
		SELECT ORD_NO
		     , NULL
		     , PAY_MEANS
		     , #{payAmt}
		     , #{pgCpnAmt}
		     , #{npayPntAmt}
		     , #{payGb}
		     , #{payStat}
		     , PG_GB
		     , NULL
		     , NULL
		     , NULL
		     , CARD_TYPE
		     , CARD_KIND
		     , CARD_BANK
		     , CARD_NM
		     , CARD_MIPS
		     , CARD_PCABLE_YN
		     , VA_NO
		     , VA_NM
		     , VA_BANK
		     , VA_DEADLINE
		     , TELECOM
		     , ESCROW_YN
		     , #{ordChgSq}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_PAYMENT
		 WHERE PAY_SQ = #{paySq}
	</insert>

	<!-- 교환철회 주문상세 상태코드 변경 -->
	<update id="updateOrderDetailForExchangeCancel" parameterType="Order">
		/* OrderChange.updateOrderDetailForExchangeCancel */
		UPDATE TB_ORDER_DETAIL OD
		 INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		    ON OD.ORD_DTL_NO = OCD.CHG_ORD_DTL_NO
		   SET OD.ORD_DTL_STAT = #{ordDtlStat}
		     , OD.UPD_NO = #{updNo}
		     , OD.UPD_DT = NOW()
		 WHERE OCD.ORD_CHG_SQ = #{ordChgSq}
		   AND OD.ORD_NO = #{ordNo}
	</update>

	<!-- 교환철회 주문단품상세 상태코드 변경 -->
	<update id="updateOrderDetailItemForExchangeCancel" parameterType="Order">
		/* OrderChange.updateOrderDetailItemForExchangeCancel */
		UPDATE TB_ORDER_DETAIL_ITEM ODI
		 INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		    ON ODI.ORD_DTL_NO = OCD.CHG_ORD_DTL_NO
		   SET ODI.ORD_DTL_STAT = #{ordDtlStat}
		     , ODI.UPD_NO = #{updNo}
		     , ODI.UPD_DT = NOW()
		 WHERE OCD.ORD_CHG_SQ = #{ordChgSq}
		   AND ODI.ORD_NO = #{ordNo}
	</update>

	<!-- 교환철회 주문상세단품정보 이력 생성 -->
	<insert id="createOrderDetailItemHstForExchangeCancel" parameterType="Order">
		/* order.createOrderDetailItemHstForExchangeCancel */
		INSERT INTO TB_ORDER_DETAIL_ITEM_HST (
		       ORD_DTL_ITEM_SQ
		     , ORD_DTL_NO
		     , ORD_NO
		     , ORD_DTL_STAT
		     , ITEM_CD
		     , OPT_CD
		     , OPT_CD1
		     , OPT_CD2
		     , SKU_MODEL_NO
		     , PRODUCT_NO
		     , PRODUCT_CODE
		     , ITEM_QTY
		     , ITEM_PRICE
		     , OPT_ADD_PRICE
		     , DISP_ORD
		     , ORD_AMT
		     , ORD_QTY
		     , CNCL_RTN_AMT
		     , CNCL_RTN_QTY
		     , CPN1_DC_AMT
		     , TMTB1_DC_AMT
		     , TMTB2_DC_AMT
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_DC_AMT
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT ODI.ORD_DTL_ITEM_SQ
		     , ODI.ORD_DTL_NO
		     , ODI.ORD_NO
		     , ODI.ORD_DTL_STAT
		     , ODI.ITEM_CD
		     , ODI.OPT_CD
		     , ODI.OPT_CD1
		     , ODI.OPT_CD2
		     , ODI.SKU_MODEL_NO
		     , ODI.PRODUCT_NO
		     , ODI.PRODUCT_CODE
		     , ODI.ITEM_QTY
		     , ODI.ITEM_PRICE
		     , ODI.OPT_ADD_PRICE
		     , ODI.DISP_ORD
		     , ODI.ORD_AMT
		     , OD.ORD_QTY
		     , ODI.CNCL_RTN_AMT
		     , OD.CNCL_RTN_QTY
		     , ODI.CPN1_DC_AMT
		     , ODI.TMTB1_DC_AMT
		     , ODI.TMTB2_DC_AMT
		     , ODI.GOODS_CPN_DC_AMT
		     , ODI.CART_CPN_DC_AMT
		     , ODI.PNT_DC_AMT
		     , ODI.PRE_PNT_DC_AMT
		     , ODI.SAVE_PNT_AMT
		     , ODI.REAL_ORD_AMT
		     , ODI.GFCD_USE_AMT
		     , ODI.REG_NO
		     , ODI.REG_DT
		     , ODI.UPD_NO
		     , ODI.UPD_DT
		  FROM TB_ORDER_DETAIL_ITEM ODI
		 INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		    ON ODI.ORD_DTL_NO = OCD.CHG_ORD_DTL_NO
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OD.ORD_NO = ODI.ORD_NO
		   AND OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		 WHERE OCD.ORD_CHG_SQ = #{ordChgSq}
		   AND ODI.ORD_NO = #{ordNo}
	</insert>

	<!-- 전체취소 주문상세단품정보 수정 -->
	<update id="updateOrderDetailForAllCancel" parameterType="Order">
		/* TscOrderChange.updateOrderDetailForAllCancel */
		UPDATE TB_ORDER_DETAIL
		   SET ORD_DTL_STAT = #{ordDtlStat}
		     , CNCL_RTN_QTY = ORD_QTY
		     , CNCL_RTN_AMT = ORD_AMT
		     , CPN1_DC_AMT = 0
		     , TMTB1_DC_AMT = 0
		     , TMTB2_DC_AMT = 0
		     , GOODS_CPN_DC_AMT = 0
		     , CART_CPN_DC_AMT = 0
		     , PNT_DC_AMT = 0
		     , PRE_PNT_DC_AMT = 0
		     , SAVE_PNT_AMT = 0
		     , REAL_ORD_AMT = 0
		     , GFCD_USE_AMT = CASE WHEN IFNULL(NULLIF(#{gfcdUseAmt}, ''), 0) > 0 THEN GFCD_USE_AMT - #{gfcdUseAmt}
		                           ELSE 0
		                       END
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		 WHERE ORD_NO = #{ordNo}
	</update>

	<!-- 전체취소 주문상세단품이력정보 등록 -->
	<insert id="createOrderDetailHstForAllCancel" parameterType="Order">
		/* TscOrderChange.createOrderDetailHstForAllCancel */
		INSERT INTO TB_ORDER_DETAIL_HST (
		       ORD_DTL_NO
		     , ORD_NO
		     , ORD_EXCH_GB
		     , ORD_DTL_STAT
		     , ORG_ORD_DTL_NO
		     , SUPPLY_COMP_CD
		     , GOODS_CD
		     , DEAL_GOODS_CD
		     , FORMAL_GB
		     , GOODS_TYPE
		     , LIST_PRICE
		     , CURR_PRICE
		     , DC_RATE
		     , OPT_ADD_PRICE
		     , ORD_QTY
		     , ORD_AMT
		     , CNCL_RTN_QTY
		     , CNCL_RTN_AMT
		     , CPN1_CPN_SQ
		     , CPN1_DC_AMT
		     , TMTB1_SQ
		     , TMTB1_DC_AMT
		     , TMTB2_SQ
		     , TMTB2_DC_AMT
		     , GOODS_CPN_SQ
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_SQ
		     , CART_CPN_DC_AMT
		     , BURDEN_RATE
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , VENDOR_ID
		     , EXTMALL_ID
		     , AGENT_ORDER_ID
		     , EXTMALL_ORDER_ID
		     , CHANGEABLE_YN
		     , CHANGE_FEE_FREE_YN
		     , RETURNABLE_YN
		     , RETURN_FEE_FREE_YN
		     , SOLDOUT_YN
		     , SOLDOUT_MEMO
		     , SOLDOUT_REG_NO
		     , SOLDOUT_REG_DT
		     , DELV_ADDR_SQ
		     , DELV_FEE_CD
		     , SHOT_DELV_YN
		     , GIFT_PACK_YN
		     , GIFT_ADDR_INP_YN
		     , MAKE_GOODS_YN
		     , ENTRY_NO
		     , DELV_LOC_CD
		     , DELV_ASSIGN_DT
		     , DELV_ASSIGN_STAT
		     , DSTRBT_NOTE
		     , DELV_STDT
		     , DELV_EDDT
		     , SHIP_COMP_CD
		     , INVOICE_NO
		     , INVOICE_SEND_YN
		     , SELL_STORE_CD
		     , SELL_FEE_RATE
		     , AF_LINK_CD
		     , ITHR_CD
		     , CONTENTS_LOC
		     , PLAN_DTL_SQ
		     , SOCIAL_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT ORD_DTL_NO
		     , ORD_NO
		     , ORD_EXCH_GB
		     , #{ordDtlStat}
		     , ORG_ORD_DTL_NO
		     , SUPPLY_COMP_CD
		     , GOODS_CD
		     , DEAL_GOODS_CD
		     , FORMAL_GB
		     , GOODS_TYPE
		     , LIST_PRICE
		     , CURR_PRICE
		     , DC_RATE
		     , OPT_ADD_PRICE
		     , ORD_QTY
		     , ORD_AMT
		     , ORD_QTY
		     , ORD_AMT
		     , CPN1_CPN_SQ
		     , 0
		     , TMTB1_SQ
		     , 0
		     , TMTB2_SQ
		     , 0
		     , GOODS_CPN_SQ
		     , 0
		     , CART_CPN_SQ
		     , 0
		     , BURDEN_RATE
		     , 0
		     , 0
		     , 0
		     , 0
		     , 0
		     , VENDOR_ID
		     , EXTMALL_ID
		     , AGENT_ORDER_ID
		     , EXTMALL_ORDER_ID
		     , CHANGEABLE_YN
		     , CHANGE_FEE_FREE_YN
		     , RETURNABLE_YN
		     , RETURN_FEE_FREE_YN
		     , SOLDOUT_YN
		     , SOLDOUT_MEMO
		     , SOLDOUT_REG_NO
		     , SOLDOUT_REG_DT
		     , DELV_ADDR_SQ
		     , DELV_FEE_CD
		     , SHOT_DELV_YN
		     , GIFT_PACK_YN
		     , GIFT_ADDR_INP_YN
		     , MAKE_GOODS_YN
		     , ENTRY_NO
		     , DELV_LOC_CD
		     , DELV_ASSIGN_DT
		     , DELV_ASSIGN_STAT
		     , DSTRBT_NOTE
		     , DELV_STDT
		     , DELV_EDDT
		     , SHIP_COMP_CD
		     , INVOICE_NO
		     , INVOICE_SEND_YN
		     , SELL_STORE_CD
		     , SELL_FEE_RATE
		     , AF_LINK_CD
		     , ITHR_CD
		     , CONTENTS_LOC
		     , PLAN_DTL_SQ
		     , SOCIAL_SQ
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL
		 WHERE ORD_NO = #{ordNo}
	</insert>

	<!-- 전체취소 주문상세단품정보 수정 -->
	<update id="updateOrderDetailItemForAllCancel" parameterType="Order">
		/* TscOrderChange.updateOrderDetailItemForAllCancel */
		UPDATE TB_ORDER_DETAIL_ITEM 
		   SET ORD_DTL_STAT = #{ordDtlStat}
		     , CNCL_RTN_AMT = ORD_AMT
		     , CPN1_DC_AMT = 0
		     , TMTB1_DC_AMT = 0
		     , TMTB2_DC_AMT = 0
		     , GOODS_CPN_DC_AMT = 0
		     , CART_CPN_DC_AMT = 0
		     , PNT_DC_AMT = 0
		     , PRE_PNT_DC_AMT = 0
		     , SAVE_PNT_AMT = 0
		     , REAL_ORD_AMT = 0
		     , GFCD_USE_AMT = 0
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		 WHERE ORD_NO = #{ordNo}
	</update>

	<!-- 전체취소 주문상세단품이력정보 등록 -->
	<insert id="createOrderDetailItemHstForAllCancel" parameterType="Order">
		/* TscOrderChange.createOrderDetailItemHstForAllCancel */
		INSERT INTO TB_ORDER_DETAIL_ITEM_HST (
		       ORD_DTL_ITEM_SQ
		     , ORD_DTL_NO
		     , ORD_NO
		     , ORD_DTL_STAT
		     , ITEM_CD
		     , OPT_CD
		     , OPT_CD1
		     , OPT_CD2
		     , SKU_MODEL_NO
		     , PRODUCT_NO
		     , PRODUCT_CODE
		     , ITEM_QTY
		     , ITEM_PRICE
		     , OPT_ADD_PRICE
		     , DISP_ORD
		     , ORD_AMT
		     , ORD_QTY
		     , CNCL_RTN_AMT
		     , CNCL_RTN_QTY
		     , CPN1_DC_AMT
		     , TMTB1_DC_AMT
		     , TMTB2_DC_AMT
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_DC_AMT
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , ORD_CHG_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT ODI.ORD_DTL_ITEM_SQ
		     , ODI.ORD_DTL_NO
		     , ODI.ORD_NO
		     , #{ordDtlStat}
		     , ODI.ITEM_CD
		     , ODI.OPT_CD
		     , ODI.OPT_CD1
		     , ODI.OPT_CD2
		     , ODI.SKU_MODEL_NO
		     , ODI.PRODUCT_NO
		     , ODI.PRODUCT_CODE
		     , ODI.ITEM_QTY
		     , ODI.ITEM_PRICE
		     , ODI.OPT_ADD_PRICE
		     , ODI.DISP_ORD
		     , ODI.ORD_AMT
		     , OD.ORD_QTY
		     , ODI.ORD_AMT
		     , OD.CNCL_RTN_QTY
		     , ODI.CPN1_DC_AMT
		     , ODI.TMTB1_DC_AMT
		     , ODI.TMTB2_DC_AMT
		     , ODI.GOODS_CPN_DC_AMT
		     , ODI.CART_CPN_DC_AMT
		     , ODI.PNT_DC_AMT
		     , ODI.PRE_PNT_DC_AMT
		     , ODI.SAVE_PNT_AMT
		     , ODI.REAL_ORD_AMT
		     , ODI.GFCD_USE_AMT
		     , #{ordChgSq}
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL_ITEM ODI
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON ODI.ORD_DTL_NO = OD.ORD_DTL_NO
		 WHERE ODI.ORD_NO = #{ordNo}
	</insert>

	<!-- 마이페이지 포인트 원복 사용포인트 조회 -->
	<select id="getCustPointHst" parameterType="Order" resultType="Order">
		/* TscOrderChange.getCustPointHst */
		SELECT PNT_HST_SQ
		     , CUST_NO
		     , OCCUR_GB
		     , OCCUR_DTL_DESC
		     , PNT_AMT
		     , CUST_PNT_SQ
		     , ORD_NO
		     , ORD_DTL_NO
		     , REVIEW_SQ
		     , SWITCH_DUE_DT
		     , PNT_UPLOAD_STAT
		     , PNT_UPLOAD_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		  FROM TB_CUST_POINT_HST
		 WHERE ORD_NO = #{ordNo}
		<if test="firstOrdDtlNo != null and firstOrdDtlNo != ''">
		   AND ORD_DTL_NO = #{firstOrdDtlNo}
		</if>
		   AND OCCUR_GB = #{occurGb}
		 ORDER BY CUST_PNT_SQ
	</select>

	<!-- 마이페이지 사용포인트 원복 이력 생성 -->
	<insert id="createCustPointHstRollback" parameterType="Order">
		/* TscOrderChange.createCustPointHstRollback */
		INSERT INTO TB_CUST_POINT_HST (
		       CUST_NO
		     , OCCUR_GB
		     , OCCUR_DTL_DESC
		     , PNT_AMT
		     , CUST_PNT_SQ
		     , ORD_NO
		     , ORD_DTL_NO
		     , REVIEW_SQ
		     , SWITCH_DUE_DT
		     , PNT_UPLOAD_STAT
		     , PNT_UPLOAD_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT CPH.CUST_NO
		     , #{occurGb}
		     , #{occurDtlDesc}
		     , #{pntAmt}
		     , CPH.CUST_PNT_SQ
		     , CPH.ORD_NO
		     , CPH.ORD_DTL_NO
		     , CPH.REVIEW_SQ
		     ,
		<choose>
			<when test="occurGb == 'G069_13'">
		       NULL
			</when>
			<otherwise>
		       NOW()
			</otherwise>
		</choose>
		     , #{pntUploadStat}
		     ,
		<choose>
			<when test="occurGb == 'G069_13'">
		       NULL
			</when>
			<otherwise>
		       NOW()
			</otherwise>
		</choose>
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_CUST_POINT_HST CPH
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON CPH.ORD_DTL_NO = OD.ORD_DTL_NO
		 WHERE PNT_HST_SQ = #{pntHstSq}
		<if test="occurGb == 'G069_13'">
		   AND OD.ORD_DTL_STAT <![CDATA[<>]]> 'G013_70'
		</if>
	</insert>
	
	<!-- 마이페이지 사용포인트 원복 수정  -->
	<update id="updateCustPointRollback" parameterType="Order">
		/* TscOrderChange.updateCustPointRollback */
		UPDATE TB_CUST_POINT
		   SET US_PNT_AMT = US_PNT_AMT - #{pntAmt}
		     , RM_PNT_AMT = RM_PNT_AMT + #{pntAmt}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		 WHERE CUST_PNT_SQ = #{custPntSq}
	</update>

	<!-- 마이페이지 상품쿠폰 원복 수정 -->
	<update id="updateGoodsCpnRollback" parameterType="Order">
		/* TscOrderChange.updateGoodsCpnRollback */
		UPDATE TB_CUST_COUPON CC
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON CC.CUST_CPN_SQ = OD.GOODS_CPN_SQ
		   AND OD.ORD_NO = #{ordNo}
		   SET CC.USED_DT = NULL
		     , CC.UPD_NO = #{updNo}
		     , CC.UPD_DT = NOW()
		 WHERE OD.ORD_NO = #{ordNo}
		<if test="firstOrdDtlNo != null and firstOrdDtlNo != ''">
		   AND OD.ORD_DTL_NO = #{firstOrdDtlNo}
		</if>
	</update>

	<!-- 마이페이지 장바구니쿠폰 원복 수정 -->
	<update id="updateCartCpnRollback" parameterType="Order">
		/* TscOrderChange.updateCartCpnRollback */
		UPDATE TB_CUST_COUPON CC
		 INNER JOIN (SELECT ORD_NO
		                  , CART_CPN_SQ
		               FROM TB_ORDER_DETAIL
		              WHERE ORD_NO = #{ordNo}
		              GROUP BY ORD_NO
		                  , CART_CPN_SQ) OD
		    ON CC.CUST_CPN_SQ = OD.CART_CPN_SQ
		   SET CC.USED_DT = NULL
		     , CC.UPD_NO = #{updNo}
		     , CC.UPD_DT = NOW()
		 WHERE OD.ORD_NO = #{ordNo}
	</update>

	<!-- 마이페이지 배송비쿠폰 원복 수정 -->
	<update id="updateDeliveryCpnRollback" parameterType="Order">
		/* TscOrderChange.updateDeliveryCpnRollback */
		UPDATE TB_CUST_COUPON CC
		 INNER JOIN (SELECT ORD_NO
		                  , DELV_CPN_SQ
		               FROM TB_DELIVERY_FEE
		              WHERE DELV_FEE_GB = 'G018_10'
		                AND ORD_NO = #{ordNo}
		              GROUP BY ORD_NO
		                  , DELV_CPN_SQ) DF
		    ON CC.CUST_CPN_SQ = DF.DELV_CPN_SQ
		   SET CC.USED_DT = NULL
		     , CC.UPD_NO = #{updNo}
		     , CC.UPD_DT = NOW()
		 WHERE DF.ORD_NO = #{ordNo}
	</update>

	<!-- 마이페이지 상품권 원복 사용상품권 조회 -->
	<select id="getCustGiftCardHst" parameterType="Order" resultType="Order">
		/* TscOrderChange.getCustGiftCardHst */
		SELECT GFCD_HST_SQ
		     , CUST_NO
		     , OCCUR_GB
		     , OCCUR_DTL_DESC
		     , GFCD_AMT
		     , CUST_GFCD_SQ
		     , ORD_NO
		     , ORD_DTL_NO
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		  FROM TB_CUST_GIFTCARD_HST
		 WHERE ORD_NO = #{ordNo}
		<if test="firstOrdDtlNo != null and firstOrdDtlNo != ''">
		   AND ORD_DTL_NO = #{firstOrdDtlNo}
		</if>
		   AND OCCUR_GB = 'G074_12'
		   AND IFNULL(DELV_FEE_SQ, 0) = 0
		 ORDER BY CUST_GFCD_SQ
	</select>

	<!-- 마이페이지 상품권 원복 사용상품권 조회 -->
	<select id="getCustGiftCardDelvHst" parameterType="Order" resultType="Order">
		/* TscOrderChange.getCustGiftCardDelvHst */
		SELECT CGH.GFCD_HST_SQ
		     , CGH.CUST_NO
		     , CGH.OCCUR_GB
		     , CGH.OCCUR_DTL_DESC
		     , CGH.GFCD_AMT
		     , CGH.CUST_GFCD_SQ
		     , CGH.ORD_NO
		     , CGH.ORD_DTL_NO
		     , CGH.REG_NO
		     , CGH.REG_DT
		     , CGH.UPD_NO
		     , CGH.UPD_DT
		  FROM TB_CUST_GIFTCARD_HST CGH
		 INNER JOIN TB_DELIVERY_FEE DF
		    ON CGH.DELV_FEE_SQ = DF.DELV_FEE_SQ
		 WHERE CGH.ORD_NO = #{ordNo}
		<if test="delvFeeCd != null and delvFeeCd !=''">
		   AND DF.DELV_FEE_CD = #{delvFeeCd}
		</if>
		   AND CGH.OCCUR_GB = 'G074_12'
		 ORDER BY CGH.CUST_GFCD_SQ
	</select>

	<!-- 마이페이지 사용상품권 원복 이력 생성 -->
	<insert id="createCustGiftCardHstRollback" parameterType="Order">
		/* TscOrderChange.createCustGiftCardHstRollback */
		INSERT INTO TB_CUST_GIFTCARD_HST (
		       CUST_NO
		     , OCCUR_GB
		     , OCCUR_DTL_DESC
		     , GFCD_AMT
		     , CUST_GFCD_SQ
		     , ORD_NO
		     , ORD_DTL_NO
		     , DELV_FEE_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT CUST_NO
		     , #{occurGb}
		     , #{occurDtlDesc}
		     , #{gfcdAmt}
		     , CUST_GFCD_SQ
		     , ORD_NO
		     , ORD_DTL_NO
		     , DELV_FEE_SQ
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_CUST_GIFTCARD_HST
		 WHERE GFCD_HST_SQ = #{gfcdHstSq}
	</insert>

	<!-- 마이페이지 전체취소 사용상품권 원복 수정  -->
	<update id="updateCustGiftCardRollback" parameterType="Order">
		/* TscOrderChange.updateCustGiftCardRollback */
		UPDATE TB_CUST_GIFTCARD
		   SET US_GFCD_AMT = US_GFCD_AMT - #{gfcdAmt}
		     , RM_GFCD_AMT = RM_GFCD_AMT + #{gfcdAmt}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		 WHERE CUST_GFCD_SQ = #{custGfcdSq}
	</update>

	<!-- 결제정보 조회 -->
	<select id="getPaymentInfo" parameterType="Payment" resultType="Payment">
		/* TscOrderChange.getPaymentInfo */
		SELECT PAY_SQ
		     , ORD_NO
		     , PAY_DT
		     , PAY_MEANS
		     , PAY_AMT
		     , PG_CPN_AMT
		     , NPAY_PNT_AMT
		     , PAY_GB
		     , PAY_STAT
		     , PG_GB
		     , PG_TID
		     , PG_TRADE_NO
		     , PG_SHOP_ID
		     , CARD_TYPE
		     , CARD_KIND
		     , CARD_BANK
		     , CARD_CD
		     , CARD_NM
		     , CARD_MIPS
		     , CARD_PCABLE_YN
		     , VA_NO
		     , VA_NM
		     , VA_BANK
		     , VA_DEADLINE
		     , TELECOM
		     , ESCROW_YN
		     , CASH_AUTH_NO
		     , CASH_TRADE_NO
		     , ORD_CHG_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		  FROM TB_PAYMENT
		 WHERE ORD_NO = #{ordNo}
		   AND PAY_GB = 'O'
		   AND PAY_STAT IN ('G016_30', 'G016_10')
	</select>
	
	<!-- 마이페이지 전체취소 주문변경상세 등록 -->
	<insert id="createOrderChangeDetailForAllCancel" parameterType="OrderChange">
		/* TscOrder.createOrderChangeDetailForAllCancel */
		INSERT INTO TB_ORDER_CHANGE_DETAIL (
		       ORD_CHG_SQ
		     , ORD_DTL_NO
		     , CHG_QTY
		     , CHG_STAT
		     , CHG_ORD_DTL_NO
		     , WH_MEMO
		     , COMPLETE_DT
		     , DEL_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT #{ordChgSq}
		     , ORD_DTL_NO
		     , ORD_QTY
		     , #{chgStat}
		     , NULL
		     , NULL
		     , NOW()
		     , 'N'
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL
		 WHERE ORD_NO = #{ordNo}
	</insert>

	<!-- 마이페이지 전체취소 주문변경상세 이력 등록-->
	<insert id="createOrderChangeDetailHstForAllCancel" parameterType="OrderChange">
		/* OrderChange.createOrderChangeDetailHstForAllCancel */
		INSERT INTO TB_ORDER_CHANGE_DETAIL_HST (
		       ORD_CHG_SQ
		     , ORD_DTL_NO
		     , CHG_QTY
		     , CHG_STAT
		     , CHG_ORD_DTL_NO
		     , WH_MEMO
		     , COMPLETE_DT
		     , DEL_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT ORD_CHG_SQ
		     , ORD_DTL_NO
		     , CHG_QTY
		     , #{chgStat}
		     , CHG_ORD_DTL_NO
		     , WH_MEMO
		     , COMPLETE_DT
		     , DEL_YN
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER_CHANGE_DETAIL
		 WHERE ORD_CHG_SQ = #{ordChgSq}
	</insert>
	
	<!-- 마이페이지 전체취소 환불정보 조회 -->
	<select id="getRefundInfoForAllCancel" parameterType="Order" resultType="Order">
		/* TscOrderChange.getRefundInfoForAllCancel */
		SELECT OD.ORD_NO
		     , SUM(OD.ORD_AMT)          AS RF_CNCL_AMT
		     , SUM(OD.CPN1_DC_AMT)      AS RF_CPN1_AMT
		     , SUM(OD.TMTB1_DC_AMT)     AS RF_TMTB1_AMT
		     , SUM(OD.TMTB2_DC_AMT)     AS RF_TMTB2_AMT
		     , SUM(OD.GOODS_CPN_DC_AMT) AS RF_GOODS_CPN_AMT
		     , SUM(OD.CART_CPN_DC_AMT)  AS RF_CART_CPN_AMT
		     , DF.DELV_CPN_DC_AMT       AS RF_DELV_CPN_AMT
		     , SUM(OD.PNT_DC_AMT)       AS RF_PNT_AMT
		     , SUM(OD.PRE_PNT_DC_AMT)   AS RF_PRE_PNT_AMT
		     , SUM(OD.GFCD_USE_AMT)     AS RF_GFCD_USE_AMT
		     , DF.DELV_GFCD_USE_AMT     AS RF_DELV_GFCD_USE_AMT
		     , DF.REAL_DELV_AMT         AS RF_DELIVERY_FEE
		     , SUM(OD.REAL_ORD_AMT)     AS REAL_ORD_AMT
		  FROM TB_ORDER_DETAIL OD
		 INNER JOIN (SELECT ORD_NO
		                  , SUM(DELV_FEE)          AS DELV_FEE
		                  , SUM(DELV_CPN_DC_AMT)   AS DELV_CPN_DC_AMT
		                  , SUM(DELV_GFCD_USE_AMT) AS DELV_GFCD_USE_AMT
		                  , SUM(REAL_DELV_AMT)     AS REAL_DELV_AMT
		               FROM TB_DELIVERY_FEE
		              WHERE ORD_NO = #{ordNo}
		                AND DELV_FEE_GB = 'G018_10'
		              GROUP BY ORD_NO) DF
		    ON OD.ORD_NO = DF.ORD_NO
		 WHERE OD.ORD_NO = #{ordNo}
		 GROUP BY OD.ORD_NO
	</select>

	<!-- 추가배송비 결제정보 조회 -->
	<select id="getAddPayCostPaymentInfo" parameterType="Payment" resultType="Payment">
		/* TscOrder.getAddPayCostPaymentInfo */
		SELECT PAY_SQ
		     , ORD_NO
		     , PAY_DT
		     , PAY_MEANS
		     , PAY_AMT
		     , PG_CPN_AMT
		     , NPAY_PNT_AMT
		     , PAY_GB
		     , PAY_STAT
		     , PG_GB
		     , PG_TID
		     , PG_TRADE_NO
		     , PG_SHOP_ID
		     , CARD_TYPE
		     , CARD_KIND
		     , CARD_BANK
		     , CARD_CD
		     , CARD_NM
		     , CARD_MIPS
		     , CARD_PCABLE_YN
		     , VA_NO
		     , VA_NM
		     , VA_BANK
		     , VA_DEADLINE
		     , TELECOM
		     , ESCROW_YN
		     , CASH_AUTH_NO
		     , CASH_TRADE_NO
		     , ORD_CHG_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		  FROM TB_PAYMENT
		 WHERE ORD_CHG_SQ = #{ordChgSq}
		   AND PAY_GB = 'D'
		   AND PAY_STAT = 'G016_30'
	</select>
	
	<!-- 교환 상품 재고 조회 -->
	<select id="getCurrStockQty" parameterType="Order" resultType="Order">
		/* TscOrder.getCurrStockQty */
		SELECT VS.CURR_STOCK_QTY - VS.BASE_STOCK_QTY AS CURR_STOCK_QTY
		     , VS.SOLDOUT_YN
		     , ODI.ITEM_QTY
		  FROM TB_ORDER_DETAIL_ITEM ODI
		 INNER JOIN VW_STOCK VS
		    ON VS.GOODS_CD = ODI.ITEM_CD
		   AND VS.OPT_CD = #{ordChgOpt}
		   AND VS.DISP_YN = 'Y'
		 WHERE ODI.ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
	</select>

	<!-- 취소/반품 환불 사전 정보 조회 -->
	<select id="getRefundPreInfo" parameterType="OrderChange" resultType="Order">
		/* TscOrderChange.getRefundPreInfo */
		SELECT Z.ORD_NO
		     , Z.ORD_DTL_NO
		     , Z.GOODS_NM
		     , Z.GOODS_TYPE_NM
		     , Z.ORD_DTL_STAT
		     , Z.ORD_DTL_STAT_NM
		     , GROUP_CONCAT(Z.ITEM_CD  ORDER BY Z.ORD_DTL_ITEM_SQ) AS ITEM_CD
		     , GROUP_CONCAT(Z.ITEM_NM  ORDER BY Z.ORD_DTL_ITEM_SQ) AS ITEM_NM
		     , GROUP_CONCAT(Z.OPT_CD   ORDER BY Z.ORD_DTL_ITEM_SQ) AS OPT_CD
		     , GROUP_CONCAT(Z.OPT_CD1  ORDER BY Z.ORD_DTL_ITEM_SQ) AS OPT_CD1
		     , GROUP_CONCAT(Z.OPT_CD2  ORDER BY Z.ORD_DTL_ITEM_SQ) AS OPT_CD2
		     , GROUP_CONCAT(Z.ITEM_QTY ORDER BY Z.ORD_DTL_ITEM_SQ) AS ITEM_QTYR
		     , Z.CURR_PRICE
		     , Z.ORD_QTY
		     , Z.CNCL_RTN_QTY
		     , (SELECT SUM(ORD_QTY)
		          FROM TB_ORDER_DETAIL
		         WHERE ORD_NO = Z.ORD_NO)                          AS TOT_ORD_QTY
		     , SUM(OPT_ADD_PRICE)                                  AS OPT_ADD_PRICE
		     , Z.ORD_AMT
		     , Z.CNCL_RTN_AMT
		     , Z.CPN1_DC_AMT
		     , Z.TMTB1_DC_AMT
		     , Z.TMTB2_DC_AMT
		     , Z.GOODS_CPN_DC_AMT
		     , Z.CART_CPN_DC_AMT
		     , Z.PRE_PNT_DC_AMT
		     , Z.PNT_DC_AMT
		     , Z.GFCD_USE_AMT
		     , Z.SAVE_PNT_AMT
		     , Z.REAL_ORD_AMT
		     , Z.DELV_FEE
		     , Z.DELV_CPN_DC_AMT
		     , Z.DELV_GFCD_USE_AMT
		     , Z.MIN_ORD_AMT
		     , Z.ORG_DELV_FEE
		     , Z.RTN_DELV_FEE
		     , Z.EXC_DELV_FEE
		     , Z.SUPPLY_COMP_CD
		     , Z.DELV_FEE_CD
		     , Z.PG_GB
		     , Z.PG_TID
		     , Z.PAY_MEANS
		     , Z.PAY_STAT
		     , Z.CASH_AUTH_NO
		     , Z.DELV_YN
		FROM (
		    SELECT O.ORD_NO
		         , OD.ORD_DTL_NO
		         , OD.GOODS_CD
		         , G1.GOODS_NM
		         , ODI.ORD_DTL_ITEM_SQ
		         , ODI.ITEM_CD
		         , G2.GOODS_NM                                        AS ITEM_NM
		         , ODI.ITEM_QTY
		         , ODI.OPT_CD
		         , ODI.OPT_CD1
		         , ODI.OPT_CD2
		         , ODI.ITEM_PRICE
		         , OD.CURR_PRICE
		         , OD.ORD_QTY
		         , OD.CNCL_RTN_QTY
		         , OD.OPT_ADD_PRICE
		         , OD.ORD_AMT
		         , OD.CNCL_RTN_AMT
		         , OD.CPN1_DC_AMT
		         , OD.TMTB1_DC_AMT
		         , OD.TMTB2_DC_AMT
		         , OD.GOODS_CPN_DC_AMT
		         , OD.CART_CPN_DC_AMT
		         , OD.PNT_DC_AMT
		         , OD.PRE_PNT_DC_AMT
		         , OD.SAVE_PNT_AMT
		         , OD.GFCD_USE_AMT
		         , OD.REAL_ORD_AMT
		         , FN_GET_CODE_NM('G056', OD.GOODS_TYPE)              AS GOODS_TYPE_NM
		         , OD.ORD_DTL_STAT
		         , FN_GET_CODE_NM('G013', OD.ORD_DTL_STAT)            AS ORD_DTL_STAT_NM
		         , DF.DELV_FEE
		         , DF.DELV_CPN_DC_AMT
		         , DF.DELV_GFCD_USE_AMT
		         , CASE DFP.DELV_FEE_CRITE WHEN 'G078_30' THEN 99999999
		                                   WHEN 'G078_20' THEN 0
		                                   ELSE DFP.MIN_ORD_AMT
		            END                                               AS MIN_ORD_AMT
		         , DFP.DELV_FEE                                       AS ORG_DELV_FEE
		         , DFP.RTN_DELV_FEE
		         , DFP.RTN_DELV_FEE + DFP.RTN_DELV_FEE                AS EXC_DELV_FEE
		         , DFP.SUPPLY_COMP_CD
		         , IF(G1.SELF_GOODS_YN = 'Y', 'WMS', DFP.DELV_FEE_CD) AS DELV_FEE_CD
		         , P.PG_GB
		         , P.PG_TID
		         , P.PAY_MEANS
		         , P.PAY_STAT
		         , P.CASH_AUTH_NO
		         , CASE WHEN (SELECT COUNT(1) FROM TB_ORDER_DETAIL_HST WHERE ORD_DTL_NO = OD.ORD_DTL_NO AND ORD_DTL_STAT = 'G013_50') > 0 THEN 'Y'
		                ELSE 'N'
		            END AS DELV_YN
		      FROM TB_ORDER O
		     INNER JOIN TB_ORDER_DETAIL OD
		        ON O.ORD_NO = OD.ORD_NO
		     INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		        ON O.ORD_NO = ODI.ORD_NO
		       AND OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		     INNER JOIN TB_GOODS G1
		        ON OD.GOODS_CD = G1.GOODS_CD
		     INNER JOIN TB_GOODS G2
		        ON ODI.ITEM_CD = G2.GOODS_CD
		     INNER JOIN TB_PAYMENT P
		        ON P.ORD_NO = O.ORD_NO
		       AND P.PAY_STAT IN ('G016_10', 'G016_30')
		       AND P.PAY_GB = 'O'
		      LEFT OUTER JOIN (SELECT X.DELV_FEE_CD
		                            , SUM(X.DELV_FEE)          AS DELV_FEE
		                            , SUM(X.DELV_CPN_DC_AMT)   AS DELV_CPN_DC_AMT
		                            , SUM(X.DELV_GFCD_USE_AMT) AS DELV_GFCD_USE_AMT
		                         FROM TB_DELIVERY_FEE X
		                        WHERE X.DELV_FEE_GB = 'G018_10'
		                          AND X.ORD_NO = #{ordNo}
		                        GROUP BY X.DELV_FEE_CD
		                      ) DF
		        ON IF(G1.SELF_GOODS_YN = 'Y', 'WMS', OD.DELV_FEE_CD) = DF.DELV_FEE_CD
		      LEFT OUTER JOIN TB_DELV_FEE_POLICY DFP
		        ON OD.DELV_FEE_CD = DFP.DELV_FEE_CD
		       AND OD.SUPPLY_COMP_CD = DFP.SUPPLY_COMP_CD
		       AND DFP.USE_YN = 'Y'
			<where>
				<choose>
					<when test='custNo > 0'>
		       AND O.CUST_NO = #{custNo}
					</when>
					<otherwise>
		       AND O.ORD_NO = #{ordNo}
		       AND O.ORD_NM = #{ordNm}
		       AND O.ORD_PHNNO = #{ordPhnno}
					</otherwise>
				</choose>
				<if test="ordNo != null and ordNo != ''">
		       AND O.ORD_NO = #{ordNo}
				</if>
		--       AND O.DISP_YN = 'Y'
			</where>
		) Z
		WHERE 1=1
		<if test="delvFeeCdGrp != null and delvFeeCdGrp != ''">
		  AND Z.DELV_FEE_CD = #{delvFeeCdGrp}
		</if>
		GROUP  BY Z.ORD_NO
		     , Z.ORD_DTL_NO
		     , Z.GOODS_NM
		     , Z.GOODS_TYPE_NM
		     , Z.ORD_DTL_STAT
		     , Z.ORD_DTL_STAT_NM
		     , Z.CURR_PRICE
		     , Z.ORD_QTY
		     , Z.CNCL_RTN_QTY
		     , Z.ORD_AMT
		     , Z.CNCL_RTN_AMT
		     , Z.CPN1_DC_AMT
		     , Z.TMTB1_DC_AMT
		     , Z.TMTB2_DC_AMT
		     , Z.GOODS_CPN_DC_AMT
		     , Z.CART_CPN_DC_AMT
		     , Z.PRE_PNT_DC_AMT
		     , Z.PNT_DC_AMT
		     , Z.GFCD_USE_AMT
		     , Z.SAVE_PNT_AMT
		     , Z.REAL_ORD_AMT
		     , Z.DELV_FEE
		     , Z.DELV_CPN_DC_AMT
		     , Z.DELV_GFCD_USE_AMT
		     , Z.MIN_ORD_AMT
		     , Z.ORG_DELV_FEE
		     , Z.RTN_DELV_FEE
		     , Z.EXC_DELV_FEE
		     , Z.SUPPLY_COMP_CD
		     , Z.DELV_FEE_CD
		     , Z.PG_GB
		     , Z.PG_TID
		     , Z.PAY_MEANS
		     , Z.PAY_STAT
		     , Z.CASH_AUTH_NO
		     , Z.DELV_YN
		 ORDER BY Z.DELV_FEE_CD
		     , Z.ORD_NO
		     , Z.ORD_DTL_NO
	</select>
	
	<!-- 결제취소 환불정보 수정 -->
	<update id="updateRefundInfo" parameterType="Order">
		/* TscOrderChange.updateRefundInfo */
		UPDATE TB_REFUND
		   SET PAY_SQ = #{paySq}
		 WHERE ORD_NO = #{ordNo}
		   AND ORD_CHG_SQ = #{ordChgSq}
	</update>
	
	<!-- 주문취소접수승인 정보 조회 -->
	<select id="approveCancelRequestInfo" parameterType="OrderChange" resultType="OrderChange">
		/* TscOrderChange.approveCancelRequestInfo */
		SELECT OD.ORD_NO
		     , OD.NPAY_ORD_DTL_NO
		     , O.CUST_NO
		     , O.ORD_NM
		     , OCD.ORD_DTL_NO
		     , OCD.CHG_QTY
		     , OC.CHG_REASON
		     , FN_GET_CODE_NM('G686', OC.CHG_REASON) AS CHG_REASON_NM
		     , OC.CHG_MEMO
		     , P.PG_TID
		     , P.PAY_MEANS
		     , P.PG_GB
		  FROM TB_ORDER_CHANGE_DETAIL OCD
		 INNER JOIN TB_ORDER_CHANGE OC
		    ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OD.ORD_DTL_NO = OCD.ORD_DTL_NO
		 INNER JOIN TB_ORDER O
		    ON O.ORD_NO = OD.ORD_NO
		 INNER JOIN TB_PAYMENT P
		    ON P.ORD_NO = O.ORD_NO
		   AND P.PAY_GB = 'O'
		   AND P.PAY_STAT = 'G016_30'
		 WHERE OCD.ORD_CHG_SQ = #{ordChgSq}
	</select>
	
	<!-- 주문취소 남은금액 조회 -->
	<select id="getLeftAmt" parameterType="int" resultType="int">
		/* TscOrderChange.getLeftAmt */
		SELECT SUM(PAY_AMT) AS PAY_AMT
		  FROM TB_PAYMENT
		 WHERE ORD_NO = #{ordNo}
	</select>
	
	<!-- 상품권 현금영수증 신청 정보 조회 -->
	<select id="getGiftCardReceiptsInfo" parameterType="Integer" resultType="GiftCard">
		/* TscOrderChange.getGiftCardReceiptsInfo */
		SELECT ORD_NO
		     , TRADE_NO
		     , AUTH_NO
		     , AMT
		     , REG_DT
		     , UPD_DT
		  FROM TB_GIFTCARD_RECEIPT
		 WHERE ORD_NO = #{ordNo}
	</select>
	
	<!-- 입점업체 주문변경상태 변경 -->
	<update id="updateOrderChangeDtlForSeller" parameterType="Order">
		/* TscOrderChange.updateOrderChangeDtlForSeller */
		UPDATE TB_ORDER_CHANGE_DETAIL
		   SET CHG_STAT = #{chgStat}
		     , WH_MEMO  = #{whMemo}
		     , COMPLETE_DT = NOW()
		     , UPD_NO   = #{updNo}
		     , UPD_DT   = NOW()
		 WHERE 1 = 1
		   AND ORD_CHG_SQ = #{ordChgSq}
		   AND ORD_DTL_NO = #{ordDtlNo}
	</update>
	
	<!-- 입점업체 주문변경신청정보변경 -->
	<update id="updateOrderChangeForSeller" parameterType="Order">
		/* TscOrderChange.updateOrderChangeForSeller */
		UPDATE TB_ORDER_CHANGE
		   SET ADD_PAY_COST   = #{addPayCost}
		     , CHG_REASON     = #{chgReason}
		     , CHG_MEMO       = #{chgMemo}
		     , UPD_NO         = #{updNo}
		     , UPD_DT         = NOW()
		 WHERE 1 = 1
		   AND ORD_CHG_SQ = #{ordChgSq}
	</update>
	
	<!-- 입점업체 주문변경신청정보변경 -->
	<select id="getWithdrawInfoForSeller" parameterType="Order" resultType="Order">
		/* TscOrderChange.getWithdrawInfoForSeller */
		SELECT OC.ORD_CHG_SQ 
		     , OD.ORD_NO
		     , OCD.ORD_DTL_NO 
		     , OCD.CHG_QTY 
		     , OD.DELV_FEE_CD
		     , IFNULL(RF.REFUND_AMT, 0) AS REFUND_AMT
		     , DFP.DELV_FEE
		     , DFP.RTN_DELV_FEE 
		     , DFP.MIN_ORD_AMT 
		FROM   TB_ORDER_CHANGE OC
		INNER  JOIN TB_ORDER_CHANGE_DETAIL OCD
		ON     OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ 
		INNER  JOIN TB_ORDER_DETAIL OD
		ON     OCD.ORD_DTL_NO = OD.ORD_DTL_NO 
		INNER  JOIN TB_DELV_FEE_POLICY DFP
		ON     OD.DELV_FEE_CD = DFP.DELV_FEE_CD
		AND    OD.SUPPLY_COMP_CD = DFP.SUPPLY_COMP_CD
		LEFT   OUTER JOIN TB_REFUND RF
		ON     OC.ORD_CHG_SQ = RF.ORD_CHG_SQ 
		WHERE  1=1
		AND    OC.ORD_CHG_SQ = #{ordChgSq}
	</select>

	<!-- 회수결과 등록  -->
	<insert id="insertTbWithdraw" parameterType="Order" >
		/* TscOrderChange.insertTbWithdraw */
		INSERT INTO  TB_WITHDRAW 
		(
		    WD_INVOICE_NO
		    , ORD_CHG_SQ
		    , SENDER_NM
		    , SENDER_PHNNO
		    , SENDER_TELNO
		    , SENDER_POST_NO
		    , SENDER_BASE_ADDR
		    , SENDER_DTL_ADDR
		    , SHIP_COMP_CD
		    , WD_REQ_REASON
		    , ENCLOSE_FEE
		    , WD_MEMO
		    , ARRIVAL_DT
		    , CS_MEMO
		    , CS_OB_YN
		    , SMS_SEND_YN
		    , REG_NO
		    , REG_DT
		    , UPD_NO
		    , UPD_DT
		)
		SELECT
		      IFNULL(OC.WD_INVOICE_NO, '111111111') AS WD_INVOICE_NO
		    , OC.ORD_CHG_SQ 
		    , OC.CHGER_NM
		    , OC.CHGER_PHNNO
		    , OC.CHGER_TELNO
		    , OC.CHGER_ZIPCODE 
		    , OC.CHGER_BASE_ADDR
		    , OC.CHGER_DTL_ADDR
		    , OC.SHIP_COMP_CD  
		    , OC.CHG_REASON			 -- 회수요청사유
		    , NULL 
		    , #{whMemo}              -- 물류메모 
		    , NOW()
		    , NULL 
		    , 'N' 
		    , 'N'                   -- SMS 발송여부 
		    , #{regNo}              -- 등록자NO 
		    , NOW()                 -- 등록일시
		    , #{regNo}              -- 수정자NO
		    , NOW()                 -- 수정일시 
		FROM TB_ORDER_CHANGE OC
		WHERE OC.ORD_CHG_SQ = #{ordChgSq}
		  AND NOT EXISTS (
		        SELECT 1
		          FROM TB_WITHDRAW A
		         WHERE 1=1
		           AND A.ORD_CHG_SQ    = OC.ORD_CHG_SQ 
			)
	</insert>
	
	<!-- 회수상세결과 등록   -->
	<update id="insertTbWithdrawDetail" parameterType="Order">
		/* TscOrderChange.insertTbWithdrawDetail */
		INSERT INTO TB_WITHDRAW_DETAIL 
		(
		       WD_INVOICE_NO
		     , ORD_CHG_SQ
		     , GOODS_CD
		     , OPT_CD1
		     , OPT_CD2
		     , ORD_DTL_NO
		     , WD_QTY
		     , RTN_LOC_CD
		     , SELL_STORE_CD
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT IFNULL(OC.WD_INVOICE_NO, '111111111') AS WD_INVOICE_NO
		     , OCD.ORD_CHG_SQ
		     , ODI.ITEM_CD 
		     , ODI.OPT_CD1
		     , ODI.OPT_CD2 
		     , OCD.ORD_DTL_NO
		     , ODI.ITEM_QTY * OCD.CHG_QTY
		     , NULL
		     , NULL
		     , #{regNo}
		     , NOW()
		     , #{regNo}
		     , NOW()
		FROM   TB_ORDER_CHANGE_DETAIL OCD
		INNER  JOIN TB_ORDER_DETAIL OD
		ON     OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		INNER  JOIN TB_ORDER_DETAIL_ITEM ODI
		ON     OD.ORD_DTL_NO = ODI.ORD_DTL_NO 
		INNER  JOIN TB_ORDER_CHANGE OC
		ON     OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		WHERE  1=1
		AND    OCD.ORD_CHG_SQ = #{ordChgSq}
		AND    OCD.ORD_DTL_NO = #{ordDtlNo}
		AND NOT EXISTS (
		        SELECT 1
		          FROM TB_WITHDRAW_DETAIL A
		         WHERE 1=1
		           AND A.ORD_CHG_SQ = OC.ORD_CHG_SQ
		           AND A.ORD_DTL_NO = OCD.ORD_DTL_NO 
		    )
	</update>
	
	<!-- 주문변경 요청메모 수정 -->
	<update id="updateOrderChangeMemo" parameterType="Order">
		/* TscOrderChange.updateOrderChangeMemo */
		UPDATE TB_ORDER_CHANGE
		   SET CHG_MEMO = #{chgMemo}
		     , UPD_NO   = #{updNo}
		     , UPD_DT   = NOW()
		 WHERE 1 = 1
		   AND ORD_CHG_SQ = #{ordChgSq}
	</update>

	<!-- 주문상세단품정보 조회 -->
	<select id="getOrderDetailItem" parameterType="Order" resultType="Order">
		/* TscOrderChange.getOrderDetailItem */
		SELECT OD.ORD_NO
		     , OD.ORD_DTL_NO
		     , ODI.ORD_DTL_ITEM_SQ
		     , OD.ORD_AMT                                   AS DTL_ORD_AMT
		     , ODI.ORD_AMT                                  AS DTL_ITEM_ORD_AMT
		     , OD.ORD_AMT
		     , OD.CPN1_DC_AMT
		     , OD.TMTB1_DC_AMT
		     , OD.TMTB2_DC_AMT
		     , OD.GOODS_CPN_DC_AMT
		     , OD.CART_CPN_DC_AMT
		     , OD.PNT_DC_AMT
		     , OD.PRE_PNT_DC_AMT
		     , OD.SAVE_PNT_AMT
		     , OD.REAL_ORD_AMT
		     , OD.GFCD_USE_AMT
		     , OD.GOODS_CD
		     , ODI.OPT_CD
		     , ODI.ITEM_CD
		  FROM TB_ORDER_DETAIL OD
		 INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		    ON OD.ORD_NO = ODI.ORD_NO
		   AND OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		 WHERE OD.ORD_NO = #{ordNo}
		   AND OD.ORD_DTL_NO = #{ordDtlNo}
	</select>
	
	<!-- 주문변경정보 조회 -->
	<select id="getOrderChangeDetailInfo" parameterType="OrderChange" resultType="OrderChange">
		/* TscOrderChange.getOrderChangeDetailInfo */
		SELECT OC.ORD_CHG_SQ
		     , OD.ORD_NO
		     , OCD.ORD_DTL_NO
		     , OCD.CHG_QTY
		     , O.CUST_NO
		     , O.ORD_NM
		     , O.ORD_PHNNO
		     , OC.CHG_GB
		     , OC.CHG_REASON
		     , CASE WHEN OC.CHG_GB = 'G680_20' THEN FN_GET_CODE_NM('G686', OC.CHG_REASON)
		            WHEN OC.CHG_GB = 'G680_30' THEN FN_GET_CODE_NM('G688', OC.CHG_REASON)
		            WHEN OC.CHG_GB = 'G680_40' THEN FN_GET_CODE_NM('G689', OC.CHG_REASON)
		            ELSE '결제전취소'
		        END                                       AS CHG_REASON_NM
		     , R.RA_NO                                    AS ACCOUNT_NO
		     , R.RA_BANK                                  AS BANK_CD
		     , R.RA_NM                                    AS ACCOUNT_NM
		     , OC.WD_INVOICE_NO
		     , OC.WD_INVOICE_SEND_YN
		     , OC.ADD_PAY_COST
		     , OCD.CHG_STAT
		     , OD.DELV_FEE_CD
		     , OD.SUPPLY_COMP_CD
		  FROM TB_ORDER_CHANGE OC
		 INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		    ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		 INNER JOIN TB_ORDER O
		    ON OD.ORD_NO = O.ORD_NO
		 INNER JOIN TB_REFUND R
		    ON OC.ORD_CHG_SQ = R.ORD_CHG_SQ
		 WHERE OC.ORD_CHG_SQ = #{ordChgSq}
	</select>
	
	<!-- 환불컨펌 주문변경 수정 -->
	<update id="updateOrderChangeDtl" parameterType="OrderChange">
		/* TscOrderChange.updateOrderChangeDtl */
		UPDATE TB_ORDER_CHANGE_DETAIL
		   SET CHG_STAT     = #{chgStat}
		     , COMPLETE_DT  = NOW()
		     , UPD_NO       = #{updNo}
		     , UPD_DT       = NOW()
		 WHERE ORD_CHG_SQ = #{ordChgSq}
	</update>
	
	<!-- 주문취소시 주문상세단품정보등록을 정보 조회 -->
	<select id="getOrderDetailItemForCnclRtn" parameterType="Order" resultType="Order">
		/* TscOrderChange.getOrderDetailItemForCnclRtn : 주문취소시 주문상세단품정보등록을 정보 조회 */
		SELECT OD.ORD_NO
		     , OD.ORD_DTL_NO
		     , ODI.ORD_DTL_ITEM_SQ
		     , ODI.ITEM_PRICE
		     , ODI.OPT_ADD_PRICE
		     , ODI.ITEM_QTY
		     , OD.ORD_AMT
		     , OD.ORD_AMT AS DTL_ORD_AMT
		     , OD.CNCL_RTN_AMT
		     , OD.ORD_QTY
		     , OD.CNCL_RTN_QTY 
		     , OD.CPN1_DC_AMT 
		     , OD.TMTB1_DC_AMT 
		     , OD.TMTB2_DC_AMT 
		     , OD.GOODS_CPN_DC_AMT 
		     , OD.CART_CPN_DC_AMT 
		     , OD.PRE_PNT_DC_AMT 
		     , OD.PNT_DC_AMT 
		     , OD.GFCD_USE_AMT 
		     , OD.REAL_ORD_AMT
		     , OD.SAVE_PNT_AMT 
		     , ODI.ORD_AMT AS DTL_ITEM_ORD_AMT
		FROM   TB_ORDER_DETAIL OD
		INNER  JOIN TB_ORDER_DETAIL_ITEM ODI
		ON     OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		WHERE 1=1
		AND    OD.ORD_DTL_NO = #{ordDtlNo}
	</select>
	
	<!-- 반품 배송비 마이너스처리  -->
	<insert id="insertTbDeliveryFeeMinus" parameterType="OrderChange" >
		/* TscOrderChange.insertTbDeliveryFeeMinus */
		INSERT INTO TB_DELIVERY_FEE
		(
		      PAY_SQ
		    , ORD_NO
		    , DELV_FEE_GB
		    , DELV_FEE_CD
		    , DELV_FEE
		    , DELV_CPN_SQ
		    , DELV_CPN_DC_AMT
		    , DELV_GFCD_USE_AMT
		    , REAL_DELV_AMT
		    , ORD_CHG_SQ
		    , SUPPLY_COMP_CD
		    , DELV_USAC_YN
		    , DELV_USAC_DT
		    , REG_NO
		    , REG_DT
		    , UPD_NO
		    , UPD_DT
		)
		SELECT 
		      PAY_SQ
		    , ORD_NO
		    , DELV_FEE_GB
		    , DELV_FEE_CD
		    , DELV_FEE * -1
		    , DELV_CPN_SQ
		    , DELV_CPN_DC_AMT * -1
		    , DELV_GFCD_USE_AMT * -1
		    , REAL_DELV_AMT *- 1
		    , #{ordChgSq}
		    , SUPPLY_COMP_CD
		    , 'N'
		    , NULL
		    , #{regNo}
		    , NOW()
		    , #{regNo}
		    , NOW()	
		  FROM TB_DELIVERY_FEE 
		 WHERE ORD_NO      = #{ordNo}
		   AND DELV_FEE_GB = 'G018_10'
		<if test="delvFeeCd != null and delvFeeCd != ''">
		   AND DELV_FEE_CD = #{delvFeeCd}
		   AND SUPPLY_COMP_CD = #{supplyCompCd}
		</if>
	</insert>
	
	<!-- 환불금액 배송비 포함 변경  -->
	<update id="updateRefundChange" parameterType="OrderChange">
		/* TscOrderChange.updateRefundChange */
		UPDATE TB_REFUND SET
		  REFUND_AMT       = #{refundAmt}
		, DEPOSIT_AMT      = #{depositAmt}
		, RF_GFCD_USE_AMT  = #{rfGfcdUseAmt}
		, RF_DELV_GFCD_USE_AMT = #{rfDelvGfcdUseAmt}
		, RF_DELIVERY_FEE  = CASE WHEN #{enCloseFeeYn} = 'Y' || #{codFeeYn} = 'Y' THEN RF_DELIVERY_FEE + IFNULL(#{rfDeliveryFee},0) ELSE #{rfDeliveryFee} END 
		WHERE ORD_NO     = #{ordNo}
		  AND ORD_CHG_SQ = #{ordChgSq}
	</update>
	
	<!-- 착불비 반품배송비로 처리  -->
	<insert id="insertTbDeliveryFeeCodFee" parameterType="OrderChange" >
		/* TscOrderChange.insertTbDeliveryFeeCodFee */
		INSERT INTO TB_DELIVERY_FEE
		(
		      PAY_SQ
		    , ORD_NO
		    , DELV_FEE_GB
		    , DELV_FEE_CD
		    , DELV_FEE
		    , DELV_CPN_SQ
		    , DELV_CPN_DC_AMT
		    , REAL_DELV_AMT
		    , ORD_CHG_SQ
		    , SUPPLY_COMP_CD
		    , DELV_USAC_YN
		    , DELV_USAC_DT
		    , REG_NO
		    , REG_DT
		    , UPD_NO
		    , UPD_DT
		)
		SELECT 
		      PAY_SQ
		    , ORD_NO
		    , 'G018_40'
		    , DELV_FEE_CD
		    , #{codFee}
		    , DELV_CPN_SQ
		    , DELV_CPN_DC_AMT
		    , #{codFee}
		    , #{ordChgSq}
		    , SUPPLY_COMP_CD
		    , DELV_USAC_YN
		    , DELV_USAC_DT
		    , #{regNo}
		    , NOW()
		    , #{regNo}
		    , NOW()	
		  FROM TB_DELIVERY_FEE 
		 WHERE ORD_NO      = #{ordNo}
		   AND DELV_FEE_GB = 'G018_10'
		   AND DELV_FEE_CD = #{delvFeeCd}
	</insert>
	
	<!-- 반품 배송비 마이너스처리  -->
	<update id="updateWithdrawFee" parameterType="OrderChange" >
		/* TscOrderChange.updateWithdrawFee */
		UPDATE TB_WITHDRAW SET
		   COD_FEE     = #{codFee}
		 , ENCLOSE_FEE = #{encloseFee}
		 , UPD_NO      = #{updNo}
		 , UPD_DT      = NOW()
		WHERE WD_INVOICE_NO  = #{wdInvoiceNo}
		  AND ORD_CHG_SQ     = #{ordChgSq}
	</update>
		
	<!-- 취소 알림톡 정보 조회 -->
	<select id="getKakaoOrderCancelInfo" parameterType="int" resultType="OrderChange">
		/* TscOrderChange.getKakaoOrderCancelInfo */
		SELECT Z.*
		     , DATE_FORMAT(ADDDATE(Z.ORD_DT, INTERVAL 3 DAY), '%Y년 %m월 %d일')                    AS GIFT_PACK_CLOSE_DT
		  FROM (SELECT O.ORD_NO
		             , OC.ORD_CHG_SQ
		             , OC.CHG_REASON
		             , O.ORD_NM
		             , O.ORD_PHNNO
		             , O.MALL_GB
		             , R.REFUND_AMT                                                               AS REFUND_AMT
		             , G.GOODS_NM
		             , P.PAY_MEANS
		             , FN_GET_CODE_NM('G014', P.PAY_MEANS)                                        AS PAY_MEANS_NM
		             , P.PG_GB
		             , P.PAY_STAT
		             , O.CUST_NO
		             , O.ORD_DT
		             , IFNULL(CA.ACCOUNT_NM, R.RA_NM) AS ACCOUNT_NM
		             , IFNULL(CA.ACCOUNT_NO, R.RA_NO) AS ACCOUNT_NO
		             , IFNULL(CA.BANK_CD, R.RA_BANK)  AS BANK_CD
		             , COUNT(*) OVER (PARTITION BY OC.ORD_CHG_SQ) - 1                             AS GOODS_CNT
		             , ROW_NUMBER() OVER (PARTITION BY OC.ORD_CHG_SQ ORDER BY OCD.ORD_DTL_NO)     AS RNUM
		          FROM TB_ORDER_CHANGE OC
		         INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		            ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		         INNER JOIN TB_ORDER_DETAIL OD
		            ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		         INNER JOIN TB_ORDER O
		            ON O.ORD_NO = OD.ORD_NO
		           AND O.MALL_GB = 'G011_10'
		         INNER JOIN TB_REFUND R
		            ON OC.ORD_CHG_SQ = R.ORD_CHG_SQ
		         INNER JOIN TB_PAYMENT P
		            ON OC.ORD_CHG_SQ = P.ORD_CHG_SQ
		           AND O.ORD_NO = P.ORD_NO
		         INNER JOIN TB_GOODS G
		            ON OD.GOODS_CD = G.GOODS_CD
		          LEFT OUTER JOIN TB_CUST_ACCOUNT CA
		            ON O.CUST_NO = CA.CUST_NO
		         WHERE OC.ORD_CHG_SQ = #{ordChgSq}
		           AND OC.CHG_GB IN ('G680_10', 'G680_20')
		         GROUP BY O.ORD_NO, OC.ORD_CHG_SQ, OC.CHG_REASON, OCD.ORD_DTL_NO, O.ORD_NM, O.ORD_PHNNO, O.MALL_GB, R.REFUND_AMT
		                , R.RF_GFCD_USE_AMT ,R.RF_DELV_GFCD_USE_AMT ,R.RF_PNT_AMT, R.RA_NM ,R.RA_NO ,R.RA_BANK,  G.GOODS_NM, P.PAY_MEANS
		                , PAY_MEANS_NM, P.PG_GB, O.CUST_NO, P.PAY_STAT, CA.ACCOUNT_NM, CA.ACCOUNT_NO, CA.BANK_CD, O.ORD_DT
		        ) Z
		 WHERE Z.RNUM = 1
	</select>

	<!-- 반품 알림톡 정보 조회 -->
	<select id="getKakaoOrderReturnInfo" parameterType="int" resultType="OrderChange">
		/* TscOrderChange.getKakaoOrderReturnInfo */
		SELECT Z.*
		  FROM (SELECT O.ORD_NO
		             , OC.ORD_CHG_SQ
		             , O.ORD_NM
		             , O.ORD_PHNNO
		             , O.MALL_GB
		             , G.GOODS_NM
		             , O.CUST_NO
		             , OC.CHGER_BASE_ADDR
		             , OC.CHGER_DTL_ADDR
		             , OC.WD_GB
		             , IF(IFNULL(P.PAY_AMT, 0) > 0, 0, OC.ADD_PAY_COST)                       AS ADD_PAY_COST
		             , COUNT(*) OVER (PARTITION BY OC.ORD_CHG_SQ) - 1                         AS GOODS_CNT
		             , ROW_NUMBER() OVER (PARTITION BY OC.ORD_CHG_SQ ORDER BY OCD.ORD_DTL_NO) AS RNUM
		          FROM TB_ORDER_CHANGE OC
		         INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		            ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		         INNER JOIN TB_ORDER_DETAIL OD
		            ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		         INNER JOIN TB_ORDER O
		            ON O.ORD_NO = OD.ORD_NO
		           AND O.MALL_GB = 'G011_10'
		         INNER JOIN TB_GOODS G
		            ON OD.GOODS_CD = G.GOODS_CD
		          LEFT OUTER JOIN TB_PAYMENT P
		            ON OC.ORD_CHG_SQ = P.ORD_CHG_SQ
		           AND P.PAY_GB = 'D'
		           AND P.PAY_STAT = 'G016_30'
		         WHERE OC.ORD_CHG_SQ = #{ordChgSq}
		         GROUP BY O.ORD_NO, OC.ORD_CHG_SQ, OCD.ORD_DTL_NO, O.ORD_NM, O.ORD_PHNNO, O.MALL_GB, G.GOODS_NM, O.CUST_NO, OC.CHGER_BASE_ADDR
		                , OC.CHGER_DTL_ADDR, OC.WD_GB, OC.ADD_PAY_COST, P.PAY_AMT
		       ) Z
		 WHERE Z.RNUM = 1
	</select>

	<!-- 마이페이지 취소 상세 정보 조회 -->
	<select id="getCreCancelDetailInfo" parameterType="OrderChange" resultType="OrderChange">
		/* TscOrderChange.getCreCancelDetailInfo */
		SELECT GROUP_CONCAT(Z.ITEM_NM ORDER BY Z.ORD_DTL_ITEM_SQ SEPARATOR '!@!')       AS ITEM_NM
		     , GROUP_CONCAT(Z.COLOR_NM ORDER BY Z.ORD_DTL_ITEM_SQ)                      AS COLOR_NM
		     , GROUP_CONCAT(Z.OPT_CD1 ORDER BY Z.ORD_DTL_ITEM_SQ)                       AS OPT_CD1
		     , GROUP_CONCAT(Z.OPT_CD2 ORDER BY Z.ORD_DTL_ITEM_SQ)                       AS OPT_CD2
		     , Z.ORD_CHG_SQ
		     , Z.CHG_GB
		     , Z.CHG_QTY
		     , Z.ORD_DT
		     , Z.ORD_DATE
		     , Z.CHG_DATE
		     , Z.CHG_TIME
		     , Z.CHG_DT
		     , Z.COMPLETE_DT
		     , Z.CHG_STAT
		     , Z.CHG_STAT_NM
		     , Z.CHG_REASON
		     , Z.ORD_NO
		     , Z.ORD_AMT
		     , Z.ORD_QTY
		     , Z.CNCL_RTN_QTY
		     , Z.CNCL_RTN_AMT
		     , Z.CPN1_DC_AMT
		     , Z.REAL_ORD_AMT
		     , Z.PNT_DC_AMT
		     , Z.GFCD_USE_AMT
		     , Z.ORD_DTL_NO
		     , Z.GOODS_CD
		     , Z.BRAND_NM
		     , Z.SHOT_DELV_YN
		     , Z.SELF_GOODS_YN
		     , Z.GOODS_NM
		     , Z.GOODS_TYPE
		     , Z.ADD_PAY_COST
		     , Z.SYS_IMG_NM
		     , Z.GIFT_PACK_YN
		     , Z.GIFT_ADDR_INP_YN
		     , Z.GIFT_CANCEL_DAY
		     , Z.DELV_FEE_CD
		     , Z.SUPPLY_COMP_NM
		     , Z.ORD_NM
		     , Z.CUST_NO
		     , Z.ORD_EMAIL
		     , Z.REFUND_AMT
		     , Z.RF_CPN1_AMT
		     , Z.RF_TMTB1_AMT
		     , Z.RF_TMTB2_AMT
		     , Z.RF_GOODS_CPN_AMT
		     , Z.RF_CART_CPN_AMT
		     , Z.RF_DELV_CPN_AMT
		     , Z.RF_PNT_AMT
		     , Z.RF_PRE_PNT_AMT
		     , Z.RF_GFCD_USE_AMT
		     , Z.RF_DELV_GFCD_USE_AMT
		     , Z.RF_CNCL_AMT
		     , Z.RF_DELIVERY_FEE
		     , Z.RF_REAL_CNCL_AMT
		     , Z.PG_TID
		     , Z.PG_GB
		     , Z.PAY_MEANS
		     , Z.PAY_MEANS_NM
		FROM (SELECT OC.ORD_CHG_SQ
		           , OC.CHG_GB
		           , OCD.CHG_QTY
		           , DATE_FORMAT(O.ORD_DT, '%Y.%m.%d')                                AS ORD_DT
		           , DATE_FORMAT(O.ORD_DT, '%Y.%m.%d %H:%i')                          AS ORD_DATE
		           , DATE_FORMAT(OCDH.REG_DT, '%Y.%m.%d')                             AS CHG_DATE
		           , DATE_FORMAT(OCDH.REG_DT,'%H:%i:%S')                              AS CHG_TIME
		           , DATE_FORMAT(OCD.REG_DT, '%Y.%m.%d')                              AS CHG_DT
		           , DATE_FORMAT(OCD.COMPLETE_DT, '%Y.%m.%d')                         AS COMPLETE_DT
		           , OCD.CHG_STAT
		           , FN_GET_CODE_NM('G685', OCD.CHG_STAT)                             AS CHG_STAT_NM
		           , OC.CHG_REASON
		           , OD.ORD_NO
		           , OD.ORD_AMT
		           , OD.ORD_QTY
		           , OD.CNCL_RTN_QTY
		           , OD.CNCL_RTN_AMT
		           , OD.CPN1_DC_AMT
		           , OD.REAL_ORD_AMT
		           , OD.PNT_DC_AMT
		           , OD.GFCD_USE_AMT
		           , OCD.ORD_DTL_NO
		           , G1.GOODS_CD
		           , CASE BG.DISP_NM_LANG WHEN 'EN' THEN BG.BRAND_GROUP_ENM
		             ELSE BG.BRAND_GROUP_KNM
		              END                                                             AS BRAND_NM
		           , OD.SHOT_DELV_YN
		           , G1.SELF_GOODS_YN
		           , G1.GOODS_NM
		           , IFNULL((SELECT COLOR_KNM FROM TB_COLOR WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,'') , G1.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		           , G2.GOODS_NM                                                      AS ITEM_NM
		           , G1.GOODS_TYPE
		           , ODI.ORD_DTL_ITEM_SQ
		           , ODI.OPT_CD1
		           , ODI.OPT_CD2
		           , OC.ADD_PAY_COST
		           , CASE WHEN G1.GOODS_TYPE != 'G056_S' AND G1.SELF_GOODS_YN = 'Y' THEN (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G1.GOODS_CD AND COLOR_CD = ODI.OPT_CD1 AND DEFAULT_IMG_YN = 'Y')
		             ELSE (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G1.GOODS_CD AND COLOR_CD = IFNULL(G1.MAIN_COLOR_CD,'XX') AND DEFAULT_IMG_YN = 'Y') END AS SYS_IMG_NM
		           , OD.GIFT_PACK_YN
		           , OD.GIFT_ADDR_INP_YN
		           , TIMESTAMPDIFF(DAY, O.ORD_DT, OCDH.REG_DT)                        AS GIFT_CANCEL_DAY
		           , OD.DELV_FEE_CD
		           , FN_GET_SUPPLY_COMP_NM(OD.SUPPLY_COMP_CD)                         AS SUPPLY_COMP_NM
		           , O.ORD_NM
		           , O.CUST_NO
		           , O.ORD_EMAIL
		           , R.REFUND_AMT
		           , R.RF_CPN1_AMT
		           , R.RF_TMTB1_AMT
		           , R.RF_TMTB2_AMT
		           , R.RF_GOODS_CPN_AMT
		           , R.RF_CART_CPN_AMT
		           , R.RF_DELV_CPN_AMT
		           , R.RF_PNT_AMT
		           , R.RF_PRE_PNT_AMT
		           , R.RF_GFCD_USE_AMT
		           , R.RF_DELV_GFCD_USE_AMT
		           , R.RF_CNCL_AMT
		           , R.RF_DELIVERY_FEE
		           , R.RF_REAL_CNCL_AMT
		           , P.PG_TID
		           , P.PG_GB
		           , P.PAY_MEANS
		           , FN_GET_CODE_NM('G014', P.PAY_MEANS)                              AS PAY_MEANS_NM
		        FROM TB_ORDER_CHANGE OC
		       INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		          ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		        LEFT OUTER JOIN TB_ORDER_CHANGE_DETAIL_HST OCDH
		          ON OCD.ORD_CHG_SQ = OCDH.ORD_CHG_SQ
		         AND OCD.ORD_DTL_NO = OCDH.ORD_DTL_NO
		         AND OCD.CHG_STAT = OCDH.CHG_STAT
		       INNER JOIN TB_ORDER_DETAIL OD
		          ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		         AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_11', 'G013_25')
		       INNER JOIN TB_ORDER O
		          ON OD.ORD_NO = O.ORD_NO
		       INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		          ON OD.ORD_NO = ODI.ORD_NO
		         AND OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		         AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_11', 'G013_25')
		       INNER JOIN TB_GOODS G1
		          ON OD.GOODS_CD = G1.GOODS_CD
		       INNER JOIN TB_GOODS G2
		          ON ODI.ITEM_CD = G2.GOODS_CD
		       INNER JOIN TB_BRAND B
		          ON G1.BRAND_CD = B.BRAND_CD
		         AND B.USE_YN = 'Y'
		       INNER JOIN TB_BRAND_GROUP BG
		          ON B.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		         AND BG.USE_YN = 'Y'
		        LEFT OUTER JOIN TB_REFUND R
		          ON R.ORD_CHG_SQ = OC.ORD_CHG_SQ
		       INNER JOIN TB_PAYMENT P
		          ON P.ORD_NO = O.ORD_NO
		         AND P.PAY_GB = 'O'
		         AND P.PAY_STAT IN ('G016_10', 'G016_30')
		         AND P.PG_GB <![CDATA[<>]]> 'NAVER_ORDER'
		       WHERE OCD.DEL_YN = 'N'
		--         AND O.DISP_YN = 'Y'
		<choose>
			<when test="custNo > 0">
		         AND O.CUST_NO = #{custNo}
			</when>
			<otherwise>
		         AND O.ORD_NO = #{ordNo}
		         AND O.ORD_NM = #{ordNm}
		         AND O.ORD_PHNNO = #{ordPhnno}
			</otherwise>
		</choose>
		<if test="ordChgSq != null and ordChgSq != ''">
		         AND OC.ORD_CHG_SQ = #{ordChgSq}
		</if>
		) Z
		 GROUP BY Z.ORD_CHG_SQ, Z.CHG_GB, Z.CHG_QTY, Z.ORD_DT, Z.ORD_DATE, Z.CHG_DATE, Z.CHG_TIME, Z.CHG_DT, Z.COMPLETE_DT, Z.CHG_STAT
		        , Z.CHG_STAT_NM, Z.CHG_REASON, Z.ORD_NO, Z.ORD_AMT, Z.ORD_QTY, Z.CNCL_RTN_QTY, Z.CNCL_RTN_AMT, Z.CPN1_DC_AMT, Z.REAL_ORD_AMT, Z.PNT_DC_AMT
		        , Z.GFCD_USE_AMT, Z.ORD_DTL_NO, Z.GOODS_CD, Z.BRAND_NM, Z.SHOT_DELV_YN, Z.SELF_GOODS_YN, Z.GOODS_NM, Z.GOODS_TYPE
		        , Z.ADD_PAY_COST, Z.SYS_IMG_NM, Z.GIFT_PACK_YN, Z.GIFT_ADDR_INP_YN, Z.GIFT_CANCEL_DAY, Z.DELV_FEE_CD, Z.SUPPLY_COMP_NM, Z.ORD_NM, Z.CUST_NO, Z.ORD_EMAIL
		        , Z.REFUND_AMT, Z.RF_CPN1_AMT, Z.RF_TMTB1_AMT, Z.RF_TMTB2_AMT, Z.RF_GOODS_CPN_AMT, Z.RF_CART_CPN_AMT, Z.RF_DELV_CPN_AMT, Z.RF_PNT_AMT
		        , Z.RF_PRE_PNT_AMT, Z.RF_GFCD_USE_AMT, Z.RF_DELV_GFCD_USE_AMT, Z.RF_CNCL_AMT, Z.RF_DELIVERY_FEE, Z.RF_REAL_CNCL_AMT, Z.PG_TID, Z.PG_GB, Z.PAY_MEANS, Z.PAY_MEANS_NM
		 ORDER BY Z.ORD_CHG_SQ DESC, Z.DELV_FEE_CD DESC, Z.ORD_DTL_NO DESC
	</select>

	<!-- 마이페이지 반품 상세 정보 조회 -->
	<select id="getCreReturnDetailInfo" parameterType="OrderChange" resultType="OrderChange">
		/* TsfOrderChange.getCreReturnDetailInfo */
		SELECT GROUP_CONCAT(Z.ITEM_NM ORDER BY Z.ORD_DTL_ITEM_SQ SEPARATOR '!@!')       AS ITEM_NM
		     , GROUP_CONCAT(Z.COLOR_NM ORDER BY Z.ORD_DTL_ITEM_SQ)                      AS COLOR_NM
		     , GROUP_CONCAT(Z.OPT_CD1 ORDER BY Z.ORD_DTL_ITEM_SQ)                       AS OPT_CD1
		     , GROUP_CONCAT(Z.OPT_CD2 ORDER BY Z.ORD_DTL_ITEM_SQ)                       AS OPT_CD2
		     , Z.ORD_CHG_SQ
		     , Z.CHG_GB
		     , Z.CHG_QTY
		     , Z.ORD_DT
		     , Z.ORD_DATE
		     , Z.CHG_DATE
		     , Z.CHG_TIME
		     , Z.CHG_DT
		     , Z.COMPLETE_DT
		     , Z.CHG_STAT
		     , Z.CHG_STAT_NM
		     , Z.ORD_NO
		     , Z.DELV_FEE_CD
		     , Z.ORD_AMT
		     , Z.ORD_QTY
		     , Z.CNCL_RTN_QTY
		     , Z.CNCL_RTN_AMT
		     , Z.CPN1_DC_AMT
		     , Z.REAL_ORD_AMT
		     , Z.PNT_DC_AMT
		     , Z.GFCD_USE_AMT
		     , Z.ORD_DTL_NO
		     , Z.GOODS_CD
		     , Z.BRAND_NM
		     , Z.SHOT_DELV_YN
		     , Z.SELF_GOODS_YN
		     , Z.GOODS_NM
		     , Z.GOODS_TYPE
		     , Z.PRICE_ORG
		     , Z.PRICE_SALE
		     , Z.ADD_PAY_COST
		     , Z.SYS_IMG_NM
		     , Z.GIFT_PACK_YN
		     , Z.REFUND_AMT
		     , Z.RF_CPN1_AMT
		     , Z.RF_TMTB1_AMT
		     , Z.RF_TMTB2_AMT
		     , Z.RF_GOODS_CPN_AMT
		     , Z.RF_CART_CPN_AMT
		     , Z.RF_DELV_CPN_AMT
		     , Z.RF_PNT_AMT
		     , Z.RF_PRE_PNT_AMT
		     , Z.RF_GFCD_USE_AMT
		     , Z.RF_CNCL_AMT
		     , Z.RF_DELIVERY_FEE
		     , Z.RF_REAL_CNCL_AMT
		     , Z.PG_GB
		     , Z.PAY_MEANS
		     , Z.PAY_MEANS_NM
		     , Z.WD_GB
		     , Z.CHGER_NM
		     , Z.CHGER_PHNNO
		     , Z.CHGER_BASE_ADDR
		     , Z.CHGER_DTL_ADDR
		     , Z.CHGER_RTN_MEMO
		     , Z.CHGER_ZIPCODE
		     , Z.WD_INVOICE_NO
		     , Z.SHIP_COMP_CD
		     , Z.SHIP_COMP_NM
		     , Z.ORD_NM
		     , Z.ORD_EMAIL
		     , Z.CUST_NO
		  FROM (SELECT OC.ORD_CHG_SQ
		             , OC.CHG_GB
		             , OCD.CHG_QTY
		             , DATE_FORMAT(O.ORD_DT, '%Y.%m.%d')                                AS ORD_DT
		             , DATE_FORMAT(O.ORD_DT, '%Y.%m.%d %H:%i')                          AS ORD_DATE
		             , DATE_FORMAT(OCDH.REG_DT, '%Y.%m.%d')                             AS CHG_DATE
		             , DATE_FORMAT(OCDH.REG_DT,'%H:%i:%S')                              AS CHG_TIME
		             , DATE_FORMAT(OCD.REG_DT, '%Y.%m.%d')                              AS CHG_DT
		             , DATE_FORMAT(OCD.COMPLETE_DT, '%Y.%m.%d')                         AS COMPLETE_DT
		             , OCD.CHG_STAT
		             , FN_GET_CODE_NM('G685', OCD.CHG_STAT)                             AS CHG_STAT_NM
		             , OD.ORD_NO
		             , OD.DELV_FEE_CD
		             , OD.ORD_AMT
		             , OD.ORD_QTY
		             , OD.CNCL_RTN_QTY
		             , OD.CNCL_RTN_AMT
		             , OD.CPN1_DC_AMT
		             , OD.REAL_ORD_AMT
		             , OD.PNT_DC_AMT
		             , OD.GFCD_USE_AMT
		             , OCD.ORD_DTL_NO
		             , G1.GOODS_CD
		             , CASE BG.DISP_NM_LANG WHEN 'EN' THEN BG.BRAND_GROUP_ENM
		               ELSE BG.BRAND_GROUP_KNM
		                END                                                             AS BRAND_NM
		             , OD.SHOT_DELV_YN
		             , G1.SELF_GOODS_YN
		             , G1.GOODS_NM
		             , IFNULL((SELECT COLOR_KNM FROM TB_COLOR WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,'') , G1.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		             , G2.GOODS_NM                                                      AS ITEM_NM
		             , G1.GOODS_TYPE
		             , ODI.ORD_DTL_ITEM_SQ
		             , ODI.OPT_CD1
		             , ODI.OPT_CD2
		             , ((OD.ORD_AMT - OD.CNCL_RTN_AMT - OD.CPN1_DC_AMT) * (OCD.CHG_QTY / (OD.ORD_QTY - OD.CNCL_RTN_QTY))) AS PRICE_ORG
		             , ((OD.REAL_ORD_AMT + OD.PNT_DC_AMT + OD.GFCD_USE_AMT) * (OCD.CHG_QTY / (OD.ORD_QTY - OD.CNCL_RTN_QTY))) AS PRICE_SALE
		             , OC.ADD_PAY_COST
		             , CASE WHEN G1.GOODS_TYPE != 'G056_S' AND G1.SELF_GOODS_YN = 'Y' THEN (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G1.GOODS_CD AND COLOR_CD = ODI.OPT_CD1 AND DEFAULT_IMG_YN = 'Y')
		               ELSE (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G1.GOODS_CD AND COLOR_CD = IFNULL(G1.MAIN_COLOR_CD,'XX') AND DEFAULT_IMG_YN = 'Y') END AS SYS_IMG_NM
		             , OD.GIFT_PACK_YN
		             , R.REFUND_AMT
		             , R.RF_CPN1_AMT
		             , R.RF_TMTB1_AMT
		             , R.RF_TMTB2_AMT
		             , R.RF_GOODS_CPN_AMT
		             , R.RF_CART_CPN_AMT
		             , R.RF_DELV_CPN_AMT
		             , R.RF_PNT_AMT
		             , R.RF_PRE_PNT_AMT
		             , R.RF_GFCD_USE_AMT
		             , R.RF_CNCL_AMT
		             , R.RF_DELIVERY_FEE
		             , R.RF_REAL_CNCL_AMT
		             , P.PG_GB
		             , P.PAY_MEANS
		             , FN_GET_CODE_NM('G014', P.PAY_MEANS)                              AS PAY_MEANS_NM
		             , OC.WD_GB
		             , OC.CHGER_NM
		             , OC.CHGER_PHNNO
		             , OC.CHGER_BASE_ADDR
		             , OC.CHGER_DTL_ADDR
		             , OC.CHGER_RTN_MEMO
		             , OC.CHGER_ZIPCODE
		             , OC.WD_INVOICE_NO
		             , OC.SHIP_COMP_CD
		             , (SELECT SHIP_COMP_NM
		                  FROM TB_SHIP_COMPANY SC
		                 WHERE SC.SHIP_COMP_CD = OC.SHIP_COMP_CD)                       AS SHIP_COMP_NM
		             , O.ORD_NM
		             , O.ORD_EMAIL
		             , O.CUST_NO
		          FROM TB_ORDER_CHANGE OC
		         INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		            ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		          LEFT OUTER JOIN TB_ORDER_CHANGE_DETAIL_HST OCDH
		            ON OCD.ORD_CHG_SQ = OCDH.ORD_CHG_SQ
		           AND OCD.ORD_DTL_NO = OCDH.ORD_DTL_NO
		           AND OCD.CHG_STAT = OCDH.CHG_STAT
		         INNER JOIN TB_ORDER_DETAIL OD
		            ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		           AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_11', 'G013_25')
		         INNER JOIN TB_ORDER O
		            ON OD.ORD_NO = O.ORD_NO
		         INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		            ON OD.ORD_NO = ODI.ORD_NO
		           AND OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		           AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_11', 'G013_25')
		         INNER JOIN TB_GOODS G1
		            ON OD.GOODS_CD = G1.GOODS_CD
		         INNER JOIN TB_GOODS G2
		           ON ODI.ITEM_CD = G2.GOODS_CD
		         INNER JOIN TB_BRAND B
		            ON G1.BRAND_CD = B.BRAND_CD
		           AND B.USE_YN = 'Y'
		         INNER JOIN TB_BRAND_GROUP BG
		            ON B.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		           AND BG.USE_YN = 'Y'
		          LEFT OUTER JOIN TB_REFUND R
		            ON R.ORD_CHG_SQ = OC.ORD_CHG_SQ
		         INNER JOIN TB_PAYMENT P
		            ON P.ORD_NO = O.ORD_NO
		           AND P.PAY_GB = 'O'
		           AND P.PAY_STAT = 'G016_30'
		           AND P.PG_GB <![CDATA[<>]]> 'NAVER_ORDER'
		<where>
			<choose>
				<when test="custNo > 0">
		           AND O.CUST_NO = #{custNo}
				</when>
				<otherwise>
		           AND O.ORD_NO = #{ordNo}
		           AND O.ORD_NM = #{ordNm}
		           AND O.ORD_PHNNO = #{ordPhnno}
				</otherwise>
			</choose>
			<if test="ordChgSq != null and ordChgSq != ''">
		           AND OC.ORD_CHG_SQ = #{ordChgSq}
			</if>
		</where>
		) Z
		 GROUP BY Z.ORD_CHG_SQ, Z.CHG_GB, Z.CHG_QTY, Z.ORD_DT, Z.ORD_DATE, Z.CHG_DATE, Z.CHG_TIME, Z.CHG_DT, Z.COMPLETE_DT, Z.CHG_STAT
		        , Z.CHG_STAT_NM, Z.ORD_NO, Z.DELV_FEE_CD, Z.ORD_AMT, Z.ORD_QTY, Z.CNCL_RTN_QTY, Z.CNCL_RTN_AMT, Z.CPN1_DC_AMT, Z.REAL_ORD_AMT, Z.PNT_DC_AMT
		        , Z.GFCD_USE_AMT, Z.ORD_DTL_NO, Z.GOODS_CD, Z.BRAND_NM, Z.SHOT_DELV_YN, Z.SELF_GOODS_YN, Z.GOODS_NM
		        , Z.GOODS_TYPE, Z.PRICE_ORG, Z.PRICE_SALE, Z.ADD_PAY_COST, Z.SYS_IMG_NM, Z.GIFT_PACK_YN, Z.REFUND_AMT, Z.RF_CPN1_AMT, Z.RF_TMTB1_AMT
		        , Z.RF_TMTB2_AMT, Z.RF_GOODS_CPN_AMT, Z.RF_CART_CPN_AMT, Z.RF_DELV_CPN_AMT, Z.RF_PNT_AMT, Z.RF_PRE_PNT_AMT, Z.RF_GFCD_USE_AMT, Z.RF_CNCL_AMT
		        , Z.RF_DELIVERY_FEE, Z.RF_REAL_CNCL_AMT, Z.PG_GB, Z.PAY_MEANS, Z.PAY_MEANS_NM, Z.WD_GB, Z.CHGER_NM, Z.CHGER_PHNNO, Z.CHGER_BASE_ADDR
		        , Z.CHGER_DTL_ADDR, Z.CHGER_RTN_MEMO, Z.CHGER_ZIPCODE, Z.WD_INVOICE_NO, Z.SHIP_COMP_CD, Z.SHIP_COMP_NM, Z.ORD_NM, Z.ORD_EMAIL, Z.CUST_NO
		 ORDER BY Z.ORD_CHG_SQ DESC, Z.DELV_FEE_CD DESC, Z.ORD_DTL_NO DESC
	</select>

	<!-- 마이페이지 교환 상세 정보 조회 -->
	<select id="getCreExchangeDetailInfo" parameterType="OrderChange" resultType="OrderChange">
		/* TsfOrderChange.getCreExchangeDetailInfo */
		SELECT GROUP_CONCAT(Z.ITEM_NM ORDER BY Z.ORD_DTL_ITEM_SQ SEPARATOR '!@!')       AS ITEM_NM
		     , GROUP_CONCAT(Z.COLOR_NM ORDER BY Z.ORD_DTL_ITEM_SQ)                      AS COLOR_NM
		     , GROUP_CONCAT(Z.OPT_CD1 ORDER BY Z.ORD_DTL_ITEM_SQ)                       AS OPT_CD1
		     , GROUP_CONCAT(Z.OPT_CD2 ORDER BY Z.ORD_DTL_ITEM_SQ)                       AS OPT_CD2
		     , Z.ORD_CHG_SQ
		     , Z.CHG_GB
		     , Z.WD_BF_SEND_YN
		     , Z.CHG_QTY
		     , Z.ORD_DT
		     , Z.ORD_DATE
		     , Z.CHG_DATE
		     , Z.CHG_TIME
		     , Z.CHG_DT
		     , Z.COMPLETE_DT
		     , Z.CHG_STAT
		     , Z.CHG_STAT_NM
		     , Z.ORD_DTL_STAT
		     , Z.EXCHANGE_SHIP_COMP_CD
		     , Z.EXCHANGE_INVOICE_NO
		     , Z.ORD_NO
		     , Z.DELV_FEE_CD
		     , Z.ORD_AMT
		     , Z.ORD_QTY
		     , Z.CNCL_RTN_QTY
		     , Z.CNCL_RTN_AMT
		     , Z.CPN1_DC_AMT
		     , Z.REAL_ORD_AMT
		     , Z.PNT_DC_AMT
		     , Z.GFCD_USE_AMT
		     , Z.ORD_DTL_NO
		     , Z.CHG_ORD_DTL_NO
		     , Z.GOODS_CD
		     , Z.BRAND_NM
		     , Z.SHOT_DELV_YN
		     , Z.SELF_GOODS_YN
		     , Z.GOODS_NM
		     , Z.GOODS_TYPE
		     , Z.PRICE_ORG
		     , Z.PRICE_SALE
		     , Z.ADD_PAY_COST
		     , Z.SYS_IMG_NM
		     , Z.GIFT_PACK_YN
		     , Z.WD_GB
		     , Z.CHGER_NM
		     , Z.CHGER_PHNNO
		     , Z.CHGER_BASE_ADDR
		     , Z.CHGER_DTL_ADDR
		     , Z.CHGER_ZIPCODE
		     , Z.CHGER_RTN_MEMO
		     , Z.CHG_MEMO
		     , Z.WD_INVOICE_NO
		     , Z.SHIP_COMP_CD
		     , Z.SHIP_COMP_NM
		     , Z.DELV_ADDR_SQ
		     , Z.RECIP_NM
		     , Z.RECIP_PHNNO
		     , Z.RECIP_BASE_ADDR
		     , Z.RECIP_DTL_ADDR
		     , Z.RECIP_ZIPCODE
		     , Z.DELV_MEMO
		     , Z.PG_TID
		     , Z.PAY_MEANS
		     , Z.PAY_MEANS_NM
		     , Z.CARD_NM
		     , Z.CARD_MIPS
		     , Z.CHG_ORD_DTL_STAT
		     , Z.ORD_NM
		     , Z.ORD_EMAIL
		     , Z.CUST_NO
		  FROM (SELECT OC.ORD_CHG_SQ
		             , OC.CHG_GB
		             , OC.WD_BF_SEND_YN
		             , OCD.CHG_QTY
		             , DATE_FORMAT(O.ORD_DT, '%Y.%m.%d')                                AS ORD_DT
		             , DATE_FORMAT(O.ORD_DT, '%Y.%m.%d %H:%i')                          AS ORD_DATE
		             , DATE_FORMAT(OCDH.REG_DT, '%Y.%m.%d')                             AS CHG_DATE
		             , DATE_FORMAT(OCDH.REG_DT,'%H:%i:%S')                              AS CHG_TIME
		             , DATE_FORMAT(OCD.REG_DT, '%Y.%m.%d')                              AS CHG_DT
		             , DATE_FORMAT(OCD.COMPLETE_DT, '%Y.%m.%d')                         AS COMPLETE_DT
		             , OCD.CHG_STAT
		             , FN_GET_CODE_NM('G685', OCD.CHG_STAT)                             AS CHG_STAT_NM
		             , OD2.ORD_DTL_STAT                                                 AS ORD_DTL_STAT
		             , OD2.INVOICE_NO                                                   AS EXCHANGE_INVOICE_NO
		             , OD2.SHIP_COMP_CD                                                 AS EXCHANGE_SHIP_COMP_CD
		             , OD.ORD_NO
		             , OD.DELV_FEE_CD
		             , OD.ORD_AMT
		             , OD.ORD_QTY
		             , OD.CNCL_RTN_QTY
		             , OD.CNCL_RTN_AMT
		             , OD.CPN1_DC_AMT
		             , OD.REAL_ORD_AMT
		             , OD.PNT_DC_AMT
		             , OD.GFCD_USE_AMT
		             , OCD.ORD_DTL_NO
		             , OCD.CHG_ORD_DTL_NO
		             , G1.GOODS_CD
		             , CASE BG.DISP_NM_LANG WHEN 'EN' THEN BG.BRAND_GROUP_ENM
		               ELSE BG.BRAND_GROUP_KNM
		                END                                                             AS BRAND_NM
		             , OD.SHOT_DELV_YN
		             , G1.SELF_GOODS_YN
		             , G1.GOODS_NM
		             , IFNULL((SELECT COLOR_KNM FROM TB_COLOR WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,'') , G1.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		             , G2.GOODS_NM                                                      AS ITEM_NM
		             , G1.GOODS_TYPE
		             , ODI.ORD_DTL_ITEM_SQ
		             , ODI.OPT_CD1
		             , ODI.OPT_CD2
		             , ((OD.ORD_AMT - OD.CNCL_RTN_AMT - OD.CPN1_DC_AMT) * (OCD.CHG_QTY / (OD.ORD_QTY - OD.CNCL_RTN_QTY))) AS PRICE_ORG
		             , ((OD.REAL_ORD_AMT + OD.PNT_DC_AMT + OD.GFCD_USE_AMT) * (OCD.CHG_QTY / (OD.ORD_QTY - OD.CNCL_RTN_QTY))) AS PRICE_SALE
		             , OC.ADD_PAY_COST
		             , CASE WHEN G1.GOODS_TYPE != 'G056_S' AND G1.SELF_GOODS_YN = 'Y' THEN (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G1.GOODS_CD AND COLOR_CD = ODI.OPT_CD1 AND DEFAULT_IMG_YN = 'Y')
		               ELSE (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G1.GOODS_CD AND COLOR_CD = IFNULL(G1.MAIN_COLOR_CD,'XX') AND DEFAULT_IMG_YN = 'Y') END AS SYS_IMG_NM
		             , OD.GIFT_PACK_YN
		             , OC.WD_GB
		             , OC.CHGER_NM
		             , OC.CHGER_PHNNO
		             , OC.CHGER_BASE_ADDR
		             , OC.CHGER_DTL_ADDR
		             , OC.CHGER_ZIPCODE
		             , OC.CHGER_RTN_MEMO
		             , OC.CHG_MEMO
		             , OC.WD_INVOICE_NO
		             , OC.SHIP_COMP_CD
		             , (SELECT SHIP_COMP_NM
		                  FROM TB_SHIP_COMPANY SC
		                 WHERE SC.SHIP_COMP_CD = OC.SHIP_COMP_CD)                       AS SHIP_COMP_NM
		             , DA.DELV_ADDR_SQ
		             , DA.RECIP_NM
		             , DA.RECIP_PHNNO
		             , DA.RECIP_BASE_ADDR
		             , DA.RECIP_DTL_ADDR
		             , DA.RECIP_ZIPCODE
		             , DA.DELV_MEMO
		             , P.PG_TID
		             , P.PAY_MEANS
		             , FN_GET_CODE_NM('G014', P.PAY_MEANS)                              AS PAY_MEANS_NM
		             , P.CARD_NM
		             , IF(P.CARD_MIPS = 0, '일시불', CONCAT(P.CARD_MIPS, '개월'))          AS CARD_MIPS
		             , OD2.ORD_DTL_STAT                                                 AS CHG_ORD_DTL_STAT
		             , O.ORD_NM
		             , O.ORD_EMAIL
		             , O.CUST_NO
		          FROM TB_ORDER_CHANGE OC
		         INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		            ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		          LEFT OUTER JOIN TB_ORDER_CHANGE_DETAIL_HST OCDH
		            ON OCD.ORD_CHG_SQ = OCDH.ORD_CHG_SQ
		           AND OCD.ORD_DTL_NO = OCDH.ORD_DTL_NO
		           AND OCD.CHG_STAT = OCDH.CHG_STAT
		         INNER JOIN TB_ORDER_DETAIL OD
		            ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		           AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_11', 'G013_25')
		         INNER JOIN TB_ORDER_DETAIL OD2
		            ON OCD.CHG_ORD_DTL_NO = OD2.ORD_DTL_NO
		           AND OD2.ORD_EXCH_GB = 'E'
		          LEFT OUTER JOIN TB_DELIVERY_ADDR DA
		            ON OD2.DELV_ADDR_SQ = DA.DELV_ADDR_SQ
		         INNER JOIN TB_ORDER O
		            ON OD.ORD_NO = O.ORD_NO
		         INNER JOIN TB_PAYMENT P2
		            ON O.ORD_NO = P2.ORD_NO
		           AND P2.PAY_STAT IN ('G016_10', 'G016_30')
		           AND P2.PAY_GB = 'O'
		           AND P2.PAY_GB <![CDATA[<>]]> 'NAVER_ORDER'
		         INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		            ON OD.ORD_NO = ODI.ORD_NO
		           AND OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		           AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_11', 'G013_25')
		         INNER JOIN TB_GOODS G1
		            ON OD.GOODS_CD = G1.GOODS_CD
		         INNER JOIN TB_GOODS G2
		            ON ODI.ITEM_CD = G2.GOODS_CD
		         INNER JOIN TB_BRAND B
		            ON G1.BRAND_CD = B.BRAND_CD
		           AND B.USE_YN = 'Y'
		         INNER JOIN TB_BRAND_GROUP BG
		            ON B.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		           AND BG.USE_YN = 'Y'
		          LEFT OUTER JOIN TB_PAYMENT P
		            ON P.ORD_CHG_SQ = OC.ORD_CHG_SQ
		           AND P.PAY_GB = 'D'
		           AND P.PAY_STAT = 'G016_30'
		<where>
			<choose>
				<when test="custNo > 0">
		           AND O.CUST_NO = #{custNo}
				</when>
				<otherwise>
		           AND O.ORD_NO = #{ordNo}
		           AND O.ORD_NM = #{ordNm}
		           AND O.ORD_PHNNO = #{ordPhnno}
				</otherwise>
			</choose>
			<if test="ordChgSq != null and ordChgSq != ''">
		           AND OC.ORD_CHG_SQ = #{ordChgSq}
			</if>
		</where>
		) Z
		 GROUP BY Z.ORD_CHG_SQ, Z.CHG_GB, Z.WD_BF_SEND_YN, Z.CHG_QTY, Z.ORD_DT, Z.ORD_DATE, Z.CHG_DATE, Z.CHG_TIME, Z.CHG_DT, Z.COMPLETE_DT, Z.CHG_STAT
		        , Z.CHG_STAT_NM, Z.ORD_DTL_STAT, Z.EXCHANGE_SHIP_COMP_CD, Z.EXCHANGE_INVOICE_NO, Z.ORD_NO, Z.DELV_FEE_CD, Z.ORD_AMT, Z.ORD_QTY, Z.CNCL_RTN_QTY, Z.CNCL_RTN_AMT
		        , Z.CPN1_DC_AMT, Z.REAL_ORD_AMT, Z.PNT_DC_AMT, Z.GFCD_USE_AMT, Z.ORD_DTL_NO, Z.CHG_ORD_DTL_NO, Z.GOODS_CD, Z.BRAND_NM, Z.SHOT_DELV_YN, Z.SELF_GOODS_YN, Z.GOODS_NM
		        , Z.GOODS_TYPE, Z.PRICE_ORG, Z.PRICE_SALE, Z.ADD_PAY_COST, Z.SYS_IMG_NM, Z.GIFT_PACK_YN, Z.WD_GB, Z.CHGER_NM, Z.CHGER_PHNNO, Z.CHGER_BASE_ADDR
		        , Z.CHGER_DTL_ADDR, Z.CHGER_ZIPCODE, Z.CHGER_RTN_MEMO, Z.CHG_MEMO, Z.WD_INVOICE_NO, Z.SHIP_COMP_CD, Z.SHIP_COMP_NM, Z.DELV_ADDR_SQ, Z.RECIP_NM, Z.RECIP_PHNNO
		        , Z.RECIP_BASE_ADDR, Z.RECIP_DTL_ADDR, Z.RECIP_ZIPCODE, Z.DELV_MEMO, Z.PG_TID, Z.PAY_MEANS, Z.PAY_MEANS_NM, Z.CARD_NM, Z.CARD_MIPS, Z.CHG_ORD_DTL_STAT
		        , Z.ORD_NM, Z.ORD_EMAIL, Z.CUST_NO
		 ORDER BY Z.ORD_CHG_SQ DESC, Z.DELV_FEE_CD DESC, Z.ORD_DTL_NO DESC
	</select>

	<!-- 마이페이지 교환 상품 옵션 정보 조회 -->
	<select id="getExchangeGoodsOptionInfoList" parameterType="OrderChange" resultType="OrderChange">
		/* TscOrderChange.getExchangeGoodsOptionInfoList */
		SELECT Z.ORD_CHG_SQ
		     , Z.CHG_GB
		     , Z.ORD_DTL_NO
		     , Z.ORG_ORD_DTL_NO
		     , Z.ORD_DTL_STAT
		     , Z.SHIP_COMP_CD
		     , Z.INVOICE_NO
		     , GROUP_CONCAT(Z.ITEM_NM ORDER BY Z.ORD_DTL_ITEM_SQ SEPARATOR '!@!')       AS ITEM_NM
		     , GROUP_CONCAT(Z.COLOR_NM ORDER BY Z.ORD_DTL_ITEM_SQ)                      AS COLOR_NM
		     , GROUP_CONCAT(Z.OPT_CD1 ORDER BY Z.ORD_DTL_ITEM_SQ)                       AS OPT_CD1
		     , GROUP_CONCAT(Z.OPT_CD2 ORDER BY Z.ORD_DTL_ITEM_SQ)                       AS OPT_CD2
		  FROM (SELECT OC.ORD_CHG_SQ
		             , OC.CHG_GB
		             , OD.ORD_DTL_NO
		             , OD.ORG_ORD_DTL_NO
		             , OD.ORD_DTL_STAT
		             , OD.SHIP_COMP_CD
		             , OD.INVOICE_NO
		             , IFNULL((SELECT COLOR_KNM FROM TB_COLOR WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,'') , G1.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		             , G2.GOODS_NM                      AS ITEM_NM
		             , ODI.OPT_CD1
		             , ODI.OPT_CD2
		             , ODI.ORD_DTL_ITEM_SQ
		          FROM TB_ORDER_CHANGE OC
		         INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		            ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		         INNER JOIN TB_ORDER_DETAIL OD
		            ON OCD.CHG_ORD_DTL_NO = OD.ORD_DTL_NO
		         INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		            ON OD.ORD_NO = ODI.ORD_NO
		           AND OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		         INNER JOIN TB_GOODS G1
		            ON OD.GOODS_CD = G1.GOODS_CD
		         INNER JOIN TB_GOODS G2
		            ON ODI.ITEM_CD = G2.GOODS_CD
		         WHERE OC.ORD_CHG_SQ = #{ordChgSq}
		           AND OCD.ORD_DTL_NO = #{ordDtlNo}
		  ) Z
		 GROUP BY Z.ORD_CHG_SQ, Z.CHG_GB, Z.ORD_DTL_NO, Z.ORG_ORD_DTL_NO, Z.ORD_DTL_STAT, Z.SHIP_COMP_CD, Z.INVOICE_NO
	</select>
	
	<!-- 전체취소 배송비 취소 처리 -->
	<insert id="createDeliveryFeeForAllCancel" parameterType="OrderChange">
		/* TscOrderChange.createDeliveryFeeForAllCancel */
		INSERT INTO TB_DELIVERY_FEE (
		       PAY_SQ
		     , ORD_NO
		     , DELV_FEE_GB
		     , DELV_FEE_CD
		     , DELV_FEE
		     , DELV_CPN_SQ
		     , DELV_CPN_DC_AMT
		     , DELV_GFCD_USE_AMT
		     , REAL_DELV_AMT
		     , ORD_CHG_SQ
		     , SUPPLY_COMP_CD
		     , DELV_USAC_YN
		     , DELV_USAC_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT 0
		     , ORD_NO
		     , DELV_FEE_GB
		     , DELV_FEE_CD
		     , DELV_FEE * -1
		     , DELV_CPN_SQ
		     , DELV_CPN_DC_AMT * -1
		     , DELV_GFCD_USE_AMT * -1
		     , REAL_DELV_AMT * -1
		     , #{ordChgSq}
		     , SUPPLY_COMP_CD
		     , 'N'
		     , NULL
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_DELIVERY_FEE
		 WHERE ORD_NO = #{ordNo}
		   AND DELV_FEE > 0
	</insert>

	<!-- 취소 사은품 조회 -->
	<select id="getCancelFreeGiftList" parameterType="OrderChange" resultType="OrderChange">
		/* TscOrderChange.getCancelFreeGiftList */
		SELECT FG.GOODS_NM
		     , OFV.USE_POINT
		  FROM TB_ORD_FREEGIFT OFG
		 INNER JOIN TB_ORD_FREEGIFT_VAL OFV
		    ON OFG.ORD_FREEGIFT_SQ = OFV.ORD_FREEGIFT_SQ
		 INNER JOIN TB_FREE_GOODS FG
		    ON OFV.PRODUCT_NO = FG.PRODUCT_NO
		   AND OFV.PRODUCT_CODE = FG.PRODUCT_CODE
		 WHERE OFG.ORD_NO = #{ordNo}
		   AND OFG.DEL_YN = #{delYn}
	</select>
	
	<!-- 교환출고 재고부족 취소처리 -->
	<update id="updateExchangeDelvFailCnclYn" parameterType="Order">
		/* TscOrderChange.updateExchangeDelvFailCnclYn */
		UPDATE TB_EXCHANGE_DELV_FAIL
		SET    DELV_CNCL_YN = 'Y'
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    ORD_CHG_SQ = #{ordChgSq}
		AND    DELV_CNCL_YN = 'N'
	</update>
	
	<!-- 교환 주문상세정보 수정 -->
	<update id="updateChgOrderDetailTemp" parameterType="Order">
		/* OrderChange.updateChgOrderDetailTemp */
		UPDATE TB_ORDER_DETAIL OD
		   SET OD.ORD_AMT          = #{cnclRtnAmt}
		     <if test='wdBfSendYn == "N"'>
		     , OD.ORD_DTL_STAT     = #{ordDtlStat}
		     </if>
		     , OD.ORD_QTY          = ABS(#{ordCanChgQty})
			 , OD.CNCL_RTN_QTY     = 0
			 , OD.CNCL_RTN_AMT     = 0
			 , OD.CPN1_DC_AMT      = #{cpn1DcAmt}
			 , OD.TMTB1_DC_AMT     = #{tmtb1DcAmt}
			 , OD.TMTB2_DC_AMT     = #{tmtb2DcAmt}
			 , OD.GOODS_CPN_DC_AMT = #{goodsCpnDcAmt}
			 , OD.CART_CPN_DC_AMT  = #{cartCpnDcAmt}
			 , OD.PNT_DC_AMT       = #{pntDcAmt}
			 , OD.PRE_PNT_DC_AMT   = #{prePntDcAmt}
			 , OD.SAVE_PNT_AMT     = #{savePntAmt}
			 , OD.REAL_ORD_AMT     = #{realOrdAmt}
			 , OD.GFCD_USE_AMT     = #{gfcdUseAmt}
			 , OD.UPD_NO           = #{updNo}
			 , OD.UPD_DT           = NOW()
		 WHERE OD.ORD_NO = #{ordNo}
		   AND OD.ORD_DTL_NO = #{ordDtlNo}
	</update>
	
	<!-- 교환 주문상세단품정보 수정 -->
	<update id="updateChgOrderDetailItemTemp" parameterType="Order">
		/* OrderChange.updateChgOrderDetailItemTemp */
		UPDATE TB_ORDER_DETAIL_ITEM
		   SET ORD_AMT          = #{ordAmt}
		     , CNCL_RTN_AMT     = 0
		     , CPN1_DC_AMT      = #{cpn1DcAmt}
		     , TMTB1_DC_AMT     = #{tmtb1DcAmt}
		     , TMTB2_DC_AMT     = #{tmtb2DcAmt}
		     , GOODS_CPN_DC_AMT = #{goodsCpnDcAmt}
		     , CART_CPN_DC_AMT  = #{cartCpnDcAmt}
		     , PRE_PNT_DC_AMT   = #{prePntDcAmt}
		     , PNT_DC_AMT       = #{pntDcAmt}
		     , REAL_ORD_AMT     = #{realOrdAmt}
		     , GFCD_USE_AMT     = #{gfcdUseAmt}
		     , SAVE_PNT_AMT     = #{savePntAmt}
		     , UPD_NO           = #{updNo}
		     , UPD_DT           = NOW()
		 WHERE ORD_NO = #{ordNo}
		   AND ORD_DTL_NO = #{ordDtlNo}
		   AND ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
	</update>
	
	<!-- 교환배송실패 변경요청단위 전체취소 여부 -->
	<select id="getExchangeDelvFailQty" parameterType="Payment" resultType="int">
		/* OrderChange.getExchangeDelvFailQty */
		SELECT SUM(A.QTY) AS QTY
		FROM (
			SELECT OD.ORD_QTY - OD.CNCL_RTN_QTY AS QTY
			FROM   TB_ORDER_DETAIL OD
			INNER  JOIN TB_ORDER_CHANGE_DETAIL OCD
			ON     OD.ORD_DTL_NO = OCD.CHG_ORD_DTL_NO 
			WHERE  1=1
			AND    OCD.ORD_CHG_SQ = #{ordChgSq}
		) A
	</select>
	
	<!-- 추가배송비 취소 처리 (부분취소)ㄴ -->
	<insert id="createAddDeliveryFeeCancelPart" parameterType="OrderChange">
		/* TscOrderChange.createAddDeliveryFeeCancelPart */
		INSERT INTO TB_DELIVERY_FEE (
		       PAY_SQ
		     , ORD_NO
		     , DELV_FEE_GB
		     , DELV_FEE_CD
		     , DELV_FEE
		     , DELV_CPN_SQ
		     , DELV_CPN_DC_AMT
		     , REAL_DELV_AMT
		     , ORD_CHG_SQ
		     , SUPPLY_COMP_CD
		     , DELV_USAC_YN
		     , DELV_USAC_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT NULL                            AS PAY_SQ
		     , DF.ORD_NO
		     , DF.DELV_FEE_GB
		     , DF.DELV_FEE_CD
		     , DF.DELV_FEE * -1                AS DELV_FEE
		     , NULL                            AS DELV_CPN_SQ
		     , 0                               AS DELV_CPN_DC_AMT
		     , DF.REAL_DELV_AMT * -1           AS REAL_DELV_AMT
		     , DF.ORD_CHG_SQ
		     , DF.SUPPLY_COMP_CD
		     , 'N'
		     , NULL
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_DELIVERY_FEE DF
		 INNER JOIN TB_PAYMENT P
		    ON P.ORD_CHG_SQ = DF.ORD_CHG_SQ
		   AND P.PAY_STAT = 'G016_30'
		   AND DF.DELV_FEE_GB = 'G018_30'
		   AND P.PAY_GB = 'D'
		 WHERE DF.ORD_CHG_SQ = #{ordChgSq}
	</insert>

	<!-- 마이페이지 회수지 수정 -->
	<update id="updateChgerAddr" parameterType="OrderChange">
		/* TscOrderChange.updateChgerAddr */
		UPDATE TB_ORDER_CHANGE
		   SET CHGER_NM = #{chgerNm}
			 , CHGER_PHNNO = #{chgerPhnno}
			 , CHGER_ZIPCODE = #{chgerZipcode}
			 , CHGER_BASE_ADDR = #{chgerBaseAddr}
			 , CHGER_DTL_ADDR = #{chgerDtlAddr}
			 , CHGER_RTN_MEMO = #{chgerRtnMemo}
			 , UPD_NO = #{updNo}
			 , UPD_DT = NOW()
		 WHERE ORD_CHG_SQ = #{ordChgSq}
	</update>

	<!-- 마이페이지 반품메모 수정 -->
	<update id="updateChgerRtnMemo" parameterType="OrderChange">
		/* TscOrderChange.updateChgerRtnMemo */
		UPDATE TB_ORDER_CHANGE
		   SET CHGER_RTN_MEMO = #{chgerRtnMemo}
			 , UPD_NO = #{updNo}
			 , UPD_DT = NOW()
		 WHERE ORD_CHG_SQ = #{ordChgSq}
	</update>

	<!-- 미착 정보 조회 -->
	<select id="getNonArrivalInfo" parameterType="Order" resultType="Order">
		/* TscWmsDelivery.getNonArrivalInfo */
		SELECT Z.ORD_NO
		     , Z.ORD_CHG_SQ
		     , Z.ORD_DTL_NO
		     , Z.ORD_QTY
		     , MIN(Z.CHG_QTY)       AS CHG_QTY
		  FROM (SELECT ORE.ORDER_NO                                    AS ORD_NO
		             , ORE.ORDER_EXCEPTION_NO                          AS ORD_CHG_SQ
		             , OREI.ORDER_DTL_NO                               AS ORD_DTL_NO
		             , TRUNCATE(OREI.EXCEPTION_QTY / ODI.ITEM_QTY, 0)  AS CHG_QTY
		             , OREI.QTY                                        AS ORD_QTY
		          FROM TB_ORDER_RECALL_EXCEPTION ORE
		         INNER JOIN TB_ORDER_RECALL_EXCEPTION_ITEM OREI
		            ON ORE.RECALL_EXCEPTION_NO = OREI.RECALL_EXCEPTION_NO
		         INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		            ON OREI.ORDER_DTL_NO = ODI.ORD_DTL_NO
		           AND OREI.PRODUCT_NO = ODI.PRODUCT_NO
		           AND OREI.PRODUCT_CODE = ODI.PRODUCT_CODE
		         WHERE ORE.ORDER_EXCEPTION_NO = #{ordChgSq}
		       ) Z
		 GROUP BY Z.ORD_NO, Z.ORD_CHG_SQ, Z.ORD_DTL_NO, Z.ORD_QTY
	</select>
	
	<!-- 주문변경신청 완료 정보 조회(취소,반품) -->
	<select id="getCnclRtnCompleteList" parameterType="Order" resultType="Order">
		/* TscOrderChange.getCnclRtnCompleteList */
		SELECT A.ORD_NO
		     , A.ORD_DTL_NO
		     , A.GOODS_CD
		     , A.GOODS_NM
		     , A.GOODS_TYPE_NM
		     , A.CHG_REASON 
		     , A.CHG_REASON_NM
		     , A.CHG_MEMO
		     , A.ADD_PAY_COST
		     , A.RA_BANK 
		     , A.RA_BANK_NM
		     , A.RA_NM 
		     , A.RA_NO
		     , A.REAL_DELV_AMT
		     , A.DELV_CPN_DC_AMT
		     , A.ORD_QTY
		     , A.CNCL_RTN_QTY
		     , A.ORD_AMT
		     , GROUP_CONCAT(A.OPT_CD ORDER BY A.ORD_DTL_ITEM_SQ) AS OPT_CD
		     , GROUP_CONCAT(A.OPT_CD1 ORDER BY A.ORD_DTL_ITEM_SQ) AS OPT_CD1
		     , GROUP_CONCAT(A.OPT_CD2 ORDER BY A.ORD_DTL_ITEM_SQ) AS OPT_CD2
		     , GROUP_CONCAT(A.COLOR_NM ORDER BY A.ORD_DTL_ITEM_SQ) AS COLOR_NM
		     , SUM(A.CNCL_RTN_AMT) AS CNCL_RTN_AMT
		     , SUM(A.CPN1_DC_AMT) AS CPN1_DC_AMT
		     , SUM(A.TMTB1_DC_AMT) AS TMTB1_DC_AMT
		     , SUM(A.TMTB2_DC_AMT) AS TMTB2_DC_AMT
		     , SUM(A.GOODS_CPN_DC_AMT) AS GOODS_CPN_DC_AMT
		     , SUM(A.CART_CPN_DC_AMT) AS CART_CPN_DC_AMT
		     , SUM(A.PNT_DC_AMT) AS PNT_DC_AMT
		     , SUM(A.PRE_PNT_DC_AMT) AS PRE_PNT_DC_AMT
		     , SUM(A.GFCD_USE_AMT) AS GFCD_USE_AMT
		     , SUM(A.REAL_ORD_AMT) AS REAL_ORD_AMT
		     , SUM(A.SAVE_PNT_AMT) AS SAVE_PNT_AMT
		     , A.REFUND_AMT
		     , A.DEPOSIT_AMT
		     , A.RF_CPN1_AMT
		     , A.RF_TMTB1_AMT
		     , A.RF_TMTB2_AMT
		     , A.RF_GOODS_CPN_AMT
		     , A.RF_CART_CPN_AMT
		     , A.RF_DELV_CPN_AMT
		     , A.RF_PNT_AMT
		     , A.RF_PRE_PNT_AMT
		     , A.RF_GFCD_USE_AMT
		     , A.RF_DELV_GFCD_USE_AMT
		     , A.RF_CNCL_AMT
		     , A.RF_DELIVERY_FEE
		     , A.RF_REAL_CNCL_AMT
		FROM (
		    SELECT ODIH.ORD_NO
		         , ODIH.ORD_DTL_NO
		         , G1.GOODS_CD
		         , G1.GOODS_NM
		         , CASE WHEN G1.GOODS_TYPE IN ('G056_N')
		                THEN '일반'
		                ELSE '셋트'
		                END GOODS_TYPE_NM
		         , OC.CHG_REASON 
		         , CASE WHEN OC.CHG_GB = 'G680_20' THEN FN_GET_CODE_NM('G686', OC.CHG_REASON)
  		                WHEN OC.CHG_GB = 'G680_30' THEN FN_GET_CODE_NM('G688', OC.CHG_REASON)
  		                ELSE FN_GET_CODE_NM('G689', OC.CHG_REASON)
  		                END  CHG_REASON_NM
		         , CASE WHEN OC.CHG_MEMO IS NULL
		                THEN ''
		                ELSE OC.CHG_MEMO
		                END  CHG_MEMO
		         , OC.ADD_PAY_COST
		         , RF.RA_BANK 
		         , FN_GET_CODE_NM('G940', RF.RA_BANK) AS RA_BANK_NM
		         , RF.RA_NM 
		         , RF.RA_NO
		         , IFNULL(DDF.REAL_DELV_AMT, 0) * -1 AS REAL_DELV_AMT
		         , RF.RF_DELV_CPN_AMT AS DELV_CPN_DC_AMT
		         , IFNULL((SELECT COLOR_KNM FROM TB_COLOR C WHERE COLOR_CD = IFNULL(NULLIF(ODIH.OPT_CD1,'') , G1.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODIH.OPT_CD1) AS COLOR_NM
		         , ODIH.ORD_DTL_ITEM_SQ
		         , ODIH.OPT_CD
		         , ODIH.OPT_CD1
		         , ODIH.OPT_CD2
		         , ODIH.ORD_QTY
		         , ODIH.CNCL_RTN_QTY
		         , ODIH.ORD_AMT
		         , ODIH.CNCL_RTN_AMT
		         , ODIH.CPN1_DC_AMT
		         , ODIH.TMTB1_DC_AMT 
		         , ODIH.TMTB2_DC_AMT 
		         , ODIH.GOODS_CPN_DC_AMT
		         , ODIH.CART_CPN_DC_AMT
		         , ODIH.PNT_DC_AMT
		         , ODIH.PRE_PNT_DC_AMT 
		         , ODIH.GFCD_USE_AMT 
		         , ODIH.REAL_ORD_AMT 
		         , ODIH.SAVE_PNT_AMT
		         , RF.REFUND_AMT
		         , RF.DEPOSIT_AMT
		         , RF.RF_CPN1_AMT
		         , RF.RF_TMTB1_AMT
		         , RF.RF_TMTB2_AMT
		         , RF.RF_GOODS_CPN_AMT
		         , RF.RF_CART_CPN_AMT
		         , RF.RF_DELV_CPN_AMT
		         , RF.RF_PNT_AMT
		         , RF.RF_PRE_PNT_AMT
		         , RF.RF_GFCD_USE_AMT
		         , RF.RF_DELV_GFCD_USE_AMT
		         , RF.RF_CNCL_AMT
		         , RF.RF_DELIVERY_FEE
		         , RF.RF_REAL_CNCL_AMT
		    FROM   TB_ORDER_DETAIL_ITEM_HST ODIH
		    INNER  JOIN TB_ORDER_DETAIL OD
		    ON     ODIH.ORD_DTL_NO = OD.ORD_DTL_NO
		    INNER  JOIN TB_GOODS G1
		    ON     OD.GOODS_CD = G1.GOODS_CD
		    INNER  JOIN TB_ORDER_CHANGE OC
		    ON     ODIH.ORD_CHG_SQ = OC.ORD_CHG_SQ
		    INNER  JOIN TB_REFUND RF
		    ON     ODIH.ORD_CHG_SQ = RF.ORD_CHG_SQ
		    LEFT   OUTER JOIN (
		        SELECT SUM(DF.REAL_DELV_AMT) AS REAL_DELV_AMT
		             , DF.ORD_CHG_SQ
		        FROM   TB_DELIVERY_FEE DF
		        WHERE  DF.ORD_CHG_SQ = #{ordChgSq}
		        GROUP  BY DF.ORD_CHG_SQ
		    ) DDF
		    ON     DDF.ORD_CHG_SQ = ODIH.ORD_CHG_SQ
		    WHERE  1=1
		    AND    ODIH.ORD_CHG_SQ = #{ordChgSq}
		<choose>
			<when test="chgStat == 'G720_30'">
		    AND    ODIH.ORD_DTL_STAT IN ('G720_30', 'G720_40')
			</when>
			<otherwise>
		    AND    ODIH.ORD_DTL_STAT = #{chgStat}
			</otherwise>
		</choose>
		) A
		WHERE  1=1
		GROUP  BY A.ORD_NO
		     , A.ORD_DTL_NO
		     , A.GOODS_CD
		     , A.GOODS_NM
		     , A.GOODS_TYPE_NM
		     , A.CHG_REASON 
		     , A.CHG_REASON_NM
		     , A.CHG_MEMO
		     , A.ADD_PAY_COST
		     , A.RA_BANK 
		     , A.RA_BANK_NM
		     , A.RA_NM 
		     , A.RA_NO 
		     , A.ORD_QTY
		     , A.CNCL_RTN_QTY
		     , A.ORD_AMT
		     , A.REAL_DELV_AMT
		     , A.DELV_CPN_DC_AMT
		     , A.REFUND_AMT
		     , A.DEPOSIT_AMT
		     , A.RF_CPN1_AMT
		     , A.RF_TMTB1_AMT
		     , A.RF_TMTB2_AMT
		     , A.RF_GOODS_CPN_AMT
		     , A.RF_CART_CPN_AMT
		     , A.RF_DELV_CPN_AMT
		     , A.RF_PNT_AMT
		     , A.RF_PRE_PNT_AMT
		     , A.RF_GFCD_USE_AMT
		     , A.RF_DELV_GFCD_USE_AMT
		     , A.RF_CNCL_AMT
		     , A.RF_DELIVERY_FEE
		     , A.RF_REAL_CNCL_AMT
		ORDER  BY A.ORD_NO
		     , A.ORD_DTL_NO
	</select>

	<!-- 확정 후 품절 및 불량 데이터 조회 -->
	<select id="getOrderRecallExceptionInfo" parameterType="OrderChange" resultType="OrderChange">
		/* TscOrderChange.getOrderRecallExceptionInfo : 확정 후 품절 및 불량 데이터 조회 */
		SELECT OD.ORD_NO
		     , OD.NPAY_ORD_DTL_NO
		     , P.PG_GB
		     , OREI.ORDER_DTL_NO
		     , MIN(CASE WHEN CHG_OD.ORD_DTL_NO IS NOT NULL THEN CHG_OD.ORD_DTL_NO
		                ELSE OD.ORD_DTL_NO END) AS ORD_DTL_NO
		     , MIN(CASE WHEN CHG_OD.ORD_EXCH_GB IS NOT NULL THEN CHG_OD.ORD_EXCH_GB
		                ELSE OD.ORD_EXCH_GB END) AS ORD_EXCH_GB
		     , OCD.ORD_CHG_SQ
		FROM   TB_ORDER_DETAIL OD
		INNER  JOIN TB_PAYMENT P
		ON     OD.ORD_NO = P.ORD_NO
		AND    P.PAY_STAT = 'G016_30'
		AND    P.PAY_GB = 'O'
		INNER  JOIN TB_ORDER_CHANGE_DETAIL OCD
		ON     OD.ORD_DTl_NO = OCD.ORD_DTL_NO
		LEFT   OUTER JOIN TB_ORDER_RECALL_EXCEPTION_ITEM OREI
		ON     OD.ORD_DTL_NO = OREI.ORDER_DTL_NO
		AND    OREI.REASON_CODE IN ('09','11')
		LEFT   OUTER JOIN TB_ORDER_DETAIL CHG_OD
		ON     OCD.CHG_ORD_DTL_NO = CHG_OD.ORD_DTL_NO
		WHERE  1=1
		AND    OCD.ORD_CHG_SQ = #{ordChgSq}
		GROUP  BY OD.ORD_NO
		        , OD.NPAY_ORD_DTL_NO
		        , P.PG_GB
		        , OREI.ORDER_DTL_NO
		        , OCD.ORD_CHG_SQ
	</select>
	
	<!-- 현재결제금액조회 -->
	<select id="getPaymentPayamt" parameterType="Payment" resultType="int">
		/* TscOrderChange.getPaymentPayamt : 현재결제금액조회 */
		SELECT SUM(PAY_AMT) AS PAY_AMT
		FROM   TB_PAYMENT
		WHERE  1=1
		AND    ORD_NO = #{ordNo}
		AND    PAY_GB = #{payGb}
		AND    PAY_STAT IN ('G016_30', 'G016_99')
	</select>
	
	<!-- 환불컨펌시 배송중상태 조회 -->
	<select id="getOrderDetailItem20Cnt" parameterType="Order" resultType="int">
		/* TscOrderChange.getOrderDetailItem20Cnt : 환불컨펌시 배송중상태 조회 */
		SELECT SUM(CNT) AS CNT
		FROM (
			SELECT CASE WHEN ODIH.ORD_DTL_STAT IS NULL AND ODI.REG_DT > '2021-09-01'
			            THEN 0
			            ELSE 1
			            END  CNT
			FROM   TB_ORDER_DETAIL_ITEM ODI
			LEFT   JOIN TB_ORDER_DETAIL_ITEM_HST ODIH
			ON     ODIH.ORD_DTL_ITEM_SQ = ODI.ORD_DTL_ITEM_SQ
			AND    ODIH.ORD_DTL_STAT = 'G720_20'
			WHERE  1=1
			AND    ODI.ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
		) A
	</select>
	
		<!-- 환불컨펌시 배송중상태 조회 전체취소 -->
	<select id="getOrderDetailItem20CntAll" parameterType="OrderChange" resultType="int">
		/* TscOrderChange.getOrderDetailItem20CntAll : 환불컨펌시 배송중상태 조회 전체취소 */
		SELECT SUM(CNT) AS CNT
		FROM (
			SELECT CASE WHEN ODIH.ORD_DTL_STAT IS NULL AND O.REG_DT > '2021-09-01'
			            THEN 0
			            ELSE 1
			            END  CNT
			FROM   TB_ORDER O
			LEFT   JOIN TB_ORDER_DETAIL_ITEM_HST ODIH
			ON     ODIH.ORD_NO = O.ORD_NO
			AND    ODIH.ORD_DTL_STAT = 'G720_20'
			WHERE  1=1
			AND    O.ORD_NO = #{ordNo}
		) A
	</select>

	<!-- 주문상세단품 정보 조회 -->
	<select id="getOrderDetailItemInfo" parameterType="Order" resultType="Order">
		/* TscOrderChange.getOrderDetailItemInfo */
		SELECT ORD_DTL_ITEM_SQ
		     , ORD_DTL_NO
		     , ORD_NO
		     , ORD_DTL_STAT
		     , ITEM_CD
		     , OPT_CD
		     , OPT_CD1
		     , OPT_CD2
		     , SKU_MODEL_NO
		     , PRODUCT_NO
		     , PRODUCT_CODE
		     , ITEM_QTY
		     , ITEM_PRICE
		     , OPT_ADD_PRICE
		     , DISP_ORD
		     , ORD_AMT
		     , CNCL_RTN_AMT
		     , CPN1_DC_AMT
		     , TMTB1_DC_AMT
		     , TMTB2_DC_AMT
		     , GOODS_CPN_DC_AMT
		     , CART_CPN_DC_AMT
		     , PNT_DC_AMT
		     , PRE_PNT_DC_AMT
		     , SAVE_PNT_AMT
		     , REAL_ORD_AMT
		     , GFCD_USE_AMT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		  FROM TB_ORDER_DETAIL_ITEM
		 WHERE ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
	</select>

	<!-- 주문상세 정보 조회 -->
	<select id="getOrderDetailInfo" parameterType="Order" resultType="Order">
		/* TscOrderChange.getOrderDetailInfo */
		SELECT OD.ORD_DTL_NO
		     , OD.ORD_NO
		     , OD.ORD_EXCH_GB
		     , OD.ORD_DTL_STAT
		     , OD.ORG_ORD_DTL_NO
		     , OD.SUPPLY_COMP_CD
		     , OD.GOODS_CD
		     , OD.DEAL_GOODS_CD
		     , OD.FORMAL_GB
		     , OD.GOODS_TYPE
		     , OD.LIST_PRICE
		     , OD.CURR_PRICE
		     , OD.DC_RATE
		     , OD.OPT_ADD_PRICE
		     , OD.ORD_QTY
		     , OD.ORD_AMT
		     , OD.CNCL_RTN_QTY
		     , OD.CNCL_RTN_AMT
		     , OD.CPN1_CPN_SQ
		     , OD.CPN1_DC_AMT
		     , OD.TMTB1_SQ
		     , OD.TMTB1_DC_AMT
		     , OD.TMTB2_SQ
		     , OD.TMTB2_DC_AMT
		     , OD.GOODS_CPN_SQ
		     , OD.GOODS_CPN_DC_AMT
		     , OD.CART_CPN_SQ
		     , OD.CART_CPN_DC_AMT
		     , OD.BURDEN_RATE
		     , OD.PNT_DC_AMT
		     , OD.PRE_PNT_DC_AMT
		     , OD.SAVE_PNT_AMT
		     , OD.REAL_ORD_AMT
		     , OD.GFCD_USE_AMT
		     , OD.VENDOR_ID
		     , OD.EXTMALL_ID
		     , OD.AGENT_ORDER_ID
		     , OD.EXTMALL_ORDER_ID
		     , OD.CHANGEABLE_YN
		     , OD.CHANGE_FEE_FREE_YN
		     , OD.RETURNABLE_YN
		     , OD.RETURN_FEE_FREE_YN
		     , OD.SOLDOUT_YN
		     , OD.SOLDOUT_MEMO
		     , OD.SOLDOUT_REG_NO
		     , OD.SOLDOUT_REG_DT
		     , OD.DELV_ADDR_SQ
		     , OD.DELV_FEE_CD
		     , OD.SHOT_DELV_YN
		     , OD.GIFT_PACK_YN
		     , OD.GIFT_ADDR_INP_YN
		     , OD.MAKE_GOODS_YN
		     , OD.ENTRY_NO
		     , OD.DELV_LOC_CD
		     , OD.DELV_ASSIGN_DT
		     , OD.DELV_ASSIGN_STAT
		     , OD.DSTRBT_NOTE
		     , OD.DELV_STDT
		     , OD.DELV_EDDT
		     , OD.SHIP_COMP_CD
		     , OD.INVOICE_NO
		     , OD.INVOICE_SEND_YN
		     , OD.SELL_STORE_CD
		     , OD.SELL_FEE_RATE
		     , OD.AF_LINK_CD
		     , OD.ITHR_CD
		     , OD.CONTENTS_LOC
		     , OD.PLAN_DTL_SQ
		     , OD.SOCIAL_SQ
		     , OD.NPAY_ORD_DTL_NO
		     , OD.REG_NO
		     , OD.REG_DT
		     , OD.UPD_NO
		     , OD.UPD_DT
		     , ODI.CURR_PRICE AS ORG_CURR_PRICE
		     , ODI.ITEM_CNT
		  FROM TB_ORDER_DETAIL OD
		  INNER JOIN (SELECT ORD_DTL_NO
		                   , COUNT(*)                                     AS ITEM_CNT
		                   , SUM((ITEM_PRICE + OPT_ADD_PRICE) * ITEM_QTY) AS CURR_PRICE
		                FROM TB_ORDER_DETAIL_ITEM
		               WHERE ORD_DTL_NO = #{ordDtlNo}
		               GROUP BY ORD_DTL_NO) ODI
		  ON OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		 WHERE OD.ORD_DTL_NO = #{ordDtlNo}
	</select>

	<!-- 회수 예외 정보 조회 -->
	<select id="getRecallExceptionInfo" parameterType="Order" resultType="Order">
		/* TscOrderChange.getRecallExceptionInfo */
		SELECT RECALL_EXCEPTION_NO
		     , DELIVERY_ORDER_NO
		     , ORDER_NO
		     , CUSTOMER_NAME
		     , STATUS_CD
		     , LOGISTICS_NAME
		     , INVOICE_NO
		     , RECALL_STAT
		     , RECALL_STAT_DT
		     , WMS_SEND_YN
		     , WMS_SEND_DT
		     , CHARGE_TYPE
		     , CHARGE_AMOUNT
		     , USER_ID_CREATED
		     , USER_NAME_CREATED
		     , DATE_CREATED
		     , USER_ID_MODIFIED
		     , USER_NAME_MODIFIED
		     , DATE_LAST_MODIFIED
		     , CS_ADD_FEE
		     , CS_MEMO
		     , COD_FEE
		     , PAY_GB
		     , ORDER_EXCEPTION_NO
		     , REG_NO
		     , REG_DT
		  FROM TB_ORDER_RECALL_EXCEPTION
		 WHERE ORDER_EXCEPTION_NO = #{ordChgSq}
		 LIMIT 1
	</select>
	
	<!-- 반송지 주소 조회 -->
	<select id="getRtnLocInfo" parameterType="Order" resultType="Order">
		/* TscOrderChange.getRtnLocInfo */
		SELECT DFP.DELV_FEE_CD
		     , DL.DELV_LOC_CD
		     , DL.SUPPLY_COMP_CD
		     , FN_GET_SUPPLY_COMP_NM(DL.SUPPLY_COMP_CD) AS SUPPLY_COMP_NM
		     , DL.RTN_LOC_NM
		     , DL.RTN_LOC_TELNO
		     , DL.RTN_LOC_ZIPCODE
		     , DL.RTN_LOC_BASE_ADDR
		     , DL.RTN_LOC_DTL_ADDR
		  FROM TB_DELV_FEE_POLICY DFP
		 INNER JOIN TB_DELIVERY_LOC DL
		    ON DL.SUPPLY_COMP_CD = DFP.SUPPLY_COMP_CD
		   AND DL.USE_YN = 'Y'
		 WHERE DFP.DELV_FEE_CD = #{delvFeeCd}
		 LIMIT 1
	</select>
	
	<!-- 교환상품 출고예외등록 -->
	<insert id="insertTbExchangeDelvFail" parameterType="OrderChange">
		/* TscOrderChange.insertTbExchangeDelvFail */
		INSERT INTO TB_EXCHANGE_DELV_FAIL (
			ORD_NO	 			--	주문번호
			, ORD_DTL_NO	 		--	주문상세번호
			, ORD_CHG_SQ	 		--	변경요청번호
			, ORD_QTY	 			--	주문수량(출고가능수량)
			, CNCL_RTN_QTY	 		--	취소수량(미출고수량)
			, DELV_FAIL_REASON		--	출고실패사유
			, DEL_YN
			, REG_NO	 			--	등록자 NO
			, REG_DT	 			--	등록일
			, UPD_NO	 			--	수정자 NO
			, UPD_DT	 			--	수정일
		) VALUES (
			#{ordNo} 	 			--	주문번호
			, #{ordDtlNo}	 		--	주문상세번호
			, #{ordChgSq}			--  변경요청번호
			, #{ordQty}	 			--	주문수량(출고가능수량)
			, #{chgQty}	 		    --	취소수량(미출고수량)
			, '재고부족'				--	출고실패사유
			, 'N' 
			, #{regNo}	 			--	등록자 NO
			, NOW()	 				--	등록일
			, #{regNo}	 			--	수정자 NO
			, NOW()	 				--	수정일
		)		
	</insert>
	
	<!-- 반품배송비 수정 -->
	<update id="updateReturnDeliveryFee" parameterType="OrderChange">
		/* TscOrderChange.updateReturnDeliveryFee */
		UPDATE TB_DELIVERY_FEE
		   SET DELV_FEE = #{delvGfcdUseAmt} + #{realDelvAmt}
		     , DELV_GFCD_USE_AMT = #{delvGfcdUseAmt}
		     , REAL_DELV_AMT = #{realDelvAmt}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		 WHERE ORD_CHG_SQ = #{ordChgSq}
		   AND PAY_SQ IS NULL
	</update>

	<!-- 반품배송비 정보 조회 -->
	<select id="getReturnDeliveryFeeInfo" parameterType="OrderChange" resultType="OrderChange">
		/* TscOrderChange.getReturnDeliveryFeeInfo */
		SELECT DELV_FEE_SQ
		     , PAY_SQ
		     , ORD_NO
		     , DELV_FEE_GB
		     , DELV_FEE_CD
		     , DELV_FEE
		     , DELV_CPN_SQ
		     , DELV_CPN_DC_AMT
		     , DELV_GFCD_USE_AMT
		     , REAL_DELV_AMT
		     , ORD_CHG_SQ
		     , SUPPLY_COMP_CD
		     , DELV_USAC_YN
		     , DELV_USAC_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		  FROM TB_DELIVERY_FEE
		 WHERE ORD_CHG_SQ = #{ordChgSq}
		   AND PAY_SQ IS NULL
	</select>

	<!-- 원주문 배송비 정보 조회 -->
	<select id="getOrgDeliveryFeeInfo" parameterType="OrderChange" resultType="OrderChange">
		/* TscOrderChange.getOrgDeliveryFeeInfo */
		SELECT DELV_FEE_SQ
		     , PAY_SQ
		     , ORD_NO
		     , DELV_FEE_GB
		     , DELV_FEE_CD
		     , DELV_FEE
		     , DELV_CPN_SQ
		     , DELV_CPN_DC_AMT
		     , DELV_GFCD_USE_AMT
		     , REAL_DELV_AMT
		     , ORD_CHG_SQ
		     , SUPPLY_COMP_CD
		     , DELV_USAC_YN
		     , DELV_USAC_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		  FROM TB_DELIVERY_FEE
		 WHERE ORD_CHG_SQ = #{ordChgSq}
		   AND DELV_FEE_GB = #{delvFeeGb}
		   AND DELV_FEE > 0
	</select>
	
	<!-- 네이버페이 주문형 교환접수 승인 옵션 수정 -->
	<update id="updateExchangeApprovalOption" parameterType="OrderChange">
		/* TscOrderChange.updateExchangeApprovalOption */
		UPDATE TB_ORDER_DETAIL_ITEM ODI
		 INNER JOIN TB_OPTION OP
		    ON ODI.ITEM_CD = OP.GOODS_CD
		   SET ODI.OPT_CD = OP.OPT_CD
		     , ODI.OPT_CD1 = OP.OPT_CD1
		     , ODI.OPT_CD2 = OP.OPT_CD2
		     , ODI.SKU_MODEL_NO = OP.SKU_MODEL_NO
		     , ODI.PRODUCT_CODE = OP.PRODUCT_CODE
		     , ODI.PRODUCT_NO = OP.PRODUCT_NO
		 WHERE ODI.ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
		   AND OP.OPT_CD = #{chgOptCd}
	</update>

	<!-- 네이버페이 주문형 교환접수 승인대기 목록 수 조회 -->
	<select id="getExchangeApprovalTargetListCount" parameterType="OrderChange" resultType="int">
		/* TscOrderChange.getExchangeApprovalTargetListCount */
		SELECT COUNT(*) AS CNT
		  FROM TB_ORDER_CHANGE OC
		 INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		    ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		 INNER JOIN TB_ORDER O
		    ON OD.ORD_NO = O.ORD_NO
		 INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		    ON OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		 WHERE OCD.CHG_STAT = 'G685_22'
		<if test="stDate != null and stDate != '' and edDate != null and edDate != ''">
		   AND OC.REG_DT BETWEEN CONCAT(#{stDate}, ' 00:00:00') AND CONCAT(#{edDate}, ' 23:59:59')
		</if>
		<if test="ordNm != null and ordNm != ''">
		   AND O.ORD_NM = #{ordNm}
		</if>
		<if test="ordNo != null and ordNo != ''">
		   AND O.ORD_NO = #{ordNo}
		</if>
		<if test="ordChgSq != null and ordChgSq != ''">
		   AND OC.ORD_CHG_SQ = #{ordChgSq}
		</if>
	</select>

	<!-- 네이버페이 주문형 교환접수 승인대기 목록 조회 -->
	<select id="getExchangeApprovalTargetList" parameterType="OrderChange" resultType="OrderChange">
		/* TscOrderChange.getExchangeApprovalTargetListCount */
		<include refid="selectForPagingHeader"/>
		SELECT OD.ORD_NO
		     , OD.ORD_DTL_NO
		     , OCD.ORD_CHG_SQ
		     , O.ORD_DT
		     , ODI.ITEM_CD                                                           AS GOODS_CD
		     , OD.DELV_FEE_CD
		     , (SELECT CASE WHEN BG.DISP_NM_LANG = 'EN' THEN BG.BRAND_GROUP_ENM
		                    ELSE BG.BRAND_GROUP_KNM
		                END                                                          AS BRAND_GROUP_NM
		          FROM TB_BRAND B
		          INNER JOIN TB_BRAND_GROUP BG
		          ON B.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		         WHERE B.BRAND_CD = G2.BRAND_CD
		           AND BG.USE_YN = 'Y')                                              AS BRAND_GROUP_NM
		     , O.ORD_NM
		     , O.ORD_PHNNO
		     , OD.GOODS_TYPE
		     , FN_GET_CODE_NM('G056', G1.GOODS_TYPE)                                 AS GOODS_TYPE_NM
		     , G2.GOODS_NM
		     , CASE WHEN G1.GOODS_TYPE != 'G056_S' AND G1.SELF_GOODS_YN = 'Y' THEN (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G2.GOODS_CD AND COLOR_CD = ODI.OPT_CD1 AND DEFAULT_IMG_YN = 'Y')
		            ELSE (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G2.GOODS_CD AND COLOR_CD = IFNULL(G2.MAIN_COLOR_CD,'XX') AND DEFAULT_IMG_YN = 'Y')
		       END                                                                   AS SYS_IMG_NM
		     , RANK() OVER(PARTITION BY OCD.ORD_CHG_SQ ORDER BY OCD.ORD_DTL_NO)      AS ROWSPAN_RANK
		     , RANK() OVER(PARTITION BY OCD.ORD_CHG_SQ ORDER BY OCD.ORD_DTL_NO DESC) AS ROWSPAN_CNT
		     , ROW_NUMBER() OVER(ORDER BY OCD.ORD_CHG_SQ DESC)                       AS NUMB
		  FROM TB_ORDER_CHANGE OC
		 INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		    ON OC.ORD_CHG_SQ = OCD.ORD_CHG_SQ
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		 INNER JOIN TB_GOODS G1
		    ON OD.GOODS_CD = G1.GOODS_CD
		 INNER JOIN TB_ORDER O
		    ON OD.ORD_NO = O.ORD_NO
		 INNER JOIN TB_ORDER_DETAIL_ITEM ODI
		    ON OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		 INNER JOIN TB_GOODS G2
		    ON ODI.ITEM_CD = G2.GOODS_CD
		 WHERE OCD.CHG_STAT = 'G685_22'
		<if test="stDate != null and stDate != '' and edDate != null and edDate != ''">
		   AND OC.REG_DT BETWEEN CONCAT(#{stDate}, ' 00:00:00') AND CONCAT(#{edDate}, ' 23:59:59')
		</if>
		<if test="ordNm != null and ordNm != ''">
		   AND O.ORD_NM = #{ordNm}
		</if>
		<if test="ordNo != null and ordNo != ''">
		   AND O.ORD_NO = #{ordNo}
		</if>
		<if test="ordChgSq != null and ordChgSq != ''">
		   AND OC.ORD_CHG_SQ = #{ordChgSq}
		</if>
		 ORDER BY OC.ORD_CHG_SQ DESC, OCD.ORD_DTL_NO
		<include refid="selectForPagingFooter"/>
	</select>

	<!-- 마이페이지 반품 주문 정보 조회 -->
	<select id="getReturnOrderInfo" parameterType="Order" resultType="Order">
		/* TsfOrderChange.getReturnOrderInfo */
		SELECT OD.ORD_DTL_NO
			 , OD.ORD_QTY
			 , DF.DELV_FEE
			 , DF.DELV_CPN_DC_AMT
			 , DF.DELV_GFCD_USE_AMT
			 , DF.REAL_DELV_AMT
			 , DFP.DELV_FEE                        AS ORG_DELV_FEE
		  FROM TB_ORDER O
		  INNER JOIN TB_ORDER_DETAIL OD
		  ON O.ORD_NO = OD.ORD_NO
		  INNER JOIN (SELECT ORD_NO
						   , SUM(DELV_FEE)          AS DELV_FEE
						   , SUM(DELV_CPN_DC_AMT)   AS DELV_CPN_DC_AMT
						   , SUM(DELV_GFCD_USE_AMT) AS DELV_GFCD_USE_AMT
						   , SUM(REAL_DELV_AMT)     AS REAL_DELV_AMT
						FROM TB_DELIVERY_FEE
					   WHERE ORD_NO = #{ordNo}
					     AND DELV_FEE_CD = #{delvFeeCd}
						 AND DELV_FEE_GB = 'G018_10'
					   GROUP BY ORD_NO
		  ) DF
		  ON O.ORD_NO = DF.ORD_NO
		  INNER JOIN TB_DELV_FEE_POLICY DFP
		  ON OD.DELV_FEE_CD = DFP.DELV_FEE_CD
		 AND OD.SUPPLY_COMP_CD = DFP.SUPPLY_COMP_CD
		 WHERE O.ORD_NO = #{ordNo}
		   AND OD.DELV_FEE_CD = #{delvFeeCd}
	</select>
	
	<!-- 2021.11.15 회수컨펌 변경요청사유 변경 -->
	<update id="updateOrderChangeChgReason" parameterType="OrderChange">
		/* TscOrderChange.updateOrderChangeChgReason */
		UPDATE TB_ORDER_CHANGE
		   SET CHG_REASON     = #{chgReason}
		     , UPD_NO         = #{updNo}
		     , UPD_DT         = NOW()
		 WHERE 1 = 1
		   AND ORD_CHG_SQ = #{ordChgSq}
	</update>

	<!-- 최초 주문상세 번호 조회 -->
	<select id="getFirstOrdDtlNo" parameterType="Order" resultType="int">
		/* TscOrderChange.getFirstOrdDtlNo */
		SELECT CASE WHEN FIRST_ORD_DTL_NO > 0 THEN FIRST_ORD_DTL_NO
		            ELSE ORD_DTL_NO
		        END AS FIRST_ORD_DTL_NO
		  FROM TB_ORDER_DETAIL
		 WHERE ORD_DTL_NO = #{ordDtlNo}
	</select>
	
	<!-- 최초주문상세번호 기준 상품쿠폰 할인액 조회 -->
	<select id="getGoodsCpnDcAmt" parameterType="Order" resultType="int">
		/* TscOrderChange.getGoodsCpnDcAmt */
		SELECT SUM(GOODS_CPN_DC_AMT) AS GOODS_CPN_DC_AMT
		  FROM TB_ORDER_DETAIL
		 WHERE FIRST_ORD_DTL_NO = #{firstOrdDtlNo}
	</select>
</mapper>


