JiaoYangReportMapper.xml 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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.JiaoYangReportMapper">
  6. <insert id="replaceItems">
  7. replace into jy_auth_order(
  8. item_id,
  9. item_name,
  10. item_image_url,
  11. item_price_view,
  12. commission_rate_view,
  13. promoter_id,
  14. promoter_nick,
  15. promoter_photo,
  16. mcn_commission_rate_view,
  17. sort_count
  18. )
  19. values
  20. <foreach collection="adds" item="add" separator=",">
  21. (
  22. #{add.itemId},
  23. #{add.itemName},
  24. #{add.itemImageUrl},
  25. #{add.itemPriceView},
  26. #{add.commissionRateView},
  27. #{add.promoterId},
  28. #{add.promoterNick},
  29. #{add.promoterPhoto},
  30. #{add.mcnCommissionRateView},
  31. #{add.sortCount}
  32. )
  33. </foreach>
  34. </insert>
  35. <delete id="deleteAuthItem">
  36. delete
  37. from jy_auth_order
  38. where 1 = 1
  39. </delete>
  40. <select id="item" resultType="com.alibaba.fastjson.JSONObject">
  41. select t.* from (
  42. select
  43. t1.item_id as 'itemId',
  44. t1.reserve_price as 'reservePrice',
  45. t1.item_title as 'itemTitle',
  46. t1.image_url as 'imageUrl',
  47. count(t1.oid) as 'orderNum',
  48. sum(case when t1.order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  49. round(sum(case when t1.order_status != 80 then 1 else 0 end) / count(t1.oid), 4) as 'validRadio',
  50. sum(case when t1.send_status = 1 and t1.order_status != 80 then 1 else 0 end) as 'deliveryNum',
  51. sum(case when t1.send_status = 0 and t1.order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  52. round(sum(case when t1.send_status = 1 and t1.order_status != 80 then 1 else 0 end) / sum(case when
  53. t1.order_status != 80 then 1 else 0 end), 4) as 'deliveryRadio',
  54. t1.commission_rate as 'itemCommissionRate'
  55. from jy_order_list t1
  56. where 1 = 1
  57. <if test="start != null and start != ''">
  58. and t1.stat_date &gt;= #{start}
  59. </if>
  60. <if test="end != null and end != ''">
  61. and t1.stat_date &lt;= #{end}
  62. </if>
  63. <if test="itemId != null and itemId != ''">
  64. and t1.item_id = #{itemId}
  65. </if>
  66. <if test="itemTitle != null and itemTitle != ''">
  67. and t1.item_title like concat(concat('%',#{itemTitle}),'%')
  68. </if>
  69. group by t1.item_id) t
  70. order by ${fieId} ${sort}
  71. </select>
  72. <select id="itemDetail" resultType="com.alibaba.fastjson.JSONObject">
  73. select t.*,tt.headImg,ttt.type,ttt.user_name as 'userName'
  74. from (
  75. select
  76. clip_nick_name as 'promoterNickName',
  77. clip_user_id as 'promoterId',
  78. count(oid) as 'orderNum',
  79. sum(case when order_status != 80 then pay_amount else 0 end) as 'payAmount',
  80. regimental_promotion_rate as 'regimentalPromotionRate',
  81. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  82. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
  83. sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
  84. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  85. round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
  86. then 1 else 0 end),4) as 'deliveryRadio'
  87. from jy_order_list
  88. where 1= 1
  89. <if test="itemId != null and itemId != ''">
  90. and item_id = #{itemId}
  91. </if>
  92. <if test="start != null and start != ''">
  93. and stat_date &gt;= #{start}
  94. </if>
  95. <if test="end != null and end != ''">
  96. and stat_date &lt;= #{end}
  97. </if>
  98. <if test="promoterId != null and promoterId != ''">
  99. and clip_user_id = #{promoterId}
  100. </if>
  101. <if test="promoterNickName != null and promoterNickName != ''">
  102. and clip_nick_name like concat(concat('%',#{promoterNickName}),'%')
  103. </if>
  104. group by clip_user_id) t
  105. left join (select clip_id,head_img as 'headImg' from jy_clip_cooperation where stat_date =
  106. DATE_FORMAT(NOW(),'%Y%m%d') ) tt on t.promoterId = tt.clip_id
  107. left join jy_kuaishou_promoter ttt on t.promoterId = ttt.promoter_id
  108. order by t.orderNum desc
  109. </select>
  110. <select id="promoter" resultType="com.alibaba.fastjson.JSONObject">
  111. select t.*,
  112. tt.head_img as 'headImg',
  113. tt.video_count as 'videoCount',
  114. tt.video_show as 'videoShow',
  115. ttt.type as 'type',
  116. ttt.user_name as 'userName',
  117. ttt.expert_mentor_name as 'expertMentorName',
  118. ttt.expert_business_name as 'expertBusinessName'
  119. from (
  120. select clip_user_id as 'promoterId',
  121. clip_nick_name as 'promoterNickName',
  122. count(oid) as 'orderNum',
  123. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  124. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
  125. sum(pay_amount) as 'payAmount',
  126. sum(case when order_status != 80 then pay_amount else 0
  127. end) as 'validPayAmount',
  128. sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
  129. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  130. round(
  131. sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case
  132. when order_status != 80
  133. then 1
  134. else 0 end),
  135. 4) as 'deliveryRadio',
  136. sum(case when order_status != 80 then mcn_promotion_amount else 0 end) as 'regimentalPromotionAmount'
  137. from jy_order_list
  138. where 1 = 1
  139. <if test="start != null and start != '' ">
  140. and stat_date &gt;= #{start}
  141. </if>
  142. <if test="end != null and end != '' ">
  143. and stat_date &lt;= #{end}
  144. </if>
  145. <if test="promoterId != null and promoterId != '' ">
  146. and clip_user_id = #{promoterId}
  147. </if>
  148. <if test="promoterNickName != null and promoterNickName != '' ">
  149. and clip_nick_name like concat(concat('%',#{promoterNickName}),'%')
  150. </if>
  151. <if test='promoterIds != null and promoterIds.size() > 0'>
  152. AND clip_user_id in
  153. <foreach collection="promoterIds" item="item" separator=","
  154. open="(" close=")">
  155. #{item}
  156. </foreach>
  157. </if>
  158. group by clip_user_id) t
  159. left join ( select * from jy_clip_cooperation where stat_date = DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -1
  160. DAY),'%Y%m%d') ) tt on t.promoterId = tt.clip_id
  161. left join jy_kuaishou_promoter ttt on t.promoterId = ttt.promoter_id
  162. where 1 = 1
  163. <if test="type != null and type != '' ">
  164. and ttt.type = #{type}
  165. </if>
  166. order by t.payAmount desc
  167. </select>
  168. <select id="anchorOrderDetail" resultType="com.alibaba.fastjson.JSONObject">
  169. select t.*
  170. from (select
  171. item_title as 'itemTitle',
  172. item_id as 'itemId',
  173. reserve_price as 'reservePrice',
  174. image_url 'imageUrl',
  175. count(oid) as 'orderNum',
  176. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  177. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
  178. sum(case when order_status != 80 then pay_amount else 0 end) as 'payAmount',
  179. regimental_promotion_rate as 'regimentalPromotionRate',
  180. sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
  181. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  182. round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
  183. then 1 else 0 end),4) as 'deliveryRadio'
  184. from jy_order_list
  185. where 1= 1
  186. <if test="promoterId != null and promoterId != ''">
  187. and clip_user_id = #{promoterId}
  188. </if>
  189. <if test="start != null and start != ''">
  190. and stat_date &gt;= #{start}
  191. </if>
  192. <if test="end != null and end != ''">
  193. and stat_date &lt;= #{end}
  194. </if>
  195. <if test="itemId != null and itemId != ''">
  196. and item_id = #{itemId}
  197. </if>
  198. <if test="itemTitle != null and itemTitle != ''">
  199. and item_title like concat(concat('%',#{itemTitle}),'%')
  200. </if>
  201. <if test='promoterIds != null and promoterIds.size() > 0'>
  202. AND clip_user_id in
  203. <foreach collection="promoterIds" item="item" separator=","
  204. open="(" close=")">
  205. #{item}
  206. </foreach>
  207. </if>
  208. group by item_id) t
  209. order by t.orderNum desc
  210. </select>
  211. <select id="promoterStatistics" resultType="com.alibaba.fastjson.JSONObject">
  212. select date_format(t.stat_date, '%Y-%m-%d') as 'date',
  213. count(t.oid) as 'orderNum'
  214. from (select oid,
  215. stat_date
  216. from jy_order_list
  217. where 1 = 1
  218. <if test="promoterId != null and promoterId != ''">
  219. and clip_user_id = #{promoterId}
  220. </if>
  221. <if test="start != null and start != ''">
  222. and stat_date &gt;= #{start}
  223. </if>
  224. <if test="end != null and end != ''">
  225. and stat_date &lt;= #{end}
  226. </if>
  227. <if test='promoterIds != null and promoterIds.size() > 0'>
  228. AND clip_user_id in
  229. <foreach collection="promoterIds" item="item" separator=","
  230. open="(" close=")">
  231. #{item}
  232. </foreach>
  233. </if>
  234. ) t
  235. group by t.stat_date
  236. order by t.stat_date asc
  237. </select>
  238. <select id="getClipCooperation" resultType="com.alibaba.fastjson.JSONObject">
  239. select clip_id as 'clipId',
  240. clip_name as 'clipName',
  241. head_img as 'headImg',
  242. fans_num as 'fansNum',
  243. gmv_30d as 'gmv30d',
  244. start_time as 'startTime',
  245. end_time as 'endTime',
  246. (case when status = 1
  247. then '上架'
  248. when status = 3
  249. then '已结束'
  250. when status = 2
  251. then '待确认'
  252. else '-'
  253. end
  254. ) as 'status',
  255. termination_reason as 'terminationReason',
  256. concat(commission_rate_view,'%') as 'commissionRateView',
  257. shop_score as 'shopScore',
  258. clip_gmv_30d as 'clipGmv30d',
  259. auth_item_gmv_30d as 'authItemGmv30d',
  260. video_count as 'videoCount',
  261. video_count as 'videoShow',
  262. stat_date as 'statDate'
  263. from jy_clip_cooperation
  264. where
  265. stat_date = #{date}
  266. <if test="promoterId != null and promoterId != ''">
  267. and clip_id = #{promoterId}
  268. </if>
  269. <if test="promoterName != null and promoterName != ''">
  270. and clip_name like concat(concat('%',#{promoterName}),'%')
  271. </if>
  272. </select>
  273. <select id="getOrderTotal" resultType="com.alibaba.fastjson.JSONObject">
  274. select
  275. count(oid) as 'orderNum',
  276. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  277. sum(case when order_status = 80 then 1 else 0 end) as 'invalidOrderNUm'
  278. from jy_order_list
  279. where 1= 1
  280. <if test="start != null and start != ''">
  281. and stat_date &gt;= #{start}
  282. </if>
  283. <if test="end != null and end != ''">
  284. and stat_date &lt;= #{end}
  285. </if>
  286. <if test='promoterIds != null and promoterIds.size() > 0'>
  287. AND clip_user_id in
  288. <foreach collection="promoterIds" item="item" separator=","
  289. open="(" close=")">
  290. #{item}
  291. </foreach>
  292. </if>
  293. </select>
  294. <select id="getOrderTotalRatio" resultType="java.lang.Double">
  295. select
  296. round((t1.oid -t2.oid) / t2.oid , 4) as 'orderTotalRatio'
  297. from (select count(oid) as 'oid'
  298. from jy_order_list
  299. where 1= 1
  300. <if test="nowDate != null and nowDate != ''">
  301. and stat_date = #{nowDate}
  302. </if>
  303. <if test="hour != null and hour != ''">
  304. and stat_hour &lt;= #{hour}
  305. </if>
  306. <if test='promoterIds != null and promoterIds.size() > 0'>
  307. AND clip_user_id in
  308. <foreach collection="promoterIds" item="item" separator=","
  309. open="(" close=")">
  310. #{item}
  311. </foreach>
  312. </if>
  313. ) t1
  314. join (select count(oid) as 'oid'
  315. from jy_order_list
  316. where 1=1
  317. <if test="yesDate != null and yesDate != ''">
  318. and stat_date = #{yesDate}
  319. </if>
  320. <if test="hour != null and hour != ''">
  321. and stat_hour &lt;= #{hour}
  322. </if>
  323. <if test='promoterIds != null and promoterIds.size() > 0'>
  324. AND clip_user_id in
  325. <foreach collection="promoterIds" item="item" separator=","
  326. open="(" close=")">
  327. #{item}
  328. </foreach>
  329. </if>
  330. ) t2
  331. </select>
  332. <select id="getServiceAmountTotal" resultType="com.alibaba.fastjson.JSONObject">
  333. select
  334. count(distinct clip_user_id) as 'promoterNum',
  335. sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
  336. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  337. round(sum(case when send_status = 1 then 1 else 0 end) / sum(case when order_status != 80 then 1 else 0 end),4)
  338. as 'deliveryRadio'
  339. from jy_order_list
  340. where 1= 1
  341. <if test="start != null and start != ''">
  342. and stat_date &gt;= #{start}
  343. </if>
  344. <if test="end != null and end != ''">
  345. and stat_date &lt;= #{end}
  346. </if>
  347. <if test='promoterIds != null and promoterIds.size() > 0'>
  348. AND clip_user_id in
  349. <foreach collection="promoterIds" item="item" separator=","
  350. open="(" close=")">
  351. #{item}
  352. </foreach>
  353. </if>
  354. </select>
  355. <select id="getAmountTotal" resultType="com.alibaba.fastjson.JSONObject">
  356. select
  357. sum(order_amount) as 'orderAmount',
  358. sum(base_amount) as 'baseAmount',
  359. sum(case when order_status != 80 then mcn_promotion_amount else 0 end) as 'regimentalPromotionAmount',
  360. sum(case when order_status != 80 then total_regimental_settle_amount else 0 end) as
  361. 'totalRegimentalSettleAmount'
  362. from jy_order_list
  363. where 1= 1
  364. <if test="start != null and start != ''">
  365. and stat_date &gt;= #{start}
  366. </if>
  367. <if test="end != null and end != ''">
  368. and stat_date &lt;= #{end}
  369. </if>
  370. <if test='promoterIds != null and promoterIds.size() > 0'>
  371. AND clip_user_id in
  372. <foreach collection="promoterIds" item="item" separator=","
  373. open="(" close=")">
  374. #{item}
  375. </foreach>
  376. </if>
  377. </select>
  378. <select id="getAmountTotalRatio" resultType="java.lang.Double">
  379. select
  380. round((t1.payAmount -t2.payAmount) / t2.payAmount , 4) as 'amountTotalRatio'
  381. from (select sum(pay_amount) as 'payAmount'
  382. from jy_order_list
  383. where 1= 1
  384. <if test="nowDate != null and nowDate != ''">
  385. and stat_date = #{nowDate}
  386. </if>
  387. <if test="hour != null and hour != ''">
  388. and stat_hour &lt;= #{hour}
  389. </if>
  390. <if test='promoterIds != null and promoterIds.size() > 0'>
  391. AND clip_user_id in
  392. <foreach collection="promoterIds" item="item" separator=","
  393. open="(" close=")">
  394. #{item}
  395. </foreach>
  396. </if>
  397. ) t1
  398. join (select sum(pay_amount) as 'payAmount'
  399. from jy_order_list
  400. where 1=1
  401. <if test="yesDate != null and yesDate != ''">
  402. and stat_date = #{yesDate}
  403. </if>
  404. <if test="hour != null and jhour != ''">
  405. and stat_hour &lt;= #{hour}
  406. </if>
  407. <if test='promoterIds != null and promoterIds.size() > 0'>
  408. AND clip_user_id in
  409. <foreach collection="promoterIds" item="item" separator=","
  410. open="(" close=")">
  411. #{item}
  412. </foreach>
  413. </if>
  414. ) t2
  415. </select>
  416. <select id="getPromoterRankRatioList" resultType="com.alibaba.fastjson.JSONObject">
  417. select
  418. t1.*,
  419. round((t1.orderNum - t2.orderNum) / t2.orderNum,4) as 'radio'
  420. from (
  421. select
  422. clip_user_id as 'promoterId',
  423. clip_nick_name as 'promoterNickName',
  424. count(oid) as 'orderNum',
  425. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  426. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio'
  427. from jy_order_list
  428. where 1= 1
  429. <if test="nowDate != null and nowDate != ''">
  430. and stat_date = #{nowDate}
  431. </if>
  432. <if test="hour != null and hour != ''">
  433. and stat_hour &lt;= #{hour}
  434. </if>
  435. <if test='promoterIds != null and promoterIds.size() > 0'>
  436. AND clip_user_id in
  437. <foreach collection="promoterIds" item="item" separator=","
  438. open="(" close=")">
  439. #{item}
  440. </foreach>
  441. </if>
  442. group by clip_user_id
  443. ) t1
  444. left join (select
  445. clip_user_id as 'promoterId',
  446. count(oid) as 'orderNum'
  447. from jy_order_list
  448. where 1=1
  449. <if test="yesDate != null and yesDate != ''">
  450. and stat_date = #{yesDate}
  451. </if>
  452. <if test="hour != null and hour != ''">
  453. and stat_hour &lt;= #{hour}
  454. </if>
  455. <if test='promoterIds != null and promoterIds.size() > 0'>
  456. AND clip_user_id in
  457. <foreach collection="promoterIds" item="item" separator=","
  458. open="(" close=")">
  459. #{item}
  460. </foreach>
  461. </if>
  462. group by clip_user_id
  463. ) t2 on t1.promoterId = t2.promoterId
  464. order by t1.orderNum desc
  465. </select>
  466. <select id="getPromoterRatioList" resultType="com.alibaba.fastjson.JSONObject">
  467. select * from (
  468. select
  469. clip_user_id as 'promoterId',
  470. clip_nick_name as 'promoterNickName',
  471. count(oid) as 'orderNum',
  472. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  473. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio'
  474. from jy_order_list
  475. where 1= 1
  476. <if test="start != null and start != ''">
  477. and stat_date &gt;= #{start}
  478. </if>
  479. <if test="end != null and end != ''">
  480. and stat_date &lt;= #{end}
  481. </if>
  482. <if test='promoterIds != null and promoterIds.size() > 0'>
  483. AND clip_user_id in
  484. <foreach collection="promoterIds" item="item" separator=","
  485. open="(" close=")">
  486. #{item}
  487. </foreach>
  488. </if>
  489. group by clip_user_id) t
  490. order by t.orderNum desc
  491. </select>
  492. <select id="getOrderRankRatioList" resultType="com.alibaba.fastjson.JSONObject">
  493. select
  494. t1.*,
  495. round((t1.orderNum - t2.orderNum) / t2.orderNum,4) as 'radio'
  496. from (select
  497. item_id as 'itemId',
  498. item_title as 'itemTitle',
  499. image_url as 'imageUrl',
  500. count(oid) as 'orderNum',
  501. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  502. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
  503. sum(case when send_status = 1 then 1 else 0 end) as 'deliveryNum',
  504. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  505. round(sum(case when send_status = 1 then 1 else 0 end) / sum(case when order_status != 80 then 1 else 0 end),4)
  506. as 'deliveryRadio',
  507. concat(round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2),'%' )as 'grossMargin'
  508. from jy_order_list
  509. where 1= 1
  510. <if test="nowDate != null and nowDate != ''">
  511. and stat_date = #{nowDate}
  512. </if>
  513. <if test="hour != null and hour != ''">
  514. and stat_hour &lt;= #{hour}
  515. </if>
  516. group by item_id
  517. ) t1
  518. left join (select
  519. item_id as 'itemId',
  520. count(oid) as 'orderNum'
  521. from jy_order_list
  522. where 1=1
  523. <if test="yesDate != null and yesDate != ''">
  524. and stat_date = #{yesDate}
  525. </if>
  526. <if test="hour != null and hour != ''">
  527. and stat_hour &lt;= #{hour}
  528. </if>
  529. group by item_id
  530. ) t2 on t1.itemId = t2.itemId
  531. order by t1.orderNum desc
  532. </select>
  533. <select id="getOrderRankList" resultType="com.alibaba.fastjson.JSONObject">
  534. select * from (
  535. select
  536. item_id as 'itemId',
  537. item_title as 'itemTitle',
  538. image_url as 'imageUrl',
  539. count(oid) as 'orderNum',
  540. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
  541. round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
  542. sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
  543. sum(case when send_status = 0 and order_status != 80 then 1 else 0 end) as 'notDeliveryNum',
  544. round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
  545. then 1 else 0 end),4) as 'deliveryRadio',
  546. concat(round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2),'%' )as 'grossMargin'
  547. from jy_order_list
  548. where 1= 1
  549. <if test="start != null and start != ''">
  550. and stat_date &gt;= #{start}
  551. </if>
  552. <if test="end != null and end != ''">
  553. and stat_date &lt;= #{end}
  554. </if>
  555. group by item_id) t
  556. order by t.orderNum desc
  557. </select>
  558. <select id="indexStatistics" resultType="com.alibaba.fastjson.JSONObject">
  559. select date_format(t.stat_date,'%Y-%m-%d') as 'date',
  560. <if test="type == 'orderNum' ">
  561. count(t.oid) as 'orderNum'
  562. </if>
  563. <if test="type == 'validOrderNum' ">
  564. sum(case when t.order_status = 80 then 1 else 0 end) as 'validOrderNum'
  565. </if>
  566. <if test="type == 'orderAmount' ">
  567. sum(t.order_amount) as 'orderAmount'
  568. </if>
  569. <if test="type == 'baseAmount' ">
  570. sum(t.base_amount) as 'baseAmount'
  571. </if>
  572. <if test="type == 'deliveryNum' ">
  573. sum(case when t.send_status = 1 and t.order_status != 80 then 1 else 0 end) as 'deliveryNum'
  574. </if>
  575. from (select
  576. oid,
  577. order_status,
  578. order_amount,
  579. base_amount,
  580. send_status,
  581. stat_date
  582. from jy_order_list
  583. where 1 = 1
  584. <if test="start != null and start != ''">
  585. and stat_date &gt;= #{start}
  586. </if>
  587. <if test="end != null and end != ''">
  588. and stat_date &lt;= #{end}
  589. </if>
  590. <if test='promoterIds != null and promoterIds.size() > 0'>
  591. AND clip_user_id in
  592. <foreach collection="promoterIds" item="item" separator=","
  593. open="(" close=")">
  594. #{item}
  595. </foreach>
  596. </if>
  597. ) t
  598. group by t.stat_date
  599. order by t.stat_date asc
  600. </select>
  601. <select id="getTimeIntervalRatio" resultType="com.alibaba.fastjson.JSONObject">
  602. select
  603. round((t1.oid -t2.oid) / t2.oid , 4) as 'orderTotalRatio',
  604. round((t1.orderAmount -t2.orderAmount) / t2.orderAmount , 4) as 'orderAmountRatio'
  605. from (
  606. select count(oid) as 'oid',
  607. sum(order_amount) as 'orderAmount'
  608. from jy_order_list
  609. where 1= 1
  610. <if test="thisCycleStartTemp != null and thisCycleStartTemp != ''">
  611. and stat_date &gt;= #{thisCycleStartTemp}
  612. </if>
  613. <if test="thisCycleEndTemp != null and thisCycleEndTemp != ''">
  614. and stat_date &lt;= #{thisCycleEndTemp}
  615. </if>
  616. <if test='promoterIds != null and promoterIds.size() > 0'>
  617. AND clip_user_id in
  618. <foreach collection="promoterIds" item="item" separator=","
  619. open="(" close=")">
  620. #{item}
  621. </foreach>
  622. </if>
  623. ) t1
  624. join (
  625. select count(oid) as 'oid',
  626. sum(order_amount) as 'orderAmount'
  627. from jy_order_list
  628. where 1=1
  629. <if test="lastCycleStartTemp != null and lastCycleStartTemp != ''">
  630. and stat_date &gt;= #{lastCycleStartTemp}
  631. </if>
  632. <if test="lastCycleStartTemp != null and lastCycleStartTemp != ''">
  633. and stat_date &lt;= #{lastCycleEndTemp}
  634. </if>
  635. <if test='promoterIds != null and promoterIds.size() > 0'>
  636. AND clip_user_id in
  637. <foreach collection="promoterIds" item="item" separator=","
  638. open="(" close=")">
  639. #{item}
  640. </foreach>
  641. </if>
  642. ) t2
  643. </select>
  644. <select id="getPromoterIdsByUserIds" resultType="java.lang.Long">
  645. select promoter_id from jy_kuaishou_promoter where
  646. 1 = 1
  647. and user_id in
  648. <foreach collection="userIds" item="userId" separator="," open="(" close=")">
  649. #{userId}
  650. </foreach>
  651. </select>
  652. <select id="dayData" resultType="com.alibaba.fastjson.JSONObject">
  653. select *,
  654. t1.gmv - t2.lastGmv as 'gvmGap',
  655. t1.orderNum - t2.lastOrderNum as 'orderNumGap',
  656. t1.validGmv - t2.lastValidGmv as 'validGmvGap',
  657. t1.validOrderNUm - t2.lastValidOrderNUm as 'validOrderNumGap',
  658. t1.mcnPromotionAmount - t2.lastMcnPromotionAmount as 'mcnPromotionAmountGap',
  659. t1.grossMargin - t2.lastGrossMargin as 'grossMarginGap'
  660. from (select
  661. concat(concat(concat( date_format(#{startDate},'%m%d'),'~')), date_format(#{endDate},'%m%d') ) as 'date',
  662. round(sum(pay_amount) / 100, 2) as 'gmv',
  663. count(oid) as 'orderNum',
  664. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100, 2) as 'validGmv',
  665. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNum',
  666. round(sum(mcn_promotion_amount) / 100, 2) as 'mcnPromotionAmount',
  667. round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2) as 'grossMargin'
  668. from jy_order_list t1
  669. where 1 = 1
  670. and t1.stat_date &gt;= #{startDate}
  671. and t1.stat_date &lt;= #{endDate}
  672. <if test='dataType == "1" '>
  673. and t1.clip_user_id in (
  674. select promoter_id from jy_kuaishou_promoter
  675. where `type` = 1
  676. group by promoter_id
  677. )
  678. </if>
  679. <if test=' dataType == "2" '>
  680. and t1.clip_user_id not in (
  681. select promoter_id from jy_kuaishou_promoter
  682. where `type` = 1
  683. group by promoter_id
  684. )
  685. </if>
  686. ) t1
  687. join
  688. (
  689. select
  690. concat(concat(concat( date_format(#{lastStart},'%m%d'),'~')), date_format(#{lastEnd},'%m%d') ) as
  691. 'lastDate',
  692. round(sum(pay_amount) / 100, 2) as 'lastGmv',
  693. count(oid) as 'lastOrderNum',
  694. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100, 2) as 'lastValidGmv',
  695. sum(case when order_status != 80 then 1 else 0 end) as 'lastValidOrderNum',
  696. round(sum(mcn_promotion_amount) / 100, 2) as 'lastMcnPromotionAmount',
  697. round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2) as 'lastGrossMargin'
  698. from jy_order_list t1
  699. where 1 = 1
  700. and t1.stat_date &gt;= #{lastStart}
  701. and t1.stat_date &lt;= #{lastEnd}
  702. <if test='dataType == "1"'>
  703. and t1.clip_user_id in (
  704. select promoter_id from jy_kuaishou_promoter
  705. where `type` = 1
  706. group by promoter_id
  707. )
  708. </if>
  709. <if test='dataType == "2" '>
  710. and t1.clip_user_id not in (
  711. select promoter_id from jy_kuaishou_promoter
  712. where `type` = 1
  713. group by promoter_id
  714. )
  715. </if>
  716. ) t2
  717. </select>
  718. <select id="monthData" resultType="com.alibaba.fastjson.JSONObject">
  719. select *,
  720. concat(ROUND((t1.gmv - t2.lastGmv) / t2.lastGmv * 100, 2) ,'%') as 'gvmRadio',
  721. concat(ROUND((t1.orderNum - t2.lastOrderNum) / t2.lastOrderNum * 100, 2),'%') as 'orderNumRadio',
  722. concat(ROUND((t1.validGmv - t2.lastValidGmv) / t2.lastValidGmv * 100, 2) ,'%')as 'validGmvRadio',
  723. concat(ROUND((t1.validOrderNUm - t2.lastValidOrderNUm) / t2.lastValidOrderNUm * 100,
  724. 2) ,'%')as 'validOrderNumRadio',
  725. concat(ROUND((t1.mcnPromotionAmount - t2.lastMcnPromotionAmount) / t2.lastMcnPromotionAmount * 100,
  726. 2) ,'%')as 'mcnPromotionAmountRadio',
  727. ROUND((t1.grossMargin - t2.lastGrossMargin) / t2.lastGrossMargin * 100,
  728. 2) as 'grossMarginRadio'
  729. from (select CONCAT(date_format(#{nowMonthEndDate} ,'%Y/%m/%d') , '合计') as 'date',
  730. round(sum(pay_amount) / 100, 2) as 'gmv',
  731. count(oid) as 'orderNum',
  732. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100, 2) as 'validGmv',
  733. sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNum',
  734. round(sum(mcn_promotion_amount) / 100, 2) as 'mcnPromotionAmount',
  735. round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2) as 'grossMargin'
  736. from jy_order_list t1
  737. where t1.stat_date >= #{nowMonthStartDate}
  738. and t1.stat_date &lt;= #{nowMonthEndDate}
  739. <if test='dataType == "1"'>
  740. and t1.clip_user_id in (
  741. select promoter_id from jy_kuaishou_promoter
  742. where `type` = 1
  743. group by promoter_id
  744. )
  745. </if>
  746. <if test='dataType == "2" '>
  747. and t1.clip_user_id not in (
  748. select promoter_id from jy_kuaishou_promoter
  749. where `type` = 1
  750. group by promoter_id
  751. )
  752. </if>
  753. ) t1
  754. join (select CONCAT(date_format(#{lastMonthEndDate} ,'%Y/%m/%d') , '合计') as 'lastDate',
  755. round(sum(pay_amount) / 100, 2) as 'lastGmv',
  756. count(oid) as 'lastOrderNum',
  757. round(sum(case when order_status != 80 then pay_amount else 0 end) / 100, 2) as 'lastValidGmv',
  758. sum(case when order_status != 80 then 1 else 0 end) as 'lastValidOrderNum',
  759. round(sum(mcn_promotion_amount) / 100, 2) as 'lastMcnPromotionAmount',
  760. round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2) as 'lastGrossMargin'
  761. from jy_order_list t1
  762. where t1.stat_date >= #{lastMonthStartDate}
  763. and t1.stat_date &lt;= #{lastMonthEndDate}
  764. <if test='dataType == "1"'>
  765. and t1.clip_user_id in (
  766. select promoter_id from jy_kuaishou_promoter
  767. where `type` = 1
  768. group by promoter_id
  769. )
  770. </if>
  771. <if test='dataType == "2"'>
  772. and t1.clip_user_id not in (
  773. select promoter_id from jy_kuaishou_promoter
  774. where `type` = 1
  775. group by promoter_id
  776. )
  777. </if>
  778. ) t2
  779. </select>
  780. <select id="getTopItem" resultType="com.alibaba.fastjson.JSONObject">
  781. select t1.*,
  782. t2.promotionVolume as 'yesPromotionVolume',
  783. t1.promotionVolume - t2.promotionVolume as 'difference',
  784. round((t1.promotionVolume - t2.promotionVolume) / t2.promotionVolume * 100, 2) as 'increaseInPrice',
  785. (
  786. case when t2.itemId is null
  787. then 1
  788. else 2
  789. end
  790. ) as 'isNew'
  791. from (select clip_id as 'clipId',
  792. clip_name as 'clipName',
  793. item_id as 'itemId',
  794. item_name as 'itemName',
  795. item_img_url as 'itemImgUrl',
  796. item_price as 'itemPrice',
  797. promotion_volume as 'promotionVolume',
  798. promotion_promoter_count as 'promotionPromoterCount'
  799. from jy_clip_top_list
  800. where stat_date = #{date}
  801. <if test="promoterId != null and promoterId != ''">
  802. and clip_id = #{promoterId}
  803. </if>
  804. ) t1
  805. left join (select clip_id as 'clipId',
  806. item_id as 'itemId',
  807. promotion_volume as 'promotionVolume'
  808. from jy_clip_top_list
  809. where stat_date = DATE_FORMAT(DATE_ADD(#{date}, INTERVAL -1 DAY),'%Y%m%d')
  810. <if test="promoterId != null and promoterId != ''">
  811. and clip_id = #{promoterId}
  812. </if>
  813. ) t2
  814. on t1.clipId = t2.clipId and t1.itemId = t2.itemId
  815. order by ${fieId} ${sort}
  816. </select>
  817. <select id="getTopItemUser" resultType="com.alibaba.fastjson.JSONObject">
  818. select id, name
  819. from jy_fx_top_item_config
  820. </select>
  821. <select id="getDataByDate" resultType="com.alibaba.fastjson.JSONObject" parameterType="java.lang.Long">
  822. select stat_hour as 'time', round(sum(order_amount) / 100, 2) as 'charge'
  823. from jy_order_list
  824. where stat_date = #{date}
  825. group by stat_hour
  826. order by stat_hour
  827. </select>
  828. <select id="getJiaoYangCookie" resultType="java.lang.String">
  829. select cookie
  830. from jy_fx_cookie limit 1
  831. </select>
  832. <select id="getAuthItemList" resultType="com.alibaba.fastjson.JSONObject">
  833. select
  834. cast(item_id as char ) as 'itemId',
  835. item_name as 'itemName',
  836. item_image_url as 'itemImageUrl',
  837. item_price_view as 'itemPriceView',
  838. commission_rate_view as 'commissionRateView',
  839. promoter_id as 'promoterId',
  840. promoter_nick as 'promoterNick',
  841. promoter_photo as 'promoterPhoto',
  842. mcn_commission_rate_view as 'mcnCommissionRateView'
  843. from jy_auth_order
  844. where 1 = 1
  845. <if test="itemId != null and itemId != ''">
  846. and item_id = #{itemId}
  847. </if>
  848. <if test="itemName != null and itemName != ''">
  849. and item_name like concat(concat('%',#{itemName}),'%')
  850. </if>
  851. <if test="promoterId != null and promoterId != ''">
  852. and promoter_id = #{promoterId}
  853. </if>
  854. <if test="promoterNick != null and promoterNick != ''">
  855. and promoter_nick like concat(concat('%',#{promoterNick}),'%')
  856. </if>
  857. order by sort_count asc
  858. </select>
  859. <select id="getTypeData" resultType="com.alibaba.fastjson.JSONObject">
  860. select concat('自营:', t1.orderNum) as 'selfOrderNum', t1.gmv as 'selfGmv', concat(t1.grossMargin,'%' )as 'selfGrossProfit', concat('分销:', t2.orderNum) as 'disOrderNum', t2.gmv as 'disGmv', concat(t2.grossMargin,'%') as 'disGrossProfit'
  861. from (select count(oid) as 'orderNum', round(sum(pay_amount) / 100, 2) as 'gmv', round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2) as 'grossMargin'
  862. from jy_order_list
  863. where 1 = 1
  864. and stat_date &gt;= #{start}
  865. and stat_date &lt;= #{end}
  866. and clip_user_id in (select promoter_id
  867. from jy_kuaishou_promoter
  868. where `type` = 1
  869. group by promoter_id)) t1
  870. join (select count(oid) as 'orderNum', round(sum(pay_amount) / 100, 2) as 'gmv', round(sum(mcn_promotion_amount) / sum(pay_amount) * 100, 2) as 'grossMargin'
  871. from jy_order_list
  872. where 1 = 1
  873. and stat_date &gt;= #{start}
  874. and stat_date &lt;= #{end}
  875. and clip_user_id not in (select promoter_id
  876. from jy_kuaishou_promoter
  877. where `type` = 1
  878. group by promoter_id)) t2
  879. </select>
  880. <select id="getPromoterIdsByBusinessId" resultType="java.lang.Long" parameterType="java.lang.Long">
  881. select promoter_id
  882. from jy_kuaishou_promoter
  883. where expert_business_id = #{userId}
  884. group by promoter_id
  885. </select>
  886. <select id="getPromoterIdsByMentorId" resultType="java.lang.Long" parameterType="java.lang.Long">
  887. select promoter_id
  888. from jy_kuaishou_promoter
  889. where expert_mentor_id = #{userId}
  890. group by promoter_id
  891. </select>
  892. </mapper>