StudentPaymentOrderMapper.xml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.StudentPaymentOrderDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.StudentPaymentOrder" id="StudentPaymentOrder">
  9. <result column="id_" property="id"/>
  10. <result column="group_type_" property="groupType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  11. <result column="user_id_" property="userId"/>
  12. <result column="organ_id_" property="organId"/>
  13. <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  14. <result column="expect_amount_" property="expectAmount"/>
  15. <result column="actual_amount_" property="actualAmount"/>
  16. <result column="com_amount_" property="comAmount"/>
  17. <result column="per_amount_" property="perAmount"/>
  18. <result column="balance_payment_amount_" property="balancePaymentAmount"/>
  19. <result column="remit_fee_" property="remitFee"/>
  20. <result column="course_remit_fee_" property="courseRemitFee"/>
  21. <result column="trans_no_" property="transNo"/>
  22. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  23. <result column="memo_" property="memo"/>
  24. <result column="create_time_" property="createTime"/>
  25. <result column="update_time_" property="updateTime"/>
  26. <result column="payment_channel_" property="paymentChannel"/>
  27. <result column="payment_business_channel_" property="paymentBusinessChannel"/>
  28. <result column="payment_account_no_" property="paymentAccountNo"/>
  29. <result column="mer_nos_" property="merNos"/>
  30. <result column="order_no_" property="orderNo"/>
  31. <result column="music_group_id_" property="musicGroupId"/>
  32. <result column="class_group_id_" property="classGroupId"/>
  33. <result column="pay_time_" property="payTime"/>
  34. <result column="version_" property="version"/>
  35. </resultMap>
  36. <resultMap type="com.ym.mec.biz.dal.entity.StudentPaymentOrder" extends="StudentPaymentOrder"
  37. id="PaymentOrderAndStudentInfo">
  38. <result column="username_" property="user.username"/>
  39. <result column="phone_" property="user.phone"/>
  40. </resultMap>
  41. <resultMap type="com.ym.mec.biz.dal.entity.Goods" id="Goods">
  42. <result column="id_" property="id"/>
  43. <result column="goods_category_id_" property="goodsCategoryId"/>
  44. <result column="sn_" property="sn"/>
  45. <result column="name_" property="name"/>
  46. <result column="brand_" property="brand"/>
  47. <result column="specification_" property="specification"/>
  48. <result column="image_" property="image"/>
  49. <result column="stock_count_" property="stockCount"/>
  50. <result column="sell_count_" property="sellCount"/>
  51. <result column="market_price_" property="marketPrice"/>
  52. <result column="discount_price_" property="discountPrice"/>
  53. <result column="group_purchase_price_" property="groupPurchasePrice"/>
  54. <result column="brief_" property="brief"/>
  55. <result column="desc_" property="desc"/>
  56. <result column="is_new_" property="isNew" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  57. <result column="is_top_" property="isTop" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  58. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  59. <result column="memo_" property="memo"/>
  60. <result column="publish_time_" property="publishTime"/>
  61. <result column="create_time_" property="createTime"/>
  62. <result column="update_time_" property="updateTime"/>
  63. <result column="complement_goods_id_list_" property="complementGoodsIdList"/>
  64. </resultMap>
  65. <!-- 根据主键查询一条记录 -->
  66. <select id="get" resultMap="StudentPaymentOrder">
  67. SELECT *
  68. FROM student_payment_order
  69. WHERE id_ = #{id}
  70. </select>
  71. <!-- 全查询 -->
  72. <select id="findAll" resultMap="StudentPaymentOrder">
  73. SELECT *
  74. FROM student_payment_order
  75. ORDER BY id_
  76. </select>
  77. <!-- 向数据库增加一条记录 -->
  78. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder" useGeneratedKeys="true"
  79. keyColumn="id" keyProperty="id">
  80. INSERT INTO student_payment_order
  81. (id_, group_type_, user_id_, organ_id_, routing_organ_id_, type_, expect_amount_, actual_amount_, com_amount_,
  82. per_amount_,
  83. balance_payment_amount_, remit_fee_,course_remit_fee_, trans_no_,
  84. status_, memo_, create_time_, update_time_, payment_channel_, payment_business_channel_,
  85. payment_account_no_, mer_nos_, order_no_, music_group_id_, class_group_id_, pay_time_)
  86. VALUES (#{id}, #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  87. #{userId}, #{organId}, #{routingOrganId},
  88. #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  89. #{expectAmount}, #{actualAmount}, #{comAmount}, #{perAmount}, #{balancePaymentAmount},
  90. #{remitFee},#{courseRemitFee}, #{transNo},
  91. #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, #{memo}, now(), now(),
  92. #{paymentChannel}, #{paymentBusinessChannel}, #{paymentAccountNo}, #{merNos}, #{orderNo},
  93. #{musicGroupId},
  94. #{classGroupId}, #{payTime})
  95. </insert>
  96. <!-- 根据主键查询一条记录 -->
  97. <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder">
  98. UPDATE student_payment_order
  99. <set>
  100. <if test="status != null">
  101. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  102. </if>
  103. <if test="groupType != null">
  104. group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  105. </if>
  106. <if test="orderNo != null">
  107. order_no_ = #{orderNo},
  108. </if>
  109. <if test="classGroupId != null">
  110. class_group_id_ = #{classGroupId},
  111. </if>
  112. <if test="expectAmount != null">
  113. expect_amount_ = #{expectAmount},
  114. </if>
  115. <if test="memo != null">
  116. memo_ = #{memo},
  117. </if>
  118. <if test="paymentChannel != null">
  119. payment_channel_ = #{paymentChannel},
  120. </if>
  121. <if test="userId != null">
  122. user_id_ = #{userId},
  123. </if>
  124. <if test="paymentAccountNo != null">
  125. payment_account_no_ = #{paymentAccountNo},
  126. </if>
  127. <if test="merNos != null">
  128. mer_nos_ = #{merNos},
  129. </if>
  130. <if test="paymentBusinessChannel != null">
  131. payment_business_channel_ = #{paymentBusinessChannel},
  132. </if>
  133. <if test="transNo != null">
  134. trans_no_ = #{transNo},
  135. </if>
  136. <if test="actualAmount != null">
  137. actual_amount_ = #{actualAmount},
  138. </if>
  139. <if test="comAmount != null">
  140. com_amount_ = #{comAmount},
  141. </if>
  142. <if test="perAmount != null">
  143. per_amount_ = #{perAmount},
  144. </if>
  145. <if test="balancePaymentAmount != null">
  146. balance_payment_amount_ = #{balancePaymentAmount},
  147. </if>
  148. <if test="remitFee != null">
  149. remit_fee_ = #{remitFee},
  150. </if>
  151. <if test="courseRemitFee != null">
  152. course_remit_fee_ = #{courseRemitFee},
  153. </if>
  154. <if test="type != null">
  155. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  156. </if>
  157. <if test="musicGroupId != null">
  158. music_group_id_ = #{musicGroupId},
  159. </if>
  160. <if test="organId != null">
  161. organ_id_ = #{organId},
  162. </if>
  163. <if test="routingOrganId != null">
  164. routing_organ_id_ = #{routingOrganId},
  165. </if>
  166. <if test="payTime != null">
  167. pay_time_ = #{payTime},
  168. </if>
  169. <if test="version != null">
  170. version_ = version_+1,
  171. </if>
  172. update_time_ = NOW()
  173. </set>
  174. WHERE id_ = #{id} AND version_ = #{version}
  175. </update>
  176. <!-- 根据主键删除一条记录 -->
  177. <delete id="delete">
  178. DELETE
  179. FROM student_payment_order
  180. WHERE id_ = #{id}
  181. </delete>
  182. <!-- 分页查询 -->
  183. <select id="queryPage" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  184. SELECT spo.*,u.username_,u.phone_ FROM student_payment_order spo
  185. left join sys_user u on spo.user_id_ = u.id_
  186. <include refid="queryPaymentOrder"/>
  187. ORDER BY spo.id_ DESC
  188. <include refid="global.limit"/>
  189. </select>
  190. <!-- 查询当前表的总记录数 -->
  191. <select id="queryCount" resultType="int" parameterType="map">
  192. SELECT COUNT(spo.id_) FROM student_payment_order spo
  193. left join sys_user u on spo.user_id_ = u.id_
  194. <include refid="queryPaymentOrder"/>
  195. </select>
  196. <sql id="queryPaymentOrder">
  197. <where>
  198. <if test="userIds != null">
  199. AND spo.user_id_ IN
  200. <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  201. #{userId}
  202. </foreach>
  203. </if>
  204. <if test="organId != null">
  205. AND FIND_IN_SET(spo.organ_id_,#{organId})
  206. </if>
  207. <if test="orderStartDate != null">
  208. AND DATE_FORMAT(spo.create_time_,'%Y-%m-%d') &gt;= #{orderStartDate}
  209. </if>
  210. <if test="orderEndDate != null">
  211. AND DATE_FORMAT(spo.create_time_,'%Y-%m-%d') &lt;= #{orderEndDate}
  212. </if>
  213. <if test="paymentType != null">
  214. AND spo.type_ = #{paymentType}
  215. </if>
  216. <if test="remark != null">
  217. AND spo.memo_ LIKE CONCAT('%',#{remark},'%')
  218. </if>
  219. <if test="studentId != null">
  220. AND spo.user_id_ = #{studentId}
  221. </if>
  222. <if test="paymentStatus != null">
  223. AND spo.status_ = #{paymentStatus}
  224. </if>
  225. <if test="paymentChannel != null">
  226. AND spo.payment_channel_ NOT IN (#{paymentChannel})
  227. </if>
  228. <if test='orderType != null and orderType.toString()=="1".toString()'>
  229. AND spo.com_amount_ > 0
  230. </if>
  231. <if test='orderType != null and orderType.toString()=="2".toString()'>
  232. AND spo.per_amount_ > 0
  233. </if>
  234. <if test="routingOrganId != null">
  235. AND FIND_IN_SET(spo.routing_organ_id_,#{routingOrganId})
  236. </if>
  237. <if test="actualAmount != null">
  238. AND spo.actual_amount_ >= #{actualAmount}
  239. </if>
  240. <if test="balancePaymentAmount != null">
  241. AND spo.balance_payment_amount_ >= #{balancePaymentAmount}
  242. </if>
  243. <if test="orderNo != null">
  244. AND spo.order_no_ = #{orderNo}
  245. </if>
  246. <if test="merNos != null">
  247. AND FIND_IN_SET(#{merNos},spo.mer_nos_)
  248. </if>
  249. <if test="transNo != null">
  250. AND spo.trans_no_ = #{transNo}
  251. </if>
  252. <if test="chargeType != null">
  253. AND spo.group_type_='SPORADIC'
  254. AND sci.charge_type_ = #{chargeType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  255. </if>
  256. </where>
  257. </sql>
  258. <select id="queryApplyGoodsList" resultMap="Goods" parameterType="map">
  259. select g.*
  260. from goods g
  261. where g.id_ in (SELECT spod.goods_id_list_
  262. FROM student_payment_order spo
  263. left join
  264. student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  265. where spo.music_group_id_ =
  266. #{musicGroupId}
  267. and spo.type_ = 'APPLY'
  268. and spod.type_ =
  269. #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler})
  270. </select>
  271. <select id="queryByCondition" resultMap="StudentPaymentOrder" parameterType="map">
  272. SELECT spo.*
  273. FROM student_payment_order spo
  274. WHERE spo.user_id_ = #{userId}
  275. AND spo.music_group_id_ = #{musicGroupId}
  276. AND spo.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  277. AND spo.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  278. and spo.type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  279. </select>
  280. <select id="findByStudentVipGroup" resultMap="StudentPaymentOrder">
  281. SELECT
  282. spo.*
  283. FROM
  284. student_payment_order spo
  285. WHERE spo.user_id_=#{userId}
  286. AND spo.music_group_id_=#{vipGroupId}
  287. <if test="status!=null and status!=''">
  288. AND spo.status_=#{status}
  289. </if>
  290. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  291. </select>
  292. <select id="sumSurplusCourseFee" resultType="java.math.BigDecimal">
  293. SELECT SUM(cssp.expect_price_)
  294. FROM course_schedule_student_payment cssp
  295. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  296. WHERE cssp.user_id_ = #{userId}
  297. AND cssp.music_group_id_ = #{vipGroupId}
  298. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
  299. </select>
  300. <select id="findNotFailedOrderByStudentVipGroup" resultMap="StudentPaymentOrder">
  301. SELECT spo.*
  302. FROM student_payment_order spo
  303. WHERE spo.user_id_ = #{userId}
  304. AND spo.music_group_id_ = #{vipGroupId}
  305. AND spo.status_ != 'FAILED'
  306. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  307. </select>
  308. <!-- 查询报名订单 -->
  309. <select id="findMusicGroupApplyOrderByStatus" resultMap="StudentPaymentOrder">
  310. SELECT *
  311. FROM student_payment_order
  312. WHERE music_group_id_ = #{musicGroupId}
  313. AND user_id_ = #{userId}
  314. AND type_ = 'APPLY'
  315. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  316. ORDER BY id_ DESC
  317. LIMIT 1
  318. </select>
  319. <!-- 根据订单号查询订单 -->
  320. <select id="findOrderByOrderNo" resultMap="StudentPaymentOrder">
  321. SELECT *
  322. FROM student_payment_order
  323. WHERE order_no_ = #{orderNo}
  324. </select>
  325. <select id="queryByDealStatus" resultMap="StudentPaymentOrder" parameterType="map">
  326. SELECT *
  327. FROM student_payment_order
  328. WHERE music_group_id_ = #{musicGroupId}
  329. AND type_ =
  330. #{type}
  331. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  332. </select>
  333. <!-- 查找支付成功和支付中订单 -->
  334. <select id="findPayOrderNum" resultType="int">
  335. <![CDATA[
  336. SELECT COUNT(*)
  337. FROM student_payment_order
  338. WHERE FIND_IN_SET(status_, 'SUCCESS,ING,WAIT_PAY')
  339. ]]>
  340. </select>
  341. <resultMap type="com.ym.mec.biz.dal.dto.UserGoodsDto" id="userGoodsDto">
  342. <result column="goods_id_" property="goodsId"/>
  343. <collection property="goodsName" ofType="string">
  344. <result column="goods_name_"/>
  345. </collection>
  346. </resultMap>
  347. <select id="findGoodsIds" resultMap="userGoodsDto">
  348. SELECT g.id_ goods_id_, g.name_ goods_name_
  349. FROM student_payment_order spo
  350. LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
  351. LEFT JOIN goods g ON FIND_IN_SET(g.id_, spod.goods_id_list_)
  352. WHERE spo.type_ = 'APPLY'
  353. AND spo.status_ = 'SUCCESS'
  354. AND spod.goods_id_list_ IS NOT NULL
  355. AND spo.music_group_id_ = #{musicGroupId}
  356. AND spo.user_id_ = #{userId}
  357. </select>
  358. <select id="findOrdersByStatus" resultMap="StudentPaymentOrder">
  359. SELECT *
  360. FROM student_payment_order
  361. WHERE status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  362. AND payment_channel_ = #{paymentChannel}
  363. LIMIT 100
  364. </select>
  365. <!-- 查询支付中超时订单 -->
  366. <select id="findOrdersOverTime" resultMap="StudentPaymentOrder">
  367. SELECT * FROM student_payment_order WHERE order_no_ IN
  368. <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
  369. #{orderNo}
  370. </foreach>
  371. AND status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  372. <![CDATA[ AND create_time_ <= ]]> #{beforeTime}
  373. </select>
  374. <select id="countStudentPaymentNum" resultType="int">
  375. select count(1)
  376. from student_payment_order
  377. where music_group_id_ = #{musicGroupId}
  378. AND status_ = 'SUCCESS'
  379. AND type_ = 'SMALL_CLASS_TO_BUY'
  380. </select>
  381. <select id="countSurplusCourseByMusicGroupAndUser" resultType="int">
  382. SELECT COUNT(*)
  383. FROM course_schedule_student_payment cssp
  384. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  385. WHERE cssp.user_id_ = #{userId}
  386. AND cssp.music_group_id_ = #{musicGroupId}
  387. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
  388. </select>
  389. <select id="sumGroupIncomeFee" resultType="java.math.BigDecimal">
  390. SELECT SUM(expect_amount_)
  391. FROM student_payment_order
  392. WHERE group_type_ = #{groupType}
  393. AND music_group_id_ = #{musicGroupId}
  394. AND status_ = 'SUCCESS'
  395. </select>
  396. <select id="findStudentPaymentOrder" resultMap="StudentPaymentOrder">
  397. SELECT *
  398. FROM student_payment_order
  399. WHERE id_ IN (SELECT MAX(sp.id_)
  400. FROM (SELECT *
  401. FROM student_payment_order
  402. WHERE group_type_ = #{groupType}
  403. AND type_ = 'APPLY'
  404. AND music_group_id_ = #{musicGroupId}
  405. AND status_ = 'SUCCESS'
  406. ORDER BY id_ DESC) sp
  407. GROUP BY sp.user_id_)
  408. </select>
  409. <select id="findOrderByGroupType" resultType="int">
  410. SELECT COUNT(id_) FROM student_payment_order
  411. WHERE group_type_ = #{groupType}
  412. AND user_id_ = #{userId}
  413. AND music_group_id_ = #{sporadicId}
  414. <if test="status != null">
  415. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  416. </if>
  417. </select>
  418. <select id="queryActualAmount" resultType="java.util.Map">
  419. SELECT spo.actual_amount_ 'value',spo.id_ 'key'
  420. FROM student_payment_order spo
  421. WHERE spo.id_ IN
  422. <foreach collection="paymentOrderNo" open="(" close=")" separator="," item="item">
  423. #{item}
  424. </foreach>
  425. </select>
  426. <select id="findFixOrder" resultMap="StudentPaymentOrder">
  427. SELECT *
  428. FROM student_payment_order
  429. where status_ = 'SUCCESS'
  430. AND type_ = 'APPLY'
  431. AND actual_amount_ > 0
  432. and mer_nos_ IS NULL
  433. LIMIT 100
  434. </select>
  435. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto" id="orderAndDetail"
  436. extends="StudentPaymentOrder">
  437. <result column="organ_name" property="organName"/>
  438. <result column="username_" property="user.username"/>
  439. <result column="charge_type_" property="chargeType"/>
  440. <result column="routeMerNo" property="routeMerNo"/>
  441. <result column="routeAmount" property="routeAmount"/>
  442. <result column="routeBalance" property="routeBalance"/>
  443. <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
  444. <result column="detail_id_" property="id"/>
  445. <result column="detail_type_" property="type"/>
  446. <result column="detail_price_" property="price"/>
  447. <result column="detail_kit_group_purchase_type_" property="kitGroupPurchaseType"/>
  448. </collection>
  449. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  450. <result column="goods_id" property="id"/>
  451. <result column="goods_name" property="name"/>
  452. </collection>
  453. </resultMap>
  454. <!-- 分页查询 -->
  455. <select id="ExportQueryPage" resultMap="orderAndDetail" parameterType="map">
  456. SELECT spo.*,u.username_,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  457. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  458. sci.charge_type_,g.id_ goods_id, g.name_ goods_name,o.name_ organ_name
  459. FROM student_payment_order spo
  460. LEFT JOIN sys_user u on spo.user_id_ = u.id_
  461. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  462. <if test='orderType != null and orderType.toString()=="0".toString()'>
  463. LEFT JOIN organization o on spo.organ_id_ = o.id_
  464. </if>
  465. <if test='orderType != null and orderType.toString()=="1".toString()'>
  466. LEFT JOIN organization o on spo.organ_id_ = o.id_
  467. </if>
  468. <if test='orderType != null and orderType.toString()=="2".toString()'>
  469. LEFT JOIN organization o on spo.organ_id_ = o.id_
  470. </if>
  471. <if test='orderType != null and orderType.toString()=="3".toString()'>
  472. LEFT JOIN organization o on spo.routing_organ_id_ = o.id_
  473. </if>
  474. LEFT JOIN sporadic_charge_info sci on spo.music_group_id_ = sci.id_
  475. LEFT JOIN goods g on FIND_IN_SET(g.id_,spod.goods_id_list_)
  476. <include refid="queryPaymentOrder"/>
  477. ORDER BY spo.id_ ASC
  478. </select>
  479. <resultMap id="SporadicChargeInfoDtoMap" type="com.ym.mec.biz.dal.dto.SporadicChargeInfoDto">
  480. <result property="organName" column="organ_name_"/>
  481. <result property="title" column="title_"/>
  482. <result property="type" column="type_"/>
  483. <result property="amount" column="amount_"/>
  484. <result property="createTime" column="create_time_"/>
  485. <result property="payTime" column="pay_time_"/>
  486. <result property="username" column="username_"/>
  487. <result property="payStatus" column="pay_status_"/>
  488. </resultMap>
  489. <select id="sporadicQueryPage" resultMap="SporadicChargeInfoDtoMap">
  490. SELECT o.name_ organ_name_,sci.title_,sci.charge_type_ type_,
  491. spo.actual_amount_ amount_,spo.create_time_,spo.pay_time_,su.username_,spo.status_ pay_status_
  492. FROM student_payment_order spo
  493. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  494. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  495. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  496. WHERE spo.type_ = 'SPORADIC'
  497. <include refid="sporadicQueryPageSql"/>
  498. ORDER BY spo.id_ DESC
  499. <include refid="global.limit"/>
  500. </select>
  501. <select id="countSporadicPage" resultType="java.lang.Integer">
  502. SELECT COUNT(spo.id_)
  503. FROM student_payment_order spo
  504. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  505. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  506. WHERE spo.type_ = 'SPORADIC'
  507. <include refid="sporadicQueryPageSql"/>
  508. </select>
  509. <sql id="sporadicQueryPageSql">
  510. <if test="organId != null">
  511. AND FIND_IN_SET(spo.organ_id_,#{organId})
  512. </if>
  513. <if test="search != null">
  514. AND (sci.title_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%'))
  515. </if>
  516. <if test="chargeType != null">
  517. AND sci.charge_type_ = #{chargeType}
  518. </if>
  519. <if test="payStatus != null">
  520. AND spo.status_ = #{payStatus}
  521. </if>
  522. </sql>
  523. <resultMap id="luckStatis" type="com.ym.mec.biz.dal.dto.OrderStatisDto">
  524. <result property="organName" column="organName"/>
  525. <result property="nums" column="nums"/>
  526. <result property="money" column="money"/>
  527. </resultMap>
  528. <select id="getLuckStatis" resultMap="luckStatis">
  529. SELECT o.name_ organName, SUM(spo.actual_amount_) money, COUNT(spo.id_) nums
  530. FROM student_payment_order spo
  531. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  532. WHERE spo.type_ = 'LUCK'
  533. AND spo.status_ = 'SUCCESS'
  534. GROUP BY spo.organ_id_
  535. ORDER BY nums DESC;
  536. </select>
  537. <select id="queryIncomeStatisticsWithCurrentMonth" resultType="map">
  538. select count(*) total,sum(actual_amount_) total_num_ from student_payment_order
  539. where actual_amount_ &gt; 0 and DATE_FORMAT(create_time_, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' ) AND
  540. status_ = 'SUCCESS' and organ_id_ not in (36,38)
  541. <if test="organId != null">
  542. and FIND_IN_SET(organ_id_,#{organId})
  543. </if>
  544. </select>
  545. <select id="countUserBuyVipGroupSuccessOrder" resultType="int">
  546. select count(*)
  547. from student_payment_order
  548. where user_id_ = #{userId}
  549. and music_group_id_ = #{vipGroupId}
  550. and group_type_ = 'VIP'
  551. and status_ = 'SUCCESS'
  552. </select>
  553. <select id="findUserBuyVipGroupOrder" resultMap="StudentPaymentOrder">
  554. select *
  555. from student_payment_order
  556. where user_id_ = #{userId}
  557. and music_group_id_ = #{vipGroupId}
  558. and group_type_ = 'VIP'
  559. </select>
  560. <select id="findUserGroupOrders" resultMap="StudentPaymentOrder">
  561. select * from student_payment_order
  562. where user_id_=#{userId}
  563. and music_group_id_=#{groupId}
  564. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  565. <if test="status!=null">
  566. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  567. </if>
  568. </select>
  569. <select id="getOrderMoneyAmount" parameterType="map" resultMap="StudentPaymentOrder">
  570. SELECT SUM(spo.expect_amount_) expect_amount_,SUM(actual_amount_) actual_amount_,SUM(balance_payment_amount_)
  571. balance_payment_amount_ FROM student_payment_order spo
  572. <include refid="queryPaymentOrder"/>
  573. </select>
  574. <!-- 分页查询 -->
  575. <select id="queryPageOrder" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  576. SELECT spo.*,u.username_,u.phone_ FROM student_payment_order spo
  577. left join sys_user u on spo.user_id_ = u.id_
  578. <include refid="queryPaymentOrder"/>
  579. ORDER BY spo.id_ DESC
  580. <include refid="global.limit"/>
  581. </select>
  582. <select id="findOrderByGroup" resultMap="StudentPaymentOrder">
  583. SELECT * FROM student_payment_order
  584. WHERE music_group_id_=#{groupId}
  585. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  586. <if test="status!=null">
  587. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  588. </if>
  589. </select>
  590. <select id="sumPerAccountAmount" resultType="java.math.BigDecimal"><![CDATA[
  591. SELECT SUM(per_amount_)
  592. FROM student_payment_order
  593. WHERE FIND_IN_SET(status_, 'SUCCESS,ING')
  594. AND create_time_ >= #{firstDate}
  595. AND create_time_ <= NOW()
  596. AND FIND_IN_SET(#{merNo}, mer_nos_)
  597. ]]>
  598. </select>
  599. <select id="getChargeAmount" parameterType="map" resultType="java.math.BigDecimal">
  600. SELECT SUM(actual_amount_) FROM student_payment_order spo
  601. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_ = sci.id_
  602. <include refid="queryPaymentOrder"/>
  603. </select>
  604. <select id="sumAccountAmount" resultType="java.math.BigDecimal">
  605. <![CDATA[
  606. SELECT SUM(actual_amount_)
  607. FROM student_payment_order
  608. WHERE status_ IN ('SUCCESS', 'ING')
  609. AND create_time_ >= #{firstDate}
  610. AND create_time_ <= NOW()
  611. AND mer_nos_ = #{merNo}
  612. ]]></select>
  613. <select id="countGroupOrderWithoutFailed" resultType="int">
  614. SELECT COUNT(*)
  615. FROM student_payment_order spo
  616. LEFT JOIN class_group_student_mapper cgsm
  617. ON spo.music_group_id_ = cgsm.music_group_id_ AND spo.user_id_ = cgsm.user_id_
  618. WHERE spo.music_group_id_ = #{groupId}
  619. AND spo.status_ != 'FAILED'
  620. AND cgsm.status_ != 'QUIT'
  621. AND spo.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  622. AND cgsm.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  623. </select>
  624. <select id="countSporadicOrder" resultType="java.lang.Integer">
  625. SELECT COUNT(id_)
  626. FROM student_payment_order spo
  627. WHERE spo.group_type_ = 'SPORADIC'
  628. AND spo.music_group_id_ = #{sporadicId}
  629. </select>
  630. <!-- 查找支付成功和支付中订单 -->
  631. <select id="findOrganPayOrderNum" resultType="int">
  632. SELECT COUNT(*)
  633. FROM student_payment_order
  634. WHERE organ_id_ = #{organId}
  635. AND status_ IN ('SUCCESS', 'ING')
  636. </select>
  637. <!-- 获取每月用户的对应类型订单订单 -->
  638. <select id="getOrderByMonthAndType" resultType="com.ym.mec.biz.dal.dto.OrderByTypeExportDto">
  639. SELECT o.name_ organName, spo.user_id_ studentId,su.username_ studentName,spo.type_ orderType,
  640. spo.actual_amount_ actualAmount,spo.music_group_id_ musicGroupId,spo.group_type_ groupType,spo.create_time_
  641. createTime
  642. FROM student_payment_order spo
  643. LEFT JOIN sys_user su on spo.user_id_ = su.id_
  644. LEFT JOIN organization o ON o.id_ = spo.id_
  645. WHERE spo.status_ = 'SUCCESS'
  646. <if test="organIds != null">
  647. AND FIND_IN_SET (spo.organ_id_,#{organIds})
  648. </if>
  649. <if test="orderTypeList != null">
  650. AND spo.type_ IN
  651. <foreach collection="orderTypeList" item="orderType" open="(" close=")"
  652. separator=",">
  653. #{orderType}
  654. </foreach>
  655. </if>
  656. <if test="startTime != null">
  657. AND spo.create_time_ >= #{startTime}
  658. </if>
  659. <if test="endTime != null"><![CDATA[
  660. AND spo.create_time_ <= #{endTime}
  661. ]]></if>
  662. AND spo.actual_amount_ > 0
  663. </select>
  664. <select id="getUsers" resultType="com.ym.mec.biz.dal.dto.BasicUserDto">
  665. SELECT username_ name ,id_ userId,phone_ phone FROM sys_user
  666. WHERE id_ = #{search} OR username_ LIKE CONCAT('%',#{search},'%') OR phone_ LIKE CONCAT('%',#{search},'%')
  667. </select>
  668. <select id="lockOrder" resultMap="StudentPaymentOrder">
  669. SELECT * FROM student_payment_order WHERE id_ = #{id} FOR UPDATE
  670. </select>
  671. </mapper>