UserOrderMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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.paymentVersion != null">
  137. and t.payment_version_ = #{param.paymentVersion}
  138. </if>
  139. <if test="null != param.search and '' != param.search">
  140. AND (
  141. t.user_id_ LIKE CONCAT('%', #{param.search}, '%') or
  142. u.username_ LIKE CONCAT('%', #{param.search}, '%') or
  143. u.phone_ LIKE CONCAT('%', #{param.search}, '%') or
  144. ti.name_ LIKE CONCAT('%', #{param.search}, '%')
  145. )
  146. </if>
  147. <if test="null != param.searchNo and '' != param.searchNo">
  148. AND (
  149. t.order_no_ LIKE CONCAT('%', #{param.searchNo}, '%') or
  150. p.trans_no_ LIKE CONCAT('%', #{param.searchNo}, '%')
  151. )
  152. </if>
  153. <if test="null != param.orderType and '' != param.orderType">
  154. AND FIND_IN_SET(t.order_type_,#{param.orderType})
  155. </if>
  156. <if test="null != param.status and '' != param.status">
  157. AND FIND_IN_SET(t.status_,#{param.status})
  158. </if>
  159. <if test="param.startTime !=null">
  160. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  161. </if>
  162. <if test="param.endTime !=null">
  163. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  164. </if>
  165. <if test="param.userId !=null">
  166. AND t.user_id_ = #{param.userId}
  167. </if>
  168. <if test="param.merchId !=null or (param.goodType !=null and param.goodType !='') or param.bizId !=null">
  169. AND exists(
  170. select 1 from user_order_detail d where t.order_no_ = d.order_no_
  171. <if test="param.merchId !=null ">
  172. and d.merch_id_ = #{param.merchId}
  173. </if>
  174. <if test="param.goodType !=null and param.goodType !=''">
  175. and d.good_type_ = #{param.goodType}
  176. </if>
  177. <if test="param.bizId !=null">
  178. and d.biz_id_ = #{param.bizId}
  179. </if>
  180. )
  181. </if>
  182. </where>
  183. order by field(t.status_,'WAIT_PAY','PAYING') desc, t.create_time_ desc
  184. </sql>
  185. <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  186. <include refid="selectSql"/>
  187. </select>
  188. <select id="selectAllList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  189. <include refid="selectSql"/>
  190. </select>
  191. <select id="selectPendingList" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  192. SELECT
  193. <include refid="baseColumns"/>
  194. FROM user_order t
  195. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  196. <where>
  197. <if test="null != param.status and '' != param.status">
  198. AND t.status_ = #{param.status}
  199. </if>
  200. <if test="param.paymentVersion != null">
  201. and t.payment_version_ = #{param.paymentVersion}
  202. </if>
  203. <if test="param.startTime != null">
  204. AND (
  205. (p.id_ is null and t.create_time_ &gt;= #{param.startTime}) or (p.id_ is not null and p.create_time_ &gt;= #{param.startTime})
  206. )
  207. </if>
  208. <if test="param.endTime != null">
  209. AND (
  210. (p.id_ is null and t.create_time_ &lt; #{param.endTime}) or (p.id_ is not null and p.create_time_ &lt; #{param.endTime})
  211. )
  212. </if>
  213. </where>
  214. order by t.create_time_
  215. </select>
  216. <select id="getPendingOrder" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  217. SELECT
  218. <include refid="baseColumns"/>,
  219. p.open_type_ as openType,
  220. p.payment_client_ as paymentClient,
  221. p.pay_channel_ as payChannel,
  222. p.trans_no_ as transNo,
  223. p.payment_no_ as paymentNo
  224. FROM user_order t
  225. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  226. where t.status_ in ('WAIT_PAY','PAYING')
  227. and t.user_id_ = #{param.userId}
  228. <if test="null != param.orderClient and '' != param.orderClient">
  229. AND t.order_client_ = #{param.orderClient}
  230. </if>
  231. and exists (
  232. select 1 from user_order_detail d where t.order_no_ = d.order_no_
  233. and d.good_type_ = #{param.goodType}
  234. <choose>
  235. <when test="param.goodType != null and param.goodType != 'PRACTICE'">
  236. and d.biz_id_ = #{param.bizId}
  237. </when>
  238. </choose>
  239. )
  240. order by t.create_time_ desc limit 1
  241. </select>
  242. <select id="selectUnRecordTimeOrder" resultType="com.yonge.cooleshow.biz.dal.entity.UserOrder">
  243. SELECT
  244. <include refid="baseColumns"/>
  245. FROM user_order t
  246. left join student_time st on t.user_id_ = st.user_id_
  247. where t.status_ = 'PAID'
  248. and t.order_client_ = #{param.orderClient}
  249. and exists (
  250. select 1 from user_order_detail od where t.order_no_ = od.order_no_
  251. and (
  252. (st.first_vip_time_ is null and od.good_type_ = 'VIP') or
  253. (st.first_practice_time_ is null and od.good_type_ = 'PRACTICE') or
  254. (st.first_video_time_ is null and od.good_type_ = 'VIDEO') or
  255. (st.first_live_time_ is null and od.good_type_ = 'LIVE') or
  256. (st.first_activity_time_ is null and od.good_type_ = 'ACTI_REGIST') or
  257. (st.first_music_time_ is null and od.good_type_ = 'MUSIC') or
  258. (st.first_pay_time_ is null and t.actual_price_ &gt; 0)
  259. )
  260. )
  261. <if test="param.startTime !=null">
  262. <![CDATA[AND t.create_time_ >= #{param.startTime} ]]>
  263. </if>
  264. <if test="param.endTime !=null">
  265. <![CDATA[AND t.create_time_ < #{param.endTime} ]]>
  266. </if>
  267. </select>
  268. <select id="getUserOrderByPaymentNoOrTransNo" resultType="com.yonge.cooleshow.biz.dal.vo.UserOrderVo">
  269. SELECT
  270. <include refid="baseColumns"/>,
  271. p.open_type_ as openType,
  272. p.payment_client_ as paymentClient,
  273. p.pay_channel_ as payChannel,
  274. p.trans_no_ as transNo,
  275. p.payment_no_ as paymentNo
  276. FROM user_order t
  277. left join user_order_payment p on t.order_no_ = p.order_no_ and (p.status_ = 'pending' or p.status_ = 'succeeded')
  278. <where>
  279. <choose>
  280. <when test="paymentNo != null and paymentNo != ''">
  281. and (
  282. exists (select 1 from user_order_payment p1 where t.order_no_ = p1.order_no_ and p1.payment_no_ = #{paymentNo}) or
  283. exists (
  284. select 1 from user_order_refund b1
  285. left join user_order_refund_bill b2 on b1.id_ = b2.refund_id_
  286. where t.order_no_ = b1.order_no_ and b2.bill_no_ = #{paymentNo}
  287. )
  288. )
  289. </when>
  290. <otherwise>
  291. and (
  292. exists (select 1 from user_order_payment p1 where p1.trans_no_ = #{transNo}) or
  293. exists (
  294. select 1 from user_order_refund b1
  295. left join user_order_refund_bill b2 on b1.id_ = b2.refund_id_
  296. where t.order_no_ = b1.order_no_ and b2.trans_no_ = #{transNo}
  297. )
  298. )
  299. </otherwise>
  300. </choose>
  301. </where>
  302. </select>
  303. <update id="updateStatusByOrderNo">
  304. update user_order set status_ = #{orderStatus},update_time_ = now() where order_no_ = #{orderNo}
  305. </update>
  306. <select id="selectPaymentOrderPage" resultMap="BaseResultMap">
  307. select t.*
  308. from user_order t
  309. <where>
  310. t.payment_version_ = 'V2'
  311. <if test="query.paymentStatus != null and query.paymentStatus.size() != 0">
  312. and t.status_ in
  313. <foreach collection="query.paymentStatus" item="item" separator="," open="(" close=")">
  314. #{item}
  315. </foreach>
  316. </if>
  317. <if test="query.endTime != null">
  318. AND t.create_time_ &lt; #{query.endTime}
  319. </if>
  320. </where>
  321. </select>
  322. <select id="queryExpend"
  323. resultType="com.yonge.cooleshow.biz.dal.wrapper.PaymentDivMemberRecordWrapper$IndexIncomeQueryDto">
  324. select
  325. uo.order_no_ as orderNo,
  326. sut.name_ as name,
  327. su.avatar_ as avatar,
  328. su.phone_ as phone,
  329. uo.actual_price_ as amount,
  330. uo.pay_time_ as payTime,
  331. uo.order_type_ as orderType
  332. from user_order uo
  333. left join
  334. sys_user_tsign sut ON sut.user_id_ = uo.user_id_
  335. left join
  336. sys_user su ON su.id_ = sut.user_id_
  337. where uo.status_ = 'SUCCESS' AND uo.tenant_id_ = #{param.tenantId} AND uo.order_type_ = 'TENANT_ALBUM'
  338. <if test="param.startTime != null and param.startTime != ''">
  339. AND uo.pay_time_ BETWEEN #{param.startTime} AND #{param.endTime}
  340. </if>
  341. <if test="param.orderType != null">
  342. AND uo.order_type_ = #{param.orderType}
  343. </if>
  344. <if test="param.keyword != null and param.keyword != ''">
  345. and sut.name_ LIKE CONCAT('%',#{param.keyword},'%')
  346. </if>
  347. ORDER BY ${param.sortField} ${param.sortType}
  348. </select>
  349. <select id="getExpendOrderDetail"
  350. resultType="com.yonge.cooleshow.biz.dal.wrapper.PaymentDivMemberRecordWrapper$OrderDetailDto">
  351. select
  352. uo.order_no_ as orderNo,
  353. sut.name_ as name,
  354. su.avatar_ as avatar,
  355. su.phone_ as phone,
  356. uo.actual_price_ as amount,
  357. uo.pay_time_ as payTime,
  358. uo.order_type_ as orderType,
  359. uod.good_name_ as goodsName,
  360. uod.good_num_ as goodsNum,
  361. uod.good_type_ as goodsType,
  362. uod.good_url_ as goodsUrl
  363. from user_order uo
  364. left join
  365. sys_user_tsign sut ON sut.user_id_ = uo.user_id_
  366. left join
  367. sys_user su ON su.id_ = sut.user_id_
  368. left join
  369. user_order_detail uod ON uod.order_no_ = uo.order_no_
  370. WHERE pdmr.order_no_ = #{orderNo} LIMIT 1
  371. </select>
  372. </mapper>