StudentPaymentOrderMapper.xml 39 KB

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