pitcher_panel.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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,
  11. formatDateTime(dt,'%Y-%m-%d') as date,
  12. cost,
  13. first_order_amount,
  14. toDecimal32(if(cost=0,0,first_order_amount/cost),4) first_roi,
  15. first_order_user,first_order_count,
  16. toDecimal32(if(first_order_user=0,0,cost/first_order_user),2) first_per_cost,
  17. view_count,click_count,follow_user,
  18. toDecimal32(if(click_count=0,0,follow_user/click_count),4) follow_rate,
  19. toDecimal32(if(follow_user=0,0,cost/follow_user),2) follow_per_cost,
  20. total_cost,
  21. toDecimal32(if(total_cost=0,0,total_amount/total_cost),2) back_rate
  22. from dw_daily_channel where dt>='{start}' and dt<='{end}' """
  23. if pitcher!='all':
  24. sql += f" and pitcher='{pitcher}' "
  25. if channel!='':
  26. sql += f" and channel='{channel}' "
  27. sql += f" order by {order_by} {order} limit {page},{page_size} "
  28. print(sql)
  29. data=ck.execute(sql)
  30. key=['channel','stage','platform','book','date','cost','first_order_amount','first_roi','first_order_user',
  31. 'first_order_count','first_per_cost','view_count','click_count','follow_user','follow_rate','follow_per_cost',
  32. 'total_cost','back_rate']
  33. return get_dict_list(key, data)
  34. def get_pitcher_panel_daily(pitcher, start, end, page, page_size, order_by, order):
  35. sql=f"""
  36. select formatDateTime(dt,'%Y-%m-%d') date ,pitcher,
  37. toDecimal32(sum(cost),2) cost,
  38. toDecimal32(sum(first_order_amount),2) first_order_amount,
  39. toDecimal32(if(cost=0,0,first_order_amount/cost),4) first_roi ,
  40. toDecimal32(sum(order_amount),2) order_amount,
  41. toDecimal32(if(cost=0,0,sum(reg_order_amount)/cost),4) today_roi,
  42. toDecimal32(sum(total_cost),2) total_cost,
  43. toDecimal32(sum(total_amount),2) total_amount,
  44. toDecimal32(total_amount-total_cost,2) total_profit,
  45. toDecimal32(if(total_cost=0,0,total_amount/total_cost),4) total_roi
  46. from dw_daily_channel where dt>='{start}' and dt<='{end}' """
  47. if pitcher != 'all':
  48. sql += f" and pitcher='{pitcher}' "
  49. sql += f" group by date,pitcher order by {order_by} {order} limit {page},{page_size} "
  50. print(sql)
  51. data = ck.execute(sql)
  52. key=['date','pitcher','cost','first_order_amount','first_roi','order_amount','today_roi','total_cost','total_amount','total_profit','total_roi']
  53. return get_dict_list(key,data)
  54. def get_pitcher_panel_overview(pitcher):
  55. sql=f"""select pitcher,
  56. toDecimal32(cost,2) cost,
  57. toDecimal32(amount,2) amount,
  58. toDecimal32(roi,4) roi,
  59. channel_count,on_channel_count,
  60. off_channel_count,
  61. toDecimal32(this_month_cost,2) this_month_cost,
  62. toDecimal32(this_month_amount,2) this_month_amount,
  63. toDecimal32(this_month_roi,4) this_month_roi,
  64. toDecimal32(last_month_cost,2) last_month_cost,
  65. toDecimal32(last_month_amount,2) last_month_amount,
  66. toDecimal32(last_month_roi,4) last_month_roi,
  67. toDecimal32(last_month_far_amount,2) last_month_far_amount,
  68. follow_user
  69. from dm_pitcher_daily_page_total where dt='{du.get_n_days(-1)}'"""
  70. if pitcher != 'all':
  71. sql += f" and pitcher='{pitcher}' "
  72. print(sql)
  73. data=ck.execute(sql)
  74. print(data)
  75. key=['pitcher','cost','amount','roi','channel_count','on_channel_count','off_channel_count','this_month_cost','this_month_amount','this_month_roi',
  76. 'last_month_cost','last_month_amount','last_month_roi','last_month_far_amount','follow_user']
  77. return get_dict_list(key,data)
  78. def get_channel_overview(channel,start,end):
  79. a =[{'date':'2020-12-30',
  80. 'channel':'宝珠书屋',
  81. 'view_count':2,
  82. 'click_count':2,
  83. 'click_rate':0.23,
  84. 'follow_user':2,
  85. 'follow_rate':0.23,
  86. 'follow_per_cost':2.12,
  87. 'order_rate':0.12,
  88. 'order_per_cost':3.21,
  89. 'cost':343.12,
  90. 'first_order_count':23,
  91. 'first_order_user':23,
  92. 'first_order_amount':122.23,
  93. 'order_count':21,
  94. 'order_user':12,
  95. 'order_amount':234.12,
  96. 'old_order_amount':234.12,
  97. 'first_amount_per_user':232,
  98. 'amount_per_follow':123.12,
  99. 'first_cost_per_user':234.12,
  100. 'new_user_order_rate':0.22,
  101. 'reg_user_amount':212.1,
  102. 'total_cost':2342.11,
  103. 'total_amount':123.11,
  104. 'day_roi':0.87,
  105. 'all_roi':23.12,
  106. 'avg_new_order_rate':0.23,
  107. 'old_user_once_order_rate':0.23
  108. }]
  109. return a
  110. def get_channel_again_order_trend(channel,date):
  111. a=[{'date':'2020-12-01',
  112. 'channel':'宝珠书屋',
  113. 'book':'熊出没',
  114. 'cost':23.23,
  115. 'reg_amount':23421.11,
  116. 'roi':0.23,
  117. 'new_follow':23,
  118. 'new_follow_per_cost':234.11,
  119. 'reg_user':111,
  120. 'reg_count':123,
  121. 'cost_per_user':123,
  122. 'avg_again_order_rate':0.24,
  123. 'avg_order_amount':1231.11,
  124. 'order_count':11,
  125. 'data':[{'user_order_count' :1,
  126. 'd1':{'origin':12,
  127. 'new':1231,
  128. 'move':12,
  129. 'now':2134,
  130. 'follow_order_rate':0.12},
  131. 'd2': {'origin': 12,
  132. 'new': 1231,
  133. 'move': 12,
  134. 'now': 2134,
  135. 'follow_order_rate': 0.12},
  136. 'd3': {'origin': 12,
  137. 'new': 1231,
  138. 'move': 12,
  139. 'now': 2134,
  140. 'follow_order_rate': 0.12},
  141. 'd4': {'origin': 12,
  142. 'new': 1231,
  143. 'move': 12,
  144. 'now': 2134,
  145. 'follow_order_rate': 0.12},
  146. 'd5': {'origin': 12,
  147. 'new': 1231,
  148. 'move': 12,
  149. 'now': 2134,
  150. 'follow_order_rate': 0.12},
  151. 'd6': {'origin': 12,
  152. 'new': 1231,
  153. 'move': 12,
  154. 'now': 2134,
  155. 'follow_order_rate': 0.12},
  156. 'd7': {'origin': 12,
  157. 'new': 1231,
  158. 'move': 12,
  159. 'now': 2134,
  160. 'follow_order_rate': 0.12}
  161. }
  162. ]
  163. }]
  164. return a
  165. def get_channel_active(channel,start,end):
  166. a=[{
  167. 'date':'2020-12-01',
  168. 'channel':'宝珠书屋',
  169. 'book':'魏汝稳',
  170. 'cost':234.11,
  171. 'reg_amount':123.11,
  172. 'roi':0.45,
  173. 'new_follow_user':11,
  174. 'new_follow_per_cost':234.11,
  175. 'order_user':222,
  176. 'order_count':12312,
  177. 'order_user_per_cost':123.11,
  178. 'day7_avg_act_rate':0.14,
  179. 'day7_avg_act_per_cost':5.23,
  180. 'day30_avg_act_rate':0.9334,
  181. 'day30_avg_act_rate':5.23,
  182. 'act_per_cost':43.11,
  183. 'd1':{
  184. 'act_user':12,
  185. 'act_cost_per_cost':23.11,
  186. 'act_rate':0.4512},
  187. 'd2': {
  188. 'act_user': 12,
  189. 'act_cost_per_cost': 23.11,
  190. 'act_rate': 0.4512},
  191. 'd3': {
  192. 'act_user': 12,
  193. 'act_cost_per_cost': 23.11,
  194. 'act_rate': 0.4512}
  195. }]
  196. return a
  197. def get_channel_order_trend(channel,start,end):
  198. a=[{
  199. 'date': '2020-12-01',
  200. 'channel': '宝珠书屋',
  201. 'book': '魏汝稳',
  202. 'cost': 234.11,
  203. 'reg_amount': 123.11,
  204. 'roi': 0.45,
  205. 'new_follow_user': 11,
  206. 'new_follow_per_cost': 234.11,
  207. 'order_user': 222,
  208. 'order_count': 12312,
  209. 'order_user_per_cost': 123.11,
  210. 'd1':{
  211. 'order':232.11,
  212. 'roi':0.2341,
  213. 'add':0.4511,
  214. 'mult':1.12},
  215. 'd2': {
  216. 'order': 232.11,
  217. 'roi': 0.2341,
  218. 'add': 0.4511,
  219. 'mult': 1.12},
  220. 'd3': {
  221. 'order': 232.11,
  222. 'roi': 0.2341,
  223. 'add': 0.4511,
  224. 'mult': 1.12},
  225. }]
  226. return a