JiaoYangCallbackMapper.xml 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  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.bytedance.mapper.BytedancePromoterOrderListMapper">
  6. <resultMap type="com.ruixuan.bytedance.entity.BytedancePromoterOrderList" id="BytedancePromoterOrderListResult">
  7. <result property="orderId" column="order_id"/>
  8. <result property="productId" column="product_id"/>
  9. <result property="productName" column="product_name"/>
  10. <result property="productImg" column="product_img"/>
  11. <result property="productBindUserId" column="product_bind_user_id"/>
  12. <result property="productBindUserName" column="product_bind_user_name"/>
  13. <result property="shopId" column="shop_id"/>
  14. <result property="shopName" column="shop_name"/>
  15. <result property="totalPayAmount" column="total_pay_amount"/>
  16. <result property="flowPoint" column="flow_point"/>
  17. <result property="app" column="app"/>
  18. <result property="updateTime" column="update_time"/>
  19. <result property="paySuccessTime" column="pay_success_time"/>
  20. <result property="settleTime" column="settle_time"/>
  21. <result property="payGoodsAmount" column="total_pay_amount"/>
  22. <result property="settledGoodsAmount" column="total_pay_amount"/>
  23. <result property="itemNum" column="item_num"/>
  24. <result property="refundTime" column="refund_time"/>
  25. <result property="authorShortId" column="author_short_id"/>
  26. <result property="authorShortName" column="author_short_name"/>
  27. <result property="authorShortUrl" column="author_short_url"/>
  28. <result property="authorBindUserId" column="author_bind_user_id"/>
  29. <result property="authorBindUserName" column="author_bind_user_name"/>
  30. <result property="colonelType" column="colonel_type"/>
  31. <result property="mediaType" column="media_type"/>
  32. <result property="commissionRate" column="commission_rate"/>
  33. <result property="isTrusteeship" column="is_trusteeship"/>
  34. <result property="goodShareType" column="good_share_type"/>
  35. <result property="colonelCommissionRate" column="colonel_commission_rate"/>
  36. <result property="colonelActivityId" column="colonel_activity_id"/>
  37. <result property="colonelEstimatedCommission" column="colonel_estimated_commission"/>
  38. <result property="colonelRealCommission" column="colonel_real_commission"/>
  39. <result property="colonelTechServiceFeeRate" column="colonel_tech_service_fee_rate"/>
  40. <result property="colonelTechServiceFee" column="colonel_tech_service_fee"/>
  41. <result property="colonelSettledTechServiceFee" column="colonel_settled_tech_service_fee"/>
  42. <result property="colonelInstitutionId" column="colonel_institution_id"/>
  43. <result property="colonelInstitutionName" column="colonel_institution_name"/>
  44. <result property="secondCommissionRate" column="second_commission_rate"/>
  45. <result property="secondActivityId" column="second_activity_id"/>
  46. <result property="secondEstimatedCommission" column="second_estimated_commission"/>
  47. <result property="secondRealCommission" column="second_real_commission"/>
  48. <result property="createTime" column="create_time"/>
  49. <result property="statDate" column="stat_date"/>
  50. </resultMap>
  51. <sql id="SELECTBytedancePromoterOrderListVo">
  52. SELECT order_id,
  53. product_id,
  54. product_name,
  55. product_img,
  56. product_bind_user_id,
  57. product_bind_user_name,
  58. shop_id,
  59. shop_name,
  60. total_pay_amount,
  61. flow_point,
  62. app,
  63. update_time,
  64. pay_success_time,
  65. settle_time,
  66. total_pay_amount,
  67. total_pay_amount,
  68. item_num,
  69. refund_time,
  70. author_short_id,
  71. author_short_url,
  72. author_bind_user_id,
  73. author_bind_user_name,
  74. colonel_type,
  75. media_type,
  76. commission_rate,
  77. is_trusteeship,
  78. good_share_type,
  79. colonel_commission_rate,
  80. colonel_activity_id,
  81. colonel_estimated_commission,
  82. colonel_real_commission,
  83. colonel_tech_service_fee_rate,
  84. colonel_tech_service_fee,
  85. colonel_settled_tech_service_fee,
  86. colonel_institution_id,
  87. colonel_institution_name,
  88. second_commission_rate,
  89. second_activity_id,
  90. second_estimated_commission,
  91. second_real_commission,
  92. create_time,
  93. stat_date
  94. FROM bytedance_promoter_order_list
  95. </sql>
  96. <select id="SELECTBytedancePromoterOrderListList"
  97. parameterType="com.ruixuan.bytedance.entity.BytedancePromoterOrderList"
  98. resultMap="BytedancePromoterOrderListResult">
  99. <include refid="SELECTBytedancePromoterOrderListVo"/>
  100. <where>
  101. <if test="productId != null and productId != ''">and product_id = #{productId}</if>
  102. <if test="productName != null and productName != ''">and product_name like CONCAT('%', #{productName},
  103. '%')
  104. </if>
  105. <if test="productImg != null and productImg != ''">and product_img = #{productImg}</if>
  106. <if test="productBindUserId != null and productBindUserId != ''">and product_bind_user_id =
  107. #{productBindUserId}
  108. </if>
  109. <if test="productBindUserName != null and productBindUserName != ''">and product_bind_user_name like
  110. CONCAT('%', #{productBindUserName}, '%')
  111. </if>
  112. <if test="shopId != null ">and shop_id = #{shopId}</if>
  113. <if test="shopName != null and shopName != ''">and shop_name like CONCAT('%', #{shopName}, '%')</if>
  114. <if test="totalPayAmount != null ">and total_pay_amount = #{totalPayAmount}</if>
  115. <if test="flowPoint != null and flowPoint != ''">and flow_point = #{flowPoint}</if>
  116. <if test="app != null and app != ''">and app = #{app}</if>
  117. <if test="paySuccessTime != null ">and pay_success_time = #{paySuccessTime}</if>
  118. <if test="settleTime != null ">and settle_time = #{settleTime}</if>
  119. <if test="payGoodsAmount != null ">and total_pay_amount = #{payGoodsAmount}</if>
  120. <if test="settledGoodsAmount != null ">and total_pay_amount = #{settledGoodsAmount}</if>
  121. <if test="itemNum != null ">and item_num = #{itemNum}</if>
  122. <if test="refundTime != null ">and refund_time = #{refundTime}</if>
  123. <if test="authorShortId != null and authorShortId != ''">and author_short_id = #{authorShortId}</if>
  124. <if test="authorShortUrl != null and authorShortUrl != ''">and author_short_url = #{authorShortUrl}</if>
  125. <if test="authorBindUserId != null and authorBindUserId != ''">and author_bind_user_id =
  126. #{authorBindUserId}
  127. </if>
  128. <if test="authorBindUserName != null and authorBindUserName != ''">and author_bind_user_name like
  129. CONCAT('%', #{authorBindUserName}, '%')
  130. </if>
  131. <if test="colonelType != null and colonelType != ''">and colonel_type = #{colonelType}</if>
  132. <if test="mediaType != null and mediaType != ''">and media_type = #{mediaType}</if>
  133. <if test="commissionRate != null ">and commission_rate = #{commissionRate}</if>
  134. <if test="isTrusteeship != null and isTrusteeship != ''">and is_trusteeship = #{isTrusteeship}</if>
  135. <if test="goodShareType != null and goodShareType != ''">and good_share_type = #{goodShareType}</if>
  136. <if test="colonelCommissionRate != null ">and colonel_commission_rate = #{colonelCommissionRate}</if>
  137. <if test="colonelActivityId != null ">and colonel_activity_id = #{colonelActivityId}</if>
  138. <if test="colonelEstimatedCommission != null ">and colonel_estimated_commission =
  139. #{colonelEstimatedCommission}
  140. </if>
  141. <if test="colonelRealCommission != null ">and colonel_real_commission = #{colonelRealCommission}</if>
  142. <if test="colonelTechServiceFeeRate != null ">and colonel_tech_service_fee_rate =
  143. #{colonelTechServiceFeeRate}
  144. </if>
  145. <if test="colonelTechServiceFee != null ">and colonel_tech_service_fee = #{colonelTechServiceFee}</if>
  146. <if test="colonelSettledTechServiceFee != null ">and colonel_settled_tech_service_fee =
  147. #{colonelSettledTechServiceFee}
  148. </if>
  149. <if test="colonelInstitutionId != null ">and colonel_institution_id = #{colonelInstitutionId}</if>
  150. <if test="colonelInstitutionName != null and colonelInstitutionName != ''">and colonel_institution_name
  151. like CONCAT('%', #{colonelInstitutionName}, '%')
  152. </if>
  153. <if test="secondCommissionRate != null ">and second_commission_rate = #{secondCommissionRate}</if>
  154. <if test="secondActivityId != null ">and second_activity_id = #{secondActivityId}</if>
  155. <if test="secondEstimatedCommission != null ">and second_estimated_commission =
  156. #{secondEstimatedCommission}
  157. </if>
  158. <if test="secondRealCommission != null ">and second_real_commission = #{secondRealCommission}</if>
  159. </where>
  160. </select>
  161. <select id="SELECTBytedancePromoterOrderListByOrderId" parameterType="Long"
  162. resultMap="BytedancePromoterOrderListResult">
  163. <include refid="SELECTBytedancePromoterOrderListVo"/>
  164. WHERE order_id = #{orderId}
  165. </select>
  166. <select id="getBytedanceOrderList" resultType="com.alibaba.fastjson.JSONObject">
  167. SELECT
  168. t.*,
  169. ROUND(((t.orderNum-t2.orderNum)/t2.orderNum)*100,2) as 'orderNumRatio'
  170. FROM (
  171. SELECT
  172. IFNULL(t1.author_short_id,'-') AS 'promoterId',
  173. IFNULL(t1.author_short_name,'-') AS 'promoterNickName',
  174. count( t1.order_id ) AS 'orderNum',
  175. sum( CASE WHEN t1.flow_point != 'REFUND' THEN 1 ELSE 0 END ) AS 'validOrderNUm',
  176. CONCAT(round( sum( CASE WHEN t1.flow_point != 'REFUND' THEN 1 ELSE 0 END ) / count( t1.order_id )*100, 2 ),'%')
  177. AS
  178. 'validRadio',
  179. sum( t1.total_pay_amount )/100 AS 'payAmount',
  180. sum( CASE WHEN t1.flow_point != 'REFUND' THEN t1.total_pay_amount ELSE 0 END )/100 AS 'validPayAmount',
  181. sum(CASE
  182. WHEN t1.flow_point != 'REFUND' and t1.colonel_type != 2
  183. THEN t1.colonel_estimated_commission
  184. WHEN t1.flow_point != 'REFUND' and t1.colonel_type = 2
  185. then t1.second_estimated_commission
  186. ELSE 0 END) * 0.9 / 100 AS
  187. 'regimentalPromotionAmount',
  188. sum(CASE
  189. WHEN t1.flow_point != 'REFUND' and t1.colonel_type != 2
  190. THEN t1.second_estimated_commission
  191. ELSE 0 END) / 100 AS 'secondEstimatedCommission',
  192. t1.author_bind_user_id,
  193. IFNULL(t1.author_bind_user_name,'-') AS 'userName'
  194. FROM
  195. bytedance_promoter_order_list t1 LEFT JOIN
  196. bytedance_order_list t2 ON t1.order_id = t2.order_id
  197. <where>
  198. <if test="hour != null and hour != ''">
  199. and t2.pay_success_time_hour &lt;= #{hour}
  200. </if>
  201. <if test="start != null and start != ''">
  202. and t2.pay_success_time &gt;= #{start}
  203. </if>
  204. <if test="end != null and end != ''">
  205. and t2.pay_success_time &lt;= #{end}
  206. </if>
  207. <if test="promoterId != null and promoterId != ''">
  208. and t1.author_short_id = #{promoterId}
  209. </if>
  210. <if test="promoterNickName != null and promoterNickName != ''">
  211. and t1.author_short_name like CONCAT(CONCAT('%',#{promoterNickName}),'%')
  212. </if>
  213. </where>
  214. GROUP BY t1.author_short_id
  215. ) t
  216. LEFT JOIN (
  217. SELECT
  218. IFNULL(t1.author_short_id,'-') AS 'promoterId',
  219. count( t1.order_id ) AS 'orderNum'
  220. FROM
  221. bytedance_promoter_order_list t1 LEFT JOIN
  222. bytedance_order_list t2 ON t1.order_id = t2.order_id
  223. <where>
  224. <if test="hour != null and hour != ''">
  225. and t2.pay_success_time_hour &lt;= #{hour}
  226. </if>
  227. <if test="lastTimeStart != null and lastTimeStart != ''">
  228. and t2.pay_success_time &gt;= #{lastTimeStart}
  229. </if>
  230. <if test="lastTimeEnd != null and lastTimeEnd != ''">
  231. and t2.pay_success_time &lt;= #{lastTimeEnd}
  232. </if>
  233. <if test="promoterId != null and promoterId != ''">
  234. and t1.author_short_id = #{promoterId}
  235. </if>
  236. <if test="promoterNickName != null and promoterNickName != ''">
  237. and t1.author_short_name like CONCAT(CONCAT('%',#{promoterNickName}),'%')
  238. </if>
  239. </where>
  240. GROUP BY t1.author_short_id
  241. ) t2 on t.promoterId = t2.promoterId
  242. ORDER BY t.orderNum desc
  243. </select>
  244. <select id="getTopOrders" resultType="com.alibaba.fastjson.JSONObject">
  245. SELECT *
  246. FROM
  247. (SELECT product_id AS 'itemId',
  248. product_name AS 'itemTitle',
  249. product_img AS 'imageUrl',
  250. count(order_id) AS 'orderNum'
  251. FROM bytedance_promoter_order_list
  252. WHERE author_short_id = #{promoterId}
  253. <if test="start != null and start != ''">
  254. and pay_success_time &gt;= #{start}
  255. </if>
  256. <if test="end != null and end != ''">
  257. and pay_success_time &lt;= #{end}
  258. </if>
  259. GROUP BY product_id) t
  260. ORDER BY t.orderNum desc limit 3
  261. </select>
  262. <select id="bytedanceBDReportList" resultType="com.alibaba.fastjson.JSONObject">
  263. SELECT
  264. t1.collectSampleId,
  265. t1.collectSampleName,
  266. t2.promoterCount,
  267. t3.sampleCount,
  268. round(t3.sampleCount / t2.promoterCount * 100, 2) AS 'sampleRate',
  269. t2.promoterCount - t3.sampleCount AS 'notSampleCount',
  270. t1.orderNum,
  271. t1.validOrderNum,
  272. t1.validOrderRate,
  273. t1.orderAmount,
  274. t1.regimentalPromotionAmount,
  275. t1.totalRegimentalSettleAmount,
  276. t4.sendTotalCount,
  277. t4.sendPromoterCount,
  278. t4.sendItemCount,
  279. t1.voucherOrderNum,
  280. t1.voucherValidOrderNum,
  281. t1.voucherOrderAmount,
  282. t1.voucherRegimentalPromotionAmount,
  283. t1.voucherTotalRegimentalSettleAmount,
  284. IFNULL(t5.promoters_count,'-') AS 'promotersCount'
  285. FROM (
  286. SELECT author_bind_user_id AS 'collectSampleId',
  287. author_bind_user_name AS 'collectSampleName',
  288. count(order_id) AS 'orderNum',
  289. IFNULL(count(CASE WHEN sample_voucher_status = 2 THEN 1 ELSE 0 END), 0) AS 'voucherOrderNum',
  290. t0.validOrderNUm AS 'validOrderNUm',
  291. IFNULL(SUM(CASE WHEN sample_voucher_status = 2 THEN 1 ELSE 0 END), 0) AS 'voucherValidOrderNum',
  292. CONCAT(round(t0.validOrderNUm / count(order_id) * 100, 2),'%') AS 'validOrderRate',
  293. sum(total_pay_amount)/100 AS 'orderAmount',
  294. IFNULL(round(SUM(CASE WHEN sample_voucher_status = 2 THEN total_pay_amount ELSE 0 END) / 100,2), 0) AS
  295. 'voucherOrderAmount',
  296. round( sum( CASE WHEN flow_point != 'REFUND' THEN colonel_estimated_commission ELSE 0 END ) * 0.9 / 100, 2 ) AS
  297. 'regimentalPromotionAmount',
  298. IFNULL(SUM(CASE WHEN sample_voucher_status = 2 THEN colonel_estimated_commission ELSE 0 END)/100, 0)
  299. AS'voucherRegimentalPromotionAmount',
  300. sum(colonel_real_commission)/100 AS 'totalRegimentalSettleAmount',
  301. IFNULL(SUM(CASE WHEN sample_voucher_status = 2 THEN colonel_real_commission ELSE 0 END)/100, 0) AS
  302. 'voucherTotalRegimentalSettleAmount'
  303. FROM bytedance_promoter_order_list t
  304. LEFT JOIN (
  305. SELECT author_bind_user_id AS 'collectSampleId',
  306. sum(CASE WHEN flow_point != 'REFUND' THEN 1 ELSE 0 END) AS 'validOrderNUm'
  307. FROM bytedance_promoter_order_list
  308. WHERE author_bind_user_id is not null
  309. <if test="start != null and start != ''">
  310. and pay_success_time &gt;= #{start}
  311. </if>
  312. <if test="end != null and end != ''">
  313. and pay_success_time &lt;= #{end}
  314. </if>
  315. <if test="collectSampleId != null and collectSampleId != ''">
  316. and author_bind_user_id = #{collectSampleId}
  317. </if>
  318. GROUP BY author_bind_user_id
  319. ) t0 ON t.author_bind_user_id= t0.collectSampleId
  320. WHERE author_bind_user_id is not null
  321. <if test="start != null and start != ''">
  322. and pay_success_time &gt;= #{start}
  323. </if>
  324. <if test="end != null and end != ''">
  325. and pay_success_time &lt;= #{end}
  326. </if>
  327. <if test="collectSampleId != null and collectSampleId != ''">
  328. and author_bind_user_id = #{collectSampleId}
  329. </if>
  330. GROUP BY author_bind_user_id) t1
  331. LEFT JOIN (
  332. SELECT user_id AS 'userId',
  333. count(distinct promoter_id) AS 'promoterCount'
  334. FROM kuaishou_promoter
  335. GROUP BY user_id) t2
  336. on t1.collectSampleId = t2.userId
  337. LEFT JOIN (
  338. SELECT collect_sample_id AS 'collectSampleId',
  339. count(distinct promoter_id) AS 'sampleCount'
  340. FROM kuaishou_item_collect_samples
  341. WHERE collect_sample_status > 2
  342. GROUP BY collect_sample_id) t3
  343. on t2.userId = t3.collectSampleId
  344. LEFT JOIN (
  345. SELECT collect_sample_id AS 'collectSampleId',
  346. count(1) AS 'sendTotalCount',
  347. count(distinct promoter_id) AS 'sendPromoterCount',
  348. count(distinct item_id) AS 'sendItemCount'
  349. FROM kuaishou_item_collect_samples
  350. WHERE collect_sample_status > 2
  351. <if test="collectSampleId != null and collectSampleId != ''">
  352. and collect_sample_id = #{collectSampleId}
  353. </if>
  354. <if test="start != null and start != ''">
  355. and create_time &gt;= str_to_date(CONCAT(date_format(#{start}, '%Y-%m-%d'), '00:00:01'), '%Y-%m-%d
  356. %H:%i:%s')
  357. </if>
  358. <if test="end != null and end != ''">
  359. and create_time &lt;= str_to_date(CONCAT(date_format(#{end}, '%Y-%m-%d'), '23:59:59'), '%Y-%m-%d %H:%i:%s')
  360. </if>
  361. GROUP BY collect_sample_id
  362. ) t4
  363. on t1.collectSampleId = t4.collectSampleId
  364. LEFT JOIN (
  365. SELECT user_id,promoters_count
  366. FROM user_promoters_count
  367. WHERE media_id = 1
  368. ) t5
  369. on t1.collectSampleId = t5.user_id
  370. ORDER BY t1.orderNum desc
  371. </select>
  372. <select id="anchorBytedanceOrderDetail" resultType="com.alibaba.fastjson.JSONObject">
  373. SELECT t.*,
  374. t2.status,
  375. (
  376. case
  377. when t3.activity_item_status = 1 then '待审核'
  378. when t3.activity_item_status = 2 then '已上架'
  379. when t3.activity_item_status = 3 then '审核拒绝'
  380. when t3.activity_item_status = 4 then '活动失效'
  381. when t3.activity_item_status = 5 then '商品下架'
  382. else ''
  383. end
  384. ) AS 'activityItemStatus'
  385. FROM (
  386. SELECT
  387. tt.product_name AS 'itemTitle',
  388. tt.product_id AS 'itemId',
  389. tt.total_pay_amount/100 AS 'reservePrice',
  390. tt.product_img 'imageUrl',
  391. count(order_id) AS 'orderNum',
  392. sum( CASE WHEN flow_point != 'REFUND' THEN 1 ELSE 0 END ) AS 'validOrderNUm',
  393. CONCAT(round(sum(case when flow_point != 'REFUND' then 1 else 0 end) / count(order_id)*100,2),'%') as
  394. 'validRadio',
  395. sum(case when flow_point != 'REFUND' then total_pay_amount else 0 end)/100 AS 'payAmount',
  396. CONCAT(round(colonel_commission_rate/100,2),'%') AS 'regimentalPromotionRate'
  397. FROM bytedance_promoter_order_list tt
  398. WHERE 1= 1
  399. <if test="promoterId != null and promoterId != ''">
  400. and tt.author_short_id = #{promoterId}
  401. </if>
  402. <if test="start != null and start != ''">
  403. and tt.pay_success_time &gt;= #{start}
  404. </if>
  405. <if test="end != null and end != ''">
  406. and tt.pay_success_time &lt;= #{end}
  407. </if>
  408. <if test="itemId != null and itemId != ''">
  409. and tt.product_id = #{itemId}
  410. </if>
  411. <if test="itemTitle != null and itemTitle != ''">
  412. and tt.product_name like CONCAT(CONCAT('%',#{itemTitle}),'%')
  413. </if>
  414. GROUP BY tt.product_id) t
  415. LEFT JOIN
  416. ( SELECT item_id AS 'itemId', collect_sample_status AS 'status' FROM
  417. kuaishou_item_collect_samples WHERE promoter_id = #{promoterId}) t2
  418. on t.itemId = t2.itemId
  419. LEFT JOIN kuaishou_item_list t3 ON t.itemId = t3.item_id
  420. ORDER BY t.orderNum desc
  421. </select>
  422. <select id="bytedanceItemList" resultType="com.alibaba.fastjson.JSONObject">
  423. SELECT
  424. t.*,
  425. ROUND(((t.orderNum-t2.orderNum)/t2.orderNum)*100,2) as 'orderNumRatio'
  426. FROM (
  427. SELECT
  428. t1.product_bind_user_id AS 'userId',
  429. t1.product_bind_user_name AS 'userName',
  430. t1.product_id AS 'itemId',
  431. t1.total_pay_amount/100 AS 'reservePrice',
  432. t1.product_name AS 'itemTitle',
  433. t1.product_img AS 'imageUrl',
  434. count(t1.order_id) AS 'orderNum',
  435. sum(case when t1.flow_point != 'REFUND' then 1 else 0 end) AS 'validOrderNUm',
  436. CONCAT(round(sum(case when t1.flow_point != 'REFUND' then 1 else 0 end) / count(t1.order_id)*100, 2),'%') as
  437. 'validRadio',
  438. CONCAT(Round(t1.commission_rate/100,2),'%') AS 'itemCommissionRate',
  439. SUM(CASE
  440. WHEN t1.flow_point != 'REFUND' and t1.colonel_type != 2
  441. THEN t1.colonel_estimated_commission
  442. WHEN t1.flow_point != 'REFUND' and t1.colonel_type = 2
  443. then t1.second_estimated_commission
  444. ELSE 0 END) * 0.9 / 100 AS 'regimentalPromotionAmount',
  445. SUM(CASE
  446. WHEN t1.flow_point != 'REFUND' and t1.colonel_type != 2 THEN t1.second_estimated_commission
  447. ELSE 0 END) / 100 AS 'secondEstimatedCommission'
  448. FROM bytedance_promoter_order_list t1
  449. LEFT JOIN bytedance_order_list t2 ON t1.order_id = t2.order_id
  450. <where>
  451. <if test="hour != null and hour != ''">
  452. and t2.pay_success_time_hour &lt;= #{hour}
  453. </if>
  454. <if test="start != null and start != ''">
  455. and t2.pay_success_time &gt;= #{start}
  456. </if>
  457. <if test="end != null and end != ''">
  458. and t2.pay_success_time &lt;= #{end}
  459. </if>
  460. <if test="itemId != null and itemId != ''">
  461. and t1.product_id = #{itemId}
  462. </if>
  463. <if test="itemTitle != null and itemTitle != ''">
  464. and t1.product_name like CONCAT(CONCAT('%',#{itemTitle}),'%')
  465. </if>
  466. <if test="userId != null and userId != ''">
  467. and t1.product_bind_user_id = #{userId}
  468. </if>
  469. </where>
  470. GROUP BY t1.product_id
  471. ) t
  472. LEFT JOIN(
  473. SELECT
  474. t1.product_id AS 'itemId',
  475. count(t1.order_id) AS 'orderNum'
  476. FROM bytedance_promoter_order_list t1
  477. LEFT JOIN bytedance_order_list t2 ON t1.order_id = t2.order_id
  478. <where>
  479. <if test="hour != null and hour != ''">
  480. and t2.pay_success_time_hour &lt;= #{hour}
  481. </if>
  482. <if test="lastTimeStart != null and lastTimeStart != ''">
  483. and t2.pay_success_time &gt;= #{lastTimeStart}
  484. </if>
  485. <if test="lastTimeEnd != null and lastTimeEnd != ''">
  486. and t2.pay_success_time &lt;= #{lastTimeEnd}
  487. </if>
  488. <if test="itemId != null and itemId != ''">
  489. and t1.product_id = #{itemId}
  490. </if>
  491. <if test="itemTitle != null and itemTitle != ''">
  492. and t1.product_name like CONCAT(CONCAT('%',#{itemTitle}),'%')
  493. </if>
  494. <if test="userId != null and userId != ''">
  495. and t1.product_bind_user_id = #{userId}
  496. </if>
  497. </where>
  498. GROUP BY t1.product_id
  499. ) t2 ON t.itemId = t2.itemId
  500. ORDER BY t.${fieId} ${sort}
  501. </select>
  502. <select id="adminBytedanceReportList" resultType="com.alibaba.fastjson.JSONObject">
  503. SELECT
  504. t.*,
  505. t1.sendSampleCount,
  506. ROUND(((t.orderNum-t2.orderNum)/t2.orderNum)*100,2) as 'orderNumRatio'
  507. FROM (
  508. SELECT
  509. t2.product_bind_user_id AS 'userId',
  510. t2.product_bind_user_name AS 'userName',
  511. count(distinct t2.product_id) AS 'itemCount',
  512. count(t2.order_id) AS 'orderNum',
  513. sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) AS 'validOrderNUm',
  514. CONCAT(round(sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) / count(t2.order_id)*100, 2),'%') as
  515. 'validRadio',
  516. sum(case when t2.flow_point = 'REFUND' then 1 else 0 end) AS 'invalidOrderNUm',
  517. sum(case when t2.flow_point != 'REFUND' then t2.total_pay_amount else 0 end)/100 AS 'payAmount',
  518. sum(CASE
  519. WHEN t2.flow_point != 'REFUND' and t2.colonel_type != 2
  520. THEN t2.colonel_estimated_commission
  521. WHEN t2.flow_point != 'REFUND' and t2.colonel_type = 2
  522. then t2.second_estimated_commission
  523. ELSE 0 END) * 0.9 / 100 AS
  524. 'regimentalPromotionAmount',
  525. sum(CASE
  526. WHEN t2.flow_point != 'REFUND' and t2.colonel_type != 2
  527. THEN t2.second_estimated_commission
  528. ELSE 0 END) / 100 AS 'secondEstimatedCommission',
  529. sum(case when t2.flow_point != 'REFUND' then t2.colonel_real_commission else 0 end)/100 as
  530. 'totalRegimentalSettleAmount'
  531. FROM bytedance_promoter_order_list t2
  532. LEFT JOIN bytedance_order_list t3 ON t3.order_id = t2.order_id
  533. WHERE product_bind_user_id is not null
  534. <if test="hour != null and hour != ''">
  535. and t3.pay_success_time_hour &lt;= #{hour}
  536. </if>
  537. <if test="start != null and start != ''">
  538. and t3.pay_success_time &gt;= #{start}
  539. </if>
  540. <if test="end != null and end != ''">
  541. and t3.pay_success_time &lt;= #{end}
  542. </if>
  543. GROUP BY t2.product_bind_user_id
  544. ) t
  545. LEFT JOIN(
  546. SELECT item_create_id,count(1) AS 'sendSampleCount' FROM kuaishou_item_collect_samples
  547. WHERE courier_number_time >= CONCAT(#{start},' 00:00:00')
  548. and courier_number_time &lt;= CONCAT(#{end},' 23:59:59')
  549. GROUP BY item_create_id
  550. ) t1 on t.userId = t1.item_create_id
  551. LEFT JOIN(
  552. SELECT
  553. t2.product_bind_user_id,
  554. count(t2.order_id) AS 'orderNum'
  555. FROM bytedance_promoter_order_list t2
  556. LEFT JOIN bytedance_order_list t3 ON t3.order_id = t2.order_id
  557. WHERE product_bind_user_id is not null
  558. <if test="hour != null and hour != ''">
  559. and t3.pay_success_time_hour &lt;= #{hour}
  560. </if>
  561. <if test="lastTimeStart != null and lastTimeStart != ''">
  562. and t3.pay_success_time &gt;= #{lastTimeStart}
  563. </if>
  564. <if test="lastTimeEnd != null and lastTimeEnd != ''">
  565. and t3.pay_success_time &lt;= #{lastTimeEnd}
  566. </if>
  567. GROUP BY t2.product_bind_user_id
  568. ) t2 on t.userId = t2.product_bind_user_id
  569. <where>
  570. <if test="userId != null and userId != ''">
  571. and t.userId = #{userId}
  572. </if>
  573. </where>
  574. ORDER BY t.orderNum desc
  575. </select>
  576. <select id="adminBytedanceReportListByBind" resultType="com.alibaba.fastjson.JSONObject">
  577. SELECT
  578. t.*,
  579. t2.sendSampleCount,
  580. ROUND(((t.orderNum-t3.orderNum)/t3.orderNum)*100,2) as 'orderNumRatio'
  581. FROM (
  582. SELECT
  583. t1.user_id AS 'userId',
  584. t1.user_name AS 'userName',
  585. count(distinct t1.item_id) AS 'itemCount',
  586. count(t2.order_id) AS 'orderNum',
  587. sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) AS 'validOrderNUm',
  588. CONCAT(round(sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) / count(t2.order_id)*100, 2),'%') as
  589. 'validRadio',
  590. sum(case when t2.flow_point = 'REFUND' then 1 else 0 end) AS 'invalidOrderNUm',
  591. sum(case when t2.flow_point != 'REFUND' then t2.total_pay_amount else 0 end)/100 AS 'payAmount',
  592. sum(CASE
  593. WHEN t2.flow_point != 'REFUND' and t2.colonel_type != 2
  594. THEN t2.colonel_estimated_commission
  595. WHEN t2.flow_point != 'REFUND' and t2.colonel_type = 2
  596. then t2.second_estimated_commission
  597. ELSE 0 END) * 0.9 / 100 AS
  598. 'regimentalPromotionAmount',
  599. sum(CASE
  600. WHEN t2.flow_point != 'REFUND' and t2.colonel_type != 2
  601. THEN t2.second_estimated_commission
  602. ELSE 0 END) / 100 AS 'secondEstimatedCommission',
  603. sum(case when t2.flow_point != 'REFUND' then t2.colonel_real_commission else 0 end) / 100 as
  604. 'totalRegimentalSettleAmount'
  605. FROM (select * from kuaishou_item_list where create_time >= CONCAT(date_format(#{start},'%Y-%m-%d'),' 00:00:00')
  606. and create_time &lt;= CONCAT(date_format(#{end},'%Y-%m-%d'),' 23:59:59')
  607. and media_id = 1
  608. ) t1
  609. LEFT JOIN (
  610. SELECT
  611. t1.product_id,
  612. t1.order_id,
  613. t1.flow_point,
  614. t1.total_pay_amount,
  615. t1.colonel_estimated_commission,
  616. t1.colonel_real_commission,
  617. t1.colonel_type,
  618. t1.second_estimated_commission
  619. FROM bytedance_promoter_order_list t1
  620. LEFT JOIN bytedance_order_list t2 ON t1.order_id = t2.order_id
  621. WHERE t2.pay_success_time &gt;= #{start}
  622. <if test="hour != null and hour != ''">
  623. and t2.pay_success_time_hour &lt;= #{hour}
  624. </if>
  625. ) t2
  626. on t1.item_id = t2.product_id
  627. <if test="userId != null and userId != ''">
  628. and t1.userId = #{userId}
  629. </if>
  630. GROUP BY t1.user_id
  631. ) t
  632. LEFT JOIN (
  633. SELECT t1.user_id,count(distinct courier_number) AS 'sendSampleCount'
  634. FROM kuaishou_item_list t1
  635. LEFT JOIN kuaishou_item_collect_samples t2 ON t1.item_id = t2.item_id
  636. WHERE t1.create_time >=CONCAT(date_format(#{start},'%Y-%m-%d'),' 00:00:00')
  637. and t1.create_time &lt;= CONCAT(date_format(#{end},'%Y-%m-%d'),' 23:59:59')
  638. and t2.courier_number_time >= CONCAT(date_format(#{start},'%Y-%m-%d'),' 00:00:00')
  639. GROUP BY t1.user_id
  640. ) t2 on t.userId = t2.user_id
  641. LEFT JOIN (
  642. SELECT
  643. t1.user_id,
  644. count(t2.order_id) AS 'orderNum'
  645. FROM (
  646. select item_id,user_id
  647. from kuaishou_item_list
  648. where create_time >= CONCAT(date_format(#{lastTimeStart},'%Y-%m-%d'),' 00:00:00')
  649. and create_time &lt;= CONCAT(date_format(#{lastTimeEnd},'%Y-%m-%d'),' 23:59:59')
  650. and media_id = 1
  651. ) t1
  652. LEFT JOIN (
  653. SELECT
  654. t1.product_id,
  655. t1.order_id
  656. FROM bytedance_promoter_order_list t1
  657. LEFT JOIN bytedance_order_list t2 ON t1.order_id = t2.order_id
  658. WHERE t2.pay_success_time &gt;= #{lastTimeStart}
  659. AND t2.pay_success_time &lt;= #{lastTimeEnd}
  660. <if test="hour != null and hour != ''">
  661. and t2.pay_success_time_hour &lt;= #{hour}
  662. </if>
  663. ) t2 ON t1.item_id = t2.product_id
  664. <if test="userId != null and userId != ''">
  665. and t1.userId = #{userId}
  666. </if>
  667. GROUP BY t1.user_id
  668. ) t3 ON t.userId = t3.user_id
  669. ORDER BY t.orderNum desc
  670. </select>
  671. <select id="getBytedanceTopPromoterByItemId" resultType="com.alibaba.fastjson.JSONObject">
  672. SELECT
  673. *
  674. FROM
  675. (
  676. SELECT author_short_id AS 'promoterId',
  677. author_short_name AS 'promoterNickName',
  678. count(order_id) AS 'orderNum'
  679. FROM bytedance_promoter_order_list
  680. WHERE product_id = #{itemId}
  681. AND author_bind_user_id is not null
  682. <if test="start != null and start != ''">
  683. and pay_success_time &gt;= #{start}
  684. </if>
  685. <if test="end != null and end != ''">
  686. and pay_success_time &lt;= #{end}
  687. </if>
  688. GROUP BY author_bind_user_id) t
  689. ORDER BY t.orderNum desc
  690. limit 3
  691. </select>
  692. <select id="bytedanceOrderStatistics" resultType="com.alibaba.fastjson.JSONObject">
  693. SELECT
  694. DATE_FORMAT(t.pay_success_time , '%Y-%m-%d') AS 'date',
  695. count(t.order_id) AS 'orderNum'
  696. FROM (
  697. SELECT
  698. order_id,
  699. pay_success_time
  700. FROM bytedance_promoter_order_list
  701. WHERE 1 = 1
  702. <if test="promoterId != null and promoterId != ''">
  703. and author_short_id = #{promoterId}
  704. </if>
  705. <if test="start != null and start != ''">
  706. and pay_success_time &gt;= #{start}
  707. </if>
  708. <if test="end != null and end != ''">
  709. and pay_success_time &lt;= #{end}
  710. </if>
  711. ) t
  712. GROUP BY DATE_FORMAT(t.pay_success_time , '%Y-%m-%d')
  713. ORDER BY DATE_FORMAT(t.pay_success_time , '%Y-%m-%d') asc
  714. </select>
  715. <select id="bytedanceItemDetail" resultType="com.alibaba.fastjson.JSONObject">
  716. SELECT *
  717. FROM (
  718. SELECT
  719. author_short_id AS 'promoterId',
  720. author_short_name AS 'promoterNickName',
  721. count(order_id) AS 'orderNum',
  722. sum(case when flow_point = 'REFUND' then total_pay_amount else 0 end) AS 'payAmount',
  723. CONCAT(round(colonel_commission_rate/100,2),'%') AS 'regimentalPromotionRate',
  724. sum(case when flow_point = 'REFUND' then 1 else 0 end) AS 'validOrderNUm',
  725. CONCAT(round(sum(case when flow_point != 'REFUND' then 1 else 0 end) / count(order_id)*100, 2),'%') as
  726. 'validRadio'
  727. FROM bytedance_promoter_order_list
  728. WHERE 1= 1
  729. <if test="itemId != null and itemId != ''">
  730. and product_id = #{itemId}
  731. </if>
  732. <if test="start != null and start != ''">
  733. and pay_success_time &gt;= #{start}
  734. </if>
  735. <if test="end != null and end != ''">
  736. and pay_success_time &lt;= #{end}
  737. </if>
  738. <if test="promoterId != null and promoterId != ''">
  739. and author_short_id = #{promoterId}
  740. </if>
  741. <if test="promoterNickName != null and promoterNickName != ''">
  742. and author_bind_user_name like CONCAT(CONCAT('%',#{promoterNickName}),'%')
  743. </if>
  744. GROUP BY author_bind_user_id) t
  745. ORDER BY t.orderNum desc
  746. </select>
  747. <select id="bytedanceBDTotal" resultType="com.alibaba.fastjson.JSONObject">
  748. select t.*, tt.sampleCount
  749. from (select
  750. count(t2.order_id) as 'orderNum',
  751. sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) AS 'validOrderNum',
  752. concat(round(sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) / count(t2.order_id) * 100, 2), '%') as
  753. 'validOrderRate',
  754. round(sum(t2.total_pay_amount) / 100, 2) as 'orderAmount',
  755. round(sum(t2.pay_goods_amount) / 100, 2) as 'regimentalPromotionAmount',
  756. round(sum(t2.settled_goods_amount) / 100, 2) as 'totalRegimentalSettleAmount'
  757. from promoter_bind_channel_date t1
  758. left join bytedance_promoter_order_list t2
  759. on t1.promoter_id = t2.author_short_id and t1.stat_date = t2.pay_success_time
  760. where 1 = 1
  761. <if test="start != null and start != '' ">
  762. and t1.stat_date &gt;= #{start}
  763. </if>
  764. <if test="end != null and end != ''">
  765. and t1.stat_date &lt;= #{end}
  766. </if>
  767. <if test="collectSampleId != null and collectSampleId != ''">
  768. and t1.user_id = #{collectSampleId}
  769. </if>) t
  770. join (select promoter_id,
  771. count(distinct item_id) as 'sampleCount'
  772. from kuaishou_item_collect_samples
  773. where collect_sample_status > 2
  774. and collect_sample_id = #{collectSampleId}
  775. ) tt
  776. </select>
  777. <select id="bytedanceBDDetailList" resultType="com.alibaba.fastjson.JSONObject">
  778. select t.*, tt.sampleCount
  779. from (select t1.promoter_id as 'promoterId',
  780. t1.promoter_name as 'promoterName',
  781. t1.promoter_url as 'promoterUrl',
  782. count(t2.order_id) as 'orderNum',
  783. sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) AS 'validOrderNum',
  784. concat(round(sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) / count(t2.order_id) * 100, 2), '%') as
  785. 'validOrderRate',
  786. round(sum(t2.total_pay_amount) / 100, 2) as 'orderAmount',
  787. round(sum(t2.pay_goods_amount) / 100, 2) as 'regimentalPromotionAmount',
  788. round(sum(t2.settled_goods_amount) / 100, 2) as 'totalRegimentalSettleAmount'
  789. from promoter_bind_channel_date t1
  790. left join bytedance_promoter_order_list t2
  791. on t1.promoter_id = t2.author_short_id and t1.stat_date = t2.pay_success_time
  792. where 1 = 1
  793. <if test="start != null and start != '' ">
  794. and t1.stat_date &gt;= #{start}
  795. </if>
  796. <if test="end != null and end != ''">
  797. and t1.stat_date &lt;= #{end}
  798. </if>
  799. <if test="collectSampleId != null and collectSampleId != ''">
  800. and t1.user_id = #{collectSampleId}
  801. </if>
  802. group by t1.promoter_id) t
  803. left join (select promoter_id,
  804. count(distinct item_id) as 'sampleCount'
  805. from kuaishou_item_collect_samples
  806. where collect_sample_status > 2
  807. and collect_sample_id = #{collectSampleId}
  808. group by promoter_id) tt on t.promoterId = tt.promoter_id
  809. where t.orderNum > 0
  810. order by ${fieId} ${sort}
  811. </select>
  812. <select id="bytedanceUserItemTotal" resultType="com.alibaba.fastjson.JSONObject">
  813. SELECT
  814. count( t2.order_id ) AS 'orderNum',
  815. sum( CASE WHEN t2.flow_point != 'REFUND' THEN 1 ELSE 0 END ) AS 'validOrderNUm',
  816. CONCAT(round( sum( CASE WHEN t2.flow_point != 'REFUND' THEN 1 ELSE 0 END ) / count( t2.order_id )*100, 2),'%')
  817. AS 'validRadio',
  818. sum( CASE WHEN t2.flow_point = 'REFUND' THEN 1 ELSE 0 END ) AS 'invalidOrderNUm',
  819. sum( CASE WHEN t2.flow_point != 'REFUND' THEN t2.total_pay_amount ELSE 0 END ) AS 'payAmount',
  820. sum( CASE WHEN t2.flow_point != 'REFUND' THEN t2.colonel_estimated_commission ELSE 0 END ) * 0.9 AS
  821. 'regimentalPromotionAmount',
  822. sum( CASE WHEN t2.flow_point != 'REFUND' THEN t2.colonel_real_commission ELSE 0 END ) AS
  823. 'totalRegimentalSettleAmount'
  824. FROM bytedance_promoter_order_list t2
  825. WHERE
  826. 1 = 1
  827. <if test="start != null and start != ''">
  828. and t2.pay_success_time &gt;= #{start}
  829. </if>
  830. <if test="end != null and end != ''">
  831. and t2.pay_success_time &lt;= #{end}
  832. </if>
  833. <if test="userId != null and userId != ''">
  834. AND t2.product_bind_user_id = #{userId}
  835. </if>
  836. </select>
  837. <select id="bytedanceUserItemDetail" resultType="com.alibaba.fastjson.JSONObject">
  838. SELECT
  839. product_bind_user_id AS 'user_id',
  840. product_bind_user_name AS 'userName',
  841. product_id AS 'itemId',
  842. product_name AS 'itemTitle',
  843. product_img AS 'imageUrl',
  844. total_pay_amount/100 AS 'reservePrice',
  845. count( order_id ) AS 'orderNum',
  846. sum( CASE WHEN flow_point != 'REFUND' THEN 1 ELSE 0 END ) AS 'validOrderNUm',
  847. CONCAT(round( sum( CASE WHEN flow_point != 'REFUND' THEN 1 ELSE 0 END ) / count( order_id )*100, 2),'%') AS
  848. 'validRadio',
  849. sum( CASE WHEN flow_point = 'REFUND' THEN 1 ELSE 0 END ) AS 'invalidOrderNUm',
  850. round( sum( CASE WHEN flow_point != 'REFUND' THEN total_pay_amount ELSE 0 END )/ 100, 2 ) AS 'payAmount',
  851. CONCAT(round(colonel_commission_rate/100,2),'%') AS 'regimentalPromotionRate',
  852. round( sum( CASE WHEN flow_point != 'REFUND' THEN colonel_estimated_commission ELSE 0 END ) * 0.9 / 100, 2 ) AS
  853. 'regimentalPromotionAmount',
  854. round( sum( CASE WHEN flow_point != 'REFUND' THEN colonel_real_commission ELSE 0 END ) / 100, 2 ) AS
  855. 'totalRegimentalSettleAmount',
  856. CONCAT(round(colonel_commission_rate/100,2),'%') AS 'itemCommissionRate'
  857. FROM bytedance_promoter_order_list
  858. WHERE
  859. product_bind_user_id is not null
  860. <if test="start != null and start != ''">
  861. and pay_success_time &gt;= #{start}
  862. </if>
  863. <if test="end != null and end != ''">
  864. and pay_success_time &lt;= #{end}
  865. </if>
  866. <if test="itemId != null and itemId != ''">
  867. and product_id = #{itemId}
  868. </if>
  869. <if test="itemTitle != null and itemTitle != ''">
  870. and product_name like CONCAT(CONCAT('%',#{itemTitle}),'%')
  871. </if>
  872. <if test="userId != null and userId != ''">
  873. and product_bind_user_id = #{userId}
  874. </if>
  875. GROUP BY product_id
  876. ORDER BY orderNum desc
  877. </select>
  878. <select id="exportBytedancePromoter" resultType="com.alibaba.fastjson.JSONObject">
  879. SELECT *
  880. FROM (
  881. SELECT
  882. author_short_id AS 'promoterId',
  883. author_short_name AS 'promoterNickName',
  884. product_id AS 'itemId',
  885. product_name AS 'itemTitle',
  886. product_img AS 'imageUrl',
  887. count(order_id) AS 'orderNum',
  888. sum(case when flow_point != 'REFUND' then 1 else 0 end) AS 'validOrderNUm',
  889. CONCAT(round(sum(case when flow_point != 'REFUND' then 1 else 0 end) / count(order_id)*100, 2),'%') AS
  890. 'validRadio'
  891. FROM bytedance_promoter_order_list
  892. WHERE author_short_id is not null
  893. <if test="start != null and start != ''">
  894. and pay_success_time &gt;= #{start}
  895. </if>
  896. <if test="end != null and end != ''">
  897. and pay_success_time &lt;= #{end}
  898. </if>
  899. <if test="promoterId != null and promoterId != ''">
  900. and author_short_id = #{promoterId}
  901. </if>
  902. <if test="promoterNickName != null and promoterNickName != ''">
  903. and author_short_name like CONCAT(CONCAT('%',#{promoterNickName}),'%')
  904. </if>
  905. <if test="itemId != null and itemId != ''">
  906. and product_id = #{itemId}
  907. </if>
  908. <if test="itemTitle != null and itemTitle != ''">
  909. and product_name like CONCAT(CONCAT('%',#{itemTitle}),'%')
  910. </if>
  911. GROUP BY author_short_id,product_id) t
  912. ORDER BY t.promoterId,t.itemId desc
  913. </select>
  914. <select id="bdReportList" resultType="com.alibaba.fastjson.JSONObject">
  915. select t.*,
  916. tt.promoterCount,
  917. ttt.sampleCount,
  918. tttt.sendTotalCount,
  919. tttt.sendPromoterCount,
  920. tttt.sendItemCount,
  921. ROUND(((t.orderNum-t11.orderNum)/t11.orderNum)*100,2) as 'orderNumRatio',
  922. IFNULL( ttttt.promoters_count,'-') as 'promotersCount',
  923. concat(round(ttt.sampleCount / tt.promoterCount * 100, 2), '%') as 'sampleRate',
  924. tt.promoterCount - ttt.sampleCount as 'notSampleCount'
  925. from (
  926. select t1.user_id as 'collectSampleId',
  927. t1.user_name as 'collectSampleName',
  928. count(t2.order_id) as 'orderNum',
  929. sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) AS 'validOrderNum',
  930. concat(round(sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) / count(t2.order_id) * 100, 2), '%') as
  931. 'validOrderRate',
  932. round(sum(t2.total_pay_amount) / 100, 2) as 'orderAmount',
  933. sum(CASE
  934. WHEN t2.flow_point != 'REFUND' and t2.colonel_type != 2
  935. THEN t2.colonel_estimated_commission
  936. WHEN t2.flow_point != 'REFUND' and t2.colonel_type = 2
  937. then t2.second_estimated_commission
  938. ELSE 0 END) * 0.9 / 100 AS
  939. 'regimentalPromotionAmount',
  940. sum(CASE
  941. WHEN t2.flow_point != 'REFUND' and t2.colonel_type != 2
  942. THEN t2.second_estimated_commission
  943. ELSE 0 END) /
  944. 100 AS 'secondEstimatedCommission',
  945. round(sum(t2.colonel_real_commission) / 100, 2) as 'totalRegimentalSettleAmount'
  946. from (select user_id, user_name, promoter_id, stat_date
  947. from promoter_bind_channel_date
  948. where media_id = 1
  949. <if test="start != null and start != ''">
  950. and stat_date &gt;= #{start}
  951. </if>
  952. <if test="end != null and end != ''">
  953. and stat_date &lt;= #{end}
  954. </if>
  955. <if test="collectSampleId != null and collectSampleId != ''">
  956. and user_id = #{collectSampleId}
  957. </if>
  958. ) t1
  959. left join (
  960. select *
  961. from bytedance_order_list
  962. <where>
  963. <if test="hour != null and hour != ''">
  964. and pay_success_time_hour &lt;= #{hour}
  965. </if>
  966. <if test="start != null and start != ''">
  967. and pay_success_time &gt;= #{start}
  968. </if>
  969. <if test="end != null and end != ''">
  970. and pay_success_time &lt;= #{end}
  971. </if>
  972. </where>
  973. ) t2
  974. on t1.promoter_id = t2.author_short_id and t1.stat_date = t2.pay_success_time
  975. group by t1.user_id
  976. ) t
  977. LEFT JOIN (
  978. select t1.user_id,
  979. count(t2.order_id) as 'orderNum'
  980. from (select user_id, promoter_id, stat_date
  981. from promoter_bind_channel_date
  982. where media_id = 1
  983. <if test="lastTimeStart != null and lastTimeStart != ''">
  984. and stat_date &gt;= #{lastTimeStart}
  985. </if>
  986. <if test="lastTimeEnd != null and lastTimeEnd != ''">
  987. and stat_date &lt;= #{lastTimeEnd}
  988. </if>
  989. <if test="collectSampleId != null and collectSampleId != ''">
  990. and user_id = #{collectSampleId}
  991. </if>
  992. ) t1
  993. left join (
  994. select author_short_id,
  995. order_id,
  996. pay_success_time
  997. from bytedance_order_list
  998. <where>
  999. <if test="hour != null and hour != ''">
  1000. and pay_success_time_hour &lt;= #{hour}
  1001. </if>
  1002. <if test="lastTimeStart != null and lastTimeStart != ''">
  1003. and pay_success_time &gt;= #{lastTimeStart}
  1004. </if>
  1005. <if test="lastTimeEnd != null and lastTimeEnd != ''">
  1006. and pay_success_time &lt;= #{lastTimeEnd}
  1007. </if>
  1008. </where>
  1009. ) t2 ON t1.promoter_id = t2.author_short_id and t1.stat_date = t2.pay_success_time
  1010. group by t1.user_id
  1011. ) t11 ON t11.user_id = t.collectSampleId
  1012. left join (select user_id,
  1013. count(distinct promoter_id) as 'promoterCount'
  1014. from kuaishou_promoter
  1015. group by user_id) tt on t.collectSampleId = tt.user_id
  1016. left join (select collect_sample_id as 'user_id',
  1017. count(distinct promoter_id) as 'sampleCount'
  1018. from kuaishou_item_collect_samples
  1019. where collect_sample_status > 2
  1020. group by collect_sample_id) ttt on t.collectSampleId = ttt.user_id
  1021. left join (select collect_sample_id as 'user_id',
  1022. count(1) as 'sendTotalCount',
  1023. count(distinct promoter_id) as 'sendPromoterCount',
  1024. count(distinct item_id) as 'sendItemCount'
  1025. from kuaishou_item_collect_samples
  1026. where collect_sample_status > 2
  1027. <if test="collectSampleId != null and collectSampleId != ''">
  1028. and collect_sample_id = #{collectSampleId}
  1029. </if>
  1030. <if test="start != null and start != ''">
  1031. and create_time &gt;= str_to_date(concat(date_format(#{start}, '%Y-%m-%d'), '00:00:01'), '%Y-%m-%d
  1032. %H:%i:%s')
  1033. </if>
  1034. <if test="end != null and end != ''">
  1035. and create_time &lt;= str_to_date(concat(date_format(#{end}, '%Y-%m-%d'), '23:59:59'), '%Y-%m-%d %H:%i:%s')
  1036. </if>
  1037. group by collect_sample_id) tttt on t.collectSampleId = tttt.user_id
  1038. left join (select user_id, promoters_count
  1039. from user_promoters_count
  1040. where media_id = 1) ttttt
  1041. on t.collectSampleId = ttttt.user_id
  1042. where t.orderNum > 0
  1043. order by t.orderNum desc
  1044. </select>
  1045. <select id="bdReportListByBind" resultType="com.alibaba.fastjson.JSONObject">
  1046. select t.*,
  1047. tt.promoterCount,
  1048. ttt.sampleCount,
  1049. tttt.sendTotalCount,
  1050. tttt.sendPromoterCount,
  1051. tttt.sendItemCount,
  1052. ROUND(((t.orderNum-t11.orderNum)/t11.orderNum)*100,2) as 'orderNumRatio',
  1053. IFNULL(ttttt.promoters_count, '-') as 'promotersCount'
  1054. from (select t1.user_id as 'collectSampleId',
  1055. t1.user_name as 'collectSampleName',
  1056. count(t2.order_id) as 'orderNum',
  1057. sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) as 'validOrderNum',
  1058. concat(round(sum(case when t2.flow_point != 'REFUND' then 1 else 0 end) / count(t2.order_id) * 100, 2), '%') as
  1059. 'validOrderRate',
  1060. round(sum(t2.total_pay_amount) / 100, 2) as 'orderAmount',
  1061. sum(CASE
  1062. WHEN t2.flow_point != 'REFUND' and t2.colonel_type != 2
  1063. THEN t2.colonel_estimated_commission
  1064. WHEN t2.flow_point != 'REFUND' and t2.colonel_type = 2
  1065. then t2.second_estimated_commission
  1066. ELSE 0 END) * 0.9 / 100 AS
  1067. 'regimentalPromotionAmount',
  1068. sum(CASE
  1069. WHEN t2.flow_point != 'REFUND' and t2.colonel_type != 2
  1070. THEN t2.second_estimated_commission
  1071. ELSE 0 END) / 100 AS 'secondEstimatedCommission',
  1072. round(sum(t2.colonel_real_commission) / 100, 2) as 'totalRegimentalSettleAmount'
  1073. from kuaishou_promoter t1
  1074. left join
  1075. (
  1076. select t1.*
  1077. from bytedance_promoter_order_list t1
  1078. LEFT JOIN bytedance_order_list t2 ON t1.order_id = t2.order_id
  1079. where t2.pay_success_time &gt;= #{bindStartDate}
  1080. and t2.pay_success_time_hour &lt;= #{hour}
  1081. ) t2 ON t1.promoter_id = t2.author_short_id
  1082. where 1 = 1
  1083. <if test="bindStartDate != null and bindStartDate != '' ">
  1084. and t1.create_time &gt;= str_to_date(concat(date_format(#{bindStartDate}, '%Y-%m-%d'), '00:00:01'),
  1085. '%Y-%m-%d %H:%i:%s')
  1086. </if>
  1087. <if test="bindEndDate != null and bindEndDate != '' ">
  1088. and t1.create_time &lt;= str_to_date(concat(date_format(#{bindEndDate}, '%Y-%m-%d'), '23:59:59'), '%Y-%m-%d
  1089. %H:%i:%s')
  1090. </if>
  1091. <if test="collectSampleId != null and collectSampleId != '' ">
  1092. and t1.user_id = #{collectSampleId}
  1093. </if>
  1094. group by t1.user_id
  1095. ) t
  1096. left join (
  1097. select t1.user_id,
  1098. count(t2.order_id) as 'orderNum'
  1099. from kuaishou_promoter t1
  1100. left join
  1101. (select t1.order_id,t1.author_short_id
  1102. from bytedance_promoter_order_list t1
  1103. LEFT JOIN bytedance_order_list t2 ON t1.order_id = t2.order_id
  1104. where t2.pay_success_time &gt;= #{lastTimeStart}
  1105. AND t2.pay_success_time &lt;= #{lastTimeEnd}
  1106. and t2.pay_success_time_hour &lt;= #{hour}
  1107. ) t2 ON t1.promoter_id = t2.author_short_id
  1108. where 1 = 1
  1109. <if test="bindStartDate != null and bindStartDate != '' ">
  1110. and t1.create_time &gt;= str_to_date(concat(date_format(#{lastTimeStart}, '%Y-%m-%d'), '00:00:01'),
  1111. '%Y-%m-%d %H:%i:%s')
  1112. </if>
  1113. <if test="bindEndDate != null and bindEndDate != '' ">
  1114. and t1.create_time &lt;= str_to_date(concat(date_format(#{lastTimeEnd}, '%Y-%m-%d'), '23:59:59'), '%Y-%m-%d
  1115. %H:%i:%s')
  1116. </if>
  1117. <if test="collectSampleId != null and collectSampleId != '' ">
  1118. and t1.user_id = #{collectSampleId}
  1119. </if>
  1120. group by t1.user_id
  1121. )t11 ON t.collectSampleId = t11.user_id
  1122. left join (select user_id,
  1123. count(distinct promoter_id) as 'promoterCount'
  1124. from kuaishou_promoter
  1125. where 1 = 1
  1126. <if test="collectSampleId != null and collectSampleId != '' ">
  1127. and user_id = #{collectSampleId}
  1128. </if>
  1129. group by user_id) tt on t.collectSampleId = tt.user_id
  1130. left join (select collect_sample_id as 'user_id',
  1131. count(distinct promoter_id) as 'sampleCount'
  1132. from kuaishou_item_collect_samples
  1133. where collect_sample_status > 2
  1134. <if test="collectSampleId != null and collectSampleId != '' ">
  1135. and collect_sample_id = #{collectSampleId}
  1136. </if>
  1137. group by collect_sample_id) ttt on t.collectSampleId = ttt.user_id
  1138. left join (select collect_sample_id as 'user_id',
  1139. count(1) as 'sendTotalCount',
  1140. count(distinct promoter_id) as 'sendPromoterCount',
  1141. count(distinct item_id) as 'sendItemCount'
  1142. from kuaishou_item_collect_samples
  1143. where collect_sample_status > 2
  1144. <if test="collectSampleId != null and collectSampleId != '' ">
  1145. and collect_sample_id = #{collectSampleId}
  1146. </if>
  1147. <if test="bindStartDate != null and bindStartDate != '' ">
  1148. and create_time &gt;= str_to_date(concat(date_format(#{bindStartDate}, '%Y-%m-%d'), '00:00:01'),
  1149. '%Y-%m-%d %H:%i:%s')
  1150. </if>
  1151. <if test="bindEndDate != null and bindEndDate != '' ">
  1152. and create_time &lt;= str_to_date(concat(date_format(#{bindEndDate}, '%Y-%m-%d'), '23:59:59'), '%Y-%m-%d
  1153. %H:%i:%s')
  1154. </if>
  1155. group by collect_sample_id) tttt on t.collectSampleId = tttt.user_id
  1156. left join (select user_id, promoters_count
  1157. from user_promoters_count
  1158. where media_id = 2
  1159. <if test="collectSampleId != null and collectSampleId != '' ">
  1160. and user_id = #{collectSampleId}
  1161. </if>
  1162. ) ttttt
  1163. on t.collectSampleId = ttttt.user_id
  1164. where t.orderNum > 0
  1165. order by t.orderNum desc
  1166. </select>
  1167. <select id="getproDate" resultType="com.alibaba.fastjson.JSONObject">
  1168. select promoter_id as 'promoter_id', min(stat_date) as 'start', max(stat_date) as 'end'
  1169. from promoter_bind_channel_date
  1170. where user_name = '胡勤朴'
  1171. and stat_date >= 20240101
  1172. and stat_date &lt;= 20240131
  1173. group by promoter_id
  1174. </select>
  1175. <select id="getCount" resultType="java.math.BigDecimal">
  1176. select sum(CASE
  1177. WHEN flow_point != 'REFUND' and colonel_type != 2
  1178. THEN colonel_estimated_commission
  1179. WHEN flow_point != 'REFUND' and colonel_type = 2
  1180. then second_estimated_commission
  1181. ELSE 0 END) * 0.9 / 100 AS
  1182. 'regimentalPromotionAmount'
  1183. from bytedance_order_list
  1184. where author_short_id = #{promoterId}
  1185. and pay_success_time >= #{start}
  1186. and pay_success_time &lt;= #{end}
  1187. </select>
  1188. </mapper>