|
@@ -94,38 +94,46 @@ def get_pitcher_panel_overview(pitcher):
|
|
|
return get_dict_list(key,data)
|
|
|
|
|
|
|
|
|
-def get_channel_overview(channel,start,end):
|
|
|
- a =[{'date':'2020-12-30',
|
|
|
- 'channel':'宝珠书屋',
|
|
|
- 'view_count':2,
|
|
|
- 'click_count':2,
|
|
|
- 'click_rate':0.23,
|
|
|
- 'follow_user':2,
|
|
|
- 'follow_rate':0.23,
|
|
|
- 'follow_per_cost':2.12,
|
|
|
- 'order_rate':0.12,
|
|
|
- 'order_per_cost':3.21,
|
|
|
- 'cost':343.12,
|
|
|
- 'first_order_count':23,
|
|
|
- 'first_order_user':23,
|
|
|
- 'first_order_amount':122.23,
|
|
|
- 'order_count':21,
|
|
|
- 'order_user':12,
|
|
|
- 'order_amount':234.12,
|
|
|
- 'old_order_amount':234.12,
|
|
|
- 'first_amount_per_user':232,
|
|
|
- 'amount_per_follow':123.12,
|
|
|
- 'first_cost_per_user':234.12,
|
|
|
- 'new_user_order_rate':0.22,
|
|
|
- 'reg_user_amount':212.1,
|
|
|
- 'total_cost':2342.11,
|
|
|
- 'total_amount':123.11,
|
|
|
- 'day_roi':0.87,
|
|
|
- 'all_roi':23.12,
|
|
|
- 'avg_new_order_rate':0.23,
|
|
|
- 'old_user_once_order_rate':0.23
|
|
|
- }]
|
|
|
- return a
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def get_channel_overview(channel,start,end,page,page_size,order_by,order):
|
|
|
+ sql="""select channel,toString(dt) date,
|
|
|
+ view_count,click_count,
|
|
|
+ round(if(view_count=0,0,click_count/view_count),4) click_rate,
|
|
|
+ follow_user,
|
|
|
+ round(if(click_count=0,0,follow_user/click_count),4) follow_rate,
|
|
|
+ round(if(follow_user=0,0,cost/follow_user),2) follow_per_cost,
|
|
|
+ round(if(click_count=0,0,first_order_count/click_count),4) order_rate,
|
|
|
+ round(if(first_order_user=0,0,cost/first_order_user),2) order_per_cost,
|
|
|
+ round(cost,2) cost,
|
|
|
+ first_order_count,first_order_user,
|
|
|
+ round(first_order_amount,2) first_order_amount,order_count,order_user,
|
|
|
+ round(order_amount,2) order_amount,
|
|
|
+ round(order_amount-first_order_amount,2) old_order_amount,
|
|
|
+ round(if(first_order_user=0,0,first_order_amount/first_order_user),2) first_amount_per_user,
|
|
|
+ round(if(follow_user=0,0,first_order_amount/follow_user),2) amount_per_follow,
|
|
|
+ round(if(first_order_user=0,0,cost/first_order_user),2) first_cost_per_user,
|
|
|
+ round(if(follow_user=0,0,first_order_user/follow_user),4) new_user_order_rate,
|
|
|
+ round(reg_order_amount,2) reg_user_amount,
|
|
|
+ round(total_cost,2) total_cost,
|
|
|
+ round(total_amount,2) total_amount,
|
|
|
+ round(if(cost=0,0,first_order_amount/cost),4) day_roi,
|
|
|
+ round(if(cost=0,0,reg_order_amount/cost),4) all_roi,
|
|
|
+ 0 avg_new_order_rate,
|
|
|
+ 0 old_user_once_order_rate from dw_daily_channel where 1=1 """
|
|
|
+ if channel!='':
|
|
|
+ sql+=f" and channel='{channel}'"
|
|
|
+ if start!='':
|
|
|
+ sql+=f" and start>='{start}'"
|
|
|
+ if end!='':
|
|
|
+ sql+=f" and end<='{end}'"
|
|
|
+
|
|
|
+ sql += f" order by {order_by} {order} limit {page},{page_size} "
|
|
|
+ print(sql)
|
|
|
+
|
|
|
+ return ck.execute(sql)
|
|
|
+
|
|
|
|
|
|
|
|
|
def get_channel_again_order_trend(channel,date):
|
|
@@ -250,4 +258,47 @@ def get_channel_order_trend(channel,start,end):
|
|
|
'add': 0.4511,
|
|
|
'mult': 1.12},
|
|
|
}]
|
|
|
- return a
|
|
|
+ return a
|
|
|
+
|
|
|
+
|
|
|
+def get_channel_summary(channel,pitcher):
|
|
|
+ sql = """select a.channel,state,'朋友圈' location,toString(start),toString(end),total_cost,total_amount,
|
|
|
+ profit,roi,follow_user,follow_per_cost,order_user,
|
|
|
+ if(follow_user=0,0,order_user/follow_user) order_tran_rate,if(order_user=0,0,total_cost/order_user) order_tran_cost
|
|
|
+ from
|
|
|
+ (
|
|
|
+ select channel,if(max(dt)>subtractDays(today(),10),'在投','停投') state,
|
|
|
+ min(dt) start,max(dt) end
|
|
|
+ from dw_daily_channel_cost where cost>0 {} group by channel) a
|
|
|
+
|
|
|
+ left outer join(
|
|
|
+ select channel,sum(follow_user) follow_user,
|
|
|
+ if(follow_user=0,0,sum(cost)/follow_user) follow_per_cost
|
|
|
+ from dw_daily_channel group by channel) b on a.channel=b.channel
|
|
|
+
|
|
|
+ left outer join(
|
|
|
+ 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
|
|
|
+
|
|
|
+ left outer join (
|
|
|
+ select total_cost,
|
|
|
+ total_amount,
|
|
|
+ channel,
|
|
|
+ total_amount-total_cost profit,
|
|
|
+ if(total_cost=0,0,total_amount/total_cost) roi
|
|
|
+ from dw_channel_daily_total where dt=subtractDays(today(),1)) d on a.channel=d.channel
|
|
|
+ where 1=1 """
|
|
|
+
|
|
|
+ if pitcher!='':
|
|
|
+ sql=sql.format(f" and pitcher='{pitcher}'")
|
|
|
+ else:
|
|
|
+ sql=sql.format('')
|
|
|
+ if channel!='':
|
|
|
+ sql+=f" and channel='{channel}'"
|
|
|
+ return ck.execute(sql)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ # a=get_channel_overview('','','',1,10,'date','desc')
|
|
|
+ a=get_channel_summary('','')
|
|
|
+ print(a)
|