OrderMapper.xml 31 KB

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