pitcher_panel.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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, get_round(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. round(sum(cost),2) cost,
  38. round(sum(first_order_amount),2) first_order_amount,
  39. round(if(cost=0,0,first_order_amount/cost),4) first_roi ,
  40. round(sum(order_amount),2) order_amount,
  41. round(if(cost=0,0,sum(reg_order_amount)/cost),4) today_roi,
  42. round(sum(total_cost),2) total_cost,
  43. round(sum(total_amount),2) total_amount,
  44. round(total_amount-total_cost,2) total_profit,
  45. round(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. toDecimal32(last_month_far_roi,2) last_month_far_roi
  70. from dm_pitcher_daily_page_total where dt='{du.get_n_days(-1)}'"""
  71. if pitcher != 'all':
  72. sql += f" and pitcher='{pitcher}' "
  73. print(sql)
  74. data=ck.execute(sql)
  75. print(data)
  76. key=['pitcher','cost','amount','roi','channel_count','on_channel_count','off_channel_count','this_month_cost','this_month_amount','this_month_roi',
  77. 'last_month_cost','last_month_amount','last_month_roi','last_month_far_amount','follow_user','last_month_far_roi']
  78. return get_dict_list(key,data)
  79. def get_channel_overview(channel,pitcher,start,end,page,page_size,order_by,order):
  80. sql="""select channel,toString(dt) date,
  81. view_count,click_count,
  82. round(if(view_count=0,0,click_count/view_count),4) click_rate,
  83. follow_user,
  84. round(if(click_count=0,0,follow_user/click_count),4) follow_rate,
  85. round(if(follow_user=0,0,cost/follow_user),2) follow_per_cost,
  86. round(if(click_count=0,0,first_order_count/click_count),4) order_rate,
  87. round(if(first_order_user=0,0,cost/first_order_user),2) order_per_cost,
  88. round(cost,2) cost,
  89. first_order_count,first_order_user,
  90. round(first_order_amount,2) first_order_amount,order_count,order_user,
  91. round(order_amount,2) order_amount,
  92. round(order_amount-first_order_amount,2) old_order_amount,
  93. round(if(first_order_user=0,0,first_order_amount/first_order_user),2) first_amount_per_user,
  94. round(if(follow_user=0,0,first_order_amount/follow_user),2) amount_per_follow,
  95. round(if(first_order_user=0,0,cost/first_order_user),2) first_cost_per_user,
  96. round(if(follow_user=0,0,first_order_user/follow_user),4) new_user_order_rate,
  97. round(reg_order_amount,2) reg_user_amount,
  98. round(total_cost,2) total_cost,
  99. round(total_amount,2) total_amount,
  100. round(if(cost=0,0,first_order_amount/cost),4) day_roi,
  101. round(if(cost=0,0,reg_order_amount/cost),4) all_roi,
  102. 0 avg_new_order_rate,
  103. 0 old_user_once_order_rate from dw_daily_channel where 1=1 """
  104. if channel!='':
  105. sql+=f" and channel='{channel}'"
  106. if start!='':
  107. sql+=f" and start>='{start}'"
  108. if end!='':
  109. sql+=f" and end<='{end}'"
  110. if pitcher!='':
  111. sql+=f" and pitcher='{pitcher}'"
  112. sql += f" order by {order_by} {order} limit {page},{page_size} "
  113. print(sql)
  114. key=['channel','date','view_count','click_count','click_rate','follow_user','follow_rate','follow_per_cost','order_rate','order_per_cost','cost',
  115. 'first_order_count','first_order_user','first_order_amount','order_count','order_user','order_amount','old_order_amount','first_amount_per_user',
  116. 'new_user_order_rate','reg_user_amount','total_cost','total_amount','day_roi','all_roi','avg_new_order_rate','old_user_once_order_rate']
  117. return get_dict_list(key,get_round(ck.execute(sql)))
  118. def get_channel_again_order_trend(channel,date):
  119. sql=f"""select toString(dt) date,
  120. channel,book,
  121. round(cost,2) cost,
  122. round(reg_order_amount,2) reg_amount,
  123. round(reg_order_amount/cost,4) roi,
  124. follow_user new_follow,
  125. round(cost/follow_user,2) new_follow_per_cost,
  126. reg_order_count reg_count,reg_order_user reg_user,
  127. round(cost/reg_order_user,2) cost_per_user,
  128. round(reg_order_amount/reg_order_user,2) avg_order_amount,
  129. round(reg_order_user_again/reg_order_user,4) avg_again_order_rate,
  130. order_count
  131. from dw_daily_channel where channel='{channel}' and dt='{date}'
  132. """
  133. print(sql)
  134. data=ck.execute(sql)
  135. print(data)
  136. key1=['date','channel','book','cost','reg_amount','roi','new_follow','new_follow_per_cost',
  137. 'reg_count','reg_user','cost_per_user','avg_order_amount','avg_again_order_rate','order_count']
  138. json1=get_dict_list(key1,data)[0]
  139. # print(json1)
  140. sql2="""select
  141. date ,
  142. count(1) c1,
  143. sum(if(count>1,1,0)) c2,
  144. sum(if(count>2,1,0)) c3,
  145. sum(if(count>3,1,0)) c4,
  146. sum(if(count>4,1,0)) c5
  147. from (
  148. select count(1) count,date
  149. from order where channel='玉龙书社' and date>='2020-09-19' and date<=addDays(toDate('2020-09-19'),6)
  150. and formatDateTime(reg_time,'%Y-%m-%d')='2020-09-19' group by user_id,date
  151. ) a group by date"""
  152. df=ck.getData_pd(sql2,[['date','c1','c2','c3','c4','c5']])
  153. reg_user=json1["reg_user"]
  154. li=[]
  155. for i in range(1,5):
  156. d1={}
  157. d1["origin"]=int(df.iat[0,i])
  158. d1["new"]=0
  159. d1["move"]=int(df.iat[0,i+1])
  160. d1["now"]=int(d1["origin"]+d1['new']-d1["move"])
  161. d1["follow_order_rate"]=round(d1["now"]/reg_user,2)
  162. d2={}
  163. d2["origin"] = int(d1["now"])
  164. d2["new"] = int(df.iat[1,i])
  165. d2["move"] = int(df.iat[1, i+1])
  166. d2["now"] = int(d2["origin"] +d2['new']- d2["move"])
  167. d2["follow_order_rate"] = round(d2["now"] / reg_user, 2)
  168. d3={}
  169. d3["origin"] = int(d2["now"])
  170. d3["new"] = int(df.iat[2, i])
  171. d3["move"] = int(df.iat[2, i+1])
  172. d3["now"] = int(d3["origin"] +d3['new']- d3["move"])
  173. d3["follow_order_rate"] = round(d3["now"] / reg_user, 2)
  174. d4={}
  175. d4["origin"] = int(d3["now"])
  176. d4["new"] = int(df.iat[3, i])
  177. d4["move"] = int(df.iat[3, i+1])
  178. d4["now"] = int(d4["origin"] +d4['new']- d4["move"])
  179. d4["follow_order_rate"] = round(d4["now"] / reg_user, 2)
  180. d5={}
  181. d5["origin"] = int(d4["now"])
  182. d5["new"] = int(df.iat[4, i])
  183. d5["move"] = int(df.iat[4, i+1])
  184. d5["now"] = int(d5["origin"] +d5['new']- d5["move"])
  185. d5["follow_order_rate"] = round(d4["now"] / reg_user, 2)
  186. d6 = {}
  187. d6["origin"] = int(d5["now"])
  188. d6["new"] = int(df.iat[5, i])
  189. d6["move"] = int(df.iat[5, i+1])
  190. d6["now"] = int(d6["origin"] +d6['new']- d6["move"])
  191. d6["follow_order_rate"] = round(d6["now"] / reg_user, 2)
  192. d7 = {}
  193. d7["origin"] = int(d6["now"])
  194. d7["new"] = int(df.iat[6, i])
  195. d7["move"] = int(df.iat[6, i+1])
  196. d7["now"] = int(d7["origin"] +d7['new']- d7["move"])
  197. d7["follow_order_rate"] = round(d7["now"] / reg_user, 2)
  198. d={}
  199. d["user_order_count"]=i
  200. d['d1']=d1
  201. d['d2']=d2
  202. d['d3']=d3
  203. d['d4']=d4
  204. d['d5']=d5
  205. d['d6']=d6
  206. d['d7']=d7
  207. li.append(d)
  208. json1['data']=li
  209. print([json1])
  210. return [json1]
  211. def get_channel_active(channel,start,end,page,page_size,order_by,order):
  212. print(channel,)
  213. sql=f"""select formatDateTime(a.dt,'%Y-%m-%d') date, '{channel}' channel,book,cost,reg_amount,roi,new_follow_user,new_follow_per_cost,order_user,order_count,
  214. order_user_per_cost,day7_avg_act_rate,day7_avg_act_per_cost,day30_avg_act_rate,ay30_avg_act_cost,
  215. act_per_cost,
  216. concat(toString(reg_order_user1),',',toString(cost/reg_order_user1),',',toString(reg_order_user1/order_user)),
  217. concat(toString(reg_order_user2),',',toString(cost/reg_order_user2),',',toString(reg_order_user2/order_user)),
  218. concat(toString(reg_order_user3),',',toString(cost/reg_order_user3),',',toString(reg_order_user3/order_user)),
  219. concat(toString(reg_order_user4),',',toString(cost/reg_order_user4),',',toString(reg_order_user4/order_user)),
  220. concat(toString(reg_order_user5),',',toString(cost/reg_order_user5),',',toString(reg_order_user5/order_user)),
  221. concat(toString(reg_order_user6),',',toString(cost/reg_order_user6),',',toString(reg_order_user6/order_user)),
  222. concat(toString(reg_order_user7),',',toString(cost/reg_order_user7),',',toString(reg_order_user7/order_user)),
  223. concat(toString(reg_order_user8),',',toString(cost/reg_order_user8),',',toString(reg_order_user8/order_user)),
  224. concat(toString(reg_order_user9),',',toString(cost/reg_order_user9),',',toString(reg_order_user9/order_user)),
  225. concat(toString(reg_order_user10),',',toString(cost/reg_order_user10),',',toString(reg_order_user10/order_user)),
  226. concat(toString(reg_order_user11),',',toString(cost/reg_order_user11),',',toString(reg_order_user11/order_user)),
  227. concat(toString(reg_order_user12),',',toString(cost/reg_order_user12),',',toString(reg_order_user12/order_user)),
  228. concat(toString(reg_order_user13),',',toString(cost/reg_order_user13),',',toString(reg_order_user13/order_user)),
  229. concat(toString(reg_order_user14),',',toString(cost/reg_order_user14),',',toString(reg_order_user14/order_user)),
  230. concat(toString(reg_order_user15),',',toString(cost/reg_order_user15),',',toString(reg_order_user15/order_user)),
  231. concat(toString(reg_order_user16),',',toString(cost/reg_order_user16),',',toString(reg_order_user16/order_user)),
  232. concat(toString(reg_order_user17),',',toString(cost/reg_order_user17),',',toString(reg_order_user17/order_user)),
  233. concat(toString(reg_order_user18),',',toString(cost/reg_order_user18),',',toString(reg_order_user18/order_user)),
  234. concat(toString(reg_order_user19),',',toString(cost/reg_order_user19),',',toString(reg_order_user19/order_user)),
  235. concat(toString(reg_order_user20),',',toString(cost/reg_order_user20),',',toString(reg_order_user20/order_user)),
  236. concat(toString(reg_order_user21),',',toString(cost/reg_order_user21),',',toString(reg_order_user21/order_user)),
  237. concat(toString(reg_order_user22),',',toString(cost/reg_order_user22),',',toString(reg_order_user22/order_user)),
  238. concat(toString(reg_order_user23),',',toString(cost/reg_order_user23),',',toString(reg_order_user23/order_user)),
  239. concat(toString(reg_order_user24),',',toString(cost/reg_order_user24),',',toString(reg_order_user24/order_user)),
  240. concat(toString(reg_order_user25),',',toString(cost/reg_order_user25),',',toString(reg_order_user25/order_user)),
  241. concat(toString(reg_order_user26),',',toString(cost/reg_order_user26),',',toString(reg_order_user26/order_user)),
  242. concat(toString(reg_order_user27),',',toString(cost/reg_order_user27),',',toString(reg_order_user27/order_user)),
  243. concat(toString(reg_order_user28),',',toString(cost/reg_order_user28),',',toString(reg_order_user28/order_user)),
  244. concat(toString(reg_order_user29),',',toString(cost/reg_order_user29),',',toString(reg_order_user29/order_user)),
  245. concat(toString(reg_order_user30),',',toString(cost/reg_order_user30),',',toString(reg_order_user30/order_user))
  246. from (
  247. select dt,book,cost,
  248. reg_order_amount reg_amount,
  249. if(cost=0,0,reg_order_amount/cost) roi,
  250. follow_user new_follow_user,
  251. if(follow_user=0,0,cost/follow_user) new_follow_per_cost,
  252. reg_order_user order_user,
  253. reg_order_count order_count,
  254. if(reg_order_user=0,0,cost/reg_order_user) order_user_per_cost,
  255. if(follow_user=0,0,reg_order_user7/follow_user) day7_avg_act_rate ,
  256. if(reg_order_user7=0,0,cost/reg_order_user7) day7_avg_act_per_cost,
  257. if(follow_user=0,0,reg_order_user30/follow_user) day30_avg_act_rate,
  258. if(reg_order_user30=0,0,cost/reg_order_user30) ay30_avg_act_cost,
  259. if(reg_order_user=0,0,cost/reg_order_user) act_per_cost
  260. from dw_daily_channel where channel='{channel}' and dt>='{start}' and dt<='{end}') a
  261. left outer join (
  262. select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,
  263. count(distinct if(subtractDays(date, 1)>reg_time,'',user_id))-1 reg_order_user1,
  264. count(distinct if(subtractDays(date, 2)>reg_time,'',user_id))-1 reg_order_user2,
  265. count(distinct if(subtractDays(date, 3)>reg_time,'',user_id))-1 reg_order_user3,
  266. count(distinct if(subtractDays(date, 4)>reg_time,'',user_id))-1 reg_order_user4,
  267. count(distinct if(subtractDays(date, 5)>reg_time,'',user_id))-1 reg_order_user5,
  268. count(distinct if(subtractDays(date, 6)>reg_time,'',user_id))-1 reg_order_user6,
  269. count(distinct if(subtractDays(date, 7)>reg_time,'',user_id))-1 reg_order_user7,
  270. count(distinct if(subtractDays(date, 8)>reg_time,'',user_id))-1 reg_order_user8,
  271. count(distinct if(subtractDays(date, 9)>reg_time,'',user_id))-1 reg_order_user9,
  272. count(distinct if(subtractDays(date, 10)>reg_time,'',user_id))-1 reg_order_user10,
  273. count(distinct if(subtractDays(date, 11)>reg_time,'',user_id))-1 reg_order_user11,
  274. count(distinct if(subtractDays(date, 12)>reg_time,'',user_id))-1 reg_order_user12,
  275. count(distinct if(subtractDays(date, 13)>reg_time,'',user_id))-1 reg_order_user13,
  276. count(distinct if(subtractDays(date, 14)>reg_time,'',user_id))-1 reg_order_user14,
  277. count(distinct if(subtractDays(date, 15)>reg_time,'',user_id))-1 reg_order_user15,
  278. count(distinct if(subtractDays(date, 16)>reg_time,'',user_id))-1 reg_order_user16,
  279. count(distinct if(subtractDays(date, 17)>reg_time,'',user_id))-1 reg_order_user17,
  280. count(distinct if(subtractDays(date, 18)>reg_time,'',user_id))-1 reg_order_user18,
  281. count(distinct if(subtractDays(date, 19)>reg_time,'',user_id))-1 reg_order_user19,
  282. count(distinct if(subtractDays(date, 20)>reg_time,'',user_id))-1 reg_order_user20,
  283. count(distinct if(subtractDays(date, 21)>reg_time,'',user_id))-1 reg_order_user21,
  284. count(distinct if(subtractDays(date, 22)>reg_time,'',user_id))-1 reg_order_user22,
  285. count(distinct if(subtractDays(date, 23)>reg_time,'',user_id))-1 reg_order_user23,
  286. count(distinct if(subtractDays(date, 24)>reg_time,'',user_id))-1 reg_order_user24,
  287. count(distinct if(subtractDays(date, 25)>reg_time,'',user_id))-1 reg_order_user25,
  288. count(distinct if(subtractDays(date, 26)>reg_time,'',user_id))-1 reg_order_user26,
  289. count(distinct if(subtractDays(date, 27)>reg_time,'',user_id))-1 reg_order_user27,
  290. count(distinct if(subtractDays(date, 28)>reg_time,'',user_id))-1 reg_order_user28,
  291. count(distinct if(subtractDays(date, 29)>reg_time,'',user_id))-1 reg_order_user29,
  292. count(distinct if(subtractDays(date, 30)>reg_time,'',user_id))-1 reg_order_user30
  293. from order where channel='{channel}' and dt>='{start}' group by formatDateTime(reg_time,'%Y-%m-%d')) b on a.dt=b.dt
  294. order by {order_by} {order} limit {page},{page_size}
  295. """
  296. print(sql)
  297. data=ck.execute(sql)
  298. key=['date','channel','book','cost','reg_amount','roi','new_follow_user','new_follow_per_cost','order_user','order_count','order_user_per_cost',
  299. 'day7_avg_act_rate','day7_avg_act_per_cost','day30_avg_act_rate','day30_avg_act_cost','act_per_cost','d1','d2','d3','d4','d5','d6','d7','d8','d9','d10',
  300. 'd11','d12','d13','d14','d15','d16','d17','d18','d19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30']
  301. x=get_dict_list(key,get_round(data))
  302. li=[]
  303. for i in x:
  304. di = {}
  305. for j in i:
  306. if j in ['d1','d2','d3','d4','d5','d6','d7','d8','d9','d10',
  307. 'd11','d12','d13','d14','d15','d16','d17','d18','d19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30']:
  308. k=i[j].split(",")
  309. k[0]=round(float(k[0]),0)
  310. k[1]=round(float(k[1]),2)
  311. k[2]=round(float(k[2]),4)
  312. di[j]= dict(zip(['act_user','act_cost_per_cost','act_rate'],k))
  313. else:
  314. di[j]=i[j]
  315. li.append(di)
  316. return li
  317. def get_channel_order_trend(channel,start,end):
  318. a=[{
  319. 'date': '2020-12-01',
  320. 'channel': '宝珠书屋',
  321. 'book': '魏汝稳',
  322. 'cost': 234.11,
  323. 'reg_amount': 123.11,
  324. 'roi': 0.45,
  325. 'new_follow_user': 11,
  326. 'new_follow_per_cost': 234.11,
  327. 'order_user': 222,
  328. 'order_count': 12312,
  329. 'order_user_per_cost': 123.11,
  330. 'd1':{
  331. 'order':232.11,
  332. 'roi':0.2341,
  333. 'add':0.4511,
  334. 'mult':1.12},
  335. 'd2': {
  336. 'order': 232.11,
  337. 'roi': 0.2341,
  338. 'add': 0.4511,
  339. 'mult': 1.12},
  340. 'd3': {
  341. 'order': 232.11,
  342. 'roi': 0.2341,
  343. 'add': 0.4511,
  344. 'mult': 1.12},
  345. }]
  346. return a
  347. def get_channel_summary(channel,pitcher,page,page_size,order_by,order):
  348. sql = """select a.channel,state,'朋友圈' location,toString(start) start,toString(end) end,total_cost,total_amount,
  349. profit,roi,follow_user,follow_per_cost,order_user,
  350. if(follow_user=0,0,order_user/follow_user) order_tran_rate,if(order_user=0,0,total_cost/order_user) order_tran_cost
  351. from
  352. (
  353. select channel,if(max(dt)>subtractDays(today(),10),'在投','停投') state,
  354. min(dt) start,max(dt) end
  355. from dw_daily_channel_cost where cost>0 {} group by channel) a
  356. left outer join(
  357. select channel,sum(follow_user) follow_user,
  358. if(follow_user=0,0,sum(cost)/follow_user) follow_per_cost
  359. from dw_daily_channel group by channel) b on a.channel=b.channel
  360. left outer join(
  361. select sum(reg_order_user) order_user,channel from dw_daily_channel where dt=subtractDays(today(),1) group by channel) c on a.channel=c.channel
  362. left outer join (
  363. select total_cost,
  364. total_amount,
  365. channel,
  366. total_amount-total_cost profit,
  367. if(total_cost=0,0,total_amount/total_cost) roi
  368. from dw_channel_daily_total where dt=subtractDays(today(),1)) d on a.channel=d.channel
  369. where 1=1 """
  370. if pitcher!='':
  371. sql=sql.format(f" and pitcher='{pitcher}'")
  372. else:
  373. sql=sql.format('')
  374. if channel!='':
  375. sql+=f" and channel='{channel}'"
  376. sql+=f' order by {order_by} {order} limit {page},{page_size} '
  377. print(sql)
  378. key=['channel','state','location','start','end','total_cost','total_amount','profit','roi',
  379. 'follow_user','follow_per_cost','order_user','order_tran_rate','order_tran_cost']
  380. return get_dict_list(key,get_round(ck.execute(sql)))
  381. if __name__ == '__main__':
  382. # a=get_channel_overview('','','',1,10,'date','desc')
  383. # a=get_channel_summary('','')
  384. # a=get_channel_again_order_trend('玉龙书社','2020-09-19')
  385. a=get_channel_active('玉龙书社','2020-09-15','2020-09-20',1,10,'date','desc')
  386. print(a)