UserOrderMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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.yonge.cooleshow.biz.dal.dao.UserOrderDao">
  4. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.UserOrder">
  5. <result column="id_" property="id"/>
  6. <result column="order_no_" property="orderNo"/>
  7. <result column="user_id_" property="userId"/>
  8. <result column="order_name_" property="orderName"/>
  9. <result column="order_type_" property="orderType"/>
  10. <result column="order_desc_" property="orderDesc"/>
  11. <result column="status_" property="status"/>
  12. <result column="original_price_" property="originalPrice"/>
  13. <result column="expect_price_" property="expectPrice"/>
  14. <result column="actual_price_" property="actualPrice"/>
  15. <result column="coupon_amount_" property="couponAmount"/>
  16. <result column="plantform_fee_" property="plantformFee"/>
  17. <result column="user_note_" property="userNote"/>
  18. <result column="create_time_" property="createTime"/>
  19. <result column="pay_time_" property="payTime"/>
  20. <result column="reason_" property="reason"/>
  21. <result column="update_time_" property="updateTime"/>
  22. </resultMap>
  23. <!-- 表字段 -->
  24. <sql id="baseColumns">
  25. t.id_ as id
  26. , t.order_no_ as orderNo
  27. , t.user_id_ as userId
  28. , t.order_name_ as orderName
  29. , t.order_type_ as orderType
  30. , t.order_desc_ as orderDesc
  31. , t.status_ as status
  32. , t.original_price_ as originalPrice
  33. , t.expect_price_ as expectPrice
  34. , t.actual_price_ as actualPrice
  35. , t.coupon_amount_ as couponAmount
  36. , t.plantform_fee_ as plantformFee
  37. , t.user_note_ as userNote
  38. , t.create_time_ as createTime
  39. , t.pay_time_ as payTime
  40. , t.reason_ as reason
  41. , t.update_time_ as updateTime
  42. </sql>
  43. <select id="detailById" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  44. SELECT
  45. <include refid="baseColumns"/>,
  46. p.open_type_ as openType,
  47. p.payment_client_ as paymentClient,
  48. p.pay_channel_ as payChannel,
  49. p.trans_no_ as transNo,
  50. p.payment_no_ as paymentNo,
  51. p.fee_amt_ as feeAmt,
  52. u.username_ as username,
  53. u.phone_ as phone
  54. FROM user_order t
  55. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  56. left join sys_user u on t.user_id_ = u.id_
  57. where u.del_flag_ = 0 and t.id_ = #{id}
  58. </select>
  59. <select id="detailByOrderNo" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  60. SELECT
  61. <include refid="baseColumns"/>,
  62. p.open_type_ as openType,
  63. p.payment_client_ as paymentClient,
  64. p.pay_channel_ as payChannel,
  65. p.trans_no_ as transNo,
  66. p.payment_no_ as paymentNo,
  67. p.fee_amt_ as feeAmt,
  68. u.username_ as username,
  69. u.phone_ as phone
  70. FROM user_order t
  71. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  72. left join sys_user u on t.user_id_ = u.id_
  73. where u.del_flag_ = 0 and t.order_no_ = #{param.orderNo}
  74. <if test="param.userId != null">
  75. and t.user_id_ = #{param.userId}
  76. </if>
  77. </select>
  78. <select id="detailApp" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  79. SELECT
  80. <include refid="baseColumns"/>,
  81. p.open_type_ as openType,
  82. p.payment_client_ as paymentClient,
  83. p.pay_channel_ as payChannel,
  84. p.trans_no_ as transNo,
  85. p.payment_no_ as paymentNo
  86. FROM user_order t
  87. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  88. where t.user_id_ = #{param.userId}
  89. <if test="param.id != null">
  90. and t.id_ = #{param.id}
  91. </if>
  92. <if test="param.orderNo != null and param.orderNo != ''">
  93. and t.order_no_ = #{param.orderNo}
  94. </if>
  95. </select>
  96. <sql id="selectSql">
  97. SELECT
  98. <include refid="baseColumns"/>,
  99. p.open_type_ as openType,
  100. p.payment_client_ as paymentClient,
  101. p.pay_channel_ as payChannel,
  102. p.trans_no_ as transNo,
  103. p.payment_no_ as paymentNo,
  104. p.fee_amt_ as feeAmt,
  105. u.username_ as username,
  106. u.phone_ as phone
  107. FROM user_order t
  108. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  109. left join sys_user u on t.user_id_ = u.id_
  110. <where>
  111. u.del_flag_ = 0
  112. <if test="null != param.search and '' != param.search">
  113. AND (
  114. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  115. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  116. u.phone_ LIKE CONCAT('%', #{param.search}, '%')
  117. )
  118. </if>
  119. <if test="null != param.searchNo and '' != param.searchNo">
  120. AND (
  121. t.order_no_ LIKE CONCAT('%', #{param.searchNo}, '%') or
  122. p.trans_no_ LIKE CONCAT('%', #{param.searchNo}, '%')
  123. )
  124. </if>
  125. <if test="null != param.orderType and '' != param.orderType">
  126. AND INTE_ARRAY(#{param.orderType},t.order_type_)
  127. </if>
  128. <if test="null != param.status and '' != param.status">
  129. AND INTE_ARRAY(#{param.status},t.status_)
  130. </if>
  131. <if test="param.startTime !=null">
  132. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  133. </if>
  134. <if test="param.endTime !=null">
  135. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  136. </if>
  137. <if test="param.userId !=null">
  138. AND t.user_id_ = #{param.userId}
  139. </if>
  140. <if test="param.merchId !=null or (param.goodType !=null and param.goodType !='') or param.bizId !=null">
  141. AND exists(
  142. select 1 from user_order_detail d where t.order_no_ = d.order_no_
  143. <if test="param.merchId !=null ">
  144. and d.merch_id_ = #{param.merchId}
  145. </if>
  146. <if test="param.goodType !=null and param.goodType !=''">
  147. and d.good_type_ = #{param.goodType}
  148. </if>
  149. <if test="param.bizId !=null">
  150. and d.biz_id_ = #{param.bizId}
  151. </if>
  152. )
  153. </if>
  154. </where>
  155. order by field(t.status_,'WAIT_PAY','PAYING') desc, t.create_time_ desc
  156. </sql>
  157. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  158. <include refid="selectSql"/>
  159. </select>
  160. <select id="selectAllList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  161. <include refid="selectSql"/>
  162. </select>
  163. <select id="selectPendingList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  164. SELECT
  165. <include refid="baseColumns"/>
  166. FROM user_order t
  167. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  168. <where>
  169. <if test="null != param.status and '' != param.status">
  170. AND t.status_ = #{param.status}
  171. </if>
  172. <if test="param.startTime != null">
  173. AND (
  174. (p.id_ is null and t.create_time_ &gt;= #{param.startTime}) or (p.id_ is not null and p.create_time_ &gt;= #{param.startTime})
  175. )
  176. </if>
  177. <if test="param.endTime != null">
  178. AND (
  179. (p.id_ is null and t.create_time_ &lt; #{param.endTime}) or (p.id_ is not null and p.create_time_ &lt; #{param.endTime})
  180. )
  181. </if>
  182. </where>
  183. order by t.create_time_
  184. </select>
  185. <select id="getPendingOrder" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  186. SELECT
  187. <include refid="baseColumns"/>,
  188. p.open_type_ as openType,
  189. p.payment_client_ as paymentClient,
  190. p.pay_channel_ as payChannel,
  191. p.trans_no_ as transNo,
  192. p.payment_no_ as paymentNo
  193. FROM user_order t
  194. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  195. where t.status_ in ('WAIT_PAY','PAYING')
  196. and t.user_id_ = #{param.userId}
  197. and exists (
  198. select 1 from user_order_detail d where t.order_no_ = d.order_no_
  199. and d.good_type_ = #{param.goodType}
  200. <choose>
  201. <when test="param.goodType != null and param.goodType != 'PRACTICE'">
  202. and d.biz_id_ = #{param.bizId}
  203. </when>
  204. </choose>
  205. )
  206. order by t.create_time_ desc limit 1
  207. </select>
  208. <select id="selectUnRecordTimeOrder" resultType="com.yonge.cooleshow.biz.dal.entity.UserOrder">
  209. SELECT
  210. <include refid="baseColumns"/>
  211. FROM user_order t
  212. left join student_time st on t.user_id_ = st.user_id_
  213. where t.status_ = 'PAID'
  214. and exists (
  215. select 1 from user_order_detail od where t.order_no_ = od.order_no_
  216. and (
  217. (st.first_vip_time_ is null and od.good_type_ = 'VIP') or
  218. (st.first_practice_time_ is null and od.good_type_ = 'PRACTICE') or
  219. (st.first_video_time_ is null and od.good_type_ = 'VIDEO') or
  220. (st.first_live_time_ is null and od.good_type_ = 'LIVE') or
  221. (st.first_music_time_ is null and od.good_type_ = 'MUSIC')
  222. )
  223. )
  224. <if test="param.startTime !=null">
  225. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  226. </if>
  227. <if test="param.endTime !=null">
  228. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  229. </if>
  230. </select>
  231. <select id="getUserOrderByPaymentNoOrTransNo" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  232. SELECT
  233. <include refid="baseColumns"/>,
  234. p.open_type_ as openType,
  235. p.payment_client_ as paymentClient,
  236. p.pay_channel_ as payChannel,
  237. p.trans_no_ as transNo,
  238. p.payment_no_ as paymentNo
  239. FROM user_order t
  240. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  241. <where>
  242. <choose>
  243. <when test="paymentNo != null and paymentNo != ''">
  244. and (
  245. exists (select 1 from user_order_payment p1 where t.order_no_ = p1.order_no_ and p1.payment_no_ = #{paymentNo}) or
  246. exists (
  247. select 1 from user_order_refund b1
  248. left join user_order_refund_bill b2 on b1.id_ = b2.refund_id_
  249. where t.order_no_ = b1.order_no_ and b2.bill_no_ = #{paymentNo}
  250. )
  251. )
  252. </when>
  253. <otherwise>
  254. and (
  255. exists (select 1 from user_order_payment p1 where p1.trans_no_ = #{transNo}) or
  256. exists (
  257. select 1 from user_order_refund b1
  258. left join user_order_refund_bill b2 on b1.id_ = b2.refund_id_
  259. where t.order_no_ = b1.order_no_ and b2.trans_no_ = #{transNo}
  260. )
  261. )
  262. </otherwise>
  263. </choose>
  264. </where>
  265. </select>
  266. <update id="updateStatusByOrderNo">
  267. update user_order set status_ = #{orderStatus},update_time_ = now() where order_no_ = #{orderNo}
  268. </update>
  269. </mapper>