JiaoYangDingPanMapper.xml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ruixuan.jiaoyang.mapper.IJiaoYangDingMapper">
  6. <select id="getPromoterIdsByUserIds" resultType="java.lang.Long">
  7. select promoter_id from jy_kuaishou_promoter where
  8. 1 = 1
  9. and user_id in
  10. <foreach collection="userIds" item="userId" separator="," open="(" close=")">
  11. #{userId}
  12. </foreach>
  13. group by promoter_id
  14. </select>
  15. <select id="getPromoterIdsByBusinessId" resultType="java.lang.Long" parameterType="java.lang.Long">
  16. SELECT promoter_id
  17. FROM jy_kuaishou_promoter
  18. WHERE expert_business_id = #{userId}
  19. GROUP BY promoter_id
  20. </select>
  21. <select id="getPromoterIdsByMentorId" resultType="java.lang.Long" parameterType="java.lang.Long">
  22. SELECT promoter_id
  23. FROM jy_kuaishou_promoter
  24. WHERE expert_mentor_id = #{userId}
  25. GROUP BY promoter_id
  26. </select>
  27. <select id="getSumInfo" resultType="com.alibaba.fastjson.JSONObject">
  28. select t.*,
  29. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  30. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate',
  31. round((t.regimentalPromotionAmount - tt.regimentalPromotionAmount) / tt.regimentalPromotionAmount *100,2) as
  32. 'regimentalPromotionAmountRate',
  33. round((t.grossMargin - tt.grossMargin) / tt.grossMargin * 100, 2) as 'grossMarginRate'
  34. from (
  35. select count(t1.oid) as 'orderNum',
  36. sum(case when t1.order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  37. round(sum(case when t1.order_status != 80 then 1 else 0 end) / count(t1.oid) * 100, 2) as 'validRadio',
  38. sum(case when t2.type = 1 then 1 else 0 end) as 'zyOrderNUm',
  39. sum(case when t2.type = 2 then
  40. 1 else 0 end) as 'fxOrderNUm',
  41. round(sum(t1.pay_amount) / 100, 2) as 'payAmount',
  42. round(sum(case when order_status
  43. != 80 then t1.pay_amount else 0 end) / 100,
  44. 2) as 'validPayAmount',
  45. round(sum(case when t1.order_status != 80 then t1.pay_amount else 0 end) /
  46. sum(t1.pay_amount) * 100,
  47. 2) as 'validPayAmountRadio',
  48. round(sum(case when t2.type = 1 then t1.pay_amount else 0 end) / 1000000, 2) as 'zyPayAmount',
  49. round(sum(case when t2.type = 2 then t1.pay_amount else 0 end) / 1000000, 2) as 'fxPayAmount',
  50. sum(case when
  51. t1.send_status = 1 and t1.order_status != 80 then 1 else 0 end) as 'deliveryNum',
  52. sum(case when t1.send_status = 0 and t1.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  53. round(sum(case when t1.send_status = 1 and
  54. t1.order_status != 80 then 1 else 0 end) /
  55. sum(case
  56. when order_status != 80
  57. then 1
  58. else 0 end) *
  59. 100,
  60. 2) as 'deliveryRadio',
  61. count(distinct t1.clip_user_id) as 'promoterCount',
  62. count( distinct t3.promoter_id ) as 'addPromoterCount',
  63. count(distinct t1.item_id) as 'itemCount',
  64. count(distinct t4.item_id) as 'addItemCount',
  65. round(sum(case when t1.order_status != 80 then t1.mcn_promotion_amount else 0 end) / 100, 2) as
  66. 'regimentalPromotionAmount',
  67. round(sum(case when t1.order_status != 80 and t2.type = 1 then t1.mcn_promotion_amount else 0 end) / 100, 2) as
  68. 'zyRegimentalPromotionAmount',
  69. round(sum(case when t1.order_status != 80 and t2.type = 2 then t1.mcn_promotion_amount else 0 end) / 100, 2) as
  70. 'fxRegimentalPromotionAmount',
  71. round(sum(t1.mcn_promotion_amount) / sum(t1.pay_amount) * 100, 2) as 'grossMargin',
  72. round(sum(case when t2.type = 1 then t1.mcn_promotion_amount else 0 end) / sum(case when t2.type = 1 then
  73. t1.pay_amount else 0 end) * 100, 2) as 'zyGrossMargin',
  74. round(sum(case when t2.type = 2 then t1.mcn_promotion_amount else 0 end) /
  75. sum(case when t2.type = 2 then t1.pay_amount else 0 end) * 100, 2) as 'fxGrossMargin'
  76. from jy_order_list t1
  77. left join jy_kuaishou_promoter t2
  78. on t1.clip_user_id = t2.promoter_id
  79. left join (select *
  80. from jy_promoter_frist_order_date
  81. where frist_order_time &gt;= #{start}
  82. and frist_order_time &lt;= #{end}) t3 on t1.clip_user_id = t3.promoter_id
  83. left join (select *
  84. from jy_order_item_list
  85. where first_order_time &gt;=#{start}
  86. and first_order_time &lt;= #{end}) t4
  87. on t1.item_id = t4.item_id
  88. where t1.stat_date &gt;= #{start}
  89. and t1.stat_date &lt;= #{end}
  90. <if test='nowHour != null and nowHour != ""'>
  91. and t1.stat_hour &lt;= #{nowHour}
  92. </if>
  93. <if test='promoterIds != null and promoterIds.size() > 0'>
  94. AND t1.clip_user_id in
  95. <foreach collection="promoterIds" item="item" separator=","
  96. open="(" close=")">
  97. #{item}
  98. </foreach>
  99. </if>
  100. ) t
  101. join (select count(oid) as 'orderNum', round(sum(pay_amount) / 100, 2) as 'payAmount', round(sum(case when
  102. order_status != 80 then mcn_promotion_amount else 0 end) / 100,
  103. 2) as 'regimentalPromotionAmount', round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2) as 'grossMargin'
  104. from jy_order_list
  105. where stat_date &gt;= #{lastStart}
  106. and stat_date &lt;= #{lastEnd}
  107. <if test='nowHour != null and nowHour != ""'>
  108. and stat_hour &lt;= #{nowHour}
  109. </if>
  110. <if test='promoterIds != null and promoterIds.size() > 0'>
  111. AND clip_user_id in
  112. <foreach collection="promoterIds" item="item" separator=","
  113. open="(" close=")">
  114. #{item}
  115. </foreach>
  116. </if>
  117. ) tt
  118. </select>
  119. <select id="getMonthInfo" resultType="com.alibaba.fastjson.JSONObject">
  120. select t1.*,
  121. round((t1.orderNum - t2.orderNum) / t2.orderNum * 100, 2) as 'orderNumRate',
  122. round((t1.payAmount - t2.payAmount) / t2.payAmount * 100, 2) as 'payAmountRate'
  123. from (select count(oid) as 'orderNum',
  124. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  125. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid) * 100,
  126. 2) as 'validRadio',
  127. round(sum(pay_amount) / 100, 2) as 'payAmount',
  128. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  129. 2) as 'validPayAmount',
  130. round(sum(case when order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  131. 2) as 'validPayAmountRadio',
  132. count(distinct clip_user_id) as 'promoterCount',
  133. count(distinct item_id) as 'itemCount',
  134. sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum'
  135. from jy_order_list
  136. where stat_date &gt;= #{monthStart}
  137. and stat_date &lt;= #{monthEnd}
  138. <if test='promoterIds != null and promoterIds.size() > 0'>
  139. AND clip_user_id in
  140. <foreach collection="promoterIds" item="item" separator=","
  141. open="(" close=")">
  142. #{item}
  143. </foreach>
  144. </if>
  145. ) t1
  146. join (
  147. select count(oid) as 'orderNum',
  148. round(sum(pay_amount) / 100, 2) as 'payAmount'
  149. from jy_order_list
  150. where stat_date &gt;= #{lastMonthStart}
  151. and stat_date &lt;= #{lastMonthEnd}
  152. <if test='promoterIds != null and promoterIds.size() > 0'>
  153. AND clip_user_id in
  154. <foreach collection="promoterIds" item="item" separator=","
  155. open="(" close=")">
  156. #{item}
  157. </foreach>
  158. </if>
  159. ) t2
  160. </select>
  161. <select id="getEchartData" resultType="com.alibaba.fastjson.JSONObject">
  162. select date_format(stat_date,'%m-%d') as 'date',
  163. count(oid) as 'orderNum',
  164. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  165. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  166. 2) as 'validPayAmount',
  167. count(distinct clip_user_id) as 'promoterCount',
  168. count(distinct item_id) as 'itemCount'
  169. from jy_order_list
  170. where stat_date &gt;= #{echartStart}
  171. and stat_date &lt;= #{echartEnd}
  172. <if test='promoterIds != null and promoterIds.size() > 0'>
  173. AND clip_user_id in
  174. <foreach collection="promoterIds" item="item" separator=","
  175. open="(" close=")">
  176. #{item}
  177. </foreach>
  178. </if>
  179. group by stat_date
  180. order by stat_date asc
  181. </select>
  182. <select id="getGmvHours" resultType="com.alibaba.fastjson.JSONObject">
  183. select stat_hour as 'time', round(sum(order_amount) / 100, 2) as 'charge'
  184. from jy_order_list
  185. where stat_date = #{date}
  186. <if test='promoterIds != null and promoterIds.size() > 0'>
  187. AND clip_user_id in
  188. <foreach collection="promoterIds" item="item" separator=","
  189. open="(" close=")">
  190. #{item}
  191. </foreach>
  192. </if>
  193. group by stat_hour
  194. order by stat_hour
  195. </select>
  196. <select id="getTeamList" resultType="com.alibaba.fastjson.JSONObject">
  197. select t.*,
  198. (select user.nick_name
  199. from sys_user user
  200. left join sys_user_role userRole on user.user_id = userRole.user_id
  201. left join sys_role role on userRole.role_id = role.role_id
  202. where user.dept_id = t.deptId
  203. and role.role_key in (
  204. 'jy_bd_manage', 'jy_scissors_manage', 'jy_out_operation_manager'
  205. )
  206. and user.status = 0
  207. limit 1) as 'leaderName',
  208. (select count(user.user_id)
  209. from sys_user user
  210. left join sys_user_role userRole on user.user_id = userRole.user_id
  211. left join sys_role role on userRole.role_id = role.role_id
  212. where user.dept_id = t.deptId
  213. and role.role_key not in (
  214. 'jy_expert_business', 'jy_expert_mentor'
  215. )
  216. and user.status = 0) as 'teamMember',
  217. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  218. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate'
  219. from (select t4.dept_id as 'deptId',
  220. t4.dept_name as 'deptName',
  221. count(t1.oid) as 'orderNum',
  222. round(sum(case when t1.order_status != 80 then 1 else 0 end) / count(t1.oid) * 100,
  223. 2) as 'validRadio',
  224. round(sum(pay_amount) / 100, 2) as 'payAmount',
  225. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  226. 2) as 'validPayAmount',
  227. round(sum(case when t1.order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  228. 2) as 'validPayAmountRadio',
  229. sum(case when t1.send_status = 0 and t1.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  230. round(sum(case when t1.send_status = 1 and t1.order_status != 80 then 1 else 0 end) / sum(case
  231. when order_status != 80
  232. then 1
  233. else 0 end) *
  234. 100,
  235. 2) as 'deliveryRadio',
  236. count(distinct t1.clip_user_id) as 'promoterCount',
  237. count(
  238. distinct t5.promoter_id
  239. ) as 'addPromoterCount',
  240. count(distinct t1.item_id) as 'itemCount',
  241. count(distinct t6.item_id) as 'addItemCount'
  242. from jy_order_list t1
  243. left join jy_kuaishou_promoter t2
  244. on t1.clip_user_id = t2.promoter_id
  245. left join sys_user t3 on t2.user_id = t3.user_id
  246. left join sys_dept t4 on t3.dept_id = t4.dept_id
  247. left join (select *
  248. from jy_promoter_frist_order_date
  249. where frist_order_time &gt;= #{start}
  250. and frist_order_time &lt;= #{end}) t5 on t1.clip_user_id = t5.promoter_id
  251. left join (select *
  252. from jy_order_item_list
  253. where first_order_time &gt;= #{start}
  254. and first_order_time &lt;= #{end}) t6
  255. on t1.item_id = t6.item_id
  256. where t1.stat_date &gt;= #{start}
  257. and t1.stat_date &lt;= #{end}
  258. <if test='nowHour != null and nowHour != ""'>
  259. and t1.stat_hour &lt;= #{nowHour}
  260. </if>
  261. <if test='promoterIds != null and promoterIds.size() > 0'>
  262. AND t1.clip_user_id in
  263. <foreach collection="promoterIds" item="item" separator=","
  264. open="(" close=")">
  265. #{item}
  266. </foreach>
  267. </if>
  268. group by t4.dept_id) t
  269. left join (select t4.dept_id as 'deptId',
  270. count(t1.oid) as 'orderNum',
  271. round(sum(pay_amount) / 100, 2) as 'payAmount'
  272. from jy_order_list t1
  273. left join jy_kuaishou_promoter t2
  274. on t1.clip_user_id = t2.promoter_id
  275. left join sys_user t3 on t2.user_id = t3.user_id
  276. left join sys_dept t4 on t3.dept_id = t4.dept_id
  277. where t1.stat_date &gt;= #{lastStart}
  278. and t1.stat_date &lt;= #{lastEnd}
  279. <if test='nowHour != null and nowHour != ""'>
  280. and t1.stat_hour &lt;= #{nowHour}
  281. </if>
  282. <if test='promoterIds != null and promoterIds.size() > 0'>
  283. AND t1.clip_user_id in
  284. <foreach collection="promoterIds" item="item" separator=","
  285. open="(" close=")">
  286. #{item}
  287. </foreach>
  288. </if>
  289. group by t4.dept_id) tt on t.deptId = tt.deptId
  290. where t.deptId is not null
  291. order by t.orderNum desc
  292. </select>
  293. <select id="getAddItemList" resultType="com.alibaba.fastjson.JSONObject">
  294. SELECT t1.item_id AS 'itemId', t1.item_title AS 'itemTitle', t1.image_url AS 'image_url', round(t1.reserve_price / 100, 2) AS 'reserve_price', t1.first_order_time AS 'firstOrderTime'
  295. FROM jy_order_item_list t1
  296. INNER JOIN (SELECT item_id
  297. FROM jy_order_list
  298. WHERE stat_date &gt;= #{start}
  299. AND stat_date &lt;= #{end}
  300. AND clip_user_id IN (SELECT promoter_id
  301. FROM jy_kuaishou_promoter
  302. WHERE user_id IN (SELECT user_id
  303. FROM sys_user
  304. WHERE dept_id = #{deptId})
  305. GROUP BY promoter_id)
  306. GROUP BY item_id) t2 ON t1.item_id = t2.item_id
  307. WHERE t1.first_order_time &gt;= #{start}
  308. AND t1.first_order_time &lt;= #{end}
  309. </select>
  310. <select id="getPeopleList" resultType="com.alibaba.fastjson.JSONObject">
  311. select t.*,
  312. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  313. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate'
  314. from (select t2.user_id as 'userId',
  315. t2.user_name as 'userName',
  316. (select deap.dept_name
  317. from sys_user user
  318. left join sys_dept deap on user.dept_id = deap.dept_id
  319. where user.user_id = t2.user_id) as 'deapName',
  320. (select user.nick_name
  321. from sys_user user
  322. left join sys_user_role userrole on user.user_id
  323. = userrole.user_id
  324. left join sys_role role on userrole.role_id = role.role_id
  325. where user.dept_id = (select dept_id from sys_user where user_id = t2.user_id limit 1)
  326. and role.role_key in (
  327. 'jy_bd_manage', 'jy_scissors_manage', 'jy_out_operation_manager'
  328. )
  329. and user.status = 0
  330. limit 1) as 'leaderName',
  331. count(t1.oid) as 'orderNum',
  332. round(
  333. sum(case when t1.order_status != 80 then 1 else 0 end) / count(t1.oid) * 100,
  334. 2) as 'validRadio',
  335. round(sum(pay_amount) / 100, 2) as 'payAmount',
  336. round(sum(case when t1.order_status != 80 then t1.pay_amount else 0 end) / 100,
  337. 2) as 'validPayAmount',
  338. round(sum(case when t1.order_status != 80 then t1.pay_amount else 0 end) / sum(t1.pay_amount) * 100,
  339. 2) as 'validPayAmountRadio',
  340. sum(case when t1.send_status = 0 and t1.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  341. round(sum(case when t1.send_status = 1 and t1.order_status != 80 then 1 else 0 end) / sum(case
  342. when t1.order_status != 80
  343. then 1
  344. else 0 end) *
  345. 100,
  346. 2) as 'deliveryRadio',
  347. count(distinct t1.clip_user_id) as 'promoterCount',
  348. count(
  349. distinct t3.promoter_id
  350. ) as 'addPromoterCount',
  351. count(distinct t1.item_id) as 'itemCount',
  352. count(distinct t4.item_id) as 'addItemCount'
  353. from jy_order_list t1
  354. left join jy_kuaishou_promoter t2
  355. on t1.clip_user_id = t2.promoter_id
  356. left join (select *
  357. from jy_promoter_frist_order_date
  358. where frist_order_time &gt;= #{start}
  359. and frist_order_time &lt;= #{end}) t3 on t1.clip_user_id = t3.promoter_id
  360. left join (select *
  361. from jy_order_item_list
  362. where first_order_time &gt;= #{start}
  363. and first_order_time &lt;= #{end}) t4
  364. on t1.item_id = t4.item_id
  365. where t1.stat_date &gt;= #{start}
  366. and t1.stat_date &lt;= #{end}
  367. <if test='nowHour != null and nowHour != ""'>
  368. and t1.stat_hour &lt;= #{nowHour}
  369. </if>
  370. <if test='promoterIds != null and promoterIds.size() > 0'>
  371. AND t1.clip_user_id in
  372. <foreach collection="promoterIds" item="item" separator=","
  373. open="(" close=")">
  374. #{item}
  375. </foreach>
  376. </if>
  377. group by t2.user_id) t
  378. left join (select t2.user_id as 'userId',
  379. count(t1.oid) as 'orderNum',
  380. round(sum(pay_amount) / 100, 2) as 'payAmount'
  381. from jy_order_list t1
  382. left join jy_kuaishou_promoter t2
  383. on t1.clip_user_id = t2.promoter_id
  384. where t1.stat_date &gt;= #{lastStart}
  385. and t1.stat_date &lt;= #{lastEnd}
  386. <if test='nowHour != null and nowHour != ""'>
  387. and t1.stat_hour &lt;= #{nowHour}
  388. </if>
  389. <if test='promoterIds != null and promoterIds.size() > 0'>
  390. AND t1.clip_user_id in
  391. <foreach collection="promoterIds" item="item" separator=","
  392. open="(" close=")">
  393. #{item}
  394. </foreach>
  395. </if>
  396. group by t2.user_id) tt on t.userId = tt.userId
  397. order by t.orderNum desc
  398. </select>
  399. <select id="getAddItemListByUserId" resultType="com.alibaba.fastjson.JSONObject">
  400. SELECT t1.item_id AS 'itemId', t1.item_title AS 'itemTitle', t1.image_url AS 'image_url', round(t1.reserve_price / 100, 2) AS 'reserve_price', t1.first_order_time AS 'firstOrderTime'
  401. FROM jy_order_item_list t1
  402. INNER JOIN (SELECT item_id
  403. FROM jy_order_list
  404. WHERE stat_date &gt;= #{start}
  405. AND stat_date &lt;= #{end}
  406. AND clip_user_id IN (SELECT promoter_id
  407. FROM jy_kuaishou_promoter
  408. WHERE user_id = #{userId}
  409. GROUP BY promoter_id)
  410. GROUP BY item_id) t2 ON t1.item_id = t2.item_id
  411. WHERE t1.first_order_time &gt;= #{start}
  412. AND t1.first_order_time &lt;= #{end}
  413. </select>
  414. <select id="getPromoterList" resultType="com.alibaba.fastjson.JSONObject">
  415. select t1.*,
  416. t2.user_name as 'userName',
  417. (case
  418. when t2.type = 1 then '自营'
  419. when t2.type = 2 then '分销'
  420. else '-'
  421. end
  422. ) as 'promoterType',
  423. t2.promoter_url as 'promoterUrl',
  424. t3.videoCount as 'videoCount',
  425. round((t1.orderNum - t4.orderNum) / t4.orderNum * 100, 2) as 'orderNumRate',
  426. round((t1.payAmount - t4.payAmount) / t4.payAmount * 100, 2) as 'payAmountRate'
  427. from (select clip_user_id as 'clipUserId',
  428. clip_nick_name as 'clipNickName',
  429. count(oid) as 'orderNum',
  430. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid) * 100,
  431. 2) as 'validRadio',
  432. round(sum(pay_amount) / 100, 2) as 'payAmount',
  433. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  434. 2) as 'validPayAmount',
  435. round(sum(case when order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  436. 2) as 'validPayAmountRadio',
  437. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  438. round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case
  439. when order_status != 80
  440. then 1
  441. else 0 end) *
  442. 100,
  443. 2) as 'deliveryRadio',
  444. count(distinct item_id) as 'itemCount'
  445. from jy_order_list
  446. where stat_date &gt;= #{start}
  447. and stat_date &lt;= #{end}
  448. <if test='nowHour != null and nowHour != ""'>
  449. and stat_hour &lt;= #{nowHour}
  450. </if>
  451. <if test='promoterIds != null and promoterIds.size() > 0'>
  452. AND clip_user_id in
  453. <foreach collection="promoterIds" item="item" separator=","
  454. open="(" close=")">
  455. #{item}
  456. </foreach>
  457. </if>
  458. group by clip_user_id) t1
  459. left join jy_kuaishou_promoter t2
  460. on t1.clipUserId = t2.promoter_id
  461. left join (select promoter_id as 'promoterId', count(photo_id) as 'videoCount'
  462. from kuaishou_open_photo_list
  463. where photo_create_time &gt;= #{start}
  464. and photo_create_time &lt;= #{end}
  465. group by promoter_id) t3 on t1.clipUserId = t3.promoterId
  466. left join (select clip_user_id as 'clipUserId',
  467. count(oid) as 'orderNum',
  468. round(sum(pay_amount) / 100, 2) as 'payAmount'
  469. from jy_order_list
  470. where stat_date &gt;= #{lastStart}
  471. and stat_date &lt;= #{lastEnd}
  472. <if test='nowHour != null and nowHour != ""'>
  473. and stat_hour &lt;= #{nowHour}
  474. </if>
  475. <if test='promoterIds != null and promoterIds.size() > 0'>
  476. AND clip_user_id in
  477. <foreach collection="promoterIds" item="item" separator=","
  478. open="(" close=")">
  479. #{item}
  480. </foreach>
  481. </if>
  482. group by clip_user_id) t4 on t1.clipUserId = t4.clipUserId
  483. order by t1.orderNum desc
  484. </select>
  485. <select id="getItemList" resultType="com.alibaba.fastjson.JSONObject">
  486. select t1.*,
  487. round((t1.orderNum - t2.orderNum) / t2.orderNum * 100, 2) as 'orderNumRate',
  488. round((t1.payAmount - t2.payAmount) / t2.payAmount * 100, 2) as 'payAmountRate'
  489. from (select item_id as 'itemId',
  490. item_title as 'itemTitle',
  491. image_url as 'imageUrl',
  492. count(oid) as 'orderNum',
  493. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid) * 100,
  494. 2) as 'validRadio',
  495. round(sum(pay_amount) / 100, 2) as 'payAmount',
  496. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  497. 2) as 'validPayAmount',
  498. round(sum(case when order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  499. 2) as 'validPayAmountRadio',
  500. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  501. round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case
  502. when order_status != 80
  503. then 1
  504. else 0 end) *
  505. 100,
  506. 2) as 'deliveryRadio',
  507. round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2) as 'grossMargin',
  508. count(distinct clip_user_id) as 'promoterCount'
  509. from jy_order_list
  510. where stat_date &gt;= #{start}
  511. and stat_date &lt;= #{end}
  512. <if test="nowHour != null and nowHour != ''">
  513. and stat_hour &lt;= #{nowHour}
  514. </if>
  515. <if test='promoterIds != null and promoterIds.size() > 0'>
  516. AND clip_user_id in
  517. <foreach collection="promoterIds" item="item" separator=","
  518. open="(" close=")">
  519. #{item}
  520. </foreach>
  521. </if>
  522. group by item_id) t1
  523. left join (select item_id as 'itemId',
  524. image_url as 'imageUrl',
  525. count(oid) as 'orderNum',
  526. round(sum(pay_amount) / 100, 2) as 'payAmount'
  527. from jy_order_list
  528. where stat_date &gt;= #{lastStart}
  529. and stat_date &lt;= #{lastEnd}
  530. <if test="nowHour != null and nowHour != ''">
  531. and stat_hour &lt;= #{nowHour}
  532. </if>
  533. <if test='promoterIds != null and promoterIds.size() > 0'>
  534. AND clip_user_id in
  535. <foreach collection="promoterIds" item="item" separator=","
  536. open="(" close=")">
  537. #{item}
  538. </foreach>
  539. </if>
  540. group by item_id
  541. ) t2 on t1.itemId = t2.itemId
  542. order by t1.orderNum desc
  543. </select>
  544. <select id="getDingPanTuiGuangUserList" resultType="com.alibaba.fastjson.JSONObject">
  545. select t1.*,
  546. round((t1.orderNum - t2.orderNum) / t2.orderNum * 100, 2) as 'orderNumRate',
  547. round((t1.payAmount - t2.payAmount) / t2.payAmount * 100, 2) as 'payAmountRate'
  548. from (select promotion_id as 'promotionId',
  549. promotion_nick_name as 'promotionNickName',
  550. count(oid) as 'orderNum',
  551. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid) * 100,
  552. 2) as 'validRadio',
  553. round(sum(pay_amount) / 100, 2) as 'payAmount',
  554. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  555. 2) as 'validPayAmount',
  556. round(sum(case when order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  557. 2) as 'validPayAmountRadio',
  558. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  559. round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case
  560. when order_status != 80
  561. then 1
  562. else 0 end) *
  563. 100,
  564. 2) as 'deliveryRadio',
  565. count(distinct item_id) as 'itemCount',
  566. count(distinct clip_user_id) as 'promoterCount'
  567. from jy_order_list
  568. where stat_date &gt;= #{start}
  569. and stat_date &lt;= #{end}
  570. <if test='nowHour != null and nowHour != ""'>
  571. and stat_hour &lt;= #{nowHour}
  572. </if>
  573. group by promotion_id) t1
  574. left join (select promotion_id as 'promotionId',
  575. count(oid) as 'orderNum',
  576. round(sum(pay_amount) / 100, 2) as 'payAmount'
  577. from ruixuan.jy_order_list
  578. where stat_date &gt;= #{lastStart}
  579. and stat_date &lt;= #{lastEnd}
  580. <if test='nowHour != null and nowHour != ""'>
  581. and stat_hour &lt;= #{nowHour}
  582. </if>
  583. group by promotion_id) t2 on t1.promotionId = t2.promotionId
  584. </select>
  585. <select id="getDingPanMentorBusinessList" resultType="com.alibaba.fastjson.JSONObject">
  586. select * from (
  587. select t.*,
  588. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  589. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate'
  590. from (select '导师' as 'type',
  591. t1.expert_mentor_id as 'userId',
  592. t1.expert_mentor_name as 'userName',
  593. count(t2.oid) as 'orderNum',
  594. round(sum(case when t2.order_status != 80 then 1 else 0 end) / count(t2.oid) * 100,
  595. 2) as 'validRadio',
  596. round(sum(t2.pay_amount) / 100, 2) as 'payAmount',
  597. round(sum(case when t2.order_status != 80 then t2.pay_amount else 0 end) / 100,
  598. 2) as 'validPayAmount',
  599. round(sum(case when t2.order_status != 80 then t2.pay_amount else 0 end) / sum(t2.pay_amount) * 100,
  600. 2) as 'validPayAmountRadio',
  601. sum(case when t2.send_status = 0 and t2.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  602. round(sum(case when t2.send_status = 1 and t2.order_status != 80 then 1 else 0 end) / sum(case
  603. when t2.order_status != 80
  604. then 1
  605. else 0 end) *
  606. 100,
  607. 2) as 'deliveryRadio',
  608. count(distinct t2.clip_user_id) as 'promoterCount',
  609. count(distinct t2.item_id) as 'itemCount'
  610. from jy_kuaishou_promoter t1
  611. left join jy_order_list t2
  612. on t1.promoter_id = t2.clip_user_id
  613. where 1 = 1
  614. and t1.expert_mentor_id is not null
  615. and t2.stat_date &gt;= #{start}
  616. and t2.stat_date &lt;= #{end}
  617. <if test='nowHour != null and nowHour != ""'>
  618. and t2.stat_hour &lt;= #{nowHour}
  619. </if>
  620. group by t1.expert_mentor_id) t
  621. left join (select t1.expert_mentor_id as 'userId',
  622. count(t2.oid) as 'orderNum',
  623. round(sum(t2.pay_amount) / 100, 2) as 'payAmount'
  624. from jy_kuaishou_promoter t1
  625. left join jy_order_list t2
  626. on t1.promoter_id = t2.clip_user_id
  627. where 1 = 1
  628. and t1.expert_mentor_id is not null
  629. and t2.stat_date &gt;= #{lastStart}
  630. and t2.stat_date &lt;= #{lastEnd}
  631. <if test='nowHour != null and nowHour != ""'>
  632. and t2.stat_hour &lt;= #{nowHour}
  633. </if>
  634. group by t1.expert_mentor_id) tt on t.userId = tt.userId
  635. union all
  636. select t.*,
  637. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  638. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate'
  639. from (select '商务' as 'type',
  640. t1.expert_business_id as 'userId',
  641. t1.expert_business_name as 'userName',
  642. count(t2.oid) as 'orderNum',
  643. round(sum(case when t2.order_status != 80 then 1 else 0 end) / count(t2.oid) * 100,
  644. 2) as 'validRadio',
  645. round(sum(t2.pay_amount) / 100, 2) as 'payAmount',
  646. round(sum(case when t2.order_status != 80 then t2.pay_amount else 0 end) / 100,
  647. 2) as 'validPayAmount',
  648. round(sum(case when t2.order_status != 80 then t2.pay_amount else 0 end) / sum(t2.pay_amount) * 100,
  649. 2) as 'validPayAmountRadio',
  650. sum(case when t2.send_status = 0 and t2.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  651. round(sum(case when t2.send_status = 1 and t2.order_status != 80 then 1 else 0 end) / sum(case
  652. when t2.order_status != 80
  653. then 1
  654. else 0 end) *
  655. 100,
  656. 2) as 'deliveryRadio',
  657. count(distinct t2.clip_user_id) as 'promoterCount',
  658. count(distinct t2.item_id) as 'itemCount'
  659. from jy_kuaishou_promoter t1
  660. left join jy_order_list t2
  661. on t1.promoter_id = t2.clip_user_id
  662. where 1 = 1
  663. and t1.expert_business_id is not null
  664. and t2.stat_date &gt;= #{start}
  665. and t2.stat_date &lt;= #{end}
  666. <if test='nowHour != null and nowHour != ""'>
  667. and t2.stat_hour &lt;= #{nowHour}
  668. </if>
  669. group by t1.expert_business_id) t
  670. left join (select t1.expert_business_id as 'userid',
  671. count(t2.oid) as 'orderNum',
  672. round(sum(t2.pay_amount) / 100, 2) as 'payAmount'
  673. from jy_kuaishou_promoter t1
  674. left join jy_order_list t2
  675. on t1.promoter_id = t2.clip_user_id
  676. where 1 = 1
  677. and t1.expert_business_id is not null
  678. and t2.stat_date &gt;= #{lastStart}
  679. and t2.stat_date &lt;= #{lastEnd}
  680. <if test='nowHour != null and nowHour != ""'>
  681. and t2.stat_hour &lt;= #{nowHour}
  682. </if>
  683. group by t1.expert_business_id) tt
  684. on t.userId = tt.userid) tlist
  685. order by tlist.`type` asc ,tlist.`orderNum` desc
  686. </select>
  687. </mapper>