StudentPaymentOrderMapper.xml 49 KB

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