UserOrderMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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.payment_version_ as paymentVersion
  32. ,t.payment_vendor_ as paymentVendor
  33. , t.user_id_ as userId
  34. , t.tenant_id_ as tenantId
  35. , t.recom_user_id_ as recomUserId
  36. , t.activity_id_ as activityId
  37. , t.reward_id_ as rewardId
  38. , t.order_name_ as orderName
  39. , t.order_client_ as orderClient
  40. , t.order_type_ as orderType
  41. , t.order_desc_ as orderDesc
  42. , t.status_ as status
  43. , t.original_price_ as originalPrice
  44. , t.expect_price_ as expectPrice
  45. , t.actual_price_ as actualPrice
  46. , t.coupon_amount_ as couponAmount
  47. , t.plantform_fee_ as plantformFee
  48. , t.user_note_ as userNote
  49. , t.create_time_ as createTime
  50. , t.pay_time_ as payTime
  51. , t.reason_ as reason
  52. , t.update_time_ as updateTime
  53. </sql>
  54. <select id="detailById" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  55. SELECT
  56. <include refid="baseColumns"/>,
  57. p.open_type_ as openType,
  58. p.payment_client_ as paymentClient,
  59. p.pay_channel_ as payChannel,
  60. p.trans_no_ as transNo,
  61. p.payment_no_ as paymentNo,
  62. p.fee_amt_ as feeAmt,
  63. u.username_ as username,
  64. u.phone_ as phone
  65. FROM user_order t
  66. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  67. left join sys_user u on t.user_id_ = u.id_
  68. where u.del_flag_ = 0 and t.id_ = #{id}
  69. </select>
  70. <select id="detailByOrderNo" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  71. SELECT
  72. <include refid="baseColumns"/>,
  73. p.open_type_ as openType,
  74. p.payment_client_ as paymentClient,
  75. p.pay_channel_ as payChannel,
  76. p.trans_no_ as transNo,
  77. p.payment_no_ as paymentNo,
  78. p.fee_amt_ as feeAmt,
  79. u.username_ as username,
  80. u.phone_ as phone
  81. FROM user_order t
  82. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  83. left join sys_user u on t.user_id_ = u.id_
  84. where u.del_flag_ = 0 and t.order_no_ = #{param.orderNo}
  85. <if test="param.userId != null">
  86. and t.user_id_ = #{param.userId}
  87. </if>
  88. </select>
  89. <select id="detailApp" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  90. SELECT
  91. <include refid="baseColumns"/>,
  92. p.open_type_ as openType,
  93. p.payment_client_ as paymentClient,
  94. p.pay_channel_ as payChannel,
  95. p.trans_no_ as transNo,
  96. p.payment_no_ as paymentNo
  97. FROM user_order t
  98. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  99. <where>
  100. <if test="param.userId != null">
  101. and t.user_id_ = #{param.userId}
  102. </if>
  103. <if test="param.id != null">
  104. and t.id_ = #{param.id}
  105. </if>
  106. <if test="param.orderNo != null and param.orderNo != ''">
  107. and t.order_no_ = #{param.orderNo}
  108. </if>
  109. </where>
  110. </select>
  111. <sql id="selectSql">
  112. SELECT
  113. <include refid="baseColumns"/>,
  114. p.open_type_ as openType,
  115. p.payment_client_ as paymentClient,
  116. p.pay_channel_ as payChannel,
  117. p.trans_no_ as transNo,
  118. p.payment_no_ as paymentNo,
  119. p.fee_amt_ as feeAmt,
  120. u.username_ as username,
  121. u.phone_ as phone
  122. FROM user_order t
  123. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  124. left join sys_user u on t.user_id_ = u.id_
  125. <if test="null != param.search and '' != param.search">
  126. left join tenant_info ti on t.tenant_id_ = ti.id_
  127. </if>
  128. <where>
  129. u.del_flag_ = 0
  130. <if test="null != param.orderClient and '' != param.orderClient">
  131. AND t.order_client_ = #{param.orderClient}
  132. </if>
  133. <if test="param.tenantId != null">
  134. and t.tenant_id_ = #{param.tenantId}
  135. </if>
  136. <if test="param.keyword != null and param.keyword != ''">
  137. and t.order_name_ like CONCAT('%', #{param.keyword}, '%')
  138. </if>
  139. <if test="param.paymentVersion != null">
  140. and t.payment_version_ = #{param.paymentVersion}
  141. </if>
  142. <if test="null != param.search and '' != param.search">
  143. AND (
  144. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  145. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  146. u.phone_ LIKE CONCAT('%', #{param.search}, '%') or
  147. ti.name_ LIKE CONCAT('%', #{param.search}, '%')
  148. )
  149. </if>
  150. <if test="null != param.searchNo and '' != param.searchNo">
  151. AND (
  152. t.order_no_ LIKE CONCAT('%', #{param.searchNo}, '%') or
  153. p.trans_no_ LIKE CONCAT('%', #{param.searchNo}, '%')
  154. )
  155. </if>
  156. <if test="null != param.orderType and '' != param.orderType">
  157. AND FIND_IN_SET(t.order_type_,#{param.orderType})
  158. </if>
  159. <if test="null != param.status and '' != param.status">
  160. AND FIND_IN_SET(t.status_,#{param.status})
  161. </if>
  162. <if test="param.startTime !=null">
  163. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  164. </if>
  165. <if test="param.endTime !=null">
  166. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  167. </if>
  168. <if test="param.userId !=null">
  169. AND t.user_id_ = #{param.userId}
  170. </if>
  171. <if test="param.merchId !=null or (param.goodType !=null and param.goodType !='') or param.bizId !=null">
  172. AND exists(
  173. select 1 from user_order_detail d where t.order_no_ = d.order_no_
  174. <if test="param.merchId !=null ">
  175. and d.merch_id_ = #{param.merchId}
  176. </if>
  177. <if test="param.goodType !=null and param.goodType !=''">
  178. and d.good_type_ = #{param.goodType}
  179. </if>
  180. <if test="param.bizId !=null">
  181. and d.biz_id_ = #{param.bizId}
  182. </if>
  183. )
  184. </if>
  185. </where>
  186. order by field(t.status_,'WAIT_PAY','PAYING') desc, t.create_time_ desc
  187. </sql>
  188. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  189. <include refid="selectSql"/>
  190. </select>
  191. <select id="selectAllList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  192. <include refid="selectSql"/>
  193. </select>
  194. <select id="selectPendingList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  195. SELECT
  196. <include refid="baseColumns"/>
  197. FROM user_order t
  198. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  199. <where>
  200. <if test="null != param.status and '' != param.status">
  201. AND t.status_ = #{param.status}
  202. </if>
  203. <if test="param.paymentVersion != null">
  204. and t.payment_version_ = #{param.paymentVersion}
  205. </if>
  206. <if test="param.startTime != null">
  207. AND (
  208. (p.id_ is null and t.create_time_ &gt;= #{param.startTime}) or (p.id_ is not null and p.create_time_ &gt;= #{param.startTime})
  209. )
  210. </if>
  211. <if test="param.endTime != null">
  212. AND (
  213. (p.id_ is null and t.create_time_ &lt; #{param.endTime}) or (p.id_ is not null and p.create_time_ &lt; #{param.endTime})
  214. )
  215. </if>
  216. </where>
  217. order by t.create_time_
  218. </select>
  219. <select id="getPendingOrder" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  220. SELECT
  221. <include refid="baseColumns"/>,
  222. p.open_type_ as openType,
  223. p.payment_client_ as paymentClient,
  224. p.pay_channel_ as payChannel,
  225. p.trans_no_ as transNo,
  226. p.payment_no_ as paymentNo
  227. FROM user_order t
  228. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  229. where t.status_ in ('WAIT_PAY','PAYING')
  230. and t.user_id_ = #{param.userId}
  231. <if test="null != param.orderClient and '' != param.orderClient">
  232. AND t.order_client_ = #{param.orderClient}
  233. </if>
  234. and exists (
  235. select 1 from user_order_detail d where t.order_no_ = d.order_no_
  236. and d.good_type_ = #{param.goodType}
  237. <choose>
  238. <when test="param.goodType != null and param.goodType != 'PRACTICE'">
  239. <if test="param.bizId != null">
  240. and d.biz_id_ = #{param.bizId}
  241. </if>
  242. </when>
  243. </choose>
  244. )
  245. order by t.create_time_ desc limit 1
  246. </select>
  247. <select id="selectUnRecordTimeOrder" resultType="com.yonge.cooleshow.biz.dal.entity.UserOrder">
  248. SELECT
  249. <include refid="baseColumns"/>
  250. FROM user_order t
  251. left join student_time st on t.user_id_ = st.user_id_
  252. where t.status_ = 'PAID'
  253. and t.order_client_ = #{param.orderClient}
  254. and exists (
  255. select 1 from user_order_detail od where t.order_no_ = od.order_no_
  256. and (
  257. (st.first_vip_time_ is null and od.good_type_ = 'VIP') or
  258. (st.first_practice_time_ is null and od.good_type_ = 'PRACTICE') or
  259. (st.first_video_time_ is null and od.good_type_ = 'VIDEO') or
  260. (st.first_live_time_ is null and od.good_type_ = 'LIVE') or
  261. (st.first_activity_time_ is null and od.good_type_ = 'ACTI_REGIST') or
  262. (st.first_music_time_ is null and od.good_type_ = 'MUSIC') or
  263. (st.first_pay_time_ is null and t.actual_price_ &gt; 0)
  264. )
  265. )
  266. <if test="param.startTime !=null">
  267. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  268. </if>
  269. <if test="param.endTime !=null">
  270. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  271. </if>
  272. </select>
  273. <select id="getUserOrderByPaymentNoOrTransNo" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  274. SELECT
  275. <include refid="baseColumns"/>,
  276. p.open_type_ as openType,
  277. p.payment_client_ as paymentClient,
  278. p.pay_channel_ as payChannel,
  279. p.trans_no_ as transNo,
  280. p.payment_no_ as paymentNo
  281. FROM user_order t
  282. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  283. <where>
  284. <choose>
  285. <when test="paymentNo != null and paymentNo != ''">
  286. and (
  287. exists (select 1 from user_order_payment p1 where t.order_no_ = p1.order_no_ and p1.payment_no_ = #{paymentNo}) or
  288. exists (
  289. select 1 from user_order_refund b1
  290. left join user_order_refund_bill b2 on b1.id_ = b2.refund_id_
  291. where t.order_no_ = b1.order_no_ and b2.bill_no_ = #{paymentNo}
  292. )
  293. )
  294. </when>
  295. <otherwise>
  296. and (
  297. exists (select 1 from user_order_payment p1 where p1.trans_no_ = #{transNo}) or
  298. exists (
  299. select 1 from user_order_refund b1
  300. left join user_order_refund_bill b2 on b1.id_ = b2.refund_id_
  301. where t.order_no_ = b1.order_no_ and b2.trans_no_ = #{transNo}
  302. )
  303. )
  304. </otherwise>
  305. </choose>
  306. </where>
  307. </select>
  308. <update id="updateStatusByOrderNo">
  309. update user_order set status_ = #{orderStatus},update_time_ = now() where order_no_ = #{orderNo}
  310. </update>
  311. <select id="selectPaymentOrderPage" resultMap="BaseResultMap">
  312. select t.*
  313. from user_order t
  314. <where>
  315. t.payment_version_ = 'V2'
  316. <if test="query.paymentStatus != null and query.paymentStatus.size() != 0">
  317. and t.status_ in
  318. <foreach collection="query.paymentStatus" item="item" separator="," open="(" close=")">
  319. #{item}
  320. </foreach>
  321. </if>
  322. <if test="query.endTime != null">
  323. AND t.create_time_ &lt; #{query.endTime}
  324. </if>
  325. </where>
  326. </select>
  327. <select id="queryExpend"
  328. resultType="com.yonge.cooleshow.biz.dal.wrapper.PaymentDivMemberRecordWrapper$IndexIncomeQueryDto">
  329. select
  330. uo.order_no_ as orderNo,
  331. sut.name_ as name,
  332. su.avatar_ as avatar,
  333. su.phone_ as phone,
  334. uo.actual_price_ as amount,
  335. uo.pay_time_ as payTime,
  336. uo.order_type_ as orderType
  337. from user_order uo
  338. left join
  339. sys_user_tsign sut ON sut.user_id_ = uo.user_id_
  340. left join
  341. sys_user su ON su.id_ = sut.user_id_
  342. where uo.status_ = 'SUCCESS' AND uo.tenant_id_ = #{param.tenantId} AND uo.order_type_ = 'TENANT_ALBUM'
  343. <if test="param.startTime != null and param.startTime != ''">
  344. AND uo.pay_time_ BETWEEN #{param.startTime} AND #{param.endTime}
  345. </if>
  346. <if test="param.orderType != null">
  347. AND uo.order_type_ = #{param.orderType}
  348. </if>
  349. <if test="param.keyword != null and param.keyword != ''">
  350. and sut.name_ LIKE CONCAT('%',#{param.keyword},'%')
  351. </if>
  352. ORDER BY ${param.sortField} ${param.sortType}
  353. </select>
  354. <select id="getExpendOrderDetail"
  355. resultType="com.yonge.cooleshow.biz.dal.wrapper.PaymentDivMemberRecordWrapper$OrderDetailDto">
  356. select
  357. uo.order_no_ as orderNo,
  358. sut.name_ as name,
  359. su.avatar_ as avatar,
  360. su.phone_ as phone,
  361. uo.actual_price_ as amount,
  362. uo.pay_time_ as payTime,
  363. uo.order_type_ as orderType,
  364. uod.good_name_ as goodsName,
  365. uod.good_num_ as goodsNum,
  366. uod.good_type_ as goodsType,
  367. uod.good_url_ as goodsUrl
  368. from user_order uo
  369. left join
  370. sys_user_tsign sut ON sut.user_id_ = uo.user_id_
  371. left join
  372. sys_user su ON su.id_ = sut.user_id_
  373. left join
  374. user_order_detail uod ON uod.order_no_ = uo.order_no_
  375. WHERE pdmr.order_no_ = #{orderNo} LIMIT 1
  376. </select>
  377. <select id="getStudentTenantAlbumNum" resultType="java.lang.Long">
  378. select d.tenant_group_album_id_
  379. from user_order t
  380. left join user_order_detail d on t.order_no_ = d.order_no_
  381. where t.status_ in ('WAIT_PAY','PAYING','PAID') and t.order_type_ = 'TENANT_ALBUM' and d.good_type_ = 'TENANT_ALBUM'
  382. and t.user_id_ = #{userId}
  383. and d.tenant_group_album_id_ in
  384. <foreach collection="tenantGroupAlbumIds" item="item" open="(" separator="," close=")">
  385. #{item}
  386. </foreach>
  387. </select>
  388. </mapper>