UserOrderMapper.xml 13 KB

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