UserOrderMapper.xml 13 KB

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