StudentPaymentOrderMapper.xml 59 KB

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