|
@@ -414,22 +414,28 @@ def get_channel_order_trend(channel,pitcher,start,end,page,page_size,order_by,or
|
|
|
return a,total
|
|
|
|
|
|
def get_channel_summary(channel,pitcher,page,page_size,order_by,order):
|
|
|
- sql = """select a.channel,state,'朋友圈' location,toString(start) start,toString(end) end,total_cost,total_amount,
|
|
|
+
|
|
|
+ pitcher_op=f" and pitcher='{pitcher}'" if pitcher!='' else ''
|
|
|
+ channel_op=f" and channel='{channel}'" if channel!='' else ''
|
|
|
+
|
|
|
+
|
|
|
+ sql = f"""select a.channel channel,state,'朋友圈' location,toString(start) start,toString(end) 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
|
|
|
+ from dw_daily_channel_cost where cost>0 {pitcher_op} {channel_op} 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
|
|
|
+ from dw_daily_channel where 1=1 {pitcher_op} {channel_op} 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
|
|
|
+ select sum(reg_order_user) order_user,channel
|
|
|
+ from dw_daily_channel where dt=subtractDays(today(),1) {pitcher_op} {channel_op} group by channel) c on a.channel=c.channel
|
|
|
|
|
|
left outer join (
|
|
|
select total_cost,
|
|
@@ -437,20 +443,18 @@ def get_channel_summary(channel,pitcher,page,page_size,order_by,order):
|
|
|
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('')
|
|
|
+ from dw_channel_daily_total where dt=subtractDays(today(),1) {channel_op}) d on a.channel=d.channel
|
|
|
+ """
|
|
|
+ print(sql)
|
|
|
if channel!='':
|
|
|
- sql+=f" and channel='{channel}'"
|
|
|
- total = ck.execute(f"select count(1) from ({sql}) a")[0][0]
|
|
|
- sql+=f' order by {order_by} {order} limit {page},{page_size} '
|
|
|
+ total=1
|
|
|
+ else:
|
|
|
+ total = ck.execute(f"select count(1) from ({sql}) a")[0][0]
|
|
|
+ sql += f' order by {order_by} {order} limit {page},{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']
|
|
|
+ print(ck.execute(sql))
|
|
|
|
|
|
return get_dict_list(key,get_round(ck.execute(sql))),total
|
|
|
|