|
@@ -7,14 +7,14 @@ du = DateUtils()
|
|
|
log = logger()
|
|
|
|
|
|
"""根据公众号获取投手"""
|
|
|
-def get_channel_belong_pitcher(channel):
|
|
|
-
|
|
|
- sql = f"select pitcher,channel from dw_daily_channel_cost where dt='{du.get_n_days(-1)}' and pitcher!='' and channel!=''"
|
|
|
- data=ck.execute(sql)
|
|
|
- di={}
|
|
|
- for i in data:
|
|
|
- di[i[1]]=i[0]
|
|
|
- return di.get(channel,'')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
"""根据名字获取其归属的公众号"""
|
|
|
def get_channels_from_user(user):
|
|
@@ -25,82 +25,67 @@ def get_channels_from_user(user):
|
|
|
|
|
|
|
|
|
def get_pitcher_panel_channel(pitcher,channel,start,end,page,page_size,order_by,order):
|
|
|
- ck=CkUtils()
|
|
|
+ db=MysqlUtils()
|
|
|
sql=f"""select channel,stage,platform,book,
|
|
|
- formatDateTime(dt,'%Y-%m-%d') as date,
|
|
|
- toDecimal32(cost,2),
|
|
|
- toDecimal32(first_order_amount,2),
|
|
|
- toDecimal32(if(cost=0,0,first_order_amount/cost),4) first_roi,
|
|
|
+ dt as date,cost,first_order_amount,
|
|
|
+ if(cost=0,0,first_order_amount/cost) first_roi,
|
|
|
first_order_user,first_order_count,
|
|
|
- toDecimal32(if(first_order_user=0,0,cost/first_order_user),2) first_per_cost,
|
|
|
+ if(first_order_user=0,0,cost/first_order_user) first_per_cost,
|
|
|
view_count,click_count,follow_user,
|
|
|
- toDecimal32(if(click_count=0,0,follow_user/click_count),4) follow_rate,
|
|
|
- toDecimal32(if(follow_user=0,0,cost/follow_user),2) follow_per_cost,
|
|
|
- toDecimal32(total_cost,2),
|
|
|
- toDecimal32(if(total_cost=0,0,total_amount/total_cost),2) back_rate
|
|
|
- from dw_daily_channel where dt>='{start}' and dt<='{end}' """
|
|
|
+ if(click_count=0,0,follow_user/click_count) follow_rate,
|
|
|
+ if(follow_user=0,0,cost/follow_user) follow_per_cost,
|
|
|
+ total_cost,
|
|
|
+ if(total_cost=0,0,total_amount/total_cost) back_rate
|
|
|
+ from dw_channel_daily where dt>='{start}' and dt<='{end}' """
|
|
|
if pitcher!='all':
|
|
|
sql += f" and pitcher='{pitcher}' "
|
|
|
|
|
|
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-1)*page_size},{page_size} "
|
|
|
-
|
|
|
- print(sql)
|
|
|
- data=ck.execute(sql)
|
|
|
-
|
|
|
- key=['channel','stage','platform','book','date','cost','first_order_amount','first_roi','first_order_user',
|
|
|
- 'first_order_count','first_per_cost','view_count','click_count','follow_user','follow_rate','follow_per_cost',
|
|
|
- 'total_cost','back_rate']
|
|
|
+ sql += f" order by {order_by} {order}"
|
|
|
|
|
|
-
|
|
|
- return get_dict_list(key,get_round(data,4)),total
|
|
|
+ return getLimitData(db.quchen_text,sql,page,page_size)
|
|
|
|
|
|
|
|
|
def get_pitcher_panel_daily(pitcher, start, end, page, page_size, order_by, order):
|
|
|
- ck = CkUtils()
|
|
|
+ db=MysqlUtils()
|
|
|
+ op1= f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
+ op2=f" and dt>='{start}' " if start else ''
|
|
|
+ op3=f" and dt<='{end}' " if end else ''
|
|
|
+ op4=f" order by {order_by} {order}" if order_by and order else ''
|
|
|
+
|
|
|
sql=f"""
|
|
|
- select formatDateTime(dt,'%Y-%m-%d') date,'{pitcher}' pitcher,cost,first_order_amount,first_roi,
|
|
|
-order_amount,today_roi,total_amount,total_cost,total_amount-total_cost total_profit,
|
|
|
-if(total_cost=0,0,total_amount/total_cost) total_roi from
|
|
|
- (select dt,
|
|
|
- round(sum(cost),2) cost,
|
|
|
- round(sum(first_order_amount),2) first_order_amount,
|
|
|
- round(if(cost=0,0,first_order_amount/cost),4) first_roi ,
|
|
|
- round(sum(order_amount),2) order_amount,
|
|
|
- round(if(cost=0,0,sum(reg_order_amount)/cost),4) today_roi
|
|
|
- from dw_daily_channel
|
|
|
- where dt>='{start}' and dt<='{end}' and pitcher='{pitcher}'
|
|
|
- group by dt) a
|
|
|
- left outer join (
|
|
|
- select dt,total_amount,total_cost from dw_daily_pitcher where pitcher='{pitcher}'
|
|
|
-) b on a.dt=b.dt
|
|
|
+ select dt date,
|
|
|
+ pitcher,cost,
|
|
|
+ first_reg_amount first_order_amount,
|
|
|
+ round(if(cost=0,0,first_reg_amount/cost),4) first_roi,
|
|
|
+ amount order_amount,
|
|
|
+ round(if(cost=0,0,reg_amount/cost),4) today_roi,
|
|
|
+ total_amount,
|
|
|
+ total_cost,
|
|
|
+ total_amount-total_cost total_profit,
|
|
|
+ if(total_cost=0,0,total_amount/total_cost) total_roi
|
|
|
+ from dw_pitcher_daily where 1=1 {op1} {op2} {op3} {op4}
|
|
|
"""
|
|
|
print(sql)
|
|
|
- total = ck.execute(f"select count(1) from ({sql}) a")[0][0]
|
|
|
- sql += f" order by {order_by} {order} limit {(page-1)*page_size},{page_size} "
|
|
|
- print(sql)
|
|
|
- data = ck.execute(sql)
|
|
|
-
|
|
|
-
|
|
|
- key=['date','pitcher','cost','first_order_amount','first_roi','order_amount','today_roi','total_amount','total_cost','total_profit','total_roi']
|
|
|
- print(get_dict_list(key,get_round(data)))
|
|
|
- return get_dict_list(key,get_round(data)),total
|
|
|
+ return getLimitData(db.quchen_text,sql,page,page_size)
|
|
|
|
|
|
|
|
|
def get_pitcher_panel_overview(pitcher):
|
|
|
db=MysqlUtils()
|
|
|
+ op1= f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
+
|
|
|
+
|
|
|
sql=f"""select pitcher,
|
|
|
total_cost cost,
|
|
|
total_amount amount,
|
|
|
- total_roi roi,
|
|
|
+ if(total_cost=0,0,total_amount/total_cost) roi,
|
|
|
channel_count,
|
|
|
on_channel_count,
|
|
|
off_channel_count,
|
|
|
this_month_cost this_month_cost,
|
|
|
- this_month_amount this_month_amount,
|
|
|
+ this_month_amount this_month_amount,
|
|
|
this_month_roi this_month_roi,
|
|
|
last_month_cost last_month_cost,
|
|
|
last_month_amount last_month_amount,
|
|
@@ -108,17 +93,13 @@ def get_pitcher_panel_overview(pitcher):
|
|
|
last_month_far_amount last_month_far_amount,
|
|
|
follow_user,
|
|
|
last_month_far_roi last_month_far_roi
|
|
|
- from dm_pitcher_daily_overview where dt='{du.get_n_days(0)}'"""
|
|
|
-
|
|
|
- if pitcher != 'all':
|
|
|
- sql += f" and pitcher='{pitcher}' "
|
|
|
-
|
|
|
+ from dm_pitcher_daily_overview a
|
|
|
+left join (
|
|
|
+select total_cost,total_amount,pitcher pitcher2 from dw_pitcher_daily where dt='{du.get_n_days(0)}') b on pitcher=pitcher2
|
|
|
+where 1=1 {op1}
|
|
|
+ """
|
|
|
print(sql)
|
|
|
- data=db.quchen_text.getData(sql)
|
|
|
- print(data)
|
|
|
- key=['pitcher','cost','amount','roi','channel_count','on_channel_count','off_channel_count','this_month_cost','this_month_amount','this_month_roi',
|
|
|
- 'last_month_cost','last_month_amount','last_month_roi','last_month_far_amount','follow_user','last_month_far_roi']
|
|
|
- return get_dict_list(key,get_round(data))
|
|
|
+ return db.quchen_text.getData_json(sql)
|
|
|
|
|
|
|
|
|
def get_channel_overview(channel,pitcher,start,end,page,page_size,order_by,order):
|