HotelOrderMapper.xml 11.9 KB
<?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.sibu.orderHelper.hotel.dao.HotelOrderDao">
	    
    <sql id="Add_HotelOrder_column">
    	order_id,member_id,member_name,member_telphone,order_code,order_status,order_money,pay_integral,create_date,
    	checkin_days,renter_info,renter_idcard,renter_phone,check_in_date,
    	check_out_date,room_id,room_name,hotel_id,hotel_name,room_number,order_type 
    </sql>
    <!-- 添加主订单 -->
    <insert id="addMainHotelOrder" parameterType="map">
    	insert into room_order(
    		<include refid="Add_HotelOrder_column"/>
    	)
    	value (
    		#{mainHotelOrder.orderId},
    		#{mainHotelOrder.memberId},
    		#{mainHotelOrder.memberName},
    		#{mainHotelOrder.memberTelphone},
    		#{mainHotelOrder.orderCode},
    		#{mainHotelOrder.orderStatus},
    		#{mainHotelOrder.orderMoney},
    		#{mainHotelOrder.payIntegral},
    		NOW(),
    		#{mainHotelOrder.checkinDays},
    		#{mainHotelOrder.renterInfo},
    		#{mainHotelOrder.renterIdcard},
    		#{mainHotelOrder.renterPhone},
    		#{mainHotelOrder.checkInDate},
    		#{mainHotelOrder.checkOutDate},
    		#{mainHotelOrder.roomId},
    		#{mainHotelOrder.roomName},
    		#{mainHotelOrder.hotelId},
    		#{mainHotelOrder.hotelName},
    		#{mainHotelOrder.roomNumber},
    		#{mainHotelOrder.orderType}
    	)
    </insert>
    <!-- 添加子订单 -->
    <insert id="addSubHotelOrder" parameterType="map">
    	<![CDATA[
		    insert into room_order_detail (
				sub_order_id,sub_order_code,room_id,order_id,room_number,retail_price,
        		integral,checkin_date 
			) values 
		]]>
		<foreach collection="subHotelOrder" item="item" index="index" separator="," >
			(
				#{item.subOrderId},
				#{item.subOrderCode},
				#{item.roomId},
				#{item.orderId},
				#{item.roomNumber},
				#{item.retailPrice},
				#{item.integral},
				#{item.checkinDate}
			)
		</foreach>
	</insert>
	<!-- 删除主订单 -->
	<delete id="deleteMainHotelOrder" parameterType="map">
		delete from room_order where order_id = #{orderId} limit 1 
	</delete>
	<!-- 删除子订单 -->
	<delete id="deleteSubHotelOrder" parameterType="map">
		delete from room_order_detail where order_id = #{orderId} 
	</delete>
	<!-- 取消订单 -->
	<update id="cancelOrder" parameterType="map">
		update room_order set is_delete = 1 where order_id = #{orderId} and member_id = #{memberId}  and order_status = 1 
	</update>
	<!-- 获取支付详情 -->
	<select id="getOrderPayMsgById" resultMap="payOrderDetail" parameterType="map">
		select order_id,member_id,member_telphone,order_code,order_status,order_money,pay_integral,checkin_days,room_id,room_name,hotel_id,hotel_name,room_number,order_type,check_in_date,check_out_date 
		from room_order
		where order_id = #{orderId} and member_id = #{memberId} and is_delete = 0  limit 1 
	</select>
	<select id="getOrderPayMsgByCode" resultMap="payOrderDetail" parameterType="map">
		select order_id,member_id,member_telphone,order_code,order_status,order_money,pay_integral,checkin_days,room_id,room_name,hotel_id,hotel_name,room_number,order_type,check_in_date,check_out_date 
		from room_order
		where order_code = #{orderCode} and is_delete = 0  limit 1 
	</select>
	<resultMap type="com.sibu.orderHelper.hotel.response.HotelOrderPayResponse" id="payOrderDetail">
		<id column="order_id" property="orderId"/>
		<result column="member_id" property="memberId"/>
		<result column="member_telphone" property="memberTelphone"/>
		<result column="order_code" property="orderCode"/>
		<result column="order_status" property="orderStatus"/>
		<result column="order_money" property="orderMoney"/>
		<result column="pay_integral" property="payIntegral"/>
		<result column="checkin_days" property="checkinDays"/>
		<result column="room_id" property="roomId"/>
		<result column="room_name" property="roomName"/>
		<result column="hotel_id" property="hotelId"/>
		<result column="hotel_name" property="hotelName"/>
		<result column="room_number" property="roomNumber"/>
		<result column="order_type" property="orderType"/>
		<result column="check_in_date" property="checkInDate"/>
		<result column="check_out_date" property="checkOutDate"/>
	</resultMap>
	<!-- 获取订单详情 -->
	<select id="getOrderDetailById" resultMap="hotelOrderDetail" parameterType="map">
		select <include refid="Add_HotelOrder_column"/> 
		from room_order
		where order_id = #{orderId} and is_delete = 0 limit 1 
	</select>
	<select id="getOrderDetailByCode" resultMap="hotelOrderDetail" parameterType="map">
		select <include refid="Add_HotelOrder_column"/> 
		from room_order
		where order_code = #{orderCode} and is_delete = 0 limit 1 
	</select>
	<!-- 查询子订单 -->
	<select id="getHotelSubOrderDetail" resultMap="roomSubOrderDetail" parameterType="java.lang.String">
		select * from room_order_detail where sub_order_id = #{subOrderId} limit 1 
	</select>
	<select id="listHotelSubOrders" resultMap="roomSubOrderDetail" parameterType="java.lang.String">
		select * from room_order_detail where order_id = #{orderId}
	</select>
	<resultMap type="com.sibu.orderHelper.hotel.response.HotelSubOrderResponse" id="roomSubOrderDetail">
		<id column="sub_order_id" property="subOrderId"/>
		<result column="room_id" property="roomId"/>
		<result column="sub_order_code" property="subOrderCode"/>
		<result column="order_id" property="orderId"/>
		<result column="room_number" property="roomNumber"/>
		<result column="retail_price" property="retailPrice"/>
		<result column="integral" property="integral"/>
		<result column="checkin_date" property="checkinDate"/>
		<result column="hotel_status" property="hotelStatus"/>
		<result column="status" property="status"/>
	</resultMap>
	<resultMap type="com.sibu.orderHelper.hotel.response.HotelOrderDetailResponse" id="hotelOrderDetail">
		<id column="order_id" property="orderId"/>
		<result column="member_id" property="memberId"/>
		<result column="member_name" property="memberName"/>
		<result column="member_telphone" property="memberTelphone"/>
		<result column="order_code" property="orderCode"/>
		<result column="order_status" property="orderStatus"/>
		<result column="order_money" property="orderMoney"/>
		<result column="pay_integral" property="payIntegral"/>
		<result column="create_date" property="createDate"/>
		<result column="checkin_days" property="checkinDays"/>
		<result column="renter_info" property="renterInfo"/>
		<result column="renter_phone" property="renterPhone"/>
		<result column="check_in_date" property="checkInDate"/>
		<result column="check_out_date" property="checkOutDate"/>
		<result column="room_id" property="roomId"/>
		<result column="room_name" property="roomName"/>
		<result column="hotel_id" property="hotelId"/>
		<result column="hotel_name" property="hotelName"/>
		<result column="room_number" property="roomNumber"/>
		<result column="order_type" property="orderType"/>
	</resultMap>
	<!-- 订单列表 -->
	<select id="listOrder" resultMap="listHotelOrder" parameterType="map">
		select roo.order_id,roo.order_code,roo.order_status,roo.order_money,roo.pay_integral,roo.checkin_days,roo.room_name,
			roo.hotel_id,roo.hotel_name,roo.room_number,roo.order_type,roo.check_in_date,roo.check_out_date,roo.create_date,
			rod.sub_order_id,rod.sub_order_code,rod.room_id,rod.room_number,rod.retail_price,
			rod.integral,rod.checkin_date,rod.hotel_status,rod.status
		from room_order_detail rod, 
		(
			select ro.order_id,ro.order_code,ro.order_status,ro.order_money,ro.pay_integral,ro.checkin_days,ro.room_name,
				ro.hotel_id,ro.hotel_name,ro.room_number,ro.order_type,ro.check_in_date,ro.check_out_date,ro.create_date   
			from room_order ro left join room_order_detail rod1 on ro.order_id = rod1.order_id
			where ro.member_id = #{memberId} and ro.is_delete = 0 
			<if test="orderStatus == 3">
				AND (ro.order_status = 2 OR  ro.order_status = 3) AND (rod1.hotel_status = 0 or rod1.hotel_status = 1) 
			</if>
			<if test="orderStatus == 1">
				AND ro.order_status = 1 
			</if>
			<if test="orderStatus == 4">
				AND (ro.order_status = 2 OR  ro.order_status = 3) AND rod1.hotel_status = 3 
			</if>
			group by rod1.order_id 
			order by ro.create_date desc 
			limit ${pageNow}, ${pageSize} 
		) roo
		where roo.order_id = rod.order_id  
		<if test="orderStatus == 3">
			AND (rod.hotel_status = 0 or rod.hotel_status = 1)
		</if>
		<if test="orderStatus == 4">
			AND rod.hotel_status = 3
		</if>
		order by rod.checkin_date
	</select>
	<select id="countOrder" resultType="int" parameterType="map">
		select count(*) from (select count(*)  
		from room_order ro left join room_order_detail rod on ro.order_id = rod.order_id
		where ro.member_id = #{memberId} and ro.is_delete = 0 
		<if test="orderStatus == 3">
			AND (rod.status = 2 OR rod.status = 3) AND (rod.hotel_status = 0 or rod.hotel_status = 1)
		</if>
		<if test="orderStatus == 1">
			AND ro.order_status = 1 
		</if>
		<if test="orderStatus == 4">
			AND (rod.status = 2 OR rod.status = 3) AND rod.hotel_status = 3
		</if>
		group by ro.order_id) cou
	</select>
	<resultMap type="com.sibu.orderHelper.hotel.response.HotelListOrderResponse" id="listHotelOrder">
		<id column="order_id" property="orderId"/>
		<result column="order_code" property="orderCode"/>
		<result column="order_status" property="orderStatus"/>
		<result column="order_money" property="orderMoney"/>
		<result column="pay_integral" property="payIntegral"/>
		<result column="checkin_days" property="checkinDays"/>
		<result column="room_id" property="roomId"/>
		<result column="room_name" property="roomName"/>
		<result column="hotel_id" property="hotelId"/>
		<result column="hotel_name" property="hotelName"/>
		<result column="room_number" property="roomNumber"/>
		<result column="order_type" property="orderType"/>
		<result column="check_in_date" property="checkInDate"/>
		<result column="check_out_date" property="checkOutDate"/>
		<result column="create_date" property="createDate" />
		<collection property="subOrders" column="order_id" ofType="com.sibu.orderHelper.hotel.response.HotelSubOrderResponse">
			<id column="sub_order_id" property="subOrderId"/>
			<result column="sub_order_code" property="subOrderCode"/>
			<result column="room_id" property="roomId"/>
			<result column="order_id" property="orderId"/>
			<result column="room_number" property="roomNumber"/>
			<result column="retail_price" property="retailPrice"/>
			<result column="integral" property="integral"/>
			<result column="checkin_date" property="checkinDate"/>
			<result column="hotel_status" property="hotelStatus"/>
			<result column="status" property="status"/>
		</collection>
	</resultMap>
	<!-- 更新支付订单状态 -->
	<update id="updateHotelOrderStatus" parameterType="map">
		update room_order set pay_name=#{openId}, transaction_id=#{transactionId}, order_status=#{orderStatus},pay_type=#{payType},pay_date=now()
		where order_code=#{orderCode} and order_status = 1
	</update>
	<!-- 更新子订单状态 -->
	<update id="updateSubOrderStatus" parameterType="map">
		update room_order_detail set status=#{status} where order_id = #{orderId}
	</update>
	<!-- 更新子订单状态,通过子订单ID -->
	<update id="updateSubOrderStatusById" parameterType="java.util.Map">
		update room_order_detail set status=#{status} where sub_order_id = #{subOrderId} 
	</update>
		<!-- 将订单设置为已失效 -->
	<update id="updateOrderExpired" parameterType="java.util.List">
		update room_order set order_status = 8 WHERE order_id in 
		<foreach collection="list" item="item"  open="(" separator="," close=")">  
			#{item} 
		</foreach>
	</update>
	<!-- 添加退款记录 -->
	<insert id="addHotelRefundOrder" parameterType="com.sibu.orderHelper.hotel.model.RoomOrderRefundBean">
		    insert into room_order_refund (
				sub_order_id,order_id,refund_code,room_id,refund_price,
        		refund_integral,refund_reason,check_date 
			) value
			(
				#{subOrderId},
				#{orderId},
				#{refundCode},
				#{roomId},
				#{refundPrice},
				#{refundIntegral},
				#{refundReason},
				#{checkDate}
			)
	</insert>
</mapper>