StudentPaymentOrderMapper.xml 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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. <result column="receive_status_" property="receiveStatus"/>
  36. </resultMap>
  37. <resultMap type="com.ym.mec.biz.dal.entity.StudentPaymentOrder" extends="StudentPaymentOrder"
  38. id="PaymentOrderAndStudentInfo">
  39. <result column="username_" property="user.username"/>
  40. <result column="phone_" property="user.phone"/>
  41. </resultMap>
  42. <resultMap type="com.ym.mec.biz.dal.entity.Goods" id="Goods">
  43. <result column="id_" property="id"/>
  44. <result column="goods_category_id_" property="goodsCategoryId"/>
  45. <result column="sn_" property="sn"/>
  46. <result column="name_" property="name"/>
  47. <result column="brand_" property="brand"/>
  48. <result column="specification_" property="specification"/>
  49. <result column="image_" property="image"/>
  50. <result column="stock_count_" property="stockCount"/>
  51. <result column="sell_count_" property="sellCount"/>
  52. <result column="market_price_" property="marketPrice"/>
  53. <result column="discount_price_" property="discountPrice"/>
  54. <result column="group_purchase_price_" property="groupPurchasePrice"/>
  55. <result column="brief_" property="brief"/>
  56. <result column="desc_" property="desc"/>
  57. <result column="is_new_" property="isNew" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  58. <result column="is_top_" property="isTop" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  59. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  60. <result column="memo_" property="memo"/>
  61. <result column="publish_time_" property="publishTime"/>
  62. <result column="create_time_" property="createTime"/>
  63. <result column="update_time_" property="updateTime"/>
  64. <result column="complement_goods_id_list_" property="complementGoodsIdList"/>
  65. </resultMap>
  66. <resultMap id="StudentVipDouble11Dto" type="com.ym.mec.biz.dal.dto.StudentVipDouble11Dto">
  67. <result column="payment_one_to_one_time_" property="paymentOneToOneTime"/>
  68. <result column="payment_one_to_two_time_" property="paymentOneToTwoTime"/>
  69. <result column="course_one_to_one_time_" property="courseOneToOneTime"/>
  70. <result column="course_one_to_two_time_" property="courseOneToTwoTime"/>
  71. </resultMap>
  72. <!-- 根据主键查询一条记录 -->
  73. <select id="get" resultMap="StudentPaymentOrder">
  74. SELECT *
  75. FROM student_payment_order
  76. WHERE id_ = #{id}
  77. </select>
  78. <!-- 全查询 -->
  79. <select id="findAll" resultMap="StudentPaymentOrder">
  80. SELECT *
  81. FROM student_payment_order
  82. ORDER BY id_
  83. </select>
  84. <!-- 向数据库增加一条记录 -->
  85. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder" useGeneratedKeys="true"
  86. keyColumn="id" keyProperty="id">
  87. INSERT INTO student_payment_order
  88. (id_, group_type_, user_id_, organ_id_, routing_organ_id_, type_, expect_amount_, actual_amount_, com_amount_,
  89. per_amount_,
  90. balance_payment_amount_, remit_fee_, course_remit_fee_, trans_no_,
  91. status_, memo_, create_time_, update_time_, payment_channel_, payment_business_channel_,
  92. payment_account_no_, mer_nos_, order_no_, music_group_id_, class_group_id_, pay_time_)
  93. VALUES (#{id}, #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  94. #{userId}, #{organId}, #{routingOrganId},
  95. #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  96. #{expectAmount}, #{actualAmount}, #{comAmount}, #{perAmount}, #{balancePaymentAmount},
  97. #{remitFee}, #{courseRemitFee}, #{transNo},
  98. #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, #{memo}, now(), now(),
  99. #{paymentChannel}, #{paymentBusinessChannel}, #{paymentAccountNo}, #{merNos}, #{orderNo},
  100. #{musicGroupId},
  101. #{classGroupId}, #{payTime})
  102. </insert>
  103. <!-- 根据主键查询一条记录 -->
  104. <update id="update" parameterType="com.ym.mec.biz.dal.entity.StudentPaymentOrder">
  105. UPDATE student_payment_order
  106. <set>
  107. <if test="receiveStatus != null and receiveStatus != ''">
  108. receive_status_ = #{receiveStatus},
  109. </if>
  110. <if test="status != null">
  111. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  112. </if>
  113. <if test="groupType != null">
  114. group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  115. </if>
  116. <if test="orderNo != null">
  117. order_no_ = #{orderNo},
  118. </if>
  119. <if test="classGroupId != null">
  120. class_group_id_ = #{classGroupId},
  121. </if>
  122. <if test="expectAmount != null">
  123. expect_amount_ = #{expectAmount},
  124. </if>
  125. <if test="memo != null">
  126. memo_ = #{memo},
  127. </if>
  128. <if test="paymentChannel != null">
  129. payment_channel_ = #{paymentChannel},
  130. </if>
  131. <if test="userId != null">
  132. user_id_ = #{userId},
  133. </if>
  134. <if test="paymentAccountNo != null">
  135. payment_account_no_ = #{paymentAccountNo},
  136. </if>
  137. <if test="merNos != null">
  138. mer_nos_ = #{merNos},
  139. </if>
  140. <if test="paymentBusinessChannel != null">
  141. payment_business_channel_ = #{paymentBusinessChannel},
  142. </if>
  143. <if test="transNo != null">
  144. trans_no_ = #{transNo},
  145. </if>
  146. <if test="actualAmount != null">
  147. actual_amount_ = #{actualAmount},
  148. </if>
  149. <if test="comAmount != null">
  150. com_amount_ = #{comAmount},
  151. </if>
  152. <if test="perAmount != null">
  153. per_amount_ = #{perAmount},
  154. </if>
  155. <if test="balancePaymentAmount != null">
  156. balance_payment_amount_ = #{balancePaymentAmount},
  157. </if>
  158. <if test="remitFee != null">
  159. remit_fee_ = #{remitFee},
  160. </if>
  161. <if test="courseRemitFee != null">
  162. course_remit_fee_ = #{courseRemitFee},
  163. </if>
  164. <if test="type != null">
  165. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  166. </if>
  167. <if test="musicGroupId != null">
  168. music_group_id_ = #{musicGroupId},
  169. </if>
  170. <if test="organId != null">
  171. organ_id_ = #{organId},
  172. </if>
  173. <if test="routingOrganId != null">
  174. routing_organ_id_ = #{routingOrganId},
  175. </if>
  176. <if test="payTime != null">
  177. pay_time_ = #{payTime},
  178. </if>
  179. <if test="version != null">
  180. version_ = version_+1,
  181. </if>
  182. update_time_ = NOW()
  183. </set>
  184. WHERE id_ = #{id} AND version_ = #{version}
  185. </update>
  186. <!-- 根据主键删除一条记录 -->
  187. <delete id="delete">
  188. DELETE
  189. FROM student_payment_order
  190. WHERE id_ = #{id}
  191. </delete>
  192. <!-- 分页查询 -->
  193. <select id="queryPage" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  194. SELECT spo.*,u.username_,u.phone_ FROM student_payment_order spo
  195. left join sys_user u on spo.user_id_ = u.id_
  196. <include refid="queryPaymentOrder"/>
  197. ORDER BY spo.id_ DESC
  198. <include refid="global.limit"/>
  199. </select>
  200. <!-- 查询当前表的总记录数 -->
  201. <select id="queryCount" resultType="int" parameterType="map">
  202. SELECT COUNT(spo.id_) FROM student_payment_order spo
  203. left join sys_user u on spo.user_id_ = u.id_
  204. <include refid="queryPaymentOrder"/>
  205. </select>
  206. <sql id="queryPaymentOrder">
  207. <where>
  208. <if test="userIds != null">
  209. AND spo.user_id_ IN
  210. <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
  211. #{userId}
  212. </foreach>
  213. </if>
  214. <if test="organId != null">
  215. AND FIND_IN_SET(spo.organ_id_,#{organId})
  216. </if>
  217. <if test="orderStartDate != null">
  218. AND DATE_FORMAT(spo.create_time_,'%Y-%m-%d') &gt;= #{orderStartDate}
  219. </if>
  220. <if test="orderEndDate != null">
  221. AND DATE_FORMAT(spo.create_time_,'%Y-%m-%d') &lt;= #{orderEndDate}
  222. </if>
  223. <if test="paymentType != null">
  224. AND spo.type_ = #{paymentType}
  225. </if>
  226. <if test="remark != null">
  227. AND spo.memo_ LIKE CONCAT('%',#{remark},'%')
  228. </if>
  229. <if test="studentId != null">
  230. AND spo.user_id_ = #{studentId}
  231. </if>
  232. <if test="paymentStatus != null">
  233. AND spo.status_ = #{paymentStatus}
  234. </if>
  235. <if test="paymentChannel != null">
  236. AND spo.payment_channel_ NOT IN (#{paymentChannel})
  237. </if>
  238. <if test='orderType != null and orderType.toString()=="1".toString()'>
  239. AND spo.com_amount_ > 0
  240. </if>
  241. <if test='orderType != null and orderType.toString()=="2".toString()'>
  242. AND spo.per_amount_ > 0
  243. </if>
  244. <if test="routingOrganId != null">
  245. AND FIND_IN_SET(spo.routing_organ_id_,#{routingOrganId})
  246. </if>
  247. <if test="actualAmount != null">
  248. AND spo.actual_amount_ >= #{actualAmount}
  249. </if>
  250. <if test="balancePaymentAmount != null">
  251. AND spo.balance_payment_amount_ >= #{balancePaymentAmount}
  252. </if>
  253. <if test="lessActualAmount != null">
  254. <![CDATA[ AND spo.actual_amount_ <= #{lessActualAmount}]]>
  255. </if>
  256. <if test="lessBalancePaymentAmount != null">
  257. <![CDATA[AND spo.balance_payment_amount_ <= #{lessBalancePaymentAmount}]]>
  258. </if>
  259. <if test="orderNo != null">
  260. AND spo.order_no_ = #{orderNo}
  261. </if>
  262. <if test="merNos != null">
  263. AND FIND_IN_SET(#{merNos},spo.mer_nos_)
  264. </if>
  265. <if test="transNo != null">
  266. AND spo.trans_no_ = #{transNo}
  267. </if>
  268. <if test="chargeType != null">
  269. AND spo.group_type_='SPORADIC'
  270. AND sci.charge_type_ = #{chargeType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  271. </if>
  272. </where>
  273. </sql>
  274. <select id="queryApplyGoodsList" resultMap="Goods" parameterType="map">
  275. select g.*
  276. from goods g
  277. where g.id_ in (SELECT spod.goods_id_list_
  278. FROM student_payment_order spo
  279. left join
  280. student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  281. where spo.music_group_id_ =
  282. #{musicGroupId}
  283. and spo.type_ = 'APPLY'
  284. and spod.type_ =
  285. #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler})
  286. </select>
  287. <select id="queryByCondition" resultMap="StudentPaymentOrder" parameterType="map">
  288. SELECT spo.*
  289. FROM student_payment_order spo
  290. WHERE spo.user_id_ = #{userId}
  291. AND spo.music_group_id_ = #{musicGroupId}
  292. AND spo.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  293. AND spo.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  294. and spo.type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  295. </select>
  296. <select id="findByStudentVipGroup" resultMap="StudentPaymentOrder">
  297. SELECT
  298. spo.*
  299. FROM
  300. student_payment_order spo
  301. WHERE spo.user_id_=#{userId}
  302. AND spo.music_group_id_=#{vipGroupId}
  303. <if test="status!=null and status!=''">
  304. AND spo.status_=#{status}
  305. </if>
  306. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  307. </select>
  308. <select id="sumSurplusCourseFee" resultType="java.math.BigDecimal">
  309. SELECT SUM(cssp.expect_price_)
  310. FROM course_schedule_student_payment cssp
  311. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  312. WHERE cssp.user_id_ = #{userId}
  313. AND cssp.music_group_id_ = #{vipGroupId}
  314. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
  315. </select>
  316. <select id="findNotFailedOrderByStudentVipGroup" resultMap="StudentPaymentOrder">
  317. SELECT spo.*
  318. FROM student_payment_order spo
  319. WHERE spo.user_id_ = #{userId}
  320. AND spo.music_group_id_ = #{vipGroupId}
  321. AND spo.status_ != 'FAILED'
  322. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  323. </select>
  324. <!-- 查询报名订单 -->
  325. <select id="findMusicGroupApplyOrderByStatus" resultMap="StudentPaymentOrder">
  326. SELECT *
  327. FROM student_payment_order
  328. WHERE music_group_id_ = #{musicGroupId}
  329. AND user_id_ = #{userId}
  330. AND type_ = 'APPLY'
  331. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  332. ORDER BY id_ DESC
  333. LIMIT 1
  334. </select>
  335. <!-- 根据订单号查询订单 -->
  336. <select id="findOrderByOrderNo" resultMap="StudentPaymentOrder">
  337. SELECT *
  338. FROM student_payment_order
  339. WHERE order_no_ = #{orderNo}
  340. </select>
  341. <select id="queryByDealStatus" resultMap="StudentPaymentOrder" parameterType="map">
  342. SELECT *
  343. FROM student_payment_order
  344. WHERE music_group_id_ = #{musicGroupId}
  345. AND type_ =
  346. #{type}
  347. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  348. </select>
  349. <!-- 查找支付成功和支付中订单 -->
  350. <select id="findPayOrderNum" resultType="int">
  351. <![CDATA[
  352. SELECT COUNT(*)
  353. FROM student_payment_order
  354. WHERE FIND_IN_SET(status_, 'SUCCESS,ING,WAIT_PAY')
  355. ]]>
  356. </select>
  357. <resultMap type="com.ym.mec.biz.dal.dto.UserGoodsDto" id="userGoodsDto">
  358. <result column="goods_id_" property="goodsId"/>
  359. <collection property="goodsName" ofType="string">
  360. <result column="goods_name_"/>
  361. </collection>
  362. </resultMap>
  363. <select id="findGoodsIds" resultMap="userGoodsDto">
  364. SELECT g.id_ goods_id_, g.name_ goods_name_
  365. FROM student_payment_order spo
  366. LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
  367. LEFT JOIN goods g ON FIND_IN_SET(g.id_, spod.goods_id_list_)
  368. WHERE spo.type_ = 'APPLY'
  369. AND spo.status_ = 'SUCCESS'
  370. AND spod.goods_id_list_ IS NOT NULL
  371. AND spo.music_group_id_ = #{musicGroupId}
  372. AND spo.user_id_ = #{userId}
  373. </select>
  374. <select id="getUserGoods" resultMap="userGoodsDto">
  375. SELECT id_ goods_id_, name_ goods_name_ FROM goods WHERE FIND_IN_SET(id_,#{ids})
  376. </select>
  377. <select id="findOrdersByStatus" resultMap="StudentPaymentOrder">
  378. SELECT *
  379. FROM student_payment_order
  380. WHERE status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  381. AND payment_channel_ = #{paymentChannel}
  382. LIMIT 100
  383. </select>
  384. <!-- 查询支付中超时订单 -->
  385. <select id="findOrdersOverTime" resultMap="StudentPaymentOrder">
  386. SELECT * FROM student_payment_order WHERE order_no_ IN
  387. <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
  388. #{orderNo}
  389. </foreach>
  390. AND status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  391. <![CDATA[ AND create_time_ <= ]]> #{beforeTime}
  392. </select>
  393. <select id="countStudentPaymentNum" resultType="int">
  394. select count(1)
  395. from student_payment_order
  396. where music_group_id_ = #{musicGroupId}
  397. AND status_ = 'SUCCESS'
  398. AND type_ = 'SMALL_CLASS_TO_BUY'
  399. </select>
  400. <select id="countSurplusCourseByMusicGroupAndUser" resultType="int">
  401. SELECT COUNT(*)
  402. FROM course_schedule_student_payment cssp
  403. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  404. WHERE cssp.user_id_ = #{userId}
  405. AND cssp.music_group_id_ = #{musicGroupId}
  406. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
  407. </select>
  408. <select id="sumGroupIncomeFee" resultType="java.math.BigDecimal">
  409. SELECT SUM(expect_amount_)
  410. FROM student_payment_order
  411. WHERE group_type_ = #{groupType}
  412. AND music_group_id_ = #{musicGroupId}
  413. AND status_ = 'SUCCESS'
  414. </select>
  415. <select id="findStudentPaymentOrder" resultMap="StudentPaymentOrder">
  416. SELECT *
  417. FROM student_payment_order
  418. WHERE id_ IN (SELECT MAX(sp.id_)
  419. FROM (SELECT *
  420. FROM student_payment_order
  421. WHERE group_type_ = #{groupType}
  422. AND type_ = 'APPLY'
  423. AND music_group_id_ = #{musicGroupId}
  424. AND status_ = 'SUCCESS'
  425. ORDER BY id_ DESC) sp
  426. GROUP BY sp.user_id_)
  427. </select>
  428. <select id="findOrderByGroupType" resultType="int">
  429. SELECT COUNT(id_) FROM student_payment_order
  430. WHERE group_type_ = #{groupType}
  431. AND user_id_ = #{userId}
  432. AND music_group_id_ = #{sporadicId}
  433. <if test="status != null">
  434. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  435. </if>
  436. </select>
  437. <select id="findPaymentOrderByGroupType" resultMap="StudentPaymentOrder">
  438. SELECT * FROM student_payment_order
  439. WHERE group_type_ = #{groupType}
  440. AND user_id_ = #{userId}
  441. AND music_group_id_ = #{sporadicId}
  442. <if test="status != null">
  443. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  444. </if>
  445. </select>
  446. <select id="queryExpectAmount" resultType="java.util.Map">
  447. SELECT spo.expect_amount_ 'value',spo.id_ 'key'
  448. FROM student_payment_order spo
  449. WHERE spo.id_ IN
  450. <foreach collection="paymentOrderNo" open="(" close=")" separator="," item="item">
  451. #{item}
  452. </foreach>
  453. </select>
  454. <select id="findFixOrder" resultMap="StudentPaymentOrder">
  455. SELECT *
  456. FROM student_payment_order
  457. where status_ = 'SUCCESS'
  458. AND type_ = 'APPLY'
  459. AND actual_amount_ > 0
  460. and mer_nos_ IS NULL
  461. LIMIT 100
  462. </select>
  463. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto" id="orderAndDetail"
  464. extends="StudentPaymentOrder">
  465. <result column="organ_name" property="organName"/>
  466. <result column="username_" property="user.username"/>
  467. <result column="charge_type_" property="chargeType"/>
  468. <result column="routeMerNo" property="routeMerNo"/>
  469. <result column="routeAmount" property="routeAmount"/>
  470. <result column="routeBalance" property="routeBalance"/>
  471. <result column="feeFlag" property="feeFlag"/>
  472. <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
  473. <result column="detail_id_" property="id"/>
  474. <result column="detail_type_" property="type"/>
  475. <result column="detail_price_" property="price"/>
  476. <result column="detail_kit_group_purchase_type_" property="kitGroupPurchaseType"/>
  477. </collection>
  478. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  479. <result column="goods_id" property="id"/>
  480. <result column="goods_name" property="name"/>
  481. </collection>
  482. </resultMap>
  483. <!-- 分页查询 -->
  484. <select id="ExportQueryPage" resultMap="orderAndDetail" parameterType="map">
  485. SELECT spo.*,u.username_,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  486. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  487. sci.charge_type_,g.id_ goods_id, g.name_ goods_name,o.name_ organ_name
  488. FROM student_payment_order spo
  489. LEFT JOIN sys_user u on spo.user_id_ = u.id_
  490. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  491. <if test='orderType != null and orderType.toString()=="0".toString()'>
  492. LEFT JOIN organization o on spo.organ_id_ = o.id_
  493. </if>
  494. <if test='orderType != null and orderType.toString()=="1".toString()'>
  495. LEFT JOIN organization o on spo.organ_id_ = o.id_
  496. </if>
  497. <if test='orderType != null and orderType.toString()=="2".toString()'>
  498. LEFT JOIN organization o on spo.organ_id_ = o.id_
  499. </if>
  500. <if test='orderType != null and orderType.toString()=="3".toString()'>
  501. LEFT JOIN organization o on spo.routing_organ_id_ = o.id_
  502. </if>
  503. LEFT JOIN sporadic_charge_info sci on spo.music_group_id_ = sci.id_
  504. LEFT JOIN goods g on FIND_IN_SET(g.id_,spod.goods_id_list_)
  505. <include refid="queryPaymentOrder"/>
  506. ORDER BY spo.id_ ASC
  507. </select>
  508. <resultMap id="SporadicChargeInfoDtoMap" type="com.ym.mec.biz.dal.dto.SporadicChargeInfoDto">
  509. <result property="organName" column="organ_name_"/>
  510. <result property="title" column="title_"/>
  511. <result property="type" column="type_"/>
  512. <result property="amount" column="amount_"/>
  513. <result property="createTime" column="create_time_"/>
  514. <result property="payTime" column="pay_time_"/>
  515. <result property="username" column="username_"/>
  516. <result property="payStatus" column="pay_status_"/>
  517. </resultMap>
  518. <select id="sporadicQueryPage" resultMap="SporadicChargeInfoDtoMap">
  519. SELECT o.name_ organ_name_,sci.title_,sci.charge_type_ type_,
  520. spo.actual_amount_ amount_,spo.create_time_,spo.pay_time_,su.username_,spo.status_ pay_status_
  521. FROM student_payment_order spo
  522. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  523. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  524. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  525. WHERE spo.type_ = 'SPORADIC'
  526. <include refid="sporadicQueryPageSql"/>
  527. ORDER BY spo.id_ DESC
  528. <include refid="global.limit"/>
  529. </select>
  530. <select id="countSporadicPage" resultType="java.lang.Integer">
  531. SELECT COUNT(spo.id_)
  532. FROM student_payment_order spo
  533. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  534. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  535. WHERE spo.type_ = 'SPORADIC'
  536. <include refid="sporadicQueryPageSql"/>
  537. </select>
  538. <sql id="sporadicQueryPageSql">
  539. <if test="organId != null">
  540. AND FIND_IN_SET(spo.organ_id_,#{organId})
  541. </if>
  542. <if test="search != null">
  543. AND (sci.title_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%'))
  544. </if>
  545. <if test="chargeType != null">
  546. AND sci.charge_type_ = #{chargeType}
  547. </if>
  548. <if test="payStatus != null">
  549. AND spo.status_ = #{payStatus}
  550. </if>
  551. </sql>
  552. <resultMap id="luckStatis" type="com.ym.mec.biz.dal.dto.OrderStatisDto">
  553. <result property="organId" column="organId"/>
  554. <result property="organName" column="organName"/>
  555. <result property="estimatedNums" column="estimatedNums"/>
  556. <result property="nums" column="nums"/>
  557. <result property="times" column="times"/>
  558. <result property="scale" column="scale"/>
  559. <result property="money" column="money"/>
  560. </resultMap>
  561. <select id="getLuckStatis" resultMap="luckStatis">
  562. SELECT o.name_ organName, SUM(spo.actual_amount_) money, COUNT(spo.id_) nums
  563. FROM student_payment_order spo
  564. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  565. WHERE spo.type_ = 'LUCK'
  566. AND spo.status_ = 'SUCCESS'
  567. GROUP BY spo.organ_id_
  568. ORDER BY nums DESC;
  569. </select>
  570. <select id="queryIncomeStatisticsWithCurrentMonth" resultType="map">
  571. select count(*) total,sum(actual_amount_) total_num_ from student_payment_order
  572. where actual_amount_ &gt; 0 and DATE_FORMAT(create_time_, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' ) AND
  573. status_ = 'SUCCESS' and organ_id_ not in (36,38)
  574. <if test="organId != null">
  575. and FIND_IN_SET(organ_id_,#{organId})
  576. </if>
  577. </select>
  578. <select id="countUserBuyVipGroupSuccessOrder" resultType="int">
  579. select count(*)
  580. from student_payment_order
  581. where user_id_ = #{userId}
  582. and music_group_id_ = #{vipGroupId}
  583. and group_type_ = 'VIP'
  584. and status_ = 'SUCCESS'
  585. </select>
  586. <select id="findUserBuyVipGroupOrder" resultMap="StudentPaymentOrder">
  587. select *
  588. from student_payment_order
  589. where user_id_ = #{userId}
  590. and music_group_id_ = #{vipGroupId}
  591. and group_type_ = 'VIP'
  592. </select>
  593. <select id="findUserGroupOrders" resultMap="StudentPaymentOrder">
  594. select * from student_payment_order
  595. where user_id_=#{userId}
  596. and music_group_id_=#{groupId}
  597. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  598. <if test="status!=null">
  599. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  600. </if>
  601. </select>
  602. <select id="getOrderMoneyAmount" parameterType="map" resultMap="StudentPaymentOrder">
  603. SELECT SUM(spo.expect_amount_) expect_amount_,SUM(actual_amount_) actual_amount_,SUM(balance_payment_amount_)
  604. balance_payment_amount_ FROM student_payment_order spo
  605. <include refid="queryPaymentOrder"/>
  606. </select>
  607. <!-- 分页查询 -->
  608. <select id="queryPageOrder" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  609. SELECT spo.*,u.username_,u.phone_ FROM student_payment_order spo
  610. left join sys_user u on spo.user_id_ = u.id_
  611. <include refid="queryPaymentOrder"/>
  612. ORDER BY spo.id_ DESC
  613. <include refid="global.limit"/>
  614. </select>
  615. <select id="findOrderByGroup" resultMap="StudentPaymentOrder">
  616. SELECT * FROM student_payment_order
  617. WHERE music_group_id_=#{groupId}
  618. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  619. <if test="status!=null">
  620. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  621. </if>
  622. </select>
  623. <select id="sumPerAccountAmount" resultType="java.math.BigDecimal"><![CDATA[
  624. SELECT SUM(per_amount_)
  625. FROM student_payment_order
  626. WHERE FIND_IN_SET(status_, 'SUCCESS,ING')
  627. AND create_time_ >= #{firstDate}
  628. AND create_time_ <= NOW()
  629. AND FIND_IN_SET(#{merNo}, mer_nos_)
  630. ]]>
  631. </select>
  632. <select id="getChargeAmount" parameterType="map" resultType="java.math.BigDecimal">
  633. SELECT SUM(actual_amount_) FROM student_payment_order spo
  634. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_ = sci.id_
  635. <include refid="queryPaymentOrder"/>
  636. </select>
  637. <select id="sumAccountAmount" resultType="java.math.BigDecimal">
  638. <![CDATA[
  639. SELECT SUM(actual_amount_)
  640. FROM student_payment_order
  641. WHERE status_ IN ('SUCCESS', 'ING')
  642. AND create_time_ >= #{firstDate}
  643. AND create_time_ <= NOW()
  644. AND mer_nos_ = #{merNo}
  645. ]]></select>
  646. <select id="countGroupOrderWithoutFailed" resultType="int">
  647. SELECT COUNT(*)
  648. FROM student_payment_order spo
  649. LEFT JOIN class_group_student_mapper cgsm
  650. ON spo.music_group_id_ = cgsm.music_group_id_ AND spo.user_id_ = cgsm.user_id_
  651. WHERE spo.music_group_id_ = #{groupId}
  652. AND spo.status_ != 'FAILED'
  653. AND cgsm.status_ != 'QUIT'
  654. AND spo.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  655. AND cgsm.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  656. </select>
  657. <select id="countSporadicOrder" resultType="java.lang.Integer">
  658. SELECT COUNT(id_)
  659. FROM student_payment_order spo
  660. WHERE spo.group_type_ = 'SPORADIC'
  661. AND spo.music_group_id_ = #{sporadicId}
  662. </select>
  663. <!-- 查找支付成功和支付中订单 -->
  664. <select id="findOrganPayOrderNum" resultType="int">
  665. SELECT COUNT(*)
  666. FROM student_payment_order
  667. WHERE organ_id_ = #{organId}
  668. AND status_ IN ('SUCCESS', 'ING')
  669. </select>
  670. <!-- 获取每月用户的对应类型订单订单 -->
  671. <select id="getOrderByMonthAndType" resultType="com.ym.mec.biz.dal.dto.OrderByTypeExportDto">
  672. SELECT o.name_ organName, spo.user_id_ studentId,su.username_ studentName,spo.type_ orderType,
  673. spo.actual_amount_ actualAmount,spo.music_group_id_ musicGroupId,spo.group_type_ groupType,spo.create_time_
  674. createTime
  675. FROM student_payment_order spo
  676. LEFT JOIN sys_user su on spo.user_id_ = su.id_
  677. LEFT JOIN organization o ON o.id_ = spo.id_
  678. WHERE spo.status_ = 'SUCCESS'
  679. <if test="organIds != null">
  680. AND FIND_IN_SET (spo.organ_id_,#{organIds})
  681. </if>
  682. <if test="orderTypeList != null">
  683. AND spo.type_ IN
  684. <foreach collection="orderTypeList" item="orderType" open="(" close=")"
  685. separator=",">
  686. #{orderType}
  687. </foreach>
  688. </if>
  689. <if test="startTime != null">
  690. AND spo.create_time_ >= #{startTime}
  691. </if>
  692. <if test="endTime != null"><![CDATA[
  693. AND spo.create_time_ <= #{endTime}
  694. ]]></if>
  695. AND spo.actual_amount_ > 0
  696. </select>
  697. <select id="getUsers" resultType="com.ym.mec.biz.dal.dto.BasicUserDto">
  698. SELECT username_ name, id_ userId, phone_ phone
  699. FROM sys_user
  700. WHERE id_ = #{search}
  701. OR username_ LIKE CONCAT('%', #{search}, '%')
  702. OR phone_ LIKE CONCAT('%', #{search}, '%')
  703. </select>
  704. <select id="lockOrder" resultMap="StudentPaymentOrder">
  705. SELECT *
  706. FROM student_payment_order
  707. WHERE id_ = #{id} FOR
  708. UPDATE
  709. </select>
  710. <select id="doubleEleven2020Statis" resultMap="luckStatis">
  711. SELECT o.id_ organId, o.name_ organName, SUM(spo.actual_amount_) money, COUNT(DISTINCT spo.user_id_) nums,
  712. SUM(IF(spo.class_group_id_ is null ,1,spo.class_group_id_)) times FROM student_payment_order spo
  713. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  714. WHERE spo.type_ = 'DOUBLE_ELEVEN2020'
  715. AND spo.status_ = 'SUCCESS'
  716. AND spo.organ_id_ IN
  717. <foreach collection="organs" item="organ" open="(" close=")" separator=",">
  718. #{organ.id}
  719. </foreach>
  720. GROUP BY spo.organ_id_
  721. </select>
  722. <select id="getUserOrderNumByType" resultType="int">
  723. SELECT COUNT(*)
  724. FROM student_payment_order
  725. WHERE user_id_ = #{userId}
  726. AND status_ = 'SUCCESS'
  727. AND type_ = #{orderType}
  728. </select>
  729. <select id="getUserOrderByType" resultMap="StudentPaymentOrder">
  730. SELECT * FROM student_payment_order WHERE user_id_=#{userId} AND type_=#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler} AND status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  731. </select>
  732. <select id="queryDouble11Students" resultMap="StudentVipDouble11Dto">
  733. SELECT
  734. su.id_ userId,
  735. su.username_ userName,
  736. su.phone_ phone,
  737. su.avatar_ avatar,
  738. SUM(CASE WHEN sci.title_ LIKE '%1V1%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_one_time_,
  739. SUM(CASE WHEN sci.title_ LIKE '%1V2%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_two_time_
  740. FROM
  741. student_payment_order spo
  742. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  743. LEFT JOIN student s ON spo.user_id_=s.user_id_
  744. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  745. WHERE
  746. spo.status_ = 'SUCCESS'
  747. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  748. AND sci.title_ LIKE '双十一%'
  749. AND s.teacher_id_= #{teacherId}
  750. <if test="search!=null and search!=''">
  751. AND (su.phone_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
  752. </if>
  753. GROUP BY
  754. spo.user_id_
  755. ORDER BY spo.user_id_
  756. <include refid="global.limit" />
  757. </select>
  758. <select id="countDouble11Students" resultType="int">
  759. SELECT
  760. COUNT(DISTINCT spo.user_id_)
  761. FROM
  762. student_payment_order spo
  763. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  764. LEFT JOIN student s ON spo.user_id_=s.user_id_
  765. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  766. WHERE
  767. spo.status_ = 'SUCCESS'
  768. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  769. AND sci.title_ LIKE '双十一%'
  770. AND s.teacher_id_= #{teacherId}
  771. <if test="search!=null and search!=''">
  772. AND (su.phone_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
  773. </if>;
  774. </select>
  775. <select id="findStudentsDouble11Infos" resultMap="StudentVipDouble11Dto">
  776. SELECT
  777. su.id_ userId,
  778. su.username_ userName,
  779. su.phone_ phone,
  780. su.avatar_ avatar,
  781. SUM(CASE WHEN sci.title_ LIKE '%1V1%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_one_time_,
  782. SUM(CASE WHEN sci.title_ LIKE '%1V2%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_two_time_
  783. FROM
  784. student_payment_order spo
  785. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  786. LEFT JOIN student s ON spo.user_id_=s.user_id_
  787. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  788. WHERE
  789. spo.status_ = 'SUCCESS'
  790. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  791. AND sci.title_ LIKE '双十一%'
  792. AND spo.user_id_ IN
  793. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  794. #{studentId}
  795. </foreach>
  796. GROUP BY
  797. spo.user_id_
  798. </select>
  799. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto" id="applyOrderAndDetail"
  800. extends="StudentPaymentOrder">
  801. <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
  802. <result column="detail_id_" property="id"/>
  803. <result column="detail_type_" property="type"/>
  804. <result column="detail_price_" property="price"/>
  805. <result column="detail_kit_group_purchase_type_" property="kitGroupPurchaseType"/>
  806. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  807. <result column="goods_id" property="id"/>
  808. <result column="goods_name" property="name"/>
  809. </collection>
  810. </collection>
  811. </resultMap>
  812. <select id="getUserApplyOrders" resultMap="applyOrderAndDetail" parameterType="map">
  813. SELECT spo.*,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  814. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  815. g.id_ goods_id, g.name_ goods_name
  816. FROM student_payment_order spo
  817. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  818. LEFT JOIN goods g on FIND_IN_SET(g.id_,spod.goods_id_list_)
  819. WHERE spo.user_id_ = #{userId} AND spo.type_='APPLY' AND spo.music_group_id_=#{musicGroupId}
  820. ORDER BY spo.id_ desc
  821. </select>
  822. <select id="getAdaPayOrdersByTime" resultMap="StudentPaymentOrder"><![CDATA[
  823. SELECT * FROM student_payment_order WHERE pay_time_ >= #{startTime} AND pay_time_ <= #{endTime} AND payment_channel_='ADAPAY' AND status_ ='SUCCESS']]>
  824. </select>
  825. </mapper>