AccountReport.py 33 KB

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