UserOrderMapper.xml 13 KB

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