You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
6.6 KiB

  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. <mapper namespace="com.example.demo.mapper.bean.BeanConsumeMapper">
  4. <!--获取消费用户分部-->
  5. <select id="getDept" resultType="java.lang.String">
  6. select distinct fm.dept
  7. from fx_member fm
  8. inner join fx_yaoqing_records fyr on fyr.uid = fm.id
  9. where fm.dept is not null and fm.dept != ''
  10. </select>
  11. <!--筛选查询直播消费-->
  12. <select id="selectLiveBy" resultType="com.example.demo.domain.vo.bean.BeanConsumeLive">
  13. SELECT *
  14. FROM (
  15. SELECT fm.nickname AS name,
  16. fm.jwcode,
  17. fm.dept,
  18. fyr.source_type AS type,
  19. CASE
  20. WHEN LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
  21. THEN SUBSTRING(content, LOCATE('送礼物', content) + CHAR_LENGTH('送礼物'))
  22. ELSE NULL
  23. END AS gift,
  24. fyr.money AS beanNum,
  25. CASE
  26. WHEN LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
  27. THEN SUBSTRING_INDEX(SUBSTRING(content, LOCATE('直播间', content) + CHAR_LENGTH('直播间')), '送礼物', 1)
  28. ELSE NULL
  29. END AS channel,
  30. fyr.source_name AS liveName,
  31. FROM_UNIXTIME(fyr.time, '%Y-%m-%d %H:%i:%s') AS consumeTime,
  32. fyr.pay_type AS payType
  33. FROM fx_member fm
  34. INNER JOIN fx_yaoqing_records fyr ON fyr.uid = fm.id
  35. <where>
  36. fyr.pay_type IN (1,2,3,4,5)
  37. <if test="beanConsumeLive.jwcode != null and beanConsumeLive.jwcode != ''">
  38. AND fm.jwcode = #{beanConsumeLive.jwcode}
  39. </if>
  40. <if test="beanConsumeLive.dept != null and beanConsumeLive.dept != ''">
  41. AND fm.dept = #{beanConsumeLive.dept}
  42. </if>
  43. <if test="beanConsumeLive.type != null and beanConsumeLive.type != ''">
  44. AND fyr.source_type = #{beanConsumeLive.type}
  45. </if>
  46. <if test="beanConsumeLive.startTime != null and beanConsumeLive.endTime != null">
  47. AND fyr.time BETWEEN UNIX_TIMESTAMP(#{beanConsumeLive.startTime})
  48. AND UNIX_TIMESTAMP(#{beanConsumeLive.endTime})
  49. </if>
  50. </where>
  51. ) AS t
  52. <where>
  53. <if test="beanConsumeLive.gift != null and beanConsumeLive.gift != ''">
  54. AND t.gift = #{beanConsumeLive.gift}
  55. </if>
  56. <if test="beanConsumeLive.channel != null and beanConsumeLive.channel != ''">
  57. AND t.channel= #{beanConsumeLive.channel}
  58. </if>
  59. <if test="beanConsumeLive.liveName != null and beanConsumeLive.liveName != ''">
  60. AND t.liveName LIKE CONCAT('%', #{beanConsumeLive.liveName}, '%')
  61. </if>
  62. </where>
  63. <choose>
  64. <when test="beanConsumeLive.sortField != null and beanConsumeLive.sortField != '' and beanConsumeLive.sortOrder != null and beanConsumeLive.sortOrder != ''">
  65. ORDER BY t.${beanConsumeLive.sortField} ${beanConsumeLive.sortOrder}
  66. </when>
  67. <otherwise>
  68. ORDER BY t.consumeTime DESC
  69. </otherwise>
  70. </choose>
  71. </select>
  72. <!--查询消费直播合计数-->
  73. <select id="selectSumLiveBy" resultType="com.example.demo.domain.vo.bean.BeanConsumeGold">
  74. SELECT
  75. IFNULL(SUM(t.money_buy), 0) AS permanentBean,
  76. IFNULL(SUM(t.money_free), 0) AS freeBean,
  77. COUNT(*) AS totalNum
  78. FROM (
  79. SELECT
  80. fyr.money_buy,
  81. fyr.money_free,
  82. fyr.time
  83. FROM fx_member fm
  84. INNER JOIN fx_yaoqing_records fyr ON fyr.uid = fm.id
  85. <where>
  86. fyr.pay_type IN (1,2,3,4,5)
  87. <if test="beanConsumeLive.jwcode != null and beanConsumeLive.jwcode != ''">
  88. AND fm.jwcode = #{beanConsumeLive.jwcode}
  89. </if>
  90. <if test="beanConsumeLive.dept != null and beanConsumeLive.dept != ''">
  91. AND fm.dept = #{beanConsumeLive.dept}
  92. </if>
  93. <if test="beanConsumeLive.type != null and beanConsumeLive.type != ''">
  94. AND fyr.source_type = #{beanConsumeLive.type}
  95. </if>
  96. <if test="beanConsumeLive.gift != null and beanConsumeLive.gift != ''">
  97. AND CASE
  98. WHEN LOCATE('直播间', fyr.content) > 0 AND LOCATE('送礼物', fyr.content) > 0
  99. THEN SUBSTRING(fyr.content, LOCATE('送礼物', fyr.content) + CHAR_LENGTH('送礼物'))
  100. ELSE NULL
  101. END = #{beanConsumeLive.gift}
  102. </if>
  103. <if test="beanConsumeLive.channel != null and beanConsumeLive.channel != ''">
  104. AND CASE
  105. WHEN LOCATE('直播间', fyr.content) > 0 AND LOCATE('送礼物', fyr.content) > 0
  106. THEN SUBSTRING_INDEX(SUBSTRING(fyr.content, LOCATE('直播间', fyr.content) + CHAR_LENGTH('直播间')), '送礼物', 1)
  107. ELSE NULL
  108. END = #{beanConsumeLive.channel}
  109. </if>
  110. <if test="beanConsumeLive.startTime != null and beanConsumeLive.endTime != null">
  111. AND fyr.time BETWEEN UNIX_TIMESTAMP(#{beanConsumeLive.startTime})
  112. AND UNIX_TIMESTAMP(#{beanConsumeLive.endTime})
  113. </if>
  114. <if test="beanConsumeLive.liveName != null and beanConsumeLive.liveName != ''">
  115. AND fyr.source_name LIKE CONCAT('%', #{beanConsumeLive.liveName}, '%')
  116. </if>
  117. </where>
  118. ) AS t
  119. </select>
  120. <select id="getLiveGift" resultType="java.lang.String">
  121. SELECT DISTINCT
  122. CASE
  123. WHEN LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
  124. THEN SUBSTRING(content, LOCATE('送礼物', content) + CHAR_LENGTH('送礼物'))
  125. ELSE NULL
  126. END AS gift
  127. FROM fx_yaoqing_records
  128. WHERE LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
  129. AND content IS NOT NULL AND source_type=1
  130. </select>
  131. <select id="getLiveChannel" resultType="java.lang.String">
  132. SELECT DISTINCT
  133. CASE
  134. WHEN LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
  135. THEN SUBSTRING_INDEX(SUBSTRING(content, LOCATE('直播间', content) + CHAR_LENGTH('直播间')), '送礼物', 1)
  136. ELSE NULL
  137. END AS channel
  138. FROM fx_yaoqing_records
  139. WHERE LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
  140. AND content IS NOT NULL AND pay_type in (1,2,3,4,5)
  141. </select>
  142. </mapper>