StudentPaymentOrderMapper.xml 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  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="queryExpectAmount" resultType="java.util.Map">
  438. SELECT spo.expect_amount_ 'value',spo.id_ 'key'
  439. FROM student_payment_order spo
  440. WHERE spo.id_ IN
  441. <foreach collection="paymentOrderNo" open="(" close=")" separator="," item="item">
  442. #{item}
  443. </foreach>
  444. </select>
  445. <select id="findFixOrder" resultMap="StudentPaymentOrder">
  446. SELECT *
  447. FROM student_payment_order
  448. where status_ = 'SUCCESS'
  449. AND type_ = 'APPLY'
  450. AND actual_amount_ > 0
  451. and mer_nos_ IS NULL
  452. LIMIT 100
  453. </select>
  454. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto" id="orderAndDetail"
  455. extends="StudentPaymentOrder">
  456. <result column="organ_name" property="organName"/>
  457. <result column="username_" property="user.username"/>
  458. <result column="charge_type_" property="chargeType"/>
  459. <result column="routeMerNo" property="routeMerNo"/>
  460. <result column="routeAmount" property="routeAmount"/>
  461. <result column="routeBalance" property="routeBalance"/>
  462. <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
  463. <result column="detail_id_" property="id"/>
  464. <result column="detail_type_" property="type"/>
  465. <result column="detail_price_" property="price"/>
  466. <result column="detail_kit_group_purchase_type_" property="kitGroupPurchaseType"/>
  467. </collection>
  468. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  469. <result column="goods_id" property="id"/>
  470. <result column="goods_name" property="name"/>
  471. </collection>
  472. </resultMap>
  473. <!-- 分页查询 -->
  474. <select id="ExportQueryPage" resultMap="orderAndDetail" parameterType="map">
  475. SELECT spo.*,u.username_,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  476. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  477. sci.charge_type_,g.id_ goods_id, g.name_ goods_name,o.name_ organ_name
  478. FROM student_payment_order spo
  479. LEFT JOIN sys_user u on spo.user_id_ = u.id_
  480. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  481. <if test='orderType != null and orderType.toString()=="0".toString()'>
  482. LEFT JOIN organization o on spo.organ_id_ = o.id_
  483. </if>
  484. <if test='orderType != null and orderType.toString()=="1".toString()'>
  485. LEFT JOIN organization o on spo.organ_id_ = o.id_
  486. </if>
  487. <if test='orderType != null and orderType.toString()=="2".toString()'>
  488. LEFT JOIN organization o on spo.organ_id_ = o.id_
  489. </if>
  490. <if test='orderType != null and orderType.toString()=="3".toString()'>
  491. LEFT JOIN organization o on spo.routing_organ_id_ = o.id_
  492. </if>
  493. LEFT JOIN sporadic_charge_info sci on spo.music_group_id_ = sci.id_
  494. LEFT JOIN goods g on FIND_IN_SET(g.id_,spod.goods_id_list_)
  495. <include refid="queryPaymentOrder"/>
  496. ORDER BY spo.id_ ASC
  497. </select>
  498. <resultMap id="SporadicChargeInfoDtoMap" type="com.ym.mec.biz.dal.dto.SporadicChargeInfoDto">
  499. <result property="organName" column="organ_name_"/>
  500. <result property="title" column="title_"/>
  501. <result property="type" column="type_"/>
  502. <result property="amount" column="amount_"/>
  503. <result property="createTime" column="create_time_"/>
  504. <result property="payTime" column="pay_time_"/>
  505. <result property="username" column="username_"/>
  506. <result property="payStatus" column="pay_status_"/>
  507. </resultMap>
  508. <select id="sporadicQueryPage" resultMap="SporadicChargeInfoDtoMap">
  509. SELECT o.name_ organ_name_,sci.title_,sci.charge_type_ type_,
  510. spo.actual_amount_ amount_,spo.create_time_,spo.pay_time_,su.username_,spo.status_ pay_status_
  511. FROM student_payment_order spo
  512. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  513. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  514. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  515. WHERE spo.type_ = 'SPORADIC'
  516. <include refid="sporadicQueryPageSql"/>
  517. ORDER BY spo.id_ DESC
  518. <include refid="global.limit"/>
  519. </select>
  520. <select id="countSporadicPage" resultType="java.lang.Integer">
  521. SELECT COUNT(spo.id_)
  522. FROM student_payment_order spo
  523. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  524. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  525. WHERE spo.type_ = 'SPORADIC'
  526. <include refid="sporadicQueryPageSql"/>
  527. </select>
  528. <sql id="sporadicQueryPageSql">
  529. <if test="organId != null">
  530. AND FIND_IN_SET(spo.organ_id_,#{organId})
  531. </if>
  532. <if test="search != null">
  533. AND (sci.title_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%'))
  534. </if>
  535. <if test="chargeType != null">
  536. AND sci.charge_type_ = #{chargeType}
  537. </if>
  538. <if test="payStatus != null">
  539. AND spo.status_ = #{payStatus}
  540. </if>
  541. </sql>
  542. <resultMap id="luckStatis" type="com.ym.mec.biz.dal.dto.OrderStatisDto">
  543. <result property="organId" column="organId"/>
  544. <result property="organName" column="organName"/>
  545. <result property="estimatedNums" column="estimatedNums"/>
  546. <result property="nums" column="nums"/>
  547. <result property="times" column="times"/>
  548. <result property="scale" column="scale"/>
  549. <result property="money" column="money"/>
  550. </resultMap>
  551. <select id="getLuckStatis" resultMap="luckStatis">
  552. SELECT o.name_ organName, SUM(spo.actual_amount_) money, COUNT(spo.id_) nums
  553. FROM student_payment_order spo
  554. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  555. WHERE spo.type_ = 'LUCK'
  556. AND spo.status_ = 'SUCCESS'
  557. GROUP BY spo.organ_id_
  558. ORDER BY nums DESC;
  559. </select>
  560. <select id="queryIncomeStatisticsWithCurrentMonth" resultType="map">
  561. select count(*) total,sum(actual_amount_) total_num_ from student_payment_order
  562. where actual_amount_ &gt; 0 and DATE_FORMAT(create_time_, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' ) AND
  563. status_ = 'SUCCESS' and organ_id_ not in (36,38)
  564. <if test="organId != null">
  565. and FIND_IN_SET(organ_id_,#{organId})
  566. </if>
  567. </select>
  568. <select id="countUserBuyVipGroupSuccessOrder" resultType="int">
  569. select count(*)
  570. from student_payment_order
  571. where user_id_ = #{userId}
  572. and music_group_id_ = #{vipGroupId}
  573. and group_type_ = 'VIP'
  574. and status_ = 'SUCCESS'
  575. </select>
  576. <select id="findUserBuyVipGroupOrder" resultMap="StudentPaymentOrder">
  577. select *
  578. from student_payment_order
  579. where user_id_ = #{userId}
  580. and music_group_id_ = #{vipGroupId}
  581. and group_type_ = 'VIP'
  582. </select>
  583. <select id="findUserGroupOrders" resultMap="StudentPaymentOrder">
  584. select * from student_payment_order
  585. where user_id_=#{userId}
  586. and music_group_id_=#{groupId}
  587. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  588. <if test="status!=null">
  589. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  590. </if>
  591. </select>
  592. <select id="getOrderMoneyAmount" parameterType="map" resultMap="StudentPaymentOrder">
  593. SELECT SUM(spo.expect_amount_) expect_amount_,SUM(actual_amount_) actual_amount_,SUM(balance_payment_amount_)
  594. balance_payment_amount_ FROM student_payment_order spo
  595. <include refid="queryPaymentOrder"/>
  596. </select>
  597. <!-- 分页查询 -->
  598. <select id="queryPageOrder" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  599. SELECT spo.*,u.username_,u.phone_ FROM student_payment_order spo
  600. left join sys_user u on spo.user_id_ = u.id_
  601. <include refid="queryPaymentOrder"/>
  602. ORDER BY spo.id_ DESC
  603. <include refid="global.limit"/>
  604. </select>
  605. <select id="findOrderByGroup" resultMap="StudentPaymentOrder">
  606. SELECT * FROM student_payment_order
  607. WHERE music_group_id_=#{groupId}
  608. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  609. <if test="status!=null">
  610. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  611. </if>
  612. </select>
  613. <select id="sumPerAccountAmount" resultType="java.math.BigDecimal"><![CDATA[
  614. SELECT SUM(per_amount_)
  615. FROM student_payment_order
  616. WHERE FIND_IN_SET(status_, 'SUCCESS,ING')
  617. AND create_time_ >= #{firstDate}
  618. AND create_time_ <= NOW()
  619. AND FIND_IN_SET(#{merNo}, mer_nos_)
  620. ]]>
  621. </select>
  622. <select id="getChargeAmount" parameterType="map" resultType="java.math.BigDecimal">
  623. SELECT SUM(actual_amount_) FROM student_payment_order spo
  624. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_ = sci.id_
  625. <include refid="queryPaymentOrder"/>
  626. </select>
  627. <select id="sumAccountAmount" resultType="java.math.BigDecimal">
  628. <![CDATA[
  629. SELECT SUM(actual_amount_)
  630. FROM student_payment_order
  631. WHERE status_ IN ('SUCCESS', 'ING')
  632. AND create_time_ >= #{firstDate}
  633. AND create_time_ <= NOW()
  634. AND mer_nos_ = #{merNo}
  635. ]]></select>
  636. <select id="countGroupOrderWithoutFailed" resultType="int">
  637. SELECT COUNT(*)
  638. FROM student_payment_order spo
  639. LEFT JOIN class_group_student_mapper cgsm
  640. ON spo.music_group_id_ = cgsm.music_group_id_ AND spo.user_id_ = cgsm.user_id_
  641. WHERE spo.music_group_id_ = #{groupId}
  642. AND spo.status_ != 'FAILED'
  643. AND cgsm.status_ != 'QUIT'
  644. AND spo.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  645. AND cgsm.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  646. </select>
  647. <select id="countSporadicOrder" resultType="java.lang.Integer">
  648. SELECT COUNT(id_)
  649. FROM student_payment_order spo
  650. WHERE spo.group_type_ = 'SPORADIC'
  651. AND spo.music_group_id_ = #{sporadicId}
  652. </select>
  653. <!-- 查找支付成功和支付中订单 -->
  654. <select id="findOrganPayOrderNum" resultType="int">
  655. SELECT COUNT(*)
  656. FROM student_payment_order
  657. WHERE organ_id_ = #{organId}
  658. AND status_ IN ('SUCCESS', 'ING')
  659. </select>
  660. <!-- 获取每月用户的对应类型订单订单 -->
  661. <select id="getOrderByMonthAndType" resultType="com.ym.mec.biz.dal.dto.OrderByTypeExportDto">
  662. SELECT o.name_ organName, spo.user_id_ studentId,su.username_ studentName,spo.type_ orderType,
  663. spo.actual_amount_ actualAmount,spo.music_group_id_ musicGroupId,spo.group_type_ groupType,spo.create_time_
  664. createTime
  665. FROM student_payment_order spo
  666. LEFT JOIN sys_user su on spo.user_id_ = su.id_
  667. LEFT JOIN organization o ON o.id_ = spo.id_
  668. WHERE spo.status_ = 'SUCCESS'
  669. <if test="organIds != null">
  670. AND FIND_IN_SET (spo.organ_id_,#{organIds})
  671. </if>
  672. <if test="orderTypeList != null">
  673. AND spo.type_ IN
  674. <foreach collection="orderTypeList" item="orderType" open="(" close=")"
  675. separator=",">
  676. #{orderType}
  677. </foreach>
  678. </if>
  679. <if test="startTime != null">
  680. AND spo.create_time_ >= #{startTime}
  681. </if>
  682. <if test="endTime != null"><![CDATA[
  683. AND spo.create_time_ <= #{endTime}
  684. ]]></if>
  685. AND spo.actual_amount_ > 0
  686. </select>
  687. <select id="getUsers" resultType="com.ym.mec.biz.dal.dto.BasicUserDto">
  688. SELECT username_ name, id_ userId, phone_ phone
  689. FROM sys_user
  690. WHERE id_ = #{search}
  691. OR username_ LIKE CONCAT('%', #{search}, '%')
  692. OR phone_ LIKE CONCAT('%', #{search}, '%')
  693. </select>
  694. <select id="lockOrder" resultMap="StudentPaymentOrder">
  695. SELECT *
  696. FROM student_payment_order
  697. WHERE id_ = #{id} FOR
  698. UPDATE
  699. </select>
  700. <select id="doubleEleven2020Statis" resultMap="luckStatis">
  701. SELECT o.id_ organId, o.name_ organName, SUM(spo.actual_amount_) money, COUNT(DISTINCT spo.user_id_) nums,
  702. SUM(IF(spo.class_group_id_ is null ,1,spo.class_group_id_)) times FROM student_payment_order spo
  703. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  704. WHERE spo.type_ = 'DOUBLE_ELEVEN2020'
  705. AND spo.status_ = 'SUCCESS'
  706. AND spo.organ_id_ IN
  707. <foreach collection="organs" item="organ" open="(" close=")" separator=",">
  708. #{organ.id}
  709. </foreach>
  710. GROUP BY spo.organ_id_
  711. </select>
  712. <select id="getUserOrderNumByType" resultType="int">
  713. SELECT COUNT(*)
  714. FROM student_payment_order
  715. WHERE user_id_ = #{userId}
  716. AND status_ = 'SUCCESS'
  717. AND type_ = #{orderType}
  718. </select>
  719. <select id="getUserOrderByType" resultMap="StudentPaymentOrder">
  720. 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}
  721. </select>
  722. <select id="queryDouble11Students" resultMap="StudentVipDouble11Dto">
  723. SELECT
  724. su.id_ userId,
  725. su.username_ userName,
  726. su.phone_ phone,
  727. su.avatar_ avatar,
  728. SUM(CASE WHEN sci.title_ LIKE '%1V1%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_one_time_,
  729. SUM(CASE WHEN sci.title_ LIKE '%1V2%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_two_time_
  730. FROM
  731. student_payment_order spo
  732. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  733. LEFT JOIN student s ON spo.user_id_=s.user_id_
  734. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  735. WHERE
  736. spo.status_ = 'SUCCESS'
  737. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  738. AND sci.title_ LIKE '双十一%'
  739. AND s.teacher_id_= #{teacherId}
  740. <if test="search!=null and search!=''">
  741. AND (su.phone_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
  742. </if>
  743. GROUP BY
  744. spo.user_id_
  745. ORDER BY spo.user_id_
  746. </select>
  747. <select id="countDouble11Students" resultType="int">
  748. SELECT
  749. COUNT(DISTINCT spo.user_id_)
  750. FROM
  751. student_payment_order spo
  752. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  753. LEFT JOIN student s ON spo.user_id_=s.user_id_
  754. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  755. WHERE
  756. spo.status_ = 'SUCCESS'
  757. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  758. AND sci.title_ LIKE '双十一%'
  759. AND s.teacher_id_= #{teacherId}
  760. <if test="search!=null and search!=''">
  761. AND (su.phone_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
  762. </if>;
  763. </select>
  764. </mapper>