StudentPaymentOrderMapper.xml 58 KB

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