AdminOrderMapper.xml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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.ylx.order.mapper.AdminOrderMapper">
  4. <select id="selectAdminOrderPage" resultType="com.ylx.order.domain.vo.AdminOrderPageVO">
  5. SELECT
  6. o.id AS id,
  7. o.order_no AS orderNo,
  8. o.create_time AS orderTime,
  9. COALESCE(p.title, o.project_name) AS projectName,
  10. o.project_duration AS projectDuration,
  11. o.appointment_start_time AS appointmentStartTime,
  12. COALESCE(p.price, o.base_price) AS unitPrice,
  13. 1 AS quantity,
  14. p.unit_type AS unitType,
  15. o.final_amount AS orderAmount,
  16. o.traffic_fee AS trafficFee,
  17. o.payment_method AS paymentMethod,
  18. u.c_nick_name AS userNickName,
  19. o.contact_person_name AS contactPersonName,
  20. o.contact_phone_number AS contactPhoneNumber,
  21. o.contact_address_info AS contactAddressInfo,
  22. o.status AS status,
  23. o.exec_status AS execStatus,
  24. COALESCE(mt.te_nick_name, o.merchant_nick_name) AS merchantNickName,
  25. mt.te_phone AS merchantPhone,
  26. p.category_id AS categoryId,
  27. sc.name AS categoryName,
  28. o.merchant_latitude as merchantLatitude,
  29. o.merchant_longitude as merchantLongitude,
  30. u.sex as sex,
  31. o.start_time as startTime
  32. FROM t_order o
  33. LEFT JOIN t_wx_user u ON u.id = CAST(o.user_id AS CHAR) AND u.is_delete = 0
  34. LEFT JOIN ma_technician mt ON mt.id = o.merchant_id AND mt.is_delete = 0
  35. LEFT JOIN project p ON p.id = o.project_id AND p.is_delete = 0
  36. LEFT JOIN service_category sc ON sc.id = p.category_id AND sc.is_delete = 0
  37. <where>
  38. o.is_delete = 0
  39. <if test="dto.orderNo != null and dto.orderNo != ''">
  40. AND o.order_no LIKE CONCAT('%', #{dto.orderNo}, '%')
  41. </if>
  42. <if test="dto.queryStartTime != null">
  43. AND o.create_time &gt;= #{dto.queryStartTime}
  44. </if>
  45. <if test="dto.queryEndTime != null">
  46. AND o.create_time &lt;= #{dto.queryEndTime}
  47. </if>
  48. <if test="dto.userKeyword != null and dto.userKeyword != ''">
  49. <choose>
  50. <when test="dto.userSearchType == 'nickName'">
  51. AND u.c_nick_name LIKE CONCAT('%', #{dto.userKeyword}, '%')
  52. </when>
  53. <when test="dto.userSearchType == 'name'">
  54. AND o.contact_person_name LIKE CONCAT('%', #{dto.userKeyword}, '%')
  55. </when>
  56. <otherwise>
  57. AND u.c_phone LIKE CONCAT('%', #{dto.userKeyword}, '%')
  58. </otherwise>
  59. </choose>
  60. </if>
  61. <if test="dto.categoryId != null">
  62. AND p.category_id = #{dto.categoryId}
  63. </if>
  64. <if test="dto.projectName != null and dto.projectName != ''">
  65. AND o.project_name LIKE CONCAT('%', #{dto.projectName}, '%')
  66. </if>
  67. <if test="dto.merchantKeyword != null and dto.merchantKeyword != ''">
  68. <choose>
  69. <when test="dto.merchantSearchType == 'phone'">
  70. AND mt.te_phone LIKE CONCAT('%', #{dto.merchantKeyword}, '%')
  71. </when>
  72. <otherwise>
  73. AND o.merchant_nick_name LIKE CONCAT('%', #{dto.merchantKeyword}, '%')
  74. </otherwise>
  75. </choose>
  76. </if>
  77. <if test="dto.paymentMethod != null">
  78. AND o.payment_method = #{dto.paymentMethod}
  79. </if>
  80. <choose>
  81. <when test="dto.abnormalOrder != null and dto.abnormalOrder">
  82. AND o.status IN (7, 8, 9)
  83. </when>
  84. <when test="dto.status != null">
  85. AND o.status = #{dto.status}
  86. </when>
  87. </choose>
  88. <if test="dto.merchantType != null">
  89. AND o.merchant_type = #{dto.merchantType}
  90. </if>
  91. </where>
  92. ORDER BY o.create_time DESC
  93. </select>
  94. <!-- 查询回收站订单列表 -->
  95. <select id="selectAdminOrderRecyclePage" resultType="com.ylx.order.domain.vo.AdminOrderPageVO">
  96. SELECT
  97. o.id AS id,
  98. o.order_no AS orderNo,
  99. o.create_time AS orderTime,
  100. COALESCE(p.title, o.project_name) AS projectName,
  101. o.project_duration AS projectDuration,
  102. o.appointment_start_time AS appointmentStartTime,
  103. COALESCE(p.price, o.base_price) AS unitPrice,
  104. 1 AS quantity,
  105. p.unit_type AS unitType,
  106. o.final_amount AS orderAmount,
  107. o.traffic_fee AS trafficFee,
  108. o.payment_method AS paymentMethod,
  109. u.c_nick_name AS userNickName,
  110. o.contact_person_name AS contactPersonName,
  111. o.contact_phone_number AS contactPhoneNumber,
  112. o.contact_address_info AS contactAddressInfo,
  113. o.status AS status,
  114. o.exec_status AS execStatus,
  115. COALESCE(mt.te_nick_name, o.merchant_nick_name) AS merchantNickName,
  116. mt.te_phone AS merchantPhone,
  117. p.category_id AS categoryId,
  118. sc.name AS categoryName
  119. FROM t_order o
  120. LEFT JOIN t_wx_user u ON u.id = CAST(o.user_id AS CHAR) AND u.is_delete = 0
  121. LEFT JOIN ma_technician mt ON mt.id = o.merchant_id AND mt.is_delete = 0
  122. LEFT JOIN project p ON p.id = o.project_id AND p.is_delete = 0
  123. LEFT JOIN service_category sc ON sc.id = p.category_id AND sc.is_delete = 0
  124. <where>
  125. o.is_delete = 1
  126. <if test="dto.orderNo != null and dto.orderNo != ''">
  127. AND o.order_no LIKE CONCAT('%', #{dto.orderNo}, '%')
  128. </if>
  129. <if test="dto.queryStartTime != null">
  130. AND o.create_time &gt;= #{dto.queryStartTime}
  131. </if>
  132. <if test="dto.queryEndTime != null">
  133. AND o.create_time &lt;= #{dto.queryEndTime}
  134. </if>
  135. <if test="dto.userKeyword != null and dto.userKeyword != ''">
  136. <choose>
  137. <when test="dto.userSearchType == 'nickName'">
  138. AND u.c_nick_name LIKE CONCAT('%', #{dto.userKeyword}, '%')
  139. </when>
  140. <when test="dto.userSearchType == 'name'">
  141. AND o.contact_person_name LIKE CONCAT('%', #{dto.userKeyword}, '%')
  142. </when>
  143. <otherwise>
  144. AND u.c_phone LIKE CONCAT('%', #{dto.userKeyword}, '%')
  145. </otherwise>
  146. </choose>
  147. </if>
  148. <if test="dto.categoryId != null">
  149. AND p.category_id = #{dto.categoryId}
  150. </if>
  151. <if test="dto.projectName != null and dto.projectName != ''">
  152. AND o.project_name LIKE CONCAT('%', #{dto.projectName}, '%')
  153. </if>
  154. <if test="dto.merchantKeyword != null and dto.merchantKeyword != ''">
  155. <choose>
  156. <when test="dto.merchantSearchType == 'phone'">
  157. AND mt.te_phone LIKE CONCAT('%', #{dto.merchantKeyword}, '%')
  158. </when>
  159. <otherwise>
  160. AND o.merchant_nick_name LIKE CONCAT('%', #{dto.merchantKeyword}, '%')
  161. </otherwise>
  162. </choose>
  163. </if>
  164. <if test="dto.paymentMethod != null">
  165. AND o.payment_method = #{dto.paymentMethod}
  166. </if>
  167. <choose>
  168. <when test="dto.abnormalOrder != null and dto.abnormalOrder">
  169. AND o.status IN (7, 8, 9)
  170. </when>
  171. <when test="dto.status != null">
  172. AND o.status = #{dto.status}
  173. </when>
  174. </choose>
  175. <if test="dto.merchantType != null">
  176. AND o.merchant_type = #{dto.merchantType}
  177. </if>
  178. </where>
  179. ORDER BY o.create_time DESC
  180. </select>
  181. <!-- 查询服务分类选项 -->
  182. <select id="selectServiceCategoryOptions" resultType="com.ylx.order.domain.vo.AdminOrderServiceCategoryVO">
  183. SELECT
  184. id,
  185. service_tag AS serviceTag,
  186. name
  187. FROM service_category
  188. WHERE is_delete = 0
  189. ORDER BY sort ASC, id ASC
  190. </select>
  191. <!-- 根据订单ID逻辑删除服务订单 -->
  192. <update id="logicDeleteById">
  193. UPDATE t_order
  194. SET is_delete = 1,
  195. deleted_time = NOW(),
  196. update_time = NOW()
  197. WHERE id = #{id}
  198. AND is_delete = 0
  199. </update>
  200. <!-- 根据订单ID恢复回收站服务订单 -->
  201. <update id="restoreById">
  202. UPDATE t_order
  203. SET is_delete = 0,
  204. deleted_time = NULL,
  205. update_time = NOW()
  206. WHERE id = #{id}
  207. AND is_delete = 1
  208. </update>
  209. <select id="selectRefundApplicationOrderById" resultType="com.ylx.massage.domain.CancelOrderApplication">
  210. SELECT
  211. o.order_no AS orderNo,
  212. COALESCE(u.c_openid, CAST(o.user_id AS CHAR)) AS openId,
  213. COALESCE(o.contact_person_name, u.c_nick_name) AS userName,
  214. COALESCE(o.contact_phone_number, u.c_phone) AS userPhone,
  215. CAST(o.merchant_id AS CHAR) AS techId,
  216. mt.te_name AS techName,
  217. COALESCE(mt.te_nick_name, o.merchant_nick_name) AS techNickName,
  218. mt.te_phone AS techPhone,
  219. COALESCE(p.title, o.project_name) AS projectName,
  220. CAST(o.project_duration AS CHAR) AS projectDuration,
  221. CAST(o.project_duration AS CHAR) AS serviceDuration,
  222. COALESCE(o.final_amount, 0) AS orderAmount,
  223. COALESCE(o.final_amount, 0) AS refundAmount,
  224. o.status AS orderStatus
  225. FROM t_order o
  226. LEFT JOIN t_wx_user u ON u.id = CAST(o.user_id AS CHAR) AND u.is_delete = 0
  227. LEFT JOIN ma_technician mt ON mt.id = o.merchant_id AND mt.is_delete = 0
  228. LEFT JOIN project p ON p.id = o.project_id AND p.is_delete = 0
  229. WHERE o.id = #{id}
  230. AND o.is_delete = 0
  231. LIMIT 1
  232. </select>
  233. <select id="countPendingRefundApplicationByOrderNo" resultType="java.lang.Integer">
  234. SELECT COUNT(1)
  235. FROM t_cancel_order_application
  236. WHERE order_no = #{orderNo}
  237. AND audit_status = 0
  238. AND is_delete = 0
  239. </select>
  240. <insert id="insertRefundApplication">
  241. INSERT INTO t_cancel_order_application (
  242. id,
  243. order_no,
  244. open_id,
  245. user_name,
  246. user_phone,
  247. tech_id,
  248. tech_name,
  249. tech_nick_name,
  250. tech_phone,
  251. project_name,
  252. project_duration,
  253. service_duration,
  254. order_amount,
  255. refund_amount,
  256. order_status,
  257. audit_status,
  258. application_time,
  259. cancel_order_reason,
  260. create_time,
  261. update_time,
  262. is_delete
  263. ) VALUES (
  264. #{application.id},
  265. #{application.orderNo},
  266. #{application.openId},
  267. #{application.userName},
  268. #{application.userPhone},
  269. #{application.techId},
  270. #{application.techName},
  271. #{application.techNickName},
  272. #{application.techPhone},
  273. #{application.projectName},
  274. #{application.projectDuration},
  275. #{application.serviceDuration},
  276. #{application.orderAmount},
  277. #{application.refundAmount},
  278. #{application.orderStatus},
  279. #{application.auditStatus},
  280. #{application.applicationTime},
  281. #{application.cancelOrderReason},
  282. #{application.createTime},
  283. #{application.updateTime},
  284. #{application.isDelete}
  285. )
  286. </insert>
  287. <!-- 通过订单ID查询订单详情 -->
  288. <select id="selectOrderDetailInfoById" resultType="com.ylx.order.domain.vo.AdminOrderDetailVO$OrderInfoVO">
  289. SELECT
  290. o.id,
  291. o.order_no AS orderNo,
  292. o.status,
  293. u.c_nick_name AS userNickName,
  294. o.contact_person_name AS contactPersonName,
  295. o.contact_phone_number AS contactPhoneNumber,
  296. o.contact_address_info AS contactAddressInfo,
  297. COALESCE(mt.te_nick_name, o.merchant_nick_name) AS merchantNickName,
  298. mt.te_phone AS merchantPhone,
  299. DATE_FORMAT(o.appointment_start_time, '%Y-%m-%d %H:%i:%s') AS appointmentStartTime,
  300. DATE_FORMAT(o.start_time, '%Y-%m-%d %H:%i:%s') AS startTime,
  301. DATE_FORMAT(o.completed_time, '%Y-%m-%d %H:%i:%s') AS completedTime,
  302. DATE_FORMAT(o.create_time, '%Y-%m-%d %H:%i:%s') AS createTime,
  303. DATE_FORMAT(o.paid_time, '%Y-%m-%d %H:%i:%s') AS paidTime,
  304. o.payment_method AS paymentMethod,
  305. o.project_duration AS projectDuration,
  306. o.user_latitude AS userLatitude,
  307. o.user_longitude AS userLongitude,
  308. o.merchant_latitude AS merchantLatitude,
  309. o.merchant_longitude AS merchantLongitude,
  310. o.virtual_latitude AS virtualLatitude,
  311. o.virtual_longitude AS virtualLongitude,
  312. o.start_photo AS startPhoto,
  313. o.platform_income AS platformIncome,
  314. o.merchant_income AS merchantIncome,
  315. ass.id AS afterSalesServiceId,
  316. ass.status AS afterSalesServiceStatus
  317. FROM t_order o
  318. LEFT JOIN t_wx_user u ON u.id = CAST(o.user_id AS CHAR) AND u.is_delete = 0
  319. LEFT JOIN ma_technician mt ON mt.id = o.merchant_id AND mt.is_delete = 0
  320. LEFT JOIN after_sales_service ass ON ass.id = (
  321. SELECT ass_inner.id
  322. FROM after_sales_service ass_inner
  323. WHERE ass_inner.order_id = o.id
  324. AND ass_inner.is_delete = 0
  325. ORDER BY ass_inner.create_time DESC, ass_inner.id DESC
  326. LIMIT 1
  327. )
  328. WHERE o.id = #{id}
  329. AND o.is_delete = 0
  330. LIMIT 1
  331. </select>
  332. <select id="selectOrderProjectDetailById" resultType="com.ylx.order.domain.vo.AdminOrderDetailVO$ProjectInfoVO">
  333. SELECT
  334. COALESCE(p.title, o.project_name) AS projectName,
  335. COALESCE(p.cover, o.project_cover) AS projectCover,
  336. p.standard_duration AS standardDuration,
  337. p.unit_type AS unitType,
  338. COALESCE(p.price, o.base_price) AS unitPrice,
  339. p.merchant_share_ratio AS merchantCommission,
  340. o.final_amount AS finalAmount,
  341. o.base_price AS basePrice,
  342. o.traffic_fee AS trafficFee,
  343. o.coupon_discount AS couponDiscount,
  344. ass.id AS afterSalesServiceId,
  345. ass.status AS afterSalesServiceStatus
  346. FROM t_order o
  347. LEFT JOIN project p ON p.id = o.project_id AND p.is_delete = 0
  348. LEFT JOIN after_sales_service ass ON ass.id = (
  349. SELECT ass_inner.id
  350. FROM after_sales_service ass_inner
  351. WHERE ass_inner.order_id = o.id
  352. AND ass_inner.is_delete = 0
  353. ORDER BY ass_inner.create_time DESC, ass_inner.id DESC
  354. LIMIT 1
  355. )
  356. WHERE o.id = #{id}
  357. AND o.is_delete = 0
  358. LIMIT 1
  359. </select>
  360. <!-- 根据订单ID查询订单操作日志 -->
  361. <select id="selectOrderOperationLogs" resultType="com.ylx.order.domain.vo.AdminOrderDetailVO$OperationLogVO">
  362. SELECT
  363. COALESCE(osf.create_by, '系统') AS operator,
  364. DATE_FORMAT(osf.create_time, '%Y-%m-%d %H:%i:%s') AS operationTime,
  365. osf.status
  366. FROM t_order_status_flow osf
  367. WHERE osf.order_id = #{id}
  368. ORDER BY osf.create_time ASC
  369. </select>
  370. <!-- 根据订单ID查询派单订单 -->
  371. <select id="selectDispatchOrderById" resultType="com.ylx.order.domain.vo.AdminOrderDispatchOrderVO">
  372. SELECT
  373. o.id AS orderId,
  374. o.order_no AS orderNo,
  375. o.status AS status,
  376. o.project_id AS projectId,
  377. COALESCE(p.title, o.project_name) AS projectName,
  378. p.category_id AS categoryId,
  379. o.user_latitude AS userLatitude,
  380. o.user_longitude AS userLongitude
  381. FROM t_order o
  382. LEFT JOIN project p ON p.id = o.project_id AND p.is_delete = 0
  383. WHERE o.id = #{id}
  384. AND o.is_delete = 0
  385. LIMIT 1
  386. </select>
  387. <!-- 查询派单商户候选 -->
  388. <select id="selectDispatchMerchantCandidates" resultType="com.ylx.order.domain.vo.AdminOrderDispatchMerchantVO">
  389. SELECT
  390. candidate.*,
  391. CASE
  392. WHEN candidate.distance_meters &lt; 1000 THEN CONCAT(ROUND(candidate.distance_meters, 0), 'm')
  393. ELSE CONCAT(ROUND(candidate.distance_meters / 1000, 1), 'km')
  394. END AS distanceShow
  395. FROM (
  396. SELECT
  397. t.id AS merchantId,
  398. t.te_name AS merchantName,
  399. t.te_nick_name AS merchantNickName,
  400. t.te_phone AS merchantPhone,
  401. COALESCE(t.te_avatar, t.avatar) AS merchantAvatar,
  402. t.tech_type AS merchantType,
  403. t.post_state AS postState,
  404. CASE t.post_state
  405. WHEN 1 THEN '在线接单'
  406. WHEN 0 THEN '休息中'
  407. ELSE ''
  408. END AS postStateName,
  409. t.service_state AS serviceState,
  410. CASE t.service_state
  411. WHEN 0 THEN '服务中'
  412. WHEN 1 THEN '待接单'
  413. WHEN 2 THEN '休息中'
  414. ELSE ''
  415. END AS serviceStateName,
  416. COALESCE(addr.detail_address, addr.address, addr.atlas_add, t.te_address) AS merchantAddress,
  417. addr.latitude AS merchantLatitude,
  418. addr.longitude AS merchantLongitude,
  419. ROUND(ST_Distance_Sphere(POINT(addr.longitude, addr.latitude), POINT(#{order.userLongitude}, #{order.userLatitude})), 2) AS distance_meters
  420. FROM ma_technician t
  421. INNER JOIN ma_project mp ON mp.merchant_id = t.id
  422. AND mp.is_delete = 0
  423. AND mp.audit_status = 1
  424. AND mp.project_is_enable = 1
  425. INNER JOIN project p ON p.id = mp.project_id
  426. AND p.is_delete = 0
  427. INNER JOIN t_address addr ON addr.merchant_id = t.id
  428. AND addr.user_type = 2
  429. AND addr.type = 1
  430. AND addr.is_delete = 0
  431. WHERE t.is_delete = 0
  432. AND t.audit_status = 2
  433. AND t.n_status2 = 0
  434. AND t.merchant_status = 0
  435. AND addr.longitude IS NOT NULL
  436. AND addr.latitude IS NOT NULL
  437. <choose>
  438. <when test="order.categoryId != null">
  439. AND p.category_id = #{order.categoryId}
  440. </when>
  441. <otherwise>
  442. AND mp.project_id = #{order.projectId}
  443. </otherwise>
  444. </choose>
  445. <if test="query.cityCode != null and query.cityCode != ''">
  446. AND t.te_area_code = #{query.cityCode}
  447. </if>
  448. <if test="query.keyword != null and query.keyword != ''">
  449. AND (
  450. t.te_name LIKE CONCAT('%', #{query.keyword}, '%')
  451. OR t.te_nick_name LIKE CONCAT('%', #{query.keyword}, '%')
  452. OR t.te_phone LIKE CONCAT('%', #{query.keyword}, '%')
  453. )
  454. </if>
  455. ) candidate
  456. WHERE candidate.distance_meters &lt;= #{query.radiusMeters}
  457. ORDER BY candidate.distance_meters ASC, candidate.merchantId ASC
  458. </select>
  459. <select id="selectDispatchMerchantById" resultType="com.ylx.order.domain.vo.AdminOrderDispatchMerchantVO">
  460. SELECT
  461. candidate.*,
  462. CASE
  463. WHEN candidate.distance_meters &lt; 1000 THEN CONCAT(ROUND(candidate.distance_meters, 0), 'm')
  464. ELSE CONCAT(ROUND(candidate.distance_meters / 1000, 1), 'km')
  465. END AS distanceShow
  466. FROM (
  467. SELECT
  468. t.id AS merchantId,
  469. t.te_name AS merchantName,
  470. t.te_nick_name AS merchantNickName,
  471. t.te_phone AS merchantPhone,
  472. COALESCE(t.te_avatar, t.avatar) AS merchantAvatar,
  473. t.tech_type AS merchantType,
  474. t.post_state AS postState,
  475. CASE t.post_state
  476. WHEN 1 THEN '在线接单'
  477. WHEN 0 THEN '休息中'
  478. ELSE ''
  479. END AS postStateName,
  480. t.service_state AS serviceState,
  481. CASE t.service_state
  482. WHEN 0 THEN '服务中'
  483. WHEN 1 THEN '待接单'
  484. WHEN 2 THEN '休息中'
  485. ELSE ''
  486. END AS serviceStateName,
  487. COALESCE(addr.detail_address, addr.address, addr.atlas_add, t.te_address) AS merchantAddress,
  488. addr.latitude AS merchantLatitude,
  489. addr.longitude AS merchantLongitude,
  490. ROUND(ST_Distance_Sphere(POINT(addr.longitude, addr.latitude), POINT(#{order.userLongitude}, #{order.userLatitude})), 2) AS distance_meters
  491. FROM ma_technician t
  492. INNER JOIN ma_project mp ON mp.merchant_id = t.id
  493. AND mp.is_delete = 0
  494. AND mp.audit_status = 1
  495. AND mp.project_is_enable = 1
  496. INNER JOIN project p ON p.id = mp.project_id
  497. AND p.is_delete = 0
  498. INNER JOIN t_address addr ON addr.merchant_id = t.id
  499. AND addr.user_type = 2
  500. AND addr.type = 1
  501. AND addr.is_delete = 0
  502. WHERE t.id = #{merchantId}
  503. AND t.is_delete = 0
  504. AND t.audit_status = 2
  505. AND t.merchant_status =0
  506. AND addr.longitude IS NOT NULL
  507. AND addr.latitude IS NOT NULL
  508. <choose>
  509. <when test="order.categoryId != null">
  510. AND p.category_id = #{order.categoryId}
  511. </when>
  512. <otherwise>
  513. AND mp.project_id = #{order.projectId}
  514. </otherwise>
  515. </choose>
  516. ) candidate
  517. WHERE candidate.distance_meters &lt;= #{radiusMeters}
  518. ORDER BY candidate.distance_meters ASC
  519. LIMIT 1
  520. </select>
  521. <!-- 查询订单当前派单状态 -->
  522. <select id="countCurrentDispatchByOrderId" resultType="java.lang.Integer">
  523. SELECT COUNT(1)
  524. FROM t_order_dispatch
  525. WHERE order_id = #{orderId}
  526. AND current_flag = 1
  527. AND is_delete = 0
  528. </select>
  529. <insert id="insertOrderDispatch" parameterType="com.ylx.order.domain.OrderDispatch">
  530. INSERT INTO t_order_dispatch (
  531. order_id,
  532. order_no,
  533. merchant_id,
  534. merchant_name,
  535. merchant_nick_name,
  536. merchant_phone,
  537. merchant_avatar,
  538. merchant_type,
  539. project_id,
  540. project_name,
  541. category_id,
  542. city_code,
  543. user_latitude,
  544. user_longitude,
  545. merchant_latitude,
  546. merchant_longitude,
  547. distance_meters,
  548. dispatch_status,
  549. dispatch_source,
  550. current_flag,
  551. order_status_before,
  552. order_status_after,
  553. dispatch_time,
  554. remark,
  555. operator_id,
  556. operator_name,
  557. create_by,
  558. create_time,
  559. update_by,
  560. update_time,
  561. is_delete
  562. ) VALUES (
  563. #{orderId},
  564. #{orderNo},
  565. #{merchantId},
  566. #{merchantName},
  567. #{merchantNickName},
  568. #{merchantPhone},
  569. #{merchantAvatar},
  570. #{merchantType},
  571. #{projectId},
  572. #{projectName},
  573. #{categoryId},
  574. #{cityCode},
  575. #{userLatitude},
  576. #{userLongitude},
  577. #{merchantLatitude},
  578. #{merchantLongitude},
  579. #{distanceMeters},
  580. #{dispatchStatus},
  581. #{dispatchSource},
  582. #{currentFlag},
  583. #{orderStatusBefore},
  584. #{orderStatusAfter},
  585. #{dispatchTime},
  586. #{remark},
  587. #{operatorId},
  588. #{operatorName},
  589. #{createBy},
  590. #{createTime},
  591. #{updateBy},
  592. #{updateTime},
  593. #{isDelete}
  594. )
  595. </insert>
  596. <!-- 更新订单派单状态 -->
  597. <update id="updateOrderDispatch">
  598. UPDATE t_order
  599. SET merchant_id = #{merchant.merchantId},
  600. merchant_type = #{merchant.merchantType},
  601. merchant_nick_name = #{merchant.merchantNickName},
  602. merchant_avatar = #{merchant.merchantAvatar},
  603. merchant_latitude = #{merchant.merchantLatitude},
  604. merchant_longitude = #{merchant.merchantLongitude},
  605. status = #{statusAfter},
  606. dispatched_status = 1,
  607. dispatched_time = NOW(),
  608. update_time = NOW()
  609. WHERE id = #{orderId}
  610. AND is_delete = 0
  611. AND status = #{statusBefore}
  612. </update>
  613. <insert id="insertOrderStatusFlow">
  614. INSERT INTO t_order_status_flow (
  615. order_id,
  616. status,
  617. create_by,
  618. create_time,
  619. update_by,
  620. update_time
  621. ) VALUES (
  622. #{orderId},
  623. #{status},
  624. #{operator},
  625. NOW(),
  626. #{operator},
  627. NOW()
  628. )
  629. </insert>
  630. </mapper>