正在显示
2 个修改的文件
包含
139 行增加
和
2 行删除
cmd/mail_black_del.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +use Model\listsSql; | ||
4 | + | ||
5 | + | ||
6 | +/** | ||
7 | + * 自动回复的邮件 | ||
8 | + * @author:dc | ||
9 | + * @time 2024/9/6 17:09 | ||
10 | + * Class HotMail | ||
11 | + */ | ||
12 | +class AutoMail { | ||
13 | + | ||
14 | + public function __construct(){ | ||
15 | + $this->db = db(); | ||
16 | + $this->start(); | ||
17 | + } | ||
18 | + | ||
19 | + /** | ||
20 | + * shopk那边的预热邮箱 | ||
21 | + * @var array | ||
22 | + */ | ||
23 | + private $black_emails = []; | ||
24 | + | ||
25 | + /** | ||
26 | + * @var \Lib\Db|\Lib\DbPool | ||
27 | + */ | ||
28 | + private $db; | ||
29 | + | ||
30 | + | ||
31 | + private $fids = []; | ||
32 | + | ||
33 | + /** | ||
34 | + * @author:dc | ||
35 | + * @time 2024/7/18 14:04 | ||
36 | + */ | ||
37 | + private function start(){ | ||
38 | + | ||
39 | + $this->fids = $this->db->all("select `id` from `folders` where `folder` = '收件箱'"); | ||
40 | + $this->fids = array_column($this->fids,'id'); | ||
41 | + | ||
42 | + $this->black_emails = $this->db->all("select * from `ai_black_email`"); | ||
43 | + $this->black_emails = array_column($this->black_emails,'email'); | ||
44 | + | ||
45 | + if(redis()->add('black_mail_sync2',1,60)){ | ||
46 | + echo '正在计算数据'; | ||
47 | + $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1"); | ||
48 | + $id = 0; | ||
49 | + while (1){ | ||
50 | + $ids = []; | ||
51 | + for ($i=0;$i<1000;$i++){ | ||
52 | + $ids[] = $i+$id; | ||
53 | + } | ||
54 | + $id = end($ids); | ||
55 | + | ||
56 | + redis()->rPush('black_check_ids',implode(',',$ids)); | ||
57 | + | ||
58 | + if($id>$maxId){ | ||
59 | + break; | ||
60 | + } | ||
61 | + } | ||
62 | + echo '计算完成'; | ||
63 | + } | ||
64 | + | ||
65 | + | ||
66 | + while (1){ | ||
67 | + $ids = redis()->lPop('black_check_ids'); | ||
68 | + if($ids){ | ||
69 | + $ids = explode(',',$ids); | ||
70 | + $this->run($ids); | ||
71 | + }else{ | ||
72 | + echo '等待'.PHP_EOL; | ||
73 | + co::sleep(2); | ||
74 | + } | ||
75 | + } | ||
76 | + | ||
77 | + } | ||
78 | + | ||
79 | + private $filter = []; | ||
80 | + | ||
81 | + private function run($id){ | ||
82 | + $list = $this->db->all(\Model\listsSql::all(dbWhere(['id'=>$id,'deleted'=>0]),'`id`,`from`,`folder_id`,`email_id`')); | ||
83 | + foreach ($list as $item){ | ||
84 | + // 必须是收件箱 | ||
85 | + if(in_array($item['folder_id'],$this->fids)){ | ||
86 | + // 是否在黑名单中 | ||
87 | + if(in_array($item['from'],$this->black_emails)){ | ||
88 | + // 是否是ai邮件 | ||
89 | + if($this->db->count("select count(*) from `hot_mail` where ".dbWhere([ | ||
90 | + 'email'=> $this->db->value(listsSql::first(dbWhere(['id'=>$item['email_id']]),'email')) | ||
91 | + ]))){ | ||
92 | + | ||
93 | + echo '删除 '.$item['id'].'===>'.$this->db->update(listsSql::$table,['deleted'=>1],dbWhere(['id'=>$item['id']])); | ||
94 | + | ||
95 | + } | ||
96 | + | ||
97 | + | ||
98 | + } | ||
99 | + | ||
100 | + } | ||
101 | + | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + | ||
106 | + | ||
107 | +} | ||
108 | + | ||
109 | + | ||
110 | +swoole_set_process_name('auto-reply-run-man'); | ||
111 | + | ||
112 | +$pm = new Swoole\Process\Manager(); | ||
113 | + | ||
114 | +$pm->addBatch(3,function (){ | ||
115 | + | ||
116 | + swoole_set_process_name('auto-reply-email-run'); | ||
117 | + | ||
118 | + include_once "../vendor/autoload.php"; | ||
119 | + | ||
120 | +// while(1){ | ||
121 | + new AutoMail(); | ||
122 | + // 执行完了暂停5分钟在执行 | ||
123 | + sleep(40); | ||
124 | +// } | ||
125 | + | ||
126 | +},true); | ||
127 | + | ||
128 | +$pm->start(); | ||
129 | + | ||
130 | + |
@@ -220,9 +220,16 @@ class syncMail { | @@ -220,9 +220,16 @@ class syncMail { | ||
220 | private function black_mail($id,$data){ | 220 | private function black_mail($id,$data){ |
221 | 221 | ||
222 | if(!empty($data['from'])){ | 222 | if(!empty($data['from'])){ |
223 | - if($this->db->count("select count(*) from `ai_black_email` where ".dbWhere(['email'=>$data['from']]))){ | 223 | + // 是否是ai邮件 |
224 | + if($this->db->count("select count(*) from `hot_mail` where ".dbWhere([ | ||
225 | + 'email'=> $this->db->value(listsSql::first(dbWhere(['id'=>$data['email_id']]),'email')) | ||
226 | + ]))){ | ||
227 | + // 是否在黑名单中 | ||
228 | + if($this->db->count("select count(*) from `ai_black_email` where ".dbWhere(['email'=>$data['from']]))){ | ||
229 | + | ||
230 | + $this->db->update(listsSql::$table,['deleted'=>1],dbWhere(['id'=>$id])); | ||
231 | + } | ||
224 | 232 | ||
225 | - $this->db->update(listsSql::$table,['deleted'=>1],dbWhere(['id'=>$id])); | ||
226 | } | 233 | } |
227 | 234 | ||
228 | } | 235 | } |
-
请 注册 或 登录 后发表评论