StudentPaymentOrderMapper.xml 38 KB

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