|  | @@ -392,6 +392,93 @@ class JianYeReport(object):
 | 
	
		
			
				|  |  |                                   )
 | 
	
		
			
				|  |  |          return content
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    def get_customer_info_by_id(self, customer_id):
 | 
	
		
			
				|  |  | +        return self.db.select(Sql.sql_14, [customer_id])
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    def send_mail_for_customer_id(self, customer_id, new_mail=None):
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +            发送指客户的邮件
 | 
	
		
			
				|  |  | +        :param task_key:
 | 
	
		
			
				|  |  | +        :return:
 | 
	
		
			
				|  |  | +        """
 | 
	
		
			
				|  |  | +        message = {}
 | 
	
		
			
				|  |  | +        customer = self.get_customer_info_by_id(customer_id)
 | 
	
		
			
				|  |  | +        message['customer'] = str(customer_id)
 | 
	
		
			
				|  |  | +        send_data = []
 | 
	
		
			
				|  |  | +        if customer:
 | 
	
		
			
				|  |  | +            try:
 | 
	
		
			
				|  |  | +                save_path = FileUtil().save_path_create()
 | 
	
		
			
				|  |  | +                name = customer[1]
 | 
	
		
			
				|  |  | +                mail = customer[2]
 | 
	
		
			
				|  |  | +                customer_type = customer[3]
 | 
	
		
			
				|  |  | +                ids = self.get_house_ids(customer[5])
 | 
	
		
			
				|  |  | +                region_name = customer[4]
 | 
	
		
			
				|  |  | +                title = self.get_mail_title(customer_type, region_name, name)
 | 
	
		
			
				|  |  | +                content = self.get_mail_content(customer_type)
 | 
	
		
			
				|  |  | +                file_path = save_path + '/' + title + '.xls'
 | 
	
		
			
				|  |  | +                if customer_type == 1:
 | 
	
		
			
				|  |  | +                    # 项目
 | 
	
		
			
				|  |  | +                    table_2 = self.house_data(self.get_house_ids(ids))
 | 
	
		
			
				|  |  | +                    send_data.append(
 | 
	
		
			
				|  |  | +                        [table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], file_path,
 | 
	
		
			
				|  |  | +                         content, name, mail])
 | 
	
		
			
				|  |  | +                elif customer_type == 2:
 | 
	
		
			
				|  |  | +                    # 集团
 | 
	
		
			
				|  |  | +                    brand_table_one = self.brand_data()
 | 
	
		
			
				|  |  | +                    house_ids = self.get_house_id_by_brand_id('13')
 | 
	
		
			
				|  |  | +                    brand_table_two = self.house_data(house_ids)
 | 
	
		
			
				|  |  | +                    content = self.get_brand_content(content, brand_table_one)
 | 
	
		
			
				|  |  | +                    send_data.append(
 | 
	
		
			
				|  |  | +                        [brand_table_two, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1],
 | 
	
		
			
				|  |  | +                         file_path, content, name, mail])
 | 
	
		
			
				|  |  | +                elif customer_type == 3:
 | 
	
		
			
				|  |  | +                    # 区域
 | 
	
		
			
				|  |  | +                    table_2 = self.house_data(self.get_house_ids(ids))
 | 
	
		
			
				|  |  | +                    message['data'] = table_2
 | 
	
		
			
				|  |  | +                    send_data.append(
 | 
	
		
			
				|  |  | +                        [table_2, self.sheet_names_1, title, [self.head_1, self.head_1, self.head_1], file_path,
 | 
	
		
			
				|  |  | +                         content, name, mail])
 | 
	
		
			
				|  |  | +                else:
 | 
	
		
			
				|  |  | +                    message['customer_type'] = '客户类型错误'
 | 
	
		
			
				|  |  | +            except Exception as e:
 | 
	
		
			
				|  |  | +                message['数据查询失败'] = str(e)
 | 
	
		
			
				|  |  | +        else:
 | 
	
		
			
				|  |  | +            message['error'] = '客户id错误:{}'.format(customer_id)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        message['query_data'] = 'success'
 | 
	
		
			
				|  |  | +        # 生成文件
 | 
	
		
			
				|  |  | +        rfu = ReportFileUtils()
 | 
	
		
			
				|  |  | +        send_mail_log = []
 | 
	
		
			
				|  |  | +        send_mail_info = []
 | 
	
		
			
				|  |  | +        for data in send_data:
 | 
	
		
			
				|  |  | +            try:
 | 
	
		
			
				|  |  | +                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]])
 | 
	
		
			
				|  |  | +            except Exception as e:
 | 
	
		
			
				|  |  | +                print(e)
 | 
	
		
			
				|  |  | +                send_mail_log.append([data[6], data[7], data[2], -1, '文件创建失败:{}'.format(str(e))])
 | 
	
		
			
				|  |  | +        message['excel文件创建失败'] = 'success'
 | 
	
		
			
				|  |  | +        # 发送邮件
 | 
	
		
			
				|  |  | +        mail_util = EmailUtil()
 | 
	
		
			
				|  |  | +        for mail in send_mail_info:
 | 
	
		
			
				|  |  | +            try:
 | 
	
		
			
				|  |  | +                if new_mail:
 | 
	
		
			
				|  |  | +                    result = mail_util.send_mail_by_admin(mail[0], mail[1], new_mail, mail[3], mail[4])
 | 
	
		
			
				|  |  | +                else:
 | 
	
		
			
				|  |  | +                    result = mail_util.send_mail_by_admin(mail[0], mail[1], mail[7], 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'])
 | 
	
		
			
				|  |  | +            except Exception as e:
 | 
	
		
			
				|  |  | +                print(str(e))
 | 
	
		
			
				|  |  | +                message['邮件发送失败'] = str(e)
 | 
	
		
			
				|  |  | +                send_mail_log.append([mail[5], mail[2], mail[3], -1, '邮件发送失败:{}'.format(str(e))])
 | 
	
		
			
				|  |  | +        # 写入日志
 | 
	
		
			
				|  |  | +        self.db.add_some(Sql.sql_12, send_mail_log)
 | 
	
		
			
				|  |  | +        pass
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      def get_house_ids(self, ids_str):
 | 
	
		
			
				|  |  |          if str(ids_str).find(',') == -1:
 | 
	
		
			
				|  |  |              return [ids_str]
 |