UserOrderMapper.xml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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.pay_channel_ as payChannel,
  48. p.trans_no_ as transNo,
  49. p.payment_no_ as paymentNo,
  50. p.fee_amt_ as feeAmt,
  51. u.username_ as username,
  52. u.phone_ as phone
  53. FROM user_order t
  54. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  55. left join sys_user u on t.user_id_ = u.id_
  56. where t.id_ = #{id}
  57. </select>
  58. <select id="detailByOrderNo" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  59. SELECT
  60. <include refid="baseColumns"/>,
  61. p.open_type_ as openType,
  62. p.pay_channel_ as payChannel,
  63. p.trans_no_ as transNo,
  64. p.payment_no_ as paymentNo,
  65. p.fee_amt_ as feeAmt,
  66. u.username_ as username,
  67. u.phone_ as phone
  68. FROM user_order t
  69. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  70. left join sys_user u on t.user_id_ = u.id_
  71. where t.order_no_ = #{param.orderNo}
  72. <if test="param.userId != null">
  73. and t.user_id_ = #{param.userId}
  74. </if>
  75. </select>
  76. <select id="detailApp" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  77. SELECT
  78. <include refid="baseColumns"/>,
  79. p.open_type_ as openType,
  80. p.pay_channel_ as payChannel,
  81. p.trans_no_ as transNo,
  82. p.payment_no_ as paymentNo
  83. FROM user_order t
  84. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  85. where t.user_id_ = #{param.userId}
  86. <if test="param.id != null">
  87. and t.id_ = #{param.id}
  88. </if>
  89. <if test="param.orderNo != null and param.orderNo != ''">
  90. and t.order_no_ = #{param.orderNo}
  91. </if>
  92. </select>
  93. <sql id="selectSql">
  94. SELECT
  95. <include refid="baseColumns"/>,
  96. p.open_type_ as openType,
  97. p.pay_channel_ as payChannel,
  98. p.trans_no_ as transNo,
  99. p.payment_no_ as paymentNo,
  100. p.fee_amt_ as feeAmt,
  101. u.username_ as username,
  102. u.phone_ as phone
  103. FROM user_order t
  104. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  105. left join sys_user u on t.user_id_ = u.id_
  106. <where>
  107. <if test="null != param.search and '' != param.search">
  108. AND (
  109. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  110. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  111. u.phone_ LIKE CONCAT('%', #{param.search}, '%')
  112. )
  113. </if>
  114. <if test="null != param.searchNo and '' != param.searchNo">
  115. AND (
  116. t.order_no_ LIKE CONCAT('%', #{param.searchNo}, '%') or
  117. p.trans_no_ LIKE CONCAT('%', #{param.searchNo}, '%')
  118. )
  119. </if>
  120. <if test="null != param.orderType and '' != param.orderType">
  121. AND INTE_ARRAY(#{param.orderType},t.order_type_)
  122. </if>
  123. <if test="null != param.status and '' != param.status">
  124. AND INTE_ARRAY(#{param.status},t.status_)
  125. </if>
  126. <if test="param.startTime !=null">
  127. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  128. </if>
  129. <if test="param.endTime !=null">
  130. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  131. </if>
  132. <if test="param.userId !=null">
  133. AND t.user_id_ = #{param.userId}
  134. </if>
  135. <if test="param.merchId !=null or (param.goodType !=null and param.goodType !='') or param.bizId !=null">
  136. AND exists(
  137. select 1 from user_order_detail d where t.order_no_ = d.order_no_
  138. <if test="param.merchId !=null ">
  139. and d.merch_id_ = #{param.merchId}
  140. </if>
  141. <if test="param.goodType !=null and param.goodType !=''">
  142. and d.good_type_ = #{param.goodType}
  143. </if>
  144. <if test="param.bizId !=null">
  145. and d.biz_id_ = #{param.bizId}
  146. </if>
  147. )
  148. </if>
  149. </where>
  150. order by t.create_time_ desc
  151. </sql>
  152. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  153. <include refid="selectSql"/>
  154. </select>
  155. <select id="selectList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  156. <include refid="selectSql"/>
  157. </select>
  158. <select id="selectPendingList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  159. SELECT t.* FROM user_order t
  160. <where>
  161. <if test="null != param.status and '' != param.status">
  162. AND t.status_ = #{param.status}
  163. </if>
  164. </where>
  165. order by t.create_time_
  166. </select>
  167. <select id="getPendingOrder" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  168. SELECT
  169. <include refid="baseColumns"/>,
  170. p.open_type_ as openType,
  171. p.pay_channel_ as payChannel,
  172. p.trans_no_ as transNo,
  173. p.payment_no_ as paymentNo
  174. FROM user_order t
  175. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  176. where t.status_ in ('WAIT_PAY','PAYING')
  177. and t.user_id_ = #{param.userId}
  178. and exists (
  179. select 1 from user_order_detail d where t.order_no_ = d.order_no_
  180. and d.good_type_ = #{param.goodType}
  181. <choose>
  182. <when test="param.goodType != null and param.goodType == 'PRACTICE'">
  183. and d.merch_id_ = #{param.bizId}
  184. </when>
  185. <otherwise>
  186. and d.biz_id_ = #{param.bizId}
  187. </otherwise>
  188. </choose>
  189. )
  190. order by t.create_time_ desc limit 1
  191. </select>
  192. <select id="selectUnRecordTimeOrder" resultType="com.yonge.cooleshow.biz.dal.entity.UserOrder">
  193. SELECT
  194. <include refid="baseColumns"/>
  195. FROM user_order t
  196. left join student_time st on t.user_id_ = st.user_id_
  197. where t.status_ = 'PAID'
  198. and exists (
  199. select 1 from user_order_detail od where t.order_no_ = od.order_no_
  200. and (
  201. (st.first_vip_time_ is null and od.good_type_ = 'VIP') or
  202. (st.first_practice_time_ is null and od.good_type_ = 'PRACTICE') or
  203. (st.first_video_time_ is null and od.good_type_ = 'VIDEO') or
  204. (st.first_live_time_ is null and od.good_type_ = 'LIVE') or
  205. (st.first_music_time_ is null and od.good_type_ = 'MUSIC')
  206. )
  207. )
  208. <if test="param.startTime !=null">
  209. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  210. </if>
  211. <if test="param.endTime !=null">
  212. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  213. </if>
  214. </select>
  215. <update id="updateStatusByOrderNo">
  216. update user_order set status_ = #{orderStatus},update_time_ = now() where order_no_ = #{orderNo}
  217. </update>
  218. </mapper>