UserOrderMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 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 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. <if test="null != param.search and '' != param.search">
  112. AND (
  113. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  114. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  115. u.phone_ LIKE CONCAT('%', #{param.search}, '%')
  116. )
  117. </if>
  118. <if test="null != param.searchNo and '' != param.searchNo">
  119. AND (
  120. t.order_no_ LIKE CONCAT('%', #{param.searchNo}, '%') or
  121. p.trans_no_ LIKE CONCAT('%', #{param.searchNo}, '%')
  122. )
  123. </if>
  124. <if test="null != param.orderType and '' != param.orderType">
  125. AND INTE_ARRAY(#{param.orderType},t.order_type_)
  126. </if>
  127. <if test="null != param.status and '' != param.status">
  128. AND INTE_ARRAY(#{param.status},t.status_)
  129. </if>
  130. <if test="param.startTime !=null">
  131. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  132. </if>
  133. <if test="param.endTime !=null">
  134. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  135. </if>
  136. <if test="param.userId !=null">
  137. AND t.user_id_ = #{param.userId}
  138. </if>
  139. <if test="param.merchId !=null or (param.goodType !=null and param.goodType !='') or param.bizId !=null">
  140. AND exists(
  141. select 1 from user_order_detail d where t.order_no_ = d.order_no_
  142. <if test="param.merchId !=null ">
  143. and d.merch_id_ = #{param.merchId}
  144. </if>
  145. <if test="param.goodType !=null and param.goodType !=''">
  146. and d.good_type_ = #{param.goodType}
  147. </if>
  148. <if test="param.bizId !=null">
  149. and d.biz_id_ = #{param.bizId}
  150. </if>
  151. )
  152. </if>
  153. </where>
  154. order by field(t.status_,'WAIT_PAY','PAYING') desc, t.create_time_ desc
  155. </sql>
  156. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  157. <include refid="selectSql"/>
  158. </select>
  159. <select id="selectList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  160. <include refid="selectSql"/>
  161. </select>
  162. <select id="selectPendingList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  163. SELECT
  164. <include refid="baseColumns"/>
  165. FROM user_order t
  166. <where>
  167. <if test="null != param.status and '' != param.status">
  168. AND t.status_ = #{param.status}
  169. </if>
  170. </where>
  171. order by t.create_time_
  172. </select>
  173. <select id="getPendingOrder" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  174. SELECT
  175. <include refid="baseColumns"/>,
  176. p.open_type_ as openType,
  177. p.payment_client_ as paymentClient,
  178. p.pay_channel_ as payChannel,
  179. p.trans_no_ as transNo,
  180. p.payment_no_ as paymentNo
  181. FROM user_order t
  182. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  183. where t.status_ in ('WAIT_PAY','PAYING')
  184. and t.user_id_ = #{param.userId}
  185. and exists (
  186. select 1 from user_order_detail d where t.order_no_ = d.order_no_
  187. and d.good_type_ = #{param.goodType}
  188. <choose>
  189. <when test="param.goodType != null and param.goodType != 'PRACTICE'">
  190. and d.biz_id_ = #{param.bizId}
  191. </when>
  192. </choose>
  193. )
  194. order by t.create_time_ desc limit 1
  195. </select>
  196. <select id="selectUnRecordTimeOrder" resultType="com.yonge.cooleshow.biz.dal.entity.UserOrder">
  197. SELECT
  198. <include refid="baseColumns"/>
  199. FROM user_order t
  200. left join student_time st on t.user_id_ = st.user_id_
  201. where t.status_ = 'PAID'
  202. and exists (
  203. select 1 from user_order_detail od where t.order_no_ = od.order_no_
  204. and (
  205. (st.first_vip_time_ is null and od.good_type_ = 'VIP') or
  206. (st.first_practice_time_ is null and od.good_type_ = 'PRACTICE') or
  207. (st.first_video_time_ is null and od.good_type_ = 'VIDEO') or
  208. (st.first_live_time_ is null and od.good_type_ = 'LIVE') or
  209. (st.first_music_time_ is null and od.good_type_ = 'MUSIC')
  210. )
  211. )
  212. <if test="param.startTime !=null">
  213. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  214. </if>
  215. <if test="param.endTime !=null">
  216. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  217. </if>
  218. </select>
  219. <select id="getUserOrderByPaymentNoOrTransNo" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  220. SELECT
  221. <include refid="baseColumns"/>
  222. FROM user_order t
  223. left join user_order_payment p on t.order_no_ = p.order_no_
  224. <where>
  225. <choose>
  226. <when test="paymentNo != null and paymentNo != ''">
  227. and p.payment_no_ = #{paymentNo}
  228. </when>
  229. <otherwise>
  230. and p.trans_no_ = #{transNo}
  231. </otherwise>
  232. </choose>
  233. </where>
  234. </select>
  235. <update id="updateStatusByOrderNo">
  236. update user_order set status_ = #{orderStatus},update_time_ = now() where order_no_ = #{orderNo}
  237. </update>
  238. </mapper>