|
@@ -600,19 +600,15 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
|
|
|
if user_id in super_auth(): # 超级数据权限
|
|
|
op = ''
|
|
|
else:
|
|
|
- user_name = UserAuthUtils.get_user_name_by_id(user_id)
|
|
|
- auth_user_li = UserAuthUtils.get_auth_user(user_id)
|
|
|
- if len(UserAuthUtils.get_auth_user(user_id)) == 0: # 属于普通用户
|
|
|
- op = f" and pitcher='{user_name}'"
|
|
|
- else:
|
|
|
- op = f" and pitcher in {tuple(auth_user_li+[user_name])}"
|
|
|
+ channel_li = UserAuthUtils.get_auth_channel()
|
|
|
+ op = f" and a.channel in {tuple(channel_li)}"
|
|
|
|
|
|
op1=f" and a.channel='{channel}'" if channel else ''
|
|
|
op2=f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
op4=f" and location='{location}' " if location else ''
|
|
|
op5=f" and state='{state}'" if state else ''
|
|
|
op6=f" and a.dt>='{start}'" if start else ''
|
|
|
- op7=f" and a.dt<='{end}'" if end else ''
|
|
|
+ op7 =f" and a.dt<='{end}'" if end else ''
|
|
|
|
|
|
|
|
|
sql = f"""SELECT channel,
|
|
@@ -640,10 +636,9 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
|
|
|
|
|
|
from dw_channel a
|
|
|
left join dw_channel_amount_daily_reverse b using (dt,channel)
|
|
|
- where 1=1 {op} {op1} {op2} {op6} {op7} GROUP BY a.channel,type,pitcher,stage) x
|
|
|
+ where 1=1 {op} {op1} {op2} {op6} {op7} GROUP BY a.channel) x
|
|
|
having 1=1 {op4} {op5} ORDER BY {order_by} {order}
|
|
|
|
|
|
-
|
|
|
"""
|
|
|
print(sql)
|
|
|
sumsql=f"""select '总计' channel,
|
|
@@ -663,6 +658,74 @@ def get_channel_summary(user_id,channel,pitcher,page,page_size,order_by,order,st
|
|
|
return getLimitSumData(db.dm,sql,sumsql,page,page_size)
|
|
|
|
|
|
|
|
|
+def get_pitcher_channel_summary(user_id, channel, pitcher, page, page_size, order_by, order, state, location, start, end):
|
|
|
+ """投手投放号"""
|
|
|
+
|
|
|
+ db = MysqlUtils()
|
|
|
+
|
|
|
+ if user_id in super_auth(): # 超级数据权限
|
|
|
+ op = ''
|
|
|
+ else:
|
|
|
+ user_name_li = UserAuthUtils.get_auth_user(user_id)
|
|
|
+ if len(user_name_li) == 1:
|
|
|
+ op = f" and pitcher='{user_name_li[0]}'"
|
|
|
+ else:
|
|
|
+ op = f" and pitcher in {tuple(user_name_li)}"
|
|
|
+
|
|
|
+ op1 = f" and a.channel='{channel}'" if channel else ''
|
|
|
+ op2 = f" and pitcher='{pitcher}'" if pitcher else ''
|
|
|
+ op4 = f" and location='{location}' " if location else ''
|
|
|
+ op5 = f" and state='{state}'" if state else ''
|
|
|
+ op6 = f" and a.dt>='{start}'" if start else ''
|
|
|
+ op7 = f" and a.dt<='{end}'" if end else ''
|
|
|
+
|
|
|
+ sql = f"""SELECT channel,
|
|
|
+ if(end>date_sub(now(),interval 10 day),'在投','停投') state,
|
|
|
+ location,start,end,total_cost,total_amount,
|
|
|
+ total_amount-total_cost profit,
|
|
|
+ if(total_cost=0,0,round(total_amount/total_cost,4)) roi,
|
|
|
+ follow_user,
|
|
|
+ if(follow_user=0,0,round(total_cost/follow_user,2)) follow_per_cost,
|
|
|
+ order_user,
|
|
|
+ if(follow_user=0,0,round(order_user/follow_user,4)) order_tran_rate,
|
|
|
+ if(order_user=0,0,round(total_cost/order_user,2)) order_tran_cost,
|
|
|
+ pitcher,stage,td_amount,yd_amount,byd_amount
|
|
|
+ FROM
|
|
|
+ (select
|
|
|
+ channel,pitcher,stage,
|
|
|
+ type location,
|
|
|
+ min(if(cost>0,dt,null)) start,
|
|
|
+ max(if(cost>0,dt,null)) end,
|
|
|
+ sum(cost) total_cost,
|
|
|
+ sum(reg_order_amount) total_amount,
|
|
|
+ sum(follow_user) follow_user,
|
|
|
+ sum(reg_order_user) order_user,
|
|
|
+ sum(ba1) td_amount,sum(ba2) yd_amount,sum(ba3) byd_amount
|
|
|
+
|
|
|
+ from dw_channel a
|
|
|
+ left join dw_channel_amount_daily_reverse b using (dt,channel)
|
|
|
+ where 1=1 {op} {op1} {op2} {op6} {op7} GROUP BY a.channel,type,pitcher,stage) x
|
|
|
+ having 1=1 {op4} {op5} ORDER BY {order_by} {order}
|
|
|
+
|
|
|
+ """
|
|
|
+ print(sql)
|
|
|
+ sumsql = f"""select '总计' channel,
|
|
|
+ sum(total_cost) total_cost,
|
|
|
+ sum(total_amount) total_amount,sum(profit) profit,
|
|
|
+ round(sum(total_amount)/sum(total_cost),4) roi,
|
|
|
+ sum(follow_user) follow_user,
|
|
|
+ sum(order_user) order_user,
|
|
|
+ round(sum(total_cost)/sum(follow_user),2) follow_per_cost,
|
|
|
+ round(sum(order_user)/sum(follow_user),4) order_tran_rate,
|
|
|
+ round(sum(total_cost)/sum(order_user),2) order_tran_cost ,
|
|
|
+ sum(td_amount) td_amount,sum(yd_amount) yd_amount,sum(byd_amount) byd_amount
|
|
|
+ from ({sql}) a
|
|
|
+
|
|
|
+ """
|
|
|
+
|
|
|
+ return getLimitSumData(db.dm, sql, sumsql, page, page_size)
|
|
|
+
|
|
|
+
|
|
|
def get_pitcher_trend(pitcher,start=None,end=None,page=None,page_size=None,order_by=None,order=None):
|
|
|
|
|
|
db=MysqlUtils()
|