OrderHandleMapper.xml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.zhongzheng.modules.order.mapper.OrderHandleMapper">
  6. <resultMap type="com.zhongzheng.modules.order.domain.OrderHandle" id="OrderHandleResult">
  7. <result property="id" column="id"/>
  8. <result property="handleOrderSn" column="handle_order_sn"/>
  9. <result property="createUsername" column="create_username"/>
  10. <result property="status" column="status"/>
  11. <result property="createUserId" column="create_user_id"/>
  12. <result property="createTime" column="create_time"/>
  13. <result property="updateTime" column="update_time"/>
  14. <result property="educationTypeId" column="education_type_id"/>
  15. <result property="businessId" column="business_id"/>
  16. <result property="projectId" column="project_id"/>
  17. <result property="inputFrom" column="input_from"/>
  18. <result property="payStatus" column="pay_status"/>
  19. <result property="goodsType" column="goods_type"/>
  20. </resultMap>
  21. <resultMap type="com.zhongzheng.modules.order.vo.OrderHandleGoodsVo" id="OrderHandleGoodsVoResult">
  22. <result property="realname" column="realname"/>
  23. <result property="telPhone" column="telphone" typeHandler="com.zhongzheng.common.type.EncryptHandler"/>
  24. <result property="idCard" column="id_card" typeHandler="com.zhongzheng.common.type.EncryptHandler"/>
  25. <result property="goodsName" column="goods_name"/>
  26. <result property="year" column="year"/>
  27. <result property="goodsRealPrice" column="goods_real_price"/>
  28. <result property="orderGoodsId" column="order_goods_id"/>
  29. <result property="userId" column="user_id"/>
  30. <result property="gradeId" column="grade_id"/>
  31. <result property="goodsId" column="goods_id"/>
  32. <result property="subjectNames" column="subject_names"/>
  33. </resultMap>
  34. <select id="selectOrderList" parameterType="com.zhongzheng.modules.order.bo.OrderHandleQueryBo" resultType="com.zhongzheng.modules.order.vo.OrderHandleVo">
  35. SELECT u.*,
  36. (select count( DISTINCT o.user_id ) from `order` o where u.handle_order_sn = o.handle_order_sn) user_num,
  37. (select count( DISTINCT og.goods_id ) from `order` o LEFT JOIN order_goods og ON o.order_sn = og.order_sn where u.handle_order_sn = o.handle_order_sn) goods_num,
  38. cet.education_name education_name,
  39. cpt.project_name project_name,
  40. cb.business_name business_name,
  41. (select IFNULL(sum(og.goods_real_price),0) from order_goods og LEFT JOIN `order` o on o.order_sn = og.order_sn where o.handle_order_sn = u.handle_order_sn and og.refund_status = 2) goods_refund
  42. FROM (SELECT
  43. oh.*,s.id_card,s.telphone,s.realname AS createUsername
  44. FROM
  45. order_handle oh left join user s on oh.create_user_id=s.user_id
  46. where 1=1
  47. <if test="idCard != null and idCard != ''">
  48. AND s.id_card = #{idCard,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  49. </if>
  50. <if test="telphone != null and telphone != ''">
  51. AND s.telphone = #{telphone,typeHandler=com.zhongzheng.common.type.EncryptHandler}
  52. </if>
  53. <if test="createUsername != null and createUsername != ''">
  54. AND s.realname = #{createUsername}
  55. </if>
  56. <if test="businessId != null and businessId != ''">
  57. AND oh.business_id = #{businessId}
  58. </if>
  59. <if test="educationTypeId != null and educationTypeId != ''">
  60. AND oh.education_type_id = #{educationTypeId}
  61. </if>
  62. <if test="searchKey != null and searchKey != ''">
  63. AND (select count(*) from `order` o left JOIN `user` u on o.user_id = u.user_id
  64. left JOIN order_goods og on o.order_sn = og.order_sn
  65. LEFT JOIN goods g on og.goods_id = g.goods_id
  66. where o.handle_order_sn = oh.handle_order_sn and (u.realname like concat('%', #{searchKey}, '%') or (u.id_card = #{searchKey,typeHandler=com.zhongzheng.common.type.EncryptHandler}) or (g.goods_name like concat('%', #{searchKey}, '%'))))>0
  67. </if>
  68. <if test="goodsType != null">
  69. AND oh.goods_type = #{goodsType}
  70. </if>
  71. <if test="createUserId != null">
  72. AND oh.create_user_id = #{createUserId}
  73. </if>
  74. <if test="handleOrderSn != null and handleOrderSn != ''">
  75. AND oh.handle_order_sn = #{handleOrderSn}
  76. </if>
  77. <if test="refundStatus != null">
  78. AND oh.refund_status = #{refundStatus}
  79. </if>
  80. <if test="startTime != null and startTime != ''">
  81. AND oh.pay_time &gt;= #{startTime}
  82. </if>
  83. <if test="endTime != null and endTime != ''">
  84. AND oh.pay_time &lt;= #{endTime}
  85. </if>
  86. <if test="payStatus != null">
  87. AND oh.pay_status = #{payStatus}
  88. </if>)u
  89. LEFT JOIN course_education_type cet ON u.education_type_id = cet.id
  90. LEFT JOIN course_project_type cpt ON u.project_id = cpt.id
  91. LEFT JOIN course_business cb ON u.business_id = cb.id
  92. where 1=1
  93. <if test="invoiceStatus != null and invoiceStatus == 1">
  94. AND (SELECT
  95. oi.period_status
  96. FROM
  97. order_invoice_order oio
  98. LEFT JOIN order_invoice oi ON oio.invoice_id = oi.invoice_id
  99. WHERE
  100. oio.order_sn = u.handle_order_sn
  101. AND (oi.wash_status is null or oi.wash_status = 1)
  102. order by oi.create_time DESC limit 1
  103. ) = 1
  104. </if>
  105. <if test="invoiceStatus != null and invoiceStatus == 2">
  106. AND (SELECT
  107. oi.invoice_status
  108. FROM
  109. order_invoice_order oio
  110. LEFT JOIN order_invoice oi ON oio.invoice_id = oi.invoice_id
  111. WHERE
  112. oio.order_sn = u.handle_order_sn
  113. AND (oi.wash_status is null or oi.wash_status = 1)
  114. order by oi.create_time DESC limit 1
  115. ) = 2
  116. </if>
  117. <if test="invoiceStatus != null and invoiceStatus == 3">
  118. AND (SELECT
  119. oi.period_status
  120. FROM
  121. order_invoice_order oio
  122. LEFT JOIN order_invoice oi ON oio.invoice_id = oi.invoice_id
  123. WHERE
  124. oio.order_sn = u.handle_order_sn
  125. AND (oi.wash_status is null or oi.wash_status = 1)
  126. order by oi.create_time DESC limit 1
  127. ) = 2
  128. </if>
  129. <if test="invoiceStatus != null and invoiceStatus == 4">
  130. AND (SELECT
  131. oi.invoice_status
  132. FROM
  133. order_invoice_order oio
  134. LEFT JOIN order_invoice oi ON oio.invoice_id = oi.invoice_id
  135. WHERE
  136. oio.order_sn = u.handle_order_sn
  137. AND (oi.wash_status is null or oi.wash_status = 1)
  138. order by oi.create_time DESC limit 1
  139. ) = 4
  140. </if>
  141. <if test="invoiceStatus != null and invoiceStatus == 5">
  142. AND (SELECT
  143. count(oi.invoice_id)
  144. FROM
  145. order_invoice_order oio
  146. LEFT JOIN order_invoice oi ON oio.invoice_id = oi.invoice_id
  147. WHERE
  148. oio.order_sn = u.handle_order_sn
  149. AND (oi.wash_status is null or oi.wash_status = 1)
  150. ) = 0
  151. </if>
  152. ORDER BY u.create_time DESC
  153. </select>
  154. <select id="selectOrderGoodsList" parameterType="com.zhongzheng.modules.order.bo.OrderHandleQueryBo" resultMap="OrderHandleGoodsVoResult">
  155. SELECT
  156. u.realname,
  157. u.id_card,
  158. u.telphone,
  159. g.goods_name,
  160. g.`year`,
  161. (SELECT GROUP_CONCAT(subject_name) from course_subject where FIND_IN_SET(id,g.subject_ids)) subject_names,
  162. og.goods_real_price,
  163. og.order_goods_id,
  164. o.user_id,
  165. og.grade_id,
  166. <if test="handleOrderSn != null">
  167. oh.pay_status,
  168. </if>
  169. og.goods_id
  170. FROM
  171. `order` o
  172. <if test="handleOrderSn != null">
  173. LEFT JOIN order_handle oh ON o.handle_order_sn = oh.handle_order_sn
  174. </if>
  175. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  176. LEFT JOIN `user` u ON o.user_id = u.user_id
  177. LEFT JOIN goods g ON og.goods_id = g.goods_id
  178. WHERE
  179. 1=1
  180. <if test="handleOrderSn != null">
  181. AND o.handle_order_sn = #{handleOrderSn}
  182. </if>
  183. <if test="inputOrderSn != null">
  184. AND o.input_order_sn = #{inputOrderSn}
  185. </if>
  186. <if test="refundStatus != null">
  187. AND og.refund_status = #{refundStatus}
  188. </if>
  189. </select>
  190. <select id="selectOverTimeOrderList" parameterType="com.zhongzheng.modules.order.bo.OrderHandleQueryBo" resultType="com.zhongzheng.modules.order.vo.OrderHandleOverVo">
  191. SELECT oh.*
  192. FROM
  193. order_handle oh
  194. where 1=1 and oh.pay_status = 0 and #{overTime} > oh.over_time
  195. </select>
  196. <select id="getorderTotalPrice" parameterType="java.lang.String" resultType="java.math.BigDecimal">
  197. SELECT
  198. SUM(o.pay_price)
  199. FROM
  200. `order` o
  201. LEFT JOIN order_goods og ON o.order_sn = og.order_sn
  202. WHERE
  203. o.handle_order_sn = #{handleOrderSn}
  204. AND og.pay_status != 1
  205. AND og.refund_status != 2
  206. AND o.`status` = 1
  207. AND og.`status` = 1
  208. </select>
  209. </mapper>