OrderMapper.xml 34 KB

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