UserOrderMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. and d.biz_id_ = #{param.bizId}
  240. </when>
  241. </choose>
  242. )
  243. order by t.create_time_ desc limit 1
  244. </select>
  245. <select id="selectUnRecordTimeOrder" resultType="com.yonge.cooleshow.biz.dal.entity.UserOrder">
  246. SELECT
  247. <include refid="baseColumns"/>
  248. FROM user_order t
  249. left join student_time st on t.user_id_ = st.user_id_
  250. where t.status_ = 'PAID'
  251. and t.order_client_ = #{param.orderClient}
  252. and exists (
  253. select 1 from user_order_detail od where t.order_no_ = od.order_no_
  254. and (
  255. (st.first_vip_time_ is null and od.good_type_ = 'VIP') or
  256. (st.first_practice_time_ is null and od.good_type_ = 'PRACTICE') or
  257. (st.first_video_time_ is null and od.good_type_ = 'VIDEO') or
  258. (st.first_live_time_ is null and od.good_type_ = 'LIVE') or
  259. (st.first_activity_time_ is null and od.good_type_ = 'ACTI_REGIST') or
  260. (st.first_music_time_ is null and od.good_type_ = 'MUSIC') or
  261. (st.first_pay_time_ is null and t.actual_price_ &gt; 0)
  262. )
  263. )
  264. <if test="param.startTime !=null">
  265. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  266. </if>
  267. <if test="param.endTime !=null">
  268. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  269. </if>
  270. </select>
  271. <select id="getUserOrderByPaymentNoOrTransNo" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  272. SELECT
  273. <include refid="baseColumns"/>,
  274. p.open_type_ as openType,
  275. p.payment_client_ as paymentClient,
  276. p.pay_channel_ as payChannel,
  277. p.trans_no_ as transNo,
  278. p.payment_no_ as paymentNo
  279. FROM user_order t
  280. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  281. <where>
  282. <choose>
  283. <when test="paymentNo != null and paymentNo != ''">
  284. and (
  285. exists (select 1 from user_order_payment p1 where t.order_no_ = p1.order_no_ and p1.payment_no_ = #{paymentNo}) or
  286. exists (
  287. select 1 from user_order_refund b1
  288. left join user_order_refund_bill b2 on b1.id_ = b2.refund_id_
  289. where t.order_no_ = b1.order_no_ and b2.bill_no_ = #{paymentNo}
  290. )
  291. )
  292. </when>
  293. <otherwise>
  294. and (
  295. exists (select 1 from user_order_payment p1 where p1.trans_no_ = #{transNo}) or
  296. exists (
  297. select 1 from user_order_refund b1
  298. left join user_order_refund_bill b2 on b1.id_ = b2.refund_id_
  299. where t.order_no_ = b1.order_no_ and b2.trans_no_ = #{transNo}
  300. )
  301. )
  302. </otherwise>
  303. </choose>
  304. </where>
  305. </select>
  306. <update id="updateStatusByOrderNo">
  307. update user_order set status_ = #{orderStatus},update_time_ = now() where order_no_ = #{orderNo}
  308. </update>
  309. <select id="selectPaymentOrderPage" resultMap="BaseResultMap">
  310. select t.*
  311. from user_order t
  312. <where>
  313. t.payment_version_ = 'V2'
  314. <if test="query.paymentStatus != null and query.paymentStatus.size() != 0">
  315. and t.status_ in
  316. <foreach collection="query.paymentStatus" item="item" separator="," open="(" close=")">
  317. #{item}
  318. </foreach>
  319. </if>
  320. <if test="query.endTime != null">
  321. AND t.create_time_ &lt; #{query.endTime}
  322. </if>
  323. </where>
  324. </select>
  325. <select id="queryExpend"
  326. resultType="com.yonge.cooleshow.biz.dal.wrapper.PaymentDivMemberRecordWrapper$IndexIncomeQueryDto">
  327. select
  328. uo.order_no_ as orderNo,
  329. sut.name_ as name,
  330. su.avatar_ as avatar,
  331. su.phone_ as phone,
  332. uo.actual_price_ as amount,
  333. uo.pay_time_ as payTime,
  334. uo.order_type_ as orderType
  335. from user_order uo
  336. left join
  337. sys_user_tsign sut ON sut.user_id_ = uo.user_id_
  338. left join
  339. sys_user su ON su.id_ = sut.user_id_
  340. where uo.status_ = 'SUCCESS' AND uo.tenant_id_ = #{param.tenantId} AND uo.order_type_ = 'TENANT_ALBUM'
  341. <if test="param.startTime != null and param.startTime != ''">
  342. AND uo.pay_time_ BETWEEN #{param.startTime} AND #{param.endTime}
  343. </if>
  344. <if test="param.orderType != null">
  345. AND uo.order_type_ = #{param.orderType}
  346. </if>
  347. <if test="param.keyword != null and param.keyword != ''">
  348. and sut.name_ LIKE CONCAT('%',#{param.keyword},'%')
  349. </if>
  350. ORDER BY ${param.sortField} ${param.sortType}
  351. </select>
  352. <select id="getExpendOrderDetail"
  353. resultType="com.yonge.cooleshow.biz.dal.wrapper.PaymentDivMemberRecordWrapper$OrderDetailDto">
  354. select
  355. uo.order_no_ as orderNo,
  356. sut.name_ as name,
  357. su.avatar_ as avatar,
  358. su.phone_ as phone,
  359. uo.actual_price_ as amount,
  360. uo.pay_time_ as payTime,
  361. uo.order_type_ as orderType,
  362. uod.good_name_ as goodsName,
  363. uod.good_num_ as goodsNum,
  364. uod.good_type_ as goodsType,
  365. uod.good_url_ as goodsUrl
  366. from user_order uo
  367. left join
  368. sys_user_tsign sut ON sut.user_id_ = uo.user_id_
  369. left join
  370. sys_user su ON su.id_ = sut.user_id_
  371. left join
  372. user_order_detail uod ON uod.order_no_ = uo.order_no_
  373. WHERE pdmr.order_no_ = #{orderNo} LIMIT 1
  374. </select>
  375. <select id="getStudentTenantAlbumNum" resultType="java.lang.Long">
  376. select d.tenant_group_album_id_
  377. from user_order t
  378. left join user_order_detail d on t.order_no_ = d.order_no_
  379. where t.status_ in ('WAIT_PAY','PAYING','PAID') and t.order_type_ = 'TENANT_ALBUM' and d.good_type_ = 'TENANT_ALBUM'
  380. and t.user_id_ = #{userId}
  381. and d.tenant_group_album_id_ in
  382. <foreach collection="tenantGroupAlbumIds" item="item" open="(" separator="," close=")">
  383. #{item}
  384. </foreach>
  385. </select>
  386. </mapper>