pitcher_panel.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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_channel_belong_pitcher(channel):
  10. """根据公众号获取投手"""
  11. sql = f"select pitcher,channel from dw_daily_channel_cost where dt='{du.get_n_days(-1)}' and pitcher!='' and channel!=''"
  12. data=ck.execute(sql)
  13. di={}
  14. for i in data:
  15. di[i[1]]=i[0]
  16. return di.get(channel,'')
  17. def get_pitcher_panel_channel(pitcher,channel,start,end,page,page_size,order_by,order):
  18. sql=f"""select channel,stage,platform,book,
  19. formatDateTime(dt,'%Y-%m-%d') as date,
  20. cost,
  21. first_order_amount,
  22. toDecimal32(if(cost=0,0,first_order_amount/cost),4) first_roi,
  23. first_order_user,first_order_count,
  24. toDecimal32(if(first_order_user=0,0,cost/first_order_user),2) first_per_cost,
  25. view_count,click_count,follow_user,
  26. toDecimal32(if(click_count=0,0,follow_user/click_count),4) follow_rate,
  27. toDecimal32(if(follow_user=0,0,cost/follow_user),2) follow_per_cost,
  28. total_cost,
  29. toDecimal32(if(total_cost=0,0,total_amount/total_cost),2) back_rate
  30. from dw_daily_channel where dt>='{start}' and dt<='{end}' """
  31. if pitcher!='all':
  32. sql += f" and pitcher='{pitcher}' "
  33. if channel!='':
  34. sql += f" and channel='{channel}' "
  35. total = ck.execute(f"select count(1) from ({sql}) a")[0][0]
  36. sql += f" order by {order_by} {order} limit {(page-1)*page_size},{page_size} "
  37. print(sql)
  38. data=ck.execute(sql)
  39. key=['channel','stage','platform','book','date','cost','first_order_amount','first_roi','first_order_user',
  40. 'first_order_count','first_per_cost','view_count','click_count','follow_user','follow_rate','follow_per_cost',
  41. 'total_cost','back_rate']
  42. return get_dict_list(key,get_round(data)),total
  43. def get_pitcher_panel_daily(pitcher, start, end, page, page_size, order_by, order):
  44. sql=f"""
  45. select formatDateTime(dt,'%Y-%m-%d') date ,pitcher,
  46. round(sum(cost),2) cost,
  47. round(sum(first_order_amount),2) first_order_amount,
  48. round(if(cost=0,0,first_order_amount/cost),4) first_roi ,
  49. round(sum(order_amount),2) order_amount,
  50. round(if(cost=0,0,sum(reg_order_amount)/cost),4) today_roi,
  51. round(sum(total_cost),2) total_cost,
  52. round(sum(total_amount),2) total_amount,
  53. round(total_amount-total_cost,2) total_profit,
  54. round(if(total_cost=0,0,total_amount/total_cost),4) total_roi
  55. from dw_daily_channel where dt>='{start}' and dt<='{end}' """
  56. if pitcher != '':
  57. sql += f" and pitcher='{pitcher}' "
  58. sql+=f" group by date,pitcher"
  59. total = ck.execute(f"select count(1) from ({sql}) a")[0][0]
  60. sql += f" order by {order_by} {order} limit {(page-1)*page_size},{page_size} "
  61. print(sql)
  62. data = ck.execute(sql)
  63. key=['date','pitcher','cost','first_order_amount','first_roi','order_amount','today_roi','total_cost','total_amount','total_profit','total_roi']
  64. return get_dict_list(key,data),total
  65. def get_pitcher_panel_overview(pitcher):
  66. sql=f"""select pitcher,
  67. cost cost,
  68. amount amount,
  69. roi roi,
  70. channel_count,on_channel_count,
  71. off_channel_count,
  72. this_month_cost this_month_cost,
  73. this_month_amount this_month_amount,
  74. this_month_roi this_month_roi,
  75. last_month_cost last_month_cost,
  76. last_month_amount last_month_amount,
  77. last_month_roi last_month_roi,
  78. last_month_far_amount last_month_far_amount,
  79. follow_user,
  80. last_month_far_roi last_month_far_roi
  81. from dm_pitcher_daily_page_total where dt='{du.get_n_days(-1)}'"""
  82. if pitcher != 'all':
  83. sql += f" and pitcher='{pitcher}' "
  84. print(sql)
  85. data=ck.execute(sql)
  86. print(data)
  87. key=['pitcher','cost','amount','roi','channel_count','on_channel_count','off_channel_count','this_month_cost','this_month_amount','this_month_roi',
  88. 'last_month_cost','last_month_amount','last_month_roi','last_month_far_amount','follow_user','last_month_far_roi']
  89. return get_dict_list(key,get_round(data))
  90. def get_channel_overview(channel,pitcher,start,end,page,page_size,order_by,order):
  91. sql="""select channel,toString(dt) date,
  92. view_count,click_count,
  93. round(if(view_count=0,0,click_count/view_count),4) click_rate,
  94. follow_user,
  95. round(if(click_count=0,0,follow_user/click_count),4) follow_rate,
  96. round(if(follow_user=0,0,cost/follow_user),2) follow_per_cost,
  97. round(if(click_count=0,0,first_order_count/click_count),4) order_rate,
  98. round(if(first_order_user=0,0,cost/first_order_user),2) order_per_cost,
  99. round(cost,2) cost,
  100. first_order_count,first_order_user,
  101. round(first_order_amount,2) first_order_amount,order_count,order_user,
  102. round(order_amount,2) order_amount,
  103. round(order_amount-first_order_amount,2) old_order_amount,
  104. round(if(first_order_user=0,0,first_order_amount/first_order_user),2) first_amount_per_user,
  105. round(if(follow_user=0,0,first_order_amount/follow_user),2) amount_per_follow,
  106. round(if(first_order_user=0,0,cost/first_order_user),2) first_cost_per_user,
  107. round(if(follow_user=0,0,first_order_user/follow_user),4) new_user_order_rate,
  108. round(reg_order_amount,2) reg_user_amount,
  109. round(total_cost,2) total_cost,
  110. round(total_amount,2) total_amount,
  111. round(if(cost=0,0,first_order_amount/cost),4) day_roi,
  112. round(if(cost=0,0,reg_order_amount/cost),4) all_roi,
  113. 0 avg_new_order_rate,
  114. 0 old_user_once_order_rate from dw_daily_channel where 1=1 """
  115. if channel!='':
  116. sql+=f" and channel='{channel}'"
  117. if start!='':
  118. sql+=f" and start>='{start}'"
  119. if end!='':
  120. sql+=f" and end<='{end}'"
  121. if pitcher!='':
  122. sql+=f" and pitcher='{pitcher}'"
  123. total = ck.execute(f"select count(1) from ({sql}) a")[0][0]
  124. sql += f" order by {order_by} {order} limit {(page-1)*page_size},{page_size} "
  125. print(sql)
  126. key=['channel','date','view_count','click_count','click_rate','follow_user','follow_rate','follow_per_cost','order_rate','order_per_cost','cost',
  127. 'first_order_count','first_order_user','first_order_amount','order_count','order_user','order_amount','old_order_amount','first_amount_per_user','amount_per_follow','first_cost_per_user'
  128. 'new_user_order_rate','reg_user_amount','total_cost','total_amount','day_roi','all_roi','avg_new_order_rate','old_user_once_order_rate']
  129. return get_dict_list(key,get_round(ck.execute(sql))),total
  130. def get_channel_again_order_trend(channel,date,pitcher):
  131. # if get_channel_belong_pitcher(channel)!=pitcher:
  132. # return []
  133. sql=f"""select toString(dt) date,
  134. channel,book,
  135. round(cost,2) cost,
  136. round(reg_order_amount,2) reg_amount,
  137. round(if(cost=0,0,reg_order_amount/cost),4) roi,
  138. follow_user new_follow,
  139. round(if(follow_user=0,0,cost/follow_user),2) new_follow_per_cost,
  140. reg_order_count reg_count,reg_order_user reg_user,
  141. round(if(reg_order_user=0,0,cost/reg_order_user),2) cost_per_user,
  142. round(if(reg_order_user=0,0,reg_order_amount/reg_order_user),2) avg_order_amount,
  143. round(if(reg_order_user=0,0,reg_order_user_again/reg_order_user),4) avg_again_order_rate,
  144. order_count
  145. from dw_daily_channel where channel='{channel}' and dt='{date}'
  146. """
  147. # print(sql)
  148. data=ck.execute(sql)
  149. # print(data)
  150. key1=['date','channel','book','cost','reg_amount','roi','new_follow','new_follow_per_cost',
  151. 'reg_count','reg_user','cost_per_user','avg_order_amount','avg_again_order_rate','order_count']
  152. json1=get_dict_list(key1,get_round(data))[0]
  153. # print(json1)
  154. sql2=f"""select
  155. dateDiff(day,toDate('{date}'),date)+1 ddf,
  156. count(1) c1,
  157. sum(if(count>1,1,0)) c2,
  158. sum(if(count>2,1,0)) c3,
  159. sum(if(count>3,1,0)) c4,
  160. sum(if(count>4,1,0)) c5,
  161. sum(if(count>5,1,0)) c6
  162. from (
  163. select count(1) count,date
  164. from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),6)
  165. and formatDateTime(reg_time,'%Y-%m-%d')='{date}' group by user_id,date
  166. ) a group by date"""
  167. df=ck.execute(sql2)
  168. print(df)
  169. # 补全
  170. xx=[i[0] for i in df]
  171. for i in range(1,8):
  172. if i not in xx:
  173. df.append((i,0,0,0,0,0,0))
  174. # 排序
  175. import operator
  176. df.sort(key=operator.itemgetter(0))
  177. print(df)
  178. reg_user=json1["reg_user"]
  179. li=[]
  180. for i in range(1,6):
  181. print(i)
  182. d = {}
  183. d["user_order_count"] = i
  184. d1={}
  185. d1["origin"]=df[0][i]
  186. d1["new"]=0
  187. d1["move"]=df[0][i+1]
  188. d1["now"]=d1["origin"]+d1['new']-d1["move"]
  189. d1["follow_order_rate"]=round(d1["now"]/reg_user,2) if reg_user!=0 else 0
  190. d['d1'] = d1
  191. d2={}
  192. d2["origin"] = d1["now"]
  193. d2["new"] = df[1][i]
  194. d2["move"] = df[1][i+1]
  195. d2["now"] = d2["origin"] +d2['new']- d2["move"]
  196. d2["follow_order_rate"] = round(d2["now"] / reg_user, 2) if reg_user!=0 else 0
  197. d['d2'] = d2
  198. d3={}
  199. d3["origin"] = d2["now"]
  200. d3["new"] = df[2][i]
  201. d3["move"] =df[2][i+1]
  202. d3["now"] = d3["origin"] +d3['new']- d3["move"]
  203. d3["follow_order_rate"] = round(d3["now"] / reg_user, 2) if reg_user!=0 else 0
  204. d['d3'] = d3
  205. d4={}
  206. d4["origin"] = d3["now"]
  207. d4["new"] = df[3][i]
  208. d4["move"] = df[3][i+1]
  209. d4["now"] = d4["origin"] +d4['new']- d4["move"]
  210. d4["follow_order_rate"] = round(d4["now"] / reg_user, 2) if reg_user!=0 else 0
  211. d['d4'] = d4
  212. d5={}
  213. d5["origin"] = d4["now"]
  214. d5["new"] = df[4][i]
  215. d5["move"] = df[4][i+1]
  216. d5["now"] = d5["origin"] +d5['new']- d5["move"]
  217. d5["follow_order_rate"] = round(d4["now"] / reg_user, 2) if reg_user!=0 else 0
  218. d['d5'] = d5
  219. d6 = {}
  220. d6["origin"] = d5["now"]
  221. d6["new"] = df[5][i]
  222. d6["move"] = df[5][i+1]
  223. d6["now"] = d6["origin"] +d6['new']- d6["move"]
  224. d6["follow_order_rate"] = round(d6["now"] / reg_user, 2) if reg_user!=0 else 0
  225. d['d6'] = d6
  226. d7 = {}
  227. d7["origin"] = d6["now"]
  228. d7["new"] = df[6][i]
  229. d7["move"] = df[6][i+1]
  230. d7["now"] = d7["origin"] +d7['new']- d7["move"]
  231. d7["follow_order_rate"] = round(d7["now"] / reg_user, 2) if reg_user!=0 else 0
  232. d['d7'] = d7
  233. li.append(d)
  234. print(li)
  235. json1['data']=li
  236. print([json1])
  237. return [json1]
  238. def get_channel_active(channel,pitcher,start,end,page,page_size,order_by,order):
  239. if get_channel_belong_pitcher(channel)!=pitcher:
  240. return [],0
  241. 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,
  242. order_user_per_cost,day7_avg_act_rate,day7_avg_act_per_cost,day30_avg_act_rate,ay30_avg_act_cost,
  243. act_per_cost,
  244. concat(toString(reg_order_user1),',',toString(if(reg_order_user1=0,0,cost/reg_order_user1)),',',toString(if(order_user=0,0,reg_order_user1/order_user))),
  245. concat(toString(reg_order_user2-reg_order_user1),',',toString(if(reg_order_user2=0,0,cost/reg_order_user2)),',',toString(if(order_user=0,0,(reg_order_user2-reg_order_user1)/order_user))),
  246. concat(toString(reg_order_user3-reg_order_user2),',',toString(if(reg_order_user3=0,0,cost/reg_order_user3)),',',toString(if(order_user=0,0,(reg_order_user3-reg_order_user2)/order_user))),
  247. concat(toString(reg_order_user4-reg_order_user3),',',toString(if(reg_order_user4=0,0,cost/reg_order_user4)),',',toString(if(order_user=0,0,(reg_order_user4-reg_order_user3)/order_user))),
  248. concat(toString(reg_order_user5-reg_order_user4),',',toString(if(reg_order_user5=0,0,cost/reg_order_user5)),',',toString(if(order_user=0,0,(reg_order_user5-reg_order_user4)/order_user))),
  249. concat(toString(reg_order_user6-reg_order_user5),',',toString(if(reg_order_user6=0,0,cost/reg_order_user6)),',',toString(if(order_user=0,0,(reg_order_user6-reg_order_user5)/order_user))),
  250. concat(toString(reg_order_user7-reg_order_user6),',',toString(if(reg_order_user7=0,0,cost/reg_order_user7)),',',toString(if(order_user=0,0,(reg_order_user7-reg_order_user6)/order_user))),
  251. concat(toString(reg_order_user8-reg_order_user7),',',toString(if(reg_order_user8=0,0,cost/reg_order_user8)),',',toString(if(order_user=0,0,(reg_order_user8-reg_order_user7)/order_user))),
  252. concat(toString(reg_order_user9-reg_order_user8),',',toString(if(reg_order_user9=0,0,cost/reg_order_user9)),',',toString(if(order_user=0,0,(reg_order_user9-reg_order_user8)/order_user))),
  253. concat(toString(reg_order_user10-reg_order_user9),',',toString(if(reg_order_user10=0,0,cost/reg_order_user10)),',',toString(if(order_user=0,0,(reg_order_user10-reg_order_user9)/order_user))),
  254. concat(toString(reg_order_user11-reg_order_user10),',',toString(if(reg_order_user11=0,0,cost/reg_order_user11)),',',toString(if(order_user=0,0,(reg_order_user11-reg_order_user10)/order_user))),
  255. concat(toString(reg_order_user12-reg_order_user11),',',toString(if(reg_order_user12=0,0,cost/reg_order_user12)),',',toString(if(order_user=0,0,(reg_order_user12-reg_order_user11)/order_user))),
  256. concat(toString(reg_order_user13-reg_order_user12),',',toString(if(reg_order_user13=0,0,cost/reg_order_user13)),',',toString(if(order_user=0,0,(reg_order_user13-reg_order_user12)/order_user))),
  257. concat(toString(reg_order_user14-reg_order_user13),',',toString(if(reg_order_user14=0,0,cost/reg_order_user14)),',',toString(if(order_user=0,0,(reg_order_user14-reg_order_user13)/order_user))),
  258. concat(toString(reg_order_user15-reg_order_user14),',',toString(if(reg_order_user15=0,0,cost/reg_order_user15)),',',toString(if(order_user=0,0,(reg_order_user15-reg_order_user14)/order_user))),
  259. concat(toString(reg_order_user16-reg_order_user15),',',toString(if(reg_order_user16=0,0,cost/reg_order_user16)),',',toString(if(order_user=0,0,(reg_order_user16-reg_order_user15)/order_user))),
  260. concat(toString(reg_order_user17-reg_order_user16),',',toString(if(reg_order_user17=0,0,cost/reg_order_user17)),',',toString(if(order_user=0,0,(reg_order_user17-reg_order_user16)/order_user))),
  261. concat(toString(reg_order_user18-reg_order_user17),',',toString(if(reg_order_user18=0,0,cost/reg_order_user18)),',',toString(if(order_user=0,0,(reg_order_user18-reg_order_user17)/order_user))),
  262. concat(toString(reg_order_user19-reg_order_user18),',',toString(if(reg_order_user19=0,0,cost/reg_order_user19)),',',toString(if(order_user=0,0,(reg_order_user19-reg_order_user18)/order_user))),
  263. concat(toString(reg_order_user20-reg_order_user19),',',toString(if(reg_order_user20=0,0,cost/reg_order_user20)),',',toString(if(order_user=0,0,(reg_order_user20-reg_order_user19)/order_user))),
  264. concat(toString(reg_order_user21-reg_order_user20),',',toString(if(reg_order_user21=0,0,cost/reg_order_user21)),',',toString(if(order_user=0,0,(reg_order_user21-reg_order_user20)/order_user))),
  265. concat(toString(reg_order_user22-reg_order_user21),',',toString(if(reg_order_user22=0,0,cost/reg_order_user22)),',',toString(if(order_user=0,0,(reg_order_user22-reg_order_user21)/order_user))),
  266. concat(toString(reg_order_user23-reg_order_user22),',',toString(if(reg_order_user23=0,0,cost/reg_order_user23)),',',toString(if(order_user=0,0,(reg_order_user23-reg_order_user22)/order_user))),
  267. concat(toString(reg_order_user24-reg_order_user23),',',toString(if(reg_order_user24=0,0,cost/reg_order_user24)),',',toString(if(order_user=0,0,(reg_order_user24-reg_order_user23)/order_user))),
  268. concat(toString(reg_order_user25-reg_order_user24),',',toString(if(reg_order_user25=0,0,cost/reg_order_user25)),',',toString(if(order_user=0,0,(reg_order_user25-reg_order_user24)/order_user))),
  269. concat(toString(reg_order_user26-reg_order_user25),',',toString(if(reg_order_user26=0,0,cost/reg_order_user26)),',',toString(if(order_user=0,0,(reg_order_user26-reg_order_user25)/order_user))),
  270. concat(toString(reg_order_user27-reg_order_user26),',',toString(if(reg_order_user27=0,0,cost/reg_order_user27)),',',toString(if(order_user=0,0,(reg_order_user27-reg_order_user26)/order_user))),
  271. concat(toString(reg_order_user28-reg_order_user27),',',toString(if(reg_order_user28=0,0,cost/reg_order_user28)),',',toString(if(order_user=0,0,(reg_order_user28-reg_order_user27)/order_user))),
  272. concat(toString(reg_order_user29-reg_order_user28),',',toString(if(reg_order_user29=0,0,cost/reg_order_user29)),',',toString(if(order_user=0,0,(reg_order_user29-reg_order_user28)/order_user))),
  273. concat(toString(reg_order_user30-reg_order_user29),',',toString(if(reg_order_user30=0,0,cost/reg_order_user30)),',',toString(if(order_user=0,0,(reg_order_user30-reg_order_user29)/order_user)))
  274. from (
  275. select dt,book,cost,
  276. reg_order_amount reg_amount,
  277. if(cost=0,0,reg_order_amount/cost) roi,
  278. follow_user new_follow_user,
  279. if(follow_user=0,0,cost/follow_user) new_follow_per_cost,
  280. reg_order_user order_user,
  281. reg_order_count order_count,
  282. if(reg_order_user=0,0,cost/reg_order_user) order_user_per_cost,
  283. if(follow_user=0,0,reg_order_user7/follow_user) day7_avg_act_rate ,
  284. if(reg_order_user7=0,0,cost/reg_order_user7) day7_avg_act_per_cost,
  285. if(follow_user=0,0,reg_order_user30/follow_user) day30_avg_act_rate,
  286. if(reg_order_user30=0,0,cost/reg_order_user30) ay30_avg_act_cost,
  287. if(reg_order_user=0,0,cost/reg_order_user) act_per_cost
  288. from dw_daily_channel where channel='{channel}' and dt>='{start}' and dt<='{end}') a
  289. left outer join (
  290. select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,
  291. count(distinct if(subtractDays(date, 1)>=reg_time,NULL,user_id)) reg_order_user1,
  292. count(distinct if(subtractDays(date, 2)>=reg_time,NULL,user_id)) reg_order_user2,
  293. count(distinct if(subtractDays(date, 3)>=reg_time,NULL,user_id)) reg_order_user3,
  294. count(distinct if(subtractDays(date, 4)>=reg_time,NULL,user_id)) reg_order_user4,
  295. count(distinct if(subtractDays(date, 5)>=reg_time,NULL,user_id)) reg_order_user5,
  296. count(distinct if(subtractDays(date, 6)>=reg_time,NULL,user_id)) reg_order_user6,
  297. count(distinct if(subtractDays(date, 7)>=reg_time,NULL,user_id)) reg_order_user7,
  298. count(distinct if(subtractDays(date, 8)>=reg_time,NULL,user_id)) reg_order_user8,
  299. count(distinct if(subtractDays(date, 9)>=reg_time,NULL,user_id)) reg_order_user9,
  300. count(distinct if(subtractDays(date, 10)>=reg_time,NULL,user_id)) reg_order_user10,
  301. count(distinct if(subtractDays(date, 11)>=reg_time,NULL,user_id)) reg_order_user11,
  302. count(distinct if(subtractDays(date, 12)>=reg_time,NULL,user_id)) reg_order_user12,
  303. count(distinct if(subtractDays(date, 13)>=reg_time,NULL,user_id)) reg_order_user13,
  304. count(distinct if(subtractDays(date, 14)>=reg_time,NULL,user_id)) reg_order_user14,
  305. count(distinct if(subtractDays(date, 15)>=reg_time,NULL,user_id)) reg_order_user15,
  306. count(distinct if(subtractDays(date, 16)>=reg_time,NULL,user_id)) reg_order_user16,
  307. count(distinct if(subtractDays(date, 17)>=reg_time,NULL,user_id)) reg_order_user17,
  308. count(distinct if(subtractDays(date, 18)>=reg_time,NULL,user_id)) reg_order_user18,
  309. count(distinct if(subtractDays(date, 19)>=reg_time,NULL,user_id)) reg_order_user19,
  310. count(distinct if(subtractDays(date, 20)>=reg_time,NULL,user_id)) reg_order_user20,
  311. count(distinct if(subtractDays(date, 21)>=reg_time,NULL,user_id)) reg_order_user21,
  312. count(distinct if(subtractDays(date, 22)>=reg_time,NULL,user_id)) reg_order_user22,
  313. count(distinct if(subtractDays(date, 23)>=reg_time,NULL,user_id)) reg_order_user23,
  314. count(distinct if(subtractDays(date, 24)>=reg_time,NULL,user_id)) reg_order_user24,
  315. count(distinct if(subtractDays(date, 25)>=reg_time,NULL,user_id)) reg_order_user25,
  316. count(distinct if(subtractDays(date, 26)>=reg_time,NULL,user_id)) reg_order_user26,
  317. count(distinct if(subtractDays(date, 27)>=reg_time,NULL,user_id)) reg_order_user27,
  318. count(distinct if(subtractDays(date, 28)>=reg_time,NULL,user_id)) reg_order_user28,
  319. count(distinct if(subtractDays(date, 29)>=reg_time,NULL,user_id)) reg_order_user29,
  320. count(distinct if(subtractDays(date, 30)>=reg_time,NULL,user_id)) reg_order_user30
  321. from order where channel='{channel}' and dt>='{start}' group by formatDateTime(reg_time,'%Y-%m-%d')) b on a.dt=b.dt
  322. """
  323. total = ck.execute(f"select count(1) from ({sql}) a")[0][0]
  324. sql+=f" order by {order_by} {order} limit {(page-1)*page_size},{page_size} "
  325. data = ck.execute(sql)
  326. print(sql)
  327. print(data)
  328. key=['date','channel','book','cost','reg_amount','roi','new_follow_user','new_follow_per_cost','order_user','order_count','order_user_per_cost',
  329. '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',
  330. 'd11','d12','d13','d14','d15','d16','d17','d18','d19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30']
  331. x=get_dict_list(key,get_round(data))
  332. print(x)
  333. li=[]
  334. for i in x:
  335. di = {}
  336. for j in i:
  337. if j in ['d1','d2','d3','d4','d5','d6','d7','d8','d9','d10',
  338. 'd11','d12','d13','d14','d15','d16','d17','d18','d19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30']:
  339. if i[j]:
  340. k=i[j].split(",")
  341. k[0]=round(float(k[0]),0)
  342. k[1]=round(float(k[1]),2)
  343. k[2]=round(float(k[2]),4)
  344. else:
  345. k=[0,0,0]
  346. di[j] = dict(zip(['act_user', 'act_cost_per_cost', 'act_rate'], k))
  347. else:
  348. di[j]=i[j]
  349. li.append(di)
  350. return li,total
  351. def get_channel_order_trend(channel,pitcher,start,end,page,page_size,order_by,order):
  352. if get_channel_belong_pitcher(channel)!=pitcher:
  353. return [],0
  354. sql=f"""select '{channel}' channel,toString(dt) date,book,cost,reg_order_amount,roi,new_follow_user,new_follow_per_cost,order_user,order_count,
  355. order_user_per_cost,
  356. concat(toString(r1),',',toString(r1/cost),',', toString(a1/cost),',',toString(b1)),
  357. concat(toString(a2),',',toString(r2/cost),',', toString(a2/cost),',',toString(b2)),
  358. concat(toString(a3),',',toString(r3/cost),',', toString(a3/cost),',',toString(b3)),
  359. concat(toString(a4),',',toString(r4/cost),',', toString(a4/cost),',',toString(b4)),
  360. concat(toString(a5),',',toString(r5/cost),',', toString(a5/cost),',',toString(b5)),
  361. concat(toString(a6),',',toString(r6/cost),',', toString(a6/cost),',',toString(b6)),
  362. concat(toString(a7),',',toString(r7/cost),',', toString(a7/cost),',',toString(b7)),
  363. concat(toString(a8),',',toString(r8/cost),',', toString(a8/cost),',',toString(b8)),
  364. concat(toString(a9),',',toString(r9/cost),',', toString(a9/cost),',',toString(b9)),
  365. concat(toString(a10),',',toString(r10/cost),',', toString(a10/cost),',',toString(b10)),
  366. concat(toString(a11),',',toString(r11/cost),',', toString(a11/cost),',',toString(b11)),
  367. concat(toString(a12),',',toString(r12/cost),',', toString(a12/cost),',',toString(b12)),
  368. concat(toString(a13),',',toString(r13/cost),',', toString(a13/cost),',',toString(b13)),
  369. concat(toString(a14),',',toString(r14/cost),',', toString(a14/cost),',',toString(b14)),
  370. concat(toString(a15),',',toString(r15/cost),',', toString(a15/cost),',',toString(b15)),
  371. concat(toString(a16),',',toString(r16/cost),',', toString(a16/cost),',',toString(b16)),
  372. concat(toString(a17),',',toString(r17/cost),',', toString(a17/cost),',',toString(b17)),
  373. concat(toString(a18),',',toString(r18/cost),',', toString(a18/cost),',',toString(b18)),
  374. concat(toString(a19),',',toString(r19/cost),',', toString(a19/cost),',',toString(b19)),
  375. concat(toString(a20),',',toString(r20/cost),',', toString(a20/cost),',',toString(b20)),
  376. concat(toString(a21),',',toString(r21/cost),',', toString(a21/cost),',',toString(b21)),
  377. concat(toString(a22),',',toString(r22/cost),',', toString(a22/cost),',',toString(b22)),
  378. concat(toString(a23),',',toString(r23/cost),',', toString(a23/cost),',',toString(b23)),
  379. concat(toString(a24),',',toString(r24/cost),',', toString(a24/cost),',',toString(b24)),
  380. concat(toString(a25),',',toString(r25/cost),',', toString(a25/cost),',',toString(b25)),
  381. concat(toString(a26),',',toString(r26/cost),',', toString(a26/cost),',',toString(b26)),
  382. concat(toString(a27),',',toString(r27/cost),',', toString(a27/cost),',',toString(b27)),
  383. concat(toString(a28),',',toString(r28/cost),',', toString(a28/cost),',',toString(b28)),
  384. concat(toString(a29),',',toString(r29/cost),',', toString(a29/cost),',',toString(b29)),
  385. concat(toString(a30),',',toString(r30/cost),',', toString(a30/cost),',',toString(b30)),
  386. concat(toString(a31),',',toString(r31/cost),',', toString(a31/cost),',',toString(b31)),
  387. concat(toString(a32),',',toString(r32/cost),',', toString(a32/cost),',',toString(b32)),
  388. concat(toString(a33),',',toString(r33/cost),',', toString(a33/cost),',',toString(b33)),
  389. concat(toString(a34),',',toString(r34/cost),',', toString(a34/cost),',',toString(b34)),
  390. concat(toString(a35),',',toString(r35/cost),',', toString(a35/cost),',',toString(b35)),
  391. concat(toString(a36),',',toString(r36/cost),',', toString(a36/cost),',',toString(b36)),
  392. concat(toString(a37),',',toString(r37/cost),',', toString(a37/cost),',',toString(b37)),
  393. concat(toString(a38),',',toString(r38/cost),',', toString(a38/cost),',',toString(b38)),
  394. concat(toString(a39),',',toString(r39/cost),',', toString(a39/cost),',',toString(b39)),
  395. concat(toString(a40),',',toString(r40/cost),',', toString(a40/cost),',',toString(b40)),
  396. concat(toString(a41),',',toString(r41/cost),',', toString(a41/cost),',',toString(b41)),
  397. concat(toString(a42),',',toString(r42/cost),',', toString(a42/cost),',',toString(b42)),
  398. concat(toString(a43),',',toString(r43/cost),',', toString(a43/cost),',',toString(b43)),
  399. concat(toString(a44),',',toString(r44/cost),',', toString(a44/cost),',',toString(b44)),
  400. concat(toString(a45),',',toString(r45/cost),',', toString(a45/cost),',',toString(b45)),
  401. concat(toString(a46),',',toString(r46/cost),',', toString(a46/cost),',',toString(b46)),
  402. concat(toString(a47),',',toString(r47/cost),',', toString(a47/cost),',',toString(b47)),
  403. concat(toString(a48),',',toString(r48/cost),',', toString(a48/cost),',',toString(b48)),
  404. concat(toString(a49),',',toString(r49/cost),',', toString(a49/cost),',',toString(b49)),
  405. concat(toString(a50),',',toString(r50/cost),',', toString(a50/cost),',',toString(b50)),
  406. concat(toString(a51),',',toString(r51/cost),',', toString(a51/cost),',',toString(b51)),
  407. concat(toString(a52),',',toString(r52/cost),',', toString(a52/cost),',',toString(b52)),
  408. concat(toString(a53),',',toString(r53/cost),',', toString(a53/cost),',',toString(b53)),
  409. concat(toString(a54),',',toString(r54/cost),',', toString(a54/cost),',',toString(b54)),
  410. concat(toString(a55),',',toString(r55/cost),',', toString(a55/cost),',',toString(b55)),
  411. concat(toString(a56),',',toString(r56/cost),',', toString(a56/cost),',',toString(b56)),
  412. concat(toString(a57),',',toString(r57/cost),',', toString(a57/cost),',',toString(b57)),
  413. concat(toString(a58),',',toString(r58/cost),',', toString(a58/cost),',',toString(b58)),
  414. concat(toString(a59),',',toString(r59/cost),',', toString(a59/cost),',',toString(b59)),
  415. concat(toString(a60),',',toString(r60/cost),',', toString(a60/cost),',',toString(b60)),
  416. concat(toString(a90),',',toString(r90/cost),',', toString(a90/cost),',',toString(b90)),
  417. concat(toString(a120),',',toString(r120/cost),',', toString(a120/cost),',',toString(b120)),
  418. concat(toString(a150),',',toString(r150/cost),',', toString(a150/cost),',',toString(b150))
  419. from
  420. (
  421. select dt,book,cost,reg_order_amount,
  422. if(cost=0,0,reg_order_amount/cost) roi,
  423. follow_user new_follow_user,
  424. if(follow_user=0,0,cost/follow_user) new_follow_per_cost,
  425. reg_order_user order_user, reg_order_count order_count,
  426. if(reg_order_user=0,0,cost/reg_order_user) order_user_per_cost
  427. from dw_daily_channel where dt>='{start}' and dt<='{end}' and channel='{channel}' and cost>0) a
  428. left outer join (
  429. select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,
  430. sum(if(subtractDays(date, 1)>=reg_time,0,amount)) as r1,
  431. sum(if(subtractDays(date, 2)>=reg_time,0,amount)) as r2,
  432. sum(if(subtractDays(date, 3)>=reg_time,0,amount)) as r3,
  433. sum(if(subtractDays(date, 4)>=reg_time,0,amount)) as r4,
  434. sum(if(subtractDays(date, 5)>=reg_time,0,amount)) as r5,
  435. sum(if(subtractDays(date, 6)>=reg_time,0,amount)) as r6,
  436. sum(if(subtractDays(date, 7)>=reg_time,0,amount)) as r7,
  437. sum(if(subtractDays(date, 8)>=reg_time,0,amount)) as r8,
  438. sum(if(subtractDays(date, 9)>=reg_time,0,amount)) as r9,
  439. sum(if(subtractDays(date, 10)>=reg_time,0,amount)) as r10,
  440. sum(if(subtractDays(date, 11)>=reg_time,0,amount)) as r11,
  441. sum(if(subtractDays(date, 12)>=reg_time,0,amount)) as r12,
  442. sum(if(subtractDays(date, 13)>=reg_time,0,amount)) as r13,
  443. sum(if(subtractDays(date, 14)>=reg_time,0,amount)) as r14,
  444. sum(if(subtractDays(date, 15)>=reg_time,0,amount)) as r15,
  445. sum(if(subtractDays(date, 16)>=reg_time,0,amount)) as r16,
  446. sum(if(subtractDays(date, 17)>=reg_time,0,amount)) as r17,
  447. sum(if(subtractDays(date, 18)>=reg_time,0,amount)) as r18,
  448. sum(if(subtractDays(date, 19)>=reg_time,0,amount)) as r19,
  449. sum(if(subtractDays(date, 20)>=reg_time,0,amount)) as r20,
  450. sum(if(subtractDays(date, 21)>=reg_time,0,amount)) as r21,
  451. sum(if(subtractDays(date, 22)>=reg_time,0,amount)) as r22,
  452. sum(if(subtractDays(date, 23)>=reg_time,0,amount)) as r23,
  453. sum(if(subtractDays(date, 24)>=reg_time,0,amount)) as r24,
  454. sum(if(subtractDays(date, 25)>=reg_time,0,amount)) as r25,
  455. sum(if(subtractDays(date, 26)>=reg_time,0,amount)) as r26,
  456. sum(if(subtractDays(date, 27)>=reg_time,0,amount)) as r27,
  457. sum(if(subtractDays(date, 28)>=reg_time,0,amount)) as r28,
  458. sum(if(subtractDays(date, 29)>=reg_time,0,amount)) as r29,
  459. sum(if(subtractDays(date, 30)>=reg_time,0,amount)) as r30,
  460. sum(if(subtractDays(date, 31)>=reg_time,0,amount)) as r31,
  461. sum(if(subtractDays(date, 32)>=reg_time,0,amount)) as r32,
  462. sum(if(subtractDays(date, 33)>=reg_time,0,amount)) as r33,
  463. sum(if(subtractDays(date, 34)>=reg_time,0,amount)) as r34,
  464. sum(if(subtractDays(date, 35)>=reg_time,0,amount)) as r35,
  465. sum(if(subtractDays(date, 36)>=reg_time,0,amount)) as r36,
  466. sum(if(subtractDays(date, 37)>=reg_time,0,amount)) as r37,
  467. sum(if(subtractDays(date, 38)>=reg_time,0,amount)) as r38,
  468. sum(if(subtractDays(date, 39)>=reg_time,0,amount)) as r39,
  469. sum(if(subtractDays(date, 40)>=reg_time,0,amount)) as r40,
  470. sum(if(subtractDays(date, 41)>=reg_time,0,amount)) as r41,
  471. sum(if(subtractDays(date, 42)>=reg_time,0,amount)) as r42,
  472. sum(if(subtractDays(date, 43)>=reg_time,0,amount)) as r43,
  473. sum(if(subtractDays(date, 44)>=reg_time,0,amount)) as r44,
  474. sum(if(subtractDays(date, 45)>=reg_time,0,amount)) as r45,
  475. sum(if(subtractDays(date, 46)>=reg_time,0,amount)) as r46,
  476. sum(if(subtractDays(date, 47)>=reg_time,0,amount)) as r47,
  477. sum(if(subtractDays(date, 48)>=reg_time,0,amount)) as r48,
  478. sum(if(subtractDays(date, 49)>=reg_time,0,amount)) as r49,
  479. sum(if(subtractDays(date, 50)>=reg_time,0,amount)) as r50,
  480. sum(if(subtractDays(date, 51)>=reg_time,0,amount)) as r51,
  481. sum(if(subtractDays(date, 52)>=reg_time,0,amount)) as r52,
  482. sum(if(subtractDays(date, 53)>=reg_time,0,amount)) as r53,
  483. sum(if(subtractDays(date, 54)>=reg_time,0,amount)) as r54,
  484. sum(if(subtractDays(date, 55)>=reg_time,0,amount)) as r55,
  485. sum(if(subtractDays(date, 56)>=reg_time,0,amount)) as r56,
  486. sum(if(subtractDays(date, 57)>=reg_time,0,amount)) as r57,
  487. sum(if(subtractDays(date, 58)>=reg_time,0,amount)) as r58,
  488. sum(if(subtractDays(date, 59)>=reg_time,0,amount)) as r59,
  489. sum(if(subtractDays(date, 60)>=reg_time,0,amount)) as r60,
  490. sum(if(subtractDays(date, 90)>=reg_time,0,amount)) as r90,
  491. sum(if(subtractDays(date, 120)>=reg_time,0,amount)) as r120,
  492. sum(if(subtractDays(date, 150)>=reg_time,0,amount)) as r150,
  493. 0 a1,1 b1,
  494. r2-r1 a2,if(r1=0,0,r2/r1) b2,
  495. r3-r2 a3,if(r1=0,0,r3/r1) b3,
  496. r4-r3 a4,if(r1=0,0,r4/r1) b4,
  497. r5-r4 a5,if(r1=0,0,r5/r1) b5,
  498. r6-r5 a6,if(r1=0,0,r6/r1) b6,
  499. r7-r6 a7,if(r1=0,0,r7/r1) b7,
  500. r8-r7 a8,if(r1=0,0,r8/r1) b8,
  501. r9-r8 a9,if(r1=0,0,r9/r1) b9,
  502. r10-r9 a10,if(r1=0,0,r10/r1) b10,
  503. r11-r10 a11,if(r1=0,0,r11/r1) b11,
  504. r12-r11 a12,if(r1=0,0,r12/r1) b12,
  505. r13-r12 a13,if(r1=0,0,r13/r1) b13,
  506. r14-r13 a14,if(r1=0,0,r14/r1) b14,
  507. r15-r14 a15,if(r1=0,0,r15/r1) b15,
  508. r16-r15 a16,if(r1=0,0,r16/r1) b16,
  509. r17-r16 a17,if(r1=0,0,r17/r1) b17,
  510. r18-r17 a18,if(r1=0,0,r18/r1) b18,
  511. r19-r18 a19,if(r1=0,0,r19/r1) b19,
  512. r20-r19 a20,if(r1=0,0,r20/r1) b20,
  513. r21-r20 a21,if(r1=0,0,r21/r1) b21,
  514. r22-r21 a22,if(r1=0,0,r22/r1) b22,
  515. r23-r22 a23,if(r1=0,0,r23/r1) b23,
  516. r24-r23 a24,if(r1=0,0,r24/r1) b24,
  517. r25-r24 a25,if(r1=0,0,r25/r1) b25,
  518. r26-r25 a26,if(r1=0,0,r26/r1) b26,
  519. r27-r26 a27,if(r1=0,0,r27/r1) b27,
  520. r28-r27 a28,if(r1=0,0,r28/r1) b28,
  521. r29-r28 a29,if(r1=0,0,r29/r1) b29,
  522. r30-r29 a30,if(r1=0,0,r30/r1) b30,
  523. r31-r30 a31,if(r1=0,0,r31/r1) b31,
  524. r32-r31 a32,if(r1=0,0,r32/r1) b32,
  525. r33-r32 a33,if(r1=0,0,r33/r1) b33,
  526. r34-r33 a34,if(r1=0,0,r34/r1) b34,
  527. r35-r34 a35,if(r1=0,0,r35/r1) b35,
  528. r36-r35 a36,if(r1=0,0,r36/r1) b36,
  529. r37-r36 a37,if(r1=0,0,r37/r1) b37,
  530. r38-r37 a38,if(r1=0,0,r38/r1) b38,
  531. r39-r38 a39,if(r1=0,0,r39/r1) b39,
  532. r40-r39 a40,if(r1=0,0,r40/r1) b40,
  533. r41-r40 a41,if(r1=0,0,r41/r1) b41,
  534. r42-r41 a42,if(r1=0,0,r42/r1) b42,
  535. r43-r42 a43,if(r1=0,0,r43/r1) b43,
  536. r44-r43 a44,if(r1=0,0,r44/r1) b44,
  537. r45-r44 a45,if(r1=0,0,r45/r1) b45,
  538. r46-r45 a46,if(r1=0,0,r46/r1) b46,
  539. r47-r46 a47,if(r1=0,0,r47/r1) b47,
  540. r48-r47 a48,if(r1=0,0,r48/r1) b48,
  541. r49-r48 a49,if(r1=0,0,r49/r1) b49,
  542. r50-r49 a50,if(r1=0,0,r50/r1) b50,
  543. r51-r50 a51,if(r1=0,0,r51/r1) b51,
  544. r52-r51 a52,if(r1=0,0,r52/r1) b52,
  545. r53-r52 a53,if(r1=0,0,r53/r1) b53,
  546. r54-r53 a54,if(r1=0,0,r54/r1) b54,
  547. r55-r54 a55,if(r1=0,0,r55/r1) b55,
  548. r56-r55 a56,if(r1=0,0,r56/r1) b56,
  549. r57-r56 a57,if(r1=0,0,r57/r1) b57,
  550. r58-r57 a58,if(r1=0,0,r58/r1) b58,
  551. r59-r58 a59,if(r1=0,0,r59/r1) b59,
  552. r60-r59 a60,if(r1=0,0,r60/r1) b60,
  553. r90-r60 a90,if(r1=0,0,r90/r1) b90,
  554. r120-r90 a120,if(r1=0,0,r120/r1) b120,
  555. r150-r120 a150,if(r1=0,0,r150/r1) b150
  556. from order where channel='{channel}' and dt>='{start}' group by formatDateTime(reg_time,'%Y-%m-%d')
  557. ) b on a.dt=b.dt
  558. """
  559. if start==end:
  560. total=1
  561. else:
  562. total = ck.execute(f"select count(1) from ({sql}) a")[0][0]
  563. sql += f" order by {order_by} {order} limit {(page-1)*page_size},{page_size} "
  564. data=get_round(ck.execute(sql))
  565. # print(data)
  566. def parse(str):
  567. li=str.split(',')
  568. li[0]=round(float(li[0]),2)
  569. li[1]=round(float(li[1]),4)
  570. li[2]=round(float(li[2]),4)
  571. li[3]=round(float(li[3]),2)
  572. return dict(zip(['order','roi','add','mult'],li))
  573. for i in data:
  574. for x,y in enumerate(i):
  575. if x>=11:
  576. i[x]=parse(y)
  577. print(data)
  578. key=['date','channel','book','cost','reg_amount','roi','new_follow_user','new_follow_per_cost','order_user','order_count',
  579. 'order_user_per_cost','d1','d2','d3','d4','d5','d6','d7','d8','d9','d10','d11','d12','d13','d14','d15','d16','d17','d18',
  580. 'd19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30','d31','d32','d33','d34','d35','d36','d37','d38',
  581. 'd39','d40','d41','d42','d43','d44','d45','d46','d47','d48','d49','d50','d51','d52','d53','d54','d55','d56','d57','d58','d59',
  582. 'd60','m3','m4','m5']
  583. return get_dict_list(key,data),total
  584. def get_channel_summary(channel,pitcher,page,page_size,order_by,order,state):
  585. pitcher_op=f" and pitcher='{pitcher}'" if pitcher!='' else ''
  586. channel_op=f" and channel='{channel}'" if channel!='' else ''
  587. sql = f"""select a.channel channel,state,'朋友圈' location,toString(start) start,toString(end) end,total_cost,total_amount,
  588. profit,roi,follow_user,follow_per_cost,order_user,
  589. if(follow_user=0,0,order_user/follow_user) order_tran_rate,if(order_user=0,0,total_cost/order_user) order_tran_cost
  590. from
  591. (
  592. select channel,if(max(dt)>subtractDays(today(),10),'在投','停投') state,
  593. min(dt) start,max(dt) end
  594. from dw_daily_channel_cost where cost>0 {pitcher_op} {channel_op} group by channel) a
  595. left outer join(
  596. select channel,sum(follow_user) follow_user,
  597. if(follow_user=0,0,sum(cost)/follow_user) follow_per_cost
  598. from dw_daily_channel where 1=1 {pitcher_op} {channel_op} group by channel) b on a.channel=b.channel
  599. left outer join(
  600. select sum(reg_order_user) order_user,channel
  601. from dw_daily_channel where dt=subtractDays(today(),1) {pitcher_op} {channel_op} group by channel) c on a.channel=c.channel
  602. left outer join (
  603. select total_cost,
  604. total_amount,
  605. channel,
  606. total_amount-total_cost profit,
  607. if(total_cost=0,0,total_amount/total_cost) roi
  608. from dw_channel_daily_total where dt=subtractDays(today(),1) {channel_op}) d on a.channel=d.channel
  609. """
  610. print(sql)
  611. if channel!='':
  612. total=1
  613. else:
  614. sql+=f" having state='{state}' " if state!='' else ''
  615. total = ck.execute(f"select count(1) from ({sql}) a")[0][0]
  616. sql += f' order by {order_by} {order} limit {(page-1)*page_size},{page_size} '
  617. print(sql)
  618. key=['channel','state','location','start','end','total_cost','total_amount','profit','roi',
  619. 'follow_user','follow_per_cost','order_user','order_tran_rate','order_tran_cost']
  620. print(ck.execute(sql))
  621. return get_dict_list(key,get_round(ck.execute(sql))),total
  622. if __name__ == '__main__':
  623. # a=get_channel_overview('','','',1,10,'date','desc')
  624. # a=get_channel_summary('','')
  625. a=get_channel_again_order_trend('龙鳞文学','2021-01-01','宋刚')
  626. # a=get_channel_active('玉龙书社','2020-09-15','2020-09-20',1,10,'date','desc')
  627. # a,b =get_channel_order_trend("玉龙书社",'王俊杰','2020-12-01','2020-12-12',1,5,'date','desc')
  628. print(a)
  629. pass