|
@@ -203,30 +203,26 @@ from ({sql}) a
|
|
|
|
|
|
def get_channel_again_order_trend(channel,date):
|
|
|
ck = CkUtils()
|
|
|
+ db = MysqlUtils()
|
|
|
|
|
|
-
|
|
|
- sql=f"""select toString(dt) date,
|
|
|
+ sql=f"""select dt date,
|
|
|
channel,book,pitcher,stage,
|
|
|
- toDecimal32(cost,2),
|
|
|
- toDecimal32(reg_order_amount,2),
|
|
|
- toDecimal32(if(cost=0,0,reg_order_amount/cost),4) roi,
|
|
|
+ cost,
|
|
|
+ reg_order_amount,
|
|
|
+ round(if(cost=0,0,reg_order_amount/cost),4) roi,
|
|
|
follow_user new_follow,
|
|
|
- toDecimal32(if(follow_user=0,0,cost/follow_user),2) new_follow_per_cost,
|
|
|
+ round(if(follow_user=0,0,cost/follow_user),2) new_follow_per_cost,
|
|
|
reg_order_count reg_count,reg_order_user reg_user,
|
|
|
- toDecimal32(if(reg_order_user=0,0,cost/reg_order_user),2) cost_per_user,
|
|
|
- toDecimal32(if(reg_order_user=0,0,reg_order_amount/reg_order_user),2) avg_order_amount,
|
|
|
- toDecimal32(if(reg_order_user=0,0,reg_order_user_again/reg_order_user),4) avg_again_order_rate,
|
|
|
+ round(if(reg_order_user=0,0,cost/reg_order_user),2) cost_per_user,
|
|
|
+ round(if(reg_order_user=0,0,reg_order_amount/reg_order_user),2) avg_order_amount,
|
|
|
+ round(if(reg_order_user=0,0,reg_order_user_again/reg_order_user),4) avg_again_order_rate,
|
|
|
if(reg_order_user=0,0,order_count/reg_order_user) order_count
|
|
|
|
|
|
- from dw_daily_channel where channel='{channel}' and dt='{date}'
|
|
|
+ from dw_channel where channel='{channel}' and dt='{date}'
|
|
|
"""
|
|
|
# print(sql)
|
|
|
- data=ck.execute(sql)
|
|
|
- # print(data)
|
|
|
- key1=['date','channel','book','pitcher','stage','cost','reg_amount','roi','new_follow','new_follow_per_cost',
|
|
|
- 'reg_count','reg_user','cost_per_user','avg_order_amount','avg_again_order_rate','order_count']
|
|
|
+ j=db.dm.getData_json(sql)
|
|
|
|
|
|
- j=get_dict_list(key1,get_round(data))
|
|
|
if len(j) == 0:
|
|
|
return None
|
|
|
else:
|
|
@@ -238,7 +234,7 @@ def get_channel_again_order_trend(channel,date):
|
|
|
1 as ddf,count(1) c1,sum(if(count>1,1,0)) c2,sum(if(count>2,1,0)) c3,
|
|
|
sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
|
|
|
from (select count(1) count
|
|
|
- from order where channel='{channel}' and date='{date}'
|
|
|
+ from order where channel='{channel}' and date='{date}'and status=2
|
|
|
and formatDateTime(reg_time,'%Y-%m-%d')='{date}' group by user_id,date) a
|
|
|
union all
|
|
|
select
|
|
@@ -246,7 +242,7 @@ select
|
|
|
sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
|
|
|
from (
|
|
|
select count(1) count
|
|
|
- from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),1)
|
|
|
+ from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),1) and status=2
|
|
|
and formatDateTime(reg_time,'%Y-%m-%d')='{date}' group by user_id) a
|
|
|
union all
|
|
|
select
|
|
@@ -254,7 +250,7 @@ select
|
|
|
sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
|
|
|
from (
|
|
|
select count(1) count
|
|
|
- from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),2)
|
|
|
+ from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),2) and status=2
|
|
|
and formatDateTime(reg_time,'%Y-%m-%d')='{date}' group by user_id) a
|
|
|
union all
|
|
|
select
|
|
@@ -262,7 +258,7 @@ select
|
|
|
sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
|
|
|
from (
|
|
|
select count(1) count
|
|
|
- from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),3)
|
|
|
+ from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),3) and status=2
|
|
|
and formatDateTime(reg_time,'%Y-%m-%d')='{date}' group by user_id) a
|
|
|
union all
|
|
|
select
|
|
@@ -270,7 +266,7 @@ select
|
|
|
sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
|
|
|
from (
|
|
|
select count(1) count
|
|
|
- from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),4)
|
|
|
+ from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),4) and status=2
|
|
|
and formatDateTime(reg_time,'%Y-%m-%d')='{date}' group by user_id) a
|
|
|
union all
|
|
|
select
|
|
@@ -278,7 +274,7 @@ select
|
|
|
sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
|
|
|
from (
|
|
|
select count(1) count
|
|
|
- from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),5)
|
|
|
+ from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),5) and status=2
|
|
|
and formatDateTime(reg_time,'%Y-%m-%d')='{date}' group by user_id) a
|
|
|
union all
|
|
|
select
|
|
@@ -286,7 +282,7 @@ select
|
|
|
sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
|
|
|
from (
|
|
|
select count(1) count
|
|
|
- from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),6)
|
|
|
+ from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),6) and status=2
|
|
|
and formatDateTime(reg_time,'%Y-%m-%d')='{date}' group by user_id) a"""
|
|
|
|
|
|
df=ck.execute(sql2)
|