|
@@ -7,9 +7,9 @@ ck = CkUtils()
|
|
|
db = MysqlUtils()
|
|
|
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={}
|
|
@@ -17,21 +17,27 @@ def get_channel_belong_pitcher(channel):
|
|
|
di[i[1]]=i[0]
|
|
|
return di.get(channel,'')
|
|
|
|
|
|
+"""根据名字获取其归属的公众号"""
|
|
|
+def get_channels_from_user(user):
|
|
|
+ sql=f"""SELECT a.nick_name FROM t_mp_account a
|
|
|
+ left join t_sys_user b on a.oper_user_id=b.user_id where b.nick_name='{user}'"""
|
|
|
+ return tuple(db.zx.getOneList(sql))
|
|
|
+
|
|
|
|
|
|
|
|
|
def get_pitcher_panel_channel(pitcher,channel,start,end,page,page_size,order_by,order):
|
|
|
|
|
|
sql=f"""select channel,stage,platform,book,
|
|
|
formatDateTime(dt,'%Y-%m-%d') as date,
|
|
|
- cost,
|
|
|
- first_order_amount,
|
|
|
+ toDecimal32(cost,2),
|
|
|
+ toDecimal32(first_order_amount,2),
|
|
|
toDecimal32(if(cost=0,0,first_order_amount/cost),4) first_roi,
|
|
|
first_order_user,first_order_count,
|
|
|
toDecimal32(if(first_order_user=0,0,cost/first_order_user),2) 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,
|
|
|
- total_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 pitcher!='all':
|
|
@@ -149,7 +155,8 @@ def get_channel_overview(channel,pitcher,start,end,page,page_size,order_by,order
|
|
|
if end!='':
|
|
|
sql+=f" and dt<='{end}'"
|
|
|
if pitcher!='':
|
|
|
- sql+=f" and pitcher='{pitcher}'"
|
|
|
+ if pitcher!='赞象 admin':
|
|
|
+ sql+=f" and channel in {get_channels_from_user(pitcher)}"
|
|
|
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)
|
|
@@ -326,8 +333,7 @@ select
|
|
|
|
|
|
|
|
|
def get_channel_active(channel,pitcher,start,end,page,page_size,order_by,order):
|
|
|
- if get_channel_belong_pitcher(channel)!=pitcher:
|
|
|
- return [],0
|
|
|
+ channels=f' and channel in {get_channels_from_user(pitcher)} ' if pitcher !='赞象 admin' else ''
|
|
|
|
|
|
sql=f"""select formatDateTime(a.dt,'%Y-%m-%d') date, '{channel}' channel,book,toDecimal32(cost,2),toDecimal32(reg_amount,2),roi,new_follow_user,toDecimal32(new_follow_per_cost,2),order_user,order_count,
|
|
|
toDecimal32(order_user_per_cost,2),day7_avg_act_rate,toDecimal32(day7_avg_act_per_cost,2),day30_avg_act_rate,toDecimal32(ay30_avg_act_cost,2),
|
|
@@ -378,7 +384,7 @@ select dt,book,cost,
|
|
|
if(follow_user=0,0,reg_order_user30/follow_user) day30_avg_act_rate,
|
|
|
if(reg_order_user30=0,0,cost/reg_order_user30) ay30_avg_act_cost,
|
|
|
if(reg_order_user=0,0,cost/reg_order_user) act_per_cost
|
|
|
- from dw_daily_channel where channel='{channel}' and dt>='{start}' and dt<='{end}') a
|
|
|
+ from dw_daily_channel where channel='{channel}' {channels} and dt>='{start}' and dt<='{end}') a
|
|
|
left outer join (
|
|
|
|
|
|
select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,
|
|
@@ -451,8 +457,7 @@ select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,
|
|
|
return li,total
|
|
|
|
|
|
def get_channel_order_trend(channel,pitcher,start,end,page,page_size,order_by,order):
|
|
|
- if get_channel_belong_pitcher(channel)!=pitcher:
|
|
|
- return [],0
|
|
|
+ channels = f' and channel in {get_channels_from_user(pitcher)} ' if pitcher != '赞象 admin' else ''
|
|
|
sql=f"""select '{channel}' channel,toString(dt) date,book,toDecimal32(cost,2),toDecimal32(reg_order_amount,2),roi,new_follow_user,new_follow_per_cost,order_user,order_count,
|
|
|
toDecimal32(order_user_per_cost,2),
|
|
|
concat(toString(r1),',',toString(r1/cost),',', toString(a1/cost),',',toString(b1)),
|
|
@@ -526,7 +531,7 @@ select dt,book,cost,reg_order_amount,
|
|
|
if(follow_user=0,0,cost/follow_user) new_follow_per_cost,
|
|
|
reg_order_user order_user, reg_order_count order_count,
|
|
|
if(reg_order_user=0,0,cost/reg_order_user) order_user_per_cost
|
|
|
- from dw_daily_channel where dt>='{start}' and dt<='{end}' and channel='{channel}' and cost>0) a
|
|
|
+ from dw_daily_channel where dt>='{start}' and dt<='{end}' and channel='{channel}' {channels} and cost>0) a
|
|
|
|
|
|
left outer join (
|
|
|
select toDate(formatDateTime(reg_time,'%Y-%m-%d')) dt,
|
|
@@ -656,7 +661,7 @@ r60-r59 a60,if(r1=0,0,r60/r1) b60,
|
|
|
r90-r60 a90,if(r1=0,0,r90/r1) b90,
|
|
|
r120-r90 a120,if(r1=0,0,r120/r1) b120,
|
|
|
r150-r120 a150,if(r1=0,0,r150/r1) b150
|
|
|
-from order where channel='{channel}' and dt>='{start}' group by formatDateTime(reg_time,'%Y-%m-%d')
|
|
|
+from order where channel='{channel}' {channels} and dt>='{start}' group by formatDateTime(reg_time,'%Y-%m-%d')
|
|
|
) b on a.dt=b.dt
|
|
|
"""
|
|
|
if start==end:
|
|
@@ -765,7 +770,6 @@ if __name__ == '__main__':
|
|
|
# a=get_channel_active('玉龙书社','2020-09-15','2020-09-20',1,10,'date','desc')
|
|
|
# a,b =get_channel_order_trend("玉龙书社",'王俊杰','2020-12-01','2020-12-12',1,5,'date','desc')
|
|
|
# print(a)
|
|
|
- a={'a':1}
|
|
|
- print(list(a.keys()))
|
|
|
|
|
|
- pass
|
|
|
+ get_channels_from_user('叶静')
|
|
|
+
|