|
@@ -11,7 +11,7 @@ from sync_to_ck_task import dw_order_channel_sync_ck
|
|
|
def dw_daily_channel(ymd):
|
|
|
sql="""replace into dw_daily_channel
|
|
|
select dt,x.channel,pitcher,stage,platform,book,ifnull(order_count,0) order_count,ifnull(order_user,0),ifnull(order_amount,0),ifnull(first_order_count,0),ifnull(first_order_user,0),
|
|
|
- ifnull(first_order_amount,0),ifnull(view_count,0),ifnull(click_count,0),ifnull(follow_user,0),ifnull(cost,0) as cost from
|
|
|
+ ifnull(first_order_amount,0),ifnull(view_count,0),ifnull(click_count,0),ifnull(follow_user,0),ifnull(cost,0) as cost,type from
|
|
|
(select dt,channel,stage,pitcher,platform,book from channel_info_daily where dt='{0}' and channel!='') x
|
|
|
left join
|
|
|
(select channel,count(1) as order_count,count(distinct user_id) as order_user,sum(amount) as order_amount,
|
|
@@ -21,25 +21,24 @@ def dw_daily_channel(ymd):
|
|
|
from ods_order where date='{0}' group by channel) y on x.channel=y.channel
|
|
|
|
|
|
left join
|
|
|
- (select channel,sum(cost) as cost,sum(view_count) as view_count,sum(valid_click_count) as click_count,sum(from_follow_uv) as follow_user from
|
|
|
+ (select channel,type,sum(cost) as cost,sum(view_count) as view_count,sum(valid_click_count) as click_count,sum(from_follow_uv) as follow_user from
|
|
|
(select account_id,cost,view_count,valid_click_count,round(valid_click_count*official_account_follow_rate,0) as from_follow_uv from daily_vx where date='{0} 00:00:00'
|
|
|
union
|
|
|
select account_id,cost,view_count,valid_click_count,from_follow_uv from daily_qq where date='{0} 00:00:00') a
|
|
|
left join
|
|
|
- (select account_id,channel from channel_by_account_daily where dt='{0}') b on a.account_id=b.account_id group by channel) z on x.channel=z.channel
|
|
|
+ (select account_id,channel,type from channel_by_account_daily where dt='{0}') b on a.account_id=b.account_id group by channel,type) z on x.channel=z.channel
|
|
|
""".format(ymd)
|
|
|
|
|
|
db.quchen_text.execute(sql)
|
|
|
|
|
|
|
|
|
-
|
|
|
def channel_by_account_daily(ymd):
|
|
|
"""返回当天消耗账户对应的公众号表"""
|
|
|
sql="""replace into channel_by_account_daily
|
|
|
- select '{0}' as dt,a.account_id as account_id, ifnull(ifnull(b.name,a.name),'') as channel from
|
|
|
- (select account_id,name from advertiser_qq
|
|
|
+ select '{0}' as dt,a.account_id as account_id, ifnull(ifnull(b.name,a.name),'') as channel,type from
|
|
|
+ (select account_id,name,'qq' as type from advertiser_qq
|
|
|
union
|
|
|
- select account_id,name from advertiser_vx
|
|
|
+ select account_id,name,'vx' as type from advertiser_vx
|
|
|
) a
|
|
|
left join
|
|
|
(select b.account_id,b.name from
|
|
@@ -130,22 +129,47 @@ def order_account_text():
|
|
|
db.quchen_text.execute("insert into order_account_text(platform,text) values ('文鼎','{}')".format(i))
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+def dw_daily_channel_plus():
|
|
|
+ """快照表 每日一更新 t-1"""
|
|
|
+ sql="""insert into dw_daily_channel_plus
|
|
|
+ select
|
|
|
+ dt,channel,pitcher,stage,platform,book,order_count,order_user,order_amount,first_order_count,first_order_user,first_order_amount,
|
|
|
+ view_count,click_count,follow_user,cost,reg_order_count,reg_order_user,reg_order_amount,reg_order_amount30
|
|
|
+
|
|
|
+ from
|
|
|
+ (select dt,channel,picher as pitcher,stage,platform,book,cost,view_count,click_count,follow_user,order_count,order_user,order_amount from dw_daily_channel) a
|
|
|
+ left outer join
|
|
|
+ (select toDate(formatDateTime(reg_time,'%Y-%m-%d')) as dt2,channel as channel2,
|
|
|
+ sum(amount) as reg_order_amount,
|
|
|
+ count(distinct user_id) as reg_order_user,
|
|
|
+ count(1) as reg_order_count,
|
|
|
+ sum(if(subtractDays(date, 30)>reg_time,toDecimal32(0,2),amount)) as reg_order_amount30
|
|
|
+ from order where reg_time>'2019-03-18 00:00:00' group by toDate(formatDateTime(reg_time,'%Y-%m-%d')),channel) b
|
|
|
+ on dt=dt2 and channel=channel2 left outer join
|
|
|
+ (select date as dt3,channel as channel3,
|
|
|
+ count(1) as first_order_count,
|
|
|
+ count(distinct user_id) as first_order_user,
|
|
|
+ sum(amount) as first_order_amount
|
|
|
+ from order where toDate(reg_time)=date group by date,channel) c
|
|
|
+ on dt=dt3 and channel=channel3"""
|
|
|
+ ck.execute("truncate table dw_daily_channel_plus")
|
|
|
+ ck.execute(sql)
|
|
|
+ print("ok")
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
+ # channel_by_account_daily('2020-12-17')
|
|
|
|
|
|
- ods_order('2019-03-18')
|
|
|
+ # ods_order('2019-03-18')
|
|
|
+ dw_daily_channel_plus()
|
|
|
+ exit()
|
|
|
|
|
|
- for i in dt.getDateLists('2019-03-18','2020-12-17'):
|
|
|
- print(i)
|
|
|
+ # for i in dt.getDateLists('2019-03-18','2020-12-17'):
|
|
|
+ # print(i)
|
|
|
# ods_order(i)
|
|
|
# channel_by_account_daily(i)
|
|
|
# channel_info_daily(i)
|
|
|
- dw_daily_channel(i)
|
|
|
- dw_order_channel_sync_ck(i)
|
|
|
+ # dw_daily_channel(i)
|
|
|
+ # dw_order_channel_sync_ck(i)
|
|
|
|
|
|
|