StatisticsExportMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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.cyksj.mapper.manage.statistics.StatisticsExportMapper">
  4. <select id="getMonthNfExNumOfUser" resultType="java.lang.Integer">
  5. select count(distinct user_id)
  6. from (select user_id
  7. from `order_don`
  8. where sku_id = 4
  9. and status not in ('close', 'noPayment', 'refund')
  10. and created_time between #{lastMonth} and #{thisMonth}
  11. union all
  12. select user_id
  13. from `order_don`
  14. where sku_id = 5
  15. and status not in ('close', 'noPayment', 'refund')
  16. and created_time between #{lastThreeMonth} and #{lastTwoMonth}
  17. union all
  18. select user_id
  19. from `order_don`
  20. where sku_id = 6
  21. and status not in ('close', 'noPayment', 'refund')
  22. and created_time between #{lastYearMonth}
  23. and #{lastElevMonth}
  24. ) s
  25. </select>
  26. <select id="getMonthNfExNumOfUserByType" resultType="java.lang.Integer">
  27. select count(distinct user_id)
  28. from (select user_id
  29. from `order_don`
  30. where sku_id = 4
  31. and status not in ('close', 'noPayment', 'refund')
  32. and created_time between #{lastMonth} and #{thisMonth}
  33. union all
  34. select user_id
  35. from `order_don`
  36. where sku_id = 5
  37. and status not in ('close', 'noPayment', 'refund')
  38. and created_time between #{lastThreeMonth} and #{lastTwoMonth}
  39. union all
  40. select user_id
  41. from `order_don`
  42. where sku_id = 6
  43. and status not in ('close', 'noPayment', 'refund')
  44. and created_time between #{lastYearMonth}
  45. and #{lastElevMonth}) s
  46. where EXISTS(select id
  47. from order_don od
  48. where status not in ('close', 'refund', 'noPayment')
  49. and created_time between #{thisMonth} and #{nextMonth}
  50. and order_type = #{type}
  51. and od.user_id = s.user_id
  52. and goods_id = #{goodsId})
  53. </select>
  54. <select id="getMonthNfRenewNumOfUser" resultType="java.lang.Integer">
  55. select count(distinct user_id)
  56. from `order_don`
  57. where goods_id = #{goodsId}
  58. and order_type = 2
  59. and status not in ('close', 'refund', 'noPayment')
  60. and created_time between #{thisMonth} and #{nextMonth}
  61. </select>
  62. <select id="getAiMonthPlus" resultType="java.lang.Long">
  63. select id
  64. from `goods_don_sku`
  65. where goods_id = #{goodsId}
  66. and months = 1
  67. </select>
  68. <select id="getMonthAiExNumOfUser" resultType="java.lang.Integer">
  69. select count(distinct user_id)
  70. from `order_don` od
  71. where status not in ('close','refund','noPayment')
  72. and created_time BETWEEN #{lastMonth} and #{thisMonth}
  73. and sku_id in
  74. <foreach collection="skuIds" item="item" open="(" separator="," close=")">
  75. #{item}
  76. </foreach>
  77. </select>
  78. <select id="getMonthAiExNumOfUserByType" resultType="java.lang.Integer">
  79. select count(distinct user_id) from (select user_id
  80. from `order_don` od
  81. where status not in ('close','refund','noPayment')
  82. and created_time BETWEEN #{lastMonth} and #{thisMonth}
  83. and sku_id in
  84. <foreach collection="skuIds" item="item" open="(" separator="," close=")">
  85. #{item}
  86. </foreach>) s where EXISTS(select id
  87. from order_don
  88. where status not in ('close','refund','noPayment')
  89. and created_time between #{thisMonth} and #{nextMonth}
  90. and order_type = #{type}
  91. and user_id = s.user_id
  92. and sku_id in
  93. <foreach collection="skuIds" item="item" open="(" separator="," close=")">
  94. #{item}
  95. </foreach>
  96. )
  97. </select>
  98. <select id="getMonthAiRenewNumOfUser" resultType="java.lang.Integer">
  99. select count(distinct user_id)
  100. from `order_don` od
  101. where status not in ('close','refund','noPayment')
  102. and created_time BETWEEN #{thisMonth} and #{nextMonth}
  103. and order_type = 2
  104. and sku_id in
  105. <foreach collection="skuIds" item="item" open="(" separator="," close=")">
  106. #{item}
  107. </foreach>
  108. </select>
  109. <select id="getMonthStreamingNewNumOfUser" resultType="java.lang.Integer">
  110. select count(DISTINCT user_id)
  111. from (select user_id, created_time
  112. from `order_don`
  113. where goods_id in
  114. (select goods_id
  115. from `goods_don_category_relate`
  116. where category = 2)
  117. and status not in ('close', 'refund', 'noPayment')
  118. and created_time BETWEEN
  119. #{thisMonth} and #{nextMonth}) s
  120. where not EXISTS(select id
  121. from order_don od
  122. where status not in ('close', 'refund', 'noPayment')
  123. and od.user_id = s.user_id
  124. and od.created_time &lt;
  125. s.created_time)
  126. </select>
  127. <select id="getMonthStreamingNewPayOtherNumOfUser" resultType="java.lang.Integer">
  128. select count(DISTINCT user_id)
  129. from (select user_id, created_time
  130. from `order_don`
  131. where goods_id in
  132. (select goods_id
  133. from `goods_don_category_relate`
  134. where category = 2)
  135. and status not in ('close', 'refund', 'noPayment')
  136. and created_time BETWEEN
  137. #{thisMonth} and #{nextMonth}) s
  138. where not EXISTS(select id
  139. from order_don od
  140. where status not in ('close', 'refund', 'noPayment')
  141. and od.user_id = s.user_id
  142. and od.created_time &lt;
  143. s.created_time)
  144. and EXISTS(select id
  145. from order_don od
  146. where status not in ('close', 'refund', 'noPayment')
  147. and od.user_id = s.user_id
  148. and od.created_time between
  149. #{thisMonth} and #{nextMonth}
  150. and od.created_time > s.created_time)
  151. </select>
  152. <select id="getMonthStreamingNewPayAiNumOfUser" resultType="java.lang.Integer">
  153. select count(DISTINCT user_id)
  154. from (select user_id, created_time
  155. from `order_don`
  156. where goods_id in
  157. (select goods_id
  158. from `goods_don_category_relate`
  159. where category = 2)
  160. and status not in ('close', 'refund', 'noPayment')
  161. and created_time BETWEEN
  162. #{thisMonth} and #{nextMonth}) s
  163. where not EXISTS(select id
  164. from order_don od
  165. where status not in ('close', 'refund', 'noPayment')
  166. and od.user_id = s.user_id
  167. and od.created_time &lt;
  168. s.created_time)
  169. and EXISTS(select id
  170. from (select id, goods_id
  171. from order_don od
  172. where status not in ('close', 'refund', 'noPayment')
  173. and od.user_id = s.user_id
  174. and od.created_time between #{thisMonth} and #{nextMonth}
  175. order by od.created_time limit 1,1) s
  176. where s.goods_id in (select goods_id
  177. from `goods_don_category_relate`
  178. where category = 1))
  179. </select>
  180. <select id="getMonthAiNewNumOfUser" resultType="java.lang.Integer">
  181. select count(DISTINCT user_id)
  182. from (select user_id, created_time
  183. from `order_don`
  184. where goods_id in
  185. (select goods_id
  186. from `goods_don_category_relate`
  187. where category = 1)
  188. and status not in ('close', 'refund', 'noPayment')
  189. and created_time BETWEEN
  190. #{thisMonth} and #{nextMonth}) s
  191. where not EXISTS(select id
  192. from order_don od
  193. where status not in ('close', 'refund', 'noPayment')
  194. and od.user_id = s.user_id
  195. and od.created_time &lt;
  196. s.created_time)
  197. </select>
  198. <select id="getMonthAiNewPayOtherNumOfUser" resultType="java.lang.Integer">
  199. select count(DISTINCT user_id)
  200. from (select user_id, created_time
  201. from `order_don`
  202. where goods_id in
  203. (select goods_id
  204. from `goods_don_category_relate`
  205. where category = 1)
  206. and status not in ('close', 'refund', 'noPayment')
  207. and created_time BETWEEN
  208. #{thisMonth} and #{nextMonth}) s
  209. where not EXISTS(select id
  210. from order_don od
  211. where status not in ('close', 'refund', 'noPayment')
  212. and od.user_id = s.user_id
  213. and od.created_time &lt;
  214. s.created_time)
  215. and EXISTS(select id
  216. from order_don od
  217. where status not in ('close', 'refund', 'noPayment')
  218. and od.user_id = s.user_id
  219. and od.created_time between #{thisMonth} and #{nextMonth}
  220. and od.created_time > s.created_time)
  221. </select>
  222. <select id="getMonthAiNewPayStreamingNumOfUser" resultType="java.lang.Integer">
  223. select count(DISTINCT user_id)
  224. from (select user_id, created_time
  225. from `order_don`
  226. where goods_id in
  227. (select goods_id
  228. from `goods_don_category_relate`
  229. where category = 1)
  230. and status not in ('close', 'refund', 'noPayment')
  231. and created_time BETWEEN
  232. #{thisMonth} and #{nextMonth}) s
  233. where not EXISTS(select id
  234. from order_don od
  235. where status not in ('close', 'refund', 'noPayment')
  236. and od.user_id = s.user_id
  237. and od.created_time &lt;
  238. s.created_time)
  239. and EXISTS(select id
  240. from (select id, goods_id
  241. from order_don od
  242. where status not in ('close', 'refund', 'noPayment')
  243. and od.user_id = s.user_id
  244. and od.created_time between #{thisMonth} and #{nextMonth}
  245. order by od.created_time limit 1,1) s
  246. where s.goods_id in (select goods_id
  247. from `goods_don_category_relate`
  248. where category = 2))
  249. </select>
  250. <select id="getMonthPrivateCorpNumOfUser" resultType="java.lang.Integer">
  251. select count(distinct s.user_id) from (select user_id from (select user_id,created_time from `order_don` where
  252. goods_id in
  253. (select id from goods_don
  254. <where>
  255. <if test="category!=null">
  256. and category = #{category}
  257. </if>
  258. <if test="type!=null">
  259. and `type` = #{type}
  260. </if>
  261. </where>
  262. )
  263. and status not in ('close','noPayment','refund')) s where not exists (select id from `order_don` where status
  264. not
  265. in ('close','noPayment','refund')
  266. and user_id= s.user_id and created_time &lt; s.created_time)) s inner join user u on u.id = s.user_id and
  267. u.unionid != '' inner join corp_user cu on cu.user_id =
  268. u.id
  269. inner join corp_user_auth ca on ca.corp_user_id = cu.id and ca.wx_corp_id = 2
  270. </select>
  271. <select id="getShouldApplyMoney" resultType="java.math.BigDecimal">
  272. select sum(points) / 1000
  273. from `distribute_waiting_send_points`
  274. where send_status = 'success'
  275. and created_time &lt; #{endDate}
  276. </select>
  277. <select id="getRealApplyMoney" resultType="java.math.BigDecimal">
  278. select sum(money) / 100
  279. from `distribute_money_apply`
  280. where `verify_status` = 'success'
  281. and created_time &lt; #{endDate}
  282. </select>
  283. <select id="getMonthUserSourceNumByType" resultType="java.lang.Integer">
  284. select count(u.id)
  285. from (select id from `user` where created_time >= #{startDate} and created_time &lt; #{endDate}) u
  286. left join user_distribute_shared us on us.user_id = u.id
  287. left join user_distribute ud on ud.user_id = us.shared_id
  288. <where>
  289. <choose>
  290. <when test="type == 1">
  291. us.id is null
  292. </when>
  293. <otherwise>
  294. us.id is not null
  295. </otherwise>
  296. </choose>
  297. </where>
  298. </select>
  299. <select id="getNfTicketNumOfUser" resultType="java.lang.Integer">
  300. select count(distinct user_id)
  301. from `order_don`
  302. where goods_id = #{goodsId}
  303. and status not in ('close', 'noPayment', 'refund')
  304. </select>
  305. <select id="getAiTicketNumOfUser" resultType="java.lang.Integer">
  306. select count(distinct o.user_id)
  307. from `order_don` o
  308. left join goods_don g on g.id = o.goods_id
  309. where g.id in (select goods_id
  310. from `goods_don_category_relate`
  311. where category = 1)
  312. and o.status not in ('close', 'noPayment', 'refund')
  313. </select>
  314. <select id="getNfAiTicketNumOfUser" resultType="java.lang.Integer">
  315. select count(distinct o.user_id)
  316. from `order_don` o
  317. left join order_don o2 on o2.user_id = o.user_id
  318. left join goods_don g on g.id = o2.goods_id
  319. where o.goods_id = #{goodsId}
  320. and o.status not in ('close', 'noPayment', 'refund')
  321. and o2.status not in ('close', 'noPayment', 'refund')
  322. and g.id in (select goods_id
  323. from `goods_don_category_relate`
  324. where category = 1)
  325. </select>
  326. <select id="getMonthAmountOfOrderByType" resultType="java.math.BigDecimal">
  327. select ifnull((sum(o.money) - ifnull(sum(o.refund_money),0))/100,0) from `order_don` o left join `user_distribute_shared`
  328. us on us.user_id = o.user_Id
  329. left join `user_distribute` ud on ud.user_id = us.shared_id
  330. where
  331. <choose>
  332. <when test="type == 1">
  333. us.id is null
  334. </when>
  335. <when test="type == 2">
  336. us.id is not null and ud.id is null
  337. </when>
  338. <when test="type == 3">
  339. ud.id is not null
  340. </when>
  341. </choose>
  342. and o.created_time >= #{startDate} and o.created_time &lt; #{endDate}
  343. and status not in ('close', 'noPayment')
  344. </select>
  345. <select id="getMonthGoodsTypeAmountOfOrderByType" resultType="java.math.BigDecimal">
  346. select ifnull((sum(o.money) - ifnull(sum(o.refund_money),0))/100,0) from `order_don` o left join `user_distribute_shared`
  347. us on us.user_id = o.user_Id
  348. left join `user_distribute` ud on ud.user_id = us.shared_id
  349. where
  350. <choose>
  351. <when test="type == 1">
  352. us.id is null
  353. </when>
  354. <otherwise>
  355. us.id is not null
  356. </otherwise>
  357. </choose>
  358. <if test="startDate != null">
  359. and o.created_time >= #{startDate}
  360. </if>
  361. <if test="endDate != null">
  362. and o.created_time &lt; #{endDate}
  363. </if>
  364. and status not in ('close', 'noPayment')
  365. and goods_id in (select id from goods_don
  366. <where>
  367. <if test="goodsType != null">
  368. `type` = #{goodsType}
  369. </if>
  370. <if test="category!=null">
  371. and id in (select goods_id from goods_don_category_relate where category = #{category})
  372. </if>
  373. </where>
  374. )
  375. </select>
  376. <select id="getMonthUserSourceNumOrderByType" resultType="java.lang.Integer">
  377. select count(distinct s.id) from (select u.id
  378. from (select id from `user` where created_time >= #{startDate} and created_time &lt; #{endDate}) u
  379. left join user_distribute_shared us on us.user_id = u.id
  380. left join user_distribute ud on ud.user_id = us.shared_id
  381. <where>
  382. <choose>
  383. <when test="type == 1">
  384. us.id is null
  385. </when>
  386. <otherwise>
  387. us.id is not null
  388. </otherwise>
  389. </choose>
  390. </where>
  391. ) s left join order_don o on o.user_id = s.id where o.status not in ('close', 'noPayment','refund')
  392. and o.created_time >= #{startDate} and o.created_time &lt; #{endDate}
  393. </select>
  394. <select id="getAppleOneDataThisMonth" resultType="com.cyksj.model.excel.statistics.ExcelAppleOneData">
  395. select count(distinct if(status = 'refund',NUll,user_id)) as numOfUser,
  396. count(if(status = 'refund',NULL,id)) as numOfOrder,
  397. cast((ifnull(sum(money),0)-ifnull(sum(refund_money),0))/100 as decimal(10,2)) as money,
  398. count(if(type = 'EX_CODE' and status != 'refund',id,NULL)) as numOfExCodeOrder,
  399. count(if(is_distribute = 1 and status != 'refund',id,NULL)) as disOrder,
  400. cast((sum(if(is_distribute = 1,money,0))-ifnull(sum(if(is_distribute = 1,refund_money,0)),0))/100 as
  401. decimal(10,2)) as disMoney
  402. from `order_don`
  403. where sku_id in
  404. <foreach collection="skuIds" item="item" open="(" separator="," close=")">
  405. #{item}
  406. </foreach>
  407. and status not in ('close','noPayment')
  408. <if test="startDate != null">
  409. and created_time >= #{startDate}
  410. </if>
  411. <if test="endDate != null">
  412. and created_time &lt; #{endDate}
  413. </if>
  414. </select>
  415. <select id="getAppleOnePayMonthTypeOrderThisMonth" resultType="java.lang.Integer">
  416. select count(*) from `order_don` where sku_id = #{skuId}
  417. and status not in ('close','noPayment','refund')
  418. <if test="startDate != null">
  419. and created_time >= #{startDate}
  420. </if>
  421. <if test="endDate != null">
  422. and created_time &lt; #{endDate}
  423. </if>
  424. </select>
  425. <select id="getTransferData" resultType="java.util.Map">
  426. select sum(if(money &lt;= 40000, money, 0)) autoMoney,
  427. sum(if(type = 'usdt', money, 0)) usdtMoney,
  428. sum(if(money > 40000 and type != 'usdt', money, 0)) manualMoney
  429. from distribute_money_apply
  430. where created_time >= #{startDate}
  431. and created_time &lt; #{endDate}
  432. and verify_status = 'success'
  433. </select>
  434. <select id="getGroupsOrderData" resultType="com.cyksj.model.dto.NatureOrderDataDto">
  435. select type,
  436. ifnull((sum(money) - ifnull(sum(refund_money),0))/100,0) as money from (select money,
  437. refund_money,
  438. (case
  439. when us.id is null then 1
  440. when us.id is not null and ud.id is null then 2
  441. when ud.id is not null then 3
  442. else 1
  443. end) as `type`
  444. from `order_don` o
  445. left join `user_distribute_shared` us on us.user_id = o.user_Id
  446. left join `user_distribute` ud on ud.user_id = us.shared_id
  447. where status not in ('close', 'noPayment')
  448. <if test="startDate != null">
  449. and o.created_time >= #{startDate}
  450. </if>
  451. <if test="endDate != null">
  452. and o.created_time &lt; #{endDate}
  453. </if>) s group by `type`
  454. </select>
  455. </mapper>