AccountReport.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. # Author renyupeng
  2. # coding=utf-8
  3. # @Time : 2021/9/15 5:10 下午
  4. # @Site :
  5. # @File : AccountReport.py
  6. # @Software: PyCharm
  7. # @contact: renyupeng@c-top.com.cn
  8. import logging
  9. from Apietl.conn.TidbConn import TidbConn
  10. from Apietl.kwai_etl.report.ReplaceAccountInfo import ReplaceAccountInfo
  11. from Apietl.utlis.Utils import Utils
  12. class AccountReport:
  13. def __init__(self):
  14. self.conn = TidbConn.get_connection()
  15. def daily_report(self, account_id, start_date, end_date):
  16. try:
  17. sql = """
  18. replace into application.kuaishou_account_report_daily_dw
  19. (account_id, stat_date, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
  20. company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
  21. play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
  22. cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
  23. event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
  24. event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
  25. event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
  26. event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
  27. event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
  28. event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
  29. event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
  30. event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
  31. event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
  32. play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
  33. event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
  34. event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
  35. event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
  36. event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
  37. event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
  38. event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
  39. event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
  40. event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
  41. union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
  42. key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
  43. event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
  44. ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
  45. event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
  46. event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
  47. event_outbound_call_ratio, event_ad_watch_times,event_pay_purchase_amount_one_day_by_conversion,
  48. ad_photo_played_10s
  49. ,ad_photo_played_2s
  50. ,ad_photo_played_75percent
  51. ,approx_pay_cost
  52. ,approx_pay_count
  53. ,approx_pay_ratio
  54. ,cancel_like
  55. ,click_conversion_ratio
  56. ,conversion_cost
  57. ,conversion_cost_by_impression_7d
  58. ,conversion_num
  59. ,conversion_num_by_impression_7d
  60. ,conversion_num_cost
  61. ,conversion_ratio
  62. ,conversion_ratio_by_impression_7d
  63. ,deep_conversion_cost
  64. ,deep_conversion_cost_by_impression_7d
  65. ,deep_conversion_num
  66. ,deep_conversion_num_by_impression_7d
  67. ,deep_conversion_ratio
  68. ,deep_conversion_ratio_by_impression_7d
  69. ,download_completed_cost
  70. ,download_completed_ratio
  71. ,download_conversion_ratio
  72. ,download_installed
  73. ,download_started_cost
  74. ,download_started_ratio
  75. ,event_24h_stay
  76. ,event_24h_stay_by_conversion
  77. ,event_24h_stay_by_conversion_cost
  78. ,event_24h_stay_by_conversion_ratio
  79. ,event_24h_stay_cost
  80. ,event_24h_stay_ratio
  81. ,event_ad_watch_10_times
  82. ,event_ad_watch_10_times_cost
  83. ,event_ad_watch_10_times_ratio
  84. ,event_ad_watch_20_times
  85. ,event_ad_watch_20_times_cost
  86. ,event_ad_watch_20_times_ratio
  87. ,event_ad_watch_5_times
  88. ,event_ad_watch_5_times_cost
  89. ,event_ad_watch_5_times_ratio
  90. ,event_audition
  91. ,event_consultation_valid_retained
  92. ,event_consultation_valid_retained_cost
  93. ,event_consultation_valid_retained_ratio
  94. ,event_conversion_click_cost
  95. ,event_conversion_click_ratio
  96. ,event_credit_grant_first_day_app
  97. ,event_credit_grant_first_day_app_cost
  98. ,event_credit_grant_first_day_app_ratio
  99. ,event_credit_grant_first_day_landing_page
  100. ,event_credit_grant_first_day_landing_page_cost
  101. ,event_credit_grant_first_day_landing_page_ratio
  102. ,event_making_calls
  103. ,event_making_calls_cost
  104. ,event_making_calls_ratio
  105. ,event_order_submit
  106. ,event_pay_purchase_amount_one_day
  107. ,event_pay_purchase_amount_one_day_by_conversion_roi
  108. ,event_pay_purchase_amount_one_day_roi
  109. ,event_pay_purchase_amount_three_day_by_conversion
  110. ,event_pay_purchase_amount_three_day_by_conversion_roi
  111. ,event_pay_purchase_amount_week_by_conversion
  112. ,event_pay_purchase_amount_week_by_conversion_roi
  113. ,event_pay_week_by_conversion
  114. ,event_pay_week_by_conversion_cost
  115. ,event_pay_weighted_purchase_amount
  116. ,event_pay_weighted_purchase_amount_first_day
  117. ,event_pre_component_consultation_valid_retained
  118. ,event_three_day_stay_by_conversion
  119. ,event_three_day_stay_by_conversion_cost
  120. ,event_three_day_stay_by_conversion_ratio
  121. ,event_wechat_qr_code_link_click
  122. ,event_week_stay_by_conversion
  123. ,event_week_stay_by_conversion_cost
  124. ,event_week_stay_by_conversion_ratio
  125. ,live_event_goods_view
  126. ,live_played_3s
  127. ,played_end
  128. ,played_five_seconds
  129. ,played_three_seconds
  130. ,event_next_day_stay_new
  131. ,event_next_day_stay_new_cost
  132. ,event_next_day_stay_new_ratio
  133. ,ad_show
  134. ,event_credit_card_recheck
  135. ,event_credit_card_recheck_first_day
  136. ,event_no_intention
  137. ,event_multi_pay_seven_day_by_conversion
  138. ,event_multi_pay_seven_day_by_conversion_cost
  139. ,mcb_left_time_perf_cpa_bid
  140. ,mcb_left_time_perf_roi_ratio
  141. ,mcb_all_day_perf_cpa_bid
  142. ,mcb_all_day_perf_roi_ratio
  143. ,live_room_avg_played_seconds
  144. ,ad_live_share
  145. ,ad_live_comment
  146. ,live_played_started
  147. ,live_played_started_cost
  148. ,ad_live_follow
  149. ,ad_live_follow_cost
  150. ,simple_live_played_started
  151. ,standard_live_played_started
  152. ,conversion_component_impression
  153. ,conversion_component_click
  154. ,conversion_component_rate
  155. ,ad_landing_page_impression
  156. ,ad_app_download_half_impression
  157. ,event_draw_credit_line
  158. )
  159. select report.advertiser_id as account_id,
  160. stat_date,
  161. project_id,
  162. product_id,
  163. sys.advertiser_id,
  164. company_id,
  165. account_name,
  166. project_name,
  167. advertiser_name,
  168. company_name,
  169. sale_id,
  170. user_id,
  171. org_code,
  172. charge,
  173. `show`,
  174. photo_click,
  175. aclick,
  176. bclick,
  177. photo_click_ratio,
  178. play_3s_ratio,
  179. action_ratio,
  180. impression_1k_cost,
  181. photo_click_cost,
  182. action_cost,
  183. share,
  184. comment,
  185. `like`,
  186. follow,
  187. cancel_follow,
  188. report,
  189. block,
  190. negative,
  191. submit,
  192. download_started,
  193. download_completed,
  194. activation,
  195. event_pay_first_day,
  196. event_pay_purchase_amount_first_day,
  197. event_pay_first_day_roi,
  198. event_pay,
  199. event_pay_purchase_amount,
  200. event_pay_roi,
  201. event_register,
  202. event_register_cost,
  203. event_register_ratio,
  204. event_jin_jian_app,
  205. event_jin_jian_app_cost,
  206. event_credit_grant_app,
  207. event_credit_grant_app_cost,
  208. event_credit_grant_app_ratio,
  209. event_order_paid,
  210. event_order_paid_purchase_amount,
  211. event_order_paid_cost,
  212. event_next_day_stay,
  213. event_next_day_stay_cost,
  214. event_next_day_stay_ratio,
  215. form_count,
  216. form_cost,
  217. form_action_ratio,
  218. event_jin_jian_landing_page,
  219. event_jin_jian_landing_page_cost,
  220. event_credit_grant_landing_page,
  221. event_credit_grant_landing_page_cost,
  222. event_credit_grant_landing_page_ratio,
  223. event_valid_clues,
  224. event_valid_clues_cost,
  225. event_add_wechat,
  226. event_add_wechat_cost,
  227. event_add_wechat_ratio,
  228. event_get_through,
  229. event_get_through_cost,
  230. event_get_through_ratio,
  231. event_app_invoked,
  232. event_app_invoked_cost,
  233. event_app_invoked_ratio,
  234. event_credit_grant_landing_ratio,
  235. play_5s_ratio,
  236. play_end_ratio,
  237. event_new_user_pay,
  238. event_new_user_pay_cost,
  239. event_new_user_pay_ratio,
  240. click_1k_cost,
  241. ad_product_cnt,
  242. event_goods_view,
  243. merchant_reco_fans,
  244. event_order_amount_roi,
  245. event_goods_view_cost,
  246. merchant_reco_fans_cost,
  247. event_button_click,
  248. event_button_click_cost,
  249. event_button_click_ratio,
  250. event_order_paid_roi,
  251. event_new_user_jinjian_app,
  252. event_new_user_jinjian_app_cost,
  253. event_new_user_jinjian_app_roi,
  254. event_new_user_credit_grant_app,
  255. event_new_user_credit_grant_app_cost,
  256. event_new_user_credit_grant_app_roi,
  257. event_new_user_jinjian_page,
  258. event_new_user_jinjian_page_cost,
  259. event_new_user_jinjian_page_roi,
  260. event_new_user_credit_grant_page,
  261. event_new_user_credit_grant_page_cost,
  262. event_new_user_credit_grant_page_roi,
  263. event_appoint_form,
  264. event_appoint_form_cost,
  265. event_appoint_form_ratio,
  266. event_appoint_jump_click,
  267. event_appoint_jump_click_cost,
  268. event_appoint_jump_click_ratio,
  269. union_event_pay_purchase_amount_7d,
  270. union_event_pay_purchase_amount_7d_roi,
  271. placement_type,
  272. ad_scene,
  273. event_order_successed,
  274. ad_photo_played_10s_ratio,
  275. key_action_cost,
  276. event_add_shopping_cart_cost,
  277. event_ad_watch_times_ratio,
  278. event_outbound_call_cost,
  279. event_outbound_call,
  280. action_new_ratio,
  281. event_watch_app_ad,
  282. event_multi_conversion_cost,
  283. event_phone_card_activate,
  284. ad_photo_played_75percent_ratio,
  285. key_action_ratio,
  286. event_ad_watch_times_cost,
  287. event_add_shopping_cart,
  288. key_action,
  289. event_multi_conversion,
  290. event_wechat_connected,
  291. event_dsp_gift_form,
  292. event_intention_confirmed,
  293. event_phone_get_through,
  294. event_multi_conversion_ratio,
  295. event_measurement_house,
  296. ad_photo_played_2s_ratio,
  297. event_outbound_call_ratio,
  298. event_ad_watch_times,
  299. event_pay_purchase_amount_one_day_by_conversion,
  300. ad_photo_played_10s
  301. ,ad_photo_played_2s
  302. ,ad_photo_played_75percent
  303. ,approx_pay_cost
  304. ,approx_pay_count
  305. ,approx_pay_ratio
  306. ,cancel_like
  307. ,click_conversion_ratio
  308. ,conversion_cost
  309. ,conversion_cost_by_impression_7d
  310. ,conversion_num
  311. ,conversion_num_by_impression_7d
  312. ,conversion_num_cost
  313. ,conversion_ratio
  314. ,conversion_ratio_by_impression_7d
  315. ,deep_conversion_cost
  316. ,deep_conversion_cost_by_impression_7d
  317. ,deep_conversion_num
  318. ,deep_conversion_num_by_impression_7d
  319. ,deep_conversion_ratio
  320. ,deep_conversion_ratio_by_impression_7d
  321. ,download_completed_cost
  322. ,download_completed_ratio
  323. ,download_conversion_ratio
  324. ,download_installed
  325. ,download_started_cost
  326. ,download_started_ratio
  327. ,event_24h_stay
  328. ,event_24h_stay_by_conversion
  329. ,event_24h_stay_by_conversion_cost
  330. ,event_24h_stay_by_conversion_ratio
  331. ,event_24h_stay_cost
  332. ,event_24h_stay_ratio
  333. ,event_ad_watch_10_times
  334. ,event_ad_watch_10_times_cost
  335. ,event_ad_watch_10_times_ratio
  336. ,event_ad_watch_20_times
  337. ,event_ad_watch_20_times_cost
  338. ,event_ad_watch_20_times_ratio
  339. ,event_ad_watch_5_times
  340. ,event_ad_watch_5_times_cost
  341. ,event_ad_watch_5_times_ratio
  342. ,event_audition
  343. ,event_consultation_valid_retained
  344. ,event_consultation_valid_retained_cost
  345. ,event_consultation_valid_retained_ratio
  346. ,event_conversion_click_cost
  347. ,event_conversion_click_ratio
  348. ,event_credit_grant_first_day_app
  349. ,event_credit_grant_first_day_app_cost
  350. ,event_credit_grant_first_day_app_ratio
  351. ,event_credit_grant_first_day_landing_page
  352. ,event_credit_grant_first_day_landing_page_cost
  353. ,event_credit_grant_first_day_landing_page_ratio
  354. ,event_making_calls
  355. ,event_making_calls_cost
  356. ,event_making_calls_ratio
  357. ,event_order_submit
  358. ,event_pay_purchase_amount_one_day
  359. ,event_pay_purchase_amount_one_day_by_conversion_roi
  360. ,event_pay_purchase_amount_one_day_roi
  361. ,event_pay_purchase_amount_three_day_by_conversion
  362. ,event_pay_purchase_amount_three_day_by_conversion_roi
  363. ,event_pay_purchase_amount_week_by_conversion
  364. ,event_pay_purchase_amount_week_by_conversion_roi
  365. ,event_pay_week_by_conversion
  366. ,event_pay_week_by_conversion_cost
  367. ,event_pay_weighted_purchase_amount
  368. ,event_pay_weighted_purchase_amount_first_day
  369. ,event_pre_component_consultation_valid_retained
  370. ,event_three_day_stay_by_conversion
  371. ,event_three_day_stay_by_conversion_cost
  372. ,event_three_day_stay_by_conversion_ratio
  373. ,event_wechat_qr_code_link_click
  374. ,event_week_stay_by_conversion
  375. ,event_week_stay_by_conversion_cost
  376. ,event_week_stay_by_conversion_ratio
  377. ,live_event_goods_view
  378. ,live_played_3s
  379. ,played_end
  380. ,played_five_seconds
  381. ,played_three_seconds
  382. ,event_next_day_stay_new
  383. ,event_next_day_stay_new_cost
  384. ,event_next_day_stay_new_ratio
  385. ,ad_show
  386. ,event_credit_card_recheck
  387. ,event_credit_card_recheck_first_day
  388. ,event_no_intention
  389. ,event_multi_pay_seven_day_by_conversion
  390. ,event_multi_pay_seven_day_by_conversion_cost
  391. ,mcb_left_time_perf_cpa_bid
  392. ,mcb_left_time_perf_roi_ratio
  393. ,mcb_all_day_perf_cpa_bid
  394. ,mcb_all_day_perf_roi_ratio
  395. ,live_room_avg_played_seconds
  396. ,ad_live_share
  397. ,ad_live_comment
  398. ,live_played_started
  399. ,live_played_started_cost
  400. ,ad_live_follow
  401. ,ad_live_follow_cost
  402. ,simple_live_played_started
  403. ,standard_live_played_started
  404. ,conversion_component_impression
  405. ,conversion_component_click
  406. ,conversion_component_rate
  407. ,ad_landing_page_impression
  408. ,ad_app_download_half_impression
  409. ,event_draw_credit_line
  410. from media_api.kuaishou_account_report_daily report
  411. left join
  412. (SELECT
  413. cua.account_id id,
  414. cua.account_id account_id,
  415. cp.id project_id,
  416. product.id product_id,
  417. ca.id advertiser_id,
  418. uc.company_id company_id,
  419. cua.auth_name account_name,
  420. cp.project_name project_name,
  421. ca.`name` advertiser_name,
  422. uc.company_name company_name,
  423. cp.sale_id sale_id,
  424. su.id user_id,
  425. su.leader_id,
  426. su.org_code org_code
  427. FROM
  428. `jeecg-boot`.ctop_user_allocation cua
  429. LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
  430. LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON ca.id = cua.advertiser_id
  431. LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
  432. LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
  433. LEFT JOIN `jeecg-boot`.ctop_product product ON product.id = cp.product_id
  434. WHERE
  435. cua.account_id IS NOT NULL
  436. ) sys
  437. on report.advertiser_id = sys.account_id
  438. where report.stat_date between {start_date} and {end_date}
  439. and report.advertiser_id={account_id}
  440. """.format(start_date=start_date, end_date=end_date, account_id=account_id)
  441. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  442. self.conn.commit()
  443. TidbConn.conn_close(conn=self.conn)
  444. print(account_id, '快手账户日报执行完成')
  445. except Exception as e:
  446. logging.error(account_id, '执行失败')
  447. def hourly_report(self, account_id, start_date, end_date):
  448. try:
  449. sql = """
  450. replace into application.kuaishou_account_report_hourly_dw
  451. (account_id, stat_date,`hour`, project_id, product_id, advertiser_id, company_id, account_name, project_name, advertiser_name,
  452. company_name, sale_id, user_id, org_code, charge, `show`, photo_click, aclick, bclick, photo_click_ratio,
  453. play_3s_ratio, action_ratio, impression_1k_cost, photo_click_cost, action_cost, share, comment, `like`, follow,
  454. cancel_follow, report, block, negative, submit, download_started, download_completed, activation, event_pay_first_day,
  455. event_pay_purchase_amount_first_day, event_pay_first_day_roi, event_pay, event_pay_purchase_amount, event_pay_roi,
  456. event_register, event_register_cost, event_register_ratio, event_jin_jian_app, event_jin_jian_app_cost,
  457. event_credit_grant_app, event_credit_grant_app_cost, event_credit_grant_app_ratio, event_order_paid,
  458. event_order_paid_purchase_amount, event_order_paid_cost, event_next_day_stay, event_next_day_stay_cost,
  459. event_next_day_stay_ratio, form_count, form_cost, form_action_ratio, event_jin_jian_landing_page,
  460. event_jin_jian_landing_page_cost, event_credit_grant_landing_page, event_credit_grant_landing_page_cost,
  461. event_credit_grant_landing_page_ratio, event_valid_clues, event_valid_clues_cost, event_add_wechat,
  462. event_add_wechat_cost, event_add_wechat_ratio, event_get_through, event_get_through_cost, event_get_through_ratio,
  463. event_app_invoked, event_app_invoked_cost, event_app_invoked_ratio, event_credit_grant_landing_ratio, play_5s_ratio,
  464. play_end_ratio, event_new_user_pay, event_new_user_pay_cost, event_new_user_pay_ratio, click_1k_cost, ad_product_cnt,
  465. event_goods_view, merchant_reco_fans, event_order_amount_roi, event_goods_view_cost, merchant_reco_fans_cost,
  466. event_button_click, event_button_click_cost, event_button_click_ratio, event_order_paid_roi,
  467. event_new_user_jinjian_app, event_new_user_jinjian_app_cost, event_new_user_jinjian_app_roi,
  468. event_new_user_credit_grant_app, event_new_user_credit_grant_app_cost, event_new_user_credit_grant_app_roi,
  469. event_new_user_jinjian_page, event_new_user_jinjian_page_cost, event_new_user_jinjian_page_roi,
  470. event_new_user_credit_grant_page, event_new_user_credit_grant_page_cost, event_new_user_credit_grant_page_roi,
  471. event_appoint_form, event_appoint_form_cost, event_appoint_form_ratio, event_appoint_jump_click,
  472. event_appoint_jump_click_cost, event_appoint_jump_click_ratio, union_event_pay_purchase_amount_7d,
  473. union_event_pay_purchase_amount_7d_roi, placement_type, ad_scene, event_order_successed, ad_photo_played_10s_ratio,
  474. key_action_cost, event_add_shopping_cart_cost, event_ad_watch_times_ratio, event_outbound_call_cost,
  475. event_outbound_call, action_new_ratio, event_watch_app_ad, event_multi_conversion_cost, event_phone_card_activate,
  476. ad_photo_played_75percent_ratio, key_action_ratio, event_ad_watch_times_cost, event_add_shopping_cart, key_action,
  477. event_multi_conversion, event_wechat_connected, event_dsp_gift_form, event_intention_confirmed,
  478. event_phone_get_through, event_multi_conversion_ratio, event_measurement_house, ad_photo_played_2s_ratio,
  479. event_outbound_call_ratio, event_ad_watch_times,event_pay_purchase_amount_one_day_by_conversion, ad_photo_played_10s
  480. ,ad_photo_played_2s
  481. ,ad_photo_played_75percent
  482. ,approx_pay_cost
  483. ,approx_pay_count
  484. ,approx_pay_ratio
  485. ,cancel_like
  486. ,click_conversion_ratio
  487. ,conversion_cost
  488. ,conversion_cost_by_impression_7d
  489. ,conversion_num
  490. ,conversion_num_by_impression_7d
  491. ,conversion_num_cost
  492. ,conversion_ratio
  493. ,conversion_ratio_by_impression_7d
  494. ,deep_conversion_cost
  495. ,deep_conversion_cost_by_impression_7d
  496. ,deep_conversion_num
  497. ,deep_conversion_num_by_impression_7d
  498. ,deep_conversion_ratio
  499. ,deep_conversion_ratio_by_impression_7d
  500. ,download_completed_cost
  501. ,download_completed_ratio
  502. ,download_conversion_ratio
  503. ,download_installed
  504. ,download_started_cost
  505. ,download_started_ratio
  506. ,event_24h_stay
  507. ,event_24h_stay_by_conversion
  508. ,event_24h_stay_by_conversion_cost
  509. ,event_24h_stay_by_conversion_ratio
  510. ,event_24h_stay_cost
  511. ,event_24h_stay_ratio
  512. ,event_ad_watch_10_times
  513. ,event_ad_watch_10_times_cost
  514. ,event_ad_watch_10_times_ratio
  515. ,event_ad_watch_20_times
  516. ,event_ad_watch_20_times_cost
  517. ,event_ad_watch_20_times_ratio
  518. ,event_ad_watch_5_times
  519. ,event_ad_watch_5_times_cost
  520. ,event_ad_watch_5_times_ratio
  521. ,event_audition
  522. ,event_consultation_valid_retained
  523. ,event_consultation_valid_retained_cost
  524. ,event_consultation_valid_retained_ratio
  525. ,event_conversion_click_cost
  526. ,event_conversion_click_ratio
  527. ,event_credit_grant_first_day_app
  528. ,event_credit_grant_first_day_app_cost
  529. ,event_credit_grant_first_day_app_ratio
  530. ,event_credit_grant_first_day_landing_page
  531. ,event_credit_grant_first_day_landing_page_cost
  532. ,event_credit_grant_first_day_landing_page_ratio
  533. ,event_making_calls
  534. ,event_making_calls_cost
  535. ,event_making_calls_ratio
  536. ,event_order_submit
  537. ,event_pay_purchase_amount_one_day
  538. ,event_pay_purchase_amount_one_day_by_conversion_roi
  539. ,event_pay_purchase_amount_one_day_roi
  540. ,event_pay_purchase_amount_three_day_by_conversion
  541. ,event_pay_purchase_amount_three_day_by_conversion_roi
  542. ,event_pay_purchase_amount_week_by_conversion
  543. ,event_pay_purchase_amount_week_by_conversion_roi
  544. ,event_pay_week_by_conversion
  545. ,event_pay_week_by_conversion_cost
  546. ,event_pay_weighted_purchase_amount
  547. ,event_pay_weighted_purchase_amount_first_day
  548. ,event_pre_component_consultation_valid_retained
  549. ,event_three_day_stay_by_conversion
  550. ,event_three_day_stay_by_conversion_cost
  551. ,event_three_day_stay_by_conversion_ratio
  552. ,event_wechat_qr_code_link_click
  553. ,event_week_stay_by_conversion
  554. ,event_week_stay_by_conversion_cost
  555. ,event_week_stay_by_conversion_ratio
  556. ,live_event_goods_view
  557. ,live_played_3s
  558. ,played_end
  559. ,played_five_seconds
  560. ,played_three_seconds
  561. ,event_next_day_stay_new
  562. ,event_next_day_stay_new_cost
  563. ,event_next_day_stay_new_ratio
  564. ,ad_show
  565. ,event_credit_card_recheck
  566. ,event_credit_card_recheck_first_day
  567. ,event_no_intention
  568. ,event_multi_pay_seven_day_by_conversion
  569. ,event_multi_pay_seven_day_by_conversion_cost
  570. ,mcb_left_time_perf_cpa_bid
  571. ,mcb_left_time_perf_roi_ratio
  572. ,mcb_all_day_perf_cpa_bid
  573. ,mcb_all_day_perf_roi_ratio
  574. ,live_room_avg_played_seconds
  575. ,ad_live_share
  576. ,ad_live_comment
  577. ,live_played_started
  578. ,live_played_started_cost
  579. ,ad_live_follow
  580. ,ad_live_follow_cost
  581. ,simple_live_played_started
  582. ,standard_live_played_started
  583. ,conversion_component_impression
  584. ,conversion_component_click
  585. ,conversion_component_rate
  586. ,ad_landing_page_impression
  587. ,ad_app_download_half_impression
  588. ,event_draw_credit_line
  589. )
  590. select report.advertiser_id as account_id,
  591. stat_date,
  592. `hour`,
  593. project_id,
  594. product_id,
  595. sys.advertiser_id,
  596. company_id,
  597. account_name,
  598. project_name,
  599. advertiser_name,
  600. company_name,
  601. sale_id,
  602. user_id,
  603. org_code,
  604. charge,
  605. `show`,
  606. photo_click,
  607. aclick,
  608. bclick,
  609. photo_click_ratio,
  610. play_3s_ratio,
  611. action_ratio,
  612. impression_1k_cost,
  613. photo_click_cost,
  614. action_cost,
  615. share,
  616. comment,
  617. `like`,
  618. follow,
  619. cancel_follow,
  620. report,
  621. block,
  622. negative,
  623. submit,
  624. download_started,
  625. download_completed,
  626. activation,
  627. event_pay_first_day,
  628. event_pay_purchase_amount_first_day,
  629. event_pay_first_day_roi,
  630. event_pay,
  631. event_pay_purchase_amount,
  632. event_pay_roi,
  633. event_register,
  634. event_register_cost,
  635. event_register_ratio,
  636. event_jin_jian_app,
  637. event_jin_jian_app_cost,
  638. event_credit_grant_app,
  639. event_credit_grant_app_cost,
  640. event_credit_grant_app_ratio,
  641. event_order_paid,
  642. event_order_paid_purchase_amount,
  643. event_order_paid_cost,
  644. event_next_day_stay,
  645. event_next_day_stay_cost,
  646. event_next_day_stay_ratio,
  647. form_count,
  648. form_cost,
  649. form_action_ratio,
  650. event_jin_jian_landing_page,
  651. event_jin_jian_landing_page_cost,
  652. event_credit_grant_landing_page,
  653. event_credit_grant_landing_page_cost,
  654. event_credit_grant_landing_page_ratio,
  655. event_valid_clues,
  656. event_valid_clues_cost,
  657. event_add_wechat,
  658. event_add_wechat_cost,
  659. event_add_wechat_ratio,
  660. event_get_through,
  661. event_get_through_cost,
  662. event_get_through_ratio,
  663. event_app_invoked,
  664. event_app_invoked_cost,
  665. event_app_invoked_ratio,
  666. event_credit_grant_landing_ratio,
  667. play_5s_ratio,
  668. play_end_ratio,
  669. event_new_user_pay,
  670. event_new_user_pay_cost,
  671. event_new_user_pay_ratio,
  672. click_1k_cost,
  673. ad_product_cnt,
  674. event_goods_view,
  675. merchant_reco_fans,
  676. event_order_amount_roi,
  677. event_goods_view_cost,
  678. merchant_reco_fans_cost,
  679. event_button_click,
  680. event_button_click_cost,
  681. event_button_click_ratio,
  682. event_order_paid_roi,
  683. event_new_user_jinjian_app,
  684. event_new_user_jinjian_app_cost,
  685. event_new_user_jinjian_app_roi,
  686. event_new_user_credit_grant_app,
  687. event_new_user_credit_grant_app_cost,
  688. event_new_user_credit_grant_app_roi,
  689. event_new_user_jinjian_page,
  690. event_new_user_jinjian_page_cost,
  691. event_new_user_jinjian_page_roi,
  692. event_new_user_credit_grant_page,
  693. event_new_user_credit_grant_page_cost,
  694. event_new_user_credit_grant_page_roi,
  695. event_appoint_form,
  696. event_appoint_form_cost,
  697. event_appoint_form_ratio,
  698. event_appoint_jump_click,
  699. event_appoint_jump_click_cost,
  700. event_appoint_jump_click_ratio,
  701. union_event_pay_purchase_amount_7d,
  702. union_event_pay_purchase_amount_7d_roi,
  703. placement_type,
  704. ad_scene,
  705. event_order_successed,
  706. ad_photo_played_10s_ratio,
  707. key_action_cost,
  708. event_add_shopping_cart_cost,
  709. event_ad_watch_times_ratio,
  710. event_outbound_call_cost,
  711. event_outbound_call,
  712. action_new_ratio,
  713. event_watch_app_ad,
  714. event_multi_conversion_cost,
  715. event_phone_card_activate,
  716. ad_photo_played_75percent_ratio,
  717. key_action_ratio,
  718. event_ad_watch_times_cost,
  719. event_add_shopping_cart,
  720. key_action,
  721. event_multi_conversion,
  722. event_wechat_connected,
  723. event_dsp_gift_form,
  724. event_intention_confirmed,
  725. event_phone_get_through,
  726. event_multi_conversion_ratio,
  727. event_measurement_house,
  728. ad_photo_played_2s_ratio,
  729. event_outbound_call_ratio,
  730. event_ad_watch_times,
  731. event_pay_purchase_amount_one_day_by_conversion,
  732. ad_photo_played_10s
  733. ,ad_photo_played_2s
  734. ,ad_photo_played_75percent
  735. ,approx_pay_cost
  736. ,approx_pay_count
  737. ,approx_pay_ratio
  738. ,cancel_like
  739. ,click_conversion_ratio
  740. ,conversion_cost
  741. ,conversion_cost_by_impression_7d
  742. ,conversion_num
  743. ,conversion_num_by_impression_7d
  744. ,conversion_num_cost
  745. ,conversion_ratio
  746. ,conversion_ratio_by_impression_7d
  747. ,deep_conversion_cost
  748. ,deep_conversion_cost_by_impression_7d
  749. ,deep_conversion_num
  750. ,deep_conversion_num_by_impression_7d
  751. ,deep_conversion_ratio
  752. ,deep_conversion_ratio_by_impression_7d
  753. ,download_completed_cost
  754. ,download_completed_ratio
  755. ,download_conversion_ratio
  756. ,download_installed
  757. ,download_started_cost
  758. ,download_started_ratio
  759. ,event_24h_stay
  760. ,event_24h_stay_by_conversion
  761. ,event_24h_stay_by_conversion_cost
  762. ,event_24h_stay_by_conversion_ratio
  763. ,event_24h_stay_cost
  764. ,event_24h_stay_ratio
  765. ,event_ad_watch_10_times
  766. ,event_ad_watch_10_times_cost
  767. ,event_ad_watch_10_times_ratio
  768. ,event_ad_watch_20_times
  769. ,event_ad_watch_20_times_cost
  770. ,event_ad_watch_20_times_ratio
  771. ,event_ad_watch_5_times
  772. ,event_ad_watch_5_times_cost
  773. ,event_ad_watch_5_times_ratio
  774. ,event_audition
  775. ,event_consultation_valid_retained
  776. ,event_consultation_valid_retained_cost
  777. ,event_consultation_valid_retained_ratio
  778. ,event_conversion_click_cost
  779. ,event_conversion_click_ratio
  780. ,event_credit_grant_first_day_app
  781. ,event_credit_grant_first_day_app_cost
  782. ,event_credit_grant_first_day_app_ratio
  783. ,event_credit_grant_first_day_landing_page
  784. ,event_credit_grant_first_day_landing_page_cost
  785. ,event_credit_grant_first_day_landing_page_ratio
  786. ,event_making_calls
  787. ,event_making_calls_cost
  788. ,event_making_calls_ratio
  789. ,event_order_submit
  790. ,event_pay_purchase_amount_one_day
  791. ,event_pay_purchase_amount_one_day_by_conversion_roi
  792. ,event_pay_purchase_amount_one_day_roi
  793. ,event_pay_purchase_amount_three_day_by_conversion
  794. ,event_pay_purchase_amount_three_day_by_conversion_roi
  795. ,event_pay_purchase_amount_week_by_conversion
  796. ,event_pay_purchase_amount_week_by_conversion_roi
  797. ,event_pay_week_by_conversion
  798. ,event_pay_week_by_conversion_cost
  799. ,event_pay_weighted_purchase_amount
  800. ,event_pay_weighted_purchase_amount_first_day
  801. ,event_pre_component_consultation_valid_retained
  802. ,event_three_day_stay_by_conversion
  803. ,event_three_day_stay_by_conversion_cost
  804. ,event_three_day_stay_by_conversion_ratio
  805. ,event_wechat_qr_code_link_click
  806. ,event_week_stay_by_conversion
  807. ,event_week_stay_by_conversion_cost
  808. ,event_week_stay_by_conversion_ratio
  809. ,live_event_goods_view
  810. ,live_played_3s
  811. ,played_end
  812. ,played_five_seconds
  813. ,played_three_seconds
  814. ,event_next_day_stay_new
  815. ,event_next_day_stay_new_cost
  816. ,event_next_day_stay_new_ratio
  817. ,ad_show
  818. ,event_credit_card_recheck
  819. ,event_credit_card_recheck_first_day
  820. ,event_no_intention
  821. ,event_multi_pay_seven_day_by_conversion
  822. ,event_multi_pay_seven_day_by_conversion_cost
  823. ,mcb_left_time_perf_cpa_bid
  824. ,mcb_left_time_perf_roi_ratio
  825. ,mcb_all_day_perf_cpa_bid
  826. ,mcb_all_day_perf_roi_ratio
  827. ,live_room_avg_played_seconds
  828. ,ad_live_share
  829. ,ad_live_comment
  830. ,live_played_started
  831. ,live_played_started_cost
  832. ,ad_live_follow
  833. ,ad_live_follow_cost
  834. ,simple_live_played_started
  835. ,standard_live_played_started
  836. ,conversion_component_impression
  837. ,conversion_component_click
  838. ,conversion_component_rate
  839. ,ad_landing_page_impression
  840. ,ad_app_download_half_impression
  841. ,event_draw_credit_line
  842. from media_api.kuaishou_account_report_hourly report
  843. left join
  844. (SELECT
  845. cua.account_id id,
  846. cua.account_id account_id,
  847. cp.id project_id,
  848. product.id product_id,
  849. ca.id advertiser_id,
  850. uc.company_id company_id,
  851. cua.auth_name account_name,
  852. cp.project_name project_name,
  853. ca.`name` advertiser_name,
  854. uc.company_name company_name,
  855. cp.sale_id sale_id,
  856. su.id user_id,
  857. su.leader_id,
  858. su.org_code org_code
  859. FROM
  860. `jeecg-boot`.ctop_user_allocation cua
  861. LEFT JOIN `jeecg-boot`.ctop_project cp ON cua.project_id = cp.id
  862. LEFT JOIN `jeecg-boot`.ctop_advertiser ca ON ca.id = cua.advertiser_id
  863. LEFT JOIN `jeecg-boot`.sys_user su ON su.id = cua.user_id
  864. LEFT JOIN `jeecg-boot`.user_company uc ON uc.user_id = cua.user_id
  865. LEFT JOIN `jeecg-boot`.ctop_product product ON product.id = cp.product_id
  866. WHERE
  867. cua.account_id IS NOT NULL
  868. ) sys
  869. on report.advertiser_id = sys.account_id
  870. where report.stat_date between {start_date} and {end_date}
  871. and report.advertiser_id={account_id}
  872. """.format(start_date=start_date, end_date=end_date, account_id=account_id)
  873. TidbConn.upsert(conn=self.conn, sql_buff=sql)
  874. self.conn.commit()
  875. TidbConn.conn_close(conn=self.conn)
  876. print(account_id, '快手账户时报执行完成')
  877. except Exception as e:
  878. logging.error(account_id, '执行失败')
  879. def handler(self, date_type, account_id, start_date, end_date):
  880. if date_type == "daily":
  881. self.daily_report(account_id, start_date, end_date)
  882. else:
  883. self.hourly_report(account_id, start_date, end_date)