|
@@ -147,7 +147,8 @@ def get_channel_overview(channel,pitcher,start,end,page,page_size,order_by,order
|
|
|
toDecimal32(if(cost=0,0,first_order_amount/cost),4) day_roi,
|
|
|
toDecimal32(if(cost=0,0,reg_order_amount/cost),4) all_roi,
|
|
|
if(total_cost=0,0,total_first_amount/total_cost) avg_new_order_rate,
|
|
|
- if(reg_order_user=0,0,reg_order_user_again/reg_order_user) old_user_once_order_rate from dw_daily_channel where 1=1 """
|
|
|
+ if(reg_order_user=0,0,reg_order_user_again/reg_order_user) old_user_once_order_rate,
|
|
|
+ pitcher from dw_daily_channel where 1=1 """
|
|
|
if channel!='':
|
|
|
sql+=f" and channel='{channel}'"
|
|
|
if start!='':
|
|
@@ -163,7 +164,7 @@ def get_channel_overview(channel,pitcher,start,end,page,page_size,order_by,order
|
|
|
|
|
|
key=['channel','date','view_count','click_count','click_rate','follow_user','follow_rate','follow_per_cost','order_rate','order_per_cost','cost',
|
|
|
'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',
|
|
|
- 'new_user_order_rate','reg_user_amount','total_cost','total_amount','day_roi','all_roi','avg_new_order_rate','old_user_once_order_rate']
|
|
|
+ 'new_user_order_rate','reg_user_amount','total_cost','total_amount','day_roi','all_roi','avg_new_order_rate','old_user_once_order_rate','pitcher']
|
|
|
|
|
|
return get_dict_list(key,get_round(ck.execute(sql))),total
|
|
|
|
|
@@ -335,7 +336,7 @@ select
|
|
|
def get_channel_active(channel,pitcher,start,end,page,page_size,order_by,order):
|
|
|
# channels=f' and channel in {get_channels_from_user(pitcher)} ' if pitcher !='赞象 admin' else ''
|
|
|
channels=''
|
|
|
- channel=f" and channel='{channel}' "
|
|
|
+ channel=f" and channel='{channel}' "
|
|
|
sql=f"""select formatDateTime(a.dt,'%Y-%m-%d') date, '{channel}' channel,book,toDecimal32(cost,2),toDecimal32(reg_amount,2),roi,new_follow_user,toDecimal32(new_follow_per_cost,2),order_user,order_count,
|
|
|
toDecimal32(order_user_per_cost,2),day7_avg_act_rate,toDecimal32(day7_avg_act_per_cost,2),day30_avg_act_rate,toDecimal32(ay30_avg_act_cost,2),
|
|
|
toDecimal32(act_per_cost,2),
|
|
@@ -385,7 +386,7 @@ select dt,book,cost,
|
|
|
if(follow_user=0,0,reg_order_user30/follow_user) day30_avg_act_rate,
|
|
|
if(reg_order_user30=0,0,cost/reg_order_user30) ay30_avg_act_cost,
|
|
|
if(reg_order_user=0,0,cost/reg_order_user) act_per_cost
|
|
|
- from dw_daily_channel where 1=1 {channel} {channels} and dt>='{start}' and dt<='{end}') a
|
|
|
+ from dw_daily_channel where 1=1 {channel} and dt>='{start}' and dt<='{end}') a
|
|
|
left outer join (
|
|
|
|
|
|
select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,
|
|
@@ -419,7 +420,7 @@ select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,
|
|
|
count(distinct if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),27)>=date,user_id,NULL)) reg_order_user28,
|
|
|
count(distinct if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),28)>=date,user_id,NULL)) reg_order_user29,
|
|
|
count(distinct if(addDays(toDate(formatDateTime(reg_time,'%Y-%m-%d')),29)>=date,user_id,NULL)) reg_order_user30
|
|
|
- from order where 1=1 {channel} {channels} and dt>='{start}' group by formatDateTime(reg_time,'%Y-%m-%d')) b on a.dt=b.dt
|
|
|
+ from order where 1=1 {channel} and dt>='{start}' group by formatDateTime(reg_time,'%Y-%m-%d')) b on a.dt=b.dt
|
|
|
"""
|
|
|
|
|
|
|
|
@@ -459,8 +460,9 @@ select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,
|
|
|
return li,total
|
|
|
|
|
|
def get_channel_order_trend(channel,pitcher,start,end,page,page_size,order_by,order):
|
|
|
- channels = f' and channel in {get_channels_from_user(pitcher)} ' if pitcher != '赞象 admin' else ''
|
|
|
- sql=f"""select '{channel}' channel,toString(dt) date,book,toDecimal32(cost,2),toDecimal32(reg_order_amount,2),roi,new_follow_user,new_follow_per_cost,order_user,order_count,
|
|
|
+ # channels = f' and channel in {get_channels_from_user(pitcher)} ' if pitcher != '赞象 admin' else ''
|
|
|
+
|
|
|
+ sql=f"""select pitcher,'{channel}' channel,toString(dt) date,book,toDecimal32(cost,2),toDecimal32(reg_order_amount,2),roi,new_follow_user,new_follow_per_cost,order_user,order_count,
|
|
|
toDecimal32(order_user_per_cost,2),
|
|
|
concat(toString(r1),',',toString(r1/cost),',', toString(a1/cost),',',toString(b1)),
|
|
|
concat(toString(a2),',',toString(r2/cost),',', toString(a2/cost),',',toString(b2)),
|
|
@@ -533,7 +535,7 @@ select dt,book,cost,reg_order_amount,
|
|
|
if(follow_user=0,0,cost/follow_user) new_follow_per_cost,
|
|
|
reg_order_user order_user, reg_order_count order_count,
|
|
|
if(reg_order_user=0,0,cost/reg_order_user) order_user_per_cost
|
|
|
- from dw_daily_channel where dt>='{start}' and dt<='{end}' and channel='{channel}' {channels} and cost>0) a
|
|
|
+ from dw_daily_channel where dt>='{start}' and dt<='{end}' and channel='{channel}' and cost>0) a
|
|
|
|
|
|
left outer join (
|
|
|
select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,
|
|
@@ -663,7 +665,7 @@ r60-r59 a60,if(r1=0,0,r60/r1) b60,
|
|
|
r90-r60 a90,if(r1=0,0,r90/r1) b90,
|
|
|
r120-r90 a120,if(r1=0,0,r120/r1) b120,
|
|
|
r150-r120 a150,if(r1=0,0,r150/r1) b150
|
|
|
-from order where channel='{channel}' {channels} and dt>='{start}' group by formatDateTime(reg_time,'%Y-%m-%d')
|
|
|
+from order where channel='{channel}' and dt>='{start}' group by formatDateTime(reg_time,'%Y-%m-%d')
|
|
|
) b on a.dt=b.dt
|
|
|
"""
|
|
|
if start==end:
|
|
@@ -725,7 +727,8 @@ def get_channel_summary(channel,pitcher,page,page_size,order_by,order,state):
|
|
|
sql = f"""select a.channel channel,state,'朋友圈' location,toString(start) start,toString(end) end,
|
|
|
toDecimal32(total_cost,2),toDecimal32(total_amount,2),
|
|
|
toDecimal32(profit,2),roi,follow_user,toDecimal32(follow_per_cost,2),order_user,
|
|
|
- if(follow_user=0,0,order_user/follow_user) order_tran_rate,toDecimal32(if(order_user=0,0,total_cost/order_user),2) order_tran_cost
|
|
|
+ if(follow_user=0,0,order_user/follow_user) order_tran_rate,toDecimal32(if(order_user=0,0,total_cost/order_user),2) order_tran_cost,
|
|
|
+ pitcher
|
|
|
from
|
|
|
(
|
|
|
select channel,if(max(dt)>subtractDays(today(),10),'在投','停投') state,
|
|
@@ -748,6 +751,12 @@ def get_channel_summary(channel,pitcher,page,page_size,order_by,order,state):
|
|
|
total_amount-total_cost profit,
|
|
|
if(total_cost=0,0,total_amount/total_cost) roi
|
|
|
from dw_channel_daily_total where dt=today() {channel_op}) d on a.channel=d.channel
|
|
|
+ left outer join (
|
|
|
+ select pitcher,channel from dw_daily_channel_cost where dt=today() group by pitcher,channel
|
|
|
+ ) e on a.channel=e.channel
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
"""
|
|
|
print(sql)
|
|
|
if channel!='':
|
|
@@ -758,7 +767,7 @@ def get_channel_summary(channel,pitcher,page,page_size,order_by,order,state):
|
|
|
sql += f' order by {order_by} {order} limit {(page-1)*page_size},{page_size} '
|
|
|
print(sql)
|
|
|
key=['channel','state','location','start','end','total_cost','total_amount','profit','roi',
|
|
|
- 'follow_user','follow_per_cost','order_user','order_tran_rate','order_tran_cost']
|
|
|
+ 'follow_user','follow_per_cost','order_user','order_tran_rate','order_tran_cost','pitcher']
|
|
|
print(ck.execute(sql))
|
|
|
|
|
|
return get_dict_list(key,get_round(ck.execute(sql))),total
|