StudentPaymentOrderMapper.xml 51 KB

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