OrderMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.sqx.modules.order.dao.AppOrderDao">
  4. <select id="selectOrderList" resultType="com.sqx.modules.order.entity.TbOrder">
  5. select tor.*, gs.shop_name as shopName, gs.detailed_address as detailedAddress, gs.shop_lng as shopLng,
  6. gs.shop_lat as shopLat, gs.phone as shopPhone,
  7. gs.errand_money as errandMoney, gs.exempt_min_money as exemptMinMoney, gs.minimum_delivery as minimumDelivery,
  8. gs.distribution_distance as distributionDistance
  9. from tb_order tor left join goods_shop gs on tor.shop_id = gs.shop_id
  10. where tor.user_id = #{userId}
  11. <if test="orderType!=null">
  12. and tor.order_type = #{orderType}
  13. </if>
  14. <if test="shopId!=null">
  15. and tor.shop_id = #{shopId}
  16. </if>
  17. <if test="status!=null">
  18. <if test="status == 0">
  19. and tor.status = 0
  20. </if>
  21. <if test="status == 1">
  22. and tor.status = 1
  23. </if>
  24. <if test="status == 2">
  25. and tor.status = 2
  26. </if>
  27. <if test="status == 3">
  28. and tor.status in (7, 6, 3, 4, 5, 8)
  29. </if>
  30. </if>
  31. </select>
  32. <insert id="insertOrder" parameterType="com.sqx.modules.order.entity.TbOrder" useGeneratedKeys="true"
  33. keyProperty="orderId">
  34. insert into tb_order (coupon_id, user_id, user_name, phone, address, order_number, is_pay, pay_time,
  35. order_code, order_type, pack_money, errand_money, status, delete_flag, parent_user_id,
  36. shop_id, parent_id, create_time)
  37. values (#{couponId}, #{userId}, #{userName}, #{phone}, #{address}, #{orderNumber}, #{isPay}, #{payTime},
  38. #{orderCode}, #{orderType}, #{packMoney}, #{errandMoney}, #{status}, #{deleteFlag}, #{parentUserId},
  39. #{shopId}, #{parentId}, #{createTime})
  40. </insert>
  41. <select id="selectOrder" resultType="com.sqx.modules.order.entity.TbOrder">
  42. select tor.*, tu.avatar as avatar, gs.shop_name as shopName, gs.detailed_address as detailedAddress, gs.phone as
  43. shopPhone,
  44. ti.rider_user_id as riderUserId, tcu.money as couponMoney,
  45. pd.trade_no as transactionId
  46. from tb_order tor
  47. left join tb_user tu on tor.user_id = tu.user_id
  48. left join goods_shop gs on tor.shop_id = gs.shop_id
  49. left join tb_indent ti on tor.order_id = ti.order_id
  50. left join tb_coupon_user tcu on tor.coupon_id = tcu.id
  51. left join pay_details pd on pd.order_id = tor.order_number
  52. where 1 = 1 and tor.is_pay = 1
  53. <if test="shopName!=null and shopName!=''">
  54. and gs.shop_name like concat('%',#{shopName},'%')
  55. </if>
  56. <if test="userName!=null and userName!=''">
  57. and tor.user_name like concat('%',#{userName},'%')
  58. </if>
  59. <if test="phone!=null and phone!=''">
  60. and tor.phone like concat('%',#{phone},'%')
  61. </if>
  62. <if test="orderNumber!=null and orderNumber!=''">
  63. and tor.order_number = #{orderNumber}
  64. </if>
  65. <if test="status!=null and status!=5">
  66. and tor.status = #{status}
  67. </if>
  68. <if test="status!=null and status==5">
  69. and tor.status in (5, 8)
  70. </if>
  71. <if test="status==null">
  72. and tor.status in (7, 6, 3, 4, 5, 8)
  73. </if>
  74. <if test="shopId!=null">
  75. and tor.shop_id = #{shopId}
  76. </if>
  77. <if test="orderType!=null">
  78. and tor.order_type = #{orderType}
  79. </if>
  80. <if test="transactionId != null and transactionId != ''">
  81. and pd.trade_no = #{transactionId}
  82. </if>
  83. order by tor.pay_time desc, tor.create_time desc
  84. </select>
  85. <select id="selectAllOrderAdmin" resultType="com.sqx.modules.order.entity.TbOrder">
  86. select tor.*, tu.avatar as avatar, gs.shop_name as shopName, gs.detailed_address as detailedAddress, gs.phone as
  87. shopPhone,
  88. tiu.user_name as riderNickName,tiu.phone as riderPhone,ti.indent_id as indentId,ti.is_rider as isRider,
  89. ti.rider_user_id as riderUserId, tcu.money as couponMoney,
  90. apr.discount_amount as activityDiscountAmount, ai.title activityTitle,tiu.rider_station_id as riderStationId,
  91. (select station_name from rider_station where id = tiu.rider_station_id ) as stationName,
  92. (select st.shop_type_name from shop_type st where st.id =gs.shop_type_id ) as shopTypeName,
  93. (case when tcu.shop_id =0 then '平台' else gs2.shop_name end) as couponTypeRemark,
  94. pd.trade_no as transactionId
  95. from tb_order tor
  96. left join tb_user tu on tor.user_id = tu.user_id
  97. left join goods_shop gs on tor.shop_id = gs.shop_id
  98. left join tb_indent ti on tor.order_id = ti.order_id
  99. left join tb_user tiu on tiu.user_id = ti.rider_user_id
  100. left join tb_coupon_user tcu on tor.coupon_id = tcu.id
  101. left join activity_part_record apr on apr.order_id = tor.order_id
  102. left join activity ai on ai.id = apr.activity_id
  103. left join goods_shop gs2 on gs2.shop_id=tcu.shop_id
  104. left join pay_details pd on pd.order_id = tor.order_number
  105. where 1 = 1
  106. <if test="query.riderPhone!=null and query.riderPhone!=''">
  107. and tiu.phone =#{query.riderPhone}
  108. </if>
  109. <if test="query.shopName!=null and query.shopName!=''">
  110. and gs.shop_name like concat('%',#{query.shopName},'%')
  111. </if>
  112. <if test="query.userName!=null and query.userName!=''">
  113. and tor.user_name like concat('%',#{query.userName},'%')
  114. </if>
  115. <if test="query.phone!=null and query.phone!=''">
  116. and tor.phone like concat('%',#{query.phone},'%')
  117. </if>
  118. <if test="query.orderNumber!=null and query.orderNumber!=''">
  119. and tor.order_number = #{query.orderNumber}
  120. </if>
  121. <if test="query.status!=null and query.status!=-1 and query.status!=1">
  122. and tor.status = #{query.status}
  123. </if>
  124. <if test="query.status!=null and query.status==1">
  125. and tor.status in (1,2)
  126. </if>
  127. <if test="query.shopId!=null">
  128. and tor.shop_id = #{query.shopId}
  129. </if>
  130. <if test="query.orderType!=null">
  131. and tor.order_type_extra = #{query.orderType}
  132. </if>
  133. <if test="query.indentStatus != null and query.indentStatus != ''">
  134. and ti.indent_state = #{query.indentStatus}
  135. </if>
  136. <if test="query.reservationFlag != null and query.reservationFlag !=''">
  137. and tor.reservation_flag = #{query.reservationFlag}
  138. </if>
  139. <if test="query.startTime!=null and query.startTime!=''">
  140. and tor.create_time >= #{query.startTime}
  141. </if>
  142. <if test="query.endTime!=null and query.endTime!='' ">
  143. and tor.create_time &lt;= #{query.endTime}
  144. </if>
  145. <if test="query.payStartTime != null and query.payStartTime != ''">
  146. and tor.pay_time >= #{query.payStartTime}
  147. </if>
  148. <if test="query.payEndTime != null and query.payEndTime != '' ">
  149. and tor.pay_time &lt;= #{query.payEndTime}
  150. </if>
  151. <if test="query.riderStationId!=null and query.riderStationId!=''">
  152. and tiu.rider_station_id=#{query.riderStationId}
  153. </if>
  154. <if test="query.shopTypeId!=null and query.shopTypeId!=''">
  155. and gs.shop_type_id=#{query.shopTypeId}
  156. </if>
  157. <if test="query.transactionId != null and query.transactionId != ''">
  158. and pd.trade_no = #{query.transactionId}
  159. </if>
  160. <if test='query.couponType== "0" '>
  161. and tcu.shop_id =0
  162. </if>
  163. <if test='query.couponType== "1"'>
  164. and tcu.shop_id !=0
  165. </if>
  166. order by tor.pay_time desc, tor.create_time desc
  167. </select>
  168. <select id="excelAllOrderAdmin" resultType="com.sqx.modules.order.entity.TbOrder">
  169. select tor.*, tu.avatar as avatar, gs.shop_name as shopName, gs.detailed_address as detailedAddress, gs.phone as
  170. shopPhone,
  171. tiu.nick_name as riderNickName,tiu.phone as riderPhone,ti.indent_id as indentId,ti.is_rider as isRider,
  172. ti.rider_user_id as riderUserId, tcu.money as couponMoney,
  173. apr.discount_amount as activityDiscountAmount, ai.title activityTitle,ogg.detail,ogg.sumPrice,
  174. (select rs.station_name from rider_station rs where rs.id =tiu.rider_station_id ) as stationName,
  175. (select st.shop_type_name from shop_type st where st.id =gs.shop_type_id ) as shopTypeName,
  176. (case when tcu.shop_id =0 then '平台' else gs2.shop_name end) as couponTypeRemark
  177. from tb_order tor
  178. left join tb_user tu on tor.user_id = tu.user_id
  179. left join goods_shop gs on tor.shop_id = gs.shop_id
  180. left join tb_indent ti on tor.order_id = ti.order_id
  181. left join tb_user tiu on tiu.user_id = ti.rider_user_id
  182. left join tb_coupon_user tcu on tor.coupon_id = tcu.id
  183. left join activity_part_record apr on apr.order_id = tor.order_id
  184. left join activity ai on ai.id = apr.activity_id
  185. left join ( select @a:=0,order_id ,group_concat(@a:=@a+1,".商品名:",goods_name,",数量:",goods_num,",规格:",sku_message)
  186. detail,sum(goods_num*goods_price) sumPrice from order_goods og group by order_id
  187. ) ogg on ogg.order_id =tor.order_id
  188. left join goods_shop gs2 on gs2.shop_id=tcu.shop_id
  189. where 1 = 1
  190. <if test="query.riderPhone!=null and query.riderPhone!=''">
  191. and tiu.phone =#{query.riderPhone}
  192. </if>
  193. <if test="query.shopName!=null and query.shopName!=''">
  194. and gs.shop_name like concat('%',#{query.shopName},'%')
  195. </if>
  196. <if test="query.userName!=null and query.userName!=''">
  197. and tor.user_name like concat('%',#{query.userName},'%')
  198. </if>
  199. <if test="query.phone!=null and query.phone!=''">
  200. and tor.phone like concat('%',#{query.phone},'%')
  201. </if>
  202. <if test="query.orderNumber!=null and query.orderNumber!=''">
  203. and tor.order_number = #{query.orderNumber}
  204. </if>
  205. <if test="query.status!=null and query.status!=-1 and query.status!=1">
  206. and tor.status = #{query.status}
  207. </if>
  208. <if test="query.status!=null and query.status==1">
  209. and tor.status in (1,2)
  210. </if>
  211. <if test="query.shopId!=null">
  212. and tor.shop_id = #{query.shopId}
  213. </if>
  214. <if test="query.orderType!=null">
  215. and tor.order_type_extra = #{query.orderType}
  216. </if>
  217. <if test="query.indentStatus != null and query.indentStatus != ''">
  218. and ti.indent_state = #{query.indentStatus}
  219. </if>
  220. <if test="query.reservationFlag != null and query.reservationFlag !=''">
  221. and tor.reservation_flag = #{query.reservationFlag}
  222. </if>
  223. <if test="query.startTime!=null and query.startTime!=''">
  224. and tor.create_time >= #{query.startTime}
  225. </if>
  226. <if test="query.endTime!=null and query.endTime!='' ">
  227. and tor.create_time &lt;= #{query.endTime}
  228. </if>
  229. <if test="query.payStartTime != null and query.payStartTime != ''">
  230. and tor.pay_time >= #{query.payStartTime}
  231. </if>
  232. <if test="query.payEndTime != null and query.payEndTime != '' ">
  233. and tor.pay_time &lt;= #{query.payEndTime}
  234. </if>
  235. <if test="query.riderStationId!=null and query.riderStationId!=''">
  236. and tiu.rider_station_id=#{query.riderStationId}
  237. </if>
  238. <if test="query.shopTypeId!=null and query.shopTypeId!=''">
  239. and gs.shop_type_id=#{query.shopTypeId}
  240. </if>
  241. <if test='query.couponType== "0" '>
  242. and tcu.shop_id =0
  243. </if>
  244. <if test='query.couponType== "1"'>
  245. and tcu.shop_id !=0
  246. </if>
  247. order by tor.pay_time desc, tor.create_time desc
  248. </select>
  249. <select id="excelAllOrderAdminCount" resultType="java.lang.Integer">
  250. select count(1) from tb_order tor
  251. left join tb_user tu on tor.user_id = tu.user_id
  252. left join goods_shop gs on tor.shop_id = gs.shop_id
  253. left join tb_indent ti on tor.order_id = ti.order_id
  254. left join tb_user tiu on tiu.user_id = ti.rider_user_id
  255. left join tb_coupon_user tcu on tor.coupon_id = tcu.id
  256. where 1 = 1
  257. <if test="query.riderPhone!=null and query.riderPhone!=''">
  258. and tiu.phone =#{query.riderPhone}
  259. </if>
  260. <if test="query.shopName!=null and query.shopName!=''">
  261. and gs.shop_name like concat('%',#{query.shopName},'%')
  262. </if>
  263. <if test="query.userName!=null and query.userName!=''">
  264. and tor.user_name like concat('%',#{query.userName},'%')
  265. </if>
  266. <if test="query.phone!=null and query.phone!=''">
  267. and tor.phone like concat('%',#{query.phone},'%')
  268. </if>
  269. <if test="query.orderNumber!=null and query.orderNumber!=''">
  270. and tor.order_number = #{query.orderNumber}
  271. </if>
  272. <if test="query.status!=null and query.status!=-1 and query.status!=1">
  273. and tor.status = #{query.status}
  274. </if>
  275. <if test="query.status!=null and query.status==1">
  276. and tor.status in (1,2)
  277. </if>
  278. <if test="query.shopId!=null">
  279. and tor.shop_id = #{query.shopId}
  280. </if>
  281. <if test="query.orderType!=null">
  282. and tor.order_type_extra = #{query.orderType}
  283. </if>
  284. <if test="query.indentStatus != null and query.indentStatus != ''">
  285. and ti.indent_state = #{query.indentStatus}
  286. </if>
  287. <if test="query.reservationFlag != null and query.reservationFlag !=''">
  288. and tor.reservation_flag = #{query.reservationFlag}
  289. </if>
  290. <if test="query.startTime!=null and query.startTime!=''">
  291. and tor.create_time >= #{query.startTime}
  292. </if>
  293. <if test="query.endTime!=null and query.endTime!='' ">
  294. and tor.create_time &lt;= #{query.endTime}
  295. </if>
  296. <if test="query.payStartTime != null and query.payStartTime != ''">
  297. and tor.pay_time >= #{query.payStartTime}
  298. </if>
  299. <if test="query.payEndTime != null and query.payEndTime != '' ">
  300. and tor.pay_time &lt;= #{query.payEndTime}
  301. </if>
  302. <if test="query.riderStationId!=null and query.riderStationId!=''">
  303. and tiu.rider_station_id=#{query.riderStationId}
  304. </if>
  305. <if test="query.shopTypeId!=null and query.shopTypeId!=''">
  306. and gs.shop_type_id=#{query.shopTypeId}
  307. </if>
  308. <if test='query.couponType== "0" '>
  309. and tcu.shop_id =0
  310. </if>
  311. <if test='query.couponType== "1"'>
  312. and tcu.shop_id !=0
  313. </if>
  314. order by tor.pay_time desc, tor.create_time desc
  315. </select>
  316. <select id="selectOrderByAdmin" resultType="com.sqx.modules.order.entity.TbOrder">
  317. select tor.*, tu.avatar as avatar, gs.shop_name as shopName from sys_user_shop sus
  318. left join tb_order tor on sus.shop_id = tor.shop_id
  319. left join tb_user tu on tor.user_id = tu.user_id
  320. left join goods_shop gs on tor.shop_id = gs.shop_id
  321. where 1 = 1 and sus.user_id = #{userId}
  322. and tor.is_pay = 1
  323. <if test="userName!=null and userName!=''">
  324. and tor.user_name like concat('%',#{userName},'%')
  325. </if>
  326. <if test="phone!=null and phone!=''">
  327. and tor.phone like concat('%',#{phone},'%')
  328. </if>
  329. <if test="orderNumber!=null and orderNumber!=''">
  330. and tor.order_number = #{orderNumber}
  331. </if>
  332. <if test="status!=null">
  333. and tor.status = #{status}
  334. </if>
  335. <if test="shopId!=null">
  336. and tor.shop_id = #{shopId}
  337. </if>
  338. <if test="orderType!=null">
  339. and tor.order_type = #{orderType}
  340. </if>
  341. order by tor.pay_time desc, tor.create_time desc
  342. </select>
  343. <select id="selectCountOrderByUserId" resultType="int">
  344. select count(*) from tb_order where user_id = #{userId}
  345. <if test="dateType=='day'">
  346. and date_format(pay_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  347. </if>
  348. <if test="dateType=='month'">
  349. and date_format(pay_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  350. </if>
  351. <if test="dateType=='year'">
  352. and date_format(pay_time,'%Y')=date_format(#{date},'%Y')
  353. </if>
  354. </select>
  355. <select id="selectSunMoneyByUserId" resultType="java.math.BigDecimal">
  356. select ifnull(sum(pay_money), 0) from tb_order where user_id = #{userId}
  357. <if test="dateType=='day'">
  358. and date_format(pay_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  359. </if>
  360. <if test="dateType=='month'">
  361. and date_format(pay_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  362. </if>
  363. <if test="dateType=='year'">
  364. and date_format(pay_time,'%Y')=date_format(#{date},'%Y')
  365. </if>
  366. </select>
  367. <select id="selectOrderDetails" resultType="com.sqx.modules.order.entity.TbOrder">
  368. select tor.*,
  369. gs.shop_name as shopName,
  370. gs.detailed_address as detailedAddress,
  371. gs.phone as shopPhone,
  372. tu.nick_name as riderNickName,
  373. tu.phone as riderPhone
  374. from tb_order tor
  375. left join goods_shop gs on tor.shop_id = gs.shop_id
  376. left join tb_indent ti on tor.order_id = ti.order_id
  377. left join tb_user tu on ti.rider_user_id = tu.user_id
  378. where tor.user_id = #{userId}
  379. and tor.status in (7, 6, 3, 4, 5, 8)
  380. order by pay_time desc
  381. </select>
  382. <select id="waitTakeFood" resultType="com.sqx.modules.order.entity.TbOrder">
  383. select tor.*, tu.avatar as avatar, ti.rider_user_id as riderUserId, gs.shop_name as shopName, gs.shop_cover as
  384. shopCover, gs.detailed_address as detailedAddress,tu1.phone as riderPhone,gs.phone as shopPhone,ti.indent_state
  385. as indentState,
  386. (select count(*) from tb_order where order_type = 1 and status in (6, 3) and pay_time &lt; tor.pay_time
  387. and shop_id = tor.shop_id) as countOrder
  388. from tb_order tor
  389. left join tb_user tu on tor.user_id = tu.user_id
  390. left join tb_indent ti on tor.order_id = ti.order_id
  391. left join goods_shop gs on tor.shop_id = gs.shop_id
  392. left join tb_user tu1 on ti.rider_user_id = tu1.user_id
  393. where tor.user_id = #{userId}
  394. and order_type = #{orderType}
  395. <if test="status!=null and status!=5">
  396. and tor.status = #{status}
  397. </if>
  398. <if test="status!=null and status==5">
  399. and tor.status =5
  400. </if>
  401. <if test="status==null">
  402. and tor.status in (0, 7, 6, 3, 4, 5, 8)
  403. </if>
  404. <if test="!(status != null and status==5)">
  405. order by tor.pay_time desc, tor.create_time desc
  406. </if>
  407. <if test="status != null and status==5">
  408. order by tor.create_time desc
  409. </if>
  410. </select>
  411. <select id="selectCountOrderByTime" resultType="int">
  412. select count(*)
  413. from tb_order
  414. where order_type = 1
  415. and status = 3
  416. and pay_time &lt; #{payTime}
  417. and shop_id = #{shopId}
  418. </select>
  419. <update id="deleteCouponByOrderId">
  420. update tb_order
  421. set coupon_id = null
  422. where order_id = #{orderId}
  423. </update>
  424. <select id="selectSumMoney" resultType="java.math.BigDecimal">
  425. select ifnull(sum(pay_money), 0) from tb_order where is_pay=1 and status in (0,3,4,7,6)
  426. <if test="query.shopId!=null">
  427. and shop_id=#{query.shopId}
  428. </if>
  429. <if test="query.startTime!=null and query.startTime!=''">
  430. and pay_time>=#{query.startTime}
  431. </if>
  432. <if test="query.endTime!=null and query.endTime!=''">
  433. and pay_time <![CDATA[<=]]> #{query.endTime}
  434. </if>
  435. </select>
  436. <select id="selectCountOrder" resultType="int">
  437. select count(*) from tb_order where is_pay=1 and status in (0,3,4,7,6)
  438. <if test="query.shopId!=null">
  439. and shop_id=#{query.shopId}
  440. </if>
  441. <if test="query.startTime!=null and query.startTime!=''">
  442. and pay_time>=#{query.startTime}
  443. </if>
  444. <if test="query.endTime!=null and query.endTime!=''">
  445. and pay_time <![CDATA[<=]]> #{query.endTime}
  446. </if>
  447. </select>
  448. <update id="updateorderStatus">
  449. update tb_order
  450. set status = 4
  451. where update_time &lt; #{date}
  452. and status = 3
  453. </update>
  454. <select id="selectOrderByTimeList" resultType="com.sqx.modules.order.entity.TbOrder">
  455. select *
  456. from tb_order
  457. where update_time &lt; #{date}
  458. and status = 3
  459. </select>
  460. <select id="selectShoppingTrolley" resultType="com.sqx.modules.order.entity.TbOrder">
  461. select t.*, gs.shop_name as shopName
  462. from tb_order t
  463. left join goods_shop gs on t.shop_id = gs.shop_id
  464. where t.status = 1
  465. and t.user_id = #{userId}
  466. order by t.add_goods_time desc
  467. </select>
  468. <select id="selectShoppingTrolleyByShopId" resultType="com.sqx.modules.order.entity.TbOrder">
  469. select t.*, gs.shop_name as shopName
  470. from tb_order t
  471. left join goods_shop gs on t.shop_id = gs.shop_id
  472. where t.status = 1
  473. and t.user_id = #{userId}
  474. and t.shop_id = #{shopId}
  475. order by t.add_goods_time desc
  476. </select>
  477. <select id="selectByOrderId" resultType="com.sqx.modules.order.entity.TbOrder">
  478. select tor.*,
  479. ti.indent_id as indentId,
  480. ti.indent_number as indentNumber,
  481. ti.rider_user_id as riderUserId,
  482. ti.indent_state as indentState,
  483. tu.nick_name as riderNickName,
  484. tu.avatar as riderAvatar,
  485. tu.phone as riderPhone,
  486. e.evaluate_message as evaluateMessage,
  487. e.shop_reply_message as shopReplyMessage,
  488. e.score as score,
  489. e.create_time as eCreateTime,
  490. tus.avatar as avatar,
  491. tus.nick_name as userNickName
  492. from tb_order tor
  493. left join tb_indent ti on tor.order_id = ti.order_id
  494. left join tb_user tu on ti.rider_user_id = tu.user_id
  495. left join tb_user tus on ti.user_id = tus.user_id
  496. left join evaluate e on tor.order_number = e.order_number
  497. where tor.order_id = #{orderId}
  498. limit 1
  499. </select>
  500. <select id="selectBuyGoods" resultType="com.sqx.modules.order.entity.TbOrder">
  501. select tor.*,
  502. gs.shop_name as shopName,
  503. gs.detailed_address as detailedAddress,
  504. gs.shop_lng as shopLng,
  505. gs.shop_lat as shopLat,
  506. gs.phone as shopPhone,
  507. gs.errand_money as errandMoney,
  508. gs.exempt_min_money as exemptMinMoney,
  509. gs.minimum_delivery as minimumDelivery,
  510. gs.distribution_distance as distributionDistance
  511. from tb_order tor
  512. left join goods_shop gs on tor.shop_id = gs.shop_id
  513. where tor.order_id = #{orderId}
  514. and tor.user_id = #{userId}
  515. </select>
  516. <select id="selectOverTimeOrder" resultType="com.sqx.modules.order.entity.TbOrder">
  517. select *
  518. from tb_order
  519. where status = 7
  520. and pay_time &lt; #{overTime}
  521. </select>
  522. <select id="selectMakeOrdersList" resultType="com.sqx.modules.order.entity.TbOrder">
  523. select * from tb_order where status=6 and shop_receiving_time <![CDATA[ <= #{minusMinutes}
  524. ]]></select>
  525. <select id="selectCurrentOrderSequenceByShopId" resultType="java.lang.Long">
  526. select
  527. order_id
  528. from
  529. tb_order
  530. where
  531. is_pay = 1
  532. and shop_id = #{shopId}
  533. and date(pay_time) = date(#{payTime})
  534. order by pay_time asc
  535. </select>
  536. <select id="countByShopIdAndActivityIdAndUserIdAndCurDate" resultType="java.lang.Integer">
  537. select
  538. count(1)
  539. from
  540. tb_order o
  541. left join activity_part_record apr on apr.order_id = o.order_id
  542. where
  543. o.shop_id = #{shopId}
  544. and o.user_id = #{userId}
  545. and date(o.create_time) = curdate()
  546. and apr.activity_id = #{activityId}
  547. and o.is_pay = 1
  548. <if test="orderId != null">
  549. and o.order_id != #{orderId}
  550. </if>
  551. </select>
  552. <select id="selectCurWaitReceivingOrderIds" resultType="java.lang.Long">
  553. select
  554. order_id
  555. from
  556. tb_order
  557. where
  558. reservation_flag = '1'
  559. and `status` = '7'
  560. and expect_delivery_time <![CDATA[ <= ]]> adddate(now(),interval 30 minute)
  561. </select>
  562. <select id="countUnFinishByShopId" resultType="java.lang.Integer">
  563. select count(order_id)
  564. from tb_order
  565. where shop_id = #{shopId} and status in (6, 3)
  566. </select>
  567. <select id="countCurDayPayByShopId" resultType="java.lang.Integer">
  568. select
  569. count(order_id)
  570. from
  571. tb_order
  572. where
  573. is_pay = 1
  574. and shop_id = #{shopId}
  575. and date(pay_time) = date(#{payTime})
  576. </select>
  577. <select id="selectOrderPage" resultType="com.sqx.modules.order.entity.TbOrder">
  578. select tor.*, gs.shop_name as shopName, gs.detailed_address as detailedAddress, gs.shop_lng as shopLng,
  579. gs.shop_lat as shopLat, gs.phone as shopPhone,
  580. gs.errand_money as errandMoney, gs.exempt_min_money as exemptMinMoney, gs.minimum_delivery as minimumDelivery,
  581. gs.distribution_distance as distributionDistance
  582. from tb_order tor left join goods_shop gs on tor.shop_id = gs.shop_id
  583. where tor.user_id = #{userId}
  584. and tor.order_id = #{orderId}
  585. </select>
  586. <select id="selectAllOrderTotalPrice" resultType="java.math.BigDecimal">
  587. select SUM(tor.pay_money) as totalPrice
  588. from tb_order tor
  589. left join tb_user tu on tor.user_id = tu.user_id
  590. left join goods_shop gs on tor.shop_id = gs.shop_id
  591. left join tb_indent ti on tor.order_id = ti.order_id
  592. left join tb_user tiu on tiu.user_id = ti.rider_user_id
  593. left join tb_coupon_user tcu on tor.coupon_id = tcu.id
  594. left join activity_part_record apr on apr.order_id = tor.order_id
  595. left join activity ai on ai.id = apr.activity_id
  596. left join goods_shop gs2 on gs2.shop_id=tcu.shop_id
  597. where 1 = 1
  598. <if test="query.riderPhone!=null and query.riderPhone!=''">
  599. and tiu.phone =#{query.riderPhone}
  600. </if>
  601. <if test="query.shopName!=null and query.shopName!=''">
  602. and gs.shop_name like concat('%',#{query.shopName},'%')
  603. </if>
  604. <if test="query.userName!=null and query.userName!=''">
  605. and tor.user_name like concat('%',#{query.userName},'%')
  606. </if>
  607. <if test="query.phone!=null and query.phone!=''">
  608. and tor.phone like concat('%',#{query.phone},'%')
  609. </if>
  610. <if test="query.orderNumber!=null and query.orderNumber!=''">
  611. and tor.order_number = #{query.orderNumber}
  612. </if>
  613. <if test="query.status!=null and query.status!=-1 and query.status!=1">
  614. and tor.status = #{query.status}
  615. </if>
  616. <if test="query.status!=null and query.status==1">
  617. and tor.status in (1,2)
  618. </if>
  619. <if test="query.shopId!=null">
  620. and tor.shop_id = #{query.shopId}
  621. </if>
  622. <if test="query.orderType!=null">
  623. and tor.order_type_extra = #{query.orderType}
  624. </if>
  625. <if test="query.indentStatus != null and query.indentStatus != ''">
  626. and ti.indent_state = #{query.indentStatus}
  627. </if>
  628. <if test="query.reservationFlag != null and query.reservationFlag !=''">
  629. and tor.reservation_flag = #{query.reservationFlag}
  630. </if>
  631. <if test="query.startTime!=null and query.startTime!=''">
  632. and tor.create_time >= #{query.startTime}
  633. </if>
  634. <if test="query.endTime!=null and query.endTime!='' ">
  635. and tor.create_time &lt;= #{query.endTime}
  636. </if>
  637. <if test="query.payStartTime != null and query.payStartTime != ''">
  638. and tor.pay_time >= #{query.payStartTime}
  639. </if>
  640. <if test="query.payEndTime != null and query.payEndTime != '' ">
  641. and tor.pay_time &lt;= #{query.payEndTime}
  642. </if>
  643. <if test="query.riderStationId!=null and query.riderStationId!=''">
  644. and tiu.rider_station_id=#{query.riderStationId}
  645. </if>
  646. <if test="query.shopTypeId!=null and query.shopTypeId!=''">
  647. and gs.shop_type_id=#{query.shopTypeId}
  648. </if>
  649. <if test='query.couponType== "0" '>
  650. and tcu.shop_id =0
  651. </if>
  652. <if test='query.couponType== "1"'>
  653. and tcu.shop_id !=0
  654. </if>
  655. order by tor.pay_time desc, tor.create_time desc
  656. </select>
  657. <select id="changeTimeOutOrder" resultType="com.sqx.modules.order.entity.TbOrder">
  658. SELECT o.*,
  659. pd.state as state
  660. FROM `tb_order` o
  661. LEFT JOIN pay_details pd ON o.order_number = pd.order_id
  662. WHERE o.`status` = 0
  663. AND o.time_out IS NOT NULL
  664. AND #{time} >= o.time_out
  665. AND pd.state in (0, 2)
  666. </select>
  667. </mapper>