HotelOrderMapper.xml
11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?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>