Browse Source

MOD:排行版cost展示修改

cxyu 3 years ago
parent
commit
ac84b6607e
1 changed files with 133 additions and 14 deletions
  1. 133 14
      data_manage/public_analysis.py

+ 133 - 14
data_manage/public_analysis.py

@@ -591,11 +591,37 @@ def advertisement_rank(user_id, start, end, type, page, page_size, order, order_
     is_video,
     use_times,
     preview_url
+    from 
+     (  select 
+    campaign_id,
+    min(dt) as dt,
+    max(stage) as stage,
+    max(platform) as platform,
+    max(book) as book,
+    max(`type`) as type, 
+    max(channel) as channel,
+    max(pitcher) as pitcher,
+    max(owner) as owner,
+    sum(cost) as cost,
+    sum(view_count) as view_count,
+    sum(click_count) as click_count,
+    sum(follow_count) as follow_count,
+    sum(order_count) as order_count,
+    sum(order_amount) as order_amount,
+    sum(use_times) as use_times,
+    max(title) as title,
+    max(description) as description,
+    max(image_id) as image_id,
+    max(is_video) as is_video,
+    max(preview_url) as preview_url
     from dw_image_cost_day
-    where replace (preview_url,' ,','') !='' 
+where replace (preview_url,' ,','') !='' 
     and (1=1 {op1}  {op_or1})  
     {op4} {op5} {op8} {op10} {op11}  {op12}  
-    {op_time_bigger} {op_time_small} 
+    {op_time_bigger} {op_time_small}
+    group by campaign_id  
+) as a
+    
      {op_order} 
     """
 
@@ -708,11 +734,34 @@ def idea_rank(user_id, start, end, page, page_size, order, order_by, book, chann
     null as videoFirstPage,
     video_length as videoLength,
     use_times as userTimes
+    from ( select
+    max(campaign_id) as campaign_id ,
+    max(book) as book,
+    min(dt) as dt,
+    max(image_id) as image_id,
+    max(`type`) as type,
+    max(owner) as owner,
+    max(download_path) as download_path,
+    max(height) as height,
+    max(width) as width,
+    max(preview_url) as preview_url,
+    max(format) as format,
+    max(size) as size,
+    sum(cost) as cost,
+    sum(view_count) as view_count,
+    sum(click_count) as click_count,
+    max(title) as title,
+    max(is_video) as is_video,
+    max(description) as description,
+    max(video_bit_rate) as video_bit_rate,
+    max(video_length) as video_length,
+    sum(use_times) as use_times
     from dw_image_cost_day
     where replace (preview_url,' ,','') !=''
      and (1=1 {op1}  {op_or1}) 
     {op4}  {op10} {op11}  {op12}  {op_campaign_id}
     {op_time_bigger} {op_time_small} 
+    group by campaign_id) as foo 
         {op_order} 
 
 '''
@@ -741,7 +790,6 @@ def media_rank(user_id, start, end, page, page_size, order, order_by, book, chan
     op4 = f" and channel='{channel}'" if channel else ''
 
     op10 = f" and book='{book}'" if book else ''
-    # TODO:添加标签相关处理------id与对应计划进行--对应
 
     op11 = f" and image_id like '%,%' " if not is_singleimg else ''
     op12 = f" and is_video" if is_video == 2 else ' and not is_video'  # 进行对应修改1----图片
@@ -753,7 +801,6 @@ def media_rank(user_id, start, end, page, page_size, order, order_by, book, chan
     op_campaign_id = f'and campaign_id in ({campaign_ids})' if campaign_ids else ''
 
     # 公共数据,和素材库一样,个人只显示个人(小组)数据
-    # TODO:之后op_or1 变化为owner来限制,------dw_image_cost_day 生成时就根据dt,cost来归类owner
     op_or1 = f' or (dt<date_add(now(),interval -5 day) or cost>5000) ' if data_type == 'all' else ''
     # clicktimes,view_times,consume_amount,click_rate---------数据进行一一对应
     if order_by == 'click_times':
@@ -775,6 +822,7 @@ def media_rank(user_id, start, end, page, page_size, order, order_by, book, chan
 
     db = MysqlUtils().dm
 
+
     sql = f'''
     select 
     campaign_id as id,
@@ -808,11 +856,35 @@ def media_rank(user_id, start, end, page, page_size, order, order_by, book, chan
     null as videoFirstPage,
     video_length as videoLength,
     use_times as userTimes
+    from 
+    ( select
+    max(campaign_id) as campaign_id ,
+    max(book) as book,
+    min(dt) as dt,
+    max(image_id) as image_id,
+    max(`type`) as type,
+    max(owner) as owner,
+    max(download_path) as download_path,
+    max(height) as height,
+    max(width) as width,
+    max(preview_url) as preview_url,
+    max(format) as format,
+    max(size) as size,
+    sum(cost) as cost,
+    sum(view_count) as view_count,
+    sum(click_count) as click_count,
+    max(title) as title,
+    max(is_video) as is_video,
+    max(description) as description,
+    max(video_bit_rate) as video_bit_rate,
+    max(video_length) as video_length,
+    sum(use_times) as use_times
     from dw_image_cost_day
         where replace (preview_url,' ,','') !=''
      and (1=1 {op1}  {op_or1}) 
     {op4}   {op10} {op11}  {op12}  {op_campaign_id}
     {op_time_bigger} {op_time_small} 
+    group by campaign_id) as foo
         {op_order} 
 
 '''
@@ -841,7 +913,6 @@ def content_rank(user_id, start, end, page, page_size, order, order_by, book, ch
 
     op4 = f" and channel='{channel}'" if channel else ''
     op10 = f" and book='{book}'" if book else ''
-    # TODO:添加标签相关处理------id与对应计划进行--对应
 
     op11 = f" and image_id like '%,%' " if not is_singleimg else ''
     op12 = f" and is_video" if is_video == 2 else ' and not is_video'  # 进行对应修改1----图片
@@ -852,7 +923,6 @@ def content_rank(user_id, start, end, page, page_size, order, order_by, book, ch
     op_campaign_id = f'and campaign_id in ({campaign_ids})' if campaign_ids else ''
 
     # 公共数据,和素材库一样,个人只显示个人(小组)数据
-    # TODO:之后op_or1 变化为owner来限制,------dw_image_cost_day 生成时就根据dt,cost来归类owner
     op_or1 = f' or (dt<date_add(now(),interval -5 day) or cost>5000) ' if data_type == 'all' else ''
     # clicktimes,view_times,consume_amount,click_rate---------数据进行一一对应
     if order_by == 'click_times':
@@ -915,12 +985,36 @@ where   REPLACE(REPLACE(title , CHAR(10), ''), CHAR(13), '')  is not null and le
     date_format( now(),'%Y-%m-%d %H:%i:%S') as upateTime,
     null as updateBy,
     use_times as userTimes
-    from 
-     dw_image_cost_day 
-    where     REPLACE(REPLACE(description, CHAR(10), ''), CHAR(13), '') is not null and length(description)>0 
+    from (
+     select
+    max(campaign_id) as campaign_id ,
+    max(book) as book,
+    min(dt) as dt,
+    max(image_id) as image_id,
+    max(`type`) as type,
+    max(owner) as owner,
+    max(download_path) as download_path,
+    max(height) as height,
+    max(width) as width,
+    max(preview_url) as preview_url,
+    max(format) as format,
+    max(size) as size,
+    sum(cost) as cost,
+    sum(view_count) as view_count,
+    sum(click_count) as click_count,
+    max(title) as title,
+    max(is_video) as is_video,
+    max(description) as description,
+    max(video_bit_rate) as video_bit_rate,
+    max(video_length) as video_length,
+    sum(use_times) as use_times
+    from dw_image_cost_day 
+    where     REPLACE(REPLACE(description, CHAR(10), ''), CHAR(13), '') is not null 
     and (1=1 {op1}  {op_or1})
     {op4}   {op10} {op11}  {op12}   {op_campaign_id}
     {op_time_bigger} {op_time_small} 
+    group by campaign_id
+    ) as foo
     limit {start_title} , {int(page_size / 2)})
 union all
 (select 
@@ -944,11 +1038,36 @@ union all
     date_format( now(),'%Y-%m-%d %H:%i:%S') as upateTime,
     null as updateBy,
     use_times as userTimes
-    from dw_image_cost_day  
-    where  REPLACE(REPLACE(title, CHAR(10), ''), CHAR(13), '') is not null and length(title)>0 
-    and (1=1 {op1}   {op_or1}) 
-      {op4}   {op10} {op11}  {op12} {op_campaign_id}
-    {op_time_bigger} {op_time_small}  
+    from  (
+     select
+    max(campaign_id) as campaign_id ,
+    max(book) as book,
+    min(dt) as dt,
+    max(image_id) as image_id,
+    max(`type`) as type,
+    max(owner) as owner,
+    max(download_path) as download_path,
+    max(height) as height,
+    max(width) as width,
+    max(preview_url) as preview_url,
+    max(format) as format,
+    max(size) as size,
+    sum(cost) as cost,
+    sum(view_count) as view_count,
+    sum(click_count) as click_count,
+    max(title) as title,
+    max(is_video) as is_video,
+    max(description) as description,
+    max(video_bit_rate) as video_bit_rate,
+    max(video_length) as video_length,
+    sum(use_times) as use_times
+    from dw_image_cost_day 
+    where     REPLACE(REPLACE(description, CHAR(10), ''), CHAR(13), '') is not null 
+    and (1=1 {op1}  {op_or1})
+    {op4}   {op10} {op11}  {op12}   {op_campaign_id}
+    {op_time_bigger} {op_time_small} 
+    group by campaign_id
+    ) as foo
     limit {start_des} , {int(page_size / 2)}
     ) 
      {op_order}