pitcher_panel.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. from model.DateUtils import DateUtils
  2. from model.DataBaseUtils import *
  3. from model.log import logger
  4. from model.CommonUtils import *
  5. du = DateUtils()
  6. ck = CkUtils()
  7. db = MysqlUtils()
  8. log = logger()
  9. def get_pitcher_panel_channel(pitcher,channel,start,end,page,page_size,order_by,order):
  10. sql=f"""select channel,stage,platform,book,formatDateTime(dt,'%Y-%m-%d') as date,cost,first_order_amount,
  11. if(cost=0,0,round(first_order_amount/cost,4)) first_roi,
  12. first_order_user,first_order_count,
  13. if(first_order_user=0,0,round(cost/first_order_user,2)) first_per_cost,
  14. view_count,click_count,follow_user,
  15. if(click_count=0,0,round(follow_user/click_count,4)) follow_rate,
  16. if(follow_user=0,0,round(cost/follow_user,2)) follow_per_cost,
  17. total_cost,
  18. if(total_cost=0,0,round(total_amount/total_cost,4)) back_rate
  19. from dw_daily_channel where dt>='{start}' and dt<='{end}' """
  20. if pitcher!='all':
  21. sql += f" and pitcher='{pitcher}' "
  22. if channel!='':
  23. sql += f" and channel='{channel}' "
  24. sql += f" order by {order_by} {order} limit {page},{page_size} "
  25. print(sql)
  26. data=ck.execute(sql)
  27. key=['channel','stage','platform','book','date','cost','first_order_amount','first_roi','first_order_user',
  28. 'first_order_count','first_per_cost','view_count','click_count','follow_user','follow_rate','follow_per_cost',
  29. 'total_cost','back_rate']
  30. return get_dict_list(key, data)
  31. def get_pitcher_panel_daily(pitcher, start, end, page, page_size, order_by, order):
  32. sql=f"""
  33. select formatDateTime(dt,'%Y-%m-%d') date ,pitcher,
  34. round(sum(cost),2) cost,
  35. round(sum(first_order_amount),2) first_order_amount,
  36. if(cost=0,0,round(first_order_amount/cost,4)) first_roi ,
  37. round(sum(order_amount),2) order_amount,
  38. if(cost=0,0,round(sum(reg_order_amount)/cost,4)) today_roi,
  39. round(sum(total_cost),2) total_cost,
  40. round(sum(total_amount),2) total_amount,
  41. total_amount-total_cost total_profit,
  42. if(total_cost=0,0,round(total_amount/total_cost,4)) total_roi
  43. from dw_daily_channel where dt>='{start}' and dt<='{end}' """
  44. if pitcher != 'all':
  45. sql += f" and pitcher='{pitcher}' "
  46. sql += f" group by date,pitcher order by {order_by} {order} limit {page},{page_size} "
  47. print(sql)
  48. data = ck.execute(sql)
  49. key=['date','pitcher','cost','first_order_amount','first_roi','order_amount','today_roi','total_cost','total_amount','total_profit','total_roi']
  50. return get_dict_list(key,data)
  51. def get_pitcher_panel_overview(pitcher):
  52. sql=f"""select pitcher,cost,amount,roi,
  53. channel_count,on_channel_count,
  54. off_channel_count,
  55. this_month_cost,
  56. this_month_amount,
  57. this_month_roi,
  58. last_month_cost,
  59. last_month_amount,
  60. last_month_roi,
  61. last_month_far_amount,
  62. follow_user
  63. from dm_pitcher_daily_page_total where dt='{du.get_n_days(-1)}'"""
  64. if pitcher != 'all':
  65. sql += f" and pitcher='{pitcher}' "
  66. print(sql)
  67. data=ck.execute(sql)
  68. print(data)
  69. key=['pitcher','cost','amount','roi','channel_count','on_channel_count','off_channel_count','this_month_cost','this_month_amount','this_month_roi',
  70. 'last_month_cost','last_month_amount','last_month_roi','last_month_far_amount','follow_user']
  71. return get_dict_list(key,data)
  72. def get_channel_overview():
  73. a ={'date':'2020-12-30',
  74. 'channel':'宝珠书屋',
  75. 'view_count':2,
  76. 'click_count':2,
  77. 'click_rate':0.23,
  78. 'follow_user':2,
  79. 'follow_rate':0.23,
  80. 'follow_per_cost':2.12,
  81. 'order_rate':0.12,
  82. 'order_per_cost':3.21,
  83. 'cost':343.12,
  84. 'first_order_count':23,
  85. 'first_order_user':23,
  86. 'first_order_amount':122.23,
  87. 'order_count':21,
  88. 'order_user':12,
  89. 'order_amount':234.12,
  90. 'old_order_amount':234.12,
  91. 'first_amount_per_user':232,
  92. 'amount_per_follow':123.12,
  93. 'first_cost_per_user':234.12,
  94. 'new_user_order_rate':0.22,
  95. 'reg_user_amount':212.1,
  96. 'total_cost':2342.11,
  97. 'total_amount':123.11,
  98. 'day_roi':0.87,
  99. 'all_roi':23.12,
  100. 'avg_new_order_rate':2
  101. }
  102. def get_channel_again_order_trend():
  103. pass
  104. def get_channel_active():
  105. pass
  106. def get_channel_order_trend():
  107. pass