BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr
Adjust the CTR open rate in the campaign task statistics obtained via campaign_id
lotk15116ed7b714
diff --git a/core/internal/controller/batch_mail/batch_mail_v1_list_tasks.go b/core/internal/controller/batch_mail/batch_mail_v1_list_tasks.goindex 67b4145f..4beda4f2 100644--- a/core/internal/controller/batch_mail/batch_mail_v1_list_tasks.go+++ b/core/internal/controller/batch_mail/batch_mail_v1_list_tasks.go@@ -105,16 +105,11 @@ func GetTaskStats(ctx context.Context, taskId int64) map[string]interface{} {query = query.LeftJoin("mailstat_message_ids mi", "sm.postfix_message_id=mi.postfix_message_id")query = query.LeftJoin("recipient_info ri", "mi.message_id=ri.message_id")- query = query.LeftJoin("mailstat_opened o", "sm.postfix_message_id=o.postfix_message_id")- query = query.LeftJoin("mailstat_clicked c", "sm.postfix_message_id=c.postfix_message_id")-query = query.Where("ri.task_id = ?", taskId)query.Fields("count(*) as sends","coalesce(sum(case when sm.status='sent' and sm.dsn like '2.%' then 1 else 0 end), 0) as delivered", // success count- "count(distinct o.postfix_message_id) as opened", // opened count- "count(distinct c.postfix_message_id) as clicked", // clicked count"coalesce(sum(case when sm.status='bounced' then 1 else 0 end), 0) as bounced", // bounced count)@@ -124,18 +119,32 @@ func GetTaskStats(ctx context.Context, taskId int64) map[string]interface{} {return nil}+ sends := result["sends"].Int()+ delivered := result["delivered"].Int()+ bounced := result["bounced"].Int()++ // 通过campaign_id查打开和点击+ campaignId := int(taskId)+ openedCount, _ := g.DB().Model("mailstat_opened").+ Where("campaign_id", campaignId).+ Fields("count(distinct postfix_message_id) as opened").+ Value()+ clickedCount, _ := g.DB().Model("mailstat_clicked").+ Where("campaign_id", campaignId).+ Fields("count(distinct postfix_message_id) as clicked").+ Value()+stats := map[string]interface{}{- "sends": result["sends"].Int(),- "delivered": result["delivered"].Int(),- "opened": result["opened"].Int(),- "clicked": result["clicked"].Int(),- "bounced": result["bounced"].Int(),+ "sends": sends,+ "delivered": delivered,+ "opened": openedCount.Int(),+ "clicked": clickedCount.Int(),+ "bounced": bounced,}- sends := stats["sends"].(int)if sends > 0 {- stats["delivery_rate"] = public.Round(float64(stats["delivered"].(int))/float64(sends)*100, 2)- stats["bounce_rate"] = public.Round(float64(stats["bounced"].(int))/float64(sends)*100, 2)+ stats["delivery_rate"] = public.Round(float64(delivered)/float64(sends)*100, 2)+ stats["bounce_rate"] = public.Round(float64(bounced)/float64(sends)*100, 2)stats["open_rate"] = public.Round(float64(stats["opened"].(int))/float64(sends)*100, 2)stats["click_rate"] = public.Round(float64(stats["clicked"].(int))/float64(sends)*100, 2)} else {diff --git a/core/internal/service/batch_mail/stat_service.go b/core/internal/service/batch_mail/stat_service.goindex 144239a7..33a4c722 100644--- a/core/internal/service/batch_mail/stat_service.go+++ b/core/internal/service/batch_mail/stat_service.go@@ -90,14 +90,9 @@ func (s *TaskStatService) prepareChartData(startTime, endTime int64) (string, stfunc (s *TaskStatService) getTaskDashboard(taskId int64, domain string, startTime, endTime int64) map[string]interface{} {query := s.buildBaseQuery(taskId, domain, startTime, endTime)- query.LeftJoin("mailstat_opened o", "sm.postfix_message_id=o.postfix_message_id")- query.LeftJoin("mailstat_clicked c", "sm.postfix_message_id=c.postfix_message_id")-query.Fields("count(*) as sends","coalesce(sum(case when status='sent' and dsn like '2.%' then 1 else 0 end), 0) as delivered",- "count(distinct o.postfix_message_id) as opened",- "count(distinct c.postfix_message_id) as clicked","coalesce(sum(case when status='bounced' then 1 else 0 end), 0) as bounced",)@@ -107,14 +102,34 @@ func (s *TaskStatService) getTaskDashboard(taskId int64, domain string, startTimreturn nil}- stats := result.Map()sends := result["sends"].Int()+ delivered := result["delivered"].Int()+ bounced := result["bounced"].Int()++ // 通过campaign_id查打开和点击+ campaignId := int(taskId)+ openedCount, _ := g.DB().Model("mailstat_opened").+ Where("campaign_id", campaignId).+ Fields("count(distinct postfix_message_id) as opened").+ Value()+ clickedCount, _ := g.DB().Model("mailstat_clicked").+ Where("campaign_id", campaignId).+ Fields("count(distinct postfix_message_id) as clicked").+ Value()++ stats := map[string]interface{}{+ "sends": sends,+ "delivered": delivered,+ "opened": openedCount.Int(),+ "clicked": clickedCount.Int(),+ "bounced": bounced,+ }if sends > 0 {- stats["delivery_rate"] = public.Round(float64(result["delivered"].Int())/float64(sends)*100, 2)- stats["bounce_rate"] = public.Round(float64(result["bounced"].Int())/float64(sends)*100, 2)- stats["open_rate"] = public.Round(float64(result["opened"].Int())/float64(sends)*100, 2)- stats["click_rate"] = public.Round(float64(result["clicked"].Int())/float64(sends)*100, 2)+ stats["delivery_rate"] = public.Round(float64(delivered)/float64(sends)*100, 2)+ stats["bounce_rate"] = public.Round(float64(bounced)/float64(sends)*100, 2)+ stats["open_rate"] = public.Round(float64(stats["opened"].(int))/float64(sends)*100, 2)+ stats["click_rate"] = public.Round(float64(stats["clicked"].(int))/float64(sends)*100, 2)} else {stats["delivery_rate"] = 0.0stats["bounce_rate"] = 0.0