IncomeOrderLedgerMapper.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.yc.ship.module.trade.dal.mysql.report.IncomeOrderLedgerMapper">
  4. <!-- 分页查询订单收入台账 -->
  5. <select id="selectIncomeOrderLedgerPage"
  6. resultType="com.yc.ship.module.trade.controller.admin.report.vo.IncomeOrderLedgerRespVO">
  7. SELECT
  8. o.id,
  9. o.order_no AS orderNo,
  10. o.order_status AS orderStatus,
  11. o.pay_status AS paymentStatus,
  12. DATE_FORMAT(v.start_time, '%Y/%m/%d') AS sailTime,
  13. o.source_name AS travelAgency,
  14. v.name AS voyage,
  15. r.name AS routeName,
  16. rm.room_model_name AS roomTypeName,
  17. IFNULL(tot.use_room_total_num, 0) AS roomCount,
  18. IFNULL(tot.adult_total_num, 0) AS adultCount,
  19. IFNULL(tot.child_total_num, 0) AS childCount,
  20. IFNULL(tot.baby_total_num, 0) AS infantCount,
  21. IFNULL(tot.with_total_num, 0) AS companionCount,
  22. IFNULL(tot.free_num, 0) AS freeCount,
  23. (IFNULL(tot.adult_total_num, 0) + IFNULL(tot.child_total_num, 0) +
  24. IFNULL(tot.baby_total_num, 0) + IFNULL(tot.with_total_num, 0) + IFNULL(tot.free_num, 0)) AS totalCount,
  25. o.amount AS marketingPrice,
  26. o.free_amount AS discountAmount,
  27. COALESCE(refund_fee_sum.refundFee, 0) AS refundFee,
  28. (o.amount - IFNULL(o.free_amount, 0) - COALESCE(refund_fee_sum.refundFee, 0)) AS actualSettlementPrice
  29. FROM trade_order o
  30. INNER JOIN product_voyage v ON o.voyage_id = v.id AND v.deleted = 0
  31. INNER JOIN resource_route r ON v.route_id = r.id AND r.deleted = 0
  32. LEFT JOIN trade_order_total tot ON o.id = tot.old_order_id AND tot.deleted = 0
  33. LEFT JOIN (
  34. SELECT rm.order_id,
  35. GROUP_CONCAT(DISTINCT rm.room_model_name SEPARATOR ',') AS room_model_name
  36. FROM trade_order_room_model rm
  37. WHERE rm.deleted = 0
  38. GROUP BY rm.order_id
  39. ) rm ON o.id = rm.order_id
  40. LEFT JOIN (
  41. SELECT order_id, SUM(fee) AS refundFee
  42. FROM trade_refund
  43. WHERE deleted = 0 AND refund_status IN (3)
  44. GROUP BY order_id
  45. ) refund_fee_sum ON o.id = refund_fee_sum.order_id
  46. WHERE o.deleted = 0
  47. <if test="vo.orderNo != null and vo.orderNo != ''">
  48. AND o.order_no LIKE CONCAT('%', #{vo.orderNo}, '%')
  49. </if>
  50. <if test="vo.orderStatus != null">
  51. AND o.order_status = #{vo.orderStatus}
  52. </if>
  53. <if test="vo.paymentStatus != null">
  54. AND o.pay_status = #{vo.paymentStatus}
  55. </if>
  56. <if test="vo.sailTime != null">
  57. AND DATE(v.start_time) = #{vo.sailTime}
  58. </if>
  59. <if test="vo.travelAgency != null and vo.travelAgency != ''">
  60. AND o.source_name LIKE CONCAT('%', #{vo.travelAgency}, '%')
  61. </if>
  62. <if test="vo.shipId != null">
  63. AND v.ship_id = #{vo.shipId}
  64. </if>
  65. <if test="vo.routeName != null and vo.routeName != ''">
  66. AND r.name LIKE CONCAT('%', #{vo.routeName}, '%')
  67. </if>
  68. <if test="vo.roomTypeName != null and vo.roomTypeName != ''">
  69. AND EXISTS (
  70. SELECT 1 FROM trade_order_room_model orm2
  71. WHERE orm2.order_id = o.id AND orm2.deleted = 0
  72. AND orm2.room_model_name LIKE CONCAT('%', #{vo.roomTypeName}, '%')
  73. )
  74. </if>
  75. ORDER BY o.create_time DESC
  76. </select>
  77. <!-- 导出查询(与分页查询条件一致,不分页) -->
  78. <select id="selectIncomeOrderLedgerExportList"
  79. resultType="com.yc.ship.module.trade.controller.admin.report.vo.IncomeOrderLedgerRespVO">
  80. SELECT
  81. o.id,
  82. o.order_no AS orderNo,
  83. o.order_status AS orderStatus,
  84. o.pay_status AS paymentStatus,
  85. DATE_FORMAT(v.start_time, '%Y/%m/%d') AS sailTime,
  86. o.source_name AS travelAgency,
  87. v.name AS voyage,
  88. r.name AS routeName,
  89. rm.room_model_name AS roomTypeName,
  90. IFNULL(tot.use_room_total_num, 0) AS roomCount,
  91. IFNULL(tot.adult_total_num, 0) AS adultCount,
  92. IFNULL(tot.child_total_num, 0) AS childCount,
  93. IFNULL(tot.baby_total_num, 0) AS infantCount,
  94. IFNULL(tot.with_total_num, 0) AS companionCount,
  95. IFNULL(tot.free_num, 0) AS freeCount,
  96. (IFNULL(tot.adult_total_num, 0) + IFNULL(tot.child_total_num, 0) +
  97. IFNULL(tot.baby_total_num, 0) + IFNULL(tot.with_total_num, 0) + IFNULL(tot.free_num, 0)) AS totalCount,
  98. o.amount AS marketingPrice,
  99. o.free_amount AS discountAmount,
  100. COALESCE(refund_fee_sum.refundFee, 0) AS refundFee,
  101. (o.amount - IFNULL(o.free_amount, 0) - COALESCE(refund_fee_sum.refundFee, 0)) AS actualSettlementPrice
  102. FROM trade_order o
  103. INNER JOIN product_voyage v ON o.voyage_id = v.id AND v.deleted = 0
  104. INNER JOIN resource_route r ON v.route_id = r.id AND r.deleted = 0
  105. LEFT JOIN trade_order_total tot ON o.id = tot.old_order_id AND tot.deleted = 0
  106. LEFT JOIN (
  107. SELECT rm.order_id,
  108. GROUP_CONCAT(DISTINCT rm.room_model_name SEPARATOR ',') AS room_model_name
  109. FROM trade_order_room_model rm
  110. WHERE rm.deleted = 0
  111. GROUP BY rm.order_id
  112. ) rm ON o.id = rm.order_id
  113. LEFT JOIN (
  114. SELECT order_id, SUM(fee) AS refundFee
  115. FROM trade_refund
  116. WHERE deleted = 0 AND refund_status IN (3)
  117. GROUP BY order_id
  118. ) refund_fee_sum ON o.id = refund_fee_sum.order_id
  119. WHERE o.deleted = 0
  120. <if test="vo.orderNo != null and vo.orderNo != ''">
  121. AND o.order_no LIKE CONCAT('%', #{vo.orderNo}, '%')
  122. </if>
  123. <if test="vo.orderStatus != null">
  124. AND o.order_status = #{vo.orderStatus}
  125. </if>
  126. <if test="vo.paymentStatus != null">
  127. AND o.pay_status = #{vo.paymentStatus}
  128. </if>
  129. <if test="vo.sailTime != null">
  130. AND DATE(v.start_time) = #{vo.sailTime}
  131. </if>
  132. <if test="vo.travelAgency != null and vo.travelAgency != ''">
  133. AND o.source_name LIKE CONCAT('%', #{vo.travelAgency}, '%')
  134. </if>
  135. <if test="vo.shipId != null">
  136. AND v.ship_id = #{vo.shipId}
  137. </if>
  138. <if test="vo.routeName != null and vo.routeName != ''">
  139. AND r.name LIKE CONCAT('%', #{vo.routeName}, '%')
  140. </if>
  141. <if test="vo.roomTypeName != null and vo.roomTypeName != ''">
  142. AND EXISTS (
  143. SELECT 1 FROM trade_order_room_model orm2
  144. WHERE orm2.order_id = o.id AND orm2.deleted = 0
  145. AND orm2.room_model_name LIKE CONCAT('%', #{vo.roomTypeName}, '%')
  146. )
  147. </if>
  148. ORDER BY o.create_time DESC
  149. </select>
  150. </mapper>