OrderMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. from tb_order tor
  46. left join tb_user tu on tor.user_id = tu.user_id
  47. left join goods_shop gs on tor.shop_id = gs.shop_id
  48. left join tb_indent ti on tor.order_id = ti.order_id
  49. left join tb_coupon_user tcu on tor.coupon_id = tcu.id
  50. where 1 = 1 and tor.is_pay = 1
  51. <if test="shopName!=null and shopName!=''">
  52. and gs.shop_name like concat('%',#{shopName},'%')
  53. </if>
  54. <if test="userName!=null and userName!=''">
  55. and tor.user_name like concat('%',#{userName},'%')
  56. </if>
  57. <if test="phone!=null and phone!=''">
  58. and tor.phone like concat('%',#{phone},'%')
  59. </if>
  60. <if test="orderNumber!=null and orderNumber!=''">
  61. and tor.order_number = #{orderNumber}
  62. </if>
  63. <if test="status!=null and status!=5">
  64. and tor.status = #{status}
  65. </if>
  66. <if test="status!=null and status==5">
  67. and tor.status in (5, 8)
  68. </if>
  69. <if test="status==null">
  70. and tor.status in (7, 6, 3, 4, 5, 8)
  71. </if>
  72. <if test="shopId!=null">
  73. and tor.shop_id = #{shopId}
  74. </if>
  75. <if test="orderType!=null">
  76. and tor.order_type = #{orderType}
  77. </if>
  78. order by tor.pay_time desc, tor.create_time desc
  79. </select>
  80. <select id="selectAllOrderAdmin" resultType="com.sqx.modules.order.entity.TbOrder">
  81. select tor.*, tu.avatar as avatar, gs.shop_name as shopName, gs.detailed_address as detailedAddress, gs.phone as
  82. shopPhone,
  83. tiu.user_name as riderNickName,tiu.phone as riderPhone,ti.indent_id as indentId,ti.is_rider as isRider,
  84. ti.rider_user_id as riderUserId, tcu.money as couponMoney
  85. from tb_order tor
  86. left join tb_user tu on tor.user_id = tu.user_id
  87. left join goods_shop gs on tor.shop_id = gs.shop_id
  88. left join tb_indent ti on tor.order_id = ti.order_id
  89. left join tb_user tiu on tiu.user_id = ti.rider_user_id
  90. left join tb_coupon_user tcu on tor.coupon_id = tcu.id
  91. where 1 = 1
  92. <if test="riderPhone!=null and riderPhone!=''">
  93. and tiu.phone =#{riderPhone}
  94. </if>
  95. <if test="shopName!=null and shopName!=''">
  96. and gs.shop_name like concat('%',#{shopName},'%')
  97. </if>
  98. <if test="userName!=null and userName!=''">
  99. and tor.user_name like concat('%',#{userName},'%')
  100. </if>
  101. <if test="phone!=null and phone!=''">
  102. and tor.phone like concat('%',#{phone},'%')
  103. </if>
  104. <if test="orderNumber!=null and orderNumber!=''">
  105. and tor.order_number = #{orderNumber}
  106. </if>
  107. <if test="status!=null and status!=-1 and status!=1">
  108. and tor.status = #{status}
  109. </if>
  110. <if test="status!=null and status==1">
  111. and tor.status in (1,2)
  112. </if>
  113. <if test="shopId!=null">
  114. and tor.shop_id = #{shopId}
  115. </if>
  116. <if test="orderType!=null">
  117. and tor.order_type_extra = #{orderType}
  118. </if>
  119. <if test="startTime!=null and startTime!=''">
  120. and date_format(tor.create_time,'%Y-%m-%d') >= date_format(#{startTime},'%Y-%m-%d')
  121. </if>
  122. <if test="endTime!=null and endTime!='' ">
  123. and date_format(tor.create_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
  124. </if>
  125. <if test="payStartTime != null and payStartTime != ''">
  126. and date_format(tor.pay_time,'%Y-%m-%d') >= date_format(#{payStartTime},'%Y-%m-%d')
  127. </if>
  128. <if test="payEndTime != null and payEndTime != '' ">
  129. and date_format(tor.pay_time,'%Y-%m-%d') &lt;= date_format(#{payEndTime},'%Y-%m-%d')
  130. </if>
  131. order by tor.pay_time desc, tor.create_time desc
  132. </select>
  133. <select id="excelAllOrderAdmin" resultType="com.sqx.modules.order.entity.TbOrder">
  134. select tor.*, tu.avatar as avatar, gs.shop_name as shopName, gs.detailed_address as detailedAddress, gs.phone as
  135. shopPhone,
  136. tiu.nick_name as riderNickName,tiu.phone as riderPhone,ti.indent_id as indentId,ti.is_rider as isRider,
  137. ti.rider_user_id as riderUserId, tcu.money as couponMoney
  138. from tb_order tor
  139. left join tb_user tu on tor.user_id = tu.user_id
  140. left join goods_shop gs on tor.shop_id = gs.shop_id
  141. left join tb_indent ti on tor.order_id = ti.order_id
  142. left join tb_user tiu on tiu.user_id = ti.rider_user_id
  143. left join tb_coupon_user tcu on tor.coupon_id = tcu.id
  144. where 1 = 1
  145. <if test="riderPhone!=null and riderPhone!=''">
  146. and tiu.phone =#{riderPhone}
  147. </if>
  148. <if test="shopName!=null and shopName!=''">
  149. and gs.shop_name like concat('%',#{shopName},'%')
  150. </if>
  151. <if test="userName!=null and userName!=''">
  152. and tor.user_name like concat('%',#{userName},'%')
  153. </if>
  154. <if test="phone!=null and phone!=''">
  155. and tor.phone like concat('%',#{phone},'%')
  156. </if>
  157. <if test="orderNumber!=null and orderNumber!=''">
  158. and tor.order_number = #{orderNumber}
  159. </if>
  160. <if test="status!=null and status!=-1 and status!=1">
  161. and tor.status = #{status}
  162. </if>
  163. <if test="status!=null and status==1">
  164. and tor.status in (1,2)
  165. </if>
  166. <if test="shopId!=null">
  167. and tor.shop_id = #{shopId}
  168. </if>
  169. <if test="orderType!=null">
  170. and tor.order_type = #{orderType}
  171. </if>
  172. <if test="startTime!=null and startTime!=''">
  173. and date_format(tor.create_time,'%Y-%m-%d') >= date_format(#{startTime},'%Y-%m-%d')
  174. </if>
  175. <if test="endTime!=null and endTime!='' ">
  176. and date_format(tor.create_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
  177. </if>
  178. order by tor.pay_time desc, tor.create_time desc
  179. </select>
  180. <select id="selectOrderByAdmin" resultType="com.sqx.modules.order.entity.TbOrder">
  181. select tor.*, tu.avatar as avatar, gs.shop_name as shopName from sys_user_shop sus
  182. left join tb_order tor on sus.shop_id = tor.shop_id
  183. left join tb_user tu on tor.user_id = tu.user_id
  184. left join goods_shop gs on tor.shop_id = gs.shop_id
  185. where 1 = 1 and sus.user_id = #{userId}
  186. and tor.is_pay = 1
  187. <if test="userName!=null and userName!=''">
  188. and tor.user_name like concat('%',#{userName},'%')
  189. </if>
  190. <if test="phone!=null and phone!=''">
  191. and tor.phone like concat('%',#{phone},'%')
  192. </if>
  193. <if test="orderNumber!=null and orderNumber!=''">
  194. and tor.order_number = #{orderNumber}
  195. </if>
  196. <if test="status!=null">
  197. and tor.status = #{status}
  198. </if>
  199. <if test="shopId!=null">
  200. and tor.shop_id = #{shopId}
  201. </if>
  202. <if test="orderType!=null">
  203. and tor.order_type = #{orderType}
  204. </if>
  205. order by tor.pay_time desc, tor.create_time desc
  206. </select>
  207. <select id="selectCountOrderByUserId" resultType="int">
  208. select count(*) from tb_order where user_id = #{userId}
  209. <if test="dateType=='day'">
  210. and date_format(pay_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  211. </if>
  212. <if test="dateType=='month'">
  213. and date_format(pay_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  214. </if>
  215. <if test="dateType=='year'">
  216. and date_format(pay_time,'%Y')=date_format(#{date},'%Y')
  217. </if>
  218. </select>
  219. <select id="selectSunMoneyByUserId" resultType="java.math.BigDecimal">
  220. select ifnull(sum(pay_money), 0) from tb_order where user_id = #{userId}
  221. <if test="dateType=='day'">
  222. and date_format(pay_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  223. </if>
  224. <if test="dateType=='month'">
  225. and date_format(pay_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  226. </if>
  227. <if test="dateType=='year'">
  228. and date_format(pay_time,'%Y')=date_format(#{date},'%Y')
  229. </if>
  230. </select>
  231. <select id="selectOrderDetails" resultType="com.sqx.modules.order.entity.TbOrder">
  232. select tor.*,
  233. gs.shop_name as shopName,
  234. gs.detailed_address as detailedAddress,
  235. gs.phone as shopPhone,
  236. tu.nick_name as riderNickName,
  237. tu.phone as riderPhone
  238. from tb_order tor
  239. left join goods_shop gs on tor.shop_id = gs.shop_id
  240. left join tb_indent ti on tor.order_id = ti.order_id
  241. left join tb_user tu on ti.rider_user_id = tu.user_id
  242. where tor.user_id = #{userId}
  243. and tor.status in (7, 6, 3, 4, 5, 8)
  244. order by pay_time desc
  245. </select>
  246. <select id="waitTakeFood" resultType="com.sqx.modules.order.entity.TbOrder">
  247. select tor.*, tu.avatar as avatar, ti.rider_user_id as riderUserId, gs.shop_name as shopName, gs.shop_cover as
  248. shopCover, gs.detailed_address as detailedAddress,
  249. (select count(*) from tb_order where order_type = 1 and status in (6, 3) and pay_time &lt; tor.pay_time
  250. and shop_id = tor.shop_id) as countOrder
  251. from tb_order tor
  252. left join tb_user tu on tor.user_id = tu.user_id
  253. left join tb_indent ti on tor.order_id = ti.order_id
  254. left join goods_shop gs on tor.shop_id = gs.shop_id
  255. where tor.user_id = #{userId}
  256. and order_type = #{orderType}
  257. <if test="status!=null and status!=5">
  258. and tor.status = #{status}
  259. </if>
  260. <if test="status!=null and status==5">
  261. and tor.status in (5, 8)
  262. </if>
  263. <if test="status==null">
  264. and tor.status in (7, 6, 3, 4, 5, 8)
  265. </if>
  266. order by pay_time desc
  267. </select>
  268. <select id="selectCountOrderByTime" resultType="int">
  269. select count(*)
  270. from tb_order
  271. where order_type = 1
  272. and status = 3
  273. and pay_time &lt; #{payTime}
  274. and shop_id = #{shopId}
  275. </select>
  276. <update id="deleteCouponByOrderId">
  277. update tb_order
  278. set coupon_id = null
  279. where order_id = #{orderId}
  280. </update>
  281. <select id="selectSumMoney" resultType="java.math.BigDecimal">
  282. select ifnull(sum(pay_money), 0) from tb_order where is_pay=1 and status in (0,3,4,7,6)
  283. <if test="shopId!=null">
  284. and shop_id=#{shopId}
  285. </if>
  286. <if test="dateType=='day'">
  287. and date_format(pay_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  288. </if>
  289. <if test="dateType=='month'">
  290. and date_format(pay_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  291. </if>
  292. <if test="dateType=='year'">
  293. and date_format(pay_time,'%Y')=date_format(#{date},'%Y')
  294. </if>
  295. </select>
  296. <select id="selectCountOrder" resultType="int">
  297. select count(*) from tb_order where is_pay=1 and status in (0,3,4,7,6)
  298. <if test="shopId!=null">
  299. and shop_id=#{shopId}
  300. </if>
  301. <if test="dateType=='day'">
  302. and date_format(pay_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  303. </if>
  304. <if test="dateType=='month'">
  305. and date_format(pay_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  306. </if>
  307. <if test="dateType=='year'">
  308. and date_format(pay_time,'%Y')=date_format(#{date},'%Y')
  309. </if>
  310. </select>
  311. <update id="updateorderStatus">
  312. update tb_order
  313. set status = 4
  314. where update_time &lt; #{date}
  315. and status = 3
  316. </update>
  317. <select id="selectOrderByTimeList" resultType="com.sqx.modules.order.entity.TbOrder">
  318. select *
  319. from tb_order
  320. where update_time &lt; #{date}
  321. and status = 3
  322. </select>
  323. <select id="selectShoppingTrolley" resultType="com.sqx.modules.order.entity.TbOrder">
  324. select t.*, gs.shop_name as shopName
  325. from tb_order t
  326. left join goods_shop gs on t.shop_id = gs.shop_id
  327. where t.status = 1
  328. and t.user_id = #{userId}
  329. order by t.add_goods_time desc
  330. </select>
  331. <select id="selectShoppingTrolleyByShopId" resultType="com.sqx.modules.order.entity.TbOrder">
  332. select t.*, gs.shop_name as shopName
  333. from tb_order t
  334. left join goods_shop gs on t.shop_id = gs.shop_id
  335. where t.status = 1
  336. and t.user_id = #{userId}
  337. and t.shop_id = #{shopId}
  338. order by t.add_goods_time desc
  339. </select>
  340. <select id="selectByOrderId" resultType="com.sqx.modules.order.entity.TbOrder">
  341. select tor.*,
  342. ti.indent_id as indentId,
  343. ti.indent_number as indentNumber,
  344. ti.rider_user_id as riderUserId,
  345. tu.nick_name as riderNickName,
  346. tu.avatar as riderAvatar,
  347. tu.phone as riderPhone,
  348. e.evaluate_message as evaluateMessage,
  349. e.shop_reply_message as shopReplyMessage,
  350. e.score as score,
  351. e.create_time as eCreateTime,
  352. tus.avatar as avatar,
  353. tus.nick_name as userNickName
  354. from tb_order tor
  355. left join tb_indent ti on tor.order_id = ti.order_id
  356. left join tb_user tu on ti.rider_user_id = tu.user_id
  357. left join tb_user tus on ti.user_id = tus.user_id
  358. left join evaluate e on tor.order_number = e.order_number
  359. where tor.order_id = #{orderId}
  360. </select>
  361. <select id="selectBuyGoods" resultType="com.sqx.modules.order.entity.TbOrder">
  362. select tor.*,
  363. gs.shop_name as shopName,
  364. gs.detailed_address as detailedAddress,
  365. gs.shop_lng as shopLng,
  366. gs.shop_lat as shopLat,
  367. gs.phone as shopPhone,
  368. gs.errand_money as errandMoney,
  369. gs.exempt_min_money as exemptMinMoney,
  370. gs.minimum_delivery as minimumDelivery,
  371. gs.distribution_distance as distributionDistance
  372. from tb_order tor
  373. left join goods_shop gs on tor.shop_id = gs.shop_id
  374. where tor.order_id = #{orderId}
  375. and tor.user_id = #{userId}
  376. </select>
  377. <select id="selectOverTimeOrder" resultType="com.sqx.modules.order.entity.TbOrder">
  378. select *
  379. from tb_order
  380. where status = 7
  381. and pay_time &lt; #{overTime}
  382. </select>
  383. <select id="selectMakeOrdersList" resultType="com.sqx.modules.order.entity.TbOrder">
  384. select * from tb_order where status=6 and shop_receiving_time <![CDATA[ <= #{minusMinutes}]]></select>
  385. <select id="selectCurrentOrderSequenceByShopId" resultType="java.lang.Long">
  386. select
  387. order_id
  388. from
  389. tb_order
  390. where
  391. is_pay = 1
  392. and shop_id = #{shopId}
  393. and date(pay_time) = date(#{payTime})
  394. order by pay_time asc
  395. </select>
  396. <select id="countByShopIdAndActivityIdAndUserIdAndCurDate" resultType="java.lang.Integer">
  397. select
  398. count(1)
  399. from
  400. tb_order o
  401. left join activity_part_record apr on apr.order_id = o.order_id
  402. where
  403. o.shop_id = #{shopId}
  404. and o.user_id = #{userId}
  405. and date(o.create_time) = curdate()
  406. and apr.activity_id = #{activityId}
  407. and o.is_pay = 1
  408. <if test="orderId != null">
  409. and o.order_id != #{orderId}
  410. </if>
  411. </select>
  412. <select id="selectCurWaitReceivingOrderIds" resultType="java.lang.Long">
  413. select
  414. order_id
  415. from
  416. tb_order
  417. where
  418. reservation_flag = '1'
  419. and `status` = '7'
  420. and expect_delivery_time <![CDATA[ <= ]]> adddate(now(),interval 30 minute)
  421. </select>
  422. <select id="countUnFinishByShopId" resultType="java.lang.Integer">
  423. select count(order_id)
  424. from tb_order
  425. where shop_id = #{shopId} and status in (6, 3)
  426. </select>
  427. </mapper>