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.

220 lines
9.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 liveChannel,
  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.liveChannel != null and beanConsumeLive.liveChannel != ''">
  57. AND t.liveChannel= #{beanConsumeLive.liveChannel}
  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.liveChannel != null and beanConsumeLive.liveChannel != ''">
  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.liveChannel}
  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="selectFanBy" resultType="com.example.demo.domain.vo.bean.BeanConsumeFan">
  121. SELECT fm.nickname AS name,
  122. fm.jwcode,
  123. fm.dept,
  124. fyr.money AS beanNum,
  125. fyr.source_name AS channel,
  126. fyr.source_type AS type,
  127. FROM_UNIXTIME(fyr.time, '%Y-%m-%d %H:%i:%s') AS consumeTime,
  128. fyr.pay_type AS payType
  129. FROM fx_member fm
  130. INNER JOIN fx_yaoqing_records fyr ON fyr.uid = fm.id
  131. <where>
  132. fyr.pay_type IN (7)
  133. <if test="beanConsumeFan.jwcode != null and beanConsumeFan.jwcode != ''">
  134. AND fm.jwcode = #{beanConsumeFan.jwcode}
  135. </if>
  136. <if test="beanConsumeFan.dept != null and beanConsumeFan.dept != ''">
  137. AND fm.dept = #{beanConsumeFan.dept}
  138. </if>
  139. <if test="beanConsumeFan.channel != null and beanConsumeFan.channel != ''">
  140. AND fyr.source_name =#{beanConsumeFan.channel}
  141. </if>
  142. <if test="beanConsumeFan.startTime != null and beanConsumeFan.endTime != null">
  143. AND fyr.time BETWEEN UNIX_TIMESTAMP(#{beanConsumeFan.startTime})
  144. AND UNIX_TIMESTAMP(#{beanConsumeFan.endTime})
  145. </if>
  146. </where>
  147. <choose>
  148. <when test="beanConsumeFan.sortField != null and beanConsumeFan.sortField != '' and beanConsumeFan.sortOrder != null and beanConsumeFan.sortOrder != ''">
  149. ORDER BY ${beanConsumeFan.sortField} ${beanConsumeFan.sortOrder}
  150. </when>
  151. <otherwise>
  152. ORDER BY consumeTime DESC
  153. </otherwise>
  154. </choose>
  155. </select>
  156. <!--铁粉消耗合计数-->
  157. <select id="selectSumFansBy" resultType="com.example.demo.domain.vo.bean.BeanConsumeGold">
  158. SELECT
  159. IFNULL(SUM(t.money_buy), 0) AS permanentBean,
  160. IFNULL(SUM(t.money_free), 0) AS freeBean,
  161. COUNT(*) AS totalNum
  162. FROM (
  163. SELECT
  164. fyr.money_buy,
  165. fyr.money_free,
  166. fyr.time
  167. FROM fx_member fm
  168. INNER JOIN fx_yaoqing_records fyr ON fyr.uid = fm.id
  169. <where>
  170. fyr.pay_type = 7
  171. <if test="beanConsumeFan.jwcode != null and beanConsumeFan.jwcode != ''">
  172. AND fm.jwcode = #{beanConsumeFan.jwcode}
  173. </if>
  174. <if test="beanConsumeFan.dept != null and beanConsumeFan.dept != ''">
  175. AND fm.dept = #{beanConsumeFan.dept}
  176. </if>
  177. <if test="beanConsumeFan.channel != null and beanConsumeFan.channel != ''">
  178. AND fyr.source_name = #{beanConsumeFan.channel}
  179. </if>
  180. <if test="beanConsumeFan.startTime != null and beanConsumeFan.endTime != null">
  181. AND fyr.time BETWEEN UNIX_TIMESTAMP(#{beanConsumeFan.startTime})
  182. AND UNIX_TIMESTAMP(#{beanConsumeFan.endTime})
  183. </if>
  184. </where>
  185. ) AS t
  186. </select>
  187. <select id="getLiveGift" resultType="java.lang.String">
  188. SELECT DISTINCT
  189. CASE
  190. WHEN LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
  191. THEN SUBSTRING(content, LOCATE('送礼物', content) + CHAR_LENGTH('送礼物'))
  192. ELSE NULL
  193. END AS gift
  194. FROM fx_yaoqing_records
  195. WHERE LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
  196. AND content IS NOT NULL AND source_type=1
  197. </select>
  198. <select id="getLiveChannel" resultType="java.lang.String">
  199. SELECT DISTINCT
  200. CASE
  201. WHEN LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
  202. THEN SUBSTRING_INDEX(SUBSTRING(content, LOCATE('直播间', content) + CHAR_LENGTH('直播间')), '送礼物', 1)
  203. ELSE NULL
  204. END AS liveChannel
  205. FROM fx_yaoqing_records
  206. WHERE LOCATE('直播间', content) > 0 AND LOCATE('送礼物', content) > 0
  207. AND content IS NOT NULL AND pay_type in (1,2,3,4,5)
  208. </select>
  209. </mapper>