|  | @@ -25,20 +25,33 @@ class JianYeReport(object):
 | 
												
													
														
															|  |          'baobeidaofang'
 |  |          'baobeidaofang'
 | 
												
													
														
															|  |      ]
 |  |      ]
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    head_1 = ['城市', '项目名称', '浏览量', '浏览人数', '新增用户', '新增获电', '推荐用户', '分享获电', '裂变获电',
 |  | 
 | 
												
													
														
															|  | 
 |  | +    head_1 = ['区域', '城市', '项目名称', '浏览量', '浏览人数', '新增用户', '新增获电', '推荐用户', '分享获电', '裂变获电',
 | 
												
													
														
															|  |                '扫码到访数', '全民经纪人注册数', '老业主注册数', '报备成功数', '报备到访数']
 |  |                '扫码到访数', '全民经纪人注册数', '老业主注册数', '报备成功数', '报备到访数']
 | 
												
													
														
															|  |      brand_id = '13'
 |  |      brand_id = '13'
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +    head_2 = ['区域名称', '城市', '项目名称', '推荐人姓名', '推荐人手机号', '分享获电', '经纪人注册数', '报备成功数']
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  |      sheet_names_1 = ['当日数据', '当月数据', '上线以来所有数据']
 |  |      sheet_names_1 = ['当日数据', '当月数据', '上线以来所有数据']
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |      def __init__(self):
 |  |      def __init__(self):
 | 
												
													
														
															|  |          self.db = MysqlDB('bi_report')
 |  |          self.db = MysqlDB('bi_report')
 | 
												
													
														
															|  | -        time_range_1 = rpfu.get_prd_day()
 |  | 
 | 
												
													
														
															|  | -        time_range_2 = rpfu.get_time_range_month()
 |  | 
 | 
												
													
														
															|  | -        time_range_3 = rpfu.get_all_time_data_range()
 |  | 
 | 
												
													
														
															|  | -        self.pv_data_1 = self.pv_count(time_range_1)
 |  | 
 | 
												
													
														
															|  | -        self.pv_data_2 = self.pv_count(time_range_2)
 |  | 
 | 
												
													
														
															|  | -        self.pv_data_3 = self.pv_count(time_range_3)
 |  | 
 | 
												
													
														
															|  | 
 |  | +        self.time_range_1 = rpfu.get_prd_day()
 | 
												
													
														
															|  | 
 |  | +        self.time_range_2 = rpfu.get_time_range_month()
 | 
												
													
														
															|  | 
 |  | +        self.time_range_3 = rpfu.get_all_time_data_range()
 | 
												
													
														
															|  | 
 |  | +        self.pv_data_1 = self.pv_count(self.time_range_1)
 | 
												
													
														
															|  | 
 |  | +        self.pv_data_2 = self.pv_count(self.time_range_2)
 | 
												
													
														
															|  | 
 |  | +        self.pv_data_3 = self.pv_count(self.time_range_3)
 | 
												
													
														
															|  | 
 |  | +        self.house_region = self.get_house_region_info()
 | 
												
													
														
															|  | 
 |  | +        self.mail_util = EmailUtil()
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +    def get_house_region(self):
 | 
												
													
														
															|  | 
 |  | +        return self.db.select(Sql.sql_15)
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +    def get_house_region_name(self, house_id):
 | 
												
													
														
															|  | 
 |  | +        for x in self.house_region:
 | 
												
													
														
															|  | 
 |  | +            if str(x[1]) in house_id:
 | 
												
													
														
															|  | 
 |  | +                return x[3]
 | 
												
													
														
															|  | 
 |  | +        return ' '
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |      def get_city_house_id(self):
 |  |      def get_city_house_id(self):
 | 
												
													
														
															|  |          return self.db.select(Sql.sql_1)
 |  |          return self.db.select(Sql.sql_1)
 | 
												
											
												
													
														
															|  | @@ -56,7 +69,7 @@ class JianYeReport(object):
 | 
												
													
														
															|  |          """
 |  |          """
 | 
												
													
														
															|  |          month_day = rpfu.get_montho_day()
 |  |          month_day = rpfu.get_montho_day()
 | 
												
													
														
															|  |          if type == 1:
 |  |          if type == 1:
 | 
												
													
														
															|  | -            return '[{}]{}数据报表_{}'.format(month_day, region_name, name)
 |  | 
 | 
												
													
														
															|  | 
 |  | +            return ['[{}]{}数据报表_{}_项目明细'.format(month_day, region_name, name), '[{}]{}数据报表_{}_置业顾问完成情况'.format(month_day, region_name, name)]
 | 
												
													
														
															|  |          elif type == 2:
 |  |          elif type == 2:
 | 
												
													
														
															|  |              return '[{}]建业云集团数据报表_{}'.format(month_day, name)
 |  |              return '[{}]建业云集团数据报表_{}'.format(month_day, name)
 | 
												
													
														
															|  |          elif type == 3:
 |  |          elif type == 3:
 | 
												
											
												
													
														
															|  | @@ -178,12 +191,9 @@ class JianYeReport(object):
 | 
												
													
														
															|  |          :return:
 |  |          :return:
 | 
												
													
														
															|  |          """
 |  |          """
 | 
												
													
														
															|  |          result = []
 |  |          result = []
 | 
												
													
														
															|  | -        time_rang_1 = rpfu.get_prd_day()
 |  | 
 | 
												
													
														
															|  | -        time_rang_2 = rpfu.get_time_range_month()
 |  | 
 | 
												
													
														
															|  | -        time_range_3 = rpfu.get_all_time_data_range()
 |  | 
 | 
												
													
														
															|  | -        result.extend(self.brand_data_of_time(time_rang_1, 1))
 |  | 
 | 
												
													
														
															|  | -        result.extend(self.brand_data_of_time(time_rang_2, 2))
 |  | 
 | 
												
													
														
															|  | -        result.extend(self.brand_data_of_time(time_range_3, 3))
 |  | 
 | 
												
													
														
															|  | 
 |  | +        result.extend(self.brand_data_of_time(self.time_range_1, 1))
 | 
												
													
														
															|  | 
 |  | +        result.extend(self.brand_data_of_time(self.time_range_2, 2))
 | 
												
													
														
															|  | 
 |  | +        result.extend(self.brand_data_of_time(self.time_range_3, 3))
 | 
												
													
														
															|  |          return result
 |  |          return result
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |      def get_house_pv_data(self, house_id, time_type):
 |  |      def get_house_pv_data(self, house_id, time_type):
 | 
												
											
												
													
														
															|  | @@ -229,6 +239,11 @@ class JianYeReport(object):
 | 
												
													
														
															|  |          result = []
 |  |          result = []
 | 
												
													
														
															|  |          for id in house_ids:
 |  |          for id in house_ids:
 | 
												
													
														
															|  |              sub = []
 |  |              sub = []
 | 
												
													
														
															|  | 
 |  | +            for x in self.house_region:
 | 
												
													
														
															|  | 
 |  | +                if x[0] == str(id):
 | 
												
													
														
															|  | 
 |  | +                    sub.append(x[1])
 | 
												
													
														
															|  | 
 |  | +            if len(sub) == 0:
 | 
												
													
														
															|  | 
 |  | +                sub.append(' ')
 | 
												
													
														
															|  |              for x in city_info:
 |  |              for x in city_info:
 | 
												
													
														
															|  |                  if str(id) == str(x[1]):
 |  |                  if str(id) == str(x[1]):
 | 
												
													
														
															|  |                      sub.extend([x[3], x[2]])
 |  |                      sub.extend([x[3], x[2]])
 | 
												
											
												
													
														
															|  | @@ -244,17 +259,20 @@ class JianYeReport(object):
 | 
												
													
														
															|  |                  if str(id) == str(x[0]):
 |  |                  if str(id) == str(x[0]):
 | 
												
													
														
															|  |                      sub.extend(x[1:])
 |  |                      sub.extend(x[1:])
 | 
												
													
														
															|  |              result.append(sub)
 |  |              result.append(sub)
 | 
												
													
														
															|  | -        result.sort(key=lambda obj: obj[5], reverse=True)
 |  | 
 | 
												
													
														
															|  | 
 |  | +        result.sort(key=lambda obj: obj[6], reverse=True)
 | 
												
													
														
															|  |          return result
 |  |          return result
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |      def house_data(self, house_ids):
 |  |      def house_data(self, house_ids):
 | 
												
													
														
															|  | -        time_range_1 = rpfu.get_prd_day()
 |  | 
 | 
												
													
														
															|  | -        time_range_2 = rpfu.get_time_range_month()
 |  | 
 | 
												
													
														
															|  | -        time_range_3 = rpfu.get_all_time_data_range()
 |  | 
 | 
												
													
														
															|  | -        result = [self.house_data_of_time(time_range_1, house_ids, 1), self.house_data_of_time(time_range_2, house_ids, 2),
 |  | 
 | 
												
													
														
															|  | -                  self.house_data_of_time(time_range_3, house_ids, 3)]
 |  | 
 | 
												
													
														
															|  | 
 |  | +        result = [self.house_data_of_time(self.time_range_1, house_ids, 1), self.house_data_of_time(self.time_range_2, house_ids, 2),
 | 
												
													
														
															|  | 
 |  | +                  self.house_data_of_time(self.time_range_3, house_ids, 3)]
 | 
												
													
														
															|  |          return result
 |  |          return result
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +    def get_table_3(self, house_ids):
 | 
												
													
														
															|  | 
 |  | +        day_data = self.db.select(Sql.sql_16, [self.time_range_1[0], house_ids])
 | 
												
													
														
															|  | 
 |  | +        month_data = self.db.select(Sql.sql_17, [self.time_range_2[1], house_ids])
 | 
												
													
														
															|  | 
 |  | +        all_data = self.db.select(Sql.sql_18, [self.time_range_3[1], house_ids])
 | 
												
													
														
															|  | 
 |  | +        return [day_data, month_data, all_data]
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  |      def get_house_region_info(self):
 |  |      def get_house_region_info(self):
 | 
												
													
														
															|  |          return self.db.select(Sql.sql_15)
 |  |          return self.db.select(Sql.sql_15)
 | 
												
													
														
															|  |  
 |  |  
 | 
												
											
												
													
														
															|  | @@ -264,17 +282,8 @@ class JianYeReport(object):
 | 
												
													
														
															|  |          :param: task_key
 |  |          :param: task_key
 | 
												
													
														
															|  |          :return:
 |  |          :return:
 | 
												
													
														
															|  |          """
 |  |          """
 | 
												
													
														
															|  | -        # 邮件发送参数
 |  | 
 | 
												
													
														
															|  | -        #                             mail_title,
 |  | 
 | 
												
													
														
															|  | -        #                             content,
 |  | 
 | 
												
													
														
															|  | -        #                             receiver,
 |  | 
 | 
												
													
														
															|  | -        #                             mail_excel,
 |  | 
 | 
												
													
														
															|  | -        #                             file_name,
 |  | 
 | 
												
													
														
															|  | -        #                             mail_excel_1=None,
 |  | 
 | 
												
													
														
															|  | -        #                             file_name_1=None
 |  | 
 | 
												
													
														
															|  |          message = {}
 |  |          message = {}
 | 
												
													
														
															|  |          send_mail_info = []
 |  |          send_mail_info = []
 | 
												
													
														
															|  | -        mail_util = EmailUtil()
 |  | 
 | 
												
													
														
															|  |          rfu = ReportFileUtils()
 |  |          rfu = ReportFileUtils()
 | 
												
													
														
															|  |          customers = self.get_report_customers(task_key)
 |  |          customers = self.get_report_customers(task_key)
 | 
												
													
														
															|  |          message[0] = '客户信息获取成功'
 |  |          message[0] = '客户信息获取成功'
 | 
												
											
												
													
														
															|  | @@ -284,25 +293,13 @@ class JianYeReport(object):
 | 
												
													
														
															|  |          try:
 |  |          try:
 | 
												
													
														
															|  |              save_path = FileUtil().save_path_create()
 |  |              save_path = FileUtil().save_path_create()
 | 
												
													
														
															|  |              send_data = []
 |  |              send_data = []
 | 
												
													
														
															|  | -            # 查询数据
 |  | 
 | 
												
													
														
															|  |              if task_key == 12:
 |  |              if task_key == 12:
 | 
												
													
														
															|  | -                # 集团信息计算一次发送给多个人
 |  | 
 | 
												
													
														
															|  |                  brand_table_one = self.brand_data()
 |  |                  brand_table_one = self.brand_data()
 | 
												
													
														
															|  |                  message['brand'] = 'success'
 |  |                  message['brand'] = 'success'
 | 
												
													
														
															|  |                  house_ids = self.get_house_id_by_brand_id('13')
 |  |                  house_ids = self.get_house_id_by_brand_id('13')
 | 
												
													
														
															|  |                  brand_table_two = self.house_data(house_ids)
 |  |                  brand_table_two = self.house_data(house_ids)
 | 
												
													
														
															|  |                  message['house'] = 'success'
 |  |                  message['house'] = 'success'
 | 
												
													
														
															|  | -                # 总浏览量:xx ,总浏览人数:xx
 |  | 
 | 
												
													
														
															|  | -                #
 |  | 
 | 
												
													
														
															|  | -                # 新增获客: xx, 新增获电:xx
 |  | 
 | 
												
													
														
															|  | -                #
 |  | 
 | 
												
													
														
															|  | -                # 推荐用户数:xx,分享获电:xx,裂变获电:xx
 |  | 
 | 
												
													
														
															|  | -                #
 |  | 
 | 
												
													
														
															|  | -                # 全民经纪人注册数:xx
 |  | 
 | 
												
													
														
															|  | -                #
 |  | 
 | 
												
													
														
															|  | -                # 报备成功数:xx,报备到访数:xx
 |  | 
 | 
												
													
														
															|  |              for customer in customers:
 |  |              for customer in customers:
 | 
												
													
														
															|  | -                # a.task_key, b.customer_type, b.name, b.mail, b.house_or_region, a.customer_id, GROUP_CONCAT(c.house_or_brand_id) as ids
 |  | 
 | 
												
													
														
															|  |                  name = customer[2]
 |  |                  name = customer[2]
 | 
												
													
														
															|  |                  customer_type = customer[1]
 |  |                  customer_type = customer[1]
 | 
												
													
														
															|  |                  mail = customer[3]
 |  |                  mail = customer[3]
 | 
												
											
												
													
														
															|  | @@ -313,60 +310,51 @@ class JianYeReport(object):
 | 
												
													
														
															|  |                  file_path = save_path + '/' + title + '.xls'
 |  |                  file_path = save_path + '/' + title + '.xls'
 | 
												
													
														
															|  |                  try:
 |  |                  try:
 | 
												
													
														
															|  |                      if customer_type == 2:
 |  |                      if customer_type == 2:
 | 
												
													
														
															|  | -                        # 集团
 |  | 
 | 
												
													
														
															|  |                          content = self.get_brand_content(content, brand_table_one)
 |  |                          content = self.get_brand_content(content, brand_table_one)
 | 
												
													
														
															|  |                          send_data.append(
 |  |                          send_data.append(
 | 
												
													
														
															|  |                              [brand_table_two, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1],
 |  |                              [brand_table_two, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1],
 | 
												
													
														
															|  |                               file_path, content, name, mail])
 |  |                               file_path, content, name, mail])
 | 
												
													
														
															|  | -                        # rfu.create_excel_file(table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], file_path)
 |  | 
 | 
												
													
														
															|  |                      elif customer_type == 1:
 |  |                      elif customer_type == 1:
 | 
												
													
														
															|  | -                        # 项目
 |  | 
 | 
												
													
														
															|  | 
 |  | +                        title_1, title_2 = title[0], title[1]
 | 
												
													
														
															|  |                          table_2 = self.house_data(self.get_house_ids(ids))
 |  |                          table_2 = self.house_data(self.get_house_ids(ids))
 | 
												
													
														
															|  | 
 |  | +                        table_3 = self.get_table_3(self.get_house_ids(ids))
 | 
												
													
														
															|  | 
 |  | +                        file_path_1 = save_path + '/' + title_2 + '.xls'
 | 
												
													
														
															|  |                          send_data.append(
 |  |                          send_data.append(
 | 
												
													
														
															|  | -                            [table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], file_path,
 |  | 
 | 
												
													
														
															|  | -                             content, name, mail])
 |  | 
 | 
												
													
														
															|  | -                        # rfu.create_excel_file(table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], file_path)
 |  | 
 | 
												
													
														
															|  | 
 |  | +                            [table_2, self.sheet_names_1, title_1, [self.head_1, self.head_1, self.head_1], file_path,
 | 
												
													
														
															|  | 
 |  | +                             content, name, mail, title_2, [self.head_2, self.head_2, self.head_2], table_3, file_path_1])
 | 
												
													
														
															|  |                      elif customer_type == 3:
 |  |                      elif customer_type == 3:
 | 
												
													
														
															|  | -                        # 区域
 |  | 
 | 
												
													
														
															|  |                          table_2 = self.house_data(self.get_house_ids(ids))
 |  |                          table_2 = self.house_data(self.get_house_ids(ids))
 | 
												
													
														
															|  |                          send_data.append(
 |  |                          send_data.append(
 | 
												
													
														
															|  |                              [table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], file_path,
 |  |                              [table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], file_path,
 | 
												
													
														
															|  |                               content, name, mail])
 |  |                               content, name, mail])
 | 
												
													
														
															|  | -                        # rfu.create_excel_file(table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], file_path)
 |  | 
 | 
												
													
														
															|  |                      else:
 |  |                      else:
 | 
												
													
														
															|  |                          send_mail_log.append([name, mail, title, -1, '客户类型错误{}'.format(customer_type)])
 |  |                          send_mail_log.append([name, mail, title, -1, '客户类型错误{}'.format(customer_type)])
 | 
												
													
														
															|  |                          pass
 |  |                          pass
 | 
												
													
														
															|  |                  except Exception as e:
 |  |                  except Exception as e:
 | 
												
													
														
															|  |                      print(str(e))
 |  |                      print(str(e))
 | 
												
													
														
															|  | -                    #  # name, mail, report_name, push_time, send_status, status, error_message
 |  | 
 | 
												
													
														
															|  |                      send_mail_log.append([name, mail, title, -1, '数据查询失败:{}'.format(str(e))])
 |  |                      send_mail_log.append([name, mail, title, -1, '数据查询失败:{}'.format(str(e))])
 | 
												
													
														
															|  |              message['query_data'] = 'success'
 |  |              message['query_data'] = 'success'
 | 
												
													
														
															|  | -            # 生成文件
 |  | 
 | 
												
													
														
															|  |              for data in send_data:
 |  |              for data in send_data:
 | 
												
													
														
															|  |                  try:
 |  |                  try:
 | 
												
													
														
															|  | 
 |  | +                    send_mai_info_sub = []
 | 
												
													
														
															|  |                      rfu.create_excel_file(data[0], data[1], data[2], data[3], data[4])
 |  |                      rfu.create_excel_file(data[0], data[1], data[2], data[3], data[4])
 | 
												
													
														
															|  | -                    # [title, content, mail, file_path, title + '.xlsx', name]
 |  | 
 | 
												
													
														
															|  | -                    send_mail_info.append([data[2], data[5], data[7], data[4], data[2] + '.xls', data[6]])
 |  | 
 | 
												
													
														
															|  | 
 |  | +                    send_mai_info_sub.extend([data[2], data[5], data[7], data[4], data[2] + '.xls', data[6]])
 | 
												
													
														
															|  | 
 |  | +                    if len(data) == 11:
 | 
												
													
														
															|  | 
 |  | +                        rfu.create_excel_file(data[10], data[1], data[8], data[9], data[11])
 | 
												
													
														
															|  | 
 |  | +                        send_mai_info_sub.extend([data[11], data[8] + '.xls'])
 | 
												
													
														
															|  | 
 |  | +                    send_mail_info.append(send_mai_info_sub)
 | 
												
													
														
															|  |                  except Exception as e:
 |  |                  except Exception as e:
 | 
												
													
														
															|  |                      print(e)
 |  |                      print(e)
 | 
												
													
														
															|  |                      send_mail_log.append([data[6], data[7], data[2], -1, '文件创建失败:{}'.format(str(e))])
 |  |                      send_mail_log.append([data[6], data[7], data[2], -1, '文件创建失败:{}'.format(str(e))])
 | 
												
													
														
															|  |              message['file'] = 'success'
 |  |              message['file'] = 'success'
 | 
												
													
														
															|  | -            # 发送邮件
 |  | 
 | 
												
													
														
															|  |              for mail in send_mail_info:
 |  |              for mail in send_mail_info:
 | 
												
													
														
															|  |                  try:
 |  |                  try:
 | 
												
													
														
															|  | -                    # for m in self.customer_mails:
 |  | 
 | 
												
													
														
															|  | -                    result = mail_util.send_mail_by_admin(mail[0], mail[1], mail[2], mail[3], mail[4])
 |  | 
 | 
												
													
														
															|  | -                    if result:
 |  | 
 | 
												
													
														
															|  | -                        # name, mail, report_name, push_time, send_status, status, error_message
 |  | 
 | 
												
													
														
															|  | -                        send_mail_log.append([mail[5], mail[2], mail[3], 1, 'success'])
 |  | 
 | 
												
													
														
															|  | -                    else:
 |  | 
 | 
												
													
														
															|  | -                        send_mail_log.append([mail[5], mail[2], mail[3], -1, '调用邮件接口失败:{}'.format(str(result))])
 |  | 
 | 
												
													
														
															|  | 
 |  | +                    self.send_mail(mail, send_mail_log)
 | 
												
													
														
															|  |                  except Exception as e:
 |  |                  except Exception as e:
 | 
												
													
														
															|  |                      print(str(e))
 |  |                      print(str(e))
 | 
												
													
														
															|  |                      message['error1'] = str(e)
 |  |                      message['error1'] = str(e)
 | 
												
													
														
															|  |                      send_mail_log.append([mail[5], mail[2], mail[3], -1, '邮件发送失败:{}'.format(str(e))])
 |  |                      send_mail_log.append([mail[5], mail[2], mail[3], -1, '邮件发送失败:{}'.format(str(e))])
 | 
												
													
														
															|  |              message['mail'] = 'success'
 |  |              message['mail'] = 'success'
 | 
												
													
														
															|  | -            # 写入日志
 |  | 
 | 
												
													
														
															|  |              self.db.add_some(Sql.sql_12, send_mail_log)
 |  |              self.db.add_some(Sql.sql_12, send_mail_log)
 | 
												
													
														
															|  |              message['log'] = 'success'
 |  |              message['log'] = 'success'
 | 
												
													
														
															|  |          except Exception as e:
 |  |          except Exception as e:
 | 
												
											
												
													
														
															|  | @@ -420,10 +408,15 @@ class JianYeReport(object):
 | 
												
													
														
															|  |                      file_path = save_path + '/' + title + '.xls'
 |  |                      file_path = save_path + '/' + title + '.xls'
 | 
												
													
														
															|  |                      if customer_type == 1:
 |  |                      if customer_type == 1:
 | 
												
													
														
															|  |                          # 项目
 |  |                          # 项目
 | 
												
													
														
															|  | -                        table_2 = self.house_data(ids)
 |  | 
 | 
												
													
														
															|  | 
 |  | +                        # 项目
 | 
												
													
														
															|  | 
 |  | +                        title_1, title_2 = title[0], title[1]
 | 
												
													
														
															|  | 
 |  | +                        table_2 = self.house_data(self.get_house_ids(ids))
 | 
												
													
														
															|  | 
 |  | +                        table_3 = self.get_table_3(self.get_house_ids(ids))
 | 
												
													
														
															|  | 
 |  | +                        file_path_1 = save_path + '/' + title_1 + '.xls'
 | 
												
													
														
															|  |                          send_data.append(
 |  |                          send_data.append(
 | 
												
													
														
															|  | -                            [table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], file_path,
 |  | 
 | 
												
													
														
															|  | -                             content, name, mail])
 |  | 
 | 
												
													
														
															|  | 
 |  | +                            [table_2, self.sheet_names_1, title_1, [self.head_1, self.head_1, self.head_1], file_path,
 | 
												
													
														
															|  | 
 |  | +                             content, name, mail, title_2, [self.head_2, self.head_2, self.head_2], table_3,
 | 
												
													
														
															|  | 
 |  | +                             file_path_1])
 | 
												
													
														
															|  |                      elif customer_type == 2:
 |  |                      elif customer_type == 2:
 | 
												
													
														
															|  |                          # 集团
 |  |                          # 集团
 | 
												
													
														
															|  |                          brand_table_one = self.brand_data()
 |  |                          brand_table_one = self.brand_data()
 | 
												
											
												
													
														
															|  | @@ -453,8 +446,15 @@ class JianYeReport(object):
 | 
												
													
														
															|  |          if len(send_data) > 0:
 |  |          if len(send_data) > 0:
 | 
												
													
														
															|  |              for data in send_data:
 |  |              for data in send_data:
 | 
												
													
														
															|  |                  try:
 |  |                  try:
 | 
												
													
														
															|  | 
 |  | +                    send_mai_info_sub = []
 | 
												
													
														
															|  |                      rfu.create_excel_file(data[0], data[1], data[2], data[3], data[4])
 |  |                      rfu.create_excel_file(data[0], data[1], data[2], data[3], data[4])
 | 
												
													
														
															|  | -                    send_mail_info.append([data[2], data[5], data[7], data[4], data[2] + '.xls', data[6]])
 |  | 
 | 
												
													
														
															|  | 
 |  | +                    # [title, content, mail, file_path, title + '.xlsx', name]
 | 
												
													
														
															|  | 
 |  | +                    send_mai_info_sub.extend([data[2], data[5], data[7], data[4], data[2] + '.xls', data[6]])
 | 
												
													
														
															|  | 
 |  | +                    if len(data) == 11:
 | 
												
													
														
															|  | 
 |  | +                        #  data, sheet_names, title, headers, file_path
 | 
												
													
														
															|  | 
 |  | +                        rfu.create_excel_file(data[10], data[1], data[8], data[9], data[4])
 | 
												
													
														
															|  | 
 |  | +                        send_mai_info_sub.extend([data[11], data[8] + '.xls'])
 | 
												
													
														
															|  | 
 |  | +                    send_mail_info.append(send_mai_info_sub)
 | 
												
													
														
															|  |                  except Exception as e:
 |  |                  except Exception as e:
 | 
												
													
														
															|  |                      print(e)
 |  |                      print(e)
 | 
												
													
														
															|  |                      message['excel文件创建失败'] = str(e)
 |  |                      message['excel文件创建失败'] = str(e)
 | 
												
											
												
													
														
															|  | @@ -462,26 +462,14 @@ class JianYeReport(object):
 | 
												
													
														
															|  |          else:
 |  |          else:
 | 
												
													
														
															|  |              message['excel_info'] = '需要生成excel的数据空'
 |  |              message['excel_info'] = '需要生成excel的数据空'
 | 
												
													
														
															|  |          # 发送邮件
 |  |          # 发送邮件
 | 
												
													
														
															|  | -        mail_util = EmailUtil()
 |  | 
 | 
												
													
														
															|  |          if len(send_data) > 0:
 |  |          if len(send_data) > 0:
 | 
												
													
														
															|  |              for mail in send_mail_info:
 |  |              for mail in send_mail_info:
 | 
												
													
														
															|  |                  try:
 |  |                  try:
 | 
												
													
														
															|  |                      if new_mail:
 |  |                      if new_mail:
 | 
												
													
														
															|  | -                        result = mail_util.send_mail_by_admin(mail[0], mail[1], new_mail, mail[3], mail[4])
 |  | 
 | 
												
													
														
															|  | -                        if result:
 |  | 
 | 
												
													
														
															|  | -                            # name, mail, report_name, push_time, send_status, status, error_message
 |  | 
 | 
												
													
														
															|  | -                            send_mail_log.append([mail[5], mail[2], mail[3], 1, 'success'])
 |  | 
 | 
												
													
														
															|  | -                        else:
 |  | 
 | 
												
													
														
															|  | -                            send_mail_log.append([mail[5], mail[2], mail[3], -1, 'fail:{}'.format(str(result))])
 |  | 
 | 
												
													
														
															|  | -                            pass
 |  | 
 | 
												
													
														
															|  | 
 |  | +                        self.send_mail(mail, send_mail_log)
 | 
												
													
														
															|  |                      else:
 |  |                      else:
 | 
												
													
														
															|  |                          for m in self.customer_mails:
 |  |                          for m in self.customer_mails:
 | 
												
													
														
															|  | -                            result = mail_util.send_mail_by_admin(mail[0], mail[1], m, mail[3], mail[4])
 |  | 
 | 
												
													
														
															|  | -                            if result:
 |  | 
 | 
												
													
														
															|  | -                                # name, mail, report_name, push_time, send_status, status, error_message
 |  | 
 | 
												
													
														
															|  | -                                send_mail_log.append([mail[5], mail[2], mail[3], 1, 'success'])
 |  | 
 | 
												
													
														
															|  | -                            else:
 |  | 
 | 
												
													
														
															|  | -                                send_mail_log.append([mail[5], mail[2], mail[3], -1, 'fail'])
 |  | 
 | 
												
													
														
															|  | 
 |  | +                            self.send_mail(m, send_mail_log)
 | 
												
													
														
															|  |                  except Exception as e:
 |  |                  except Exception as e:
 | 
												
													
														
															|  |                      print(str(e))
 |  |                      print(str(e))
 | 
												
													
														
															|  |                      message['邮件发送失败'] = str(e)
 |  |                      message['邮件发送失败'] = str(e)
 | 
												
											
												
													
														
															|  | @@ -492,11 +480,26 @@ class JianYeReport(object):
 | 
												
													
														
															|  |          self.db.add_some(Sql.sql_12, send_mail_log)
 |  |          self.db.add_some(Sql.sql_12, send_mail_log)
 | 
												
													
														
															|  |          return message
 |  |          return message
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +    def send_mail(self, mail, send_mail_log):
 | 
												
													
														
															|  | 
 |  | +        result = None
 | 
												
													
														
															|  | 
 |  | +        # for m in self.customer_mails:
 | 
												
													
														
															|  | 
 |  | +        if len(mail) == 6:
 | 
												
													
														
															|  | 
 |  | +            result = self.mail_util.send_mail_by_admin(mail[0], mail[1], mail[2], mail[3], mail[4])
 | 
												
													
														
															|  | 
 |  | +        elif len(mail) == 8:
 | 
												
													
														
															|  | 
 |  | +            result = self.mail_util.send_mail_by_admin(mail[0], mail[1], mail[2], mail[3], mail[4], mail[6],
 | 
												
													
														
															|  | 
 |  | +                                                  mail[7])
 | 
												
													
														
															|  | 
 |  | +        if result:
 | 
												
													
														
															|  | 
 |  | +            # name, mail, report_name, push_time, send_status, status, error_message
 | 
												
													
														
															|  | 
 |  | +            send_mail_log.append([mail[5], mail[2], mail[3], 1, 'success'])
 | 
												
													
														
															|  | 
 |  | +        else:
 | 
												
													
														
															|  | 
 |  | +            send_mail_log.append([mail[5], mail[2], mail[3], -1, '调用邮件接口失败:{}'.format(str(result))])
 | 
												
													
														
															|  | 
 |  | +        return send_mail_log
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  |      def get_house_ids(self, ids_str):
 |  |      def get_house_ids(self, ids_str):
 | 
												
													
														
															|  |          if str(ids_str).find(',') == -1:
 |  |          if str(ids_str).find(',') == -1:
 | 
												
													
														
															|  | -            return [ids_str]
 |  | 
 | 
												
													
														
															|  | 
 |  | +            return [str(ids_str)]
 | 
												
													
														
															|  |          else:
 |  |          else:
 | 
												
													
														
															|  | -            return [x for x in str(ids_str).split(',')]
 |  | 
 | 
												
													
														
															|  | 
 |  | +            return [str(x) for x in str(ids_str).split(',')]
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |  if __name__ == '__main__':
 |  |  if __name__ == '__main__':
 |