|
@@ -14,6 +14,8 @@ import smtplib
|
|
|
from email.mime.text import MIMEText
|
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
from sqlalchemy import create_engine
|
|
|
+
|
|
|
+
|
|
|
class CanalEmail:
|
|
|
def __init__(self):
|
|
|
self.OuterStr = "mysql+pymysql://%s:%s@%s:%d/%s" % (
|
|
@@ -38,40 +40,40 @@ from (select t1.user_id
|
|
|
t1.user_name as '绑定人名称',
|
|
|
ifnull(sum(t2.order_num),'-') as '订单数',
|
|
|
ifnull(sum(t2.valid_order_num),'-') as '有效订单数',
|
|
|
- ifnull(concat(round(sum(t2.valid_order_num) / sum(t2.order_num) * 100, 2), '%'),'-') as '有效率',
|
|
|
+ ifnull(concat(round(sum(t2.valid_order_num) / sum(t2.order_num) * 100, 2), '%%'),'-') as '有效率',
|
|
|
ifnull(round(sum(t2.order_amount) / 100, 2),'-') as '金额',
|
|
|
ifnull(round(sum(t2.regimental_promotion_amount) / 100, 2) ,'-') as '预估服务费收入',
|
|
|
ifnull( round(sum(t2.total_regimental_settle_amount) / 100, 2) ,'-') as '结算服务费收入'
|
|
|
- from {database}promoter_bind_channel_date t1
|
|
|
- left join {database}promoter_item_order_count t2
|
|
|
+ from {database}.promoter_bind_channel_date t1
|
|
|
+ left join {database}.promoter_item_order_count t2
|
|
|
on t1.promoter_id = t2.promoter_id and t1.stat_date = t2.stat_date
|
|
|
where 1 = 1
|
|
|
and t1.media_id = 2
|
|
|
- and t1.stat_date >= DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y%m01')
|
|
|
- and t1.stat_date <= DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%Y%m%d')
|
|
|
+ and t1.stat_date >= DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%%Y%%m01')
|
|
|
+ and t1.stat_date <= DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%%Y%%m%%d')
|
|
|
group by t1.user_id) t
|
|
|
left join (select user_id,
|
|
|
count(distinct promoter_id) as 'promoterCount'
|
|
|
- from {database}kuaishou_promoter
|
|
|
+ from {database}.kuaishou_promoter
|
|
|
group by user_id) tt on t.collectSampleId = tt.user_id
|
|
|
left join (select collect_sample_id as 'user_id',
|
|
|
count(distinct promoter_id) as 'sampleCount'
|
|
|
- from {database}kuaishou_item_collect_samples
|
|
|
+ from {database}.kuaishou_item_collect_samples
|
|
|
where collect_sample_status > 2
|
|
|
group by collect_sample_id) ttt on t.collectSampleId = ttt.user_id
|
|
|
left join (select collect_sample_id as 'user_id',
|
|
|
count(1) as 'sendTotalCount',
|
|
|
count(distinct promoter_id) as 'sendPromoterCount',
|
|
|
count(distinct item_id) as 'sendItemCount'
|
|
|
- from {database}kuaishou_item_collect_samples
|
|
|
+ from {database}.kuaishou_item_collect_samples
|
|
|
where collect_sample_status > 2
|
|
|
- and create_time >= str_to_date(concat(date_format(DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01'), '%Y-%m-%d'), '00:00:01'), '%Y-%m-%d
|
|
|
- %H:%i:%s')
|
|
|
- and create_time <=
|
|
|
- str_to_date(concat(date_format(DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%Y-%m-%d'), '%Y-%m-%d'), '23:59:59'), '%Y-%m-%d %H:%i:%s')
|
|
|
+
|
|
|
+ and create_time >= DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%%Y-%%m-01')
|
|
|
+
|
|
|
+ and create_time < date_sub(DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%%Y-%%m-%%d'),interval -1 day)
|
|
|
group by collect_sample_id) tttt on t.collectSampleId = tttt.user_id
|
|
|
left join (select user_id, promoters_count
|
|
|
- from {database}user_promoters_count
|
|
|
+ from {database}.user_promoters_count
|
|
|
where media_id = 2) ttttt
|
|
|
on t.collectSampleId = ttttt.user_id
|
|
|
where t.订单数 > 0
|
|
@@ -84,7 +86,7 @@ order by t.订单数 desc
|
|
|
pd.read_sql(sql, self.OuterConn).to_excel(path, index=False, engine='openpyxl')
|
|
|
my_sender = 'renyupeng@c-top.com.cn' # 发件人邮箱账号
|
|
|
my_pass = 'fcyJKkHUyPo6Zztw' # 发件人邮箱授权码 / 腾讯企业邮箱请使用登陆密码
|
|
|
- recipients = ['niuxiaoyu@c-top.com.cn','lishiwei@c-top.com.cn'] # 收件人邮箱账号
|
|
|
+ recipients = ['niuxiaoyu@c-top.com.cn', 'lishiwei@c-top.com.cn'] # 收件人邮箱账号
|
|
|
# content = "Please check the attachment. "
|
|
|
msg = MIMEMultipart()
|
|
|
# [发件人的邮箱昵称、发件人邮箱账号], 昵称随便
|