JiaoYangDingPanMapper.xml 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  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. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  209. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate'
  210. from (select t4.dept_id as 'deptId',
  211. t4.dept_name as 'deptName',
  212. (count(distinct t2.user_id)) as 'teamMember',
  213. count(t1.oid) as 'orderNum',
  214. round(sum(case when t1.order_status != 80 then 1 else 0 end) / count(t1.oid) * 100,
  215. 2) as 'validRadio',
  216. round(sum(pay_amount) / 100, 2) as 'payAmount',
  217. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  218. 2) as 'validPayAmount',
  219. round(sum(case when t1.order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  220. 2) as 'validPayAmountRadio',
  221. sum(case when t1.send_status = 0 and t1.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  222. round(sum(case when t1.send_status = 1 and t1.order_status != 80 then 1 else 0 end) / sum(case
  223. when order_status != 80
  224. then 1
  225. else 0 end) *
  226. 100,
  227. 2) as 'deliveryRadio',
  228. count(distinct t1.clip_user_id) as 'promoterCount',
  229. count(
  230. distinct t5.promoter_id
  231. ) as 'addPromoterCount',
  232. count(distinct t1.item_id) as 'itemCount',
  233. count(distinct t6.item_id) as 'addItemCount'
  234. from jy_order_list t1
  235. left join jy_kuaishou_promoter t2
  236. on t1.clip_user_id = t2.promoter_id
  237. left join sys_user t3 on t2.user_id = t3.user_id
  238. left join sys_dept t4 on t3.dept_id = t4.dept_id
  239. left join (select *
  240. from jy_promoter_frist_order_date
  241. where frist_order_time &gt;= #{start}
  242. and frist_order_time &lt;= #{end}) t5 on t1.clip_user_id = t5.promoter_id
  243. left join (select *
  244. from jy_order_item_list
  245. where first_order_time &gt;= #{start}
  246. and first_order_time &lt;= #{end}) t6
  247. on t1.item_id = t6.item_id
  248. where t1.stat_date &gt;= #{start}
  249. and t1.stat_date &lt;= #{end}
  250. <if test='nowHour != null and nowHour != ""'>
  251. and t1.stat_hour &lt;= #{nowHour}
  252. </if>
  253. <if test='promoterIds != null and promoterIds.size() > 0'>
  254. AND t1.clip_user_id in
  255. <foreach collection="promoterIds" item="item" separator=","
  256. open="(" close=")">
  257. #{item}
  258. </foreach>
  259. </if>
  260. group by t4.dept_id) t
  261. left join (select t4.dept_id as 'deptId',
  262. count(t1.oid) as 'orderNum',
  263. round(sum(pay_amount) / 100, 2) as 'payAmount'
  264. from jy_order_list t1
  265. left join jy_kuaishou_promoter t2
  266. on t1.clip_user_id = t2.promoter_id
  267. left join sys_user t3 on t2.user_id = t3.user_id
  268. left join sys_dept t4 on t3.dept_id = t4.dept_id
  269. where t1.stat_date &gt;= #{lastStart}
  270. and t1.stat_date &lt;= #{lastEnd}
  271. <if test='nowHour != null and nowHour != ""'>
  272. and t1.stat_hour &lt;= #{nowHour}
  273. </if>
  274. <if test='promoterIds != null and promoterIds.size() > 0'>
  275. AND t1.clip_user_id in
  276. <foreach collection="promoterIds" item="item" separator=","
  277. open="(" close=")">
  278. #{item}
  279. </foreach>
  280. </if>
  281. group by t4.dept_id) tt on t.deptId = tt.deptId
  282. where t.deptId is not null
  283. order by t.orderNum desc
  284. </select>
  285. <select id="getAddItemList" resultType="com.alibaba.fastjson.JSONObject">
  286. 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'
  287. FROM jy_order_item_list t1
  288. INNER JOIN (SELECT item_id
  289. FROM jy_order_list
  290. WHERE stat_date &gt;= #{start}
  291. AND stat_date &lt;= #{end}
  292. AND clip_user_id IN (SELECT promoter_id
  293. FROM jy_kuaishou_promoter
  294. WHERE user_id IN (SELECT user_id
  295. FROM sys_user
  296. WHERE dept_id = #{deptId})
  297. GROUP BY promoter_id)
  298. GROUP BY item_id) t2 ON t1.item_id = t2.item_id
  299. WHERE t1.first_order_time &gt;= #{start}
  300. AND t1.first_order_time &lt;= #{end}
  301. ORDER BY t1.first_order_time DESC
  302. </select>
  303. <select id="getPeopleList" resultType="com.alibaba.fastjson.JSONObject">
  304. select t.*,
  305. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  306. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate'
  307. from (select t2.user_id as 'userId',
  308. t2.user_name as 'userName',
  309. (select deap.dept_name
  310. from sys_user user
  311. left join sys_dept deap on user.dept_id = deap.dept_id
  312. where user.user_id = t2.user_id) as 'deapName',
  313. (select user.nick_name
  314. from sys_user user
  315. left join sys_user_role userrole on user.user_id
  316. = userrole.user_id
  317. left join sys_role role on userrole.role_id = role.role_id
  318. where user.dept_id = (select dept_id from sys_user where user_id = t2.user_id limit 1)
  319. and role.role_key in (
  320. 'jy_bd_manage', 'jy_scissors_manage', 'jy_out_operation_manager'
  321. )
  322. and user.status = 0
  323. limit 1) as 'leaderName',
  324. count(t1.oid) as 'orderNum',
  325. round(
  326. sum(case when t1.order_status != 80 then 1 else 0 end) / count(t1.oid) * 100,
  327. 2) as 'validRadio',
  328. round(sum(pay_amount) / 100, 2) as 'payAmount',
  329. round(sum(case when t1.order_status != 80 then t1.pay_amount else 0 end) / 100,
  330. 2) as 'validPayAmount',
  331. round(sum(case when t1.order_status != 80 then t1.pay_amount else 0 end) / sum(t1.pay_amount) * 100,
  332. 2) as 'validPayAmountRadio',
  333. sum(case when t1.send_status = 0 and t1.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  334. round(sum(case when t1.send_status = 1 and t1.order_status != 80 then 1 else 0 end) / sum(case
  335. when t1.order_status != 80
  336. then 1
  337. else 0 end) *
  338. 100,
  339. 2) as 'deliveryRadio',
  340. count(distinct t1.clip_user_id) as 'promoterCount',
  341. count(
  342. distinct t3.promoter_id
  343. ) as 'addPromoterCount',
  344. count(distinct t1.item_id) as 'itemCount',
  345. count(distinct t4.item_id) as 'addItemCount'
  346. from jy_order_list t1
  347. left join jy_kuaishou_promoter t2
  348. on t1.clip_user_id = t2.promoter_id
  349. left join (select *
  350. from jy_promoter_frist_order_date
  351. where frist_order_time &gt;= #{start}
  352. and frist_order_time &lt;= #{end}) t3 on t1.clip_user_id = t3.promoter_id
  353. left join (select *
  354. from jy_order_item_list
  355. where first_order_time &gt;= #{start}
  356. and first_order_time &lt;= #{end}) t4
  357. on t1.item_id = t4.item_id
  358. where t1.stat_date &gt;= #{start}
  359. and t1.stat_date &lt;= #{end}
  360. <if test='nowHour != null and nowHour != ""'>
  361. and t1.stat_hour &lt;= #{nowHour}
  362. </if>
  363. <if test='promoterIds != null and promoterIds.size() > 0'>
  364. AND t1.clip_user_id in
  365. <foreach collection="promoterIds" item="item" separator=","
  366. open="(" close=")">
  367. #{item}
  368. </foreach>
  369. </if>
  370. group by t2.user_id) t
  371. left join (select t2.user_id as 'userId',
  372. count(t1.oid) as 'orderNum',
  373. round(sum(pay_amount) / 100, 2) as 'payAmount'
  374. from jy_order_list t1
  375. left join jy_kuaishou_promoter t2
  376. on t1.clip_user_id = t2.promoter_id
  377. where t1.stat_date &gt;= #{lastStart}
  378. and t1.stat_date &lt;= #{lastEnd}
  379. <if test='nowHour != null and nowHour != ""'>
  380. and t1.stat_hour &lt;= #{nowHour}
  381. </if>
  382. <if test='promoterIds != null and promoterIds.size() > 0'>
  383. AND t1.clip_user_id in
  384. <foreach collection="promoterIds" item="item" separator=","
  385. open="(" close=")">
  386. #{item}
  387. </foreach>
  388. </if>
  389. group by t2.user_id) tt on t.userId = tt.userId
  390. order by t.orderNum desc
  391. </select>
  392. <select id="getAddItemListByUserId" resultType="com.alibaba.fastjson.JSONObject">
  393. 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'
  394. FROM jy_order_item_list t1
  395. INNER JOIN (SELECT item_id
  396. FROM jy_order_list
  397. WHERE stat_date &gt;= #{start}
  398. AND stat_date &lt;= #{end}
  399. AND clip_user_id IN (SELECT promoter_id
  400. FROM jy_kuaishou_promoter
  401. WHERE user_id = #{userId}
  402. GROUP BY promoter_id)
  403. GROUP BY item_id) t2 ON t1.item_id = t2.item_id
  404. WHERE t1.first_order_time &gt;= #{start}
  405. AND t1.first_order_time &lt;= #{end}
  406. order by t1.first_order_time desc
  407. </select>
  408. <select id="getPromoterList" resultType="com.alibaba.fastjson.JSONObject">
  409. select t1.*,
  410. t2.user_name as 'userName',
  411. (case
  412. when t2.type = 1 then '自营'
  413. when t2.type = 2 then '分销'
  414. else '-'
  415. end
  416. ) as 'promoterType',
  417. t2.promoter_url as 'promoterUrl',
  418. t3.videoCount as 'videoCount',
  419. round((t1.orderNum - t4.orderNum) / t4.orderNum * 100, 2) as 'orderNumRate',
  420. round((t1.payAmount - t4.payAmount) / t4.payAmount * 100, 2) as 'payAmountRate'
  421. from (select t1.clip_user_id as 'clipUserId',
  422. t1.clip_nick_name as 'clipNickName',
  423. count(t1.oid) as 'orderNum',
  424. round(sum(case when t1.order_status != 80 then 1 else 0 end) / count(t1.oid) * 100,
  425. 2) as 'validRadio',
  426. round(sum(t1.pay_amount) / 100, 2) as 'payAmount',
  427. round(sum(case when t1.order_status != 80 then t1.pay_amount else 0 end) / 100,
  428. 2) as 'validPayAmount',
  429. round(sum(case when t1.order_status != 80 then t1.pay_amount else 0 end) / sum(t1.pay_amount) * 100,
  430. 2) as 'validPayAmountRadio',
  431. sum(case when t1.send_status = 0 and t1.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  432. round(sum(case when t1.send_status = 1 and t1.order_status != 80 then 1 else 0 end) / sum(case
  433. when t1.order_status != 80
  434. then 1
  435. else 0 end) *
  436. 100,
  437. 2) as 'deliveryRadio',
  438. count(distinct t1.item_id) as 'itemCount',
  439. count(distinct t2.item_id) as 'addItemCount'
  440. from jy_order_list t1
  441. left join (
  442. select *
  443. from jy_order_item_list
  444. where first_order_time &gt;=#{start}
  445. and first_order_time &lt;= #{end}) t2
  446. on t1.item_id = t2.item_id
  447. where t1.stat_date &gt;= #{start}
  448. and t1.stat_date &lt;= #{end}
  449. <if test='nowHour != null and nowHour != ""'>
  450. and t1.stat_hour &lt;= #{nowHour}
  451. </if>
  452. <if test='promoterIds != null and promoterIds.size() > 0'>
  453. AND t1.clip_user_id in
  454. <foreach collection="promoterIds" item="item" separator=","
  455. open="(" close=")">
  456. #{item}
  457. </foreach>
  458. </if>
  459. group by t1.clip_user_id) t1
  460. left join jy_kuaishou_promoter t2
  461. on t1.clipUserId = t2.promoter_id
  462. left join (select promoter_id as 'promoterId', count(photo_id) as 'videoCount'
  463. from kuaishou_open_photo_list
  464. where photo_create_time &gt;= #{start}
  465. and photo_create_time &lt;= #{end}
  466. group by promoter_id) t3 on t1.clipUserId = t3.promoterId
  467. left join (select clip_user_id as 'clipUserId',
  468. count(oid) as 'orderNum',
  469. round(sum(pay_amount) / 100, 2) as 'payAmount'
  470. from jy_order_list
  471. where stat_date &gt;= #{lastStart}
  472. and stat_date &lt;= #{lastEnd}
  473. <if test='nowHour != null and nowHour != ""'>
  474. and stat_hour &lt;= #{nowHour}
  475. </if>
  476. <if test='promoterIds != null and promoterIds.size() > 0'>
  477. AND clip_user_id in
  478. <foreach collection="promoterIds" item="item" separator=","
  479. open="(" close=")">
  480. #{item}
  481. </foreach>
  482. </if>
  483. group by clip_user_id) t4 on t1.clipUserId = t4.clipUserId
  484. where 1 = 1
  485. <if test='promoterType != null and promoterType != ""'>
  486. and t2.type = #{promoterType}
  487. </if>
  488. order by t1.orderNum desc
  489. </select>
  490. <select id="getItemList" resultType="com.alibaba.fastjson.JSONObject">
  491. select t1.*,
  492. round((t1.orderNum - t2.orderNum) / t2.orderNum * 100, 2) as 'orderNumRate',
  493. round((t1.payAmount - t2.payAmount) / t2.payAmount * 100, 2) as 'payAmountRate'
  494. from (select item_id as 'itemId',
  495. item_title as 'itemTitle',
  496. image_url as 'imageUrl',
  497. count(oid) as 'orderNum',
  498. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid) * 100,
  499. 2) as 'validRadio',
  500. round(sum(pay_amount) / 100, 2) as 'payAmount',
  501. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  502. 2) as 'validPayAmount',
  503. round(sum(case when order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  504. 2) as 'validPayAmountRadio',
  505. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  506. round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case
  507. when order_status != 80
  508. then 1
  509. else 0 end) *
  510. 100,
  511. 2) as 'deliveryRadio',
  512. round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2) as 'grossMargin',
  513. count(distinct clip_user_id) as 'promoterCount'
  514. from jy_order_list
  515. where stat_date &gt;= #{start}
  516. and stat_date &lt;= #{end}
  517. <if test="nowHour != null and nowHour != ''">
  518. and stat_hour &lt;= #{nowHour}
  519. </if>
  520. <if test='promoterIds != null and promoterIds.size() > 0'>
  521. AND clip_user_id in
  522. <foreach collection="promoterIds" item="item" separator=","
  523. open="(" close=")">
  524. #{item}
  525. </foreach>
  526. </if>
  527. group by item_id) t1
  528. left join (select item_id as 'itemId',
  529. image_url as 'imageUrl',
  530. count(oid) as 'orderNum',
  531. round(sum(pay_amount) / 100, 2) as 'payAmount'
  532. from jy_order_list
  533. where stat_date &gt;= #{lastStart}
  534. and stat_date &lt;= #{lastEnd}
  535. <if test="nowHour != null and nowHour != ''">
  536. and stat_hour &lt;= #{nowHour}
  537. </if>
  538. <if test='promoterIds != null and promoterIds.size() > 0'>
  539. AND clip_user_id in
  540. <foreach collection="promoterIds" item="item" separator=","
  541. open="(" close=")">
  542. #{item}
  543. </foreach>
  544. </if>
  545. group by item_id
  546. ) t2 on t1.itemId = t2.itemId
  547. order by t1.orderNum desc
  548. </select>
  549. <select id="getDingPanTuiGuangUserList" resultType="com.alibaba.fastjson.JSONObject">
  550. select t1.*,
  551. round((t1.orderNum - t2.orderNum) / t2.orderNum * 100, 2) as 'orderNumRate',
  552. round((t1.payAmount - t2.payAmount) / t2.payAmount * 100, 2) as 'payAmountRate'
  553. from (select promotion_id as 'promotionId',
  554. promotion_nick_name as 'promotionNickName',
  555. count(oid) as 'orderNum',
  556. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid) * 100,
  557. 2) as 'validRadio',
  558. round(sum(pay_amount) / 100, 2) as 'payAmount',
  559. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  560. 2) as 'validPayAmount',
  561. round(sum(case when order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  562. 2) as 'validPayAmountRadio',
  563. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  564. round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case
  565. when order_status != 80
  566. then 1
  567. else 0 end) *
  568. 100,
  569. 2) as 'deliveryRadio',
  570. count(distinct item_id) as 'itemCount',
  571. count(distinct clip_user_id) as 'promoterCount'
  572. from jy_order_list
  573. where stat_date &gt;= #{start}
  574. and stat_date &lt;= #{end}
  575. <if test='nowHour != null and nowHour != ""'>
  576. and stat_hour &lt;= #{nowHour}
  577. </if>
  578. group by promotion_id) t1
  579. left join (select promotion_id as 'promotionId',
  580. count(oid) as 'orderNum',
  581. round(sum(pay_amount) / 100, 2) as 'payAmount'
  582. from ruixuan.jy_order_list
  583. where stat_date &gt;= #{lastStart}
  584. and stat_date &lt;= #{lastEnd}
  585. <if test='nowHour != null and nowHour != ""'>
  586. and stat_hour &lt;= #{nowHour}
  587. </if>
  588. group by promotion_id) t2 on t1.promotionId = t2.promotionId
  589. </select>
  590. <select id="getDingPanMentorBusinessList" resultType="com.alibaba.fastjson.JSONObject">
  591. select * from (
  592. select t.*,
  593. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  594. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate'
  595. from (select '导师' as 'type',
  596. t1.expert_mentor_id as 'userId',
  597. t1.expert_mentor_name as 'userName',
  598. count(t2.oid) as 'orderNum',
  599. round(sum(case when t2.order_status != 80 then 1 else 0 end) / count(t2.oid) * 100,
  600. 2) as 'validRadio',
  601. round(sum(t2.pay_amount) / 100, 2) as 'payAmount',
  602. round(sum(case when t2.order_status != 80 then t2.pay_amount else 0 end) / 100,
  603. 2) as 'validPayAmount',
  604. round(sum(case when t2.order_status != 80 then t2.pay_amount else 0 end) / sum(t2.pay_amount) * 100,
  605. 2) as 'validPayAmountRadio',
  606. sum(case when t2.send_status = 0 and t2.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  607. round(sum(case when t2.send_status = 1 and t2.order_status != 80 then 1 else 0 end) / sum(case
  608. when t2.order_status != 80
  609. then 1
  610. else 0 end) *
  611. 100,
  612. 2) as 'deliveryRadio',
  613. count(distinct t2.clip_user_id) as 'promoterCount',
  614. count(distinct t2.item_id) as 'itemCount',
  615. count(distinct t3.item_id) as 'addItemCount',
  616. count(DISTINCT t1.user_id) as 'teamCount'
  617. from jy_kuaishou_promoter t1
  618. left join jy_order_list t2
  619. on t1.promoter_id = t2.clip_user_id
  620. left join (select *
  621. from jy_order_item_list
  622. where first_order_time &gt;=#{start}
  623. and first_order_time &lt;= #{end}) t3
  624. on t2.item_id = t3.item_id
  625. where 1 = 1
  626. and t1.expert_mentor_id is not null
  627. and t2.stat_date &gt;= #{start}
  628. and t2.stat_date &lt;= #{end}
  629. <if test='nowHour != null and nowHour != ""'>
  630. and t2.stat_hour &lt;= #{nowHour}
  631. </if>
  632. group by t1.expert_mentor_id) t
  633. left join (select t1.expert_mentor_id as 'userId',
  634. count(t2.oid) as 'orderNum',
  635. round(sum(t2.pay_amount) / 100, 2) as 'payAmount'
  636. from jy_kuaishou_promoter t1
  637. left join jy_order_list t2
  638. on t1.promoter_id = t2.clip_user_id
  639. where 1 = 1
  640. and t1.expert_mentor_id is not null
  641. and t2.stat_date &gt;= #{lastStart}
  642. and t2.stat_date &lt;= #{lastEnd}
  643. <if test='nowHour != null and nowHour != ""'>
  644. and t2.stat_hour &lt;= #{nowHour}
  645. </if>
  646. group by t1.expert_mentor_id) tt on t.userId = tt.userId
  647. union all
  648. select t.*,
  649. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  650. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate'
  651. from (select '商务' as 'type',
  652. t1.expert_business_id as 'userId',
  653. t1.expert_business_name as 'userName',
  654. count(t2.oid) as 'orderNum',
  655. round(sum(case when t2.order_status != 80 then 1 else 0 end) / count(t2.oid) * 100,
  656. 2) as 'validRadio',
  657. round(sum(t2.pay_amount) / 100, 2) as 'payAmount',
  658. round(sum(case when t2.order_status != 80 then t2.pay_amount else 0 end) / 100,
  659. 2) as 'validPayAmount',
  660. round(sum(case when t2.order_status != 80 then t2.pay_amount else 0 end) / sum(t2.pay_amount) * 100,
  661. 2) as 'validPayAmountRadio',
  662. sum(case when t2.send_status = 0 and t2.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  663. round(sum(case when t2.send_status = 1 and t2.order_status != 80 then 1 else 0 end) / sum(case
  664. when t2.order_status != 80
  665. then 1
  666. else 0 end) *
  667. 100,
  668. 2) as 'deliveryRadio',
  669. count(distinct t2.clip_user_id) as 'promoterCount',
  670. count(distinct t2.item_id) as 'itemCount',
  671. count(distinct t3.item_id) as 'addItemCount',
  672. count(DISTINCT t1.user_id) as 'teamCount'
  673. from jy_kuaishou_promoter t1
  674. left join jy_order_list t2
  675. on t1.promoter_id = t2.clip_user_id
  676. left join (select *
  677. from jy_order_item_list
  678. where first_order_time &gt;=#{start}
  679. and first_order_time &lt;= #{end}) t3
  680. on t2.item_id = t3.item_id
  681. where 1 = 1
  682. and t1.expert_business_id is not null
  683. and t2.stat_date &gt;= #{start}
  684. and t2.stat_date &lt;= #{end}
  685. <if test='nowHour != null and nowHour != ""'>
  686. and t2.stat_hour &lt;= #{nowHour}
  687. </if>
  688. group by t1.expert_business_id) t
  689. left join (select t1.expert_business_id as 'userid',
  690. count(t2.oid) as 'orderNum',
  691. round(sum(t2.pay_amount) / 100, 2) as 'payAmount'
  692. from jy_kuaishou_promoter t1
  693. left join jy_order_list t2
  694. on t1.promoter_id = t2.clip_user_id
  695. where 1 = 1
  696. and t1.expert_business_id is not null
  697. and t2.stat_date &gt;= #{lastStart}
  698. and t2.stat_date &lt;= #{lastEnd}
  699. <if test='nowHour != null and nowHour != ""'>
  700. and t2.stat_hour &lt;= #{nowHour}
  701. </if>
  702. group by t1.expert_business_id) tt
  703. on t.userId = tt.userid) tlist
  704. order by tlist.`type` asc ,tlist.`orderNum` desc
  705. </select>
  706. <select id="getAddItemListByExpertId" resultType="com.alibaba.fastjson.JSONObject">
  707. SELECT t1.item_id AS 'itemId', t1.item_title AS 'itemTitle', t1.image_url AS 'image_url', round(t1.reserve_price
  708. / 100, 2) AS 'reserve_price', t1.first_order_time AS 'firstOrderTime'
  709. FROM jy_order_item_list t1
  710. INNER JOIN (SELECT item_id
  711. FROM jy_order_list
  712. WHERE stat_date &gt;= #{start}
  713. AND stat_date &lt;= #{end}
  714. AND clip_user_id IN (SELECT promoter_id
  715. FROM jy_kuaishou_promoter
  716. WHERE 1 = 1
  717. <if test='expertMentorId != null and expertMentorId != ""'>
  718. and expert_mentor_id = #{expertMentorId}
  719. </if>
  720. <if test='expertBusinessId != null and expertBusinessId != ""'>
  721. and expert_business_id = #{expertBusinessId}
  722. </if>
  723. GROUP BY promoter_id)
  724. GROUP BY item_id) t2 ON t1.item_id = t2.item_id
  725. WHERE t1.first_order_time &gt;= #{start}
  726. AND t1.first_order_time &lt;= #{end}
  727. order by t1.first_order_time desc
  728. </select>
  729. <select id="getAddItemListByClipUserId" resultType="com.alibaba.fastjson.JSONObject">
  730. SELECT t1.item_id AS 'itemId', t1.item_title AS 'itemTitle', t1.image_url AS 'image_url', round(t1.reserve_price
  731. / 100, 2) AS 'reserve_price', t1.first_order_time AS 'firstOrderTime'
  732. FROM jy_order_item_list t1
  733. INNER JOIN (SELECT item_id
  734. FROM jy_order_list
  735. WHERE stat_date &gt;= #{start}
  736. AND stat_date &lt;= #{end}
  737. AND clip_user_id = #{clipUserId}
  738. GROUP BY item_id) t2
  739. ON t1.item_id = t2.item_id
  740. WHERE t1.first_order_time &gt;= #{start}
  741. AND t1.first_order_time &lt;= #{end}
  742. ORDER BY t1.first_order_time DESC
  743. </select>
  744. <select id="getVideoList" resultType="com.alibaba.fastjson.JSONObject">
  745. SELECT promoter_id 'promoterId', photo_id 'photoId', caption 'caption', cover 'cover', play_url 'playUrl', photo_create_time 'photoCreateTime', like_count 'likeCount', comment_count 'commentCount', view_count AS 'viewCount'
  746. FROM kuaishou_open_photo_list
  747. WHERE promoter_id = #{promoterId}
  748. AND photo_create_time &gt;= #{start}
  749. AND photo_create_time &lt;= #{end}
  750. ORDER BY photo_create_time DESC
  751. </select>
  752. <select id="getTeamDetail" resultType="com.alibaba.fastjson.JSONObject">
  753. select t.*,
  754. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  755. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate'
  756. from (
  757. select t2.user_id as 'userId',
  758. t2.user_name as 'userName',
  759. count(t1.oid) as 'orderNum',
  760. round(sum(case when t1.order_status != 80 then 1 else 0 end) / count(t1.oid) * 100,
  761. 2) as 'validRadio',
  762. round(sum(pay_amount) / 100, 2) as 'payAmount',
  763. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  764. 2) as 'validPayAmount',
  765. round(sum(case when t1.order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  766. 2) as 'validPayAmountRadio',
  767. sum(case when t1.send_status = 0 and t1.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  768. round(sum(case when t1.send_status = 1 and t1.order_status != 80 then 1 else 0 end) / sum(case
  769. when order_status != 80
  770. then 1
  771. else 0 end) *
  772. 100,
  773. 2) as 'deliveryRadio',
  774. count(distinct t1.clip_user_id) as 'promoterCount',
  775. count(distinct t1.item_id) as 'itemCount',
  776. count(distinct t3.item_id) as 'addItemCount'
  777. from jy_order_list t1
  778. left join jy_kuaishou_promoter t2
  779. on t1.clip_user_id = t2.promoter_id
  780. left join (select *
  781. from jy_order_item_list
  782. where first_order_time &gt;= #{start}
  783. and first_order_time &lt;= #{end} ) t3
  784. on t1.item_id = t3.item_id
  785. where t1.stat_date &gt;= #{start}
  786. and t1.stat_date &lt;= #{end}
  787. <if test='nowHour != null and nowHour != ""'>
  788. and t1.stat_hour &lt;= #{nowHour}
  789. </if>
  790. <if test='promoterIds != null and promoterIds.size() > 0'>
  791. AND t1.clip_user_id in
  792. <foreach collection="promoterIds" item="item" separator=","
  793. open="(" close=")">
  794. #{item}
  795. </foreach>
  796. </if>
  797. and t2.user_id is not null
  798. group by t2.user_id) t
  799. left join (select t2.user_id as 'userId',
  800. count(t1.oid) as 'orderNum',
  801. round(sum(pay_amount) / 100, 2) as 'payAmount'
  802. from jy_order_list t1
  803. left join jy_kuaishou_promoter t2
  804. on t1.clip_user_id = t2.promoter_id
  805. where t1.stat_date &gt;= #{lastStart}
  806. and t1.stat_date &lt;= #{lastEnd}
  807. <if test='nowHour != null and nowHour != ""'>
  808. and t1.stat_hour &lt;= #{nowHour}
  809. </if>
  810. <if test='promoterIds != null and promoterIds.size() > 0'>
  811. AND t1.clip_user_id in
  812. <foreach collection="promoterIds" item="item" separator=","
  813. open="(" close=")">
  814. #{item}
  815. </foreach>
  816. </if>
  817. and t2.user_id is not null
  818. group by t2.user_id) tt on t.userId = tt.userId
  819. order by t.orderNum desc
  820. </select>
  821. <select id="getDeptUsers" resultType="java.lang.Long" parameterType="java.lang.Long">
  822. SELECT promoter_id
  823. FROM jy_kuaishou_promoter
  824. WHERE user_id IN (SELECT user_id
  825. FROM sys_user
  826. WHERE dept_id = #{deptId})
  827. GROUP BY promoter_id
  828. </select>
  829. <select id="getPromoterItemDetail" resultType="com.alibaba.fastjson.JSONObject">
  830. select t1.*,
  831. round((t1.orderNum - t2.orderNum) / t2.orderNum * 100, 2) as 'orderNumRate',
  832. round((t1.payAmount - t2.payAmount) / t2.payAmount * 100, 2) as 'payAmountRate'
  833. from (select item_id as 'itemId',
  834. item_title as 'itemTitle',
  835. image_url as 'imageUrl',
  836. count(oid) as 'orderNum',
  837. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid) * 100,
  838. 2) as 'validRadio',
  839. round(sum(pay_amount) / 100, 2) as 'payAmount',
  840. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  841. 2) as 'validPayAmount',
  842. round(sum(case when order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  843. 2) as 'validPayAmountRadio',
  844. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  845. round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case
  846. when order_status != 80
  847. then 1
  848. else 0 end) *
  849. 100,
  850. 2) as 'deliveryRadio'
  851. from jy_order_list
  852. where clip_user_id = #{clipUserId}
  853. and stat_date &gt;= #{start}
  854. and stat_date &lt;= #{end}
  855. <if test='nowHour != null and nowHour != ""'>
  856. and stat_hour &lt;= #{nowHour}
  857. </if>
  858. group by item_id) t1
  859. left join (select item_id as 'itemId',
  860. count(oid) as 'orderNum',
  861. round(sum(pay_amount) / 100, 2) as 'payAmount'
  862. from jy_order_list
  863. where clip_user_id = #{clipUserId}
  864. and stat_date &gt;= #{lastStart}
  865. and stat_date &lt;= #{lastEnd}
  866. <if test='nowHour != null and nowHour != ""'>
  867. and stat_hour &lt;= #{nowHour}
  868. </if>
  869. group by item_id) t2 on t1.itemId = t2.itemId
  870. order by t1.orderNum desc
  871. </select>
  872. <select id="getItemPromoterDetail" resultType="com.alibaba.fastjson.JSONObject">
  873. select t.*,
  874. round((t.orderNum - tt.orderNum) / tt.orderNum * 100, 2) as 'orderNumRate',
  875. round((t.payAmount - tt.payAmount) / tt.payAmount * 100, 2) as 'payAmountRate'
  876. from (select t1.*,
  877. t2.promoter_url as 'promoterUrl',
  878. t2.user_name as 'userName',
  879. (case WHEN t2.type = 1 then '自营'
  880. when t2.type = 2 then '分销'
  881. else '-'
  882. end
  883. ) as 'promoterType'
  884. from (select clip_user_id as 'clipUserId',
  885. clip_nick_name as 'clipNickName',
  886. count(oid) as 'orderNum',
  887. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid) * 100,
  888. 2) as 'validRadio',
  889. round(sum(pay_amount) / 100, 2) as 'payAmount',
  890. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100,
  891. 2) as 'validPayAmount',
  892. round(sum(case when order_status != 80 then pay_amount else 0 end) / sum(pay_amount) * 100,
  893. 2) as 'validPayAmountRadio',
  894. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  895. round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case
  896. when order_status != 80
  897. then 1
  898. else 0 end) *
  899. 100,
  900. 2) as 'deliveryRadio'
  901. from jy_order_list
  902. where item_id = #{itemId}
  903. and stat_date &gt;= #{start}
  904. and stat_date &lt;= #{end}
  905. <if test='nowHour != null and nowHour != ""'>
  906. and stat_hour &lt;= #{nowHour}
  907. </if>
  908. <if test='promoterIds != null and promoterIds.size() > 0'>
  909. AND clip_user_id in
  910. <foreach collection="promoterIds" item="item" separator=","
  911. open="(" close=")">
  912. #{item}
  913. </foreach>
  914. </if>
  915. group by clip_user_id) t1
  916. left join jy_kuaishou_promoter t2 on t1.clipUserId = t2.promoter_id) t
  917. left join (select clip_user_id as 'clipUserId',
  918. count(oid) as 'orderNum',
  919. round(sum(pay_amount) / 100, 2) as 'payAmount'
  920. from jy_order_list
  921. where item_id = #{itemId}
  922. and stat_date &gt;= #{lastStart}
  923. and stat_date &lt;= #{lastEnd}
  924. <if test='nowHour != null and nowHour != ""'>
  925. and stat_hour &lt;= #{nowHour}
  926. </if>
  927. <if test='promoterIds != null and promoterIds.size() > 0'>
  928. AND clip_user_id in
  929. <foreach collection="promoterIds" item="item" separator=","
  930. open="(" close=")">
  931. #{item}
  932. </foreach>
  933. </if>
  934. group by clip_user_id) tt on t.clipUserId = tt.clipUserId
  935. order by t.orderNum desc
  936. </select>
  937. </mapper>