|
@@ -1,6 +1,8 @@
|
|
|
from model.DataBaseUtils import MysqlUtils, CkUtils
|
|
|
+from datetime import datetime, timedelta, timezone
|
|
|
from model.DateUtils import DateUtils
|
|
|
import logging
|
|
|
+import time
|
|
|
|
|
|
db = MysqlUtils()
|
|
|
ck = CkUtils()
|
|
@@ -78,7 +80,13 @@ def platform_data_sum(ymd):
|
|
|
|
|
|
def dw_daily_channel_cost(ymd):
|
|
|
logging.info("run> dw_daily_channel_cost")
|
|
|
- sql = """
|
|
|
+ datatime_ymd = datetime.strptime(ymd, '%Y-%m-%d').astimezone(timezone(timedelta(hours=8))).timetuple()
|
|
|
+ timestamp_ymd = time.mktime(datatime_ymd)
|
|
|
+ tomorrow_ymd = (datetime.strptime(ymd, '%Y-%m-%d').astimezone(timezone(timedelta(hours=8))) + timedelta(
|
|
|
+ days=1)).timetuple()
|
|
|
+ timestamp_tom = time.mktime(tomorrow_ymd)
|
|
|
+
|
|
|
+ sql = f"""
|
|
|
select x.dt,x.channel,pitcher,stage,x.platform,x.book,
|
|
|
ifnull(view_count,0),ifnull(click_count,0),
|
|
|
ifnull(follow_user,0),ifnull(cost,0)/100 as cost,
|
|
@@ -86,43 +94,60 @@ def dw_daily_channel_cost(ymd):
|
|
|
ifnull(platform_view_count,0) platform_view_count,
|
|
|
ifnull(web_order_count,0) web_order_count,
|
|
|
if(stage ='趣程15期' or stage ='趣程26期' or stage ='趣程30期','GDT','MP') type
|
|
|
- ,0 require_roi,0 require_mult
|
|
|
+ ,0 require_roi,0 require_mult,ifnull(y.create_user_num,0)
|
|
|
from
|
|
|
( select dt, channel,stage,pitcher,platform,book from channel_info_daily cid
|
|
|
- where dt='{0}' and channel !=''
|
|
|
+ where dt='{ymd}' and channel !=''
|
|
|
and channel in
|
|
|
(select distinct(channel) from channel_by_account_daily cbad
|
|
|
- where dt='{0}'
|
|
|
+ where dt='{ymd}'
|
|
|
and (type ='GDT' or type='MP')
|
|
|
)
|
|
|
) x -- 只允许渠道MP、GDT
|
|
|
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,
|
|
|
- sum(web_view_count) as web_view_count,sum(platform_view_count) as platform_view_count,sum(web_order_count) as web_order_count
|
|
|
+ (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,
|
|
|
+ sum(web_view_count) as web_view_count,
|
|
|
+ sum(platform_view_count) as platform_view_count,
|
|
|
+ sum(web_order_count) as web_order_count
|
|
|
from
|
|
|
- (select account_id,cost,view_count,valid_click_count,round(valid_click_count*official_account_follow_rate,0) as from_follow_uv,
|
|
|
+ (select account_id,cost,view_count,valid_click_count,
|
|
|
+ round(valid_click_count*official_account_follow_rate,0) as from_follow_uv,
|
|
|
0 as web_view_count,
|
|
|
0 as platform_view_count,
|
|
|
0 as web_order_count
|
|
|
- from daily_vx where date='{0} 00:00:00'
|
|
|
+ from daily_vx where date='{ymd} 00:00:00'
|
|
|
union
|
|
|
select account_id,cost,view_count,valid_click_count,from_follow_uv,
|
|
|
ifnull(web_commodity_page_view_count,0) as web_view_count,
|
|
|
ifnull(platform_page_view_count,0) as platform_view_count,
|
|
|
ifnull(web_order_count,0) as web_order_count
|
|
|
- from daily_qq where date='{0} 00:00:00' ) a
|
|
|
+ from daily_qq where date='{ymd} 00:00:00' ) a
|
|
|
left join
|
|
|
- (select account_id,channel from channel_by_account_daily where dt='{0}') b
|
|
|
+ (select account_id,channel from channel_by_account_daily where dt='{ymd}') b
|
|
|
on a.account_id=b.account_id group by channel)
|
|
|
z on x.channel=z.channel
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ left join
|
|
|
+ (
|
|
|
+ select c.name as channel ,DATE(FROM_UNIXTIME(origin.create_time)) as wx_date,
|
|
|
+ count(*) as create_user_num
|
|
|
+ from
|
|
|
+ db_mp.h_member origin left join
|
|
|
+ db_mp.mp_conf_agent a on origin.app_id =a.app_id and origin.agent_id = a.agent_id
|
|
|
+ left join
|
|
|
+ db_mp.mp_mp_conf b on a.advertiser_conf_id =b.id
|
|
|
+ left join
|
|
|
+ quchen_text.advertiser_vx c on b.mp_id =c.wechat_account_id
|
|
|
+ where c.wechat_account_id is not null
|
|
|
+ and origin.create_time > {timestamp_ymd} and origin.create_time < {timestamp_tom}
|
|
|
+ group by name,wx_date
|
|
|
+ ) y on x.channel= y.channel
|
|
|
|
|
|
- """.format(ymd)
|
|
|
+ """
|
|
|
data = db.quchen_text.get_data_list(sql)
|
|
|
data1 = []
|
|
|
- col = "dt,channel,pitcher,stage,platform,book,view_count,click_count,follow_user,cost,web_view_count,platform_view_count,web_order_count,type,require_roi,require_mult"
|
|
|
+ col = "dt,channel,pitcher,stage,platform,book,view_count,click_count,follow_user,cost,web_view_count,platform_view_count,web_order_count,type,require_roi,require_mult,create_user_num"
|
|
|
for i in data:
|
|
|
i[0] = str(i[0])
|
|
|
i[9] = str(i[9])
|
|
@@ -256,9 +281,8 @@ if __name__ == '__main__':
|
|
|
# channel_info_daily('2021-02-06')
|
|
|
|
|
|
# channel_by_account_daily('2021-02-05')
|
|
|
- for i in dt.getDateLists('2021-09-11', '2021-10-27'):
|
|
|
- print(i)
|
|
|
- channel_info_daily(i)
|
|
|
+ for i in dt.getDateLists('2021-04-08', '2021-10-27'):
|
|
|
+ # channel_info_daily(i)
|
|
|
|
|
|
dw_daily_channel_cost(i)
|
|
|
# ods_order('2021-05-06')
|