StudentPaymentOrderMapper.xml 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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. <if test="orderType != null and orderType != ''">
  495. AND spo.type_ = #{orderType}
  496. </if>
  497. <if test="orderType == null or orderType == ''">
  498. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  499. </if>
  500. </select>
  501. <select id="sumSurplusCourseFee" resultType="java.math.BigDecimal">
  502. SELECT SUM(cssp.expect_price_)
  503. FROM course_schedule_student_payment cssp
  504. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  505. WHERE cssp.user_id_ = #{userId}
  506. AND cssp.music_group_id_ = #{vipGroupId}
  507. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
  508. </select>
  509. <select id="findNotFailedOrderByStudentVipGroup" resultMap="StudentPaymentOrder">
  510. SELECT spo.*
  511. FROM student_payment_order spo
  512. WHERE spo.user_id_ = #{userId}
  513. AND spo.music_group_id_ = #{vipGroupId}
  514. AND spo.status_ != 'FAILED'
  515. AND spo.type_ = 'SMALL_CLASS_TO_BUY'
  516. </select>
  517. <!-- 查询报名订单 -->
  518. <select id="findMusicGroupApplyOrderByStatus" resultMap="StudentPaymentOrder">
  519. SELECT * FROM student_payment_order
  520. WHERE music_group_id_ = #{musicGroupId}
  521. AND user_id_ = #{userId}
  522. AND type_ = 'APPLY'
  523. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  524. ORDER BY id_ DESC
  525. </select>
  526. <select id="queryByBatchNo" resultMap="StudentPaymentOrder" parameterType="map">
  527. SELECT *
  528. FROM student_payment_order
  529. WHERE batch_no_ = #{batchNo}
  530. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  531. and user_id_ = #{userId}
  532. </select>
  533. <!-- 根据订单号查询订单 -->
  534. <select id="findOrderByOrderNo" resultMap="StudentPaymentOrder">
  535. SELECT *
  536. FROM student_payment_order
  537. WHERE order_no_ = #{orderNo}
  538. </select>
  539. <select id="findOrderByOrderNos" resultMap="StudentPaymentOrder">
  540. SELECT *
  541. FROM student_payment_order
  542. WHERE order_no_ in
  543. <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
  544. #{orderNo}
  545. </foreach>
  546. </select>
  547. <select id="queryByDealStatus" resultMap="StudentPaymentOrder" parameterType="map">
  548. SELECT *
  549. FROM student_payment_order
  550. WHERE music_group_id_ = #{musicGroupId}
  551. AND type_ = #{type}
  552. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  553. </select>
  554. <resultMap type="com.ym.mec.biz.dal.dto.UserGoodsDto" id="userGoodsDto">
  555. <result column="goods_id_" property="goodsId"/>
  556. <collection property="goodsName" ofType="string">
  557. <result column="goods_name_"/>
  558. </collection>
  559. </resultMap>
  560. <select id="findGoodsIds" resultMap="userGoodsDto">
  561. SELECT g.id_ goods_id_, g.name_ goods_name_
  562. FROM student_payment_order spo
  563. LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
  564. LEFT JOIN goods g ON FIND_IN_SET(g.id_, spod.goods_id_list_)
  565. WHERE spo.type_ = 'APPLY'
  566. AND spo.status_ = 'SUCCESS'
  567. AND spod.goods_id_list_ IS NOT NULL
  568. AND spo.music_group_id_ = #{musicGroupId}
  569. AND spo.user_id_ = #{userId}
  570. </select>
  571. <select id="getUserGoods" resultMap="userGoodsDto">
  572. SELECT id_ goods_id_, name_ goods_name_ FROM goods WHERE FIND_IN_SET(id_,#{ids})
  573. </select>
  574. <select id="findOrdersByStatus" resultMap="StudentPaymentOrder">
  575. SELECT *
  576. FROM student_payment_order
  577. WHERE status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  578. AND payment_channel_ = #{paymentChannel}
  579. <!-- 商城订单由商城控制订单超时 -->
  580. and group_type_ != 'MALL_SELL' and type_ != 'MALL_BUY'
  581. </select>
  582. <!-- 查询支付中超时订单 -->
  583. <select id="findOrdersOverTime" resultMap="StudentPaymentOrder">
  584. SELECT * FROM student_payment_order WHERE order_no_ IN
  585. <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
  586. #{orderNo}
  587. </foreach>
  588. AND status_=#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  589. <![CDATA[ AND create_time_ <= ]]> #{beforeTime}
  590. </select>
  591. <select id="countStudentPaymentNum" resultType="int">
  592. select count(DISTINCT user_id_)
  593. from student_payment_order
  594. where music_group_id_ = #{musicGroupId}
  595. AND status_ = 'SUCCESS'
  596. AND type_ = 'SMALL_CLASS_TO_BUY'
  597. </select>
  598. <select id="countSurplusCourseByMusicGroupAndUser" resultType="int">
  599. SELECT COUNT(*)
  600. FROM course_schedule_student_payment cssp
  601. LEFT JOIN course_schedule cs ON cssp.course_schedule_id_ = cs.id_
  602. WHERE cssp.user_id_ = #{userId}
  603. AND cssp.music_group_id_ = #{musicGroupId}
  604. AND CONCAT(cs.class_date_, ' ', cs.start_class_time_) &gt; NOW()
  605. </select>
  606. <select id="sumGroupIncomeFee" resultType="java.math.BigDecimal">
  607. SELECT
  608. (CASE WHEN a.a > 0 THEN a.a ELSE c.c END) +
  609. (CASE WHEN d.d IS NULL THEN 0 ELSE d.d END) +
  610. (CASE WHEN e.e IS NULL THEN 0 ELSE e.e END) -
  611. (CASE WHEN b.b IS NULL THEN 0 ELSE b.b END) amount_
  612. FROM
  613. (SELECT SUM(CASE WHEN expect_amount_ IS NULL THEN 0 ELSE expect_amount_ END) a FROM student_payment_order
  614. WHERE group_type_ = #{groupType} AND music_group_id_ = #{vipGroupId} AND status_ = 'SUCCESS') a,
  615. (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_ = #{groupType}) b,
  616. (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,
  617. (SELECT SUM(CASE WHEN amount_ IS NULL THEN 0 ELSE amount_ END) d FROM sys_user_cash_account_detail WHERE group_id_ = #{vipGroupId}) d,
  618. (SELECT SUM(CASE WHEN amount_ IS NULL THEN 0 ELSE amount_ END) e FROM sys_user_courses_account_detail WHERE group_id_ = #{vipGroupId}) e
  619. </select>
  620. <select id="findStudentPaymentOrder" resultMap="StudentPaymentOrder">
  621. 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_
  622. FROM student_payment_order spo
  623. LEFT JOIN student_registration sr ON sr.user_id_ = spo.user_id_
  624. 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
  625. (SELECT max(id_) id_ from subject_change WHERE status_ = 2 GROUP BY music_group_id_,student_id_ ORDER BY id_ desc)
  626. ) sc on spo.music_group_id_ = sc.music_group_id_ and spo.id_ = sc.original_order_id_
  627. WHERE spo.music_group_id_ = #{musicGroupId} AND sr.music_group_id_ = spo.music_group_id_ AND sr.music_group_status_ = 'NORMAL'
  628. AND spo.type_ = 'APPLY' and spo.status_ = 'SUCCESS'
  629. GROUP BY sr.user_id_;
  630. </select>
  631. <select id="findPaymentOrderByGroupType" resultMap="StudentPaymentOrder">
  632. SELECT * FROM student_payment_order
  633. WHERE group_type_ = #{groupType}
  634. AND user_id_ = #{userId}
  635. AND music_group_id_ = #{sporadicId}
  636. <if test="status != null">
  637. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  638. </if>
  639. </select>
  640. <select id="queryExpectAmount" resultType="java.util.Map">
  641. SELECT spo.expect_amount_ 'value',spo.id_ 'key'
  642. FROM student_payment_order spo
  643. WHERE spo.id_ IN
  644. <foreach collection="paymentOrderNo" open="(" close=")" separator="," item="item">
  645. #{item}
  646. </foreach>
  647. </select>
  648. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderMallExportDto" id="mallOrderAndDetail"
  649. extends="StudentPaymentOrder">
  650. <result column="organ_name" property="organName"/>
  651. <result column="username_" property="user.username"/>
  652. <result column="routeMerNo" property="routeMerNo"/>
  653. <result column="routeAmount" property="routeAmount"/>
  654. <result column="routeBalance" property="routeBalance"/>
  655. <result column="sale_amount_" property="saleAmount"/>
  656. <result column="service_amount_" property="serviceAmount"/>
  657. <result column="service_fee_" property="serviceFee"/>
  658. <result column="routeBalance" property="routeBalance"/>
  659. <result column="orderAmount" property="orderAmount"/>
  660. </resultMap>
  661. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto" id="orderAndDetail"
  662. extends="StudentPaymentOrder">
  663. <result column="organ_name" property="organName"/>
  664. <result column="username_" property="user.username"/>
  665. <result column="charge_type_" property="chargeType"/>
  666. <result column="routeMerNo" property="routeMerNo"/>
  667. <result column="routeAmount" property="routeAmount"/>
  668. <result column="routeBalance" property="routeBalance"/>
  669. <result column="sale_amount_" property="saleAmount"/>
  670. <result column="service_amount_" property="serviceAmount"/>
  671. <result column="service_fee_" property="serviceFee"/>
  672. <result column="routeBalance" property="routeBalance"/>
  673. <result column="feeFlag" property="feeFlag"/>
  674. <result column="orderAmount" property="orderAmount"/>
  675. <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
  676. <result column="detail_id_" property="id"/>
  677. <result column="detail_type_" property="type"/>
  678. <result column="detail_price_" property="price"/>
  679. <result column="detail_kit_group_purchase_type_" property="kitGroupPurchaseType"/>
  680. <result column="income_item_" property="incomeItem"/>
  681. <result column="income_" property="income"/>
  682. </collection>
  683. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  684. <result column="goods_id" property="id"/>
  685. <result column="goods_name" property="name"/>
  686. </collection>
  687. </resultMap>
  688. <!-- 分页查询 -->
  689. <select id="exportMallQueryPage" resultMap="mallOrderAndDetail" parameterType="map">
  690. SELECT spo.*,u.username_,o.name_ organ_name,sgs.goods_json_
  691. FROM student_payment_order spo
  692. left join student_goods_sell sgs ON sgs.order_no_ = spo.order_no_
  693. LEFT JOIN sys_user u on spo.user_id_ = u.id_
  694. <if test='orderType != null and orderType.toString()=="0".toString()'>
  695. LEFT JOIN organization o on spo.organ_id_ = o.id_
  696. </if>
  697. <if test='orderType != null and orderType.toString()=="1".toString()'>
  698. LEFT JOIN organization o on spo.organ_id_ = o.id_
  699. </if>
  700. <if test='orderType != null and orderType.toString()=="2".toString()'>
  701. LEFT JOIN organization o on spo.organ_id_ = o.id_
  702. </if>
  703. <if test='orderType != null and orderType.toString()=="3".toString()'>
  704. LEFT JOIN organization o on spo.routing_organ_id_ = o.id_
  705. </if>
  706. <include refid="queryPaymentMallOrder"/>
  707. ORDER BY spo.id_ ASC
  708. </select>
  709. <!-- 分页查询 -->
  710. <select id="ExportQueryPage" resultMap="orderAndDetail" parameterType="map">
  711. SELECT spo.*,u.username_,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  712. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  713. sci.charge_type_,g.id_ goods_id, g.name_ goods_name,o.name_ organ_name
  714. FROM student_payment_order spo
  715. LEFT JOIN sys_user u on spo.user_id_ = u.id_
  716. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  717. <if test='orderType != null and orderType.toString()=="0".toString()'>
  718. LEFT JOIN organization o on spo.organ_id_ = o.id_
  719. </if>
  720. <if test='orderType != null and orderType.toString()=="1".toString()'>
  721. LEFT JOIN organization o on spo.organ_id_ = o.id_
  722. </if>
  723. <if test='orderType != null and orderType.toString()=="2".toString()'>
  724. LEFT JOIN organization o on spo.organ_id_ = o.id_
  725. </if>
  726. <if test='orderType != null and orderType.toString()=="3".toString()'>
  727. LEFT JOIN organization o on spo.routing_organ_id_ = o.id_
  728. </if>
  729. LEFT JOIN sporadic_charge_info sci on spo.music_group_id_ = sci.id_
  730. LEFT JOIN goods g on FIND_IN_SET(g.id_,spod.goods_id_list_)
  731. <include refid="queryPaymentOrder"/>
  732. ORDER BY spo.id_ ASC
  733. </select>
  734. <select id="ExportQueryPage1" resultMap="orderAndDetail" parameterType="map">
  735. SELECT spo.*,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  736. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  737. sci.charge_type_
  738. FROM student_payment_order spo
  739. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  740. LEFT JOIN sporadic_charge_info sci on spo.music_group_id_ = sci.id_
  741. where DATE_FORMAT(spo.pay_time_,'%Y-%m') = #{month} AND spo.order_no_ NOT IN (select distinct order_no_ from sell_order where DATE_FORMAT(delivery_time_,'%Y-%m') = #{month})
  742. AND spo.tenant_id_ = 1 AND spo.status_ = 'SUCCESS'
  743. </select>
  744. <select id="ExportQueryPage2" resultMap="orderAndDetail" parameterType="map">
  745. select spo.*,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  746. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  747. sci.charge_type_ from (select distinct order_no_ from sell_order where DATE_FORMAT(delivery_time_,'%Y-%m') = #{month}) so
  748. left join student_payment_order spo ON so.order_no_ = spo.order_no_
  749. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  750. LEFT JOIN sporadic_charge_info sci on spo.music_group_id_ = sci.id_
  751. where spo.tenant_id_ = 1 AND spo.status_ = 'SUCCESS'
  752. </select>
  753. <resultMap id="SporadicChargeInfoDtoMap" type="com.ym.mec.biz.dal.dto.SporadicChargeInfoDto">
  754. <result property="organName" column="organ_name_"/>
  755. <result property="title" column="title_"/>
  756. <result property="type" column="type_"/>
  757. <result property="amount" column="amount_"/>
  758. <result property="createTime" column="create_time_"/>
  759. <result property="payTime" column="pay_time_"/>
  760. <result property="username" column="username_"/>
  761. <result property="payStatus" column="pay_status_"/>
  762. </resultMap>
  763. <select id="sporadicQueryPage" resultMap="SporadicChargeInfoDtoMap">
  764. SELECT o.name_ organ_name_,sci.title_,sci.charge_type_ type_,
  765. spo.actual_amount_ amount_,spo.create_time_,spo.pay_time_,su.username_,spo.status_ pay_status_
  766. FROM student_payment_order spo
  767. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  768. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  769. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  770. WHERE spo.type_ = 'SPORADIC' and spo.tenant_id_ = #{tenantId}
  771. <include refid="sporadicQueryPageSql"/>
  772. ORDER BY spo.id_ DESC
  773. <include refid="global.limit"/>
  774. </select>
  775. <select id="countSporadicPage" resultType="java.lang.Integer">
  776. SELECT COUNT(spo.id_)
  777. FROM student_payment_order spo
  778. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  779. LEFT JOIN sporadic_charge_info sci ON sci.id_ = spo.music_group_id_
  780. WHERE spo.type_ = 'SPORADIC' and spo.tenant_id_ = #{tenantId}
  781. <include refid="sporadicQueryPageSql"/>
  782. </select>
  783. <sql id="sporadicQueryPageSql">
  784. <if test="organId != null">
  785. AND FIND_IN_SET(spo.organ_id_,#{organId})
  786. </if>
  787. <if test="search != null">
  788. AND (sci.title_ LIKE CONCAT('%',#{search},'%') OR su.username_ LIKE CONCAT('%',#{search},'%'))
  789. </if>
  790. <if test="chargeType != null">
  791. AND sci.charge_type_ = #{chargeType}
  792. </if>
  793. <if test="payStatus != null">
  794. AND spo.status_ = #{payStatus}
  795. </if>
  796. </sql>
  797. <resultMap id="luckStatis" type="com.ym.mec.biz.dal.dto.OrderStatisDto">
  798. <result property="organId" column="organId"/>
  799. <result property="organName" column="organName"/>
  800. <result property="estimatedNums" column="estimatedNums"/>
  801. <result property="nums" column="nums"/>
  802. <result property="times" column="times"/>
  803. <result property="scale" column="scale"/>
  804. <result property="money" column="money"/>
  805. </resultMap>
  806. <select id="getLuckStatis" resultMap="luckStatis">
  807. SELECT o.name_ organName, SUM(spo.actual_amount_) money, COUNT(spo.id_) nums
  808. FROM student_payment_order spo
  809. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  810. WHERE spo.type_ = 'LUCK'
  811. AND spo.status_ = 'SUCCESS' and spo.tenant_id_ = #{tenantId}
  812. GROUP BY spo.organ_id_
  813. ORDER BY nums DESC;
  814. </select>
  815. <select id="queryIncomeStatisticsWithCurrentMonth" resultType="map">
  816. select count(*) total,sum(actual_amount_) total_num_ from student_payment_order
  817. where actual_amount_ &gt; 0 and DATE_FORMAT(create_time_, '%Y%m' ) = DATE_FORMAT( CURDATE() , '%Y%m' ) AND
  818. status_ = 'SUCCESS' and organ_id_ not in (36,38)
  819. and FIND_IN_SET(organ_id_,#{organId})
  820. </select>
  821. <select id="countUserBuyVipGroupSuccessOrder" resultType="int">
  822. select count(*)
  823. from student_payment_order
  824. where user_id_ = #{userId}
  825. and music_group_id_ = #{vipGroupId}
  826. and group_type_ = 'VIP'
  827. and status_ = 'SUCCESS'
  828. </select>
  829. <select id="findUserBuyVipGroupOrder" resultMap="StudentPaymentOrder">
  830. select *
  831. from student_payment_order
  832. where user_id_ = #{userId}
  833. and music_group_id_ = #{vipGroupId}
  834. and group_type_ = 'VIP'
  835. </select>
  836. <select id="findUserGroupOrders" resultMap="StudentPaymentOrder">
  837. select * from student_payment_order
  838. where user_id_=#{userId}
  839. and music_group_id_=#{groupId}
  840. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  841. <if test="status!=null">
  842. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  843. </if>
  844. </select>
  845. <select id="getOrderMoneyAmount" parameterType="map" resultMap="StudentPaymentOrder">
  846. SELECT SUM(spo.expect_amount_) expect_amount_,SUM(actual_amount_) actual_amount_,SUM(balance_payment_amount_)
  847. balance_payment_amount_ FROM student_payment_order spo
  848. <include refid="queryPaymentOrder"/>
  849. </select>
  850. <!-- 分页查询 -->
  851. <select id="queryPageOrder" resultMap="PaymentOrderAndStudentInfo" parameterType="map">
  852. SELECT spo.*,u.username_,u.phone_,o.name_ organ_name_ FROM student_payment_order spo
  853. left join sys_user u on spo.user_id_ = u.id_
  854. left join organization o on o.id_ = spo.organ_id_
  855. <include refid="queryPaymentOrder"/>
  856. ORDER BY spo.id_ DESC
  857. <include refid="global.limit"/>
  858. </select>
  859. <select id="findOrderByGroup" resultMap="StudentPaymentOrder">
  860. SELECT * FROM student_payment_order
  861. WHERE music_group_id_=#{groupId}
  862. and group_type_=#{groupType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  863. <if test="status!=null">
  864. and status_=#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  865. </if>
  866. </select>
  867. <select id="sumPerAccountAmount" resultType="java.math.BigDecimal"><![CDATA[
  868. SELECT SUM(per_amount_)
  869. FROM student_payment_order
  870. WHERE FIND_IN_SET(status_, 'SUCCESS,ING')
  871. AND create_time_ >= #{firstDate}
  872. AND create_time_ <= NOW()
  873. AND FIND_IN_SET(#{merNo}, mer_nos_)
  874. ]]>
  875. </select>
  876. <select id="getChargeAmount" parameterType="map" resultType="java.math.BigDecimal">
  877. SELECT SUM(actual_amount_) FROM student_payment_order spo
  878. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_ = sci.id_
  879. <include refid="queryPaymentOrder"/>
  880. </select>
  881. <select id="sumAccountAmount" resultType="java.math.BigDecimal">
  882. <![CDATA[
  883. SELECT SUM(actual_amount_)
  884. FROM student_payment_order
  885. WHERE status_ IN ('SUCCESS', 'ING')
  886. AND create_time_ >= #{firstDate}
  887. AND create_time_ <= NOW()
  888. AND mer_nos_ = #{merNo}
  889. ]]></select>
  890. <select id="countGroupOrderWithoutFailed" resultType="int">
  891. SELECT COUNT(*)
  892. FROM student_payment_order spo
  893. WHERE spo.music_group_id_ = #{groupId}
  894. AND spo.status_ NOT IN ('FAILED','CLOSE')
  895. AND spo.group_type_ = #{groupType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler }
  896. </select>
  897. <select id="countSporadicOrder" resultType="java.lang.Integer">
  898. SELECT COUNT(id_)
  899. FROM student_payment_order spo
  900. WHERE spo.group_type_ = 'SPORADIC'
  901. AND spo.music_group_id_ = #{sporadicId}
  902. </select>
  903. <!-- 查找支付成功和支付中订单 -->
  904. <select id="findOrganPayOrderNum" resultType="int">
  905. SELECT COUNT(*)
  906. FROM student_payment_order
  907. WHERE organ_id_ = #{organId}
  908. AND status_ IN ('SUCCESS', 'ING')
  909. </select>
  910. <!-- 获取每月用户的对应类型订单订单 -->
  911. <select id="getOrderByMonthAndType" resultType="com.ym.mec.biz.dal.dto.OrderByTypeExportDto">
  912. SELECT o.name_ organName, spo.user_id_ studentId,su.username_ studentName,spo.type_ orderType,
  913. spo.actual_amount_ actualAmount,spo.music_group_id_ musicGroupId,spo.group_type_ groupType,spo.create_time_
  914. createTime
  915. FROM student_payment_order spo
  916. LEFT JOIN sys_user su on spo.user_id_ = su.id_
  917. LEFT JOIN organization o ON o.id_ = spo.id_
  918. WHERE spo.status_ = 'SUCCESS'
  919. AND FIND_IN_SET (spo.organ_id_,#{organIds})
  920. <if test="orderTypeList != null">
  921. AND spo.type_ IN
  922. <foreach collection="orderTypeList" item="orderType" open="(" close=")"
  923. separator=",">
  924. #{orderType}
  925. </foreach>
  926. </if>
  927. <if test="startTime != null">
  928. AND spo.create_time_ >= #{startTime}
  929. </if>
  930. <if test="endTime != null"><![CDATA[
  931. AND spo.create_time_ <= #{endTime}
  932. ]]></if>
  933. AND spo.actual_amount_ > 0
  934. </select>
  935. <select id="getUsers" resultType="com.ym.mec.biz.dal.dto.BasicUserDto">
  936. SELECT username_ name, id_ userId, phone_ phone
  937. FROM sys_user
  938. WHERE id_ = #{search}
  939. OR username_ LIKE CONCAT('%', #{search}, '%')
  940. OR phone_ LIKE CONCAT('%', #{search}, '%')
  941. </select>
  942. <select id="lockOrder" resultMap="StudentPaymentOrder">
  943. SELECT *
  944. FROM student_payment_order
  945. WHERE id_ = #{id} FOR
  946. UPDATE
  947. </select>
  948. <select id="doubleEleven2020Statis" resultMap="luckStatis">
  949. SELECT o.id_ organId, o.name_ organName, SUM(spo.actual_amount_) money, COUNT(DISTINCT spo.user_id_) nums,
  950. SUM(IF(spo.class_group_id_ is null ,1,spo.class_group_id_)) times FROM student_payment_order spo
  951. LEFT JOIN organization o ON o.id_ = spo.organ_id_
  952. WHERE spo.type_ = 'DOUBLE_ELEVEN2020'
  953. AND spo.status_ = 'SUCCESS'
  954. AND spo.organ_id_ IN
  955. <foreach collection="organs" item="organ" open="(" close=")" separator=",">
  956. #{organ.id}
  957. </foreach>
  958. GROUP BY spo.organ_id_
  959. </select>
  960. <select id="getUserOrderNumByType" resultType="int">
  961. SELECT COUNT(*)
  962. FROM student_payment_order
  963. WHERE user_id_ = #{userId}
  964. AND status_ = 'SUCCESS'
  965. AND type_ = #{orderType}
  966. </select>
  967. <select id="getUserOrderByType" resultMap="StudentPaymentOrder">
  968. 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}
  969. </select>
  970. <select id="queryDouble11Students" resultMap="StudentVipDouble11Dto">
  971. SELECT
  972. su.id_ userId,
  973. su.username_ userName,
  974. su.phone_ phone,
  975. su.avatar_ avatar,
  976. SUM(CASE WHEN sci.title_ LIKE '%1V1%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_one_time_,
  977. SUM(CASE WHEN sci.title_ LIKE '%1V2%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_two_time_
  978. FROM
  979. student_payment_order spo
  980. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  981. LEFT JOIN student s ON spo.user_id_=s.user_id_
  982. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  983. WHERE
  984. spo.status_ = 'SUCCESS'
  985. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  986. AND sci.title_ LIKE '双十一%'
  987. AND s.teacher_id_= #{teacherId}
  988. <if test="search!=null and search!=''">
  989. AND (su.phone_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
  990. </if>
  991. GROUP BY
  992. spo.user_id_
  993. ORDER BY spo.user_id_
  994. <include refid="global.limit" />
  995. </select>
  996. <select id="countDouble11Students" resultType="int">
  997. SELECT
  998. COUNT(DISTINCT spo.user_id_)
  999. FROM
  1000. student_payment_order spo
  1001. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  1002. LEFT JOIN student s ON spo.user_id_=s.user_id_
  1003. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  1004. WHERE
  1005. spo.status_ = 'SUCCESS'
  1006. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  1007. AND sci.title_ LIKE '双十一%'
  1008. AND s.teacher_id_= #{teacherId}
  1009. <if test="search!=null and search!=''">
  1010. AND (su.phone_=#{search} OR su.username_ LIKE CONCAT('%', #{search}, '%'))
  1011. </if>;
  1012. </select>
  1013. <select id="findStudentsDouble11Infos" resultMap="StudentVipDouble11Dto">
  1014. SELECT
  1015. su.id_ userId,
  1016. su.username_ userName,
  1017. su.phone_ phone,
  1018. su.avatar_ avatar,
  1019. SUM(CASE WHEN sci.title_ LIKE '%1V1%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_one_time_,
  1020. SUM(CASE WHEN sci.title_ LIKE '%1V2%' THEN spo.class_group_id_ ELSE 0 END) payment_one_to_two_time_
  1021. FROM
  1022. student_payment_order spo
  1023. LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_=sci.id_
  1024. LEFT JOIN student s ON spo.user_id_=s.user_id_
  1025. LEFT JOIN sys_user su ON spo.user_id_ = su.id_
  1026. WHERE
  1027. spo.status_ = 'SUCCESS'
  1028. AND spo.type_ = 'DOUBLE_ELEVEN2020'
  1029. AND sci.title_ LIKE '双十一%'
  1030. AND spo.user_id_ IN
  1031. <foreach collection="studentIds" item="studentId" open="(" close=")" separator=",">
  1032. #{studentId}
  1033. </foreach>
  1034. GROUP BY
  1035. spo.user_id_
  1036. </select>
  1037. <resultMap type="com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto" id="applyOrderAndDetail"
  1038. extends="StudentPaymentOrder">
  1039. <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
  1040. <result column="detail_id_" property="id"/>
  1041. <result column="detail_type_" property="type"/>
  1042. <result column="detail_price_" property="price"/>
  1043. <result column="detail_kit_group_purchase_type_" property="kitGroupPurchaseType"/>
  1044. <collection property="goodsList" ofType="com.ym.mec.biz.dal.entity.Goods">
  1045. <result column="goods_id" property="id"/>
  1046. <result column="goods_name" property="name"/>
  1047. <result column="complementGoodsIdList" property="complementGoodsIdList"/>
  1048. </collection>
  1049. </collection>
  1050. </resultMap>
  1051. <select id="getUserApplyOrders" resultMap="applyOrderAndDetail" parameterType="map">
  1052. SELECT spo.*,spod.id_ detail_id_,spod.type_ detail_type_,spod.price_
  1053. detail_price_,spod.kit_group_purchase_type_ detail_kit_group_purchase_type_,
  1054. g.id_ goods_id, g.name_ goods_name,g.complement_goods_id_list_ complementGoodsIdList
  1055. FROM student_payment_order spo
  1056. LEFT JOIN student_payment_order_detail spod on spo.id_ = spod.payment_order_id_
  1057. LEFT JOIN goods g on FIND_IN_SET(g.id_,spod.goods_id_list_)
  1058. WHERE spo.user_id_ = #{userId} AND spo.type_='APPLY' AND spo.music_group_id_=#{musicGroupId}
  1059. ORDER BY spo.id_ desc
  1060. </select>
  1061. <select id="getAdaPayOrdersByTime" resultMap="StudentPaymentOrder"><![CDATA[
  1062. SELECT * FROM student_payment_order WHERE pay_time_ >= #{startTime} AND pay_time_ <= #{endTime} AND payment_channel_='ADAPAY' AND status_ ='SUCCESS']]>
  1063. </select>
  1064. <select id="getUserReplacementIngOrder" resultMap="StudentPaymentOrder">
  1065. SELECT * FROM student_payment_order WHERE user_id_=#{userId} AND music_group_id_ = #{replacementId} AND status_ = 'ING' LIMIT 1
  1066. </select>
  1067. <select id="getMoneyInMusicApply" resultMap="Mapper">
  1068. 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_
  1069. FROM student_payment_order spo
  1070. LEFT JOIN student_registration sr ON sr.user_id_ = spo.user_id_
  1071. 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_
  1072. FROM subject_change WHERE id_ in
  1073. (SELECT max(sc.id_) id_ from subject_change sc WHERE sc.status_ = 2 GROUP BY music_group_id_,student_id_ ORDER BY id_ DESC)
  1074. ) a on spo.music_group_id_ = a.music_group_id_ and spo.id_ = a.original_order_id_
  1075. WHERE spo.music_group_id_ IN
  1076. <foreach collection="musicGroupIds" item="musicGroupId" open="(" close=")" separator=",">
  1077. #{musicGroupId}
  1078. </foreach>
  1079. AND spo.type_ = 'APPLY' AND spo.status_ = 'SUCCESS' AND sr.music_group_id_ = spo.music_group_id_ AND sr.music_group_status_ = 'NORMAL'
  1080. GROUP BY spo.music_group_id_
  1081. </select>
  1082. <select id="getOrderIdByMusical" resultType="java.lang.Integer">
  1083. SELECT DISTINCT spo.id_ FROM student_payment_order spo
  1084. LEFT JOIN student_payment_order_detail spod ON spo.id_ = spod.payment_order_id_
  1085. WHERE spo.type_ = 'APPLY' AND spo.status_ = 'SUCCESS' AND spo.music_group_id_ = #{musicGroupId}
  1086. AND spo.user_id_ = #{studentId} AND spod.type_ = 'MUSICAL'
  1087. </select>
  1088. <select id="queryStudentCourseAmountMap" resultType="java.util.Map">
  1089. SELECT user_id_ 'key',expect_amount_ - coupon_remit_fee_ 'value' FROM student_payment_order
  1090. WHERE status_ = 'SUCCESS' AND music_group_id_ = #{vipGroupId}
  1091. GROUP BY user_id_
  1092. </select>
  1093. <select id="queryStudentDoubleElevenOrder" resultType="java.lang.String">
  1094. SELECT GROUP_CONCAT(activity_id_) FROM student_payment_order
  1095. WHERE type_ = 'SMALL_CLASS_TO_BUY' AND group_type_ = 'ACTIVITY' AND memo_ = '2022双十一活动购买' AND status_ = 'SUCCESS' AND user_id_ = #{userId}
  1096. </select>
  1097. <select id="findByCalenderId" resultMap="StudentPaymentOrder">
  1098. SELECT * FROM student_payment_order WHERE calender_id_ = #{calenderId} AND status_ = 'SUCCESS' AND user_id_ = #{userId}
  1099. </select>
  1100. <resultMap type="com.ym.mec.biz.dal.vo.StudentPaymentOrderVo" id="QueryOrderDetail">
  1101. <result column="orderNo" property="orderNo"/>
  1102. <result column="memo_" property="memo"/>
  1103. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  1104. <result column="orderType" property="orderType"/>
  1105. <result column="orderTypeCode" property="orderTypeCode"/>
  1106. <result column="totalAmount" property="totalAmount"/>
  1107. <result column="actualAmount" property="actualAmount"/>
  1108. <result column="balanceAmount" property="balanceAmount"/>
  1109. <result column="actualAmount" property="actualAmount"/>
  1110. <result column="createTime" property="createTime"/>
  1111. <result column="payTime" property="payTime"/>
  1112. <result column="transNo" property="transNo"/>
  1113. <result column="totalRemitFee" property="totalRemitFee"/>
  1114. <collection property="list" ofType="com.ym.mec.biz.dal.vo.StudentPaymentOrderVo$StudentPaymentDetailVo">
  1115. <result column="goodsName" property="goodsName"/>
  1116. <result column="price" property="price"/>
  1117. </collection>
  1118. </resultMap>
  1119. <select id="queryStudentOrderPage" resultMap="QueryOrderDetail">
  1120. select
  1121. a.order_no_ as orderNo,
  1122. a.status_ ,a.memo_,
  1123. a.type_ as orderType,
  1124. a.type_ as orderTypeCode,
  1125. ifnull(a.actual_amount_, 0) + ifnull(a.balance_payment_amount_, 0) as totalAmount,
  1126. a.create_time_ as createTime
  1127. from student_payment_order as a
  1128. where create_time_ >= #{param.startDate}
  1129. and create_time_ <![CDATA[ < ]]> #{param.endDate}
  1130. and user_id_ = #{param.userId}
  1131. <if test="param.status != null">
  1132. and status_ = #{param.status}
  1133. </if>
  1134. </select>
  1135. <select id="queryOrderDetail" resultMap="QueryOrderDetail">
  1136. select
  1137. a.order_no_ as orderNo,
  1138. a.status_ ,a.memo_,
  1139. a.type_ as orderType,
  1140. ifnull(a.actual_amount_, 0) + ifnull(a.balance_payment_amount_, 0) + ifnull(a.remit_fee_, 0) +
  1141. ifnull(a.coupon_remit_fee_, 0) as totalAmount,
  1142. a.actual_amount_ as actualAmount,
  1143. a.balance_payment_amount_ as balanceAmount,
  1144. ifnull(a.remit_fee_,0) + ifnull(a.coupon_remit_fee_,0) as totalRemitFee,
  1145. a.create_time_ as createTime,
  1146. a.pay_time_ as payTime,
  1147. a.trans_no_ as transNo,
  1148. b.type_ as goodsName,
  1149. ifnull(b.price_, 0) as price
  1150. from student_payment_order as a
  1151. left join
  1152. student_payment_order_detail as b on a.id_ = b.payment_order_id_
  1153. where a.order_no_ = #{orderNo}
  1154. </select>
  1155. <select id="getStudentMusicOrderNum" resultType="int">
  1156. SELECT COUNT(0) FROM student_payment_order spo
  1157. WHERE spo.music_group_id_ = #{musicGroupId} AND spo.user_id_ = #{userId} AND group_type_ = 'MUSIC' AND status_ = 'SUCCESS' AND spo.id_ &lt; #{orderId}
  1158. </select>
  1159. <select id="getMemberIngOrder" resultType="com.ym.mec.biz.dal.entity.StudentPaymentOrder">
  1160. SELECT *
  1161. FROM student_payment_order
  1162. WHERE music_group_id_ IS NULL
  1163. AND type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  1164. AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  1165. LIMIT 1
  1166. </select>
  1167. <select id="countByActivityIds" resultType="java.lang.Integer">
  1168. SELECT COUNT(0) FROM student_payment_order WHERE user_id_ = #{userId} AND status_ = 'SUCCESS' AND activity_id_ IN
  1169. <foreach collection="activityIds" item="activityId" open="(" close=")" separator=",">
  1170. #{activityId}
  1171. </foreach>
  1172. </select>
  1173. </mapper>