TOrderMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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.TOrderMapper">
  4. <resultMap id="getAllMap" type="com.ylx.order.domain.TOrder">
  5. <id column="c_id" property="cId"/>
  6. <result column="order_no" property="orderNo"/>
  7. <result column="atlas_add" property="atlasAdd"/>
  8. <result column="pay_type" property="payType"/>
  9. <result column="preferential" property="preferential"/>
  10. <result column="order_type" property="orderType"/>
  11. <result column="virtual_order_flag" property="virtualOrderFlag"/>
  12. <result column="virtual_order_allocation" property="virtualOrderAllocation"/>
  13. <result column="price_difference" property="priceDifference"/>
  14. <result column="c_js_id" property="cJsId"/>
  15. <result column="tape" property="tape"/>
  16. <result column="dept_id" property="deptId"/>
  17. <result column="distance" property="distance"/>
  18. <result column="dept_name" property="deptName"/>
  19. <result column="order_type" property="orderType"/>
  20. <result column="price_difference" property="priceDifference"/>
  21. <result column="new_js_id" property="newJsId"/>
  22. <result column="fare" property="fare"/>
  23. <result column="total_price" property="totalPrice"/>
  24. <result column="parent_no" property="parentNo"/>
  25. <result column="c_open_id" property="cOpenId"/>
  26. <result column="timeout_cause" property="timeoutCause"/>
  27. <result column="coupon_receive_id" property="couponReceiveId"/>
  28. <result column="c_goods" property="cGoods"
  29. typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
  30. <result column="d_total_money" property="dTotalMoney"/>
  31. <result column="n_status" property="nStatus"/>
  32. <result column="c_address" property="cAddress"/>
  33. <result column="c_name" property="cName"/>
  34. <result column="c_phone" property="cPhone"/>
  35. <result column="c_note" property="cNote"/>
  36. <result column="c_time" property="cTime"/>
  37. <result column="name" property="name"/>
  38. <result column="address" property="address"/>
  39. <result column="longitude" property="longitude"/>
  40. <result column="latitude" property="latitude"/>
  41. <result column="arrival_longitude" property="arrivalLongitude"/>
  42. <result column="arrival_latitude" property="arrivalLatitude"/>
  43. <result column="depart_longitude" property="departLongitude"/>
  44. <result column="depart_latitude" property="departLatitude"/>
  45. <result column="arrival_photo" property="arrivalPhoto"/>
  46. <result column="depart_time" property="departTime"/>
  47. <result column="c_tj_open_id" property="cTjOpenId"/>
  48. <result column="old_js_id" property="oldJsId"/>
  49. <result column="dt_create_time" property="dtCreateTime"/>
  50. <result column="acceptance_time" property="acceptanceTime"/>
  51. <result column="reach_time" property="reachTime"/>
  52. <result column="start_time" property="startTime"/>
  53. <result column="pay_time" property="payTime"/>
  54. <result column="end_time" property="endTime"/>
  55. <result column="reason_refusal" property="reasonRefusal"/>
  56. <association property="js" javaType="com.ylx.massage.domain.TJs">
  57. <id column="jsc_id" property="cOpenId"/>
  58. <result column="jsc_bh_list" property="cBhList"/>
  59. <result column="jsc_img_list" property="cImgList"
  60. typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
  61. <result column="jsn_sex" property="nSex"/>
  62. <result column="jsc_nick_name" property="cNickName"/>
  63. <result column="jsc_portrait" property="cPortrait"/>
  64. <result column="jsc_name" property="cName"/>
  65. <result column="jsc_phone" property="cPhone"/>
  66. <result column="jsc_jianjie" property="cJianjie"/>
  67. <result column="jsn_star" property="nStar"/>
  68. <result column="jsn_bili" property="nBili"/>
  69. <result column="jsn_num" property="nNum"/>
  70. <result column="jsn_status" property="nStatus"/>
  71. <result column="jsn_status2" property="nStatus2"/>
  72. <result column="jsn_tong" property="nTong"/>
  73. <result column="jsc_time" property="cTime"/>
  74. <result column="jsn_b1" property="nB1"/>
  75. <result column="jsn_b2" property="nB2"/>
  76. <result column="jsn_b3" property="nB3"/>
  77. <result column="jsn_b3" property="nB3"/>
  78. </association>
  79. <association property="wxUser" javaType="com.ylx.massage.domain.TWxUser">
  80. <id column="wxUserc_openid" property="cOpenid"/>
  81. <result column="wxUsercc_icon" property="cIcon"/>
  82. <result column="wxc_nick_name" property="cNickName"/>
  83. </association>
  84. </resultMap>
  85. <!-- 查询所有订单(PC端 H5端) -->
  86. <select id="getAll" resultMap="getAllMap">
  87. select t_order.c_id,
  88. t_order.order_no,
  89. t_order.atlas_add,
  90. t_order.pay_type,
  91. t_order.c_js_id,
  92. t_order.order_type,
  93. t_order.virtual_order_flag,
  94. t_order.virtual_order_allocation,
  95. t_order.price_difference,
  96. t_order.tape,
  97. t_order.fare,
  98. t_order.total_price,
  99. t_order.parent_no,
  100. t_order.c_open_id,
  101. t_order.c_goods,
  102. t_order.d_total_money,
  103. t_order.n_status,
  104. t_order.c_address,
  105. t_order.c_name,
  106. t_order.c_phone,
  107. t_order.c_note,
  108. t_order.c_time,
  109. t_order.pay_time,
  110. t_order.timeout_cause,
  111. t_order.name,
  112. t_order.dept_id,
  113. t_order.dept_name,
  114. t_order.latitude,
  115. t_order.longitude,
  116. t_order.address,
  117. t_order.c_tj_open_id,
  118. t_order.dt_create_time,
  119. t_order.acceptance_time,
  120. t_order.reach_time,
  121. t_order.old_js_id,
  122. t_order.start_time,
  123. t_order.arrival_longitude,
  124. t_order.arrival_latitude,
  125. t_order.depart_longitude,
  126. t_order.depart_latitude,
  127. t_order.arrival_photo,
  128. t_order.depart_time,
  129. t_order.end_time,
  130. t_order.preferential,
  131. t_order.distance,
  132. t_order.reason_refusal,
  133. t_js.c_open_id as jsc_open_id,
  134. t_js.c_bh_list as jsc_bh_list,
  135. t_js.c_img_list as jsc_img_list,
  136. t_js.c_sfz_img as jsc_sfz_img,
  137. t_js.n_sex as jsn_sex,
  138. t_js.c_nick_name as jsc_nick_name,
  139. t_js.c_portrait as jsc_portrait,
  140. t_js.c_name as jsc_name,
  141. t_js.c_phone as jsc_phone,
  142. t_js.c_address as jsc_address,
  143. t_js.c_jianjie as jsc_jianjie,
  144. t_js.n_star as jsn_star,
  145. t_js.n_bili as jsn_bili,
  146. t_js.n_num as jsn_num,
  147. t_js.n_status as jsn_status,
  148. t_js.n_status2 as jsn_status2,
  149. t_js.n_tong as jsn_tong,
  150. t_js.c_time as jsc_time,
  151. t_js.n_b1 as jsn_b1,
  152. t_js.n_b2 as jsn_b2,
  153. t_js.n_b3 as jsn_b3,
  154. t_js.dt_create_time as jsdt_create_time,
  155. t_wx_user.c_openid as wxUserc_openid,
  156. t_wx_user.c_icon as wxUsercc_icon,
  157. t_wx_user.c_nick_name as wxc_nick_name
  158. from t_order
  159. left join
  160. t_js on
  161. t_order.c_js_id = t_js.id
  162. left join
  163. t_wx_user on
  164. t_wx_user.c_openid = t_order.c_open_id
  165. <where>
  166. t_order.is_delete = 0 and t_js.is_delete = 0 and t_wx_user.is_delete = 0
  167. and t_order.n_status != 8 and t_order.n_status != -2 and t_order.n_status != -3
  168. and t_order.n_status != -1
  169. <if test="param.cId != null and param.cId != ''">
  170. and t_order.c_id = #{ param.cId }
  171. </if>
  172. <if test="param.cName != null and param.cName != ''">
  173. and t_order.c_name like concat('%',#{param.cName},'%')
  174. </if>
  175. <if test="param.cNickName != null and param.cNickName != ''">
  176. and t_js.c_nick_name like concat('%',#{param.cNickName},'%')
  177. </if>
  178. <if test="param.jsName != null and param.jsName != ''">
  179. and t_js.c_name like concat('%',#{param.jsName},'%')
  180. </if>
  181. <if test="param.jsPhone != null and param.jsPhone != ''">
  182. and t_js.c_phone like concat('%',#{param.jsPhone},'%')
  183. </if>
  184. <if test="param.cPhone != null and param.cPhone != ''">
  185. and t_order.c_phone = #{param.cPhone}
  186. </if>
  187. <if test="param.orderNo != null and param.orderNo != ''">
  188. and t_order.order_no = #{ param.orderNo }
  189. </if>
  190. <!-- 订单状态(-1:待付款 0:待接单 1:已接单 6:已出发 2:已到达 3:服务中 4:待评价 5:已完成
  191. 7:退单待审核 8:退单审核通过 -2:已取消 -3:已拒绝) -->
  192. <!--<if test="param.nStatus != null and param.nStatus != 10 and param.nStatus != -10 and param.nStatus != 100">-->
  193. <!-- and t_order.n_status = #{ param.nStatus }-->
  194. <!--</if>-->
  195. <!--<if test="param.nStatus == 10">-->
  196. <!-- and t_order.n_status in(0,1,2,3)-->
  197. <!--</if>-->
  198. <!--<if test="param.nStatus == -10">-->
  199. <!-- and t_order.n_status in(-2,-3)-->
  200. <!--</if>-->
  201. <if test="param.nStatus != null">
  202. and t_order.n_status = #{ param.nStatus }
  203. </if>
  204. <if test="param.wStatus != null">
  205. and t_order.w_status = #{ param.wStatus }
  206. </if>
  207. <if test="param.cJsId != null and param.cJsId != ''">
  208. and t_order.c_js_id = #{ param.cJsId }
  209. </if>
  210. <if test="param.deptId != null and param.deptId != '' and param.deptId != 100">
  211. and t_order.dept_id = #{ param.deptId }
  212. </if>
  213. <if test="param.cOpenId != null and param.cOpenId != ''">
  214. and t_order.c_open_id = #{ param.cOpenId }
  215. </if>
  216. <if test="param.dtCreateTimeBegin != null and param.dtCreateTimeBegin != '' and param.dtCreateTimeTimeEnd != null and param.dtCreateTimeTimeEnd != ''">
  217. and t_order.dt_create_time between #{ param.dtCreateTimeBegin } and #{ param.dtCreateTimeTimeEnd }
  218. </if>
  219. <if test="param.payTimeBegin != null and param.payTimeBegin != '' and param.payTimeEnd != null and param.payTimeEnd != ''">
  220. and t_order.pay_time between #{param.payTimeBegin} and #{param.payTimeEnd}
  221. </if>
  222. </where>
  223. order by
  224. t_order.dt_create_time desc
  225. </select>
  226. <select id="getOrderNum" resultType="java.lang.Integer">
  227. SELECT count(1)
  228. FROM t_order
  229. WHERE is_delete = 0
  230. AND c_js_id = #{jsid}
  231. AND end_time BETWEEN #{startDate} AND #{endDate}
  232. AND n_status in (4, 5)
  233. </select>
  234. <select id="getAddNum" resultType="java.lang.Integer">
  235. SELECT count(1)
  236. FROM t_order
  237. WHERE is_delete = 0
  238. AND c_js_id = #{jsid}
  239. AND end_time BETWEEN #{startDate} AND #{endDate}
  240. AND n_status in (4, 5)
  241. and order_type = 1
  242. </select>
  243. <select id="getUpgradeNum" resultType="java.lang.Integer">
  244. SELECT count(1)
  245. FROM t_order
  246. WHERE is_delete = 0
  247. AND c_js_id = #{jsid}
  248. AND end_time BETWEEN #{startDate} AND #{endDate}
  249. AND n_status in (4, 5)
  250. and order_type = 2
  251. </select>
  252. <select id="getTurnover" resultType="java.math.BigDecimal">
  253. SELECT sum(total_price)
  254. FROM t_order
  255. WHERE is_delete = 0
  256. AND c_js_id = #{jsid}
  257. AND end_time BETWEEN #{startDate} AND #{endDate}
  258. AND n_status in (4, 5)
  259. </select>
  260. <select id="getBlock" resultType="com.ylx.massage.domain.vo.HomeBlock">
  261. SELECT
  262. DATE_FORMAT( end_time, '%Y-%m' ) AS month,
  263. SUM( total_price ) AS turnover,
  264. count(1) orderNum
  265. FROM
  266. t_order
  267. WHERE
  268. is_delete = 0
  269. AND end_time IS NOT NULL
  270. AND end_time BETWEEN #{start} AND #{end}
  271. AND n_status in (4, 5)
  272. <if test="deptId != 100 and deptId != ''">
  273. AND dept_id = #{deptId}
  274. </if>
  275. GROUP BY
  276. month
  277. ORDER BY
  278. month;
  279. </select>
  280. <select id="callAutoAccount" statementType="CALLABLE">
  281. {call updateUserBalance(#{hCount, mode=IN, jdbcType=INTEGER}, #{percent, mode=IN, jdbcType=DECIMAL})}
  282. </select>
  283. <select id="selectValidOrdersByMerchantAndDate" resultType="com.ylx.order.domain.TOrder">
  284. SELECT
  285. appointment_start_time,
  286. appointment_end_time
  287. FROM t_order
  288. WHERE merchant_id = #{merchantId}
  289. AND project_id = #{projectId}
  290. AND is_delete = 0
  291. -- 核心:只查询有效状态的订单 (待派单, 待接单, 待服务, 服务中)
  292. AND status IN (1, 2, 3, 4)
  293. -- 性能优化:限定查询当天的数据,避免全表扫描
  294. AND appointment_start_time >= #{dayStart}
  295. AND appointment_start_time &lt;= #{dayEnd}
  296. </select>
  297. <resultMap id="OrderPageVOResultMap" type="com.ylx.order.domain.vo.merchant.OrderPageVO">
  298. <id column="id" property="id"/>
  299. <result column="project_name" property="projectName"/>
  300. <result column="project_cover" property="projectCover"/>
  301. <result column="project_duration" property="projectDuration"/>
  302. <result column="base_price" property="basePrice"/>
  303. <result column="traffic_fee" property="trafficFee"/>
  304. <result column="final_amount" property="finalAmount"/>
  305. <result column="appointment_start_time" property="appointmentStartTime"/>
  306. <result column="appointment_end_time" property="appointmentEndTime"/>
  307. <result column="contact_person_name" property="contactPersonName"/>
  308. <result column="contact_phone_number" property="contactPhoneNumber"/>
  309. <result column="service_address_detail" property="contactAddressInfo"/>
  310. <result column="user_latitude" property="userLatitude"/>
  311. <result column="user_longitude" property="userLongitude"/>
  312. <result column="status" property="status"/>
  313. <result column="distance_km" property="distanceKm"/>
  314. </resultMap>
  315. <select id="queryMerchantOrderList" resultMap="OrderPageVOResultMap">
  316. SELECT
  317. o.id,
  318. p.project_name,
  319. p.cover_url AS project_cover,
  320. p.duration AS project_duration,
  321. p.base_price,
  322. o.traffic_fee,
  323. o.final_amount,
  324. o.appointment_start_time,
  325. o.appointment_end_time,
  326. o.contact_person_name,
  327. IF(o.contact_phone_number IS NULL, '', CONCAT(SUBSTRING(o.contact_phone_number,1,3), '******', SUBSTRING(o.contact_phone_number,10,2))) AS contactPhoneNumber
  328. o.service_address_detail,
  329. o.user_latitude,
  330. o.user_longitude,
  331. o.status,
  332. CASE
  333. WHEN #{dto.longitude} IS NULL OR #{dto.latitude} IS NULL THEN NULL
  334. WHEN o.user_longitude IS NULL OR o.user_latitude IS NULL THEN NULL
  335. WHEN o.user_longitude = 0 OR o.user_latitude = 0 THEN NULL
  336. ELSE ROUND(ST_Distance_Sphere(POINT(o.user_longitude, o.user_latitude), POINT(#{dto.longitude}, #{dto.latitude})) / 1000, 2)
  337. END AS distance_km
  338. FROM t_order o
  339. LEFT JOIN t_project p ON o.project_id = p.id
  340. <where>
  341. o.is_delete = 0
  342. -- 商户ID
  343. AND o.merchant_id = #{dto.merchantId}
  344. -- 创建时间范围
  345. <if test="dto.startDate != null">
  346. AND o.create_time &gt;= #{dto.startDate}
  347. </if>
  348. <if test="dto.endDate != null">
  349. AND o.create_time &lt;= #{dto.endDate}
  350. </if>
  351. -- 项目名称模糊
  352. <if test="dto.projectName != null and dto.projectName != ''">
  353. AND p.project_name LIKE CONCAT('%', #{dto.projectName}, '%')
  354. </if>
  355. -- 联系人手机号【修复:订单表字段o,不是项目表p】
  356. <if test="dto.contactPhoneNumber != null and dto.contactPhoneNumber != ''">
  357. AND o.contact_phone_number LIKE CONCAT('%', #{dto.contactPhoneNumber}, '%')
  358. </if>
  359. -- 订单状态
  360. <if test="dto.status != null">
  361. AND o.status = #{dto.status}
  362. </if>
  363. -- 是否免交通费
  364. <if test="dto.isTrafficFree != null">
  365. <choose>
  366. <when test="dto.isTrafficFree == 0">
  367. AND o.traffic_fee = 0
  368. </when>
  369. <when test="dto.isTrafficFree == 1">
  370. AND o.traffic_fee &gt; 0
  371. </when>
  372. </choose>
  373. </if>
  374. </where>
  375. ORDER BY o.create_time DESC
  376. </select>
  377. </mapper>