<?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.TscOrderDao">

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

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

	<!-- 주문목록 > 주문목록카운트 -->
	<select id="getOrderListCount" parameterType="Order" resultType="int">
		/* order.getOrderListCnt */
		WITH CTE_ORDNO AS (
		    SELECT O.ORD_NO
		         , OD.GOODS_CD
		         , OD.ORD_DTL_NO
		         , OD.DELV_ADDR_SQ
		         , O.CUST_NO
		      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_DTL_NO = ODI.ORD_DTL_NO
		     INNER JOIN TB_GOODS G2
		        ON ODI.ITEM_CD = G2.GOODS_CD
		     INNER JOIN TB_DELIVERY_ADDR DA
		        ON OD.DELV_ADDR_SQ = DA.DELV_ADDR_SQ
		     INNER JOIN TB_CUSTOMER C
		        ON O.CUST_NO = C.CUST_NO
		     WHERE 1=1
		       AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_25', 'G013_97')
		<if test='siteCd != null and siteCd != ""'>
		       AND O.SITE_CD = #{siteCd}
		</if>
		<if test='mallCd != null and mallCd != ""'>
		       AND O.MALL_GB = #{mallCd}
		</if>
		<if test='supplyCompCd != null and supplyCompCd != ""'>
		       AND OD.SUPPLY_COMP_CD = #{supplyCompCd}
		</if>
		<if test="multiSupplyCompCd != null and multiSupplyCompCd != ''">
		       AND OD.SUPPLY_COMP_CD IN
			<foreach collection="multiSupplyCompCd" item="item" index="index"  open="(" close=")" separator=",">
		           #{item}
			</foreach>
		</if>
		<if test="multiBrand != null and multiBrand != ''">
		       AND G1.BRAND_CD IN
			<foreach collection="multiBrand" item="item" index="index"  open="(" close=")" separator=",">
		           #{item}
			</foreach>
		</if>
		<if test="multiOrdDtlStat != null and multiOrdDtlStat != ''">
		       AND OD.ORD_DTL_STAT IN
			<foreach collection="multiOrdDtlStat" item="item" index="index"  open="(" close=")" separator=",">
		           #{item}
			</foreach>
		</if>
		<if test="conditions != null and conditions.length > 0">
			<choose>
				<when test='search == "searchOrdNo"'>
		       AND O.ORD_NO IN
					<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
		           #{item}
					</foreach>
				</when>
				<when test='search == "searchExtmallOrderId"'>
		       AND OD.EXTMALL_ORDER_ID IN
					<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
		           #{item}
					</foreach>
				</when>
				<when test='search == "searchAgentOrderId"'>
		       AND OD.AGENT_ORDER_ID IN
					<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
		           #{item}
					</foreach>
				</when>
				<when test='search == "searchCustId"'>
		       AND C.CUST_ID IN
					<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
		           #{item}
					</foreach>
				</when>
			</choose>
		</if>
		<if test='orderNm != null and orderNm != ""'>
		       AND O.ORD_NM = #{orderNm}
		</if>
		<if test='custNo != null and custNo != ""'>
		       AND O.CUST_NO = #{custNo}
		</if>
		<if test='orderPhnno != null and orderPhnno != ""'>
		       AND O.ORD_PHNNO = #{orderPhnno}
		</if>
		<if test='ordEmail != null and ordEmail != ""'>
		       AND O.ORD_EMAIL = #{ordEmail}
		</if>
		<if test='recipNm != null and recipNm != ""'>
		       AND DA.RECIP_NM = #{recipNm}
		</if>
		<if test='goodsCd != null and goodsCd != ""'>
		       AND G1.GOODS_CD = #{goodsCd}
		</if>
		<if test='goodsNm != null and goodsNm != ""'>
		       AND G1.GOODS_NM = #{goodsNm}
		</if>
		<if test='sizeCd != null and sizeCd != ""'>
		       AND ODI.OPT_CD2 = #{sizeCd}
		</if>
		<if test='invoiceNo != null and invoiceNo != ""'>
		       AND OD.INVOICE_NO = #{invoiceNo}
		</if>
		<if test='wdInvoiceSendYn != null and wdInvoiceSendYn == "Y"'>
		       AND OD.INVOICE_SEND_YN = 'Y'
		</if>
		<if test='wdInvoiceSendYn != null and wdInvoiceSendYn == "N"'>
		       AND OD.INVOICE_SEND_YN = 'N'
		</if>
		<if test='stDate != null and stDate != ""'>
			<if test='searchDateGb != null and searchDateGb == "ordDt"'>
		       AND O.ORD_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		       AND O.ORD_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
			</if>
			<if test='searchDateGb != null and searchDateGb == "delvStdt"'>
		       AND OD.DELV_STDT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		       AND OD.DELV_STDT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
			</if>
			<if test='searchDateGb != null and searchDateGb == "soldoutDt"'>
		       AND OD.SOLDOUT_REG_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		       AND OD.SOLDOUT_REG_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
			</if>
		</if>
		<if test="ordNoList != null and ordNoList != ''">
		       AND OD.ORD_NO IN
			<foreach collection="ordNoList" item="item" index="index"  open="(" close=")" separator=",">
		           #{item}
			</foreach>
		</if>
		<if test="optCd != null and optCd != ''">
		       AND ODI.OPT_CD LIKE CONCAT('%',#{optCd},'%')
		</if>
		<if test="extmallId != null and extmallId != ''">
		       AND OD.VENDOR_ID = #{vendorId}
		       AND OD.EXTMALL_ID = #{extmallId}
		</if>
		<if test="extmallOrderId != null and extmallOrderId != ''">
		       AND OD.EXTMALL_ORDER_ID LIKE CONCAT('%',#{extmallOrderId},'%')
		</if>
		     ORDER BY OD.ORD_NO DESC
		         , OD.ORD_DTL_NO DESC
		),
		CTE_PAYMENT AS (
		    SELECT A.*
		         , P.PAY_SQ
		         , P.PG_GB
		      FROM CTE_ORDNO A
		      LEFT OUTER JOIN TB_PAYMENT P
		        ON A.ORD_NO = P.ORD_NO
		       AND P.PAY_GB = 'O'
		       AND P.PAY_STAT IN ('G016_30')
		     WHERE 1=1
		<if test='pgGb != null and pgGb != ""'>
		       AND P.PG_GB = #{pgGb}
		</if>
		<if test='payMeans != null and payMeans != ""'>
		       AND P.PAY_MEANS = #{payMeans}
		</if>
		),
		CTE_OCD AS (
		    SELECT OCD.ORD_DTL_NO
		         , OC.CHG_GB
		         , OC.CHG_REASON
		         , OCD.CHG_STAT
		      FROM TB_ORDER_CHANGE OC
		     INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		        ON OC.ORD_CHG_SQ  = OCD.ORD_CHG_SQ
		     INNER JOIN CTE_PAYMENT PP
		        ON OCD.ORD_DTL_NO = PP.ORD_DTL_NO
		     WHERE 1=1
		     GROUP BY OCD.ORD_DTL_NO
		         , OC.CHG_GB
		         , OC.CHG_REASON
		         , OCD.CHG_STAT
		),
		CTE AS (
		    SELECT OD.ORD_NO
		         , OD.ORD_DTL_NO
		      FROM CTE_PAYMENT OD
		      LEFT OUTER JOIN CTE_OCD OCD
		        ON OD.ORD_DTL_NO = OCD.ORD_DTL_NO
		     WHERE 1=1
		<if test="chgStat != null and chgStat != ''">
			<if test="chgStat == '9999'">
		       AND OCD.CHG_REASON = 'G686_30'
			</if>
			<if test="chgStat != '9999'">
		       AND OCD.CHG_STAT = #{chgStat}
			</if>
		</if>
		<if test="chgGb != null and chgGb != ''">
		       AND OCD.CHG_GB = #{chgGb}
		</if>
		     ORDER BY OD.ORD_NO DESC
		         , OD.ORD_DTL_NO DESC
		)
		SELECT COUNT(1)
		FROM (
		    SELECT OD.ORD_NO
		         , OD.ORD_DTL_NO
		      FROM CTE TT
		     INNER JOIN TB_ORDER O
		        ON TT.ORD_NO = O.ORD_NO
		     INNER JOIN TB_ORDER_DETAIL OD
		        ON TT.ORD_NO = OD.ORD_NO
		       AND TT.ORD_DTL_NO = OD.ORD_DTL_NO
		     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
		     INNER JOIN TB_DELIVERY_ADDR DA
		        ON OD.DELV_ADDR_SQ = DA.DELV_ADDR_SQ
		     GROUP BY OD.ORD_NO
		         , OD.ORD_DTL_NO
		) A
	</select>

	<!-- 주문목록 > 주문목록 -->
	<select id="getOrderList" parameterType="Order" resultType="Order">
		/* order.getOrderList */
		WITH CTE_ORDNO AS (
		    SELECT OD.ORD_NO
		         , OD.GOODS_CD
		         , OD.ORD_DTL_NO
		         , OD.DELV_ADDR_SQ, O.CUST_NO
		      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_DTL_NO = ODI.ORD_DTL_NO
		     INNER JOIN TB_GOODS G2
		        ON ODI.ITEM_CD = G2.GOODS_CD
		     INNER JOIN TB_DELIVERY_ADDR DA
		        ON OD.DELV_ADDR_SQ = DA.DELV_ADDR_SQ
		     INNER JOIN TB_CUSTOMER C
		        ON O.CUST_NO = C.CUST_NO
		     WHERE 1=1
		       AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_25', 'G013_97')
		<if test='siteCd != null and siteCd != ""'>
		       AND O.SITE_CD = #{siteCd}
		</if>
		<if test='mallCd != null and mallCd != ""'>
		       AND O.MALL_GB = #{mallCd}
		</if>
		<if test='supplyCompCd != null and supplyCompCd != ""'>
		       AND OD.SUPPLY_COMP_CD = #{supplyCompCd}
		</if>
		<if test="multiSupplyCompCd != null and multiSupplyCompCd != ''">
		       AND OD.SUPPLY_COMP_CD IN
			<foreach collection="multiSupplyCompCd" item="item" index="index"  open="(" close=")" separator=",">
		           #{item}
			</foreach>
		</if>
		<if test="multiBrand != null and multiBrand != ''">
		       AND G1.BRAND_CD IN
			<foreach collection="multiBrand" item="item" index="index"  open="(" close=")" separator=",">
		           #{item}
			</foreach>
		</if>
		<if test="multiOrdDtlStat != null and multiOrdDtlStat != ''">
		       AND OD.ORD_DTL_STAT IN
			<foreach collection="multiOrdDtlStat" item="item" index="index"  open="(" close=")" separator=",">
		           #{item}
			</foreach>
		</if>
		<if test="conditions != null and conditions.length > 0">
			<choose>
				<when test='search == "searchOrdNo"'>
		       AND O.ORD_NO IN
					<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
		           #{item}
					</foreach>
				</when>
				<when test='search == "searchExtmallOrderId"'>
		       AND OD.EXTMALL_ORDER_ID IN
					<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
		           #{item}
					</foreach>
				</when>
				<when test='search == "searchAgentOrderId"'>
		       AND OD.AGENT_ORDER_ID IN
					<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
		           #{item}
					</foreach>
				</when>
				<when test='search == "searchCustId"'>
		       AND C.CUST_ID IN
					<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
		           #{item}
					</foreach>
				</when>
			</choose>
		</if>
		<if test='orderNm != null and orderNm != ""'>
		       AND O.ORD_NM = #{orderNm}
		</if>
		<if test='custNo != null and custNo != ""'>
		       AND O.CUST_NO = #{custNo}
		</if>
		<if test='orderPhnno != null and orderPhnno != ""'>
		       AND O.ORD_PHNNO = #{orderPhnno}
		</if>
		<if test='ordEmail != null and ordEmail != ""'>
		       AND O.ORD_EMAIL = #{ordEmail}
		</if>
		<if test='recipNm != null and recipNm != ""'>
		       AND DA.RECIP_NM = #{recipNm}
		</if>
		<if test='goodsCd != null and goodsCd != ""'>
		       AND G1.GOODS_CD = #{goodsCd}
		</if>
		<if test='goodsNm != null and goodsNm != ""'>
		       AND G1.GOODS_NM = #{goodsNm}
		</if>
		<if test='sizeCd != null and sizeCd != ""'>
		       AND ODI.OPT_CD2 = #{sizeCd}
		</if>
		<if test='invoiceNo != null and invoiceNo != ""'>
		       AND OD.INVOICE_NO = #{invoiceNo}
		</if>
		<if test='wdInvoiceSendYn != null and wdInvoiceSendYn == "Y"'>
		       AND OD.INVOICE_SEND_YN = 'Y'
		</if>
		<if test='wdInvoiceSendYn != null and wdInvoiceSendYn == "N"'>
		       AND OD.INVOICE_SEND_YN = 'N'
		</if>
		<if test='stDate != null and stDate != ""'>
			<if test='searchDateGb != null and searchDateGb == "ordDt"'>
		       AND O.ORD_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		       AND O.ORD_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
			</if>
			<if test='searchDateGb != null and searchDateGb == "delvStdt"'>
		       AND OD.DELV_STDT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		       AND OD.DELV_STDT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
			</if>
			<if test='searchDateGb != null and searchDateGb == "soldoutDt"'>
		       AND OD.SOLDOUT_REG_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		       AND OD.SOLDOUT_REG_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
			</if>
		</if>
		<if test="ordNoList != null and ordNoList != ''">
		       AND OD.ORD_NO IN
			<foreach collection="ordNoList" item="item" index="index"  open="(" close=")" separator=",">
		           #{item}
			</foreach>
		</if>
		<if test="optCd != null and optCd != ''">
		       AND ODI.OPT_CD LIKE CONCAT('%',#{optCd},'%')
		</if>
		<if test="extmallId != null and extmallId != ''">
		       AND OD.VENDOR_ID = #{vendorId}
		       AND OD.EXTMALL_ID = #{extmallId}
		</if>
		<if test="extmallOrderId != null and extmallOrderId != ''">
		       AND OD.EXTMALL_ORDER_ID LIKE CONCAT('%',#{extmallOrderId},'%')
		</if>
		    GROUP BY OD.ORD_NO, OD.GOODS_CD, OD.ORD_DTL_NO, OD.DELV_ADDR_SQ, O.CUST_NO
		    ORDER BY OD.ORD_NO DESC
		        , OD.ORD_DTL_NO DESC
		),
		CTE_PAYMENT AS (
		    SELECT A.*
		         , P.PAY_SQ
		         , P.PG_GB
		      FROM CTE_ORDNO A
		      LEFT OUTER JOIN TB_PAYMENT P
		        ON A.ORD_NO = P.ORD_NO
		       AND P.PAY_GB = 'O'
		       AND P.PAY_STAT IN ('G016_30')
		     WHERE 1=1
		<if test='pgGb != null and pgGb != ""'>
		       AND P.PG_GB = #{pgGb}
		</if>
		<if test='payMeans != null and payMeans != ""'>
		       AND P.PAY_MEANS = #{payMeans}
		</if>
		),
		CTE_OCD AS (
		    SELECT OCD.ORD_DTL_NO
		         , OC.CHG_GB
		         , OC.CHG_REASON
		         , OCD.CHG_STAT
		      FROM TB_ORDER_CHANGE OC
		     INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		        ON OC.ORD_CHG_SQ  = OCD.ORD_CHG_SQ
		     INNER JOIN CTE_PAYMENT PP
		        ON OCD.ORD_DTL_NO = PP.ORD_DTL_NO
		     WHERE 1=1
		       AND OCD.CHG_STAT NOT IN ('G685_69', 'G685_49')            -- 반품철회, 교환철회 제외
		     GROUP BY OCD.ORD_DTL_NO
		         , OC.CHG_GB
		         , OC.CHG_REASON
		         , OCD.CHG_STAT
		),
		CTE AS (
		    SELECT OD.ORD_NO
		         , OD.ORD_DTL_NO
		      FROM CTE_PAYMENT OD
		      LEFT OUTER JOIN CTE_OCD OCD
		        ON OD.ORD_DTL_NO = OCD.ORD_DTL_NO
		     WHERE 1=1
		<if test="chgStat != null and chgStat != ''">
			<if test="chgStat == '9999'">
		       AND OCD.CHG_REASON = 'G686_30'
			</if>
			<if test="chgStat != '9999'">
		       AND OCD.CHG_STAT = #{chgStat}
			</if>
		</if>
		<if test="chgGb != null and chgGb != ''">
		       AND OCD.CHG_GB = #{chgGb}
		</if>
		     ORDER BY OD.ORD_NO DESC
		         , OD.ORD_DTL_NO DESC
		)
		SELECT X.*
		  FROM (
		    SELECT @rownum := @rownum + 1 AS RNUM
		         , Z.*
		      FROM (
		          SELECT A.ORD_NO
		               , A.ORD_DTL_NO
		               , A.ORD_NM
		               , A.CUST_NO
		               , A.CUST_ID
		               , A.VENDOR_ID
		               , A.FRONT_GB
		               , A.ORD_DT
		               , A.ORD_EXCH_GB
		               , A.ORD_DTL_STAT
		               , A.ORD_DTL_STAT_NM
		               , A.DELV_LOC_CD
		               , A.GOODS_CD
		               , A.GOODS_NM
		               , A.GOODS_TYPE
		               , A.GOODS_TYPE_NM
		               , A.SYS_IMG_NM
		               , A.BRAND_CD
		               , A.BRAND_ENM
		               -- , A.SKU_MODEL_NO
		               , GROUP_CONCAT(A.ITEM_NM ORDER BY A.ORD_DTL_ITEM_SQ SEPARATOR '!@!') AS ITEM_NM
		               , GROUP_CONCAT(A.ITEM_CD ORDER BY A.ORD_DTL_ITEM_SQ) AS ITEM_CD
		               , 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.EXTMALL_ORDER_ID
		               , A.AGENT_ORDER_ID
		               , A.ORD_QTY
		               , A.CNCL_RTN_QTY
		               , A.ORD_AMT
		               , A.CNCL_RTN_AMT
		               , A.TOT_DC_AMT
		               , A.REAL_ORD_AMT
		               , A.FORMAL_GB
		               , A.DELV_ASSIGN_DT
		               , A.INVOICE_NO
		               , A.DELV_STDT
		               , A.SOLDOUT_YN
		               , A.SOLDOUT_MEMO
		               , A.SOLDOUT_REG_DT
		               , A.SOLDOUT_REG_NO
		               , A.EXCH_GB_NM
		               , A.RECIP_NM
		               , A.RECIP_PHNNO
		               , A.RECIP_ADDR
		               , A.DELV_MEMO
		               , A.DSTRBT_NOTE
		               , A.RETURNABLE_YN
		               , A.CHANGEABLE_YN
		               , A.BRAND_GROUP_NM
		               , A.EXTMALL_NM
		               , A.SHIP_COMP_NM
		           FROM (
		             SELECT O.ORD_NO
		                  , OD.ORD_DTL_NO
		                  , ODI.ORD_DTL_ITEM_SQ
		                  , O.ORD_NM
		                  , O.CUST_NO
		                  , (SELECT X.CUST_ID
		                     FROM   TB_CUSTOMER X
		                     WHERE  X.CUST_NO = O.CUST_NO) AS CUST_ID
		                  , OD.VENDOR_ID
		                  , O.FRONT_GB
		                  , DATE_FORMAT(O.ORD_DT,'%Y%m%d%H%i%S') AS ORD_DT
		                  , OD.ORD_EXCH_GB
		                  , OD.ORD_DTL_STAT
		                  , FN_GET_CODE_NM('G013', OD.ORD_DTL_STAT)		                               AS ORD_DTL_STAT_NM
		                  , OD.DELV_LOC_CD
		                  , G1.GOODS_CD
		                  , FN_GET_GOODS_NM(G1.GOODS_NM, G1.GOODS_GB, G1.FOREIGN_BUY_YN, G1.PARALLEL_IMPORT_YN, G1.ORDER_MADE_YN) AS GOODS_NM
		                  , G1.GOODS_TYPE
		                  , FN_GET_CODE_NM('G056', G1.GOODS_TYPE) AS GOODS_TYPE_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 = 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
		                  , G1.BRAND_CD
		                  , (SELECT Z.BRAND_ENM
		                     FROM   TB_BRAND Z
		                     WHERE  Z.BRAND_CD = G1.BRAND_CD) AS BRAND_ENM
		                  -- , ODI.SKU_MODEL_NO
		                  , (SELECT GOODS_NM FROM TB_GOODS WHERE GOODS_CD = ODI.ITEM_CD) AS ITEM_NM
		                  , IFNULL((SELECT COLOR_KNM FROM TB_COLOR C WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,'') , G1.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		                  , ODI.ITEM_CD
		                  , ODI.ITEM_QTY
		                  , ODI.OPT_CD
		                  , ODI.OPT_CD1
		                  , ODI.OPT_CD2
		                  , OD.EXTMALL_ORDER_ID
		                  , OD.AGENT_ORDER_ID
		                  , OD.ORD_QTY
		                  , OD.CNCL_RTN_QTY
		                  , 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.PNT_DC_AMT + OD.PRE_PNT_DC_AMT AS TOT_DC_AMT
		                  , OD.REAL_ORD_AMT
		                  , OD.FORMAL_GB
		                  , DATE_FORMAT(OD.DELV_ASSIGN_DT,'%Y%m%d%H%i%S') AS DELV_ASSIGN_DT
		                  , OD.INVOICE_NO
		                  , DATE_FORMAT(OD.DELV_STDT,'%Y%m%d%H%i%S') AS DELV_STDT
		                  , OD.SOLDOUT_YN
		                  , OD.SOLDOUT_MEMO
		                  , DATE_FORMAT(OD.SOLDOUT_REG_DT,'%Y%m%d%H%i%S') AS SOLDOUT_REG_DT
		                  , OD.SOLDOUT_REG_NO
		                  , CASE WHEN OD.ORD_EXCH_GB = 'O' THEN '원주문'
		                         ELSE '교환'
		                     END		                        AS EXCH_GB_NM
		                  , DA.RECIP_NM
		                  , DA.RECIP_PHNNO
		                  , CONCAT(DA.RECIP_BASE_ADDR, ' ', DA.RECIP_DTL_ADDR) AS RECIP_ADDR
		                  , DA.DELV_MEMO
		                  , OD.DSTRBT_NOTE
		                  , OD.RETURNABLE_YN
		                  , OD.CHANGEABLE_YN
		                  , (SELECT CASE WHEN BG.DISP_NM_LANG = 'EN'
		                                 THEN BG.BRAND_GROUP_ENM
		                                 ELSE BG.BRAND_GROUP_KNM
		                                 END  BRAND_GROUP_NM
		                     FROM   TB_BRAND BR
		                     INNER  JOIN TB_BRAND_GROUP BG
		                     ON     BR.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		                     WHERE  1=1
		                     AND    BR.BRAND_CD = G1.BRAND_CD
		                     AND    BG.USE_YN = 'Y') AS BRAND_GROUP_NM
		                  , (SELECT EXTMALL_NM
		                     FROM   TB_EXTMALL EX
		                     WHERE  EX.EXTMALL_ID = OD.EXTMALL_ID) AS EXTMALL_NM
		                  , (SELECT SHIP_COMP_NM
		                     FROM   TB_SHIP_COMPANY SC
		                     WHERE  SC.SHIP_COMP_CD = OD.SHIP_COMP_CD) AS SHIP_COMP_NM
		               FROM CTE TT
		              INNER JOIN TB_ORDER O
		                 ON TT.ORD_NO = O.ORD_NO
		              INNER JOIN TB_ORDER_DETAIL OD
		                 ON TT.ORD_NO = OD.ORD_NO
		                AND TT.ORD_DTL_NO = OD.ORD_DTL_NO
		              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
		              INNER JOIN TB_DELIVERY_ADDR DA
		                 ON OD.DELV_ADDR_SQ = DA.DELV_ADDR_SQ
		              ORDER BY OD.ORD_NO DESC
		                     , OD.ORD_DTL_NO DESC
		        ) A
		        GROUP BY A.ORD_NO
		               , A.ORD_DTL_NO
		               , A.ORD_NM
		               , A.CUST_NO
		               , A.CUST_ID
		               , A.VENDOR_ID
		               , A.FRONT_GB
		               , A.ORD_DT
		               , A.ORD_EXCH_GB
		               , A.ORD_DTL_STAT
		               , A.ORD_DTL_STAT_NM
		               , A.DELV_LOC_CD
		               , A.GOODS_CD
		               , A.GOODS_NM
		               , A.GOODS_TYPE
		               , A.GOODS_TYPE_NM
		               , A.SYS_IMG_NM
		               , A.BRAND_CD
		               , A.BRAND_ENM
		               -- , A.SKU_MODEL_NO
		               , A.EXTMALL_ORDER_ID
		               , A.AGENT_ORDER_ID
		               , A.ORD_QTY
		               , A.CNCL_RTN_QTY
		               , A.ORD_AMT
		               , A.CNCL_RTN_AMT
		               , A.TOT_DC_AMT
		               , A.REAL_ORD_AMT
		               , A.FORMAL_GB
		               , A.DELV_ASSIGN_DT
		               , A.INVOICE_NO
		               , A.DELV_STDT
		               , A.SOLDOUT_YN
		               , A.SOLDOUT_MEMO
		               , A.SOLDOUT_REG_DT
		               , A.SOLDOUT_REG_NO
		               , A.EXCH_GB_NM
		               , A.RECIP_NM
		               , A.RECIP_PHNNO
		               , A.RECIP_ADDR
		               , A.DELV_MEMO
		               , A.DSTRBT_NOTE
		               , A.RETURNABLE_YN
		               , A.CHANGEABLE_YN
		               , A.BRAND_GROUP_NM
		               , A.EXTMALL_NM
		               , A.SHIP_COMP_NM
		    ) Z
			  JOIN (SELECT @rownum := 0) R
			 ORDER BY Z.ORD_NO DESC
		            , Z.ORD_DTL_NO DESC
		) X
		 WHERE 1=1
		   AND X.RNUM BETWEEN  #{pageable.startRow} AND #{pageable.endRow}
		 ORDER BY X.ORD_NO DESC
		        , X.ORD_DTL_NO DESC
	</select>

	<!-- 주문목록 > 주문목록카운트 -->
	<select id="getOrderListCount2" parameterType="Order" resultType="int">
		/* order.getOrderListCnt2 */
		SELECT COUNT(1)
		  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
		  LEFT OUTER JOIN TB_PAYMENT P
		    ON O.ORD_NO = P.ORD_NO
		   AND P.PAY_GB = 'O'
		   AND P.PAY_STAT IN ('G016_30')
		 INNER JOIN TB_DELIVERY_ADDR DA
		    ON OD.DELV_ADDR_SQ = DA.DELV_ADDR_SQ
		<if test="(chgStat != null and chgStat != '') or (chgGb != null and chgGb != '')">
		  LEFT OUTER JOIN (SELECT OCD.ORD_DTL_NO
		                   , OC.CHG_GB
		                   , OC.CHG_REASON
		                   , OCD.CHG_STAT
		                     FROM TB_ORDER_CHANGE OC
		                    INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		                  ON OC.ORD_CHG_SQ  = OCD.ORD_CHG_SQ
		                    WHERE 1=1
		                    GROUP BY OCD.ORD_DTL_NO
		                   , OC.CHG_GB
		                   , OC.CHG_REASON
		                   , OCD.CHG_STAT
		                 ) OCD
		    ON OD.ORD_DTL_NO = OCD.ORD_DTL_NO
		</if>
		  LEFT OUTER JOIN TB_CUSTOMER CU
		    ON O.CUST_NO = CU.CUST_NO
	 	 WHERE 1=1
	 	   AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_25', 'G013_97')
		<if test='siteCd != null and siteCd != ""'>
		   AND O.SITE_CD = #{siteCd}
		</if>
		<if test='mallCd != null and mallCd != ""'>
		   AND O.MALL_GB = #{mallCd}
		</if>
		<if test='supplyCompCd != null and supplyCompCd != ""'>
		   AND OD.SUPPLY_COMP_CD = #{supplyCompCd}
		</if>
		<if test="multiSupplyCompCd != null and multiSupplyCompCd != ''">
		   AND OD.SUPPLY_COMP_CD IN
			<foreach collection="multiSupplyCompCd" item="item" index="index"  open="(" close=")" separator=",">
				#{item}
			</foreach>
		</if>
		<if test="multiBrand != null and multiBrand != ''">
		   AND G1.BRAND_CD IN
			<foreach collection="multiBrand" item="item" index="index"  open="(" close=")" separator=",">
				#{item}
			</foreach>
		</if>
		<if test="multiOrdDtlStat != null and multiOrdDtlStat != ''">
		   AND OD.ORD_DTL_STAT IN
			<foreach collection="multiOrdDtlStat" item="item" index="index"  open="(" close=")" separator=",">
				#{item}
			</foreach>
		</if>
		<if test="chgStat != null and chgStat != ''">
			<if test="chgStat == '9999'">
		   AND OCD.CHG_REASON = 'G686_30'
			</if>
			<if test="chgStat != '9999'">
		   AND OCD.CHG_STAT = #{chgStat}
			</if>
		</if>
		<if test="chgGb != null and chgGb != ''">
		   AND OCD.CHG_GB = #{chgGb}
		</if>
		<if test='search != null and search == "searchOrdNo"'>
			<if test="condition != null and condition != ''">
		   AND O.ORD_NO = #{condition}
			</if>
		</if>
		<if test='search != null and search == "searchExtmallOrderId"'>
			<if test="condition != null and condition != ''">
		   AND OD.EXTMALL_ORDER_ID = #{condition}
			</if>
		</if>
		<if test='search != null and search == "searchAgentOrderId"'>
			<if test="condition != null and condition != ''">
		   AND OD.AGENT_ORDER_ID = #{condition}
			</if>
		</if>
		<if test='pgGb != null and pgGb != ""'>
		   AND P.PG_GB = #{pgGb}
		</if>
		<if test='payMeans != null and payMeans != ""'>
		   AND P.PAY_MEANS = #{payMeans}
		</if>
		<if test='orderNm != null and orderNm != ""'>
		   AND O.ORD_NM = #{orderNm}
		</if>
		<if test='custId != null and custId != ""'>
		   AND CU.CUST_ID = #{custId}
		</if>
		<if test='orderPhnno != null and orderPhnno != ""'>
		   AND O.ORD_PHNNO = #{orderPhnno}
		</if>
		<if test='goodsCd != null and goodsCd != ""'>
		   AND G1.GOODS_CD = #{goodsCd}
		</if>
		<if test='goodsNm != null and goodsNm != ""'>
		   AND G1.GOODS_NM = #{goodsNm}
		</if>
		<if test='payMeans != null and payMeans != ""'>
		   AND P.PAY_MEANS = #{payMeans}
		</if>
		<if test='orderNm != null and orderNm != ""'>
		   AND O.ORD_NM = #{orderNm}
		</if>
		<if test='custNo != null and custNo != ""'>
		   AND O.CUST_NO = #{custNo}
		</if>
		<if test='orderPhnno != null and orderPhnno != ""'>
		   AND O.ORD_PHNNO = #{orderPhnno}
		</if>
		<if test='recipNm != null and recipNm != ""'>
		   AND DA.RECIP_NM = #{recipNm}
		</if>
		<if test='invoiceNo != null and invoiceNo != ""'>
		   AND OD.INVOICE_NO = #{invoiceNo}
		</if>
		<if test='wdInvoiceSendYn != null and wdInvoiceSendYn == "Y"'>
		   AND OD.INVOICE_SEND_YN = 'Y'
		</if>
		<if test='wdInvoiceSendYn != null and wdInvoiceSendYn == "N"'>
		   AND OD.INVOICE_SEND_YN = 'N'
		</if>
		<if test='stDate != null and stDate != ""'>
			<if test='searchDateGb != null and searchDateGb == "ordDt"'>
		       AND O.ORD_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		       AND O.ORD_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
			</if>
			<if test='searchDateGb != null and searchDateGb == "delvStdt"'>
		       AND OD.DELV_STDT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		       AND OD.DELV_STDT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
			</if>
			<if test='searchDateGb != null and searchDateGb == "soldoutDt"'>
		       AND OD.SOLDOUT_REG_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		       AND OD.SOLDOUT_REG_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
			</if>
		</if>
		<if test="ordNoList != null and ordNoList != ''">
		   AND OD.ORD_NO IN
			<foreach collection="ordNoList" item="item" index="index"  open="(" close=")" separator=",">
				#{item}
			</foreach>
		</if>
	</select>

	<!-- 주문목록 > 주문목록 -->
	<select id="getOrderList2" parameterType="Order" resultType="Order">
		/* order.getOrderList2 */
		SELECT X.*
		FROM (
		    SELECT @rownum := @rownum + 1 AS RNUM
		         , Z.*
		      FROM (SELECT A.ORD_NO
		                 , A.ORD_DTL_NO
		                 , A.ORD_NM
		                 , A.CUST_NO
		                 , A.CUST_ID
		                 , A.VENDOR_ID
		                 , A.FRONT_GB
		                 , A.ORD_DT
		                 , A.ORD_EXCH_GB
		                 , A.ORD_DTL_STAT
		                 , A.ORD_DTL_STAT_NM
		                 , A.DELV_LOC_CD
		                 , A.GOODS_CD
		                 , A.GOODS_NM
		                 , A.GOODS_TYPE
		                 , A.GOODS_TYPE_NM
		                 , A.SYS_IMG_NM
		                 , A.BRAND_CD
		                 , A.BRAND_ENM
		                 , GROUP_CONCAT(A.ITEM_NM ORDER BY A.ORD_DTL_ITEM_SQ SEPARATOR '!@!') AS ITEM_NM
		                 , GROUP_CONCAT(A.ITEM_CD ORDER BY A.ORD_DTL_ITEM_SQ) AS ITEM_CD
		                 , 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.EXTMALL_ORDER_ID
		                 , A.AGENT_ORDER_ID
		                 , A.ORD_QTY
		                 , A.CNCL_RTN_QTY
		                 , A.ORD_AMT
		                 , A.CNCL_RTN_AMT
		                 , A.TOT_DC_AMT
		                 , A.REAL_ORD_AMT
		                 , A.FORMAL_GB
		                 , A.DELV_ASSIGN_DT
		                 , A.INVOICE_NO
		                 , A.DELV_STDT
		                 , A.SOLDOUT_YN
		                 , A.SOLDOUT_MEMO
		                 , A.SOLDOUT_REG_DT
		                 , A.SOLDOUT_REG_NO
		                 , A.EXCH_GB_NM
		                 , A.RECIP_NM
		                 , A.RECIP_PHNNO
		                 , A.RECIP_ADDR
		                 , A.DELV_MEMO
		                 , A.DSTRBT_NOTE
		                 , A.RETURNABLE_YN
		                 , A.CHANGEABLE_YN
		                 , A.BRAND_GROUP_NM
		                 , A.EXTMALL_NM
		                 , A.SHIP_COMP_NM
		              FROM (SELECT O.ORD_NO
		                    , OD.ORD_DTL_NO
		                    , ODI.ORD_DTL_ITEM_SQ
		                    , O.ORD_NM
		                    , O.CUST_NO
		                    , (SELECT X.CUST_ID
		                       FROM   TB_CUSTOMER X
		                       WHERE  X.CUST_NO = O.CUST_NO) AS CUST_ID
		                    , OD.VENDOR_ID
		                    , O.FRONT_GB
		                    , DATE_FORMAT(O.ORD_DT,'%Y%m%d%H%i%S') AS ORD_DT
		                    , OD.ORD_EXCH_GB
		                    , OD.ORD_DTL_STAT
		                    , FN_GET_CODE_NM('G013', OD.ORD_DTL_STAT)							AS ORD_DTL_STAT_NM
		                    , OD.DELV_LOC_CD
		                    , G1.GOODS_CD
		                    , FN_GET_GOODS_NM(G1.GOODS_NM, G1.GOODS_GB, G1.FOREIGN_BUY_YN, G1.PARALLEL_IMPORT_YN, G1.ORDER_MADE_YN) AS GOODS_NM
		                    , G1.GOODS_TYPE
		                    , FN_GET_CODE_NM('G056', G1.GOODS_TYPE) AS GOODS_TYPE_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 = 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
		                    , G1.BRAND_CD
		                    , (SELECT Z.BRAND_ENM
		                       FROM   TB_BRAND Z
		                       WHERE  Z.BRAND_CD = G1.BRAND_CD) AS BRAND_ENM
		                    , (SELECT GOODS_NM FROM TB_GOODS WHERE GOODS_CD = ODI.ITEM_CD) AS ITEM_NM
		                    , IFNULL((SELECT COLOR_KNM FROM TB_COLOR C WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,'') , G1.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		                    , ODI.ITEM_CD
		                    , ODI.ITEM_QTY
		                    , ODI.OPT_CD
		                    , ODI.OPT_CD1
		                    , ODI.OPT_CD2
		                    , OD.EXTMALL_ORDER_ID
		                    , OD.AGENT_ORDER_ID
		                    , OD.ORD_QTY
		                    , OD.CNCL_RTN_QTY
		                    , 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 AS TOT_DC_AMT
		                    , OD.REAL_ORD_AMT
		                    , OD.FORMAL_GB
		                    , DATE_FORMAT(OD.DELV_ASSIGN_DT,'%Y%m%d%H%i%S') AS DELV_ASSIGN_DT
		                    , OD.INVOICE_NO
		                    , DATE_FORMAT(OD.DELV_STDT,'%Y%m%d%H%i%S') AS DELV_STDT
		                    , OD.SOLDOUT_YN
		                    , OD.SOLDOUT_MEMO
		                    , DATE_FORMAT(OD.SOLDOUT_REG_DT,'%Y%m%d%H%i%S') AS SOLDOUT_REG_DT
		                    , OD.SOLDOUT_REG_NO
		                    , CASE WHEN OD.ORD_EXCH_GB = 'O' THEN '원주문'
		                           ELSE '교환'
		                       END		                        AS EXCH_GB_NM
		                    , DA.RECIP_NM
		                    , DA.RECIP_PHNNO
		                    , CONCAT(DA.RECIP_BASE_ADDR, ' ', DA.RECIP_DTL_ADDR) AS RECIP_ADDR
		                    , DA.DELV_MEMO
		                    , OD.DSTRBT_NOTE
		                    , OD.RETURNABLE_YN
		                    , OD.CHANGEABLE_YN
		                    , (SELECT CASE WHEN BG.DISP_NM_LANG = 'EN'
				                      THEN BG.BRAND_GROUP_ENM
				                      ELSE BG.BRAND_GROUP_KNM
				                      END  BRAND_GROUP_NM
		                       FROM   TB_BRAND BR
		                       INNER  JOIN TB_BRAND_GROUP BG
		                       ON     BR.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		                       WHERE  1=1
		                       AND    BR.BRAND_CD = G1.BRAND_CD
		                       AND    BG.USE_YN = 'Y') AS BRAND_GROUP_NM
		                    , (SELECT EXTMALL_NM
		                       FROM   TB_EXTMALL EX
		                       WHERE  EX.EXTMALL_ID = OD.EXTMALL_ID) AS EXTMALL_NM
		                    , (SELECT SHIP_COMP_NM
		                       FROM   TB_SHIP_COMPANY SC
		                       WHERE  SC.SHIP_COMP_CD = OD.SHIP_COMP_CD) AS SHIP_COMP_NM
		                      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_DTL_NO = ODI.ORD_DTL_NO
		                     INNER JOIN TB_GOODS G2
		                   ON ODI.ITEM_CD = G2.GOODS_CD
		                      LEFT OUTER JOIN TB_PAYMENT P
		                   ON O.ORD_NO = P.ORD_NO
		                  AND P.PAY_GB = 'O'
		                  AND P.PAY_STAT IN ('G016_30')
		                     INNER JOIN TB_DELIVERY_ADDR DA
		                   ON OD.DELV_ADDR_SQ = DA.DELV_ADDR_SQ
			<if test="(chgStat != null and chgStat != '') or (chgGb != null and chgGb != '')">
		                      LEFT OUTER JOIN (SELECT OCD.ORD_DTL_NO
				                     , OC.CHG_GB
				                     , OC.CHG_REASON
				                     , OCD.CHG_STAT
				                  FROM TB_ORDER_CHANGE OC
				                      INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
				                    ON OC.ORD_CHG_SQ  = OCD.ORD_CHG_SQ
				                      WHERE 1=1
				                      GROUP BY OCD.ORD_DTL_NO, OC.CHG_GB, OCD.CHG_STAT, OC.CHG_REASON
				                    ) OCD
		                   ON OD.ORD_DTL_NO = OCD.ORD_DTL_NO
			</if>
		                      LEFT OUTER JOIN TB_CUSTOMER CU
		                   ON O.CUST_NO = CU.CUST_NO
		                     WHERE 1=1
		                  AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_25', 'G013_97')
			<if test='siteCd != null and siteCd != ""'>
		                  AND O.SITE_CD = #{siteCd}
			</if>
			<if test='mallCd != null and mallCd != ""'>
		                  AND O.MALL_GB = #{mallCd}
			</if>
			<if test='supplyCompCd != null and supplyCompCd != ""'>
		                  AND OD.SUPPLY_COMP_CD = #{supplyCompCd}
			</if>
			<if test="multiSupplyCompCd != null and multiSupplyCompCd != ''">
			                   AND OD.SUPPLY_COMP_CD IN
				<foreach collection="multiSupplyCompCd" item="item" index="index"  open="(" close=")" separator=",">
					#{item}
				</foreach>
			</if>
			<if test="multiBrand != null and multiBrand != ''">
		                  AND G1.BRAND_CD IN
				<foreach collection="multiBrand" item="item" index="index"  open="(" close=")" separator=",">
					#{item}
				</foreach>
			</if>
			<if test="multiOrdDtlStat != null and multiOrdDtlStat != ''">
		                  AND OD.ORD_DTL_STAT IN
				<foreach collection="multiOrdDtlStat" item="item" index="index"  open="(" close=")" separator=",">
					#{item}
				</foreach>
			</if>
			<if test="chgStat != null and chgStat != ''">
				<if test="chgStat == '9999'">
		                  AND OCD.CHG_REASON = 'G686_30'
				</if>
				<if test="chgStat != '9999'">
		                  AND OCD.CHG_STAT = #{chgStat}
				</if>
			</if>
			<if test="chgGb != null and chgGb != ''">
		                  AND OCD.CHG_GB = #{chgGb}
			</if>
		    <if test="conditions != null and conditions.length > 0">
				<choose>
					<when test='search == "searchOrdNo"'>
		                  AND O.ORD_NO IN
						<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
				                     #{item}
						</foreach>
					</when>
					<when test='search == "searchExtmallOrderId"'>
		                  AND OD.EXTMALL_ORDER_ID IN
						<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
				                           #{item}
						</foreach>
					</when>
					<when test='search == "searchAgentOrderId"'>
		                  AND OD.AGENT_ORDER_ID IN
						<foreach collection="conditions" item="item" index="index" open="(" close=")" separator=",">
				                         #{item}
						</foreach>
					</when>
				</choose>
			</if>
			<if test='payMeans != null and payMeans != ""'>
		                  AND P.PAY_MEANS = #{payMeans}
			</if>
			<if test='orderNm != null and orderNm != ""'>
		                  AND O.ORD_NM = #{orderNm}
			</if>
			<if test='custId != null and custId != ""'>
		                  AND CU.CUST_ID = #{custId}
			</if>
			<if test='orderPhnno != null and orderPhnno != ""'>
		                  AND O.ORD_PHNNO = #{orderPhnno}
			</if>
			<if test='goodsCd != null and goodsCd != ""'>
		                  AND G1.GOODS_CD = #{goodsCd}
			</if>
			<if test='sizeCd != null and sizeCd != ""'>
		                  AND ODI.OPT_CD2 = #{sizeCd}
			</if>
			<if test='goodsNm != null and goodsNm != ""'>
		                  AND G1.GOODS_NM = #{goodsNm}
			</if>
			<if test='pgGb != null and pgGb != ""'>
		                  AND P.PG_GB = #{pgGb}
			</if>
			<if test='payMeans != null and payMeans != ""'>
		                  AND P.PAY_MEANS = #{payMeans}
			</if>
			<if test='orderNm != null and orderNm != ""'>
		                  AND O.ORD_NM = #{orderNm}
			</if>
			<if test='custNo != null and custNo != ""'>
		                  AND O.CUST_NO = #{custNo}
			</if>
			<if test='orderPhnno != null and orderPhnno != ""'>
		                  AND O.ORD_PHNNO = #{orderPhnno}
			</if>
			<if test='recipNm != null and recipNm != ""'>
		                  AND DA.RECIP_NM = #{recipNm}
			</if>
			<if test='invoiceNo != null and invoiceNo != ""'>
		                  AND OD.INVOICE_NO = #{invoiceNo}
			</if>
			<if test='wdInvoiceSendYn != null and wdInvoiceSendYn == "Y"'>
		                  AND OD.INVOICE_SEND_YN = 'Y'
			</if>
			<if test='wdInvoiceSendYn != null and wdInvoiceSendYn == "N"'>
		                  AND OD.INVOICE_SEND_YN = 'N'
			</if>
			<if test='stDate != null and stDate != ""'>
				<if test='searchDateGb != null and searchDateGb == "ordDt"'>
		                  AND O.ORD_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		                  AND O.ORD_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
				</if>
				<if test='searchDateGb != null and searchDateGb == "delvStdt"'>
		                  AND OD.DELV_STDT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		                  AND OD.DELV_STDT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
				</if>
				<if test='searchDateGb != null and searchDateGb == "soldoutDt"'>
		                  AND OD.SOLDOUT_REG_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
		                  AND OD.SOLDOUT_REG_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
				</if>
			</if>
			<if test="ordNoList != null and ordNoList != ''">
		                  AND OD.ORD_NO IN
				<foreach collection="ordNoList" item="item" index="index"  open="(" close=")" separator=",">
					#{item}
				</foreach>
			</if>
		                     ORDER BY OD.ORD_NO DESC
		                       , OD.ORD_DTL_NO DESC
		                   ) A
		                   GROUP BY A.ORD_NO
		                  , A.ORD_DTL_NO
		                  , A.ORD_NM
		                  , A.CUST_NO
		                  , A.CUST_ID
		                  , A.VENDOR_ID
		                  , A.FRONT_GB
		                  , A.ORD_DT
		                  , A.ORD_EXCH_GB
		                  , A.ORD_DTL_STAT
		                  , A.ORD_DTL_STAT_NM
		                  , A.DELV_LOC_CD
		                  , A.GOODS_CD
		                  , A.GOODS_NM
		                  , A.GOODS_TYPE
		                  , A.GOODS_TYPE_NM
		                  , A.SYS_IMG_NM
		                  , A.BRAND_CD
		                  , A.BRAND_ENM
		                  , A.EXTMALL_ORDER_ID
		                  , A.AGENT_ORDER_ID
		                  , A.ORD_QTY
		                  , A.CNCL_RTN_QTY
		                  , A.ORD_AMT
		                  , A.CNCL_RTN_AMT
		                  , A.TOT_DC_AMT
		                  , A.REAL_ORD_AMT
		                  , A.FORMAL_GB
		                  , A.DELV_ASSIGN_DT
		                  , A.INVOICE_NO
		                  , A.DELV_STDT
		                  , A.SOLDOUT_YN
		                  , A.SOLDOUT_MEMO
		                  , A.SOLDOUT_REG_DT
		                  , A.SOLDOUT_REG_NO
		                  , A.EXCH_GB_NM
		                  , A.RECIP_NM
		                  , A.RECIP_PHNNO
		                  , A.RECIP_ADDR
		                  , A.DELV_MEMO
		                  , A.DSTRBT_NOTE
		                  , A.RETURNABLE_YN
		                  , A.CHANGEABLE_YN
		                  , A.BRAND_GROUP_NM
		                  , A.EXTMALL_NM
		                  , A.SHIP_COMP_NM
		           ) Z
		           JOIN (SELECT @rownum := 0) R
		           ORDER BY Z.ORD_NO DESC
		                  , Z.ORD_DTL_NO DESC
		    ) X
		     WHERE 1=1
		       AND X.RNUM BETWEEN  #{pageable.startRow} AND #{pageable.endRow}
		     ORDER BY X.ORD_NO DESC
		            , X.ORD_DTL_NO DESC
	</select>

	<!-- 주문상세 > 주문기본정보 -->
	<select id="getOrderInfoList" parameterType="Order" resultType="Order">
		/* order.getOrderInfoList */
		SELECT O.SITE_CD
		     , FN_GET_CODE_NM('G000', O.SITE_CD)          AS SITE_CD_NM
		     , O.MALL_GB
		     , FN_GET_CODE_NM('G011', O.MALL_GB)          AS MALL_GB_NM
		     , O.FRONT_GB
		     , CASE WHEN O.FRONT_GB = 'P'THEN 'PC'
		            WHEN O.FRONT_GB = 'M'THEN 'MOB'
		            WHEN O.FRONT_GB = 'A'THEN 'APP'
		            ELSE ''
		       END                                        AS FRONT_GB_NM
		     , OD.EXTMALL_ID
		     , (SELECT X.EXTMALL_NM
		          FROM TB_EXTMALL X
		         WHERE X.EXTMALL_ID = OD.EXTMALL_ID)      AS EXTMALL_NM
		     , DATE_FORMAT(O.ORD_DT, '%Y-%m-%d %H:%i:%S') AS ORD_DT
		     , O.ORD_NM
		     , O.CUST_NO
		     , O.ORD_NO
		     , O.ORD_EMAIL
		     , O.ORD_PHNNO
		     , O.ORD_TELNO
		     , C.CUST_GB
		     , CASE WHEN C.CUST_GB IS NULL OR C.CUST_GB IN (10)
		            THEN '비회원'
		            ELSE FN_GET_CODE_NM('G100', C.CUST_GB)
		       END                                        AS CUST_GB_NM
		     , C.MANAGED_RSN
		     , CASE WHEN C.MANAGED_RSN IS NULL
		            THEN '부'
		            ELSE FN_GET_CODE_NM('G103', C.MANAGED_RSN)
		       END                                        AS MANAGED_RSN_NM
		     , C.CUST_GRADE
		     , CASE WHEN C.CUST_GRADE IS NULL
		            THEN '등급없음'
		            ELSE FN_GET_CODE_NM('G110', C.CUST_GRADE)
		       END                                        AS CUST_GRADE_NM
		     , P.ESCROW_YN
		     , CASE WHEN O.MALL_GB IN ('G011_20')
		            THEN ''
		            ELSE P.PAY_MEANS
		       END                                        AS PAY_MEANS
		     , CASE WHEN O.MALL_GB IN ('G011_20')
		            THEN ''
		            ELSE FN_GET_CODE_NM('G014', P.PAY_MEANS)
		       END                                        AS PAY_MEANS_NM
		     , CASE WHEN P.PAY_MEANS IN ('G014_20')
		            THEN P.VA_BANK
		            ELSE ''
		       END                                        AS VA_BANK
		     , P.VA_NO
		     , P.VA_NM
		     , CASE WHEN P.PAY_MEANS = 'G014_20' OR P.PAY_MEANS = 'G014_10'
		            THEN FN_GET_CODE_NM('G940', P.VA_BANK)
		            ELSE P.CARD_NM
		       END                                        AS CARD_NM
		     , P.PG_TRADE_NO
		     , DATE_FORMAT(P.PAY_DT, '%Y%m%d%H%i%S')      AS PAY_DT
		     , P.PAY_STAT
		     , FN_GET_CODE_NM('G016', P.PAY_STAT)         AS PAY_STAT_NM
		     , P.PAY_AMT
		     , DATE_FORMAT(P.VA_DEADLINE, '%Y.%m.%d')     AS VA_DEADLINE
		     , CASE WHEN NOW() <![CDATA[<]]> DATE_ADD(O.PAY_DT, INTERVAL 3 DAY)
		            THEN 'N'
		            ELSE 'Y'
		       END                                        AS GIFT_PACK_CLOSE_YN
		     , DATE_ADD(O.PAY_DT, INTERVAL 3 DAY)         AS GIFT_PACK_CLOSE_DT
		     , CASE WHEN O.MALL_GB IN ('G011_20')
		            THEN ''
		            ELSE P.PG_GB
		       END                                        AS PG_GB
		     , CASE WHEN C.CUST_ID IS NULL
		            THEN 'GUEST'
		            ELSE C.CUST_ID
		       END                                        AS CUST_ID
		     , OD.EXTMALL_ORDER_ID
		     , O.NPAY_ORD_NO
		  FROM TB_ORDER O
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON O.ORD_NO = OD.ORD_NO
		  LEFT OUTER JOIN TB_CUSTOMER C
		    ON O.CUST_NO = C.CUST_NO
		  LEFT OUTER JOIN TB_PAYMENT P
		    ON O.ORD_NO = P.ORD_NO
		   AND P.PAY_GB = 'O'
		   AND P.PAY_STAT IN ('G016_30', 'G016_10')
		 WHERE 1 = 1
		   AND O.ORD_NO = #{ordNo}
		 LIMIT 1
	</select>
	
	<!-- 주문상세 > 원주문결제내역정보 -->
	<select id="getOriginalOrderPaymentInfo" parameterType="Order" resultType="Order">
		/* TscOrder.getOriginalOrderPaymentInfo */
		WITH ORIGINAL_ORD AS (
		    SELECT ODH.ORD_NO           /*주문번호*/
		         , ODH.ORD_DTL_NO       /*주문상세번호*/
		         , ODH.ORD_AMT          /*주문금액*/
		         , ODH.REAL_ORD_AMT     /*실주문금액*/
		         , (ODH.CURR_PRICE + ODH.OPT_ADD_PRICE) * (ODH.ORD_QTY - ODH.CNCL_RTN_QTY) AS ORD_CURR_AMT /*주문상품금액*/
		         , ODH.CPN1_CPN_SQ      /*즉시할인쿠폰번호*/
		         , ODH.CPN1_DC_AMT      /*즉시할인쿠폰금액*/
		         , ODH.TMTB1_SQ         /*다다익선수량할인번호*/
		         , ODH.TMTB1_DC_AMT     /*다다익선수량할인금액*/
		         , ODH.TMTB2_SQ         /*다다익선금액할인번호*/
		         , ODH.TMTB2_DC_AMT     /*다다익선금액할인금액*/
		         , ODH.GOODS_CPN_SQ     /*상품쿠폰번호*/
		         , ODH.GOODS_CPN_DC_AMT /*상품쿠폰할인금액*/
		         , ODH.CART_CPN_SQ      /*장바구니쿠폰번호*/
		         , ODH.CART_CPN_DC_AMT  /*장바구니쿠폰할인금액*/
		         , ODH.PRE_PNT_DC_AMT   /*선포인트할인금액*/
		         , ODH.GFCD_USE_AMT     /*상품권사용금액*/
		         , ODH.PNT_DC_AMT       /*포인트할인금액*/
		         , ODH.SAVE_PNT_AMT     /*적립포인트금액*/
		    FROM   TB_ORDER_DETAIL_HST ODH
		    INNER JOIN TB_ORDER O ON ODH.ORD_NO = O.ORD_NO
		    WHERE  ODH.ORD_NO = #{ordNo}
		    AND    ODH.ORD_EXCH_GB = 'O' /*원주문*/
		    AND    (
		            (ODH.ORD_DTL_STAT = 'G013_00' /*주문접수*/ AND O.MALL_GB = 'G011_10' /*자사몰*/)
		            OR
		            (ODH.ORD_DTL_STAT = 'G013_20' /*결제완료*/ AND O.MALL_GB = 'G011_20' /*제휴몰*/)
		           )
		)
		, ORIGINAL_DELV_FEE AS (
		    SELECT DF.DELV_FEE_CD                                             /*배송비정책코드*/
		         , DF.SUPPLY_COMP_CD                                          /*공급업체코드*/
		         , FN_GET_SUPPLY_COMP_NM(DF.SUPPLY_COMP_CD) AS SUPPLY_COMP_NM /*공급업체명*/
		         , DF.DELV_FEE                                                /*배송비*/
		         , DF.DELV_CPN_SQ                                             /*배송비쿠폰번호*/
		         , DF.DELV_CPN_DC_AMT                                         /*배송비쿠폰할인금액*/
		         , DF.DELV_GFCD_USE_AMT                                       /*배송비상품권사용금액*/
		         , DF.REAL_DELV_AMT                                           /*실배송비금액*/
		    FROM   TB_DELIVERY_FEE DF
		    WHERE  DF.ORD_NO = #{ordNo}
		    AND    DF.DELV_FEE_GB = 'G018_10' /*원주문배송비*/
		    AND    DF.ORD_CHG_SQ IS NULL /*취소/교환/반품이 없는 넘*/
		)
		, ORIGINAL_PAYMENT AS (
		    SELECT ORD_NO
		         , CASE WHEN PG_GB = 'NAVER' THEN
		                    CASE WHEN PAY_MEANS = 'G014_10' THEN '네이버페이(계좌)'
		                         WHEN PAY_MEANS = 'G014_30' THEN '네이버페이(신용)'
		                         ELSE '네이버페이'
		                    END
		                WHEN PG_GB = 'NAVER_ORDER' THEN '네이버페이주문형'
		                WHEN PG_GB = 'KAKAO' THEN
		                    CASE WHEN PAY_MEANS = 'G014_10' THEN '카카오페이(계좌)'
		                         WHEN PAY_MEANS = 'G014_30' THEN '카카오페이(신용)'
		                         WHEN PAY_MEANS = 'G014_83' THEN '카카오페이(머니)'
		                         ELSE '카카오페이'
		                    END
		                WHEN PG_GB = 'PAYCO' THEN
		                    CASE WHEN PAY_MEANS = 'G014_10' THEN '페이코(계좌)'
		                         WHEN PAY_MEANS = 'G014_30' THEN '페이코(신용)'
		                         ELSE '페이코'
		                    END
		                ELSE FN_GET_CODE_NM('G014',PAY_MEANS)
		           END           AS PAY_MEANS_NM  /*결제수단명*/
		         , CASE WHEN PG_GB = 'KCP' THEN
		                    CASE WHEN PAY_MEANS = 'G014_10' THEN CONCAT(FN_GET_CODE_NM('G940',VA_BANK),' / ',VA_NO)
		                         WHEN PAY_MEANS = 'G014_20' THEN CONCAT(FN_GET_CODE_NM('G940',VA_BANK),' / ',VA_NO,' / ',VA_NM,' / 입금일 : ',IFNULL(DATE_FORMAT(PAY_DT,'%Y-%m-%d %H:%i:%S'),''))
		                         WHEN PAY_MEANS = 'G014_30' THEN CONCAT(CARD_NM,' / ',CASE WHEN CAST(CARD_MIPS AS UNSIGNED) = 0 THEN '일시불' ELSE CONCAT(CAST(CARD_MIPS AS UNSIGNED),'개월') END)
		                         ELSE ''
		                    END
		                WHEN PG_GB IN ('NAVER','KAKAO','PAYCO') THEN
		                    CASE WHEN PAY_MEANS = 'G014_30' THEN CONCAT(CARD_NM,' / ',CASE WHEN CAST(CARD_MIPS AS UNSIGNED) = 0 THEN '일시불' ELSE CONCAT(CAST(CARD_MIPS AS UNSIGNED),'개월') END)
		                         ELSE ''
		                    END
		                ELSE ''
		           END           AS PAY_MEANS_DESC     /*결제수단설명*/
		         , PG_CPN_AMT                          /*PG쿠폰금액*/
		         , NPAY_PNT_AMT                        /*포인트금액(마일리지)*/
		         , CASE WHEN NPAY_PNT_AMT > 0 THEN
		                    CASE WHEN PG_GB = 'NAVER' THEN '네이버포인트'
		                         WHEN PG_GB = 'KAKAO' THEN '카카오포인트'
		                         WHEN PG_GB = 'PAYCO' THEN '페이코포인트'
		                         ELSE ''
		                    END
		                ELSE ''
		           END           AS NPAY_PNT_DESC      /*포인트(마일리지)설명*/
		         , CASE WHEN CASH_AUTH_NO IS NOT NULL AND CASH_TRADE_NO IS NOT NULL THEN 'Y'
		                ELSE 'N'
		           END           AS CASH_RECEIP_REQ_YN /*현금영수증신청여부*/
		    FROM   TB_PAYMENT
		    WHERE  ORD_NO = #{ordNo}
		    AND    PAY_GB = 'O' /*주문시결제*/
		    AND    PAY_STAT IN ('G016_30','G016_10') /*결제완료,무통장입금관련*/
		)
		SELECT OO.ORD_NO                                                   /*주문번호*/
		     , SUM(OO.ORD_CURR_AMT)                   AS ORD_CURR_AMT      /*주문상품금액*/
		     , IFNULL((SELECT SUM(REAL_DELV_AMT)
		               FROM   ORIGINAL_DELV_FEE
		              ),0)                            AS REAL_DELV_AMT     /*실배송비금액*/
		     , (SELECT CONCAT(IFNULL((SELECT CONCAT('자사 : ',FORMAT(SUM(DF.DELV_FEE),0),'원')
		                              FROM   ORIGINAL_DELV_FEE DF
		                              WHERE  DF.DELV_FEE_CD = 'WMS' /*자사*/
		                             ),''),
		                      CASE WHEN IFNULL((SELECT COUNT(*)
		                                        FROM   ORIGINAL_DELV_FEE DF
		                                        WHERE  DF.DELV_FEE_CD = 'WMS' /*자사*/
		                                       ),0) > 0
		                                AND
		                                IFNULL((SELECT COUNT(*)
		                                        FROM   ORIGINAL_DELV_FEE DF
		                                        WHERE  DF.DELV_FEE_CD != 'WMS' /*입점업체*/
		                                       ),0) > 0 THEN ' / '
		                           ELSE ''
		                      END,
		                      IFNULL((SELECT CONCAT('업체 : ',GROUP_CONCAT(DELV_FEE_DESC SEPARATOR ', '))
		                              FROM   (
		                                      SELECT CONCAT(DF.SUPPLY_COMP_CD,'/',FN_GET_SUPPLY_COMP_NM(DF.SUPPLY_COMP_CD),' ',FORMAT(SUM(DF.DELV_FEE),0),'원') AS DELV_FEE_DESC
		                                      FROM   ORIGINAL_DELV_FEE DF
		                                      WHERE  DF.DELV_FEE_CD != 'WMS' /*입점업체*/
		                                      GROUP  BY DF.SUPPLY_COMP_CD
		                                     ) Z
		                             ),'')) AS DELV_FEE_DESC
		        FROM   DUAL
		       )                                      AS DELV_FEE_DESC     /*배송비설명*/
		     , (SELECT GROUP_CONCAT(DISTINCT CONCAT('쿠폰번호 : ',C.CPN_ID,' / ',C.CPN_NM,' ',FORMAT(DF.DELV_CPN_DC_AMT,0),'원') SEPARATOR ', ') AS DELV_FEE_CPN_DESC
		        FROM   ORIGINAL_DELV_FEE DF
		        INNER JOIN TB_CUST_COUPON CC ON DF.DELV_CPN_SQ = CC.CUST_CPN_SQ
		        INNER JOIN TB_COUPON C ON CC.CPN_ID = C.CPN_ID
		        WHERE  DF.DELV_CPN_SQ > 0
		       )                                      AS DELV_FEE_CPN_DESC /*배송비쿠폰설명*/
		     , SUM(OO.CPN1_DC_AMT +
		           OO.TMTB1_DC_AMT + OO.TMTB2_DC_AMT +
		           OO.GOODS_CPN_DC_AMT + OO.CART_CPN_DC_AMT +
		           OO.PRE_PNT_DC_AMT)                 AS TOT_DC_AMT        /*총할인금액*/
		     , SUM(OO.CPN1_DC_AMT)                    AS CPN1_DC_AMT       /*즉시할인쿠폰금액*/
		     , (SELECT GROUP_CONCAT(DISTINCT CONCAT('쿠폰번호 : ',CPN_ID,' / ',CPN_NM) SEPARATOR '!@!') AS CPN_DESC
		        FROM   TB_COUPON
		        WHERE  CPN_ID IN (SELECT DISTINCT CPN1_CPN_SQ FROM ORIGINAL_ORD)
		       )                                      AS CPN1_CPN_DC_DESC  /*즉시할인쿠폰설명*/
		     , SUM(OO.TMTB1_DC_AMT + OO.TMTB2_DC_AMT) AS TMTB_DC_AMT       /*다다익선인금액*/
		     , SUM(OO.TMTB1_DC_AMT)                   AS TMTB1_DC_AMT      /*다다익선수량할인금액*/
		     , (SELECT GROUP_CONCAT(DISTINCT CONCAT('프로모션번호 : ',TMTB_SQ,' / ',TMTB_NM) SEPARATOR '!@!') AS CPN_DESC
		        FROM   TB_TMTB
		        WHERE  TMTB_SQ IN (SELECT DISTINCT TMTB1_SQ FROM ORIGINAL_ORD)
		       )                                      AS TMTB1_DESC        /*다다익선수량할인설명*/
		     , SUM(OO.TMTB2_DC_AMT)                   AS TMTB2_DC_AMT      /*다다익선금액할인금액*/
		     , (SELECT GROUP_CONCAT(DISTINCT CONCAT('프로모션번호 : ',TMTB_SQ,' / ',TMTB_NM) SEPARATOR '!@!') AS CPN_DESC
		        FROM   TB_TMTB
		        WHERE  TMTB_SQ IN (SELECT DISTINCT TMTB2_SQ FROM ORIGINAL_ORD)
		       )                                      AS TMTB2_DESC        /*다다익선금액할인설명*/
		     , SUM(OO.GOODS_CPN_DC_AMT)               AS GOODS_CPN_DC_AMT  /*상품쿠폰할인금액*/
		     , (SELECT GROUP_CONCAT(DISTINCT CONCAT('쿠폰번호 : ',C.CPN_ID,' / ',C.CPN_NM) SEPARATOR '!@!') AS CPN_DESC
		        FROM   TB_CUST_COUPON CC
		        INNER JOIN TB_COUPON C ON CC.CPN_ID = C.CPN_ID
		        WHERE  CC.CUST_CPN_SQ IN (SELECT DISTINCT GOODS_CPN_SQ FROM ORIGINAL_ORD)
		       )                                      AS GOODS_CPN_DC_DESC /*상품쿠폰할인설명*/
		     , SUM(OO.CART_CPN_DC_AMT)                AS CART_CPN_DC_AMT   /*장바구니쿠폰할인금액*/
		     , (SELECT CONCAT('쿠폰번호 : ',C.CPN_ID,' / ',C.CPN_NM,
		                      ' / 구매금액 ',
		                      CASE WHEN C.BUY_LIMIT_AMT = 0 THEN '제한없음'
		                           ELSE CONCAT(FORMAT(C.BUY_LIMIT_AMT,0),'원 이상')
		                      END,
		                      ' / ',
		                      FORMAT(C.DC_PVAL,0),
		                      CASE WHEN C.DC_WAY = 'G240_10' THEN '원'
		                           ELSE '%'
		                      END,
		                      ' 할인 / 최대할인 ',
		                      CASE WHEN C.MAX_DC_AMT = 0 THEN '제한없음'
		                           ELSE CONCAT(FORMAT(C.MAX_DC_AMT,0),'원')
		                      END
		                     ) AS CPN_DESC
		        FROM   TB_CUST_COUPON CC
		        INNER JOIN TB_COUPON C ON CC.CPN_ID = C.CPN_ID
		        WHERE  CC.CUST_CPN_SQ IN (SELECT DISTINCT CART_CPN_SQ FROM ORIGINAL_ORD)
		       )                                      AS CART_CPN_DC_DESC   /*장바구니쿠폰할인설명*/
		     , SUM(OO.PRE_PNT_DC_AMT)                 AS PRE_PNT_DC_AMT     /*선포인트할인금액*/
		     , SUM(OO.ORD_CURR_AMT)
		       + IFNULL((SELECT SUM(REAL_DELV_AMT)
		                 FROM   ORIGINAL_DELV_FEE
		                ),0)
		       - SUM(OO.CPN1_DC_AMT +
		             OO.TMTB1_DC_AMT + OO.TMTB2_DC_AMT +
		             OO.GOODS_CPN_DC_AMT + OO.CART_CPN_DC_AMT +
		             OO.PRE_PNT_DC_AMT)               AS TOT_PAY_AMT        /*총결제금액*/
		     , SUM(OO.REAL_ORD_AMT)
		       + IFNULL((SELECT SUM(REAL_DELV_AMT)
		                 FROM   ORIGINAL_DELV_FEE
		                ),0)                          AS REAL_ORD_AMT       /*실결제금액*/
		     , MAX(P.PAY_MEANS_NM)                    AS PAY_MEANS_NM       /*결제수단명*/
		     , MAX(P.PAY_MEANS_DESC)                  AS PAY_MEANS_DESC     /*결제수단설명*/
		     , SUM(OO.GFCD_USE_AMT)                   AS GFCD_USE_AMT       /*상품권사용금액*/
		     , (SELECT GROUP_CONCAT(GFCD_USE_DESC SEPARATOR '!@!') AS GFCD_USE_DESC
		        FROM   (
		                SELECT CONCAT(FORMAT(SUM(CGH.GFCD_AMT),0),'원 / ',CG.GFCD_NO) AS GFCD_USE_DESC
		                FROM   TB_CUST_GIFTCARD_HST CGH
		                INNER JOIN TB_CUST_GIFTCARD CG ON CGH.CUST_GFCD_SQ = CG.CUST_GFCD_SQ
		                WHERE  CGH.ORD_NO = OO.ORD_NO
		                AND    CGH.OCCUR_GB = 'G074_12' /*상품권사용*/
		                GROUP  BY CG.GFCD_NO
		               ) Z
		       )                                      AS GFCD_USE_DESC      /*상품권사용설명*/
		     , SUM(OO.PNT_DC_AMT)                     AS PNT_DC_AMT         /*포인트할인금액*/
		     , MAX(P.PG_CPN_AMT)                      AS PG_CPN_AMT         /*PG쿠폰금액(KCP쿠폰금액)*/
		     , MAX(P.NPAY_PNT_AMT)                    AS NPAY_PNT_AMT       /*네이버페이포인트금액(마일리지)*/
		     , MAX(P.NPAY_PNT_DESC)                   AS NPAY_PNT_DESC      /*네이버포인트(마일리지)설명*/
		     , SUM(OO.SAVE_PNT_AMT)                   AS SAVE_PNT_AMT       /*적립포인트금액*/
		     , MAX(P.CASH_RECEIP_REQ_YN)              AS CASH_RECEIP_REQ_YN /*현금영수증신청여부*/
		FROM   ORIGINAL_ORD OO
		INNER JOIN TB_ORDER O ON OO.ORD_NO = O.ORD_NO
		INNER JOIN ORIGINAL_PAYMENT P ON OO.ORD_NO = P.ORD_NO
		GROUP  BY OO.ORD_NO
	</select>

	<!-- 주문상세 > 주문상품상세 목록 -->
	<select id="getOrderDetailList" parameterType="Order" resultType="Order">
		/* order.getOrderDetailList */
		SELECT A.ORD_NO
		     , A.ORD_EXCH_GB
		     , A.EXCH_GB_NM
		     , A.ORD_DTL_NO
		     , A.GOODS_CD
		     , A.GOODS_NM
		     , A.GOODS_TYPE
		     , A.GOODS_TYPE_NM
		     , A.SYS_IMG_NM
		     , A.BRAND_ENM
		     , GROUP_CONCAT(A.ITEM_NM ORDER BY A.ORD_DTL_ITEM_SQ SEPARATOR '!@!') AS ITEM_NM
		     , GROUP_CONCAT(A.ITEM_CD ORDER BY A.ORD_DTL_ITEM_SQ) AS ITEM_CD
		     , 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
		     , A.ORD_QTY
		     , A.CNCL_RTN_QTY
		     , A.ORD_REQ_CHG_QTY
		     , A.CANCEL_REQUEST_QTY
		     , A.EXCHANGE_REQUEST_QTY
		     , A.RETURN_REQUEST_QTY
		     , SUM(A.OPT_ADD_PRICE) AS OPT_ADD_PRICE
		     , A.CPN1_DC_AMT
		     , A.GOODS_CPN_DC_AMT
		     , A.CART_CPN_DC_AMT
		     , A.TMTB1_DC_AMT
		     , A.TMTB2_DC_AMT
		     , A.PNT_DC_AMT
		     , A.PRE_PNT_DC_AMT
		     , A.SAVE_PNT_AMT
		     , A.GFCD_USE_AMT
		     , A.ORD_AMT
		     , A.REAL_ORD_AMT
		     , A.CNCL_RTN_AMT
		     , A.ORD_DTL_STAT
		     , A.ORD_DTL_STAT_NM
		     , A.SOLDOUT_YN
		     , A.SOLDOUT_REG_NO
		     , A.SOLDOUT_MEMO
		     , A.INVOICE_NO
		     , A.DELV_LOC_CD
		     , A.DELV_ADDR_SQ
		     , A.RETURNABLE_YN
		     , A.CHANGEABLE_YN
		     , A.DELV_FEE_CD
		     , A.DELV_FEE_CD_GRP
		     , A.BRAND_GROUP_NM
		     , A.SHIP_COMP_CD
		     , A.SHIP_COMP_NM
		     , A.DELV_LOC_NM
		     , A.PG_GB
		     , A.SUPPLY_COMP_NM
		     , A.ORD_CHG_SQ
		     , A.SHOT_DELV_GB
		     , A.CS_CHARGE_NM
		FROM (
		    SELECT OD.ORD_NO
		         , OD.ORD_EXCH_GB
		         , CASE WHEN OD.ORD_EXCH_GB = 'O'
		                THEN '주문'
		                ELSE '교환'
		           END		                      EXCH_GB_NM
		         , OD.ORD_DTL_NO
		         , ODI.ORD_DTL_ITEM_SQ
		         , G1.GOODS_CD
		         , FN_GET_GOODS_NM(G1.GOODS_NM, G1.GOODS_GB, G1.FOREIGN_BUY_YN, G1.PARALLEL_IMPORT_YN, G1.ORDER_MADE_YN) AS GOODS_NM
		         , G1.GOODS_TYPE
		         , FN_GET_CODE_NM('G056', G1.GOODS_TYPE)   AS GOODS_TYPE_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 = 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
		         , G1.BRAND_CD
		         , (SELECT Z.BRAND_ENM
		            FROM   TB_BRAND Z
		            WHERE  Z.BRAND_CD = G1.BRAND_CD) AS BRAND_ENM
		         , G2.GOODS_CD                             AS ITEM_CD
		         , G2.GOODS_NM                             AS ITEM_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
		         , ODI.OPT_CD
		         , ODI.OPT_CD1
		         , ODI.OPT_CD2
		         , ODI.ITEM_QTY
		         , ODI.ITEM_PRICE
		         , OD.LIST_PRICE
		         , OD.CURR_PRICE
		         , OD.ORD_QTY
		         , OD.CNCL_RTN_QTY
		         , CASE WHEN OCD.ORD_REQ_CHG_QTY IS NULL
		                     THEN 0
		                 ELSE OCD.ORD_REQ_CHG_QTY
		           END		                   AS ORD_REQ_CHG_QTY
		         , CASE WHEN OCD.CANCEL_REQUEST_QTY IS NULL
		                     THEN 0
		                ELSE OCD.CANCEL_REQUEST_QTY
		           END		                   AS CANCEL_REQUEST_QTY
		         , CASE WHEN OCD.EXCHANGE_REQUEST_QTY IS NULL
		                     THEN 0
		                ELSE OCD.EXCHANGE_REQUEST_QTY
		           END		                   AS EXCHANGE_REQUEST_QTY
		         , CASE WHEN OCD.RETURN_REQUEST_QTY IS NULL
		                     THEN 0
		                ELSE OCD.RETURN_REQUEST_QTY
		           END		                   AS RETURN_REQUEST_QTY
		         , ODI.OPT_ADD_PRICE
		         , OD.CPN1_DC_AMT
		         , OD.GOODS_CPN_DC_AMT
		         , OD.CART_CPN_DC_AMT
		         , OD.TMTB1_DC_AMT
		         , OD.TMTB2_DC_AMT
		         , OD.PNT_DC_AMT
		         , OD.PRE_PNT_DC_AMT
		         , OD.SAVE_PNT_AMT
		         , OD.GFCD_USE_AMT
		         , OD.ORD_AMT
		         , OD.REAL_ORD_AMT
		         , OD.CNCL_RTN_AMT
		         , OD.ORD_DTL_STAT
		         , FN_GET_CODE_NM('G013', OD.ORD_DTL_STAT) AS ORD_DTL_STAT_NM
		         , OD.SOLDOUT_YN
		         , OD.SOLDOUT_REG_NO
		         , OD.SOLDOUT_MEMO
		         , OD.INVOICE_NO
		         , OD.DELV_LOC_CD
		         , OD.DELV_ADDR_SQ
		         , OD.RETURNABLE_YN
		         , OD.CHANGEABLE_YN
		         , OD.DELV_FEE_CD
		         , CASE WHEN G1.SELF_GOODS_YN = 'Y'
		                THEN 'WMS'
		                ELSE OD.DELV_FEE_CD
		                END  DELV_FEE_CD_GRP
		         , CASE WHEN BG.DISP_NM_LANG = 'EN'
		                THEN BG.BRAND_GROUP_ENM
		                ELSE BG.BRAND_GROUP_KNM
		                END  BRAND_GROUP_NM
		         , OD.SHIP_COMP_CD
		         , (SELECT SHIP_COMP_NM
		            FROM   TB_SHIP_COMPANY SC
		            WHERE  SC.SHIP_COMP_CD = OD.SHIP_COMP_CD) AS SHIP_COMP_NM
		         , (SELECT DL.DELV_LOC_NM
		            FROM   TB_DELIVERY_LOC DL
		            WHERE  DL.DELV_LOC_CD = OD.DELV_LOC_CD
		            AND    DL.USE_YN = 'Y'
		            LIMIT  1) AS DELV_LOC_NM
		         , P.PG_GB
		         , (SELECT Z.SUPPLY_COMP_NM
		            FROM   TB_SUPPLY_COMPANY Z
		            WHERE  Z.SUPPLY_COMP_CD = OD.SUPPLY_COMP_CD) AS SUPPLY_COMP_NM
		         , OCD2.ORD_CHG_SQ
		         , CASE WHEN OD.SHOT_DELV_YN = 'Y' THEN '당일'
		                ELSE
		                    CASE WHEN OD.DELV_FEE_CD = 'WMS' THEN '일반'
		                         ELSE '업체'
		                    END
		           END AS SHOT_DELV_GB /*총알배송구분*/
		         , (SELECT CONCAT(CS_CHARGE_NM,IF(CS_CHARGE_TELNO IS NULL,'',' / '),CS_CHARGE_TELNO)
		            FROM   TB_SUPPLY_COMPANY
		            WHERE  SUPPLY_COMP_CD = OD.SUPPLY_COMP_CD) AS CS_CHARGE_NM
		      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_BRAND B
		        ON B.BRAND_CD = G1.BRAND_CD
		     INNER JOIN TB_BRAND_GROUP BG
		        ON B.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		       AND BG.USE_YN = 'Y'
		     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
		     INNER JOIN TB_PAYMENT P
		        ON O.ORD_NO = P.ORD_NO
		       AND P.PAY_GB = 'O'
		       AND P.PAY_STAT IN ('G016_10', 'G016_30')
		     INNER JOIN TB_DELIVERY_ADDR DA
		        ON OD.DELV_ADDR_SQ = DA.DELV_ADDR_SQ
		      LEFT OUTER JOIN (SELECT OD.ORD_DTL_NO
		                       , SUM(CASE OC.WD_BF_SEND_YN WHEN 'Y' THEN 0
				                                 ELSE OCD.CHG_QTY
				                 END)		                  AS ORD_REQ_CHG_QTY
		                       , SUM(CASE OCD.CHG_STAT WHEN 'G685_10' THEN OCD.CHG_QTY
				                             WHEN 'G685_11' THEN OCD.CHG_QTY
				                             ELSE 0
				                 END)		                  AS CANCEL_REQUEST_QTY
		                       , SUM(CASE WHEN OCD.CHG_STAT = 'G685_20' THEN OCD.CHG_QTY
				                     WHEN OCD.CHG_STAT = 'G685_21' THEN OCD.CHG_QTY
				                     WHEN OCD.CHG_STAT = 'G685_30' AND OC.CHG_GB = 'G680_40' THEN OCD.CHG_QTY
				                     WHEN OCD.CHG_STAT = 'G685_31' AND OC.CHG_GB = 'G680_40' THEN OCD.CHG_QTY
				                     WHEN OCD.CHG_STAT = 'G685_32' AND OC.CHG_GB = 'G680_40' THEN OCD.CHG_QTY
				                     ELSE 0
				                 END)		                  AS EXCHANGE_REQUEST_QTY
		                       , SUM(CASE WHEN OCD.CHG_STAT = 'G685_50' THEN OCD.CHG_QTY
				                     WHEN OCD.CHG_STAT = 'G685_51' THEN OCD.CHG_QTY
				                     WHEN OCD.CHG_STAT = 'G685_33' THEN OCD.CHG_QTY
				                     WHEN OCD.CHG_STAT = 'G685_30' AND OC.CHG_GB = 'G680_30' THEN OCD.CHG_QTY
				                     WHEN OCD.CHG_STAT = 'G685_31' AND OC.CHG_GB = 'G680_30' THEN OCD.CHG_QTY
				                     WHEN OCD.CHG_STAT = 'G685_32' AND OC.CHG_GB = 'G680_30' THEN OCD.CHG_QTY
				                     ELSE 0
				                END)		                   AS RETURN_REQUEST_QTY
		                    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
		                   WHERE 1 = 1
		                     AND OD.ORD_NO = #{ordNo}
		                     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 OCD.DEL_YN = 'N'
		                   GROUP BY OCD.ORD_DTL_NO
		                      ) OCD
		        ON OD.ORD_DTL_NO = OCD.ORD_DTL_NO
		      LEFT OUTER JOIN TB_ORDER_CHANGE_DETAIL OCD2
		        ON OD.ORD_DTL_NO = OCD2.CHG_ORD_DTL_NO
		       AND OCD2.DEL_YN = 'N'
		     WHERE 1 = 1
		       AND OD.ORD_NO = #{ordNo}
		       AND OD.ORD_DTL_STAT NOT IN ('G013_00', 'G013_25', 'G013_97')
		) A
		GROUP  BY A.ORD_NO
		     , A.ORD_EXCH_GB
		     , A.EXCH_GB_NM
		     , A.ORD_DTL_NO
		     , A.GOODS_CD
		     , A.GOODS_NM
		     , A.GOODS_TYPE
		     , A.GOODS_TYPE_NM
		     , A.SYS_IMG_NM
		     , A.BRAND_ENM
		     , A.LIST_PRICE
		     , A.CURR_PRICE
		     , A.ORD_QTY
		     , A.CNCL_RTN_QTY
		     , A.ORD_REQ_CHG_QTY
		     , A.CANCEL_REQUEST_QTY
		     , A.EXCHANGE_REQUEST_QTY
		     , A.RETURN_REQUEST_QTY
		     , A.CPN1_DC_AMT
		     , A.GOODS_CPN_DC_AMT
		     , A.CART_CPN_DC_AMT
		     , A.TMTB1_DC_AMT
		     , A.TMTB2_DC_AMT
		     , A.PNT_DC_AMT
		     , A.PRE_PNT_DC_AMT
		     , A.SAVE_PNT_AMT
		     , A.GFCD_USE_AMT
		     , A.ORD_AMT
		     , A.REAL_ORD_AMT
		     , A.CNCL_RTN_AMT
		     , A.ORD_DTL_STAT
		     , A.ORD_DTL_STAT_NM
		     , A.SOLDOUT_YN
		     , A.SOLDOUT_REG_NO
		     , A.SOLDOUT_MEMO
		     , A.INVOICE_NO
		     , A.DELV_LOC_CD
		     , A.DELV_ADDR_SQ
		     , A.RETURNABLE_YN
		     , A.CHANGEABLE_YN
		     , A.DELV_FEE_CD
		     , A.DELV_FEE_CD_GRP
		     , A.BRAND_GROUP_NM
		     , A.SHIP_COMP_CD
		     , A.SHIP_COMP_NM
		     , A.DELV_LOC_NM
		     , A.PG_GB
		     , A.SUPPLY_COMP_NM
		     , A.ORD_CHG_SQ
		     , A.SHOT_DELV_GB
		     , A.CS_CHARGE_NM
		 ORDER BY A.ORD_NO
		     , A.ORD_DTL_NO
	</select>

	<!-- 주문상세 > 사은품목록 -->
	<select id="getOrderFreeGiftList" parameterType="Order" resultType="Order">
		/* order.getOrderFreeGiftList */
		SELECT OFV.ORD_FREEGIFT_SQ
		     , OFV.ORD_NO
		     , OFV.FREEGIFT_SQ
		     , FG.FREEGIFT_NM
		     , OFV.FREEGIFT_VAL_SQ
		     , OFV.USE_POINT
		     , OFV.PRODUCT_NO
		     , G.GOODS_NM AS ITEM_NM
		     , OFV.ITEM_QTY
		     , OFV.DEL_YN
		     , FG.ALL_YN
		  FROM TB_ORD_FREEGIFT_VAL OFV
		 INNER JOIN TB_FREEGIFT FG
		    ON OFV.FREEGIFT_SQ = FG.FREEGIFT_SQ
		 INNER JOIN TB_FREE_GOODS G
		    ON OFV.PRODUCT_NO = G.PRODUCT_NO
		 WHERE 1 = 1
		   AND OFV.ORD_NO = #{ordNo}
		 ORDER BY OFV.REG_DT DESC
	</select>

	<!-- 주문상세 > 배송정보 -->
	<select id="getDeliveryAddrList" parameterType="Order" resultType="Order">
		/* order.getDeliveryAddrList */
		SELECT Z.DELV_ADDR_SQ
		     , Z.GIFT_PACK_YN
		     , Z.GIFT_ADDR_INP_YN
		     , Z.EXCH_GB_NM
		     , Z.GIFT_LIMIT_DT
		     , Z.RECIP_NM
		     , Z.RECIP_PHNNO
		     , Z.RECIP_TELNO
		     , Z.RECIP_ZIPCODE
		     , Z.RECIP_BASE_ADDR
		     , Z.RECIP_DTL_ADDR
		     , Z.ORD_EMAIL
		     , Z.DELV_MEMO
		     , Z.GIFT_MSG
		     , Z.ORD_NO
		  FROM (SELECT OD.DELV_ADDR_SQ
		             , OD.ORD_EXCH_GB
		             , OD.GIFT_PACK_YN
		             , OD.GIFT_ADDR_INP_YN
		             , CASE WHEN OD.ORD_EXCH_GB = 'O' AND OD.GIFT_PACK_YN = 'Y' THEN '선물'
		                    WHEN OD.ORD_EXCH_GB = 'O' AND OD.GIFT_PACK_YN = 'N' THEN '주문'
		                    ELSE '교환'
		               END EXCH_GB_NM
		             , CASE WHEN OD.GIFT_PACK_YN = 'Y' AND OD.GIFT_ADDR_INP_YN = 'N' THEN O.ORD_DT + INTERVAL 3 DAY
		                    ELSE DA.UPD_DT
		                END AS GIFT_LIMIT_DT
		             , DA.RECIP_NM
		             , DA.RECIP_PHNNO
		             , DA.RECIP_TELNO
		             , DA.RECIP_ZIPCODE
		             , DA.RECIP_BASE_ADDR
		             , DA.RECIP_DTL_ADDR
		             , O.ORD_EMAIL
		             , DA.DELV_MEMO
		             , DA.GIFT_MSG
		             , OD.ORD_NO
		          FROM TB_ORDER_DETAIL OD
		         INNER JOIN TB_ORDER O
		            ON OD.ORD_NO = O.ORD_NO
		         INNER JOIN TB_DELIVERY_ADDR DA
		            ON OD.DELV_ADDR_SQ = DA.DELV_ADDR_SQ
		         WHERE 1 = 1
		           AND OD.ORD_NO = #{ordNo}
		           AND OD.ORD_DTL_STAT <![CDATA[<>]]> 'G013_97'			-- 교환철회 상품 제외
		       ) Z
		 GROUP BY Z.DELV_ADDR_SQ
		     , Z.GIFT_PACK_YN
		     , Z.GIFT_ADDR_INP_YN
		     , Z.EXCH_GB_NM
		     , Z.GIFT_LIMIT_DT
		     , Z.RECIP_NM
		     , Z.RECIP_PHNNO
		     , Z.RECIP_TELNO
		     , Z.RECIP_ZIPCODE
		     , Z.RECIP_BASE_ADDR
		     , Z.RECIP_DTL_ADDR
		     , Z.ORD_EMAIL
		     , Z.DELV_MEMO
		     , Z.GIFT_MSG
		     , Z.ORD_NO
		 ORDER BY Z.DELV_ADDR_SQ
	</select>

	<!-- 주문상세 > 결제정보 -->
	<select id="getOrderPaymentBasicInfoList" parameterType="Order" resultType="Order">
		/* order.getOrderPaymentBasicInfoList */
		SELECT P.ESCROW_YN
		     , CASE WHEN O.MALL_GB IN ('G011_20')
		            THEN ''
		            ELSE P.PG_GB
		            END PG_GB
		     , CASE WHEN O.MALL_GB IN ('G011_20')
		            THEN ''
		            ELSE P.PAY_MEANS
		            END  PAY_MEANS
		     , CASE WHEN O.MALL_GB IN ('G011_20')
		            THEN ''
		            ELSE FN_GET_CODE_NM('G014', P.PAY_MEANS)
		            END  PAY_MEANS_NM
		     , CASE WHEN P.PAY_MEANS IN ('G014_20')
		            THEN P.VA_BANK
		            ELSE ''
		            END  VA_BANK
		     , CASE WHEN P.PAY_MEANS = 'G014_20' THEN FN_GET_CODE_NM('G940', P.VA_BANK)
		            WHEN P.PAY_MEANS = 'G014_10' THEN ''
		            ELSE P.CARD_NM
		        END		                    CARD_NM
		     , P.PG_TRADE_NO
		     , P.PG_TID
		     , P.VA_NO
		     , P.VA_NM
		     , DATE_FORMAT(P.PAY_DT, '%Y%m%d%H%i%S')      AS PAY_DT
		     , P.PAY_STAT
		     , FN_GET_CODE_NM('G016', P.PAY_STAT)         AS PAY_STAT_NM
		     , P.PAY_AMT
		     , P.PG_CPN_AMT
		     , P.NPAY_PNT_AMT
		     , DATE_FORMAT(P.VA_DEADLINE, '%Y-%m-%d') AS VA_DEADLINE
		     , CARD_MIPS
		     , CARD_TYPE
		     , CASH_AUTH_NO
		     , CASH_TRADE_NO
		  FROM TB_PAYMENT P
		 INNER JOIN TB_ORDER O
		    ON P.ORD_NO = O.ORD_NO
		 WHERE 1 = 1
		   AND P.ORD_NO = #{ordNo}
		   AND P.PAY_STAT IN ('G016_30', 'G016_10')
		 ORDER BY P.REG_DT
	</select>

	<!-- 주문상세 > 배송비정보 -->
	<select id="getDeliveryFeeList" parameterType="Order" resultType="Order">
		/* order.getDeliveryFeeList */
		SELECT Z.*
		  FROM (
		        SELECT DF.DELV_FEE_GB
		             , FN_GET_CODE_NM('G018', DF.DELV_FEE_GB)       AS DELV_FEE_GB_NM
		             , DF.DELV_FEE
		             , DF.REAL_DELV_AMT
		             , DF.DELV_USAC_YN
		             , DATE_FORMAT(DF.DELV_USAC_DT, '%Y%m%d%H%i%S') AS DELV_USAC_DT
		             , DF.SUPPLY_COMP_CD
		             , DF.DELV_FEE_SQ
		             , DF.DELV_CPN_SQ
		             , DF.DELV_CPN_DC_AMT
		             , DF.DELV_GFCD_USE_AMT
		             , DF.DELV_FEE_CD
		             , CASE WHEN DF.DELV_FEE_CD IN ('WMS')
		                    THEN '자사'
		                    ELSE (SELECT SUPPLY_COMP_NM FROM TB_SUPPLY_COMPANY X WHERE X.SUPPLY_COMP_CD = DF.SUPPLY_COMP_CD)
		                    END  SUPPLY_COMP_NM
		          FROM TB_DELIVERY_FEE DF
		         WHERE 1 = 1
		           AND DF.ORD_NO = #{ordNo}
		           AND DF.DELV_FEE_GB = 'G018_10'
		        UNION  ALL
		        SELECT DF.DELV_FEE_GB
		             , FN_GET_CODE_NM('G018', DF.DELV_FEE_GB)       AS DELV_FEE_GB_NM
		             , DF.DELV_FEE
		             , DF.REAL_DELV_AMT
		             , DF.DELV_USAC_YN
		             , DATE_FORMAT(DF.DELV_USAC_DT, '%Y%m%d%H%i%S') AS DELV_USAC_DT
		             , DF.SUPPLY_COMP_CD
		             , DF.DELV_FEE_SQ
		             , DF.DELV_CPN_SQ
		             , DF.DELV_CPN_DC_AMT
		             , DF.DELV_GFCD_USE_AMT
		             , DF.DELV_FEE_CD
		             , CASE WHEN DF.DELV_FEE_CD IN ('WMS')
		                    THEN '자사'
		                    ELSE (SELECT SUPPLY_COMP_NM FROM TB_SUPPLY_COMPANY X WHERE X.SUPPLY_COMP_CD = DF.SUPPLY_COMP_CD)
		                    END  SUPPLY_COMP_NM
		          FROM TB_DELIVERY_FEE DF
		         WHERE 1 = 1
		           AND DF.ORD_NO = #{ordNo}
		           AND EXISTS (SELECT 1
		                        FROM TB_ORDER_CHANGE OC
		                       WHERE DF.ORD_CHG_SQ = OC.ORD_CHG_SQ
		                         AND OC.CHG_GB IN ('G680_30', 'G680_40'))
		  ) Z
		 GROUP BY Z.DELV_FEE_GB
		        , Z.DELV_FEE_GB_NM
		        , Z.DELV_FEE
		        , Z.REAL_DELV_AMT
		        , Z.DELV_USAC_YN
		        , Z.DELV_USAC_DT
		        , Z.SUPPLY_COMP_CD
		        , Z.SUPPLY_COMP_NM
		        , Z.DELV_FEE_SQ
		        , Z.DELV_CPN_SQ
		        , Z.DELV_CPN_DC_AMT
		        , Z.DELV_GFCD_USE_AMT
		        , Z.DELV_FEE_CD
	</select>

	<!-- 주문상세 > 취소/반품/교환 요청정보 (변경상세단위) -->
	<select id="getOrderChangeList" parameterType="Order" resultType="Order">
		/* order.getOrderChangeList */
		SELECT OCD.ORD_CHG_SQ
		     , OC.CHG_GB
		     , FN_GET_CODE_NM('G680', OC.CHG_GB)       AS CHG_GB_NM
		     , OD.GOODS_CD
		     , G.GOODS_TYPE
		     , FN_GET_CODE_NM('G056', G.GOODS_TYPE)    AS GOODS_TYPE_NM
--		     , IFNULL((SELECT COLOR_KNM FROM TB_COLOR WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,''), G.MAIN_COLOR_CD) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		     , ODI.OPT_CD
		     , 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
		     , OC.CHG_MEMO
		     , OC.CHGER_NM
		     , OC.CHGER_PHNNO
		     , OC.CHGER_ZIPCODE
		     , OC.CHGER_BASE_ADDR
		     , OC.CHGER_DTL_ADDR
		     , OC.WD_INVOICE_SEND_YN
		     , OC.WD_INVOICE_NO
		     , OC.WD_GB
		     , OD.ORD_NO
		     , OD.ORD_DTL_NO
		     , OD.DELV_FEE_CD
		     , CASE WHEN G.SELF_GOODS_YN = 'Y'
		            THEN 'WMS'
		            ELSE OD.DELV_FEE_CD
		            END  DELV_FEE_CD_GRP
		     , OC.SHIP_COMP_CD
		     , (SELECT COUNT(1)
		        FROM   TB_ORDER_DETAIL_ITEM_HST X
		        WHERE  X.ORD_DTL_NO = OCD.ORD_DTL_NO) AS CHG_ITEM_CNT
		     , CONCAT(CASE WHEN OC.REG_NO = 0 THEN '비회원'
					WHEN OC.REG_NO = 99999 THEN '배치'
					ELSE (IFNULL((SELECT CONCAT(USER_NM,
										' / ',USER_ID)
						  FROM   TB_USER
						  WHERE  USER_NO = OC.REG_NO),'회원'
						 ))
			   END,' / ',DATE_FORMAT(OC.REG_DT,'%Y-%m-%d %H:%i:%S'))  AS REG_NM /*신청(접수)자정보*/
		  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 TB_GOODS G
		    ON G.GOODS_CD = OD.GOODS_CD
		 INNER JOIN (
		      SELECT X.ORD_DTL_NO
		           , GROUP_CONCAT(X.ITEM_CD ORDER BY X.ORD_DTL_ITEM_SQ) AS ITEM_CD
		           , GROUP_CONCAT(X.OPT_CD ORDER BY X.ORD_DTL_ITEM_SQ) AS OPT_CD
		           , GROUP_CONCAT(X.OPT_CD1 ORDER BY X.ORD_DTL_ITEM_SQ) AS OPT_CD1
		           , GROUP_CONCAT(X.OPT_CD2 ORDER BY X.ORD_DTL_ITEM_SQ) AS OPT_CD2
		        FROM TB_ORDER_DETAIL_ITEM X
		       WHERE X.ORD_NO = #{ordNo}
		       GROUP BY X.ORD_DTL_NO
		 ) ODI
		    ON OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		 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>

	<!-- 주문상세 > 환불정보 -->
	<select id="getOrderRefundInfo" parameterType="Order" resultType="Order">
		/* order.getOrderRefundInfo */
		SELECT A.ORD_CHG_SQ
		     , A.PAY_MEANS
		     , A.PAY_MEANS_NM
		     , A.RA_BANK
		     , A.CARD_NM
		     , A.RA_NO
		     , A.RA_NM
		     , A.REFUND_AMT
		     , A.UPD_DT
		     , A.USER_ID
		     , A.CUST_ID
		     , A.REG_DT
		  FROM (SELECT R.ORD_CHG_SQ
		             , P.PAY_MEANS
		             , FN_GET_CODE_NM('G014', P.PAY_MEANS)      AS PAY_MEANS_NM
		             , R.RA_BANK
		             , CASE WHEN PAY_MEANS = 'G014_20' || PAY_MEANS = 'G014_10'
		                        THEN FN_GET_CODE_NM('G940', R.RA_BANK)
		                    ELSE P.CARD_NM
		               END                                      AS CARD_NM
		             , R.RA_NO
		             , R.RA_NM
		             , R.REFUND_AMT
		             , DATE_FORMAT(P.UPD_DT, '%Y%m%d%H%i%S')    AS UPD_DT
		             , (SELECT USER_ID
		                  FROM TB_USER X
		                 WHERE X.USER_NO = P.UPD_NO
		               )		                                AS USER_ID
		             , (SELECT CUST_ID
		                  FROM TB_CUSTOMER X
		                 WHERE X.CUST_NO = P.UPD_NO
		               )		                                AS CUST_ID
		             , P.REG_DT
		          FROM TB_REFUND R
		         INNER JOIN TB_PAYMENT P
		            ON R.PAY_SQ = P.PAY_SQ
		         WHERE 1 = 1
		           AND R.ORD_NO = #{ordNo}
		           AND P.PAY_STAT IN ('G016_98', 'G016_99')
		         UNION ALL
		        SELECT P2.ORD_CHG_SQ
		             , P2.PAY_MEANS
		             , FN_GET_CODE_NM('G014', P2.PAY_MEANS)     AS PAY_MEANS_NM
		             , NULL
		             , P2.CARD_NM
		             , NULL
		             , NULL
		             , P2.PAY_AMT * -1                          AS PAY_AMT
		             , DATE_FORMAT(P2.UPD_DT, '%Y%m%d%H%i%S')   AS UPD_DT
		             , (SELECT USER_ID
		                  FROM TB_USER X
		                 WHERE X.USER_NO = P2.UPD_NO)           AS USER_ID
		             , (SELECT CUST_ID
		                  FROM TB_CUSTOMER X
		                 WHERE X.CUST_NO = P2.UPD_NO)           AS CUST_ID
		             , P2.REG_DT
		          FROM TB_PAYMENT P2
		         WHERE P2.PAY_GB = 'D'
		           AND P2.PAY_STAT = 'G016_99'
		           AND P2.ORD_NO = #{ordNo}
		       ) A
		 ORDER BY A.REG_DT
	</select>

	<!-- 주문상세 > 상담내역 -->
	<select id="getOrderCounselInfo" parameterType="Order" resultType="Order">
		/* order.getOrderCounselInfo */
		SELECT CS.COUNSEL_CLSF
		     , FN_GET_CODE_NM('G059', CS.COUNSEL_CLSF)  AS COUNSEL_CLSF_NM
		     , CS.REL_GOODS_CD
		     , CS.QUEST_TITLE
		     , DATE_FORMAT(CS.QUEST_DT, '%Y%m%d%H%i%S') AS QUEST_DT
		     , DATE_FORMAT(CS.ANS_DT, '%Y%m%d%H%i%S')   AS ANS_DT
		     , CS.ANS_NO
		     , (SELECT USER_NM
		          FROM TB_USER X
		         WHERE X.USER_NO = CS.ANS_NO)           AS ANS_NM
		     , CS.DEL_YN
		  FROM TB_COUNSEL CS
		 WHERE 1 = 1
		   AND CS.REL_ORD_NO = #{ordNo}
		 ORDER BY CS.REG_DT DESC
	</select>

	<!-- 주문상세 > 관리자메모 -->
	<select id="getOrderMemoList" parameterType="Order" resultType="Order">
		/* order.getOrderMemoList */
		SELECT ORD_MEMO_SQ
		     , OM.ORD_NO
		     , OM.MEMO
		     , OM.REG_NO
		     , OM.REG_DT
		     , OM.UPD_NO
		     , OM.UPD_DT
		     , (SELECT USER_NM
		          FROM TB_USER X
		         WHERE X.USER_NO = OM.REG_NO) AS REG_NM
		     , OM.SYS_FILE_NM
		     , OM.ORG_FILE_NM
		  FROM TB_ORDER_MEMO OM
		 WHERE 1 = 1
		   AND OM.ORD_NO = #{ordNo}
		   AND OM.DEL_YN = #{delYn}
		 ORDER BY OM.REG_DT DESC
	</select>

	<!-- 네이버페이 주문번호 저장 -->
	<update id="updateNaverPayOrderNo" parameterType="Order">
		/* TscOrder.updateNaverPayOrderNo */
		UPDATE TB_ORDER SET
		       PAY_DT      = NOW()
		     , NPAY_ORD_NO = #{npayOrdNo}
		     , ORD_NM      = #{ordNm}
		     , ORD_PHNNO   = #{ordPhnno}
		     , ORD_EMAIL   = #{ordEmail}
		     , UPD_NO      = #{updNo}
		     , UPD_DT      = NOW()
		WHERE  ORD_NO      = #{ordNo}
		AND    IFNULL(NPAY_ORD_NO, 0) = 0
	</update>

	<!-- 주문/배송 > 입점업체 주문상세정보 변경 (입점) -->
	<update id="updateOrderDetailStat" parameterType="Order">
		/* TscOrder.updateOrderDetailStat */
		UPDATE TB_ORDER_DETAIL
		   SET ORD_DTL_STAT = #{ordDtlStat}
		     , UPD_NO       = #{updNo}
		     , UPD_DT       = NOW()
		 WHERE 1=1
		   AND ORD_DTL_NO =	 #{ordDtlNo}
	</update>

	<!-- 주문/배송 > 주문상세이력 생성-->
	<insert id="createOrderDetailHst" parameterType="Order">
		/* Order.createOrderDetailHst */
		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
		     , 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
		     , #{regNo}
		     , NOW()
		     , #{regNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL
		 WHERE ORD_DTL_NO = #{ordDtlNo}
	</insert>

	<!-- 주문상세아이템 이력 정보 등록 -->
	<insert id="createOrderDetailItemHstFromDtlNo" parameterType="Order">
		/* TscOrder.createOrderDetailItemHstFromDtlNo */
		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
			 , #{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_DTL_NO = #{ordDtlNo}
	</insert>

	<!-- 주문상세 > 주문메오 > 주문메모정보조회 -->
	<select id="getOrderMemoInfo" parameterType="Order" resultType="Order">
		/* TscOrder.getOrderMemoInfo */
		SELECT ORD_MEMO_SQ
		     , OM.ORD_NO
		     , OM.MEMO
		     , OM.REG_NO
		     , OM.REG_DT
		     , OM.UPD_NO
		     , OM.UPD_DT
		     , (SELECT USER_NM
		         FROM TB_USER X
		        WHERE X.USER_NO = OM.UPD_NO) AS USER_NM
		     , OM.SYS_FILE_NM
		     , OM.ORG_FILE_NM
		  FROM TB_ORDER_MEMO OM
		 WHERE 1 = 1
		   AND OM.ORD_MEMO_SQ = #{seq}
		   AND OM.ORD_NO = #{ordNo}
		   AND OM.DEL_YN = 'N'
	</select>

	<!-- 주문상세 > 주문요청 관리자 메모 > 메모등록 -->
	<insert id="createOrderMemo" parameterType="Order">
		/* order.createOrderMemo */
		INSERT INTO TB_ORDER_MEMO (
		    ORD_NO
		  , MEMO
		  , ORG_FILE_NM
		  , SYS_FILE_NM
		  , DEL_YN
		  , REG_NO
		  , REG_DT
		  , UPD_NO
		  , UPD_DT
		) VALUES (
		    #{ordNo}
		  , #{memo}
		  , #{orgFileNm}
		  , #{sysFileNm}
		  , 'N'
		  , #{regNo}
		  , NOW()
		  , #{updNo}
		  , NOW()
		)
	</insert>

	<!-- 주문상세 > 주문요청 관리자 메모 > 메모수정 -->
	<update id="updateOrderMemo" parameterType="Order">
		/* order.updateOrderMemo */
		UPDATE TB_ORDER_MEMO
		   SET MEMO   = #{memo}
		     , ORG_FILE_NM = #{orgFileNm}
		     , SYS_FILE_NM = #{sysFileNm}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		 WHERE 1 = 1
		   AND ORD_NO = #{ordNo}
		   AND ORD_MEMO_SQ = #{seq}
	</update>

	<!-- 주문상세 > 주문요청 관리자 메모 > 메모수정 -->
	<update id="deleteOrderMemo" parameterType="Order">
		/* order.deleteOrderMemo */
		UPDATE TB_ORDER_MEMO
		   SET DEL_YN = 'Y'
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		 WHERE 1 = 1
		   AND ORD_NO = #{ordNo}
		   AND ORD_MEMO_SQ = #{seq}
	</update>

	<!-- 주문상세 > 주문상품 상세 변경 이력 -->
	<select id="getOrderDetailHistoryList" parameterType="Order" resultType="Order">
		/* order.getOrderDetailHistoryList */
		SELECT Z.*
		FROM (
		    SELECT DATE_FORMAT(ODH.UPD_DT, '%Y%m%d%H%i%S')    AS UPD_DT
		         , 1 AS DISP_ORD
		         , (SELECT Z.USER_ID
		              FROM TB_USER Z
		             WHERE Z.USER_NO = ODH.UPD_NO)            AS USER_ID
		         , (SELECT Z.CUST_ID
		              FROM TB_CUSTOMER Z
		             WHERE Z.CUST_NO = ODH.UPD_NO)            AS CUST_ID
		         , FN_GET_CODE_NM('G013', ODH.ORD_DTL_STAT)   AS ORD_DTL_STAT_NM
		         , ODH.ORD_QTY
		         , ODH.CNCL_RTN_QTY
		         , ODH.DELV_LOC_CD
		         , ODH.INVOICE_NO
		         , ODH.SHIP_COMP_CD
		         , (SELECT SHIP_COMP_NM
		              FROM TB_SHIP_COMPANY Z
		             WHERE Z.SHIP_COMP_CD = ODH.SHIP_COMP_CD) AS SHIP_COMP_NM
		      FROM TB_ORDER_DETAIL_HST ODH
		     WHERE 1=1
		       AND ODH.ORD_DTL_NO =  #{ordDtlNo}
		     UNION ALL
		    SELECT DATE_FORMAT(OCDH.UPD_DT, '%Y%m%d%H%i%S')    AS UPD_DT
		         , 2 AS DISP_ORD
		         , (SELECT Z.USER_ID
		              FROM TB_USER Z
		             WHERE Z.USER_NO = OCDH.UPD_NO)            AS USER_ID
		         , (SELECT Z.CUST_ID
		              FROM TB_CUSTOMER Z
		             WHERE Z.CUST_NO = OCDH.UPD_NO)            AS CUST_ID
		         , FN_GET_CODE_NM('G685', OCDH.CHG_STAT)       AS ORD_DTL_STAT_NM
		         , 0 AS ORD_QTY
		         , OCDH.CHG_QTY
		         , NULL
		         , NULL
		         , NULL
		         , NULL
		      FROM TB_ORDER_CHANGE_DETAIL_HST OCDH
		     WHERE 1=1
		       AND OCDH.ORD_DTL_NO =  #{ordDtlNo}
		) Z
		 ORDER BY Z.UPD_DT DESC
		     , Z.DISP_ORD DESC

	</select>

	<!-- 주문상세 > 쿠폰사용내역 팝업 화면 -->
	<select id="getOrderDiscountCouponList" parameterType="Order" resultType="Order">
		/* order.getOrderDiscountCouponList */
		  WITH COUPON_DATA AS (
		      SELECT OD.ORD_NO
		           , OD.ORD_DTL_NO
		           , OD.GOODS_CD
		           , OD.ORD_AMT
		           , OD.SUPPLY_COMP_CD
		           , OD.DELV_FEE_CD
		           , DF.DELV_FEE
		           , OD.GOODS_CPN_SQ
		           , OD.GOODS_CPN_DC_AMT
		           , OD.CART_CPN_SQ
		           , OD.CART_CPN_DC_AMT
		           , DF.DELV_CPN_SQ
		           , DF.DELV_CPN_DC_AMT
		        FROM TB_ORDER_DETAIL OD
		        LEFT OUTER JOIN TB_DELIVERY_FEE DF
		          ON OD.DELV_FEE_CD = DF.DELV_FEE_CD
		         AND OD.ORD_NO = DF.ORD_NO
		       WHERE 1 = 1
		        AND OD.ORD_NO = #{ordNo}
		  )
		SELECT X.*
		     , CP.CPN_ID
		     , CP.CPN_NM
		     , CP.DC_WAY
		     , CP.DC_PVAL
		     , CP.DC_MVAL
		     , CP.DC_AVAL
		  FROM (
		      SELECT Z.*
		        FROM (
		            SELECT 1                   AS DISP_ORD
		                 , CD.GOODS_CPN_SQ     AS CPN_SQ
		                 , CD.GOODS_CPN_DC_AMT AS CPN_DC_AMT
		                 , '상품쿠폰'             AS CPN_TYPE
		                 , CD.GOODS_CD         AS TARGET_CD1
		                 , CD.ORD_DTL_NO       AS TARGET_CD2
		                 , CD.ORD_NO
		                 , CD.ORD_AMT
		              FROM COUPON_DATA CD
		             UNION ALL
		            SELECT 2                  AS DISP_ORD
		                 , CD.CART_CPN_SQ     AS CPN_SQ
		                 , CD.CART_CPN_DC_AMT AS CPN_DC_AMT
		                 , '장바구니쿠폰'          AS CPN_TYPE
		                 , CD.GOODS_CD        AS TARGET_CD1
		                 , CD.ORD_DTL_NO      AS TARGET_CD2
		                 , CD.ORD_NO
		                 , CD.ORD_AMT
		              FROM COUPON_DATA CD
		             UNION ALL
		            SELECT 3                  AS DISP_ORD
		                 , CD.DELV_CPN_SQ     AS CPN_SQ
		                 , CD.DELV_CPN_DC_AMT AS CPN_DC_AMT
		                 , '배송비쿠폰'            AS CPN_TYPE
		                 , CD.SUPPLY_COMP_CD  AS TARGET_CD1
		                 , CD.DELV_FEE_CD     AS TARGET_CD2
		                 , CD.ORD_NO
		                 , CD.DELV_FEE        AS ORD_AMT
		              FROM COUPON_DATA CD
		             GROUP BY CD.DELV_CPN_SQ
		                    , CD.DELV_CPN_DC_AMT
		                    , CD.SUPPLY_COMP_CD
		                    , CD.DELV_FEE_CD
		                    , CD.ORD_NO
		                    , CD.DELV_FEE
		        ) Z
		       WHERE 1 = 1
		         AND Z.CPN_SQ IS NOT NULL
		  ) X
		  INNER JOIN TB_CUST_COUPON CC
		  ON X.CPN_SQ = CC.CUST_CPN_SQ
		  LEFT OUTER JOIN TB_COUPON CP
		  ON CC.CPN_ID = CP.CPN_ID
		 ORDER BY DISP_ORD
	</select>

	<!-- 주문상세 > 포인트사용내역 -->
	<select id="getOrderDiscountPointList" parameterType="Order" resultType="Order">
		/* order.getOrderDiscountPointList */
		SELECT OD.ORD_NO
		     , OD.ORD_DTL_NO
		     , OD.GOODS_CD
		     , G.PNT_PRATE
		     , G.PNT_MRATE
		     , OD.CURR_PRICE
		     , OD.REAL_ORD_AMT
		     , CPH.PNT_AMT
		     , CPH.OCCUR_GB
		     , CPH.OCCUR_DTL_DESC
		     , DATE_FORMAT(CPH.REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		  FROM TB_ORDER_DETAIL OD
		 INNER JOIN TB_CUST_POINT_HST CPH
		    ON OD.ORD_DTL_NO = CPH.ORD_DTL_NO
		   AND OD.ORD_NO = CPH.ORD_NO
		 INNER JOIN TB_GOODS G
		    ON OD.GOODS_CD = G.GOODS_CD
		 WHERE 1 = 1
		   AND OD.ORD_NO = #{ordNo}
		 ORDER BY CPH.REG_DT DESC
	</select>

	<!-- 주문상세 > 상품권사용내역 -->
	<select id="getOrderGiftcardHstList" parameterType="Order" resultType="Order">
		/* order.getOrderGiftcardHstList */
		SELECT CG.CUST_GFCD_SQ
		     , CG.GFCD_NM
		     , CG.GFCD_NO
		     , CG.CHG_GFCD_AMT
		     , CG.US_GFCD_AMT
		     , CG.RM_GFCD_AMT
		     , OD.ORD_NO
		     , OD.ORD_DTL_NO
		     , OD.GOODS_CD
		     , CGH.GFCD_AMT
		     , CGH.OCCUR_GB
		     , CGH.OCCUR_DTL_DESC
		     , DATE_FORMAT(CGH.REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		  FROM TB_ORDER_DETAIL OD
		 INNER JOIN TB_CUST_GIFTCARD_HST CGH
		    ON OD.ORD_DTL_NO = CGH.ORD_DTL_NO
		   AND OD.ORD_NO = CGH.ORD_NO
		 INNER JOIN TB_CUST_GIFTCARD CG
		    ON CGH.CUST_GFCD_SQ = CG.CUST_GFCD_SQ
		 WHERE 1 = 1
		   AND OD.ORD_NO = #{ordNo}
		 UNION ALL
		SELECT CG.CUST_GFCD_SQ
		     , CG.GFCD_NM
		     , CG.GFCD_NO
		     , CG.CHG_GFCD_AMT
		     , CG.US_GFCD_AMT
		     , CG.RM_GFCD_AMT
		     , DF.ORD_NO
		     , DF.DELV_FEE_SQ AS ORD_DTL_NO
		     , DF.DELV_FEE_CD AS GOODS_CD
		     , CGH.GFCD_AMT
		     , CGH.OCCUR_GB
		     , CGH.OCCUR_DTL_DESC
		     , DATE_FORMAT(CGH.REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		  FROM TB_DELIVERY_FEE DF
		 INNER JOIN TB_CUST_GIFTCARD_HST CGH
		    ON DF.DELV_FEE_SQ = CGH.DELV_FEE_SQ
		   AND DF.ORD_NO = CGH.ORD_NO
		 INNER JOIN TB_CUST_GIFTCARD CG
		    ON CGH.CUST_GFCD_SQ = CG.CUST_GFCD_SQ
		 WHERE 1 = 1
		   AND DF.ORD_NO = #{ordNo}
	</select>

	<!-- 주문상세 > 다다익선적용내역 -->
	<select id="getOrderTmtbHstList" parameterType="Order" resultType="Order">
		/* order.getOrderTmtbHstList */
		  WITH TMTB_DATA AS (
		      SELECT TM1.TMTB_SQ AS TMTB1_SQ
		           , TM1.TMTB_NM AS TMTB1_NM
		           , OD.TMTB1_DC_AMT
		           , OD.ORD_NO
		           , OD.ORD_DTL_NO
		           , OD.REG_NO
		           , OD.REG_DT
		           , OD.GOODS_CD
		           , TM2.TMTB_SQ AS TMTB2_SQ
		           , TM2.TMTB_NM AS TMTB2_NM
		           , OD.TMTB2_DC_AMT
		        FROM TB_ORDER_DETAIL OD
		        LEFT OUTER JOIN TB_TMTB TM1
		          ON OD.TMTB1_SQ = TM1.TMTB_SQ
		        LEFT OUTER JOIN TB_TMTB TM2
		          ON OD.TMTB2_SQ = TM2.TMTB_SQ
		       WHERE 1 = 1
		         AND OD.ORD_NO = #{ordNo}
		  )
		SELECT Z.*
		  FROM (
		      SELECT 1		                    AS DISP_ORD
		           , TD.TMTB1_SQ                            AS TMTB_SQ
		           , TD.TMTB1_NM                            AS TMTB_NM
		           , TD.TMTB1_DC_AMT                        AS TMTB_DC_AMT
		           , TD.ORD_NO
		           , TD.ORD_DTL_NO
		           , TD.GOODS_CD
		           , TD.REG_NO
		           , DATE_FORMAT(TD.REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		        FROM TMTB_DATA TD
		       UNION ALL
		      SELECT 2		                    AS DISP_ORD
		           , TD.TMTB2_SQ                            AS TMTB_SQ
		           , TD.TMTB2_NM                            AS TMTB_NM
		           , TD.TMTB2_DC_AMT                        AS TMTB_DC_AMT
		           , TD.ORD_NO
		           , TD.ORD_DTL_NO
		           , TD.GOODS_CD
		           , TD.REG_NO
		           , DATE_FORMAT(TD.REG_DT, '%Y%m%d%H%i%S') AS REG_DT
		        FROM TMTB_DATA TD
		  ) Z
		 WHERE 1 = 1
		   AND Z.TMTB_SQ IS NOT NULL
		 ORDER BY Z.DISP_ORD
	</select>

	<!-- 주문상세 > 주문상세상태변경 -->
	<update id="changedOrdDtlStat" parameterType="Order">
		/* order.changedOrdDtlStat */
		UPDATE TB_ORDER_DETAIL
		   SET ORD_DTL_STAT = #{ordDtlStat}
		     , UPD_NO       = #{updNo}
		     , UPD_DT       = NOW()
		 WHERE 1 = 1
		   AND ORD_NO = #{ordNo}
		   AND ORD_DTL_NO = #{ordDtlNo}
	</update>

	<!-- 주문상세 > 주문상세상태변경 -->
	<update id="changedOrdDtlStat2" parameterType="Order">
		/* order.changedOrdDtlStat */
		UPDATE TB_ORDER_DETAIL_ITEM
		   SET ORD_DTL_STAT = #{ordDtlStat}
		     , UPD_NO       = #{updNo}
		     , UPD_DT       = NOW()
		 WHERE 1 = 1
		   AND ORD_NO = #{ordNo}
		   AND ORD_DTL_NO = #{ordDtlNo}
	</update>

	<!-- TB_PAYMENT -->
	<update id="changedPayStat" parameterType="Order">
		/* order.changedPayStat */
		UPDATE TB_PAYMENT
		   SET PAY_STAT = 'G016_30'
		     , UPD_NO   = #{updNo}
		     , UPD_DT   = NOW()
		 WHERE 1 = 1
		   AND ORD_NO = #{ordNo}
		   AND PAY_GB = 'O'
	</update>

	<!-- 배송 > 배송지 정보 수정 -->
	<update id="updateOrderAddr" parameterType="Order">
		/* order.updateOrderAddr : 주문 변경 업데이트(주문자 주소) */
		UPDATE TB_DELIVERY_ADDR
		   SET RECIP_NM        = #{recipNm}
		     , RECIP_PHNNO     = #{recipPhnno}
		     , RECIP_TELNO     = #{recipTelno}
		     , RECIP_ZIPCODE   = #{recipZipcode}
		     , RECIP_BASE_ADDR = #{recipBaseAddr}
		     , RECIP_DTL_ADDR  = #{recipDtlAddr}
		     , DELV_MEMO       = #{delvMemo}
		     , UPD_NO          = #{updNo}
		     , UPD_DT          = NOW()
		 WHERE DELV_ADDR_SQ = #{delvAddrSq}
	</update>

	<!-- 반품/교환 > 회수지 정보 수정 -->
	<update id="updateOrderChange" parameterType="Order">
		/* order.updateOrderChange : 반품/교환 > 회수지 정보 수정 */
		UPDATE TB_ORDER_CHANGE
		   SET CHGER_ZIPCODE   = #{chgerZipcode}
		     , CHGER_BASE_ADDR = #{chgerBaseAddr}
		     , CHGER_DTL_ADDR  = #{chgerDtlAddr}
		     , UPD_NO          = #{updNo}
		     , UPD_DT          = NOW()
		 WHERE ORD_CHG_SQ = #{ordChgSq}
	</update>



	<!-- 장바구니 상품 목록 조회 (업체별 배송단위) -->
	<select id="getCartGoodsList" parameterType="Order" resultType="Order">
		/* TscOrder.getCartGoodsList */
		SELECT Z.CART_SQ
		     , Z.BRAND_ENM
		     , Z.BRAND_KNM
		     , Z.GOODS_NM
		     , Z.GOODS_CD
		     , GROUP_CONCAT(Z.ITEM_NM ORDER BY Z.CART_DTL_SQ SEPARATOR '!@!') AS ITEM_NM
		     , GROUP_CONCAT(Z.ITEM_CD ORDER BY Z.CART_DTL_SQ) AS ITEM_CD
		     , GROUP_CONCAT(Z.OPT_CD ORDER BY Z.CART_DTL_SQ) AS OPT_CD
		     , GROUP_CONCAT(Z.OPT_CD1 ORDER BY Z.CART_DTL_SQ) AS OPT_CD1
		     , GROUP_CONCAT(Z.OPT_CD2 ORDER BY Z.CART_DTL_SQ) AS OPT_CD2
		     , GROUP_CONCAT(Z.ITEM_QTY ORDER BY Z.CART_DTL_SQ) AS ITEM_QTYR
		     , GROUP_CONCAT(Z.COLOR_NM ORDER BY Z.CART_DTL_SQ) AS COLOR_NM
		     , GROUP_CONCAT(Z.OPT_ADD_PRICE ORDER BY Z.CART_DTL_SQ) AS ITEM_ADD_PRICE
		     , Z.GOODS_QTY
		     , Z.GOODS_TYPE
		     , Z.LIST_PRICE
		     , Z.GOODS_GB
		     , Z.GOODS_STAT
		     , Z.PRE_PPNT_USABLE_YN
		     , Z.PRE_MPNT_USABLE_YN
		     , Z.MAX_ORD_QTY
		     , Z.DAY_MAX_ORD_QTY
		     , Z.GIFT_PACK_YN
		     , Z.NEW_CUST_ORD_YN
		     , Z.SUPPLY_COMP_CD
		     , Z.DELV_FEE_CD
		     , Z.RES_DELV_FEE_CD
		     , Z.DELV_RES_DT
		     , Z.MIN_ORD_AMT
		     , Z.DELV_FEE
		     , Z.CURR_PRICE
		     , Z.ORG_CURR_PRICE
		     , SUM(Z.OPT_ADD_PRICE) AS OPT_ADD_PRICE
		     , Z.CPN1_CPN_SQ
		     , Z.ORG_CURR_PRICE - Z.CURR_PRICE AS CPN1_DC_AMT
		     , Z.PNT_PRATE
		     , Z.PNT_MRATE
		     , Z.SYS_IMG_NM
		     , Z.DELV_FEE_CRITE
		     , CASE WHEN #{frontGb} = 'P'
		            THEN (Z.CURR_PRICE * Z.GOODS_QTY) * (Z.PNT_PRATE/100)
		            ELSE (Z.CURR_PRICE * Z.GOODS_QTY) * (Z.PNT_MRATE/100)
		             END AS SAVE_PNT_AMT
		     , CASE WHEN #{frontGb} IN ('P')      AND Z.PRE_PPNT_USABLE_YN IN ('Y') THEN (Z.CURR_PRICE * Z.GOODS_QTY) * (Z.PNT_PRATE/100)
		            WHEN #{frontGb} IN ('M', 'A') AND Z.PRE_MPNT_USABLE_YN IN ('Y') THEN (Z.CURR_PRICE * Z.GOODS_QTY) * (Z.PNT_MRATE/100)
		             END AS PRE_PNT_DC_AMT
		     , Z.SHOT_DELV_YN
		     , Z.FOREIGN_BUY_YN
		     , Z.ORDER_MADE_YN
		     , Z.SUPPLY_COMP_NM
		     , Z.SELF_GOODS_YN
		     , Z.BRAND_GROUP_NM
		FROM  ( SELECT CA.CART_SQ
		             , CD.CART_DTL_SQ
		             , BR.BRAND_ENM
		             , BR.BRAND_KNM
		             , FN_GET_GOODS_NM(G.GOODS_NM, G.GOODS_GB, G.FOREIGN_BUY_YN, G.PARALLEL_IMPORT_YN, G.ORDER_MADE_YN) AS GOODS_NM
		             , CA.GOODS_CD
		             , (SELECT GOODS_NM FROM TB_GOODS WHERE GOODS_CD = CD.ITEM_CD) AS ITEM_NM
		             , IFNULL((SELECT COLOR_KNM FROM TB_COLOR C WHERE COLOR_CD = IFNULL(NULLIF(OP.OPT_CD1,'') , G.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), OP.OPT_CD1) AS COLOR_NM
		             , CD.ITEM_CD
		             , OP.OPT_CD
		             , OP.OPT_CD1
		             , OP.OPT_CD2
		             , CA.GOODS_QTY
		             , CD.ITEM_QTY
		             , G.GOODS_TYPE
		             , G.LIST_PRICE
		             , G.GOODS_GB
		             , G.GOODS_STAT
		             , G.PRE_PPNT_USABLE_YN
		             , G.PRE_MPNT_USABLE_YN
		             , G.MAX_ORD_QTY
		             , G.DAY_MAX_ORD_QTY
		             , G.GIFT_PACK_YN
		             , G.NEW_CUST_ORD_YN
		             , G.PNT_PRATE
		             , G.PNT_MRATE
		             , DFP.SUPPLY_COMP_CD
		             , DFP.DELV_FEE_CRITE
		             , CT.CUST_GRADE
		             , CASE WHEN G.SELF_GOODS_YN = 'Y' THEN 'WMS'
		                    ELSE DFP.DELV_FEE_CD
		                    END AS DELV_FEE_CD
		             , CASE WHEN GRS.DELV_RES_DT IS NOT NULL THEN 'RES'
		                    WHEN GQDS.GOODS_CD IS NULL AND G.SELF_GOODS_YN = 'Y' THEN 'SHOT'
		                    WHEN G.SELF_GOODS_YN = 'Y' THEN 'WMS'
		                    ELSE DFP.DELV_FEE_CD
		                    END AS RES_DELV_FEE_CD
		             , DATE_FORMAT(GRS.DELV_RES_DT, '%Y.%m.%d') AS DELV_RES_DT
		             , 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
		             , VS.CURR_STOCK_QTY
		             , FN_GET_APPLY_CPN1_PRICE(CA.GOODS_CD, #{frontGb}) AS CURR_PRICE
		             , G.CURR_PRICE AS ORG_CURR_PRICE
		             , FN_GET_APPLY_CPN1_ID(CA.GOODS_CD, #{frontGb}) AS CPN1_CPN_SQ
		             , IFNULL(OP.ADD_PRICE, 0) AS OPT_ADD_PRICE
		             , CASE WHEN G.SELF_GOODS_YN = 'Y' AND G.GOODS_TYPE != 'G056_S' THEN CD.OPT_CD1
		                    ELSE '00' END AS COLOR_CD
		             , CASE WHEN G.GOODS_TYPE != 'G056_S' AND G.SELF_GOODS_YN = 'Y' THEN (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G.GOODS_CD AND COLOR_CD = CD.OPT_CD1 AND DEFAULT_IMG_YN = 'Y')
		                    ELSE (SELECT SYS_IMG_NM FROM TB_GOODS_IMG WHERE GOODS_CD = G.GOODS_CD AND COLOR_CD = G.MAIN_COLOR_CD AND DEFAULT_IMG_YN = 'Y') END AS SYS_IMG_NM
		             , CASE WHEN GQDS.GOODS_CD IS NULL AND G.SELF_GOODS_YN = 'Y' AND GRS.DELV_RES_DT IS NULL
		                    THEN 'Y'
		                    ELSE 'N'
		                     END SHOT_DELV_YN
		             , G.FOREIGN_BUY_YN
		             , G.ORDER_MADE_YN
		             , SC.SUPPLY_COMP_NM
		             , G.SELF_GOODS_YN
		             , (CASE WHEN BG.DISP_NM_LANG = 'EN' THEN BG.BRAND_GROUP_ENM ELSE BG.BRAND_GROUP_KNM END) AS BRAND_GROUP_NM
		          FROM TB_CART CA
		         INNER JOIN TB_CART_DETAIL CD
		            ON CA.CART_SQ = CD.CART_SQ
		         INNER JOIN TB_GOODS G
		            ON CA.GOODS_CD = G.GOODS_CD
		         INNER JOIN TB_DELV_FEE_POLICY DFP
		            ON G.DELV_FEE_CD = DFP.DELV_FEE_CD
		           AND G.SUPPLY_COMP_CD = DFP.SUPPLY_COMP_CD
		         INNER JOIN TB_BRAND BR
		            ON G.BRAND_CD = BR.BRAND_CD
		         INNER JOIN TB_BRAND_GROUP BG
		            ON BR.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		          LEFT JOIN TB_OPTION OP
		            ON CD.ITEM_CD = OP.GOODS_CD
		           AND CD.OPT_CD = OP.OPT_CD
		          LEFT OUTER JOIN VW_STOCK VS
		            ON CD.ITEM_CD = VS.GOODS_CD
		           AND CD.OPT_CD = VS.OPT_CD
		          LEFT OUTER JOIN TB_GOODS_RES_SELL GRS
		            ON CA.GOODS_CD = GRS.GOODS_CD
		           AND GRS.USE_YN = 'Y'
		           AND GRS.DELV_RES_DT > NOW()
		          LEFT OUTER JOIN TB_CUSTOMER CT
		            ON CA.CUST_NO = CT.CUST_NO
		          LEFT OUTER JOIN TB_GOODS_SHOT_DELV_SKIP GQDS
		            ON G.GOODS_CD = GQDS.GOODS_CD
		         INNER JOIN TB_SUPPLY_COMPANY SC
		            ON G.SUPPLY_COMP_CD = SC.SUPPLY_COMP_CD
		         WHERE 1 = 1
		           AND G.GOODS_STAT = 'G008_90'
				<if test="custNo == 0">
		           AND CA.CUST_NO = 0
				</if>
				<if test="custNo != 0">
		           AND CA.CUST_NO = #{custNo}
				</if>
		           AND CA.CART_SQ IN
				<foreach collection="cartSqArr" item="item" index="index"  open="(" close=")" separator=",">
		           #{item}
				</foreach>
			) Z
		GROUP  BY Z.CART_SQ
		     , Z.BRAND_ENM
		     , Z.BRAND_KNM
		     , Z.GOODS_NM
		     , Z.GOODS_CD
		     , Z.GOODS_QTY
		     , Z.GOODS_TYPE
		     , Z.LIST_PRICE
		     , Z.GOODS_GB
		     , Z.GOODS_STAT
		     , Z.PRE_PPNT_USABLE_YN
		     , Z.PRE_MPNT_USABLE_YN
		     , Z.MAX_ORD_QTY
		     , Z.DAY_MAX_ORD_QTY
		     , Z.GIFT_PACK_YN
		     , Z.NEW_CUST_ORD_YN
		     , Z.SUPPLY_COMP_CD
		     , Z.DELV_FEE_CD
		     , Z.RES_DELV_FEE_CD
		     , Z.DELV_RES_DT
		     , Z.MIN_ORD_AMT
		     , Z.DELV_FEE
		     , Z.CURR_PRICE
		     , Z.ORG_CURR_PRICE
		     , Z.CPN1_CPN_SQ
		     , CPN1_DC_AMT
		     , Z.PNT_PRATE
		     , Z.PNT_MRATE
		     , Z.SYS_IMG_NM
		     , Z.DELV_FEE_CRITE
		     , SAVE_PNT_AMT
		     , PRE_PNT_DC_AMT
		     , Z.SHOT_DELV_YN
		     , Z.FOREIGN_BUY_YN
		     , Z.ORDER_MADE_YN
		     , Z.SUPPLY_COMP_NM
		     , Z.SELF_GOODS_YN
		ORDER  BY Z.DELV_FEE_CD DESC
		     , Z.CART_SQ DESC
	</select>

	<!-- 고객정보 조회 -->
	<select id="getCustemerInfo" parameterType="Order" resultType="Order">
		/* TscOrder.getCustemerInfo */
		SELECT CU.CUST_NM
		     , CU.EMAIL
		     , CU.CELL_PHNNO
		     , CU.CI
		     , CU.SEX_GB
		     , CU.BIRTH_YMD
		  FROM TB_CUSTOMER CU
		 WHERE 1=1
		   AND CU.CUST_NO = #{custNo}
		 LIMIT 1
	</select>

	<!-- 배송지정보 조회 -->
	<select id="getDeliveryAddrInfo" parameterType="Order" resultType="Order">
		/* TscOrder.getDeliveryAddrInfo */
		SELECT CDA.CUST_DELV_ADDR_SQ
		     , CDA.DELV_ADDR_NM
		     , CDA.RECIP_NM
		     , CDA.RECIP_ZIPCODE
		     , CDA.RECIP_BASE_ADDR
		     , CDA.RECIP_DTL_ADDR
		     , CDA.RECIP_PHNNO
		     , CDA.DELV_MEMO
		     , CU.CUST_NM
		     , CU.CELL_PHNNO
		     , CDA.DEFAULT_YN
		     , CASE WHEN DDZ.ZIP_NO IS NULL
		            THEN 'N'
		            ELSE 'Y'
		            END  SHOT_DELV_USE_YN
		  FROM TB_CUSTOMER CU
		  LEFT OUTER JOIN  TB_CUST_DELIVERY_ADDR CDA
		    ON CDA.CUST_NO = CU.CUST_NO
		   AND CDA.DEL_YN = 'N'
		  LEFT OUTER JOIN TB_DAILY_DELIVERY_ZONE DDZ
		    ON DDZ.ZIP_NO = CDA.RECIP_ZIPCODE
		   AND DDZ.ISUSE = 'Y'
		 WHERE 1=1
		   AND CU.CUST_NO = #{custNo}
		 ORDER BY CDA.DEFAULT_YN DESC
		     , CDA.REG_DT DESC
	</select>

	<!-- 기본배송지정보 변경 -->
	<update id="updateCustDeliveryAddrDefaultYn" parameterType="Order">
		/* TscOrder.updateCustDeliveryAddrDefaultYn */
		UPDATE TB_CUST_DELIVERY_ADDR
		SET    DEFAULT_YN = 'N'
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  CUST_NO = #{custNo}
	</update>

	<!-- 회원 배송지정보 수정 -->
	<update id="updateCustDeliveryAddr" parameterType="Order">
		/* TscOrder.updateCustDeliveryAddr */
		UPDATE TB_CUST_DELIVERY_ADDR
		SET    DELV_ADDR_NM = #{recipNm}
		     , DEFAULT_YN = #{defaultYn}
		     , RECIP_NM = #{recipNm}
		     , RECIP_PHNNO = #{recipPhnno}
		     , RECIP_TELNO = #{recipTelno}
		     , RECIP_ZIPCODE = #{recipZipcode}
		     , RECIP_BASE_ADDR = #{recipBaseAddr}
		     , RECIP_DTL_ADDR = #{recipDtlAddr}
		     , DELV_MEMO = #{delvMemo}
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  CUST_DELV_ADDR_SQ = #{custDelvAddrSq}
	</update>

	<!-- 회원 배송지정보 등록 -->
	<insert id="createCustDeliveryAddr" parameterType="Order" keyProperty="custDelvAddrSq">
		/* TscOrder.createCustDeliveryAddr */
		INSERT INTO TB_CUST_DELIVERY_ADDR (
		    CUST_NO
		    , DELV_ADDR_NM
		    , DEFAULT_YN
		    , RECIP_NM
		    , RECIP_PHNNO
		    , RECIP_TELNO
		    , RECIP_ZIPCODE
		    , RECIP_BASE_ADDR
		    , RECIP_DTL_ADDR
		    , DELV_MEMO
		    , DEL_YN
		    , REG_NO
		    , REG_DT
		    , UPD_NO
		    , UPD_DT
		) VALUES (
		    #{custNo}
		    , #{recipNm}
		    , #{defaultYn}
		    , #{recipNm}
		    , #{recipPhnno}
		    , #{recipTelno}
		    , #{recipZipcode}
		    , #{recipBaseAddr}
		    , #{recipDtlAddr}
		    , #{delvMemo}
		    , 'N'
		    , #{custNo}
		    , NOW()
		    , #{custNo}
		    , NOW()
		)
	</insert>

	<!-- 포인트정보 조회 -->
	<select id="getCustPointInfo" parameterType="Order" resultType="int">
		/* TscOrder.getCustPointInfo */
		SELECT IFNULL(SUM(CP.RM_PNT_AMT), 0) AS RM_PNT_AMT
		FROM   TB_CUST_POINT CP
		WHERE  1=1
		AND    CP.CUST_NO = #{custNo}
		AND    CP.EXP_BE_DT <![CDATA[ > ]]> NOW()
		AND    CP.EXP_CMP_DT IS NULL
	</select>

	<!-- 상품권정보 조회 -->
	<select id="getGiftcardInfo" parameterType="Order" resultType="int">
		/* TscOrder.getGiftcardInfo */
		SELECT IFNULL(SUM(CG.RM_GFCD_AMT), 0) AS RM_GFCD_AMT
		  FROM TB_CUST_GIFTCARD CG
		 WHERE 1=1
		   AND CG.CUST_NO = #{custNo}
		   AND DATE_FORMAT(NOW(), '%Y%m%d') BETWEEN CG.USE_ST_DATE AND CG.USE_EXP_DATE
	</select>

	<!-- 쿠폰정보 조회 -->
	<select id="getCouponInfo" parameterType="Order" resultType="int">
		/* order.getCouponInfo */
		SELECT COUNT(CC.CUST_CPN_SQ) AS CNT
		  FROM TB_CUST_COUPON CC
		 INNER JOIN TB_COUPON C
		    ON CC.CPN_ID = C.CPN_ID
		   AND C.CPN_STAT = 'G232_11'
		 WHERE CC.CUST_NO = #{custNo}
		   AND NOW() BETWEEN CC.AVAIL_STDT AND CC.AVAIL_EDDT
		   AND CC.USED_DT IS NULL
		<if test='expiredSoon == "Y"'>
		   AND TIMESTAMPDIFF(SECOND, CURRENT_DATE, CC.AVAIL_EDDT) BETWEEN 0 AND 604800
		</if>
	</select>

	<!-- 총알배송 가능시간 조회 -->
	<select id="getDailyDeliveryTimeInfo" resultType="int">
		/* order.getDailyDeliveryTimeInfo */
		SELECT IFNULL(SUM(A.SHOT_DELV_ABLE_YN), 0) AS SHOT_DELV_ABLE_YN
		FROM (
			SELECT CASE WHEN TIME_FORMAT(NOW(), '%H') <![CDATA[<]]> ENV.STR_SET_VAL4 AND BIZ.BIZDAY_YN IN ('Y')
			            THEN 1
			            ELSE 0
			            END  SHOT_DELV_ABLE_YN
			FROM   TB_ENVSET ENV
			LEFT   OUTER JOIN TB_BIZDAY2 BIZ
			ON     1=1
			AND    BIZ.BIZDAY = DATE_FORMAT(NOW(), '%Y%m%d')
			WHERE  1=1
			AND    ENV.SITE_CD = 'G000_10'
			AND    ENV.ENVSET_TYPE = 'O10'
			ORDER  BY ENV.REG_DT DESC
			LIMIT  1
		) A
	</select>

	<!-- 총알배송 가능지역 조회 -->
	<select id="getDailyDeliveryZoneInfo" parameterType="Order" resultType="int">
		/* TscOrder.getDailyDeliveryZoneInfo */
		SELECT COUNT(1)
		  FROM TB_DAILY_DELIVERY_ZONE DC
		 WHERE 1=1
		   AND ZIP_NO = #{recipZipcode}
		   AND ISUSE = 'Y'
	</select>

	<!-- 상품쿠폰, 장바구니쿠폰 적용 상품 조회 -->
	<select id="getGoodsCartCpnApplyGoodsList" parameterType="Order" resultType="Order">
		/* TscOrder.getGoodsCartCpnApplyGoodsList */
		WITH GOODS_DATA AS (
		    SELECT CA.GOODS_CD
		         , G.SUPPLY_COMP_CD
		         , G.BRAND_CD
		         , CA.CART_SQ
		         , (FN_GET_APPLY_CPN1_PRICE(CA.GOODS_CD, #{frontGb}) + IFNULL(OP.ADD_PRICE, 0)) * CA.GOODS_QTY AS CURR_PRICE
		    FROM   TB_CART CA
		    INNER  JOIN TB_CART_DETAIL CD
		    ON     CA.CART_SQ = CD.CART_SQ
		    INNER  JOIN TB_GOODS G
		    ON     CA.GOODS_CD = G.GOODS_CD
		    LEFT   OUTER JOIN ( SELECT OP.ADD_PRICE
		                        , C.CART_SQ
		                   FROM   TB_CART C
		                   INNER  JOIN TB_CART_DETAIL CD
		                   ON     C.CART_SQ = CD.CART_SQ
		                   INNER  JOIN TB_OPTION OP
		                   ON     C.GOODS_CD = OP.GOODS_CD
		                   AND    CD.OPT_CD = OP.OPT_CD
		           ) OP
		    ON     CA.CART_SQ = OP.CART_SQ
		    WHERE  1=1
			<if test="custNo == 0">
		    AND    CA.CUST_NO = 0
		    AND    CA.JSESSION_ID = #{jsessionId}
			</if>
			<if test="custNo != 0">
		    AND    CA.CUST_NO = #{custNo}
			</if>
		    AND    CA.CART_SQ IN
			<foreach collection="cartSqArr" item="item" index="index"  open="(" close=")" separator=",">
				#{item}
			</foreach>
		)
		SELECT X.*
		FROM (
		    SELECT Z.GOODS_CD
		         , Z.CART_SQ
		         , Z.CURR_PRICE
		         , CP.CPN_ID
		         , CP.CPN_NM
		         , CP.CPN_TYPE
		         , CP.DC_WAY
		         , CASE WHEN #{frontGb} = 'P' THEN CP.DC_PVAL
		                WHEN #{frontGb} = 'M' THEN CP.DC_MVAL
		                ELSE CP.DC_AVAL END AS DC_VAL
		         , CP.MAX_DC_AMT
		         , CP.BUY_LIMIT_AMT
		         , CP.APPLY_SCOPE
		         , CCP.CUST_CPN_SQ
		    FROM   TB_COUPON CP
		    INNER  JOIN TB_COUPON_CUST_GRADE CGR
		    ON     CP.CPN_ID = CGR.CPN_ID
		    INNER  JOIN TB_CUST_COUPON CCP
		    ON     CP.CPN_ID = CCP.CPN_ID
		    INNER  JOIN TB_CUSTOMER CT
		    ON     CCP.CUST_NO = CT.CUST_NO
		    AND    CGR.USABLE_CUST_GRADE = CT.CUST_GRADE
		    INNER  JOIN TB_COUPON_CUST_GBN CGB
		    ON     CP.CPN_ID = CGB.CPN_ID
		    AND    CGB.USABLE_CUST_GB = CT.CUST_GB
		    INNER  JOIN (
		            SELECT X.*
		            FROM (
		                SELECT CR.CPN_ID
		                     , GD.GOODS_CD
		                     , GD.CART_SQ
		                     , GD.CURR_PRICE
		                FROM   TB_COUPON_REFVAL CR
		                INNER  JOIN GOODS_DATA GD
		                ON     CR.REF_VAL = GD.GOODS_CD
		                WHERE  1=1
		                AND    CR.CPN_TARGET = 'G260_10' -- 상품
		                AND    CR.DEL_YN = 'N'
		                UNION
		                SELECT CR.CPN_ID
		                     , GD.GOODS_CD
		                     , GD.CART_SQ
		                     , GD.CURR_PRICE
		                FROM   (
		                    SELECT C4.LEAF_CATE_NO
		                    , CASE WHEN X = 1 THEN 'CATE1_NO'
		                           WHEN X = 2 THEN 'CATE2_NO'
		                           WHEN X = 3 THEN 'CATE3_NO'
		                           WHEN X = 4 THEN 'CATE4_NO'
		                           ELSE 'CATE5_NO'
		                           END  CATE_LVL
		                    , CASE WHEN X = 1 THEN CATE1_NO
		                           WHEN X = 2 THEN CATE2_NO
		                           WHEN X = 3 THEN CATE3_NO
		                           WHEN X = 4 THEN CATE4_NO
		                           ELSE CATE5_NO
		                           END  CATE_NO
		                    FROM   TB_CATE_4SRCH C4
		                    LEFT   OUTER JOIN (
		                   SELECT 1 AS X
		                   UNION  ALL
		                   SELECT 2 AS X
		                   UNION  ALL
		                   SELECT 3 AS X
		                   UNION  ALL
		                   SELECT 4 AS X
		                   UNION  ALL
		                   SELECT 5 AS X
		                    ) B
		                    ON     1=1
		                    WHERE  1=1
		                    AND    C4.SITE_CD = 'G000_10'
		                    AND    C4.CATE_TYPE = 'G031_10'
		                    ORDER  BY LEAF_CATE_NO
		                    , CATE_LVL
		                ) C4SRCH
		                INNER  JOIN TB_COUPON_REFVAL CR
		                ON     C4SRCH.CATE_NO = CR.REF_VAL
		                INNER  JOIN TB_CATE_GOODS CG
		                ON     C4SRCH.LEAF_CATE_NO = CG.CATE_NO
		                INNER  JOIN GOODS_DATA GD
		                ON     CG.GOODS_CD = GD.GOODS_CD
		                WHERE  C4SRCH.CATE_NO IS NOT NULL
		                AND    CR.CPN_TARGET = 'G260_11' -- 카테고리
		                AND    CR.DEL_YN = 'N'
		                UNION
		                SELECT CR2.CPN_ID
		                     , GD.GOODS_CD
		                     , GD.CART_SQ
		                     , GD.CURR_PRICE
		                FROM   GOODS_DATA GD
		                INNER  JOIN TB_COUPON_REFVAL CR2
		                ON     GD.SUPPLY_COMP_CD = CR2.REF_VAL
		                AND    CR2.CPN_TARGET = 'G260_13' -- 공급업체
		                AND    CR2.DEL_YN = 'N'
		                INNER  JOIN TB_COUPON_REFVAL CR1
		                ON     GD.BRAND_CD = CR1.REF_VAL
		                AND    CR1.CPN_TARGET = 'G260_12' -- 브랜드
		                AND    CR1.DEL_YN = 'N'
		                AND    CR1.CPN_ID = CR2.CPN_ID
		            ) X
		            LEFT   OUTER JOIN TB_COUPON_REFVAL CR
		            ON     X.CPN_ID = CR.CPN_ID
		            AND    X.GOODS_CD = CR.REF_VAL
		            AND    CR.CPN_TARGET = 'G260_14' -- 제외상품
		            AND    CR.DEL_YN = 'N'
		            WHERE  1=1
		            AND    CR.REF_VAL IS NULL
		    ) Z
		    ON     Z.CPN_ID = CP.CPN_ID
		    WHERE  1=1
		    <if test="cpnId != null and cpnId != 0">
		    AND    CP.CPN_ID = #{cpnId}
		    </if>
		    AND    CP.SITE_CD = 'G000_10'
		    AND    CP.CPN_STAT = 'G232_11'				 -- 진행쿠폰
		    AND    CP.CPN_TYPE IN ('G230_11', 'G230_20') -- 상품쿠폰, 장바구니쿠폰
		    AND    CCP.AVAIL_STDT <![CDATA[<]]> CURRENT_TIMESTAMP
		    AND    CCP.AVAIL_EDDT > CURRENT_TIMESTAMP
		    AND    CT.CUST_NO = #{custNo}
		    AND    CP.APPLY_SCOPE = 'I'
		    AND    CCP.USED_DT IS NULL
		    GROUP  BY Z.GOODS_CD
		         , Z.CART_SQ
		         , Z.CURR_PRICE
		         , CP.CPN_ID
		         , CP.CPN_NM
		         , CP.CPN_TYPE
		         , CP.DC_WAY
		         , CP.DC_PVAL
		         , CP.DC_MVAL
		         , CP.DC_AVAL
		         , CP.MAX_DC_AMT
		         , CP.BUY_LIMIT_AMT
		         , CP.APPLY_SCOPE
		         , CCP.CUST_CPN_SQ
		    UNION  ALL
		    SELECT 'ALL'		AS GOODS_CD
		         , 0            AS CART_SQ
		         , 0            AS CURR_PRICE
		         , CP.CPN_ID
		         , CP.CPN_NM
		         , CP.CPN_TYPE
		         , CP.DC_WAY
		         , CASE WHEN #{frontGb} = 'P' THEN CP.DC_PVAL
		                WHEN #{frontGb} = 'M' THEN CP.DC_MVAL
		                ELSE CP.DC_AVAL END AS DC_VAL
		         , CP.MAX_DC_AMT
		         , CP.BUY_LIMIT_AMT
		         , CP.APPLY_SCOPE
		         , CCP.CUST_CPN_SQ
		    FROM   TB_COUPON CP
		    INNER  JOIN TB_COUPON_CUST_GRADE CGR
		    ON     CP.CPN_ID = CGR.CPN_ID
		    INNER  JOIN TB_CUST_COUPON CCP
		    ON     CP.CPN_ID = CCP.CPN_ID
		    INNER  JOIN TB_CUSTOMER CT
		    ON     CCP.CUST_NO = CT.CUST_NO
		    AND    CGR.USABLE_CUST_GRADE = CT.CUST_GRADE
		    INNER  JOIN TB_COUPON_CUST_GBN CGB
		    ON     CP.CPN_ID = CGB.CPN_ID
		    AND    CGB.USABLE_CUST_GB = CT.CUST_GB
		    WHERE  1=1
			<if test="cpnId != null and cpnId != 0">
		    AND    CP.CPN_ID = #{cpnId}
			</if>
		    AND    CP.SITE_CD = 'G000_10'
		    AND    CP.CPN_STAT = 'G232_11'				 -- 진행쿠폰
		    AND    CP.CPN_TYPE IN ('G230_11', 'G230_20') -- 상품쿠폰, 장바구니쿠폰
		    AND    CCP.AVAIL_STDT <![CDATA[<]]> CURRENT_TIMESTAMP
		    AND    CCP.AVAIL_EDDT > CURRENT_TIMESTAMP
		    AND    CT.CUST_NO = #{custNo}
		    AND    CP.APPLY_SCOPE = 'A'
		    AND    CCP.USED_DT IS NULL
		) X
	</select>

	<!-- 배송비쿠폰 조회 -->
	<select id="getDelvCpnList" parameterType="Order" resultType="Order">
		/* TscOrder.getDelvCpnList */
		WITH GOODS_DATA AS (
		    SELECT CA.GOODS_CD
		         , G.SUPPLY_COMP_CD
		         , G.BRAND_CD
		         , CA.CART_SQ
		         , (FN_GET_APPLY_CPN1_PRICE(CA.GOODS_CD, #{frontGb}) + IFNULL(OP.ADD_PRICE, 0)) * CA.GOODS_QTY AS CURR_PRICE
		    FROM   TB_CART CA
		    INNER  JOIN TB_CART_DETAIL CD
		    ON     CA.CART_SQ = CD.CART_SQ
		    INNER  JOIN TB_GOODS G
		    ON     CA.GOODS_CD = G.GOODS_CD
		    LEFT   OUTER JOIN ( SELECT OP.ADD_PRICE
		                        , C.CART_SQ
		                   FROM   TB_CART C
		                   INNER  JOIN TB_CART_DETAIL CD
		                   ON     C.CART_SQ = CD.CART_SQ
		                   INNER  JOIN TB_OPTION OP
		                   ON     C.GOODS_CD = OP.GOODS_CD
		                   AND    CD.OPT_CD = OP.OPT_CD
		    ) OP
		    ON     CA.CART_SQ = OP.CART_SQ
		    WHERE  1=1
			<if test="custNo == 0">
		    AND    CA.CUST_NO = 0
		    AND    CA.JSESSION_ID = #{jsessionId}
			</if>
			<if test="custNo != 0">
		    AND    CA.CUST_NO = #{custNo}
			</if>
		    AND    CA.CART_SQ IN
			<foreach collection="cartSqArr" item="item" index="index"  open="(" close=")" separator=",">
				#{item}
			</foreach>
		)
		SELECT Z.*
		FROM (
		    SELECT CP.CPN_ID
		         , CP.CPN_NM
		         , CP.CPN_TYPE
		         , CP.DC_WAY
		         , CASE WHEN #{frontGb} = 'P' THEN CP.DC_PVAL
		                WHEN #{frontGb} = 'M' THEN CP.DC_MVAL
		                ELSE CP.DC_AVAL END AS DC_VAL
		         , CP.MAX_DC_AMT
		         , CP.BUY_LIMIT_AMT
		         , CCP.CUST_CPN_SQ
		         , CP.APPLY_SCOPE
		    FROM   TB_COUPON CP
		    INNER  JOIN TB_COUPON_CUST_GRADE CGR
		    ON     CP.CPN_ID = CGR.CPN_ID
		    INNER  JOIN TB_CUST_COUPON CCP
		    ON     CP.CPN_ID = CCP.CPN_ID
		    INNER  JOIN TB_CUSTOMER CT
		    ON     CCP.CUST_NO = CT.CUST_NO
		    AND    CGR.USABLE_CUST_GRADE = CT.CUST_GRADE
		    INNER  JOIN TB_COUPON_CUST_GBN CGB
		    ON     CP.CPN_ID = CGB.CPN_ID
		    AND    CGB.USABLE_CUST_GB = CT.CUST_GB
		    INNER  JOIN (
		        SELECT X.*
		        FROM (
		            SELECT CR2.CPN_ID
		                 , GD.GOODS_CD
		                 , GD.CART_SQ
		                 , GD.CURR_PRICE
		            FROM   GOODS_DATA GD
		            INNER  JOIN TB_COUPON_REFVAL CR2
		            ON     GD.SUPPLY_COMP_CD = CR2.REF_VAL
		            AND    CR2.CPN_TARGET = 'G260_13' -- 공급업체
		            AND    CR2.DEL_YN = 'N'
		        ) X
		        LEFT   OUTER JOIN TB_COUPON_REFVAL CR
		        ON     X.CPN_ID = CR.CPN_ID
		        AND    X.GOODS_CD = CR.REF_VAL
		        AND    CR.CPN_TARGET = 'G260_14' -- 제외상품
		        AND    CR.DEL_YN = 'N'
		        WHERE  1=1
		        AND    CR.REF_VAL IS NULL
		    ) Z
		    ON     Z.CPN_ID = CP.CPN_ID
		    WHERE  1=1
		    AND    CP.SITE_CD = 'G000_10'
		    AND    CP.CPN_STAT = 'G232_11' -- 진행쿠폰
		    AND    CP.CPN_TYPE = 'G230_30' -- 배송비쿠폰
		    AND    CCP.USED_DT IS NULL
		    AND    CCP.AVAIL_STDT <![CDATA[<]]> CURRENT_TIMESTAMP
		    AND    CCP.AVAIL_EDDT > CURRENT_TIMESTAMP
		    AND    CT.CUST_NO = #{custNo}
		    AND    CP.APPLY_SCOPE = 'I'
		    UNION  ALL
		    SELECT CP.CPN_ID
		         , CP.CPN_NM
		         , CP.CPN_TYPE
		         , CP.DC_WAY
		         , CASE WHEN #{frontGb} = 'P' THEN CP.DC_PVAL
		                WHEN #{frontGb} = 'M' THEN CP.DC_MVAL
		                ELSE CP.DC_AVAL END AS DC_VAL
		         , CP.MAX_DC_AMT
		         , CP.BUY_LIMIT_AMT
		         , CCP.CUST_CPN_SQ
		         , CP.APPLY_SCOPE
		    FROM   TB_COUPON CP
		    INNER  JOIN TB_COUPON_CUST_GRADE CGR
		    ON     CP.CPN_ID = CGR.CPN_ID
		    INNER  JOIN TB_CUST_COUPON CCP
		    ON     CP.CPN_ID = CCP.CPN_ID
		    INNER  JOIN TB_CUSTOMER CT
		    ON     CCP.CUST_NO = CT.CUST_NO
		    AND    CGR.USABLE_CUST_GRADE = CT.CUST_GRADE
		    INNER  JOIN TB_COUPON_CUST_GBN CGB
		    ON     CP.CPN_ID = CGB.CPN_ID
		    AND    CGB.USABLE_CUST_GB = CT.CUST_GB
		    WHERE  1=1
			<if test="cpnId != null and cpnId != 0">
		    AND    CP.CPN_ID = #{cpnId}
			</if>
		    AND    CP.SITE_CD = 'G000_10'
		    AND    CP.CPN_STAT = 'G232_11'				-- 진행쿠폰
		    AND    CP.CPN_TYPE = 'G230_30'				-- 배송비쿠폰
		    AND    CCP.USED_DT IS NULL
		    AND    CCP.AVAIL_STDT <![CDATA[<]]> CURRENT_TIMESTAMP
		    AND    CCP.AVAIL_EDDT > CURRENT_TIMESTAMP
		    AND    CT.CUST_NO = #{custNo}
		    AND    CP.APPLY_SCOPE = 'A'
		) Z
		GROUP BY Z.CPN_ID
		       , Z.CPN_NM
		       , Z.CPN_TYPE
		       , Z.DC_WAY
		       , Z.DC_VAL
		       , Z.MAX_DC_AMT
		       , Z.BUY_LIMIT_AMT
		       , Z.CUST_CPN_SQ
		       , Z.APPLY_SCOPE
	</select>

	<!-- 장바구니쿠폰 가능결제수단목록조회 -->
	<select id="getCartCpnPaytypeList" parameterType="Order" resultType="String">
		/* TscOrder.getCartCpnPaytypeList */
		SELECT CPP.PAY_TYPE
		FROM   TB_COUPON CP
		INNER  JOIN TB_COUPON_PAYTYPE CPP
		ON     CP.CPN_ID = CPP.CPN_ID
		WHERE  1=1
		AND    CP.CPN_ID = #{cpnId}
		AND    CP.CPN_TYPE = 'G230_20' -- 장바구니쿠폰
		AND    CP.CPN_ID IN (
		    SELECT CPN_ID
		    FROM   TB_CUST_COUPON
		    WHERE  CUST_NO = #{custNo}
		)
	</select>

	<!-- 구매확정 포인트 지급 -->
	<insert id="createOrderDecisionPoint" parameterType="Order">
		/* TscOrder.createOrderDecisionPoint */
		INSERT INTO TB_CUST_POINT (
		       CUST_NO
		     , GV_PNT_AMT
		     , US_PNT_AMT
		     , RM_PNT_AMT
		     , EXP_BE_DT
		     , EXP_CMP_DT
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT O.CUST_NO
		     , OD.SAVE_PNT_AMT
		     , 0
		     , OD.SAVE_PNT_AMT
		     , DATE_FORMAT(CONCAT(DATE_ADD(CURRENT_DATE, INTERVAL 1 YEAR), ' 23:59:59'), '%Y-%m-%d %H:%i:%S')
		     , NULL
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		  FROM TB_ORDER O
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON O.ORD_NO = OD.ORD_NO
		 WHERE OD.ORD_DTL_NO IN
		<foreach collection="ordDtlNoArr" item="item" index="index"  open="(" close=")" separator=",">
			#{item}
		</foreach>
	</insert>

	<select id="getKcpOrderPaymentInfo" parameterType="Payment" resultType="Payment">
		/* TscOrder.getKcpOrderPaymentInfo : PAYMENT 주문 데이터 조회 */
		SELECT PAY_MEANS
		     , PG_GB
		     , ORD_NO
		     , PG_TID
		     , PG_SHOP_ID
		     , PAY_STAT
		     , CARD_TYPE
		     , CARD_KIND
		     , CARD_BANK
		     , CARD_NM
		     , CARD_MIPS
		     , CARD_PCABLE_YN
		     , VA_NO
		     , VA_NM
		     , VA_BANK
		     , DATE_FORMAT(VA_DEADLINE, '%Y%m%d%H%i%S') AS VA_DEADLINE
		     , TELECOM
		     , PAY_AMT
		FROM   TB_PAYMENT PAY
		WHERE  PG_TID = #{pgTid}
		<choose>
			<when test="payGb != null and payGb != ''">
		AND    PAY_GB = #{payGb}
			</when>
			<otherwise>
		AND    PAY_GB = 'O'
			</otherwise>
		</choose>
		AND    PAY_STAT IN ('G016_30', 'G016_10')
	</select>

	<!-- 결제 취소 정보 생성 -->
	<insert id="insertPaymentCancel" parameterType="Payment" keyProperty="paySq">
		/* TscOrder.insertPaymentCancel : 결제 취소 정보 생성 */
		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_CD
		     , CARD_NM
		     , COM_CARD_CD
		     , CARD_MIPS
		     , CARD_PCABLE_YN
		     , VA_NO
		     , VA_NM
		     , VA_BANK
		     , VA_DEADLINE
		     , TELECOM
		     , ORD_CHG_SQ
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT )
		SELECT ORD_NO
		     , NOW()
		     , PAY_MEANS
		     , #{payAmt}
		     , #{pgCpnAmt}
		     , #{npayPntAmt}
		     , #{payGb}
		     , #{payStat}
		     , PG_GB
		     , #{pgTid}
		     , #{pgTradeNo}
		     , PG_SHOP_ID
		     , CARD_TYPE
		     , CARD_KIND
		     , CARD_BANK
		     , CARD_CD
		     , CARD_NM
		     , COM_CARD_CD
		     , CARD_MIPS
		     , CARD_PCABLE_YN
		     , VA_NO
		     , VA_NM
		     , VA_BANK
		     , VA_DEADLINE
		     , TELECOM
		     , CASE WHEN #{ordChgSq} = 0 THEN NULL ELSE #{ordChgSq} END
		     , #{regNo}
		     , NOW()
		     , #{updNo}
		     , NOW()
		FROM   TB_PAYMENT
		WHERE  1=1
		<choose>
			<when test="payMeans == 'G014_70' || payMeans == 'G014_90'">
		AND    ORD_NO = #{ordNo}
			</when>
			<otherwise>
		AND    PG_TID = #{pgTid}
			</otherwise>
		</choose>
		AND    PAY_GB = IFNULL(NULLIF(#{payGb}, ''), 'O')
		AND    PAY_STAT IN ('G016_30', 'G016_10')
	</insert>

	<!-- PAYMENT INSERT -->
	<insert id="insertPayment" parameterType="Payment" keyProperty="paySq">
		/* TscOrder.insertPayment : PAYMENT INSERT */
		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
		    , PG_SHOP_KEY
		    , CARD_TYPE
		    , CARD_KIND
		    , CARD_BANK
		    , CARD_CD
		    , CARD_NM
		    , COM_CARD_CD
		    , CARD_MIPS
		    , CARD_PCABLE_YN
		    , VA_NO
		    , VA_NM
		    , VA_BANK
		    , VA_DEADLINE
		    , TELECOM
		    , CASH_AUTH_NO
		    , CASH_TRADE_NO
		    , ORD_CHG_SQ
		    , REG_NO
		    , REG_DT
		    , UPD_NO
		    , UPD_DT
		) VALUES (
		      #{ordNo}
		    , NOW()
		    , #{payMeans}
		    , #{payAmt}
		    , #{pgCpnAmt}
		    , #{npayPntAmt}
		    , #{payGb}
		    , #{payStat}
		    , #{pgGb}
		    , #{pgTid}
		    , #{pgTradeNo}
		    , #{pgShopId}
		    , #{pgShopKey}
		    , #{cardType}
		    , #{cardKind}
		    , #{cardBank}
		    , #{cardCd}
		    , #{cardNm}
		    , FN_GET_CARD_CODE(#{pgGb}, #{cardCd})
		    , #{cardMips}
		    , IFNULL(#{cardPcableYn}, 'Y')
		    , #{vaNo}
		    , #{vaNm}
		    , #{vaBank}
		    , DATE_FORMAT(#{vaDeadline} , '%Y%m%d%H%i%S')
		    , #{telecom}
		    , #{cashAuthNo}
		    , #{cashTradeNo}
		    , CASE WHEN #{ordChgSq} = 0 THEN NULL ELSE #{ordChgSq} END
		    , #{regNo}
		    , NOW()
		    , #{updNo}
		    , NOW()
		)
	</insert>

	<!-- 주문번호 조회 -->
	<select id="getOrdChgSqToOrdNo" parameterType="Order" resultType="Order">
		/* TscOrder.getOrdChgSqToOrdNo : 주문번호 조회 */
		SELECT OD.ORD_NO
		FROM   TB_ORDER_CHANGE_DETAIL OCD
		INNER  JOIN TB_ORDER_DETAIL OD
		ON     OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		WHERE  1=1
		AND    ORD_CHG_SQ = #{ordChgSq}
		LIMIT 1
	</select>

	<!-- TB_PAYMENT 결제승인 데이터 -->
	<update id="updatePaymentOrderComplete" parameterType="Payment" keyProperty="paySq">
		/* TscOrder.updatePaymentOrderComplete : TB_PAYMENT 결제승인 데이터 */
		UPDATE TB_PAYMENT SET
		      PAY_DT = CASE WHEN #{payStat} = 'G016_30' THEN NOW() ELSE NULL END
		    , PG_CPN_AMT = #{pgCpnAmt}
		    , NPAY_PNT_AMT = #{npayPntAmt}
		    , PAY_STAT = #{payStat}
		    , PG_TID = #{pgTid}
		    , PG_TRADE_NO = #{pgTradeNo}
		    , PG_SHOP_ID = #{pgShopId}
		    , PG_shop_KEY = #{pgShopKey}
		    , CARD_TYPE = #{cardType}
		    , CARD_KIND = #{cardKind}
		    , CARD_BANK = #{cardBank}
		    , CARD_CD = #{cardCd}
		    , CARD_NM = #{cardNm}
		    , COM_CARD_CD = FN_GET_CARD_CODE(#{pgGb}, #{cardCd})
		    , CARD_MIPS = #{cardMips}
		    , CARD_PCABLE_YN = IFNULL(#{cardPcableYn}, 'Y')
		    , PAY_MEANS = #{payMeans}
		    , VA_NO = #{vaNo}
		    , VA_NM = #{vaNm}
		    , VA_BANK = #{vaBank}
		    , VA_DEADLINE = DATE_FORMAT(#{vaDeadline} , '%Y%m%d%H%i%S')
		    , TELECOM = #{telecom}
		    , CASH_AUTH_NO = #{cashAuthNo}
		    , CASH_TRADE_NO = #{cashTradeNo}
		    , UPD_NO = #{updNo}
		    , UPD_DT = NOW()
		WHERE ORD_NO = #{ordNo}
		AND   PAY_STAT = 'G016_00'
		<if test="ordChgSq != null and ordChgSq > 0">
		AND   ORD_CHG_SQ = #{ordChgSq}
		ORDER BY REG_DT DESC
		LIMIT 1
		</if>
	</update>

	<!-- 결제 상태 수정 -->
	<update id="updatePaymentStat" parameterType="Order">
		/* TscOrder.updatePaymentStat : 결제 상태 수정 */
		UPDATE TB_PAYMENT SET
		       PAY_STAT = #{payStat}
		     , CASH_AUTH_NO = #{cashAuthNo}
		     , CASH_TRADE_NO = #{cashTradeNo}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		     , PAY_DT = NOW()
		WHERE  PG_TID = #{pgTid}
		AND    ORD_NO = #{ordNo}
	</update>

	<!-- 배송비 테이블 결제시퀀스 등록 -->
	<update id="updateDeliveryFeePaySq" parameterType="Payment">
		UPDATE TB_DELIVERY_FEE DF
		INNER  JOIN TB_PAYMENT P
		ON     DF.ORD_NO = P.ORD_NO
		AND    P.PAY_STAT IN ('G016_30', 'G016_10')
		AND    P.PAY_GB = IFNULL(NULLIF(#{payGb}, ''), 'O')
		<if test="ordChgSq != null and ordChgSq != ''">
		AND    DF.ORD_CHG_SQ = P.ORD_CHG_SQ
		</if>
		SET    DF.PAY_SQ = P.PAY_SQ
		     , DF.UPD_NO = #{updNo}
		     , DF.UPD_DT = NOW()
		WHERE  P.ORD_NO = #{ordNo}
		<if test="ordChgSq != null and ordChgSq != ''">
		AND    DF.ORD_CHG_SQ = #{ordChgSq}
		</if>
	</update>

	<!-- 주문정보등록 -->
	<!-- 1. 주문기본정보등록 -->
	<insert id="createOrder" parameterType="Order" keyProperty="ordNo">
		/* TscOrder.createOrder : 주문기본정보등록 */
		INSERT INTO TB_ORDER (
		      MALL_GB
		    , ORD_DT
		    , PAY_DT
		    , CUST_NO
		    , ORD_NM
		    , ORD_PHNNO
		    , ORD_TELNO
		    , ORD_EMAIL
		    , SITE_CD
		    , NPAY_ORD_NO
		    , FRONT_GB
		    , REG_NO
		    , REG_DT
		    , UPD_NO
		    , UPD_DT
		) VALUES (
		      'G011_10'
		    , NOW()
		    , NOW()
		    , #{custNo}
		    , #{custNm}
		    , #{ordPhnno}
		    , #{ordTelno}
		    , #{email}
		    , 'G000_10'
		    , #{npayOrdNo}
		    , #{frontGb}
		    , #{custNo}
		    , NOW()
		    , #{custNo}
		    , NOW()
		)
	</insert>

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

	<!-- 3. 주문배송비정보등록-->
	<insert id="createDeliveryFee" parameterType="Order">
		/* TscOrder.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 (
		      NULL
		    , #{ordNo}
		    , #{delvFeeGb}
		    , #{delvFeeCd}
		    , #{delvFee}
		    , #{delvCpnSq}
		    , #{delvCpnDcAmt}
		    , #{delvGfcdUseAmt}
		    , #{realDelvAmt}
		    , NULL
		    , #{supplyCompCd}
		    , 'N'
		    , NULL
		    , #{custNo}
		    , NOW()
		    , #{custNo}
		    , NOW()
		)
	</insert>

	<!-- 4. 주문상세정보등록-->
	<insert id="createOrderDetail" parameterType="Order" keyProperty="ordDtlNo">
		/* TscOrder.createOrderDetail : 주문상세정보등록 */
		INSERT INTO TB_ORDER_DETAIL (
		       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 #{ordNo}                     AS ORD_NO
		     , #{ordExchGb}                 AS ORD_EXCH_GB
		     , #{ordDtlStat}                AS ORD_DTL_STAT
		     , NULL                         AS ORG_ORD_DTL_NO
		     , G.SUPPLY_COMP_CD             AS SUPPLY_COMP_CD
		     , CA.GOODS_CD                  AS GOODS_CD
		     , CA.DEAL_GOODS_CD             AS DEAL_GOODS_CD
		     , G.FORMAL_GB                  AS FORMAL_GB
		     , G.GOODS_TYPE                 AS GOODS_TYPE
		     , G.LIST_PRICE                 AS LIST_PRICE
		     , G.CURR_PRICE                 AS CURR_PRICE
		     , G.DC_RATE                    AS DC_RATE
		     , #{optAddPrice}               AS OPT_ADD_PRICE
		     , CA.GOODS_QTY                 AS GOODS_QTY
		     , #{ordAmt}                    AS ORD_AMT
		     , 0                            AS CNCL_RTN_QTY
		     , 0                            AS CNCLRTN_AMT
		     , #{cpn1CpnSq}                 AS CPN1_CPN_SQ
		     , #{cpn1DcAmt}                 AS CPN1_DC_AMT
		     , #{tmtb1Sq}                   AS TMTB1_SQ
		     , #{tmtb1DcAmt}                AS TMTB1_DC_AMT
		     , #{tmtb2Sq}                   AS TMTB2_SQ
		     , #{tmtb2DcAmt}                AS TMTB2_DC_AMT
		     , #{goodsCpnSq}                AS GOODS_CPN_SQ
		     , #{goodsCpnDcAmt}             AS GOODS_CPN_DC_AMT
		     , #{cartCpnSq}                 AS CART_CPN_SQ
		     , #{cartCpnDcAmt}              AS CART_CPN_DC_AMT
		     , 0                            AS BURDEN_RATE
		     , #{pntDcAmt}                  AS PNT_DC_AMT
		     , #{prePntDcAmt}               AS PRE_PNT_DC_AMT
		     , #{savePntAmt}                AS SAVE_PNT_AMT
		     , #{realOrdAmt}                AS REAL_ORD_AMT
		     , #{gfcdUseAmt}                AS GFCD_USE_AMT
		     , NULL                         AS VENDOR_ID
		     , NULL                         AS EXTMALL_ID
		     , NULL                         AS AGENT_ORDER_ID
		     , NULL                         AS EXTMALL_ORDER_ID
		     , G.CHANGEABLE_YN              AS CHANGEABLE_YN
		     , G.CHANGE_FEE_FREE_YN         AS CHANGE_FEE_FREE_YN
		     , G.RETURNABLE_YN              AS RETURNABLE_YN
		     , G.RETURN_FEE_FREE_YN         AS RETURN_FEE_FREE_YN
		     , 'N'                          AS SOLDOUT_YN
		     , NULL                         AS SOLDOUT_MEMO
		     , NULL                         AS SOLDOUT_REG_NO
		     , NULL                         AS SOLDOUT_REG_DT
		     , #{delvAddrSq}                AS DELV_ADDR_SQ
		     , DELV_FEE_CD                  AS DELV_FEE_CD
		     , #{shotDelvYn}                AS SHOT_DELV_YN
		     , #{giftPackYn}                AS GIFT_PACK_YN
		     , 'N'                          AS GIFT_ADDR_INP_YN
		     , G.ORDER_MADE_YN              AS MAKE_GOODS_YN
		     , #{entryNo}                   AS ENTRY_NO
		     , CASE WHEN G.SELF_GOODS_YN IN ('Y')
		            THEN NULL
		            ELSE NULL
		            END                     DELV_LOC_CD
		     , NULL                         AS DELV_ASSIGN_DT
		     , 'P'                          AS DELV_ASSIGN_STAT
		     , NULL                         AS DSTRBT_NOTE
		     , NULL                         AS DELV_STDT
		     , NULL                         AS DELV_EDDT
		     , NULL                         AS SHIP_COMP_CD
		     , NULL                         AS INVOICE_NO
		     , 'N'                          AS INVOICE_SEND_YN
		     , NULL                         AS SELL_STORE_CD
		     , G.SELL_FEE_RATE              AS SELL_FEE_RATE
		     , CA.AF_LINK_CD                AS AF_LINK_CD
		     , CA.ITHR_CD                   AS ITHR_CD
		     , CA.CONTENTS_LOC              AS CONTENTS_LOC
		     , CA.PLAN_DTL_SQ               AS PLAN_DTL_SQ
		     , NULL                         AS SOCIAL_SQ
		     , #{custNo}                    AS REG_NO
		     , NOW()                        AS REG_DT
		     , #{custNo}                    AS UPD_NO
		     , NOW()                        AS UPD_DT
		FROM  TB_CART CA
		INNER JOIN TB_GOODS G
		ON    CA.GOODS_CD = G.GOODS_CD
		WHERE 1=1
		AND   CART_SQ = #{cartSq}
	</insert>

	<!-- 5. 주문상세단품정보등록을 위한 조회 -->
	<select id="getOrderDetailItem" parameterType="Order" resultType="Order">
		/* TscOrder.getOrderDetailItem : 주문상세단품정보등록을 위한 조회 */
		SELECT #{ordDtlNo}		                AS ORD_DTL_NO
		     , #{ordNo}		                   AS ORD_NO
		     , #{ordDtlStat}                                AS ORD_DTL_STAT
		     , CD.ITEM_CD
		     , CD.OPT_CD
		     , CD.OPT_CD1
		     , CD.OPT_CD2
		     , CD.SKU_MODEL_NO
		     , CD.PRODUCT_NO
		     , CD.PRODUCT_CODE
		     , G.CURR_PRICE
		     , IFNULL(GC.QTY, 1)                            AS ITEM_QTY
		     , IFNULL(GC.COMPS_CURR_PRICE, G.CURR_PRICE)    AS ITEM_PRICE
		     , OP.ADD_PRICE		               AS OPT_ADD_PRICE
		     , CD.DISP_ORD
		     , 0		                     AS ORD_AMT
		     , 0		                     AS CNCL_RTN_AMT
		     , 0		                     AS CPN1_DC_AMT
		     , 0		                     AS TMTB1_DC_AMT
		     , 0		                     AS TMTB2_DC_AMT
		     , 0		                     AS GOODS_CPN_DC_AMT
		     , 0		                     AS CART_CPN_DC_AMT
		     , 0		                     AS PNT_DC_AMT
		     , 0		                     AS PRE_PNT_DC_AMT
		     , 0		                     AS SAVE_PNT_AMT
		     , 0		                     AS REAL_ORD_AMT
		     , 0		                     AS GFCD_USE_AMT
		FROM   TB_CART_DETAIL CD
		INNER  JOIN TB_CART CA
		ON     CD.CART_SQ = CA.CART_SQ
		INNER  JOIN TB_OPTION OP
		ON     CD.ITEM_CD = OP.GOODS_CD
		AND    CD.OPT_CD = OP.OPT_CD
		INNER  JOIN TB_GOODS G
		ON     CA.GOODS_CD = G.GOODS_CD
		LEFT   OUTER JOIN TB_GOODS_COMPOSE GC
		ON     CD.ITEM_CD = GC.COMPS_GOODS_CD
		AND    CA.GOODS_CD = GC.GOODS_CD
		WHERE 1=1
		AND    CD.CART_SQ = #{cartSq}
	</select>

	<!-- 6. 주문상세단품정보등록 -->
	<insert id="createOrderDetailItem" parameterType="Order" keyProperty="ordDtlItemSq">
		/* TscOrder.createOrderDetailItem : 주문상세단품정보등록 */
		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
		) VALUES (
		      #{ordDtlNo}
		    , #{ordNo}
		    , #{ordDtlStat}
		    , #{itemCd}
		    , #{optCd}
		    , #{optCd1}
		    , #{optCd2}
		    , #{skuModelNo}
		    , #{productNo}
		    , #{productCode}
		    , #{itemQty}
		    , #{itemPrice}
		    , #{optAddPrice}
		    , #{dispOrd}
		    , #{ordAmt}
		    , #{cnclRtnAmt}
		    , #{cpn1DcAmt}
		    , #{tmtb1DcAmt}
		    , #{tmtb2DcAmt}
		    , #{goodsCpnDcAmt}
		    , #{cartCpnDcAmt}
		    , #{pntDcAmt}
		    , #{prePntDcAmt}
		    , #{savePntAmt}
		    , #{realOrdAmt}
		    , #{gfcdUseAmt}
		    , #{custNo}
		    , NOW()
		    , #{custNo}
		    , NOW()
		)
	</insert>

	<!-- 7. 주문상세단품이력정보 등록 -->
	<insert id="createOrderDetailItemHst" parameterType="Order">
		/* TscOrder.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
		     , 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 ODI.ORD_DTL_NO = OD.ORD_DTL_NO
		 WHERE 1=1
		   AND ODI.ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
	</insert>

	<!-- 8. 주문사은품 마스터 정보 등록 -->
	<insert id="createOrdFreegift" parameterType="Order">
		/* TscOrder.createOrdFreegift */
		INSERT INTO TB_ORD_FREEGIFT (
		       ORD_NO
		     , FREEGIFT_SQ
		     , DEL_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT #{ordNo}
		     , FG.FREEGIFT_SQ
		     , 'N'
		     , #{custNo}
		     , NOW()
		     , #{custNo}
		     , NOW()
		FROM   TB_FREEGIFT_VAL FGV
		INNER  JOIN TB_FREEGIFT FG
		ON     FGV.FREEGIFT_SQ = FG.FREEGIFT_SQ
		WHERE  1=1
		AND    FREEGIFT_VAL_SQ IN
		<foreach collection="freegiftValArr" item="item" index="index"  open="(" close=")" separator=",">
			#{item}
		</foreach>
		GROUP  BY FREEGIFT_SQ
	</insert>

	<!-- 9. 주문사은품 상품 정보 등록 -->
	<insert id="createOrdFreegiftVal" parameterType="Order">
		/* TscOrder.createOrdFreegiftVal */
		INSERT INTO TB_ORD_FREEGIFT_VAL (
		       ORD_FREEGIFT_SQ
		     , ORD_NO
		     , FREEGIFT_SQ
		     , FREEGIFT_VAL_SQ
		     , ORD_DTL_STAT
		     , USE_POINT
		     , ITEM_QTY
		     , PRODUCT_NO
		     , PRODUCT_CODE
		     , BRAND_CD
		     , DEL_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT OFG.ORD_FREEGIFT_SQ
		     , #{ordNo}
		     , FGV.FREEGIFT_SQ
		     , FGV.FREEGIFT_VAL_SQ
		     , #{ordDtlStat}
		     , CASE WHEN FG.ALL_YN IN ('Y')
		            THEN 0
		            ELSE FGV.USE_POINT
		            END USE_POINT
		     , FGV.ITEM_QTY
		     , FGV.PRODUCT_NO
		     , FRG.PRODUCT_CODE
		     , FRG.BRAND_CD
		     , 'N'
		     , #{custNo}
		     , NOW()
		     , #{custNo}
		     , NOW()
		FROM   TB_FREEGIFT_VAL FGV
		INNER  JOIN TB_FREEGIFT FG
		ON     FGV.FREEGIFT_SQ = FG.FREEGIFT_SQ
		INNER  JOIN TB_FREE_GOODS FRG
		ON     FGV.PRODUCT_NO = FRG.PRODUCT_NO
		INNER  JOIN TB_ORD_FREEGIFT OFG
		ON     FGV.FREEGIFT_SQ = OFG.FREEGIFT_SQ
		WHERE  1=1
		AND    OFG.ORD_NO = #{ordNo}
		AND    FGV.FREEGIFT_VAL_SQ IN
		<foreach collection="freegiftValArr" item="item" index="index"  open="(" close=")" separator=",">
			#{item}
		</foreach>
	</insert>

	<!-- 10. 주문사은품 주문상세 정보 등록 -->
	<insert id="createOrdFreegiftDtl" parameterType="Order">
		/* TscOrder.createOrdFreegiftDtl */
		INSERT INTO TB_ORD_FREEGIFT_DTL (
		       ORD_FREEGIFT_SQ
		     , FREEGIFT_SQ
		     , ORD_NO
		     , ORD_DTL_NO
		     , DEL_YN
		     , REG_NO
		     , REG_DT
		     , UPD_NO
		     , UPD_DT
		)
		SELECT OFR.ORD_FREEGIFT_SQ
		     , OFR.FREEGIFT_SQ
		     , OD.ORD_NO
		     , OD.ORD_DTL_NO
		     , 'N'
		     , #{custNo}
		     , NOW()
		     , #{custNo}
		     , NOW()
		FROM   TB_ORDER_DETAIL OD
		INNER  JOIN TB_ORD_FREEGIFT OFR
		ON     OD.ORD_NO = OFR.ORD_NO
		INNER  JOIN TB_ORD_FREEGIFT_VAL OFV
		ON     OFR.ORD_FREEGIFT_SQ = OFV.ORD_FREEGIFT_SQ
		WHERE  1=1
		AND    OD.GOODS_CD = #{goodsCd}
		AND    OFR.FREEGIFT_SQ = #{freegiftSq}
		AND    OD.ORD_NO = #{ordNo}
		GROUP  BY OD.ORD_DTL_NO
		     , OFR.FREEGIFT_SQ
		     , OFR.ORD_FREEGIFT_SQ
	</insert>

	<!-- 31. 주문정보 결제완료 상태 업데이트 -->
	<update id="updateOrder" parameterType="Order">
		UPDATE TB_ORDER
		SET    PAY_DT = NOW()
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    ORD_NO = #{ordNo}
	</update>

	<!-- 31. 주문정보 결제완료 상태 업데이트 -->
	<update id="updateOrderPayDtNull" parameterType="Order">
		UPDATE TB_ORDER
		SET    PAY_DT = NULL
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    ORD_NO = #{ordNo}
	</update>

	<!-- 32. 주문상세정보 결제완료 상태 업데이트 -->
	<update id="updateOrderDetail" parameterType="Order">
		UPDATE TB_ORDER_DETAIL
		SET    ORD_DTL_STAT = #{ordDtlStat}
		     , FIRST_ORD_DTL_NO = ORD_DTL_NO
			<if test="payMeans == 'G014_20' and ordDtlStat == 'G013_20'">
		     , SHOT_DELV_YN = CASE WHEN SHOT_DELV_YN = 'Y' AND DATE_FORMAT(NOW(), '%Y-%m-%d') <![CDATA[<>]]> DATE_FORMAT(REG_DT, '%Y-%m-%d') THEN 'N' 
		                           WHEN SHOT_DELV_YN = 'Y' AND DATE_FORMAT(NOW(), '%H') <![CDATA[>]]> 10 THEN 'N'
		                           ELSE SHOT_DELV_YN
		                       END
			</if>
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    ORD_NO = #{ordNo}
	</update>

	<!-- 주문상세이력 생성-->
	<insert id="createOrderDetailAllHst" parameterType="Order">
		/* Order.createOrderDetailAllHst */
		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
		     , 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
		     , #{custNo}
		     , NOW()
		     , #{custNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL
		 WHERE ORD_NO = #{ordNo}
	</insert>

	<!-- 33. 주문상세아이템정보 결제완료 상태 업데이트 -->
	<update id="updateOrderDetailItem" parameterType="Order">
		UPDATE TB_ORDER_DETAIL_ITEM
		SET    ORD_DTL_STAT = #{ordDtlStat}
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    ORD_NO = #{ordNo}
	</update>

	<!-- 33.1 주문상세단품전체 이력정보 등록 -->
	<insert id="createOrderDetailItemAllHst" parameterType="Order">
		/* TscOrder.createOrderDetailItemAllHst */
		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
		     , #{custNo}
		     , NOW()
		     , #{custNo}
		     , NOW()
		  FROM TB_ORDER_DETAIL_ITEM ODI
		 INNER JOIN TB_ORDER_DETAIL OD
		    ON ODI.ORD_DTL_NO = OD.ORD_DTL_NO
		 WHERE 1=1
		   AND ODI.ORD_NO = #{ordNo}
	</insert>

	<!-- 34. 재고정보등록 -->
	<insert id="createSellQty" parameterType="Order">
		/* TscOrder.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
		     , NULL
		     , OD.AGENT_ORDER_ID
		     , OD.EXTMALL_ORDER_ID
		     , ODI.ITEM_QTY * OD.ORD_QTY
		     , #{custNo}
		     , NOW()
		FROM   TB_ORDER_DETAIL_ITEM ODI
		INNER  JOIN TB_ORDER_DETAIL OD
		ON     ODI.ORD_DTL_NO = OD.ORD_DTL_NO
		WHERE  1=1
		AND    ODI.ORD_NO = #{ordNo}
	</insert>

	<!-- 35. 주문상세할인정보조회 -->
	<select id="getOrderDetailDcInfo" parameterType="Order" resultType="Order">
		/* TscOrder.getOrderDetailDcInfo */
		SELECT OD.ORD_NO
		     , OD.ORD_DTL_NO
		     , OD.GOODS_CPN_SQ
		     , OD.CART_CPN_SQ
		     , 0 AS ORD_FREEGIFT_VAL_SQ
		     , OD.PNT_DC_AMT
		     , OD.GFCD_USE_AMT
		     , OD.SAVE_PNT_AMT
		     , 0 AS DELV_CPN_SQ
		     , 0 AS DELV_GFCD_USE_AMT
		FROM   TB_ORDER_DETAIL OD
		WHERE  ORD_NO = #{ordNo}
		UNION  ALL
		SELECT DF.ORD_NO
		     , DF.DELV_FEE_SQ AS ORD_DTL_NO
		     , 0 AS GOODS_CPN_SQ
		     , 0 AS CART_CPN_SQ
		     , 0 AS ORD_FREEGIFT_VAL_SQ
		     , 0 AS PNT_DC_AMT
		     , 0 AS GFCD_USE_AMT
		     , 0 AS SAVE_PNT_AMT
		     , DF.DELV_CPN_SQ
		     , DF.DELV_GFCD_USE_AMT
		FROM   TB_DELIVERY_FEE DF
		WHERE  ORD_NO = #{ordNo}
		UNION  ALL
		SELECT OFV.ORD_NO
		     , 0 AS ORD_DTL_NO
		     , 0 AS GOODS_CPN_SQ
		     , 0 AS CART_CPN_SQ
		     , OFV.ORD_FREEGIFT_VAL_SQ
		     , OFV.USE_POINT AS PNT_DC_AMT
		     , 0 AS GFCD_USE_POINT
		     , 0 AS SAVE_PNT_AMT
		     , 0 AS DELV_CPN_SQ
		     , 0 AS DELV_GFCD_USE_AMT
		FROM   TB_ORD_FREEGIFT_VAL OFV
		WHERE  ORD_NO = #{ordNo}
		AND    OFV.USE_POINT > 0
	</select>

	<!-- 36. 회원포인트정보조회 -->
	<select id="getCustPointInfoList" parameterType="Order" resultType="Order">
		/* TscOrder.getCustPointInfoList */
		SELECT CP.CUST_PNT_SQ
		     , CP.RM_PNT_AMT
		FROM   TB_CUST_POINT CP
		WHERE  1=1
		AND    CP.CUST_NO = #{custNo}
		AND    CP.EXP_BE_DT <![CDATA[ > ]]> NOW()
		AND    CP.EXP_CMP_DT IS NULL
		AND    CP.RM_PNT_AMT > 0
		ORDER  BY CP.EXP_BE_DT ASC
	</select>

	<!-- 37. 회원포인트정보조회 -->
	<select id="getCustGiftcardInfoList" parameterType="Order" resultType="Order">
		/* TscOrder.getCustGiftcardInfoList */
		SELECT CG.CUST_GFCD_SQ
		     , CG.RM_GFCD_AMT
		FROM   TB_CUST_GIFTCARD CG
		WHERE  1=1
		AND    CG.CUST_NO = #{custNo}
		<choose>
			<when test="delvFeeSq != null and delvFeeSq != ''">
		AND    CG.CUST_GFCD_SQ IN (SELECT CUST_GFCD_SQ
		                             FROM TB_CUST_GIFTCARD_HST
		                            WHERE ORD_NO = #{ordNo}
		                              AND OCCUR_GB = 'G074_13')
			</when>
			<otherwise>
		AND    CG.USE_EXP_DATE > NOW()
			</otherwise>
		</choose>
		AND    CG.USE_ST_DATE <![CDATA[<]]> NOW()
		AND    CG.RM_GFCD_AMT > 0
		ORDER  BY CG.USE_EXP_DATE ASC
	</select>

	<!-- 38. 회원포인트정보수정 -->
	<update id="updateCustPoint" parameterType="Order">
		/* TscOrder.updateCustPoint */
		UPDATE TB_CUST_POINT
		SET    US_PNT_AMT = US_PNT_AMT + #{usPntAmt}
		     , RM_PNT_AMT = #{rmPntAmt}
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    CUST_PNT_SQ = #{custPntSq}
		AND    CUST_NO = #{custNo}
	</update>

	<!-- 39. 회원포인트이력등록 -->
	<insert id="createCustPointHst" parameterType="Order">
		/* TscOrder.createCustPointHst */
		INSERT INTO TB_CUST_POINT_HST (
		      CUST_NO
		    , OCCUR_GB
		    , OCCUR_DTL_DESC
		    , PNT_AMT
		    , CUST_PNT_SQ
		    , ORD_FREEGIFT_VAL_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
		) VALUES (
		      #{custNo}
		    , #{occurGb}
		    , #{occurDtlDesc}
		    , #{pntAmt}
		    , #{custPntSq}
		    , #{ordFreegiftValSq}
		    , #{ordNo}
		    , #{ordDtlNo}
		    , #{reviewSq}
		    , NULL
		    , #{pntUploadStat}
		    , NULL
		    , #{custNo}
		    , NOW()
		    , #{custNo}
		    , NOW()
		)
	</insert>

	<!-- 40. 회원상품권정보수정 -->
	<update id="updateCustGiftcard" parameterType="Order">
		/* TscOrder.updateCustGiftcard */
		UPDATE TB_CUST_GIFTCARD
		SET    US_GFCD_AMT = US_GFCD_AMT + #{usGfcdAmt}
		     , RM_GFCD_AMT = #{rmGfcdAmt}
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    CUST_GFCD_SQ = #{custGfcdSq}
		AND    CUST_NO = #{custNo}
	</update>

	<!-- 41. 회원상품권정보이력 등록 -->
	<insert id="createCustGiftcardHst"  parameterType="Order">
		/* TscOrder.createCustGiftcardHst */
		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
		) VALUES (
		      #{custNo}
		    , #{occurGb}
		    , #{occurDtlDesc}
		    , #{gfcdAmt}
		    , #{custGfcdSq}
		    , #{ordNo}
		    , #{ordDtlNo}
		    , #{delvFeeSq}
		    , #{custNo}
		    , NOW()
		    , #{custNo}
		    , NOW()
		)
	</insert>

	<!-- 42. 회원쿠폰 사용처리 -->
	<update id="updateCustCouponUsedDt" parameterType="Order">
		/* TscOrder.updateCustCoupon */
		UPDATE TB_CUST_COUPON
		SET    USED_DT = NOW()
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  CUST_CPN_SQ = #{custCpnSq}
		AND    CUST_NO = #{custNo}
		AND    USED_DT IS NULL
	</update>

	<!-- 43. 사은품 상태값 업데이트 -->
	<update id="updateOrdFreegiftValOrdDtlStat" parameterType="Order">
		/* TscOrder.updateOrdFreegiftValOrdDtlStat */
		UPDATE TB_ORD_FREEGIFT_VAL
		SET    ORD_DTL_STAT = #{ordDtlStat}
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  ORD_NO = #{ordNo}
	</update>

	<!-- 43.1 사은품 남은수량 업데이트 -->
	<update id="updateFreegiftValLeftQty" parameterType="Order">
		/* TscOrder.updateFreegiftValLeftQty */
		UPDATE TB_FREEGIFT_VAL FV
		INNER  JOIN TB_ORD_FREEGIFT_VAL OFV
		ON     FV.FREEGIFT_VAL_SQ = OFV.FREEGIFT_VAL_SQ
		SET    FV.LEFT_QTY = FV.LEFT_QTY - FV.ITEM_QTY
		WHERE  1=1
		AND    OFV.ORD_NO = #{ordNo}
		AND    FV.DEL_YN = 'N'
	</update>

	<!-- 44. 주문상세 결제금액 목록 조회 -->
	<select id="getOrderDetailOrdAmtList"  parameterType="Order" resultType="Order">
		/* TscOrder.getOrderDetailOrdAmtList */
		SELECT A.ORD_DTL_NO
		     , A.LIST_PRICE
		     , A.CURR_PRICE
		     , A.ORD_QTY
		     , A.ORD_AMT
		     , A.REAL_ORD_AMT
		     , A.CPN1_DC_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.SAVE_PNT_AMT
		     , A.DELV_ADDR_SQ
		     , A.GIFT_PACK_YN
		     , A.GOODS_CD
		     , A.GOODS_NM
		     , A.BRAND_GROUP_NM
		     , A.GOODS_TYPE
		     , A.SYS_IMG_NM
		     , A.DELV_FEE_CD_GRP
		     , A.DELV_FEE_CD_GRP_SORT
		     , A.SUPPLY_COMP_CD
		     , A.SUPPLY_COMP_NM
		     , A.DELV_FEE_CD
		     , A.SELF_GOODS_YN
		     , A.ITEMKIND_NM
		     , SUM(A.OPT_ADD_PRICE) AS OPT_ADD_PRICE
		     , GROUP_CONCAT(A.ITEM_NM ORDER BY A.ORD_DTL_ITEM_SQ SEPARATOR '!@!') AS ITEM_NM
		     , GROUP_CONCAT(A.ITEM_CD ORDER BY A.ORD_DTL_ITEM_SQ) AS ITEM_CD
		     , 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
		FROM (
		    SELECT G1.GOODS_CD
		         , FN_GET_GOODS_NM(G1.GOODS_NM, G1.GOODS_GB, G1.FOREIGN_BUY_YN, G1.PARALLEL_IMPORT_YN, G1.ORDER_MADE_YN) AS GOODS_NM
		         , (SELECT CASE WHEN BG.DISP_NM_LANG = 'EN'
		                   THEN BG.BRAND_GROUP_ENM
		                   ELSE BG.BRAND_GROUP_KNM
		                   END  BRAND_GROUP_NM
		            FROM   TB_BRAND BR
		            INNER  JOIN TB_BRAND_GROUP BG
		            ON     BR.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		            WHERE  1=1
		            AND    BR.BRAND_CD = G1.BRAND_CD
		            AND    BG.USE_YN = 'Y') AS BRAND_GROUP_NM
		         , G1.GOODS_TYPE
		         , 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
		         , ODI.ORD_DTL_ITEM_SQ
		         , G2.GOODS_NM AS ITEM_NM
		         , IFNULL((SELECT COLOR_KNM FROM TB_COLOR C WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,'') , G1.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		         , ODI.ITEM_CD
		         , ODI.ITEM_QTY
		         , ODI.OPT_CD
		         , ODI.OPT_CD1
		         , ODI.OPT_CD2
		         , CASE WHEN OD.SHOT_DELV_YN IN ('Y') AND G1.SELF_GOODS_YN IN ('Y') THEN 'SHOT'
		                WHEN OD.SHOT_DELV_YN IN ('N') AND G1.SELF_GOODS_YN IN ('Y') THEN 'WMS'
		                ELSE 'DELV'
		                END  DELV_FEE_CD_GRP
		         , CASE WHEN OD.SHOT_DELV_YN IN ('Y') AND G1.SELF_GOODS_YN IN ('Y') THEN 1
		                WHEN OD.SHOT_DELV_YN IN ('N') AND G1.SELF_GOODS_YN IN ('Y') THEN 2
		                ELSE 3
		                END  DELV_FEE_CD_GRP_SORT
		         , OD.ORD_DTL_NO
		         , OD.LIST_PRICE
		         , OD.CURR_PRICE
		         , ODI.OPT_ADD_PRICE
		         , OD.ORD_QTY
		         , OD.ORD_AMT
		         , OD.REAL_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.PRE_PNT_DC_AMT
		         , OD.PNT_DC_AMT
		         , OD.GFCD_USE_AMT
		         , OD.SAVE_PNT_AMT
		         , OD.DELV_ADDR_SQ
		         , OD.GIFT_PACK_YN
		         , OD.SUPPLY_COMP_CD
		         , (SELECT SUPPLY_COMP_NM
		            FROM   TB_SUPPLY_COMPANY SC
		            WHERE  SC.SUPPLY_COMP_CD = OD.SUPPLY_COMP_CD) AS SUPPLY_COMP_NM
		         , OD.DELV_FEE_CD
		         , G1.SELF_GOODS_YN
		         , IK.ITEMKIND_NM
		    FROM   TB_ORDER_DETAIL OD
		    INNER  JOIN TB_GOODS G1
		    ON     OD.GOODS_CD = G1.GOODS_CD
		    INNER  JOIN TB_ITEMKIND IK
		    ON     G1.ITEMKIND_CD = IK.ITEMKIND_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
		    WHERE  1=1
		    AND    OD.ORD_NO = #{ordNo}
		) A
		GROUP  BY A.ORD_DTL_NO
		     , A.LIST_PRICE
		     , A.CURR_PRICE
		     , A.ORD_QTY
		     , A.ORD_AMT
		     , A.REAL_ORD_AMT
		     , A.CPN1_DC_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.SAVE_PNT_AMT
		     , A.DELV_ADDR_SQ
		     , A.GIFT_PACK_YN
		     , A.GOODS_CD
		     , A.GOODS_NM
		     , A.BRAND_GROUP_NM
		     , A.GOODS_TYPE
		     , A.DELV_FEE_CD_GRP
		     , A.DELV_FEE_CD_GRP_SORT
		     , A.SUPPLY_COMP_CD
		     , A.SUPPLY_COMP_NM
		     , A.SYS_IMG_NM
		     , A.DELV_FEE_CD
		     , A.SELF_GOODS_YN
		     , A.ITEMKIND_NM
		ORDER  BY DELV_FEE_CD_GRP_SORT ASC
		     , A.SUPPLY_COMP_CD ASC
	</select>

	<!-- 44. 주문상세 결제금액 목록 조회 -->
	<select id="getOrderDetailDelvFeeCdGrp"  parameterType="Order" resultType="Order">
		/* TscOrder.getOrderDetailDelvFeeCdGrp */
		SELECT A.DELV_FEE_CD_GRP
		FROM (
		    SELECT CASE WHEN OD.SHOT_DELV_YN IN ('Y') AND G1.SELF_GOODS_YN IN ('Y') THEN 'SHOT'
		                WHEN OD.SHOT_DELV_YN IN ('N') AND G1.SELF_GOODS_YN IN ('Y') THEN 'WMS'
		                ELSE SC.SUPPLY_COMP_NM
		                END  DELV_FEE_CD_GRP
		         , CASE WHEN OD.SHOT_DELV_YN IN ('Y') AND G1.SELF_GOODS_YN IN ('Y') THEN 1
		                WHEN OD.SHOT_DELV_YN IN ('N') AND G1.SELF_GOODS_YN IN ('Y') THEN 2
		                ELSE 3
		                END  DELV_FEE_CD_GRP_SORT
		         , OD.SUPPLY_COMP_CD
		    FROM   TB_ORDER_DETAIL OD
		    INNER  JOIN TB_GOODS G1
		    ON     OD.GOODS_CD = G1.GOODS_CD
		    INNER  JOIN TB_SUPPLY_COMPANY SC
		    ON     OD.SUPPLY_COMP_CD = SC.SUPPLY_COMP_CD
		    WHERE  1=1
		    AND    OD.ORD_NO = #{ordNo}
		) A
		GROUP  BY A.DELV_FEE_CD_GRP
		     , A.DELV_FEE_CD_GRP_SORT
		     , A.SUPPLY_COMP_CD
		ORDER  BY DELV_FEE_CD_GRP_SORT ASC
		     , A.SUPPLY_COMP_CD ASC
	</select>

	<!-- 마이페이지 주문 상태 별 수량 조회 -->
	<select id="getOrderStatCount" parameterType="Order" resultType="Order">
		/* TscOrder.getOrderStatCount */
		SELECT IFNULL(SUM(Z.ORDER_RECEIPT), 0)                          AS ORDER_RECEIPT_COUNT
		     , IFNULL(SUM(Z.DEPOSIT_WAITING), 0)                        AS DEPOSIT_WAITING_COUNT
		     , IFNULL(SUM(Z.WAITING_ADD_PAYMENT), 0)                    AS WAITING_ADD_PAYMENT_COUNT
		     , IFNULL(SUM(Z.PAYMENT_COMPLETE), 0)                       AS PAYMENT_COMPLETE_COUNT
		     , IFNULL(SUM(Z.GOODS_PREPARE), 0)                          AS GOODS_PREPARE_COUNT
		     , IFNULL(SUM(Z.SHIP_PREPARE), 0)                           AS SHIP_PREPARE_COUNT
		     , IFNULL(SUM(Z.SHIPPING), 0)                               AS SHIPPING_COUNT
		     , IFNULL(SUM(Z.SHIP_COMPLETE), 0)                          AS SHIP_COMPLETE_COUNT
		     , IFNULL(SUM(Z.CANCEL_COUNT), 0)                           AS CANCEL_COUNT
		     , IFNULL(SUM(Z.EXCHANGE_COUNT), 0)                         AS EXCHANGE_COUNT
		     , IFNULL(SUM(Z.RETURN_COUNT), 0)                           AS RETURN_COUNT
		     , IFNULL(SUM(Z.CONFIRM_COUNT), 0)                          AS CONFIRM_COUNT
		FROM (SELECT IFNULL(CASE OD.ORD_DTL_STAT WHEN 'G013_00' THEN 1
		                     END, 0) AS ORDER_RECEIPT
		           , IFNULL(CASE OD.ORD_DTL_STAT WHEN 'G013_10' THEN 1
		                     END, 0) AS DEPOSIT_WAITING
		           , IFNULL(CASE OD.ORD_DTL_STAT WHEN 'G013_11' THEN 1
		                     END, 0) AS WAITING_ADD_PAYMENT
		           , IFNULL(CASE OD.ORD_DTL_STAT WHEN 'G013_20' THEN 1
		                     END, 0) AS PAYMENT_COMPLETE
		           , IFNULL(CASE OD.ORD_DTL_STAT WHEN 'G013_30' THEN 1
		                     END, 0) AS GOODS_PREPARE
		           , IFNULL(CASE OD.ORD_DTL_STAT WHEN 'G013_35' THEN 1
				                  WHEN 'G013_40' THEN 1
		                     END, 0) AS SHIP_PREPARE
		           , IFNULL(CASE OD.ORD_DTL_STAT WHEN 'G013_50' THEN 1
				                  WHEN 'G013_55' THEN 1
		                     END, 0) AS SHIPPING
		           , IFNULL(CASE WHEN OD.ORD_DTL_STAT = 'G013_60'
		                     AND O.ORD_DT >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 WEEK, '%Y-%m-%d') THEN 1
		                    WHEN OD.ORD_DTL_STAT = 'G013_70'
		                     AND O.ORD_DT >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 WEEK, '%Y-%m-%d') THEN 1
		                     END, 0) AS SHIP_COMPLETE
		           , 0               AS CANCEL_COUNT
		           , 0               AS EXCHANGE_COUNT
		           , 0               AS RETURN_COUNT
		           , 0               AS CONFIRM_COUNT
		        FROM TB_ORDER O
		       INNER JOIN TB_ORDER_DETAIL OD
		          ON O.ORD_NO = OD.ORD_NO
		         AND OD.ORD_QTY - OD.CNCL_RTN_QTY > 0
		      <where>
		         <choose>
		             <when test='custNo > 0'>
		         AND O.CUST_NO  = #{custNo}
		             </when>
		             <otherwise>
		         AND O.ORD_NO = #{ordNo}
		         AND O.ORD_PHNNO = #{ordPhnno}
		         AND O.ORD_NM = #{ordNm}
		             </otherwise>
		         </choose>
		      </where>
		         AND O.DISP_YN = 'Y'
		         -- AND O.REG_DT > 20210901
		      UNION ALL
		      SELECT 0               AS ORDER_RECEIPT
		           , 0               AS DEPOSIT_WAITING
		           , 0               AS WAITING_ADD_PAYMENT
		           , 0               AS PAYMENT_COMPLETE
		           , 0               AS GOODS_PREPARE
		           , 0               AS SHIP_PREPARE
		           , 0               AS SHIPPING
		           , 0               AS SHIP_COMPLETE
		           , IFNULL(CASE OCD.CHG_STAT WHEN 'G685_10' THEN 1
				                    WHEN 'G685_11' THEN 1
		                     END, 0) AS CANCEL_COUNT
		           , IFNULL(CASE WHEN OCD.CHG_STAT = 'G685_20' THEN 1
		                    WHEN OCD.CHG_STAT = 'G685_21' THEN 1
		                    WHEN OCD.CHG_STAT = 'G685_34' THEN 1
		                    WHEN OCD.CHG_STAT = 'G685_40' AND (OD2.ORD_DTL_STAT IS NOT NULL AND OD2.ORD_DTL_STAT <![CDATA[<>]]> 'G013_60' AND OD2.ORD_DTL_STAT <![CDATA[<>]]> 'G013_70') THEN 1
		                     END, 0) AS EXCHANGE_COUNT
		           , IFNULL(CASE OCD.CHG_STAT WHEN 'G685_50' THEN 1
				                    WHEN 'G685_51' THEN 1
				                    WHEN 'G685_33' THEN 1
		                     END, 0) AS RETURN_COUNT
		           , IFNULL(CASE OCD.CHG_STAT WHEN 'G685_30' THEN 1
				                    WHEN 'G685_31' THEN 1
				                    WHEN 'G685_32' THEN 1
		                     END, 0) AS CONFIRM_COUNT
		        FROM TB_ORDER O
		       INNER JOIN TB_ORDER_DETAIL OD
		          ON O.ORD_NO = OD.ORD_NO
		       INNER JOIN TB_ORDER_CHANGE_DETAIL OCD
		          ON OD.ORD_DTL_NO = OCD.ORD_DTL_NO
		        LEFT OUTER JOIN TB_ORDER_DETAIL OD2
		          ON OCD.CHG_ORD_DTL_NO = OD2.ORD_DTL_NO
		<where>
			<choose>
				<when test='custNo > 0'>
			     AND O.CUST_NO  = #{custNo}
				</when>
				<otherwise>
			     AND O.ORD_NO = #{ordNo}
			     AND O.ORD_PHNNO = #{ordPhnno}
			     AND O.ORD_NM = #{ordNm}
				</otherwise>
			</choose>
		</where>
		         AND O.DISP_YN = 'Y'
		         -- AND O.REG_DT > 20210901
		) AS Z
	</select>

	<!-- 장바구니 구분의 선물하기 여부 판단 -->
	<select id="getGiftOrderCheck" parameterType="Order" resultType="int">
		/* TscOrder.getGiftOrderCheck */
		SELECT COUNT(1) CNT
		FROM   TB_CART CA
		WHERE  1=1
		AND    CA.CART_SQ IN
		<foreach collection="cartSqArr" item="item" index="index"  open="(" close=")" separator=",">
		       #{item}
		</foreach>
		AND    CA.CART_GB = 'G026_GF'
	</select>

	<!-- 선물받기 주문상품 목록 조회 -->
	<select id="getOrderGiftGoodsList" parameterType="Order" resultType="Order">
		/* TscOrder.getOrderGiftGoodsList */
		SELECT Z.ORD_NO
		     , Z.ORD_DTL_NO
		     , Z.BRAND_ENM
		     , Z.BRAND_KNM
		     , Z.GOODS_NM
		     , Z.GOODS_CD
		     , Z.ORD_QTY
		     , Z.CNCL_RTN_QTY
		     , Z.GIFT_PACK_YN
		     , Z.GIFT_ADDR_INP_YN
		     , Z.SYS_IMG_NM
		     , GROUP_CONCAT(Z.ITEM_NM    ORDER BY Z.ORD_DTL_ITEM_SQ SEPARATOR '!@!')    AS ITEM_NM
		     , GROUP_CONCAT(Z.ITEM_CD    ORDER BY Z.ORD_DTL_ITEM_SQ)                    AS ITEM_CD
		     , 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
		     , GROUP_CONCAT(Z.COLOR_NM   ORDER BY Z.ORD_DTL_ITEM_SQ)                    AS COLOR_NM
		     , Z.BRAND_GROUP_NM
		     , Z.GOODS_TYPE
		FROM (
		    SELECT OD.ORD_NO
		         , OD.ORD_DTL_NO
		         , BR.BRAND_ENM
		         , BR.BRAND_KNM
		         , G.GOODS_NM
		         , G.GOODS_CD
		         , CASE WHEN G.GOODS_TYPE != 'G056_S' AND G.SELF_GOODS_YN = 'Y'
		                THEN (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G.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 = G.GOODS_CD AND COLOR_CD = IFNULL(G.MAIN_COLOR_CD,'XX') AND DEFAULT_IMG_YN = 'Y') END AS SYS_IMG_NM
		         , (SELECT GOODS_NM FROM TB_GOODS WHERE GOODS_CD = ODI.ITEM_CD) AS ITEM_NM
		         , IFNULL((SELECT COLOR_KNM FROM TB_COLOR C WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,'') , G.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		         , ODI.ITEM_CD
		         , ODI.OPT_CD
		         , ODI.OPT_CD1
		         , ODI.OPT_CD2
		         , ODI.ITEM_QTY
		         , OD.ORD_QTY
		         , OD.CNCL_RTN_QTY
		         , ODI.ORD_DTL_ITEM_SQ
		         , OD.GIFT_PACK_YN
		         , OD.GIFT_ADDR_INP_YN
		         , (CASE WHEN BG.DISP_NM_LANG = 'EN' THEN BG.BRAND_GROUP_ENM ELSE BG.BRAND_GROUP_KNM END) AS BRAND_GROUP_NM
		         , G.GOODS_TYPE
		    FROM   TB_ORDER_DETAIL OD
		    INNER  JOIN TB_ORDER_DETAIL_ITEM ODI
		    ON     OD.ORD_DTL_NO = ODI.ORD_DTL_NO
		    INNER  JOIN TB_GOODS G
		    ON     OD.GOODS_CD = G.GOODS_CD
		    INNER  JOIN TB_BRAND BR
		    ON     G.BRAND_CD = BR.BRAND_CD
		    INNER  JOIN TB_BRAND_GROUP BG
		    ON     BR.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		    WHERE  1=1
		    AND    OD.ORD_NO = #{ordNo}
		    AND    OD.ORD_DTL_STAT = 'G013_20'
		    AND    OD.ORD_QTY > OD.CNCL_RTN_QTY
		) Z
		GROUP  BY Z.ORD_NO
		     , Z.ORD_DTL_NO
		     , Z.BRAND_ENM
		     , Z.BRAND_KNM
		     , Z.GOODS_NM
		     , Z.GOODS_CD
		     , Z.ORD_QTY
		     , Z.CNCL_RTN_QTY
		     , Z.GIFT_PACK_YN
		     , Z.GIFT_ADDR_INP_YN
		     , Z.BRAND_GROUP_NM
		     , Z.GOODS_TYPE
		     , Z.SYS_IMG_NM
	</select>

	<!-- 선물주문배송신청완료 -->
	<update id="updateOrderDetailGiftAddrInpYn" parameterType="Order">
		/* TscOrder.updateOrderDetailGiftAddrInpYn */
		UPDATE TB_ORDER_DETAIL
		SET    GIFT_ADDR_INP_YN = 'Y'
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  ORD_NO = #{ordNo}
	</update>

	<!-- 추가결제 취소,반품,교환 대상 상품목록 조회 -->
	<select id="getAddPayGoodsList" parameterType="Order" resultType="Order">
		/* TscOrder.getAddPayGoodsList */
		SELECT Z.ORD_NO
		     , Z.ORD_NM
		     , Z.ORD_PHNNO
		     , Z.ORD_DTL_NO
		     , Z.ORD_CHG_SQ
		     , Z.CHG_STAT
		     , Z.CHG_GB
		     , Z.CHG_QTY
		     , Z.ADD_PAY_COST
		     , Z.REFUND_AMT
		     , Z.BRAND_ENM
		     , Z.BRAND_KNM
		     , Z.GOODS_NM
		     , Z.GOODS_CD
		     , Z.CURR_PRICE
		     , Z.CHGER_NM
		     , Z.CHGER_PHNNO
		     , SUM(Z.OPT_ADD_PRICE)		                              AS OPT_ADD_PRICE
		     , GROUP_CONCAT(Z.ITEM_NM    ORDER BY Z.ORD_DTL_ITEM_SQ SEPARATOR '!@!')    AS ITEM_NM
		     , GROUP_CONCAT(Z.ITEM_CD    ORDER BY Z.ORD_DTL_ITEM_SQ)                    AS ITEM_CD
		     , 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
		     , GROUP_CONCAT(Z.COLOR_NM   ORDER BY Z.ORD_DTL_ITEM_SQ)                    AS COLOR_NM
		     , GROUP_CONCAT(Z.SYS_IMG_NM   ORDER BY Z.ORD_DTL_ITEM_SQ)                  AS SYS_IMG_NM
		     , Z.BRAND_GROUP_NM
		FROM (
		    SELECT OD.ORD_NO
		         , OCD.ORD_DTL_NO
		         , OC.ORD_CHG_SQ
		         , OCD.CHG_STAT
		         , BR.BRAND_ENM
		         , BR.BRAND_KNM
		         , G.GOODS_NM
		         , G.GOODS_CD
		         , OCD.CHG_QTY
		         , (SELECT GOODS_NM FROM TB_GOODS WHERE GOODS_CD = ODI.ITEM_CD) AS ITEM_NM
		         , IFNULL((SELECT COLOR_KNM FROM TB_COLOR C WHERE COLOR_CD = IFNULL(NULLIF(ODI.OPT_CD1,'') , G.MAIN_COLOR_CD ) AND USE_YN  = 'Y'), ODI.OPT_CD1) AS COLOR_NM
		         , CASE WHEN G.GOODS_TYPE != 'G056_S' AND G.SELF_GOODS_YN = 'Y' THEN (SELECT MAX(SYS_IMG_NM) FROM TB_GOODS_IMG WHERE GOODS_CD = G.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 = G.GOODS_CD AND COLOR_CD = IFNULL(G.MAIN_COLOR_CD,'XX') AND DEFAULT_IMG_YN = 'Y') END AS SYS_IMG_NM
		         , OD.CURR_PRICE
		         , ODI.ORD_DTL_ITEM_SQ
		         , ODI.OPT_ADD_PRICE
		         , ODI.ITEM_CD
		         , ODI.OPT_CD
		         , ODI.OPT_CD1
		         , ODI.OPT_CD2
		         , ODI.ITEM_QTY
		         , OC.ADD_PAY_COST
		         , RF.REFUND_AMT
		         , OC.CHG_GB
		         , OC.CHGER_NM
		         , OC.CHGER_PHNNO
		         , O.ORD_NM
		         , O.ORD_PHNNO
		         , (CASE WHEN BG.DISP_NM_LANG = 'EN' THEN BG.BRAND_GROUP_ENM ELSE BG.BRAND_GROUP_KNM END) AS BRAND_GROUP_NM
		    FROM   TB_ORDER_CHANGE_DETAIL OCD
		    INNER  JOIN TB_ORDER_CHANGE OC
		    ON     OCD.ORD_CHG_SQ = OC.ORD_CHG_SQ
		    INNER  JOIN TB_ORDER_DETAIL OD
		    ON     OCD.ORD_DTL_NO = OD.ORD_DTL_NO
		    INNER  JOIN TB_ORDER_DETAIL_ITEM ODI
		    ON     ODI.ORD_DTL_NO = OCD.ORD_DTL_NO
		    INNER  JOIN TB_ORDER O
		    ON     OD.ORD_NO = O.ORD_NO
		    INNER  JOIN TB_GOODS G
		    ON     OD.GOODS_CD = G.GOODS_CD
		    INNER  JOIN TB_BRAND BR
		    ON     G.BRAND_CD = BR.BRAND_CD
		    INNER  JOIN TB_BRAND_GROUP BG
		    ON     BR.BRAND_GROUP_NO = BG.BRAND_GROUP_NO
		    LEFT   OUTER JOIN TB_REFUND RF
		    ON     RF.ORD_CHG_SQ = OC.ORD_CHG_SQ
		    WHERE  1=1
		    AND    OC.ADD_PAY_COST <![CDATA[>]]> 0
		    AND    OCD.ORD_CHG_SQ = #{ordChgSq}
		    AND    OCD.CHG_STAT IN ('G685_11', 'G685_21', 'G685_32', 'G685_51')
		    AND    OCD.DEL_YN = 'N'
		) Z
		GROUP  BY Z.ORD_NO
		     , Z.ORD_NM
		     , Z.ORD_PHNNO
		     , Z.ORD_DTL_NO
		     , Z.ORD_CHG_SQ
		     , Z.CHG_STAT
		     , Z.CHG_GB
		     , Z.CHG_QTY
		     , Z.ADD_PAY_COST
		     , Z.REFUND_AMT
		     , Z.BRAND_ENM
		     , Z.BRAND_KNM
		     , Z.GOODS_NM
		     , Z.GOODS_CD
		     , Z.CURR_PRICE
		     , Z.CHGER_NM
		     , Z.CHGER_PHNNO
		     , Z.BRAND_GROUP_NM
	</select>

	<!-- 추가결제 반품,교환 상태값 업데이트 -->
	<update id="updateOrderChangeDetailChgStat" parameterType="Order">
		/* TscOrder.updateOrderChangeDetailChgStat */
		UPDATE TB_ORDER_CHANGE_DETAIL
		SET    CHG_STAT = CASE WHEN CHG_STAT = 'G685_51' THEN 'G685_50'
		                  WHEN CHG_STAT = 'G685_21' THEN 'G685_20'
		                  WHEN CHG_STAT = 'G685_32' THEN 'G685_31'
		                  ELSE CHG_STAT
		                  END
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    ORD_CHG_SQ = #{ordChgSq}
	</update>

	<!-- 추가결제 반품,교환 이력 생성 -->
	<insert id="createOrderChangeDetailHstChgStat" parameterType="Order">
		/* TscOrder.createOrderChangeDetailHstChgStat */
		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
		     , CHG_STAT
		     , CHG_ORD_DTL_NO
		     , WH_MEMO
		     , COMPLETE_DT
		     , DEL_YN
		     , #{custNo}
		     , NOW()
		     , #{custNo}
		     , NOW()
		  FROM TB_ORDER_CHANGE_DETAIL
		 WHERE ORD_CHG_SQ = #{ordChgSq}
	</insert>

	<!-- 주문상세단품 상태값 변경-->
	<update id="updateOrderDetailItemStat" parameterType="Order">
		/* TscOrder.updateOrderDetailItemStat */
		UPDATE TB_ORDER_DETAIL_ITEM
		SET    ORD_DTL_STAT = #{ordDtlStat}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		WHERE  ORD_NO = #{ordNo}
		AND    ORD_DTL_NO = #{ordDtlNo}
	</update>

	<!-- 보증보험 신청 완료 수정 -->
	<update id="updateInsurance" parameterType="Order">
		/* TscOrder.updateInsurance */
		UPDATE TB_INSURANCE SET
		       IF_YN = #{ifYn}
		     , INS_NO = #{insNo}
		     , RESULT_CD = #{resultCd}
		     , RESULT_MSG = #{resultMsg}
		     , REG_DT = NOW()
		 WHERE ORD_NO = #{ordNo}
	</update>

	<!-- 보증보험신청정보등록 -->
	<insert id="createInsurance" parameterType="Order">
		/* TscOrder.createInsurance */
		INSERT INTO TB_INSURANCE (
		      ORD_NO
		    , CUST_NO
		    , BIRTH_GEN
		    , INS_NO
		    , RESULT_CD
		    , RESULT_MSG
		    , REG_DT
		) VALUES (
		      #{ordNo}
		    , #{custNo}
		    , #{birthYmd}
		    , #{insNo}
		    , #{resultCd}
		    , #{resultMsg}
		    , NOW()
		)
	</insert>

	<!-- 보증보험 정보 수정 -->
	<update id="updateInsuranceInfo" parameterType="Order">
		/* TscOrder.updateInsuranceInfo */
		UPDATE TB_INSURANCE SET
		       IF_YN = #{ifYn}
		     , RESULT_CD = #{resultCd}
		     , RESULT_MSG = #{resultMsg}
		WHERE  1=1
		  AND  ORD_NO = #{ordNo}
	</update>

	<!-- 보증보험 정보 조회 -->
	<select id="getInsuranceInfo" parameterType="Order" resultType="Order">
		/* TscOrder.getInsuranceInfo */
		SELECT ORD_NO
		     , CUST_NO
		     , INS_NO
		FROM   TB_INSURANCE
		WHERE  1=1
		AND    IF_YN = 'N'
		AND    RESULT_CD = '0'
		AND    ORD_NO = #{ordNo}
	</select>

	<!-- 상품권 현금영수증 정보 등록 API 결과 -->
	<insert id="createGiftcartReceiptApi" parameterType="GiftCard">
		/* TsfOrder.createGiftcartReceiptApi : 상품권 현금영수증 정보 등록 */
		INSERT INTO TB_GIFTCARD_RECEIPT_API (
		      ORD_NO
		    , TRADE_NO
		    , AUTH_NO
		    , AMT
		    , RESULT_CD
		    , RESULT_MSG
		    , REG_DT
		) VALUES (
		      #{ordNo}
		    , #{tradeNo}
		    , #{authNo}
		    , #{usGfcdAmt}
		    , #{resultCd}
		    , #{resultMsg}
		    , NOW()
		)
	</insert>

	<!-- 사은품 현금영수증 금액 금액 수정 -->
	<update id="updateGiftCardReceipt" parameterType="GiftCard">
		/* TscOrder.updateGiftCardReceipt : 사은품 현금영수증 금액 금액 수정 */
		UPDATE TB_GIFTCARD_RECEIPT SET
		       AMT = AMT + #{usGfcdAmt}
		     , UPD_DT = NOW()
		WHERE  ORD_NO = #{ordNo}
	</update>

	<!-- 상품권 현금영수증 정보 조회 -->
	<select id="getGiftCardReceiptInfo" parameterType="Integer" resultType="GiftCard">
		/* TscOrder.getGiftCardReceiptInfo : 상품권 현금영수증 정보 조회 */
		SELECT GR.ORD_NO
		     , GR.TRADE_NO
		     , GR.AUTH_NO
		     , GR.AMT
		     , DATE_FORMAT(O.ORD_DT,'%Y%m%d%H%i%S') AS TRADE_TIME
		FROM   TB_GIFTCARD_RECEIPT GR
		INNER  JOIN TB_ORDER O
		ON     GR.ORD_NO = O.ORD_NO
		WHERE  GR.ORD_NO = #{ordNo}
	</select>

	<!-- 주문 현금영수증 정보 조회 -->
	<select id="getOrderCashReceiptsInfo" parameterType="Integer" resultType="GiftCard">
		/* TscOrder.getOrderCashReceiptsInfo */
		SELECT P.ORD_NO
		     , P.CASH_TRADE_NO                      AS TRADE_NO
		     , P.CASH_AUTH_NO                       AS AUTH_NO
		     , SUM(P.PAY_AMT)                       AS AMT
		     , DATE_FORMAT(O.ORD_DT,'%Y%m%d%H%i%S') AS TRADE_TIME
		  FROM TB_PAYMENT P
		 INNER JOIN TB_ORDER O
		    ON P.ORD_NO = O.ORD_NO
		 WHERE P.ORD_NO = #{ordNo}
		   AND P.CASH_TRADE_NO IS NOT NULL
		 GROUP BY P.ORD_NO, P.CASH_TRADE_NO, P.CASH_AUTH_NO, O.ORD_DT
	</select>

	<!-- 포인트사용 기준정보 조회 -->
	<select id="getPointUseEnvset" resultType="Order">
		/* TscOrder.getPointUseEnvset : 포인트사용 기준값 조회 */
		SELECT STR_SET_VAL1 AS POINT_USE_ORD_MIN_AMT
		     , STR_SET_VAL2 AS POINT_USE_MAX_LIMIT
		FROM   TB_ENVSET
		WHERE  1=1
		AND    ENVSET_TYPE = 'C17'
		ORDER  BY REG_DT DESC
		LIMIT  1
	</select>

	<!-- 추가결제시 업체명 목록 조회 -->
	<select id="getDelvFeeCdSupplyCompNmList" parameterType="Order" resultType="Order">
		/* TscOrder.getDelvFeeCdSupplyCompNmList : 추가결제시 업체명 목록 조회 */
		SELECT OD.DELV_FEE_CD
		     , SC.SUPPLY_COMP_NM
		FROM   TB_ORDER_DETAIL OD
		INNER  JOIN TB_ORDER_CHANGE_DETAIL OCD
		ON     OD.ORD_DTL_NO = OCD.ORD_DTL_NO
		INNER  JOIN TB_SUPPLY_COMPANY SC
		ON     OD.SUPPLY_COMP_CD = SC.SUPPLY_COMP_CD
		INNER  JOIN TB_GOODS G
		ON     OD.GOODS_CD = G.GOODS_CD
		WHERE  1=1
		AND    OCD.ORD_CHG_SQ = #{ordChgSq}
		AND    G.SELF_GOODS_YN = 'N'
		GROUP  BY OD.DELV_FEE_CD
		     , SC.SUPPLY_COMP_NM
	</select>

	<!-- 주문상세정보 조회 -->
	<select id="getOrdDtlInfo" parameterType="Order" resultType="Order">
		/* TscOrder.getOrdDtlInfo : 주문상세정보 조회 */
		SELECT OD.ORD_NO
			 , OD.ORD_DTL_NO
			 , OD.ORD_DTL_STAT
			 , OD.NPAY_ORD_DTL_NO
			 , OD.INVOICE_NO
			 , OD.SHIP_COMP_CD
			 , OD.INVOICE_SEND_YN
			 , OD.ORD_EXCH_GB
			 , DATE_FORMAT(OD.DELV_STDT,'%Y%m%d%H%i%S') AS DELV_STDT
			 , DATE_FORMAT(OD.DELV_EDDT,'%Y%m%d%H%i%S') AS DELV_EDDT
			 , P.PG_GB
			 , SC.NAVER_PAY_SHIP_COMP_CD
		     , 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'
		LEFT   OUTER JOIN TB_ORDER_CHANGE_DETAIL OCD
		ON     OD.ORD_DTL_NO = OCD.CHG_ORD_DTL_NO
		LEFT   OUTER JOIN TB_SHIP_COMPANY SC
		ON     OD.SHIP_COMP_CD = SC.SHIP_COMP_CD
		WHERE  OD.ORD_DTL_NO = #{ordDtlNo}
	</select>

	<!-- 네이버페이 연동 실패 로그 생성 -->
	<insert id="createNaverPayErrorLog" parameterType="Order">
		/* TscOrder.createNaverPayErrorLog : 네이버페이 연동 실패 로그 생성 */
		INSERT INTO TB_NAVERPAY_FAIL_LOG (
			   ERROR_REASON
			 , OPT_CD
			 , ORD_NO
			 , NPAY_ORD_DTL_NO
			 , RESULT_CD
			 , RESULT_MSG
			 , SITE_CD
			 , ACCESS_LICENSE
			 , SECRET_KEY
			 , REG_NO
			 , REG_DT
		) VALUES (
			   #{errorReason}
			 , #{optCd}
			 , #{ordNo}
			 , #{npayOrdDtlNo}
			 , #{resultCd}
			 , #{resultMsg}
			 , #{mallCd}
			 , #{accessLicense}
			 , #{secretKey}
			 , #{regNo}
			 , NOW()
			 )
	</insert>

	<!-- 2021.06.17 스윗트래커 정보 조회 -->
	<select id="getSweetTrackerDeliveryInfo" parameterType="Order" resultType="Order">
		/* TscOrder.getSweetTrackerDeliveryInfo */
		SELECT TIME_TRANS
		     , DELV_WHERE
		     , DETAILS
		     , IFNULL(TELNO_MAN, TELNO_OFFICE) AS TELNO
		  FROM TB_SWEET_TRACKER
		 WHERE SHIP_COMP_CD = (SELECT SWT_SHIP_COMP_CD
		                    FROM TB_SHIP_COMPANY
		                   WHERE SHIP_COMP_CD = #{shipCompCd}
		                     AND USE_YN = 'Y')
		   AND INVOICE_NO = #{invoiceNo}
		 ORDER BY DELV_LEVEL DESC
	</select>

	<!-- 2021.06.18 선물받기 옵션변경 -->
	<update id="updateOrderDetailItemOpt2" parameterType="Order">
		UPDATE TB_ORDER_DETAIL_ITEM
		SET    OPT_CD2 = #{optCd2}
		     , UPD_NO = #{updNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    ORD_DTL_NO = #{ordDtlNo}
		AND    ORD_DTL_ITEM_SQ = #{ordDtlItemSq}
	</update>

	<!-- 추가배송비 결제금액 환불배송비 수정 처리 -->
	<update id="updateRefundDeliveryFee" parameterType="payment">
		/* TscOrder.updateRefundDeliveryFee */
		UPDATE TB_REFUND
		   SET RF_DELIVERY_FEE = RF_DELIVERY_FEE - #{payAmt}
		 WHERE ORD_CHG_SQ = #{ordChgSq}
	</update>

	<!-- 추가결제정보 -->
	<select id="getAddPaymentInfo" parameterType="Order" resultType="Order">
		/* order.getAddPaymentInfo */
		SELECT P.PAY_SQ
		     , P.ORD_NO
		     , P.PAY_DT
		     , P.PAY_AMT
		     , P.PAY_STAT
		     , P.PAY_GB
		     , P.PG_GB
		     , P.PAY_MEANS
		FROM   TB_PAYMENT P
		WHERE  1=1
		AND    P.PAY_GB = 'D'
		AND    P.PAY_STAT = 'G016_30'
		AND    P.ORD_CHG_SQ = #{ordChgSq}
		LIMIT  1
	</select>

	<!-- 개인통관부호 정보 가져오기 -->
	<select id="getEntryNo" parameterType="Order" resultType="Order">
		/* order.getEntryNoInfo */
		SELECT ENTRY_NO
		FROM   TB_CUST_ENTRY_NO
		WHERE  1=1
		AND    CUST_NO = #{custNo}
		AND    DEL_YN = 'N'
		AND    ENTRY_NO IS NOT NULL
		LIMIT  1
	</select>

	<!-- 주문상세배송중상태변경 -->
	<update id="changedOrdDtlStatDelvStart" parameterType="Order">
		/* order.changedOrdDtlStatDelvStart : 주문상세배송중상태변경 */
		UPDATE TB_ORDER_DETAIL
		SET ORD_DTL_STAT = #{ordDtlStat}
		  , DELV_STDT    = NOW()
		  , UPD_NO       = #{updNo}
		  , UPD_DT       = NOW()
		WHERE 1 = 1
		  AND ORD_NO = #{ordNo}
		  AND ORD_DTL_NO = #{ordDtlNo}
	</update>

	<!-- 2021.09.02 외부몰 결제 여부 정보 체크 -->
	<select id="getExtmallOrderChk" parameterType="Payment" resultType="int">
		/* order.getExtmallOrderChk */
		SELECT COUNT(1)
		FROM   TB_PAYMENT P
		WHERE  1=1
		AND    P.PAY_STAT = 'G016_30'
		AND    P.PG_TID IS NULL
		AND    P.PG_GB <![CDATA[<>]]> 'ISTYLE'
		AND    P.PAY_GB = 'O'
		AND    P.ORD_NO = #{ordNo}
	</select>
	
	<!-- 자동품절취소실패목록 -->
	<select id="getSoldOutCnclFailList" parameterType="Order" resultType="Order">
		/* order.getSoldOutCnclFailList */
		SELECT AA.ORD_NO
		     , AA.ORD_DTL_NO
		     , AA.ORD_CHG_SQ
		     , AA.ORD_DTL_STAT
		     , AA.GOODS_CD
		     , AA.GOODS_NM
		     , GROUP_CONCAT(AA.OPT_CD ORDER BY AA.ORD_DTL_ITEM_SQ) AS OPT_CD
			 , GROUP_CONCAT(AA.OPT_CD1 ORDER BY AA.ORD_DTL_ITEM_SQ) AS OPT_CD1
			 , GROUP_CONCAT(AA.OPT_CD2 ORDER BY AA.ORD_DTL_ITEM_SQ) AS OPT_CD2
		     , AA.ORD_QTY
		     , AA.CNCL_RTN_QTY 
		     , AA.EXCEPTION_QTY
		     , AA.REASON_CD
		     , AA.PAY_MEANS_NM
		     , AA.PG_TID 
		     , DATE_FORMAT(AA.REG_DT,'%Y%m%d%H%i%S') AS REG_DT
		     , DATE_FORMAT(AA.UPD_DT,'%Y%m%d%H%i%S') AS UPD_DT
		     , AA.DELV_FEE_CD
		     , AA.DELV_FEE_CD_GRP
		     , AA.ORD_EXCH_GB
		FROM (
			SELECT OD.ORD_NO
			     , OD.ORD_DTL_NO
			     , OCD.ORD_CHG_SQ
			     , OCD.CHG_STAT AS ORD_DTL_STAT
			     , G.GOODS_CD
			     , G.GOODS_NM
			     , ODI.ORD_DTL_ITEM_SQ 
			     , ODI.OPT_CD
			     , ODI.OPT_CD1
			     , ODI.OPT_CD2
			     , OD.ORD_QTY
			     , OD.CNCL_RTN_QTY 
			     , OCD.CHG_QTY AS EXCEPTION_QTY
			     , FN_GET_CODE_NM('G686', OC.CHG_REASON) AS REASON_CD
			     , CASE WHEN P.PG_GB IN ('KCP') THEN (SELECT CD_NM FROM TB_COMMON_CODE X WHERE X.CD = P.PAY_MEANS)
			            WHEN P.PG_GB IN ('KAKAO') THEN '카카오'
			            WHEN P.PG_GB IN ('NAVER') THEN '네이버'
			            WHEN P.PG_GB IN ('PAYCO') THEN '페이코'
			            ELSE '외부몰입금'
			            END PAY_MEANS_NM  
			     , P.PG_TID 
			     , OD.REG_DT
			     , OD.UPD_DT
			     , OD.DELV_FEE_CD
			     , OD.DELV_FEE_CD AS DELV_FEE_CD_GRP
			     , OD.ORD_EXCH_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.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
			INNER  JOIN TB_GOODS G
			ON     OD.GOODS_CD = G.GOODS_CD
			INNER  JOIN TB_PAYMENT P
			ON     OD.ORD_NO = P.ORD_NO
			AND    P.PAY_GB = 'O'
			WHERE  1=1
			AND    OC.CHG_REASON = 'G686_30'
			AND    OCD.CHG_STAT = 'G685_10'
			<if test='ordNo != null and ordNo != ""'>
			AND    OD.ORD_NO = #{ordNo}
			</if>
			<if test='ordNm != null and ordNm != ""'>
			AND    O.ORD_NM = #{ordNm}
			</if>
			<if test='goodsCd != null and goodsCd != ""'>
			AND    OD.GOODS_CD = #{goodsCd}
			</if>
			<if test='stDate != null and stDate != ""'>
				<if test='searchDateGb != null and searchDateGb == "ordDt"'>
			       AND O.REG_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
			       AND O.REG_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
				</if>
			</if>
			UNION  ALL
			SELECT OD.ORD_NO
			     , OD.ORD_DTL_NO
			     , OCD.ORD_CHG_SQ
			     , OD.ORD_DTL_STAT
			     , G.GOODS_CD
			     , G.GOODS_NM
			     , ODI.ORD_DTL_ITEM_SQ 
			     , ODI.OPT_CD
			     , ODI.OPT_CD1
			     , ODI.OPT_CD2
			     , OD.ORD_QTY
			     , OD.CNCL_RTN_QTY 
			     , A.EXCEPTION_QTY
			     , A.REASON_CD
			     , CASE WHEN P.PG_GB IN ('KCP') THEN (SELECT CD_NM FROM TB_COMMON_CODE X WHERE X.CD = P.PAY_MEANS)
			            WHEN P.PG_GB IN ('KAKAO') THEN '카카오'
			            WHEN P.PG_GB IN ('NAVER') THEN '네이버'
			            WHEN P.PG_GB IN ('PAYCO') THEN '페이코'
			            ELSE '외부몰입금'
			            END PAY_MEANS_NM  
			     , P.PG_TID 
			     , OD.REG_DT
			     , OD.UPD_DT
			     , OD.DELV_FEE_CD
			     , OD.DELV_FEE_CD AS DELV_FEE_CD_GRP
			     , OD.ORD_EXCH_GB
			FROM   TB_ORDER_DETAIL OD
			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 G
			ON     OD.GOODS_CD = G.GOODS_CD
			INNER  JOIN (
				SELECT ODEI.ORD_DTL_NO
				     , ODEI.REASON_CD
				     , ODEI.EXCEPTION_QTY
				FROM   TB_ORDER_DELIVERY_EXCEPTION ODE
				INNER  JOIN TB_ORDER_DELIVERY_EXCEPTION_ITEM ODEI
				ON     ODE.DELIVERY_EXCEPTION_SQ = ODEI.DELIVERY_EXCEPTION_SQ 
				WHERE  1=1
				AND    ODEI.REASON_CD IN ('재고부족')
				AND    ODE.COMPLTED_YN = 'N'
				UNION  ALL
				SELECT OREI.ORDER_DTL_NO AS ORD_DTL_NO
				     , OREI.REASON_CD
				     , OREI.EXCEPTION_QTY
				FROM   TB_ORDER_RECALL_EXCEPTION ORE
				INNER  JOIN TB_ORDER_RECALL_EXCEPTION_ITEM OREI
				ON     ORE.RECALL_EXCEPTION_NO = OREI.RECALL_EXCEPTION_NO
				WHERE  1=1
				AND    OREI.REASON_CODE IN ('08', '10')
				AND    ORE.RECALL_STAT = 'P'
			) A
			ON     OD.ORD_DTL_NO = A.ORD_DTL_NO
			LEFT   JOIN TB_ORDER_CHANGE_DETAIL OCD
			ON     A.ORD_DTL_NO = OCD.ORD_DTL_NO
			INNER  JOIN TB_PAYMENT P
			ON     OD.ORD_NO = P.ORD_NO
			AND    P.PAY_GB = 'O'
			WHERE  1=1
			AND    OCD.ORD_DTL_NO IS NULL
			<if test='ordNo != null and ordNo != ""'>
			AND    OD.ORD_NO = #{ordNo}
			</if>
			<if test='ordNm != null and ordNm != ""'>
			AND    O.ORD_NM = #{ordNm}
			</if>
			<if test='goodsCd != null and goodsCd != ""'>
			AND    OD.GOODS_CD = #{goodsCd}
			</if>
			<if test='stDate != null and stDate != ""'>
				<if test='searchDateGb != null and searchDateGb == "ordDt"'>
			       AND O.REG_DT >= DATE_FORMAT(#{stDate}, '%Y-%m-%d %H:%i:%S')
			       AND O.REG_DT <![CDATA[<]]> DATE_FORMAT(DATE_ADD(#{edDate}, INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%S')
				</if>
			</if>
		) AA
		GROUP  BY AA.ORD_NO
		     , AA.ORD_DTL_NO
		     , AA.ORD_DTL_STAT
		     , AA.ORD_CHG_SQ
		     , AA.GOODS_CD
		     , AA.GOODS_NM
		     , AA.ORD_QTY
		     , AA.CNCL_RTN_QTY 
		     , AA.EXCEPTION_QTY
		     , AA.REASON_CD
		     , AA.PAY_MEANS_NM
		     , AA.PG_TID 
		     , AA.REG_DT
		     , AA.UPD_DT
		     , AA.DELV_FEE_CD
		     , AA.DELV_FEE_CD_GRP
		     , AA.ORD_EXCH_GB
	</select>
	
	<!-- 최근적용한결제정보 -->
	<select id="getCustPaymeans" parameterType="Order" resultType="Order">
		/* TscOrder.getCustPaymeans : 최근적용한결제정보 */
		SELECT PAY_MEANS
		     , PG_GB
		FROM   TB_CUST_PG_GB
		WHERE  1=1
		AND    CUST_NO = #{custNo}
		AND    DEL_YN = 'N'
		LIMIT  1
	</select>
	
	<!-- 최근적용한결제정보 -->
	<select id="getCustPgGb" parameterType="Order" resultType="Order">
		/* TscOrder.getCustPgGb : 최근적용한결제정보 */
		SELECT PAY_MEANS
		     , PG_GB
		FROM   TB_CUST_PG_GB
		WHERE  1=1
		AND    REG_NO = #{custNo}
		LIMIT  1
	</select>
	
	<!-- 자주쓰는결제정보등록 -->
	<insert id="createCustPgGb" parameterType="Order">
		/* TscOrder.createCustPgGb : 자주쓰는결제정보등록 */
		INSERT INTO TB_CUST_PG_GB (
			CUST_NO
			, PG_GB
			, PAY_MEANS
			, DEL_YN
			, REG_NO
			, REG_DT
			, UPD_NO
			, UPD_DT
		) VALUES (
			#{custNo}
			, #{pgGb}
			, #{payMeans}
			, 'N'
			, #{custNo}
			, NOW()
			, #{custNo}
			, NOW()
		)
	</insert>
	
	<!-- 자주쓰는결제정보수정 -->
	<update id="updateCustPgGb" parameterType="Order">
		/* TscOrder.updateCustPgGb : 자주쓰는결제정보수정 */
		UPDATE TB_CUST_PG_GB
		SET    PG_GB = #{pgGb}
		     , PAY_MEANS = #{payMeans}
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    CUST_NO = #{custNo}
	</update>
	
	<!-- 2021.10.25 결제실패정보등록 -->
	<insert id="createPaymentFail" parameterType="Order">
		/* TscOrder.createPaymentFail : 결제실패정보등록 */
		INSERT INTO TB_PAYMENT_FAIL (
			ORD_NO
			, STEP_NO
			, PG_GB
			, ERR_MSG
			, REG_NO
			, REG_DT
		) VALUES (
			#{ordNo}
			, #{stepNo}
			, #{pgGb}
			, #{errMsg}
			, #{regNo}
			, NOW()
		)
	</insert>

	<!-- 출고금지지역 여부 조회 -->
	<select id="getDeliveryBanZipcode" parameterType="Order" resultType="int">
		/* TsfOrder.getDeliveryBanZipcode */
		SELECT COUNT(1) AS CNT
		  FROM TB_DELIVERY_BAN_ZIPCODE
		 WHERE DELV_BAN_ZIPCODE = #{recipZipcode}
		   AND DEL_YN = 'N'
	</select>
	
	<!-- 개인통관부호 정보 가져오기 -->
	<select id="getCustEntryNo" parameterType="Order" resultType="int">
		/* order.getCustEntryNo */
		SELECT COUNT(1)
		FROM   TB_CUST_ENTRY_NO
		WHERE  1=1
		AND    CUST_NO = #{custNo}
		AND    ENTRY_NO = #{entryNo}
		AND    DEL_YN = 'N'
	</select>
	
	<!-- 회원 통관번호 등록 -->
	<insert id="createCustEntryNo" parameterType="Order">
		/* TscOrder.createCustEntryNo : 회원 통관번호 등록 */
		INSERT INTO TB_CUST_ENTRY_NO (
			CUST_NO
			, ENTRY_NO
			, DEL_YN
			, REG_NO
			, REG_DT
			, UPD_NO
			, UPD_DT
		) VALUES (
			#{custNo}
			, #{entryNo}
			, 'N'
			, #{custNo}
			, NOW()
			, #{custNo}
			, NOW()
		)
	</insert>
	
	<!-- 회원 통관번호 수정 -->
	<update id="updateCustEntryNo" parameterType="Order">
		/* TscOrder.updateCustEntryNo : 회원 통관번호 수정 */
		UPDATE TB_CUST_ENTRY_NO
		SET    ENTRY_NO = #{entryNo}
		     , UPD_NO = #{custNo}
		     , UPD_DT = NOW()
		WHERE  1=1
		AND    CUST_NO = #{custNo}
		AND    DEL_YN = 'N'
	</update>
	
</mapper>



