|  | @@ -412,12 +412,20 @@ class ReportPush(object):
 | 
	
		
			
				|  |  |          select house_id, house_name from d_house where brand_id = %s
 | 
	
		
			
				|  |  |      """
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    sql_5_1 = """
 | 
	
		
			
				|  |  | +        select house_id from d_house where brand_id in %s    
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      sql_6 = """insert into report_push_log(name, mail, report_name, push_time, send_status, status) values(%s, %s, 
 | 
	
		
			
				|  |  |      %s, now(), %s, 1) """
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      # 根据项目id获取集团id和名称
 | 
	
		
			
				|  |  |      sql_7 = """
 | 
	
		
			
				|  |  | -        select a.brand_id, a.brand_name from d_house a where a.house_id = %s;
 | 
	
		
			
				|  |  | +        select a.brand_id, a.brand_name from d_house a where a.house_id = %s
 | 
	
		
			
				|  |  | +    """
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    sql_8 = """
 | 
	
		
			
				|  |  | +        select DISTINCT a.brand_id from d_house a where a.house_id in %s
 | 
	
		
			
				|  |  |      """
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def __init__(self, db_name):
 | 
	
	
		
			
				|  | @@ -456,6 +464,7 @@ class ReportPush(object):
 | 
	
		
			
				|  |  |                      house_ids = [x for x in str(ids).split(',')]
 | 
	
		
			
				|  |  |                  else:
 | 
	
		
			
				|  |  |                      house_ids = [ids]
 | 
	
		
			
				|  |  | +                brand_id_list = self.get_brand_ids_by_house_ids(house_ids)
 | 
	
		
			
				|  |  |                  pass
 | 
	
		
			
				|  |  |              elif customer_type == 2:
 | 
	
		
			
				|  |  |                  # 集团
 | 
	
	
		
			
				|  | @@ -477,47 +486,47 @@ class ReportPush(object):
 | 
	
		
			
				|  |  |              result_data_7 = []
 | 
	
		
			
				|  |  |              result_data_8 = []
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +            all_house_ids = self.get_house_ids_by_brand_ids(brand_id_list)
 | 
	
		
			
				|  |  | +            xcx_top_data_part = self.filter_by_house_ids(xcx_top_data, all_house_ids)
 | 
	
		
			
				|  |  | +            brand_top_data_part = self.filter_by_brand_ids(brand_top_data, brand_id_list)
 | 
	
		
			
				|  |  | +            xcx_top_data_all_part = self.filter_by_house_ids(xcx_top_data_all, all_house_ids)
 | 
	
		
			
				|  |  | +            brand_top_data_all_part = self.filter_by_brand_ids(brand_top_data_all, brand_id_list)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              # 1 数据总览 12个统计指标
 | 
	
		
			
				|  |  |              data_overview = self.data_overview(time_range, house_ids, xcx_top_data, brand_top_data)
 | 
	
		
			
				|  |  |              result_data_1.extend(data_overview)
 | 
	
		
			
				|  |  |              # 4:单个项目小程序数据排行榜
 | 
	
		
			
				|  |  | -            for index, x in enumerate(xcx_top_data):
 | 
	
		
			
				|  |  | +            for index, x in enumerate(xcx_top_data_part):
 | 
	
		
			
				|  |  |                  if x[0] in house_ids:
 | 
	
		
			
				|  |  |                      result_data_4.append([index, x[1], x[2], x[3], x[4], x[5]])
 | 
	
		
			
				|  |  |              # 5: 集团项目数据排行榜
 | 
	
		
			
				|  |  |              if customer_type == 2:
 | 
	
		
			
				|  |  | -                for index, x2 in enumerate(brand_top_data):
 | 
	
		
			
				|  |  | +                for index, x2 in enumerate(brand_top_data_part):
 | 
	
		
			
				|  |  |                      if x2[1] in house_ids or x2[0] in brand_id_list:
 | 
	
		
			
				|  |  |                          result_data_5.append([index, x2[2], x2[3], x2[4], x2[5], x2[5], x2[6]])
 | 
	
		
			
				|  |  |                      pass
 | 
	
		
			
				|  |  |                  pass
 | 
	
		
			
				|  |  |              else:
 | 
	
		
			
				|  |  | -                for index, x1 in enumerate(brand_top_data):
 | 
	
		
			
				|  |  | +                for index, x1 in enumerate(brand_top_data_part):
 | 
	
		
			
				|  |  |                      if x1[1] in house_ids:
 | 
	
		
			
				|  |  |                          result_data_5.append([index, x1[2], x1[3], x1[4], x1[5], x1[5], x1[6]])
 | 
	
		
			
				|  |  |              # 2: 项目数据排行榜
 | 
	
		
			
				|  |  | -            house_with_brand_data = self.house_with_brand(xcx_top_data, brand_top_data)
 | 
	
		
			
				|  |  | +            house_with_brand_data = self.house_with_brand(xcx_top_data_part, brand_top_data_part)
 | 
	
		
			
				|  |  |              for index, x in enumerate(house_with_brand_data):
 | 
	
		
			
				|  |  | -                if x[1] in house_ids or x[0] in brand_id_list:
 | 
	
		
			
				|  |  | -                    obj = [index]
 | 
	
		
			
				|  |  | -                    obj.extend(x)
 | 
	
		
			
				|  |  | -                    result_data_2.append(obj)
 | 
	
		
			
				|  |  | +                if x[2] in house_ids or x[1] in brand_id_list:
 | 
	
		
			
				|  |  | +                    result_data_2.append(x)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              # 3: 项目历史累计总数
 | 
	
		
			
				|  |  |              if customer_type == 2:
 | 
	
		
			
				|  |  | -                all_data_history = self.house_with_brand(xcx_top_data_all, brand_top_data_all, brand_id_list)
 | 
	
		
			
				|  |  | +                all_data_history = self.house_with_brand(xcx_top_data_all_part, brand_top_data_all_part, brand_id_list)
 | 
	
		
			
				|  |  |                  for index, x in enumerate(all_data_history):
 | 
	
		
			
				|  |  | -                    if x[1] in house_ids or x[0] in brand_id_list:
 | 
	
		
			
				|  |  | -                        obj = [index]
 | 
	
		
			
				|  |  | -                        obj.extend(x)
 | 
	
		
			
				|  |  | -                        result_data_3.append(obj)
 | 
	
		
			
				|  |  | +                    if x[2] in house_ids or x[1] in brand_id_list:
 | 
	
		
			
				|  |  | +                        result_data_3.append(x)
 | 
	
		
			
				|  |  |              else:
 | 
	
		
			
				|  |  | -                all_data_history = self.house_with_brand(xcx_top_data_all, brand_top_data_all)
 | 
	
		
			
				|  |  | +                all_data_history = self.house_with_brand(xcx_top_data_all_part, brand_top_data_all_part)
 | 
	
		
			
				|  |  |                  for index, x in enumerate(all_data_history):
 | 
	
		
			
				|  |  | -                    if x[1] in house_ids:
 | 
	
		
			
				|  |  | -                        obj = [index]
 | 
	
		
			
				|  |  | -                        obj.extend(x)
 | 
	
		
			
				|  |  | -                        result_data_3.append(obj)
 | 
	
		
			
				|  |  | +                    if x[2] in house_ids:
 | 
	
		
			
				|  |  | +                        result_data_3.append(x)
 | 
	
		
			
				|  |  |              customer_data[1] = result_data_1
 | 
	
		
			
				|  |  |              customer_data[2] = result_data_2
 | 
	
		
			
				|  |  |              customer_data[3] = result_data_3
 | 
	
	
		
			
				|  | @@ -531,6 +540,24 @@ class ReportPush(object):
 | 
	
		
			
				|  |  |              # 6: 项目获客来源场景分析
 | 
	
		
			
				|  |  |          return result
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    def filter_by_brand_ids(self, data, brand_ids):
 | 
	
		
			
				|  |  | +        result = []
 | 
	
		
			
				|  |  | +        for x in data:
 | 
	
		
			
				|  |  | +            if x[0] in brand_ids:
 | 
	
		
			
				|  |  | +                result.append(x)
 | 
	
		
			
				|  |  | +        result.sort(key=lambda obj: obj[3])
 | 
	
		
			
				|  |  | +        result.reverse()
 | 
	
		
			
				|  |  | +        return result
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    def filter_by_house_ids(self, data, house_ids):
 | 
	
		
			
				|  |  | +        result = []
 | 
	
		
			
				|  |  | +        for x in data:
 | 
	
		
			
				|  |  | +            if x[0] in house_ids:
 | 
	
		
			
				|  |  | +                result.append(x)
 | 
	
		
			
				|  |  | +        result.sort(key=lambda obj: obj[2])
 | 
	
		
			
				|  |  | +        result.reverse()
 | 
	
		
			
				|  |  | +        return result
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      def data_overview(self, time_range, house_ids, xcx_top_data, brand_top_data):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |              统计数据总览
 | 
	
	
		
			
				|  | @@ -609,30 +636,39 @@ class ReportPush(object):
 | 
	
		
			
				|  |  |                  house_ids.append(x[1])
 | 
	
		
			
				|  |  |          for house_id in house_ids:
 | 
	
		
			
				|  |  |              a = []
 | 
	
		
			
				|  |  | +            a_order = 0
 | 
	
		
			
				|  |  |              for index, x in enumerate(xcx_top_data):
 | 
	
		
			
				|  |  |                  if str(house_id) == str(x[0]):
 | 
	
		
			
				|  |  |                      a.extend(x)
 | 
	
		
			
				|  |  | +                    a_order = index
 | 
	
		
			
				|  |  |              b = []
 | 
	
		
			
				|  |  | +            b_order = 0
 | 
	
		
			
				|  |  |              for index, y in enumerate(brand_top_data):
 | 
	
		
			
				|  |  |                  if str(house_id) == str(y[1]):
 | 
	
		
			
				|  |  |                      b.extend(y)
 | 
	
		
			
				|  |  | +                    b_order = index
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +            order = b_order if b_order > 0 else a_order
 | 
	
		
			
				|  |  |              if len(a) > 0 and len(b) > 0:
 | 
	
		
			
				|  |  | -                result.append([b[0], a[0], a[1], self.add(a[2], b[3]), self.add(a[3], b[4]), self.add(a[4], b[5]), self.add(a[5], b[6])])
 | 
	
		
			
				|  |  | +                result.append([order, b[0], a[0], a[1], self.add(a[2], b[3]), self.add(a[3], b[4]), self.add(a[4], b[5]), self.add(a[5], b[6])])
 | 
	
		
			
				|  |  |              elif len(a) > 0 and len(b) == 0:
 | 
	
		
			
				|  |  | -                _a = [1]
 | 
	
		
			
				|  |  | +                _a = [order, 1]
 | 
	
		
			
				|  |  |                  for x in a:
 | 
	
		
			
				|  |  |                      _a.append(x)
 | 
	
		
			
				|  |  |                  result.append(_a)
 | 
	
		
			
				|  |  |              elif len(a) == 0 and len(b) > 0:
 | 
	
		
			
				|  |  | -                result.append(b)
 | 
	
		
			
				|  |  | +                _b = [order]
 | 
	
		
			
				|  |  | +                _b.extend(b)
 | 
	
		
			
				|  |  | +                result.append(_b)
 | 
	
		
			
				|  |  |              else:
 | 
	
		
			
				|  |  |                  pass
 | 
	
		
			
				|  |  |          if brands:
 | 
	
		
			
				|  |  | -            for x in brand_top_data:
 | 
	
		
			
				|  |  | +            for index, x in enumerate(brand_top_data):
 | 
	
		
			
				|  |  |                  if x[0] in brands and x[1] is not None and int(x[1]) < 300:
 | 
	
		
			
				|  |  | -                    result.append(x)
 | 
	
		
			
				|  |  | -        result.sort(key=lambda obj: obj[2])
 | 
	
		
			
				|  |  | +                    _x = [index]
 | 
	
		
			
				|  |  | +                    _x.extend(x)
 | 
	
		
			
				|  |  | +                    result.append(_x)
 | 
	
		
			
				|  |  | +        result.sort(key=lambda obj: obj[3])
 | 
	
		
			
				|  |  |          result.reverse()
 | 
	
		
			
				|  |  |          return result
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -767,6 +803,22 @@ class ReportPush(object):
 | 
	
		
			
				|  |  |              return brand_info[0][0]
 | 
	
		
			
				|  |  |          return
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    def get_brand_ids_by_house_ids(self, house_ids):
 | 
	
		
			
				|  |  | +        brand_ids = self.db.select(self.sql_8, [house_ids])
 | 
	
		
			
				|  |  | +        ids = []
 | 
	
		
			
				|  |  | +        for x in brand_ids:
 | 
	
		
			
				|  |  | +            if x:
 | 
	
		
			
				|  |  | +               ids.append(x)
 | 
	
		
			
				|  |  | +        return ids
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    def get_house_ids_by_brand_ids(self, brand_ids):
 | 
	
		
			
				|  |  | +        result = []
 | 
	
		
			
				|  |  | +        ids = self.db.select(self.sql_5_1, [brand_ids])
 | 
	
		
			
				|  |  | +        for x in ids:
 | 
	
		
			
				|  |  | +            if x not in result:
 | 
	
		
			
				|  |  | +                result.append(x)
 | 
	
		
			
				|  |  | +        return result
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      def get_time_range(self, task_key):
 | 
	
		
			
				|  |  |          """
 | 
	
		
			
				|  |  |           根据定时任务id获取时间区间
 |