AccountReport.py 33 KB

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