StudentPaymentOrderMapper.xml 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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. <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
  567. <result column="detail_id_" property="id"/>
  568. <result column="detail_type_" property="type"/>
  569. <result column="detail_price_" property="price"/>
  570. <result column="detail_kit_group_purchase_type_" property="kitGroupPurchaseType"/>
  571. </collection>
  572. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  573. <result column="goods_id" property="id"/>
  574. <result column="goods_name" property="name"/>
  575. </collection>
  576. </resultMap>
  577. <!-- 分页查询 -->
  578. <select id="ExportQueryPage" resultMap="orderAndDetail" parameterType="map">
  579. SELECT spo.*,u.username_,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  580. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  581. sci.charge_type_,g.id_ goods_id, g.name_ goods_name,o.name_ organ_name
  582. FROM student_payment_order spo
  583. LEFT JOIN sys_user u on spo.user_id_ = u.id_
  584. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  585. <if test='orderType != null and orderType.toString()=="0".toString()'>
  586. LEFT JOIN organization o on spo.organ_id_ = o.id_
  587. </if>
  588. <if test='orderType != null and orderType.toString()=="1".toString()'>
  589. LEFT JOIN organization o on spo.organ_id_ = o.id_
  590. </if>
  591. <if test='orderType != null and orderType.toString()=="2".toString()'>
  592. LEFT JOIN organization o on spo.organ_id_ = o.id_
  593. </if>
  594. <if test='orderType != null and orderType.toString()=="3".toString()'>
  595. LEFT JOIN organization o on spo.routing_organ_id_ = o.id_
  596. </if>
  597. LEFT JOIN sporadic_charge_info sci on spo.music_group_id_ = sci.id_
  598. LEFT JOIN goods g on FIND_IN_SET(g.id_,spod.goods_id_list_)
  599. <include refid="queryPaymentOrder"/>
  600. ORDER BY spo.id_ ASC
  601. </select>
  602. <resultMap id="SporadicChargeInfoDtoMap" type="com.ym.mec.biz.dal.dto.SporadicChargeInfoDto">
  603. <result property="organName" column="organ_name_"/>
  604. <result property="title" column="title_"/>
  605. <result property="type" column="type_"/>
  606. <result property="amount" column="amount_"/>
  607. <result property="createTime" column="create_time_"/>
  608. <result property="payTime" column="pay_time_"/>
  609. <result property="username" column="username_"/>
  610. <result property="payStatus" column="pay_status_"/>
  611. </resultMap>
  612. <select id="sporadicQueryPage" resultMap="SporadicChargeInfoDtoMap">
  613. SELECT o.name_ organ_name_,sci.title_,sci.charge_type_ type_,
  614. spo.actual_amount_ amount_,spo.create_time_,spo.pay_time_,su.username_,spo.status_ pay_status_
  615. FROM student_payment_order spo
  616. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  617. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  618. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  619. WHERE spo.type_ = 'SPORADIC' and spo.tenant_id_ = #{tenantId}
  620. <include refid="sporadicQueryPageSql"/>
  621. ORDER BY spo.id_ DESC
  622. <include refid="global.limit"/>
  623. </select>
  624. <select id="countSporadicPage" resultType="java.lang.Integer">
  625. SELECT COUNT(spo.id_)
  626. FROM student_payment_order spo
  627. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  628. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  629. WHERE spo.type_ = 'SPORADIC' and spo.tenant_id_ = #{tenantId}
  630. <include refid="sporadicQueryPageSql"/>
  631. </select>
  632. <sql id="sporadicQueryPageSql">
  633. <if test="organId != null">
  634. AND FIND_IN_SET(spo.organ_id_,#{organId})
  635. </if>
  636. <if test="search != null">
  637. AND (sci.title_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%'))
  638. </if>
  639. <if test="chargeType != null">
  640. AND sci.charge_type_ = #{chargeType}
  641. </if>
  642. <if test="payStatus != null">
  643. AND spo.status_ = #{payStatus}
  644. </if>
  645. </sql>
  646. <resultMap id="luckStatis" type="com.ym.mec.biz.dal.dto.OrderStatisDto">
  647. <result property="organId" column="organId"/>
  648. <result property="organName" column="organName"/>
  649. <result property="estimatedNums" column="estimatedNums"/>
  650. <result property="nums" column="nums"/>
  651. <result property="times" column="times"/>
  652. <result property="scale" column="scale"/>
  653. <result property="money" column="money"/>
  654. </resultMap>
  655. <select id="getLuckStatis" resultMap="luckStatis">
  656. SELECT o.name_ organName, SUM(spo.actual_amount_) money, COUNT(spo.id_) nums
  657. FROM student_payment_order spo
  658. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  659. WHERE spo.type_ = 'LUCK'
  660. AND spo.status_ = 'SUCCESS' and spo.tenant_id_ = #{tenantId}
  661. GROUP BY spo.organ_id_
  662. ORDER BY nums DESC;
  663. </select>
  664. <select id="queryIncomeStatisticsWithCurrentMonth" resultType="map">
  665. select count(*) total,sum(actual_amount_) total_num_ from student_payment_order
  666. where actual_amount_ &gt; 0 and DATE_FORMAT(create_time_, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' ) AND
  667. status_ = 'SUCCESS' and organ_id_ not in (36,38)
  668. and FIND_IN_SET(organ_id_,#{organId})
  669. </select>
  670. <select id="countUserBuyVipGroupSuccessOrder" resultType="int">
  671. select count(*)
  672. from student_payment_order
  673. where user_id_ = #{userId}
  674. and music_group_id_ = #{vipGroupId}
  675. and group_type_ = 'VIP'
  676. and status_ = 'SUCCESS'
  677. </select>
  678. <select id="findUserBuyVipGroupOrder" resultMap="StudentPaymentOrder">
  679. select *
  680. from student_payment_order
  681. where user_id_ = #{userId}
  682. and music_group_id_ = #{vipGroupId}
  683. and group_type_ = 'VIP'
  684. </select>
  685. <select id="findUserGroupOrders" resultMap="StudentPaymentOrder">
  686. select * from student_payment_order
  687. where user_id_=#{userId}
  688. and music_group_id_=#{groupId}
  689. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  690. <if test="status!=null">
  691. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  692. </if>
  693. </select>
  694. <select id="getOrderMoneyAmount" parameterType="map" resultMap="StudentPaymentOrder">
  695. SELECT SUM(spo.expect_amount_) expect_amount_,SUM(actual_amount_) actual_amount_,SUM(balance_payment_amount_)
  696. balance_payment_amount_ FROM student_payment_order spo
  697. <include refid="queryPaymentOrder"/>
  698. </select>
  699. <!-- 分页查询 -->
  700. <select id="queryPageOrder" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  701. SELECT spo.*,u.username_,u.phone_,o.name_ organ_name_ FROM student_payment_order spo
  702. left join sys_user u on spo.user_id_ = u.id_
  703. left join organization o on o.id_ = spo.organ_id_
  704. <include refid="queryPaymentOrder"/>
  705. ORDER BY spo.id_ DESC
  706. <include refid="global.limit"/>
  707. </select>
  708. <select id="findOrderByGroup" resultMap="StudentPaymentOrder">
  709. SELECT * FROM student_payment_order
  710. WHERE music_group_id_=#{groupId}
  711. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  712. <if test="status!=null">
  713. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  714. </if>
  715. </select>
  716. <select id="sumPerAccountAmount" resultType="java.math.BigDecimal"><![CDATA[
  717. SELECT SUM(per_amount_)
  718. FROM student_payment_order
  719. WHERE FIND_IN_SET(status_, 'SUCCESS,ING')
  720. AND create_time_ >= #{firstDate}
  721. AND create_time_ <= NOW()
  722. AND FIND_IN_SET(#{merNo}, mer_nos_)
  723. ]]>
  724. </select>
  725. <select id="getChargeAmount" parameterType="map" resultType="java.math.BigDecimal">
  726. SELECT SUM(actual_amount_) FROM student_payment_order spo
  727. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_ = sci.id_
  728. <include refid="queryPaymentOrder"/>
  729. </select>
  730. <select id="sumAccountAmount" resultType="java.math.BigDecimal">
  731. <![CDATA[
  732. SELECT SUM(actual_amount_)
  733. FROM student_payment_order
  734. WHERE status_ IN ('SUCCESS', 'ING')
  735. AND create_time_ >= #{firstDate}
  736. AND create_time_ <= NOW()
  737. AND mer_nos_ = #{merNo}
  738. ]]></select>
  739. <select id="countGroupOrderWithoutFailed" resultType="int">
  740. SELECT COUNT(*)
  741. FROM student_payment_order spo
  742. WHERE spo.music_group_id_ = #{groupId}
  743. AND spo.status_ NOT IN ('FAILED','CLOSE')
  744. AND spo.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  745. </select>
  746. <select id="countSporadicOrder" resultType="java.lang.Integer">
  747. SELECT COUNT(id_)
  748. FROM student_payment_order spo
  749. WHERE spo.group_type_ = 'SPORADIC'
  750. AND spo.music_group_id_ = #{sporadicId}
  751. </select>
  752. <!-- 查找支付成功和支付中订单 -->
  753. <select id="findOrganPayOrderNum" resultType="int">
  754. SELECT COUNT(*)
  755. FROM student_payment_order
  756. WHERE organ_id_ = #{organId}
  757. AND status_ IN ('SUCCESS', 'ING')
  758. </select>
  759. <!-- 获取每月用户的对应类型订单订单 -->
  760. <select id="getOrderByMonthAndType" resultType="com.ym.mec.biz.dal.dto.OrderByTypeExportDto">
  761. SELECT o.name_ organName, spo.user_id_ studentId,su.username_ studentName,spo.type_ orderType,
  762. spo.actual_amount_ actualAmount,spo.music_group_id_ musicGroupId,spo.group_type_ groupType,spo.create_time_
  763. createTime
  764. FROM student_payment_order spo
  765. LEFT JOIN sys_user su on spo.user_id_ = su.id_
  766. LEFT JOIN organization o ON o.id_ = spo.id_
  767. WHERE spo.status_ = 'SUCCESS'
  768. AND FIND_IN_SET (spo.organ_id_,#{organIds})
  769. <if test="orderTypeList != null">
  770. AND spo.type_ IN
  771. <foreach collection="orderTypeList" item="orderType" open="(" close=")"
  772. separator=",">
  773. #{orderType}
  774. </foreach>
  775. </if>
  776. <if test="startTime != null">
  777. AND spo.create_time_ >= #{startTime}
  778. </if>
  779. <if test="endTime != null"><![CDATA[
  780. AND spo.create_time_ <= #{endTime}
  781. ]]></if>
  782. AND spo.actual_amount_ > 0
  783. </select>
  784. <select id="getUsers" resultType="com.ym.mec.biz.dal.dto.BasicUserDto">
  785. SELECT username_ name, id_ userId, phone_ phone
  786. FROM sys_user
  787. WHERE id_ = #{search}
  788. OR username_ LIKE CONCAT('%', #{search}, '%')
  789. OR phone_ LIKE CONCAT('%', #{search}, '%')
  790. </select>
  791. <select id="lockOrder" resultMap="StudentPaymentOrder">
  792. SELECT *
  793. FROM student_payment_order
  794. WHERE id_ = #{id} FOR
  795. UPDATE
  796. </select>
  797. <select id="doubleEleven2020Statis" resultMap="luckStatis">
  798. SELECT o.id_ organId, o.name_ organName, SUM(spo.actual_amount_) money, COUNT(DISTINCT spo.user_id_) nums,
  799. SUM(IF(spo.class_group_id_ is null ,1,spo.class_group_id_)) times FROM student_payment_order spo
  800. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  801. WHERE spo.type_ = 'DOUBLE_ELEVEN2020'
  802. AND spo.status_ = 'SUCCESS'
  803. AND spo.organ_id_ IN
  804. <foreach collection="organs" item="organ" open="(" close=")" separator=",">
  805. #{organ.id}
  806. </foreach>
  807. GROUP BY spo.organ_id_
  808. </select>
  809. <select id="getUserOrderNumByType" resultType="int">
  810. SELECT COUNT(*)
  811. FROM student_payment_order
  812. WHERE user_id_ = #{userId}
  813. AND status_ = 'SUCCESS'
  814. AND type_ = #{orderType}
  815. </select>
  816. <select id="getUserOrderByType" resultMap="StudentPaymentOrder">
  817. 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}
  818. </select>
  819. <select id="queryDouble11Students" resultMap="StudentVipDouble11Dto">
  820. SELECT
  821. su.id_ userId,
  822. su.username_ userName,
  823. su.phone_ phone,
  824. su.avatar_ avatar,
  825. SUM(CASE WHEN sci.title_ LIKE '%1V1%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_one_time_,
  826. SUM(CASE WHEN sci.title_ LIKE '%1V2%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_two_time_
  827. FROM
  828. student_payment_order spo
  829. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  830. LEFT JOIN student s ON spo.user_id_=s.user_id_
  831. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  832. WHERE
  833. spo.status_ = 'SUCCESS'
  834. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  835. AND sci.title_ LIKE '双十一%'
  836. AND s.teacher_id_= #{teacherId}
  837. <if test="search!=null and search!=''">
  838. AND (su.phone_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
  839. </if>
  840. GROUP BY
  841. spo.user_id_
  842. ORDER BY spo.user_id_
  843. <include refid="global.limit" />
  844. </select>
  845. <select id="countDouble11Students" resultType="int">
  846. SELECT
  847. COUNT(DISTINCT spo.user_id_)
  848. FROM
  849. student_payment_order spo
  850. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  851. LEFT JOIN student s ON spo.user_id_=s.user_id_
  852. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  853. WHERE
  854. spo.status_ = 'SUCCESS'
  855. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  856. AND sci.title_ LIKE '双十一%'
  857. AND s.teacher_id_= #{teacherId}
  858. <if test="search!=null and search!=''">
  859. AND (su.phone_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
  860. </if>;
  861. </select>
  862. <select id="findStudentsDouble11Infos" resultMap="StudentVipDouble11Dto">
  863. SELECT
  864. su.id_ userId,
  865. su.username_ userName,
  866. su.phone_ phone,
  867. su.avatar_ avatar,
  868. SUM(CASE WHEN sci.title_ LIKE '%1V1%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_one_time_,
  869. SUM(CASE WHEN sci.title_ LIKE '%1V2%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_two_time_
  870. FROM
  871. student_payment_order spo
  872. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  873. LEFT JOIN student s ON spo.user_id_=s.user_id_
  874. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  875. WHERE
  876. spo.status_ = 'SUCCESS'
  877. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  878. AND sci.title_ LIKE '双十一%'
  879. AND spo.user_id_ IN
  880. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  881. #{studentId}
  882. </foreach>
  883. GROUP BY
  884. spo.user_id_
  885. </select>
  886. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto" id="applyOrderAndDetail"
  887. extends="StudentPaymentOrder">
  888. <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
  889. <result column="detail_id_" property="id"/>
  890. <result column="detail_type_" property="type"/>
  891. <result column="detail_price_" property="price"/>
  892. <result column="detail_kit_group_purchase_type_" property="kitGroupPurchaseType"/>
  893. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  894. <result column="goods_id" property="id"/>
  895. <result column="goods_name" property="name"/>
  896. <result column="complementGoodsIdList" property="complementGoodsIdList"/>
  897. </collection>
  898. </collection>
  899. </resultMap>
  900. <select id="getUserApplyOrders" resultMap="applyOrderAndDetail" parameterType="map">
  901. SELECT spo.*,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  902. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  903. g.id_ goods_id, g.name_ goods_name,g.complement_goods_id_list_ complementGoodsIdList
  904. FROM student_payment_order spo
  905. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  906. LEFT JOIN goods g on FIND_IN_SET(g.id_,spod.goods_id_list_)
  907. WHERE spo.user_id_ = #{userId} AND spo.type_='APPLY' AND spo.music_group_id_=#{musicGroupId}
  908. ORDER BY spo.id_ desc
  909. </select>
  910. <select id="getAdaPayOrdersByTime" resultMap="StudentPaymentOrder"><![CDATA[
  911. SELECT * FROM student_payment_order WHERE pay_time_ >= #{startTime} AND pay_time_ <= #{endTime} AND payment_channel_='ADAPAY' AND status_ ='SUCCESS']]>
  912. </select>
  913. <select id="getUserReplacementIngOrder" resultMap="StudentPaymentOrder">
  914. SELECT * FROM student_payment_order WHERE user_id_=#{userId} AND music_group_id_ = #{replacementId} AND status_ = 'ING' LIMIT 1
  915. </select>
  916. <select id="getMoneyInMusicApply" resultMap="Mapper">
  917. 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_
  918. FROM student_payment_order spo
  919. LEFT JOIN student_registration sr ON sr.user_id_ = spo.user_id_
  920. 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_
  921. FROM subject_change WHERE id_ in
  922. (SELECT max(sc.id_) id_ from subject_change sc WHERE sc.status_ = 2 GROUP BY music_group_id_,student_id_ ORDER BY id_ DESC)
  923. ) a on spo.music_group_id_ = a.music_group_id_ and spo.id_ = a.original_order_id_
  924. WHERE spo.music_group_id_ IN
  925. <foreach collection="musicGroupIds" item="musicGroupId" open="(" close=")" separator=",">
  926. #{musicGroupId}
  927. </foreach>
  928. AND spo.type_ = 'APPLY' AND spo.status_ = 'SUCCESS' AND sr.music_group_id_ = spo.music_group_id_ AND sr.music_group_status_ = 'NORMAL'
  929. GROUP BY spo.music_group_id_
  930. </select>
  931. <select id="getOrderIdByMusical" resultType="java.lang.Integer">
  932. SELECT DISTINCT spo.id_ FROM student_payment_order spo
  933. LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
  934. WHERE spo.type_ = 'APPLY' AND spo.status_ = 'SUCCESS' AND spo.music_group_id_ = #{musicGroupId}
  935. AND spo.user_id_ = #{studentId} AND spod.type_ = 'MUSICAL'
  936. </select>
  937. <select id="queryStudentCourseAmountMap" resultType="java.util.Map">
  938. SELECT user_id_ 'key',expect_amount_ - coupon_remit_fee_ 'value' FROM student_payment_order
  939. WHERE status_ = 'SUCCESS' AND music_group_id_ = #{vipGroupId}
  940. GROUP BY user_id_
  941. </select>
  942. <select id="queryStudentDoubleEleven2021Order" resultType="java.lang.String">
  943. SELECT GROUP_CONCAT(activity_id_) FROM student_payment_order
  944. WHERE type_ = 'DOUBLE_ELEVEN2021' AND status_ = 'SUCCESS' AND user_id_ = #{userId}
  945. </select>
  946. <select id="findByCalenderId" resultMap="StudentPaymentOrder">
  947. SELECT * FROM student_payment_order WHERE calender_id_ = #{calenderId} AND status_ = 'SUCCESS' AND user_id_ = #{userId}
  948. </select>
  949. <resultMap type="com.ym.mec.biz.dal.vo.StudentPaymentOrderVo" id="QueryOrderDetail">
  950. <result column="orderNo" property="orderNo"/>
  951. <result column="orderType" property="orderType"/>
  952. <result column="orderTypeCode" property="orderTypeCode"/>
  953. <result column="totalAmount" property="totalAmount"/>
  954. <result column="actualAmount" property="actualAmount"/>
  955. <result column="balanceAmount" property="balanceAmount"/>
  956. <result column="actualAmount" property="actualAmount"/>
  957. <result column="createTime" property="createTime"/>
  958. <result column="payTime" property="payTime"/>
  959. <result column="transNo" property="transNo"/>
  960. <result column="totalRemitFee" property="totalRemitFee"/>
  961. <collection property="list" ofType="com.ym.mec.biz.dal.vo.StudentPaymentOrderVo$StudentPaymentDetailVo">
  962. <result column="goodsName" property="goodsName"/>
  963. <result column="price" property="price"/>
  964. </collection>
  965. </resultMap>
  966. <select id="queryStudentOrderPage" resultMap="QueryOrderDetail">
  967. select
  968. a.order_no_ as orderNo,
  969. a.type_ as orderType,
  970. a.type_ as orderTypeCode,
  971. ifnull(a.actual_amount_, 0) + ifnull(a.balance_payment_amount_, 0) as totalAmount,
  972. a.create_time_ as createTime
  973. from student_payment_order as a
  974. where status_ = 'SUCCESS'
  975. and create_time_ >= #{param.startDate}
  976. and create_time_ <![CDATA[ < ]]> #{param.endDate}
  977. and user_id_ = #{param.userId}
  978. </select>
  979. <select id="queryOrderDetail" resultMap="QueryOrderDetail">
  980. select
  981. a.order_no_ as orderNo,
  982. a.type_ as orderType,
  983. ifnull(a.actual_amount_, 0) + ifnull(a.balance_payment_amount_, 0) + ifnull(a.remit_fee_, 0) +
  984. ifnull(a.coupon_remit_fee_, 0) as totalAmount,
  985. a.actual_amount_ as actualAmount,
  986. a.balance_payment_amount_ as balanceAmount,
  987. ifnull(a.remit_fee_,0) + ifnull(a.coupon_remit_fee_,0) as totalRemitFee,
  988. a.create_time_ as createTime,
  989. a.pay_time_ as payTime,
  990. a.trans_no_ as transNo,
  991. b.type_ as goodsName,
  992. ifnull(b.price_, 0) as price
  993. from student_payment_order as a
  994. left join
  995. student_payment_order_detail as b on a.id_ = b.payment_order_id_
  996. where order_no_ = #{orderNo}
  997. </select>
  998. <select id="getStudentMusicOrderNum" resultType="int">
  999. SELECT COUNT(0) FROM student_payment_order spo
  1000. WHERE spo.music_group_id_ = #{musicGroupId} AND spo.user_id_ = #{userId} AND group_type_ = 'MUSIC' AND status_ = 'SUCCESS' AND spo.id_ &lt; #{orderId}
  1001. </select>
  1002. <select id="getMemberIngOrder" resultType="com.ym.mec.biz.dal.entity.StudentPaymentOrder">
  1003. SELECT *
  1004. FROM student_payment_order
  1005. WHERE music_group_id_ IS NULL
  1006. AND type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  1007. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  1008. LIMIT 1
  1009. </select>
  1010. </mapper>