<?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="MdeOrdersMapper">
    <resultMap id="MdeOrders" type="com.wechat.model.dbEntity.MdeOrders">
    <id column="ORDER_ID" jdbcType="VARCHAR" property="orderId" />
    <result column="USER_ID" jdbcType="BIGINT" property="userId" />
    <result column="PAY_TYPE" jdbcType="CHAR" property="payType" />
    <result column="ORDER_SOURCE" jdbcType="CHAR" property="orderSource" />
    <result column="THIRD_PARTY_ORD" jdbcType="VARCHAR" property="thirdPartyOrd" />
    <result column="PKG_ID" jdbcType="INTEGER" property="pkgId" />
    <result column="GOODS_ID" jdbcType="INTEGER" property="goodsId" />
    <result column="IMG" jdbcType="VARCHAR" property="img" />
    <result column="PKG_TITLE" jdbcType="VARCHAR" property="pkgTitle" />
    <result column="PKG_TITLE_EN" jdbcType="VARCHAR" property="pkgTitleEn" />
    <result column="PKG_INTRODUCTION" jdbcType="VARCHAR" property="pkgIntroduction" />
    <result column="VIP_FLAG" jdbcType="VARCHAR" property="vipFlag" />
    <result column="VALIDITY_PERIOD" jdbcType="INTEGER" property="validityPeriod" />
    <result column="SKU_EN" jdbcType="VARCHAR" property="skuEn" />
    <result column="SKU_CN" jdbcType="VARCHAR" property="skuCn" />
    <result column="PRICE" jdbcType="DECIMAL" property="price" />
    <result column="PAYABLE_MONEY" jdbcType="DECIMAL" property="payableMoney" />
    <result column="PAYABLE_FREIGHT" jdbcType="DECIMAL" property="payableFreight" />
    <result column="REAL_FREIGHT" jdbcType="DECIMAL" property="realFreight" />
    <result column="PAY_PRICE" jdbcType="DECIMAL" property="payPrice" />
    <result column="GOODS_NO" jdbcType="VARCHAR" property="goodsNo" />
    <result column="GOODS_NUMS" jdbcType="INTEGER" property="goodsNums" />
    <result column="GOODS_WEIGHT" jdbcType="DECIMAL" property="goodsWeight" />
    <result column="REFUND_NO" jdbcType="DECIMAL" property="refundNo" />
    <result column="DISCOUNT_MONEY" jdbcType="INTEGER" property="discountMoney" />
    <result column="TC_CODE" jdbcType="VARCHAR" property="tcCode" />
    <result column="TD_CODE" jdbcType="VARCHAR" property="tdCode" />
    <result column="ORDER_TIME" jdbcType="TIMESTAMP" property="orderTime" />
    <result column="PAY_TIME" jdbcType="TIMESTAMP" property="payTime" />
    <result column="SEND_TIME" jdbcType="TIMESTAMP" property="sendTime" />
    <result column="INV_TITLE" jdbcType="VARCHAR" property="invTitle" />
    <result column="TAXATION_NO" jdbcType="VARCHAR" property="taxationNo" />
    <result column="LTD_ADD" jdbcType="VARCHAR" property="ltdAdd" />
    <result column="LTD_TEL" jdbcType="VARCHAR" property="ltdTel" />
    <result column="OPENING_BANK" jdbcType="VARCHAR" property="openingBank" />
    <result column="ACCOUNT_NUMBER" jdbcType="VARCHAR" property="accountNumber" />
    <result column="INV_CONTENT" jdbcType="VARCHAR" property="invContent" />
    <result column="INV_MONEY" jdbcType="DECIMAL" property="invMoney" />
    <result column="ADD_ID" jdbcType="INTEGER" property="addId" />
    <result column="RECIPIENT_NAME" jdbcType="VARCHAR" property="recipientName" />
    <result column="RECIPIENT_TEL" jdbcType="VARCHAR" property="recipientTel" />
    <result column="RECIPIENT_ADD" jdbcType="VARCHAR" property="recipientAdd" />
    <result column="ADDR_PROVINCE" jdbcType="VARCHAR" property="addrProvince" />
    <result column="ADDR_CITY" jdbcType="VARCHAR" property="addrCity" />
    <result column="ADDR_AREA" jdbcType="VARCHAR" property="addrArea" />
    <result column="POSTCODE" jdbcType="VARCHAR" property="postcode" />
    <result column="INV_TYPE" jdbcType="CHAR" property="invType" />
    <result column="EXPRESS_NAME" jdbcType="VARCHAR" property="expressName" />
    <result column="EXPRESS_NO" jdbcType="VARCHAR" property="expressNo" />
    <result column="ORD_STATUS" jdbcType="CHAR" property="ordStatus" />
    <result column="DISTRIBUTION_STATUS" jdbcType="CHAR" property="distributionStatus" />
    <result column="POINT" jdbcType="SMALLINT" property="point" />
    <result column="TYPE" jdbcType="CHAR" property="type" />
    <result column="POSTSCRIPT" jdbcType="VARCHAR" property="postscript" />
    <result column="CHANGE_BY" jdbcType="VARCHAR" property="changeBy" />
    <result column="VERSION_NO" jdbcType="INTEGER" property="versionNo" />
    <result column="REMARKS" jdbcType="VARCHAR" property="remarks" />
    <result column="USER_DEL" jdbcType="INTEGER" property="userDel" />
    <result column="DEL_FLAG" jdbcType="INTEGER" property="delFlag" />
    <result column="CREATE_BY" jdbcType="VARCHAR" property="createBy" />
    <result column="CREATE_DATE" jdbcType="TIMESTAMP" property="createDate" />
    <result column="UPDATE_BY" jdbcType="VARCHAR" property="updateBy" />
    <result column="UPDATE_DATE" jdbcType="TIMESTAMP" property="updateDate" />
    <result column="FINISH_TIME" jdbcType="TIMESTAMP" property="finishTime" />
    <result column="SUBHEAD_CN" jdbcType="VARCHAR" property="subheadCn" />
    <result column="SUBHEAD_EN" jdbcType="VARCHAR" property="subheadEn" />
    <result column="PKG_INTRODUCTION_EN" jdbcType="VARCHAR" property="pkgIntroductionEn" />
    <result column="PKG_DETAIL" jdbcType="LONGVARCHAR" property="pkgDetail" />
    <result column="PKG_DETAIL_EN" jdbcType="LONGVARCHAR" property="pkgDetailEn" />
  </resultMap>
  <sql id="Base_Column_List">
    ORDER_ID, USER_ID, PAY_TYPE, ORDER_SOURCE, THIRD_PARTY_ORD, PKG_ID, GOODS_ID, IMG, 
    PKG_TITLE, PKG_TITLE_EN, PKG_INTRODUCTION, PKG_INTRODUCTION_EN, SUBHEAD_CN, SUBHEAD_EN, 
    PKG_DETAIL, PKG_DETAIL_EN, VIP_FLAG, VALIDITY_PERIOD, SKU_EN, SKU_CN, 
    PRICE, PAYABLE_MONEY, PAYABLE_FREIGHT, REAL_FREIGHT, PAY_PRICE, GOODS_NO, GOODS_NUMS, 
    GOODS_WEIGHT, REFUND_NO, DISCOUNT_MONEY, TC_CODE, TD_CODE, ORDER_TIME, PAY_TIME, 
    SEND_TIME, INV_TITLE, TAXATION_NO, LTD_ADD, LTD_TEL, OPENING_BANK, ACCOUNT_NUMBER, 
    INV_CONTENT, INV_MONEY, ADD_ID, RECIPIENT_NAME, RECIPIENT_TEL, RECIPIENT_ADD, ADDR_PROVINCE, 
    ADDR_CITY, ADDR_AREA, POSTCODE, INV_TYPE, EXPRESS_NAME, EXPRESS_NO, ORD_STATUS, DISTRIBUTION_STATUS, 
    POINT, TYPE, POSTSCRIPT, CHANGE_BY, VERSION_NO, REMARKS, USER_DEL, DEL_FLAG, CREATE_BY, 
    CREATE_DATE, UPDATE_BY, UPDATE_DATE, FINISH_TIME
  </sql>
  
  	<sql id="mdeOrdersColumns">
		a.order_id AS "orderId",
		a.user_id AS "userCode",
		a.pay_type AS "payType",
		a.third_party_ord AS "thirdPartyOrd",
		a.pkg_id AS "pkgId",
		a.GOODS_ID AS "goodsId",
		a.IMG as "img",
		a.pkg_title AS "pkgTitle",
		a.pkg_title_en AS "pkgTitleEn",
		a.pkg_introduction AS "pkgIntroduction",
		a.pkg_introduction_en AS "pkgIntroductionEn",
		a.pkg_detail AS "pkgDetail",
		a.pkg_detail_en AS "pkgDetailEn", 
		a.SUBHEAD_CN AS "subheadCn", 
		a.SUBHEAD_EN AS "subheadEn",
		a.VIP_FLAG as "vipFlag",
		a.validity_period AS "validityPeriod",
		a.SKU_CN AS "skuCn",
		a.SKU_EN AS "skuEn",
		a.price AS "price",
		a.payable_money AS "payableMoney",
		a.PAYABLE_FREIGHT AS "payableFreight",
		a.REAL_FREIGHT AS "realFreight",
		a.pay_price AS "payPrice",
		a.GOODS_NO AS "goodsNo",
		a.GOODS_NUMS AS "goodsNums",
		a.GOODS_WEIGHT AS "goodsWeight",
		a.refund_no AS "refundNo",
		a.discount_money AS "discountMoney",
		a.tc_code AS "tcCode",
		a.td_code AS "tdCode",
		a.order_time AS "orderTime",
		a.pay_time AS "payTime",
		a.SEND_TIME AS "sendTime",
		a.inv_title AS "invTitle",
		a.taxation_no AS "taxationNo",
		a.ltd_add AS "ltdAdd",
		a.ltd_tel AS "ltdTel",
		a.opening_bank AS "openingBank",
		a.account_number AS "accountNumber",
		a.inv_content AS "invContent",
		a.inv_money AS "invMoney",
		a.ADD_ID AS "addId",
		a.recipient_name AS "recipientName",
		a.recipient_tel AS "recipientTel",
		a.recipient_add AS "recipientAdd",
		a.ADDR_PROVINCE AS "addrProvince",
		a.ADDR_CITY AS "addrCity",
		a.ADDR_AREA AS "addrArea",
		a.POSTCODE AS "postcode",
		a.finish_time AS "finishTime",
		a.inv_type AS "invType",
		a.express_name AS "expressName",
		a.express_no AS "expressNo",
		a.ord_status AS "ordStatus",
		a.change_by AS "changeBy",
		a.DISTRIBUTION_STATUS AS "distributionStatus",
		a.POINT AS "point",
		a.TYPE AS "type",
		a.POSTSCRIPT AS "postscript",
		a.order_source AS "orderSource",
		a.user_del AS "userDel"
	</sql>
 
	<select id="get" resultType="com.wechat.model.dbEntity.MdeOrders">
		SELECT 
			<include refid="mdeOrdersColumns"/>
		FROM mde_orders a
		WHERE a.order_id =#{orderId}
	</select>
	<select id="getOrderInfoByCode" resultType="com.wechat.model.dbEntity.MdeOrders">
		SELECT 
			<include refid="mdeOrdersColumns"/>
			,b.AVAILABLE_TO as availableTo
		FROM mde_orders a
		LEFT JOIN MDE_TICKET_CATEGORY b
			on  a.TC_CODE = b.TC_CODE																		
		WHERE a.order_id =#{orderId}
			and a.user_id = #{userCode}
			<if test="ordStatus != null">
		        and ORD_STATUS = #{ordStatus}
		    </if>
	</select>
    
	<select id="getValidOrdersByUserCode" resultType="com.wechat.model.dbEntity.MdeOrders">
		SELECT
			<include refid="mdeOrdersColumns"/>
		FROM mde_orders a
		WHERE
			a.user_id = #{userCode} 
			AND a.ord_status = '2' AND a.del_flag = 0 
		ORDER BY
			unix_timestamp( a.finish_time ) DESC 
			LIMIT 1 
	</select>
	
	<select id="findList" resultType="com.wechat.model.dbEntity.MdeOrders">
		SELECT 
			<include refid="mdeOrdersColumns"/>
		FROM mde_orders a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY #{page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="com.wechat.model.dbEntity.MdeOrders">
		SELECT 
			<include refid="mdeOrdersColumns"/>
		FROM mde_orders a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY #{page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findOneByTradeCode" resultType="com.wechat.model.dbEntity.MdeOrders">
		SELECT 
			<include refid="mdeOrdersColumns"/>
		FROM mde_orders a
		where a.DEL_FLAG=0 and a.ORDER_ID=#{out_trade_no} limit 1 
	</select>
 
	<insert id="insertNewOrder">
		INSERT INTO mde_orders(
			order_id,
			user_id,
			order_source,
			order_time,
			ord_status,
			del_flag,
			create_by,
			create_date,
			update_by,
			update_date,
			validity_period,
			SKU_CN,
			SKU_EN,
			vip_flag,
			pkg_id,
			pkg_title,
			pkg_introduction,
			pkg_title_en,
			pkg_introduction_en,
			<if test="invType != '0' and invType != null " >
				INV_TITLE, 
				TAXATION_NO, 
	      		LTD_ADD, 
	      		LTD_TEL, 
	      		OPENING_BANK, 
	      		ACCOUNT_NUMBER, 
	      		INV_CONTENT, 
	      		INV_MONEY, 
	      		RECIPIENT_NAME, 
	      		RECIPIENT_TEL, 
	      		RECIPIENT_ADD, 
      		</if>
      		INV_TYPE,
			price,
			pay_type,
			pay_price,
			discount_money,
			payable_money,
			tc_code,
			td_code
		)  values( 
			#{orderId},
			#{userCode},
			#{orderSource},
			#{orderTime},
			#{ordStatus},
			#{delFlag},
			#{createBy},
			#{createDate},
			#{updateBy},
			#{updateDate},
			#{validityPeriod},
			#{skuCn},
			#{skuEn},
			#{vipFlag},
			#{pkgId},
			#{pkgTitle},
			#{pkgIntroduction},
	        #{pkgTitleEn},
	        #{pkgIntroductionEn},
			<if test="invType != '0' and invType != null " >
				#{invTitle}, 
				#{taxationNo}, 
	      		#{ltdAdd}, 
	      		#{ltdTel}, 
	      		#{openingBank}, 
	      		#{accountNumber}, 
	      		#{invContent}, 
	      		#{invMoney}, 
	      		#{recipientName}, 
	      		#{recipientTel}, 
	      		#{recipientAdd},
      		</if> 
      		#{invType},
			#{price},
			#{payType},
			#{payPrice},
			#{discountMoney},
			#{payableMoney},
			#{tcCode},
			#{tdCode}
		)
	</insert>
	
	<insert id="insert" parameterType="com.wechat.model.dbEntity.MdeOrders">
    insert into mde_orders
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="orderId != null">
        ORDER_ID,
      </if>
      <if test="userCode != null">
        USER_ID,
      </if>
      <if test="payType != null">
        PAY_TYPE,
      </if>
      <if test="orderSource != null">
        ORDER_SOURCE,
      </if>
      <if test="thirdPartyOrd != null">
        THIRD_PARTY_ORD,
      </if>
      <if test="pkgId != null">
        PKG_ID,
      </if>
      <if test="goodsId != null">
        GOODS_ID,
      </if>
      <if test="img != null">
        IMG,
      </if>
      <if test="pkgTitle != null">
        PKG_TITLE,
      </if>
      <if test="pkgTitleEn != null">
        PKG_TITLE_EN,
      </if>
      <if test="pkgIntroduction != null">
        PKG_INTRODUCTION,
      </if>
      <if test="vipFlag != null">
        VIP_FLAG,
      </if>
      <if test="validityPeriod != null">
        VALIDITY_PERIOD,
      </if>
      <if test="skuEn != null">
        SKU_EN,
      </if>
      <if test="skuCn != null">
        SKU_CN,
      </if>
      <if test="price != null">
        PRICE,
      </if>
      <if test="payableMoney != null">
        PAYABLE_MONEY,
      </if>
      <if test="payableFreight != null">
        PAYABLE_FREIGHT,
      </if>
      <if test="realFreight != null">
        REAL_FREIGHT,
      </if>
      <if test="goodsNo != null">
        GOODS_NO,
      </if>
      <if test="goodsNums != null">
        GOODS_NUMS,
      </if>
      <if test="goodsWeight != null">
        GOODS_WEIGHT,
      </if>
      <if test="discountMoney != null">
        DISCOUNT_MONEY,
      </if>
      <if test="tcCode != null">
        TC_CODE,
      </if>
      <if test="tdCode != null">
        TD_CODE,
      </if>
      <if test="orderTime != null">
        ORDER_TIME,
      </if>
      <if test="payTime != null">
        PAY_TIME,
      </if>
      <if test="sendTime != null">
        SEND_TIME,
      </if>
      <if test="invTitle != null">
        INV_TITLE,
      </if>
      <if test="taxationNo != null">
        TAXATION_NO,
      </if>
      <if test="ltdAdd != null">
        LTD_ADD,
      </if>
      <if test="ltdTel != null">
        LTD_TEL,
      </if>
      <if test="openingBank != null">
        OPENING_BANK,
      </if>
      <if test="accountNumber != null">
        ACCOUNT_NUMBER,
      </if>
      <if test="invContent != null">
        INV_CONTENT,
      </if>
      <if test="invMoney != null">
        INV_MONEY,
      </if>
      <if test="recipientName != null">
        RECIPIENT_NAME,
      </if>
      <if test="recipientTel != null">
        RECIPIENT_TEL,
      </if>
      <if test="recipientAdd != null">
        RECIPIENT_ADD,
      </if>
      <if test="addId != null">
        ADD_ID,
      </if>
      <if test="addrProvince != null">
        ADDR_PROVINCE,
      </if>
      <if test="addrCity != null">
        ADDR_CITY,
      </if>
      <if test="addrArea != null">
        ADDR_AREA,
      </if>
      <if test="postcode != null">
        POSTCODE,
      </if>
      <if test="invType != null">
        INV_TYPE,
      </if>
      <if test="expressName != null">
        EXPRESS_NAME,
      </if>
      <if test="expressNo != null">
        EXPRESS_NO,
      </if>
      <if test="ordStatus != null">
        ORD_STATUS,
      </if>
      <if test="distributionStatus != null">
        DISTRIBUTION_STATUS,
      </if>
      <if test="point != null">
        POINT,
      </if>
      <if test="type != null">
        TYPE,
      </if>
      <if test="postscript != null">
        POSTSCRIPT,
      </if>
      <if test="changeBy != null">
        CHANGE_BY,
      </if>
      <if test="remarks != null">
        REMARKS,
      </if>
      <if test="userDel != null">
        USER_DEL,
      </if>
      <if test="createBy != null">
        CREATE_BY,
      </if>
      <if test="createDate != null">
        CREATE_DATE,
      </if>
      <if test="updateBy != null">
        UPDATE_BY,
      </if>
      <if test="updateDate != null">
        UPDATE_DATE,
      </if>
      <if test="finishTime != null">
        FINISH_TIME,
      </if>
      <if test="subheadCn != null">
        SUBHEAD_CN,
      </if>
      <if test="subheadEn != null">
        SUBHEAD_EN,
      </if>
      <if test="pkgIntroductionEn != null">
        PKG_INTRODUCTION_EN,
      </if>
      <if test="pkgDetail != null">
        PKG_DETAIL,
      </if>
      <if test="pkgDetailEn != null">
        PKG_DETAIL_EN,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="orderId != null">
        #{orderId},
      </if>
      <if test="userCode != null">
        #{userCode},
      </if>
      <if test="payType != null">
        #{payType},
      </if>
      <if test="orderSource != null">
        #{orderSource},
      </if>
      <if test="thirdPartyOrd != null">
        #{thirdPartyOrd},
      </if>
      <if test="pkgId != null">
        #{pkgId},
      </if>
      <if test="goodsId != null">
        #{goodsId},
      </if>
      <if test="img != null">
        #{img},
      </if>
      <if test="pkgTitle != null">
        #{pkgTitle},
      </if>
      <if test="pkgTitleEn != null">
        #{pkgTitleEn},
      </if>
      <if test="pkgIntroduction != null">
        #{pkgIntroduction},
      </if>
      <if test="vipFlag != null">
        #{vipFlag},
      </if>
      <if test="validityPeriod != null">
        #{validityPeriod},
      </if>
      <if test="skuEn != null">
        #{skuEn},
      </if>
      <if test="skuCn != null">
        #{skuCn},
      </if>
      <if test="price != null">
        #{price},
      </if>
      <if test="payableMoney != null">
        #{payableMoney},
      </if>
      <if test="payableFreight != null">
        #{payableFreight},
      </if>
      <if test="realFreight != null">
        #{realFreight},
      </if>
      <if test="goodsNo != null">
        #{goodsNo},
      </if>
      <if test="goodsNums != null">
        #{goodsNums},
      </if>
      <if test="goodsWeight != null">
        #{goodsWeight},
      </if>
      <if test="discountMoney != null">
        #{discountMoney},
      </if>
      <if test="tcCode != null">
        #{tcCode},
      </if>
      <if test="tdCode != null">
        #{tdCode},
      </if>
      <if test="orderTime != null">
        #{orderTime},
      </if>
      <if test="payTime != null">
        #{payTime},
      </if>
      <if test="sendTime != null">
        #{sendTime},
      </if>
      <if test="invTitle != null">
        #{invTitle},
      </if>
      <if test="taxationNo != null">
        #{taxationNo},
      </if>
      <if test="ltdAdd != null">
        #{ltdAdd},
      </if>
      <if test="ltdTel != null">
        #{ltdTel},
      </if>
      <if test="openingBank != null">
        #{openingBank},
      </if>
      <if test="accountNumber != null">
        #{accountNumber},
      </if>
      <if test="invContent != null">
        #{invContent},
      </if>
      <if test="invMoney != null">
        #{invMoney},
      </if>
      <if test="recipientName != null">
        #{recipientName},
      </if>
      <if test="recipientTel != null">
        #{recipientTel},
      </if>
      <if test="recipientAdd != null">
        #{recipientAdd},
      </if>
      <if test="addId != null">
        #{addId},
      </if>
      <if test="addrProvince != null">
        #{addrProvince},
      </if>
      <if test="addrCity != null">
        #{addrCity},
      </if>
      <if test="addrArea != null">
        #{addrArea},
      </if>
      <if test="postcode != null">
        #{postcode},
      </if>
      <if test="invType != null">
        #{invType},
      </if>
      <if test="expressName != null">
        #{expressName},
      </if>
      <if test="expressNo != null">
        #{expressNo},
      </if>
      <if test="ordStatus != null">
        #{ordStatus},
      </if>
      <if test="distributionStatus != null">
        #{distributionStatus},
      </if>
      <if test="point != null">
        #{point},
      </if>
      <if test="type != null">
        #{type},
      </if>
      <if test="postscript != null">
        #{postscript},
      </if>
      <if test="changeBy != null">
        #{changeBy},
      </if>
      <if test="remarks != null">
        #{remarks},
      </if>
      <if test="userDel != null">
        #{userDel},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null">
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null">
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="finishTime != null">
        #{finishTime,jdbcType=TIMESTAMP},
      </if>
      <if test="subheadCn != null">
        #{subheadCn,jdbcType=VARCHAR},
      </if>
      <if test="subheadEn != null">
        #{subheadEn,jdbcType=VARCHAR},
      </if>
      <if test="pkgIntroductionEn != null">
        #{pkgIntroductionEn},
      </if>
      <if test="pkgDetail != null">
        #{pkgDetail},
      </if>
      <if test="pkgDetailEn != null">
        #{pkgDetailEn},
      </if>
    </trim>
  </insert>
	
	
<!-- 	<update id="update">
		UPDATE mde_orders SET 	
			<if test="userCode!=null">user_id = #{userCode},                      </if>
			<if test="payType!=null">pay_type = #{payType},                      </if>
			<if test="thirdPartyOrd!=null">third_party_ord = #{thirdPartyOrd},         </if>
			<if test="pkgId!=null">pkg_id = #{pkgId},                          </if>
			<if test="pkgTitle!=null">pkg_title = #{pkgTitle},                    </if>
			<if test="pkgIntroduction!=null">pkg_introduction = #{pkgIntroduction},      </if>
			<if test="validityPeriod!=null">validity_period = #{validityPeriod},        </if>
			<if test="price!=null">price = #{price},                           </if>
			<if test="payPrice!=null">pay_price = #{payPrice},                    </if>
			<if test="finishTime!=null">finish_time = #{finishTime},                    </if>
			<if test="refundNo!=null">refund_no = #{refundNo},                    </if>
			<if test="payTime!=null">pay_time = #{payTime},                      </if>
			<if test="invTitle!=null">inv_title = #{invTitle},                    </if>
			<if test="taxationNo!=null">taxation_no = #{taxationNo},                </if>
			<if test="ltdAdd!=null">ltd_add = #{ltdAdd},                        </if>
			<if test="ltdTel!=null">ltd_tel = #{ltdTel},                        </if>
			<if test="openingBank!=null">opening_bank = #{openingBank},              </if>
			<if test="accountNumber!=null">account_number = #{accountNumber},          </if>
			<if test="invContent!=null">inv_content = #{invContent},                </if>
			inv_money = payable_money,
			<if test="recipientName!=null">recipient_name = #{recipientName},          </if>
			<if test="recipientTel!=null">recipient_tel = #{recipientTel},            </if>
			<if test="recipientAdd!=null">recipient_add = #{recipientAdd},            </if>
			<if test="invType!=null">inv_type = #{invType},                      </if>
			<if test="vipFlag!=null">vip_flag = #{vipFlag},                      </if>
			<if test="expressName!=null">express_name = #{expressName},              </if>
			<if test="expressNo!=null">express_no = #{expressNo},                  </if>
			<if test="ordStatus!=null">ord_status = #{ordStatus},                  </if>
			<if test="changeBy!=null">change_by = #{changeBy},                    </if>
			<if test="remarks!=null">remarks = #{remarks},                       </if> 
			<if test="updateBy!=null">update_by = #{updateBy},                    </if>
			<if test="updateDate!=null">update_date = #{updateDate},                </if>
			<if test="orderSource!=null">order_source = #{orderSource},                </if>
			<if test="userDel!=null">user_del = #{userDel},                 </if>
			<if test="discountMoney">discount_money = #{discountMoney},                 </if>
			<if test="payableMoney">payable_money = #{payableMoney},                 </if>
			<if test="tcCode!=null">tc_code = #{tcCode},                 </if>
			<if test="tdCode!=null">td_code = #{tdCode},                 </if>
			version_no = version_no+1 
		WHERE order_id =#{orderId} <if test="versionNo!=null">and version_no = #{versionNo}</if>
	</update>  -->
	
	<update id="delete">
		UPDATE mde_orders SET 
			del_flag = #{DEL_FLAG_DELETE},
			version_no = #{versionNo}+1
		WHERE order_id =#{orderId} <if test="versionNo!=null">and version_no = #{versionNo}</if>
	</update>
	
	<delete id="deleteOrderByUser">
		delete from mde_orders
		WHERE order_id = #{orderId}
		  and user_id = #{userCode}
	</delete>
	
	<select id="getBuyRecord" resultType="com.wechat.model.dto.OrderListDto">
		SELECT 
			a.order_id AS "orderId",
			a.pkg_id AS "pkgId",
			a.GOODS_ID AS "goodsId",
			a.type AS "type",
			a.GOODS_NUMS as "goodsNums",
			a.img as "img",
			<choose>
				<when test=" lang == 'en'.toString() ">
					a.pkg_title_en AS "pkgTitle",
					a.pkg_title_en AS "pkgTitle",
					a.SUBHEAD_EN as "subhead",
					a.pkg_introduction_en AS "pkgIntroduction",
					a.pkg_detail_en AS "pkgDetail",
					a.SKU_EN AS "sku",
				</when>
				<otherwise>
					a.pkg_title AS "pkgTitle",
					a.SUBHEAD_CN as "subhead",
					a.pkg_introduction AS "pkgIntroduction",
					a.pkg_detail AS "pkgDetail",
					a.SKU_CN AS "sku",
				</otherwise>
			</choose>
			a.price AS "price",
			a.pay_price AS "payPrice",
			a.PAYABLE_FREIGHT as "payableFreight",
			a.DISCOUNT_MONEY as "discountMoney",
			a.order_time AS "orderTime",
			a.pay_time AS "payTime",
			a.express_name AS "expressName",
			a.express_no AS "expressNo",
			a.ord_status AS "ordStatus",
			a.user_del AS "userDel",
			a.payable_money AS "payableMoney"
		FROM mde_orders a
		WHERE
			a.del_flag=0 and a.user_id = #{userCode} and user_del = 0
		ORDER BY
			a.CREATE_DATE DESC
	</select>
	 
	<select id="getBuyRecordCount" resultType="java.lang.Integer">
		SELECT 
			count(1)
		FROM mde_orders a
		WHERE 
			a.del_flag=0 and a.user_id = #{userCode} and user_del = 0
		ORDER BY
			a.CREATE_DATE DESC
	</select>
	
	<update id="updateById" parameterType="com.wechat.model.dbEntity.MdeOrders" >
    update mde_orders
    <set>
      <if test="payType != null">
        PAY_TYPE = #{payType,jdbcType=CHAR},
      </if>
      <if test="orderSource != null">
        ORDER_SOURCE = #{orderSource},
      </if>
      <if test="thirdPartyOrd != null">
        THIRD_PARTY_ORD = #{thirdPartyOrd},
      </if>
      <if test="pkgId != null">
        PKG_ID = #{pkgId},
      </if>
      <if test="goodsId != null">
        GOODS_ID = #{goodsId},
      </if>
      <if test="img != null">
        IMG = #{img},
      </if>
      <if test="pkgTitle != null">
        PKG_TITLE = #{pkgTitle},
      </if>
      <if test="pkgTitleEn != null">
        PKG_TITLE_EN = #{pkgTitleEn},
      </if>
      <if test="pkgIntroduction != null">
        PKG_INTRODUCTION = #{pkgIntroduction},
      </if>
      <if test="vipFlag != null">
        VIP_FLAG = #{vipFlag},
      </if>
      <if test="validityPeriod != null">
        VALIDITY_PERIOD = #{validityPeriod},
      </if>
      <if test="skuEn != null">
        SKU_EN = #{skuEn},
      </if>
      <if test="skuCn != null">
        SKU_CN = #{skuCn},
      </if>
      <if test="price != null">
        PRICE = #{price},
      </if>
      <if test="payableMoney != null">
        PAYABLE_MONEY = #{payableMoney},
      </if>
      <if test="payableFreight != null">
        PAYABLE_FREIGHT = #{payableFreight},
      </if>
      <if test="realFreight != null">
        REAL_FREIGHT = #{realFreight},
      </if>
      <if test="payPrice != null">
        PAY_PRICE = #{payPrice},
      </if>
      <if test="goodsNo != null">
        GOODS_NO = #{goodsNo},
      </if>
      <if test="goodsNums != null">
        GOODS_NUMS = #{goodsNums},
      </if>
      <if test="goodsWeight != null">
        GOODS_WEIGHT = #{goodsWeight},
      </if>
      <if test="refundNo != null">
        REFUND_NO = #{refundNo},
      </if>
        DISCOUNT_MONEY = #{discountMoney},
        TC_CODE = #{tcCode},
        TD_CODE = #{tdCode},
      <if test="orderTime != null">
        ORDER_TIME = #{orderTime},
      </if>
      <if test="payTime != null">
        PAY_TIME = #{payTime},
      </if>
      <if test="sendTime != null">
        SEND_TIME = #{sendTime},
      </if>
      <if test="invTitle != null">
        INV_TITLE = #{invTitle},
      </if>
      <if test="taxationNo != null">
        TAXATION_NO = #{taxationNo},
      </if>
     	LTD_ADD = #{ltdAdd},
        LTD_TEL = #{ltdTel},
        OPENING_BANK = #{openingBank},
        ACCOUNT_NUMBER = #{accountNumber},
      <if test="invContent != null">
        INV_CONTENT = #{invContent},
      </if>
      <if test="invMoney != null">
        INV_MONEY = #{invMoney},
      </if>
      <if test="recipientName != null">
        RECIPIENT_NAME = #{recipientName},
      </if>
      <if test="recipientTel != null">
        RECIPIENT_TEL = #{recipientTel},
      </if>
      <if test="recipientAdd != null">
        RECIPIENT_ADD = #{recipientAdd},
      </if>
      <if test="addId != null">
        ADD_ID = #{addId},
      </if>
      <if test="addrProvince != null">
        ADDR_PROVINCE = #{addrProvince},
      </if>
      <if test="addrCity != null">
        ADDR_CITY = #{addrCity},
      </if>
      <if test="addrArea != null">
        ADDR_AREA = #{addrArea},
      </if>
      <if test="postcode != null">
        POSTCODE = #{postcode},
      </if>
      <if test="invType != null">
        INV_TYPE = #{invType},
      </if>
      <if test="expressName != null">
        EXPRESS_NAME = #{expressName},
      </if>
      <if test="expressNo != null">
        EXPRESS_NO = #{expressNo},
      </if>
      <if test="ordStatus != null">
        ORD_STATUS = #{ordStatus},
      </if>
      <if test="distributionStatus != null">
        DISTRIBUTION_STATUS = #{distributionStatus},
      </if>
      <if test="point != null">
        POINT = #{point},
      </if>
      <if test="type != null">
        TYPE = #{type},
      </if>
      <if test="postscript != null">
        POSTSCRIPT = #{postscript},
      </if>
      <if test="changeBy != null">
        CHANGE_BY = #{changeBy},
      </if>
      <if test="remarks != null">
        REMARKS = #{remarks},
      </if>
      <if test="userDel != null">
        USER_DEL = #{userDel},
      </if>
      <if test="updateBy != null">
        UPDATE_BY = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateDate != null">
        UPDATE_DATE = #{updateDate,jdbcType=TIMESTAMP},
      </if>
      <if test="finishTime != null">
        FINISH_TIME = #{finishTime,jdbcType=TIMESTAMP},
      </if>
      <if test="subheadCn != null">
        SUBHEAD_CN = #{subheadCn,jdbcType=VARCHAR},
      </if>
      <if test="subheadEn != null">
        SUBHEAD_EN = #{subheadEn,jdbcType=VARCHAR},
      </if>
      <if test="pkgIntroductionEn != null">
        PKG_INTRODUCTION_EN = #{pkgIntroductionEn,jdbcType=VARCHAR},
      </if>
      <if test="pkgDetail != null">
        PKG_DETAIL = #{pkgDetail,jdbcType=LONGVARCHAR},
      </if>
      <if test="pkgDetailEn != null">
        PKG_DETAIL_EN = #{pkgDetailEn,jdbcType=LONGVARCHAR},
      </if>
      version_no = version_no+1 
    </set>
    WHERE order_id =#{orderId} <if test="versionNo!=null">and version_no = #{versionNo}</if>
		  and user_id = #{userCode}
  </update>
		

  <update id="updatePaidOrder">
	  UPDATE mde_orders SET 	
		<if test="payType!=null">pay_type = #{payType},                      </if>
		<if test="thirdPartyOrd!=null">third_party_ord = #{thirdPartyOrd},   </if>
		<if test="payPrice!=null">pay_price = #{payPrice},                   </if>
		<if test="payTime!=null">pay_time = #{payTime},                      </if>
		<if test="ordStatus!=null">ord_status = #{ordStatus},                </if>
		inv_money = payable_money,
		<if test="finishTime!=null">finish_time = #{finishTime},              </if>
		<if test="updateBy!=null">update_by = #{updateBy},                    </if>
		<if test="updateDate!=null">update_date = #{updateDate},                </if>
		version_no = version_no+1 
		WHERE order_id =#{orderId} <if test="versionNo!=null">and version_no = #{versionNo}</if>
	</update> 
		
	<select id="getBuyTimesOfGoods" resultType="java.lang.Integer">
		SELECT 
			count(1)
		FROM mde_orders
		WHERE 
			del_flag=0 
		and user_id = #{userCode} 
		and GOODS_ID = #{goodsId}
		and TYPE != '0'
		and (ORD_STATUS = '1' or ORD_STATUS = '2' or ORD_STATUS = '5')
	</select>
	
	<select id="getGoodsSaleNums" resultType="java.lang.Integer">
		SELECT 
			count(1)
		FROM mde_orders
		WHERE 
			del_flag=0 
		and GOODS_ID = #{goodsId}
		and (ORD_STATUS = '1' or ORD_STATUS = '2' or ORD_STATUS = '5')
	</select>
	
</mapper>