|
@@ -15,80 +15,90 @@ class AutoMail { |
|
@@ -15,80 +15,90 @@ class AutoMail { |
15
|
$this->start();
|
15
|
$this->start();
|
16
|
}
|
16
|
}
|
17
|
|
17
|
|
|
|
18
|
+ /**
|
|
|
19
|
+ * @var Lib\Es\Es
|
|
|
20
|
+ */
|
|
|
21
|
+ public $es;
|
18
|
|
22
|
|
19
|
/**
|
23
|
/**
|
20
|
* @author:dc
|
24
|
* @author:dc
|
21
|
* @time 2024/7/18 14:04
|
25
|
* @time 2024/7/18 14:04
|
22
|
*/
|
26
|
*/
|
23
|
private function start(){
|
27
|
private function start(){
|
|
|
28
|
+ echo "start ";
|
|
|
29
|
+ echo date('Y-m-d H:i:s');
|
|
|
30
|
+ echo "\n";
|
|
|
31
|
+ if(redis()->get('resync_to_es_inbox') == 1){
|
|
|
32
|
+
|
|
|
33
|
+ $post_ids = fob_mysql()->all("select `post_id` from `e_mail_binds` group by `post_id`");
|
24
|
|
34
|
|
25
|
- $old = redis()->get('prev_auto_mail_keyword',[]);
|
|
|
26
|
-
|
|
|
27
|
- $filter = isAiAutoMail(true,true);
|
|
|
28
|
- if(!$filter) return 0;
|
|
|
29
|
- redis()->set('prev_auto_mail_keyword',$filter,86400);
|
|
|
30
|
-
|
|
|
31
|
- $t = function ($vs){
|
|
|
32
|
- return array_map(function ($v){
|
|
|
33
|
- return $v[0].":".$v[1];
|
|
|
34
|
- },$vs);
|
|
|
35
|
- };
|
|
|
36
|
- // 找到新增的
|
|
|
37
|
- $q = array_diff($t($filter),$t($old));
|
|
|
38
|
- if(!$q){
|
|
|
39
|
- return 0;
|
35
|
+ $this->es = es();
|
|
|
36
|
+
|
|
|
37
|
+ foreach ($post_ids as $post_id){
|
|
|
38
|
+ $total = $this->essss(0,$post_id,0);
|
|
|
39
|
+ $autoTotal = $this->essss(0,$post_id,1);
|
|
|
40
|
+ echo "postid {$post_id} inbox {$total} auto {$autoTotal}\n";
|
40
|
}
|
41
|
}
|
41
|
|
42
|
|
42
|
- $es = es('email_lists_copy');
|
43
|
+ }
|
|
|
44
|
+
|
|
|
45
|
+ echo "end ";
|
|
|
46
|
+ echo date('Y-m-d H:i:s');
|
|
|
47
|
+ echo "\n";
|
43
|
|
48
|
|
44
|
- $not_must = [];
|
|
|
45
|
- foreach ($q as $f){
|
|
|
46
|
- list($t,$str) = explode(':',$f,2);
|
|
|
47
|
- if($t==2){
|
|
|
48
|
- $not_must[] = ["match_phrase"=>["subject"=>$str]];
|
|
|
49
|
|
49
|
|
50
|
- }elseif ($t==1){
|
|
|
51
|
- $not_must[] = ["match_phrase"=>["from.email"=>$str]];
|
|
|
52
|
|
50
|
|
53
|
- }
|
|
|
54
|
}
|
51
|
}
|
55
|
|
52
|
|
|
|
53
|
+ public function essss($id,$post_id,$is_auto){
|
|
|
54
|
+ $total = 0;
|
|
|
55
|
+ while ( true){
|
56
|
// 查询自动回的邮件
|
56
|
// 查询自动回的邮件
|
57
|
- $lists = $es->search([
|
|
|
58
|
- "_source" => ["uuid","subject","from"],
|
|
|
59
|
- "query"=>[
|
|
|
60
|
- "constant_score"=>[
|
|
|
61
|
- "filter"=>[
|
|
|
62
|
- "bool"=>[
|
|
|
63
|
- "must"=>[
|
57
|
+ $this->es->setIndex('email_lists_branch_'.$post_id);
|
|
|
58
|
+
|
|
|
59
|
+ $must = [
|
64
|
["term"=>["folder_as_int" => 1]], // 收件箱
|
60
|
["term"=>["folder_as_int" => 1]], // 收件箱
|
65
|
- ["term"=>["is_auto" => 0]], // 非auto
|
61
|
+ ["term"=>["is_auto" => $is_auto]], // 非auto
|
66
|
["term"=>["is_hots" => 0]], // 非预热
|
62
|
["term"=>["is_hots" => 0]], // 非预热
|
67
|
["term"=>["deleted" => 0]], // 非删除
|
63
|
["term"=>["deleted" => 0]], // 非删除
|
68
|
["term"=>["source" => 2]], // 非删除
|
64
|
["term"=>["source" => 2]], // 非删除
|
69
|
- // 自动关键字
|
|
|
70
|
- [
|
|
|
71
|
- "bool" => [
|
|
|
72
|
- "should"=> $not_must,
|
|
|
73
|
- "minimum_should_match" => 1
|
|
|
74
|
- ]
|
65
|
+ ["range"=>[
|
|
|
66
|
+ 'uuid'=>[
|
|
|
67
|
+ "egt"=>$id
|
75
|
]
|
68
|
]
|
|
|
69
|
+ ]]
|
|
|
70
|
+ ];
|
|
|
71
|
+
|
|
|
72
|
+ if($is_auto){
|
|
|
73
|
+ $must[] = [
|
|
|
74
|
+ "match_phrase" =>[
|
|
|
75
|
+ "subject"=>"Re:"
|
76
|
]
|
76
|
]
|
|
|
77
|
+ ];
|
|
|
78
|
+ }
|
|
|
79
|
+
|
|
|
80
|
+ $lists = $this->es->search([
|
|
|
81
|
+ "_source" => ["uuid"],
|
|
|
82
|
+ "query"=>[
|
|
|
83
|
+ "constant_score"=>[
|
|
|
84
|
+ "filter"=>[
|
|
|
85
|
+ "bool"=>[
|
|
|
86
|
+ "must"=> $must
|
77
|
]
|
87
|
]
|
78
|
]
|
88
|
]
|
79
|
]
|
89
|
]
|
80
|
]
|
90
|
]
|
81
|
- ],0,1000,['udate'=>'desc'],1000);
|
91
|
+ ],0,1000,['uuid'=>'asc'],1000);
|
82
|
|
92
|
|
|
|
93
|
+ if(empty($lists['hits']['hits'])){
|
|
|
94
|
+ return $total;
|
|
|
95
|
+ }
|
83
|
foreach ($lists['hits']['hits']??[] as $list){
|
96
|
foreach ($lists['hits']['hits']??[] as $list){
|
84
|
- $list = $list['_source'];
|
|
|
85
|
- $id = intval($list['uuid']??0);
|
|
|
86
|
- if($id && isAiAutoMail($list['from']['email'],$list['subject'])){
|
|
|
87
|
- _echo("id = ".$id);
|
|
|
88
|
- redis()->rPush('sync_to_es',$id);
|
97
|
+ $total++;
|
|
|
98
|
+ $id = $list['_source']['uuid'];
|
|
|
99
|
+ redis()->rPush('sync_to_es',$list['_source']['uuid'].'.1');
|
89
|
}
|
100
|
}
|
90
|
}
|
101
|
}
|
91
|
-
|
|
|
92
|
}
|
102
|
}
|
93
|
|
103
|
|
94
|
}
|
104
|
}
|