RefundDetailMapper.xml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.refund.RefundDetailMapper">
  4. <update id="recoveryStatusByRefundId">
  5. update trade_detail td,trade_refund_detail rd
  6. set td.voucher_status = rd.voucher_status
  7. where td.id = rd.trade_detail_id and rd.refund_id=#{refundId}
  8. </update>
  9. <update id="updateStatusByRefundId">
  10. update trade_detail td,trade_refund_detail rd
  11. set td.voucher_status = #{refundStatus}
  12. where td.id = rd.trade_detail_id and rd.refund_id=#{refundId}
  13. </update>
  14. <select id="selectRefundOrderProduct" resultType="java.util.Map">
  15. select td.product_id,td.route_plan_id,td.route_plan_group_type,td.product_name,td.use_date,td.quantity_of_one,count(*) refundCount
  16. FROM trade_refund_detail trd
  17. inner join trade_detail td on trd.trade_detail_id = td.id
  18. where trd.refund_id=#{refundId}
  19. group by td.product_id
  20. </select>
  21. <select id="selectRefundOrderProductV2" resultType="java.util.Map">
  22. select td.product_id,td.route_plan_id,td.route_plan_group_type,td.product_name,td.use_date,td.quantity_of_one,
  23. count(if(FIND_IN_SET(td.spec_type,
  24. <foreach collection="noContainSpecList" item="item" separator="," open="" close="">
  25. #{item}
  26. </foreach> )<![CDATA[<= ]]> 0,1,null)) refundCount
  27. FROM trade_refund_detail trd
  28. inner join trade_detail td on trd.trade_detail_id = td.id
  29. where trd.refund_id=#{refundId}
  30. group by td.product_id
  31. </select>
  32. <select id="selectOrderRefundAmount" resultType="java.util.Map">
  33. select sum(refund_amount) totalRefundAmount
  34. FROM trade_refund tr
  35. where tr.order_id=#{orderId} and tr.refund_status=6
  36. group by tr.order_id
  37. </select>
  38. <select id="selectOrderRefundFee" resultType="java.util.Map">
  39. select sum(fee) totalFee
  40. FROM trade_refund tr
  41. where tr.order_id=#{orderId} and tr.refund_status=6
  42. group by tr.order_id
  43. </select>
  44. <select id="selectProductBaseByRefund" resultType="com.yc.ship.module.trade.service.order.bo.TradeOrderDetailBaseBO">
  45. select td.product_id,tdb.product_base_id,tdb.product_resource_id,tdb.product_base_type,tdb.use_date,count(*) quantity
  46. from trade_refund_detail_base rb
  47. INNER JOIN trade_detail_base tdb on rb.trade_detail_base_id = tdb.id
  48. INNER JOIN trade_detail td on td.id = tdb.detail_id
  49. where rb.refund_id = #{refundId}
  50. GROUP BY td.product_id,tdb.product_base_id
  51. </select>
  52. <select id="selectProjectCountByRefund" resultType="com.yc.ship.module.trade.service.order.bo.TradeOrderDetailBaseBO">
  53. SELECT
  54. tdb.project_code,
  55. count( DISTINCT tdb.detail_id ) quantity,
  56. ord.order_no,
  57. ord.order_status,
  58. dt.voucher_code,
  59. dis.dispatch_id,
  60. dt.product_name,
  61. tdb.detail_id,
  62. dt.use_date duseDate
  63. FROM
  64. trade_refund_detail_base rb
  65. INNER JOIN trade_detail_base tdb ON rb.trade_detail_base_id = tdb.id
  66. INNER JOIN trade_detail dt ON dt.id = tdb.detail_id
  67. INNER JOIN trade_order ord ON ord.id = dt.order_id
  68. inner join (select t1.* from trade_order_dispatch t1 inner join dispatch_operate_plan_boat t2 on t1.dispatch_id = t2.id
  69. where order_id=#{orderId} ) dis on dis.order_id = ord.id
  70. WHERE
  71. rb.refund_id = #{refundId}
  72. and tdb.project_code='boat'
  73. GROUP BY
  74. tdb.project_code,
  75. dis.dispatch_id,
  76. ord.order_no
  77. UNION ALL
  78. SELECT
  79. tdb.project_code,
  80. count( DISTINCT tdb.detail_id ) quantity,
  81. ord.order_no,
  82. ord.order_status,
  83. dt.voucher_code,
  84. dis.dispatch_id,
  85. dt.product_name,
  86. tdb.detail_id,
  87. dt.use_date duseDate
  88. FROM
  89. trade_refund_detail_base rb
  90. INNER JOIN trade_detail_base tdb ON rb.trade_detail_base_id = tdb.id
  91. INNER JOIN trade_detail dt ON dt.id = tdb.detail_id
  92. INNER JOIN trade_order ord ON ord.id = dt.order_id
  93. inner join (select t1.* from trade_order_dispatch t1 inner join dispatch_car_dispatch t2 on t1.dispatch_id = t2.id
  94. where order_id=#{orderId} ) dis on (dis.order_id = ord.id and (dis.detail_base_id is null or dis.detail_id is not null and dis.detail_id = dt.id))
  95. WHERE
  96. rb.refund_id = #{refundId}
  97. and tdb.project_code!='boat'
  98. GROUP BY
  99. tdb.project_code,
  100. dis.dispatch_id,
  101. ord.order_no
  102. </select>
  103. <select id="selectOrderApplyRefundAmount" resultType="java.util.Map">
  104. select sum(refund_amount) totalRefundAmount
  105. FROM trade_refund tr
  106. where tr.order_id=#{orderId} and tr.refund_status not in(2,99)
  107. group by tr.order_id
  108. </select>
  109. <select id="selectTradeDetailStatusByRefund" resultType="java.util.Map">
  110. select tdb.detail_id ,count(tdb.detail_id) totalCount,sum(if(tdb.use_status=5,1,0)) refundCount
  111. from trade_refund_detail trd
  112. inner join trade_detail_base tdb on trd.trade_detail_id = tdb.detail_id
  113. where trd.refund_id = #{refundId}
  114. GROUP BY tdb.detail_id
  115. </select>
  116. <select id="selectOrderOriginRefundAmount" resultType="java.util.Map">
  117. select sum(origin_amount) totalOriginRefundAmount
  118. FROM trade_refund tr
  119. where tr.order_id=#{orderId} and tr.refund_status=6
  120. group by tr.order_id
  121. </select>
  122. <select id="selectRefundAmountFromOrderDetail" resultType="java.util.Map">
  123. select sum(tr.actual_price) totalRefundAmount
  124. FROM trade_detail tr
  125. where tr.order_id=#{orderId} and tr.refund_status in (1,2)
  126. </select>
  127. </mapper>