hot_mail_2.php
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
use Model\listsSql;
/**
* 处理预热邮箱
* @author:dc
* @time 2024/9/4 11:02
* Class HotMail
*/
class HotMail {
public function __construct(){
$this->db = db();
$this->start();
}
/**
* shopk那边的预热邮箱
* @var array
*/
private $hotEmail = [];
/**
* @var \Lib\Db|\Lib\DbPool
*/
private $db;
/**
* @author:dc
* @time 2024/7/18 14:04
*/
private function start(){
_echo('启动预热邮件处理 '.getmypid());
if(redis()->add('hot_mail_sync2',1,60)){
echo '正在计算数据';
$maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
$id = 0;
while (1){
$ids = [];
for ($i=0;$i<1000;$i++){
$ids[] = $i+$id;
}
$id = end($ids);
redis()->rPush('hot_check_ids',implode(',',$ids));
if($id>$maxId){
break;
}
}
echo '计算完成';
}
while (1){
$ids = redis()->lPop('hot_check_ids');
if($ids){
$ids = explode(',',$ids);
$this->run($ids);
}else{
echo '等待'.PHP_EOL;
co::sleep(2);
}
}
}
private $folder = [];
private function run($id){
$list = $this->db->all(\Model\listsSql::all(dbWhere(['id'=>$id]),'`id`,`from`,`to`,`folder_id`,`is_hots`'));
foreach ($list as $item){
if(empty($this->folder[$item['folder_id']])){
$this->folder[$item['folder_id']] = folderAlias($this->db->value(\Model\folderSql::first($item['folder_id'],'folder')));
}
if(!in_array($this->folder[$item['folder_id']],['收件箱','发件箱'])){
continue;
}
// 是否是发件箱
if($this->folder[$item['folder_id']] == '发件箱'){
$w = ['email' => array_map('strtolower',explode(',',$item['to']))];
}else{
$w = ['email' =>strtolower($item['from'])];
}
// 是否在 预热邮箱中
$mkey = md5(dbWhere($w));
if(!isset($this->hotEmail[$mkey])){
$this->hotEmail[$mkey] = $this->db->count('select count(*) from `hot_mail` where '.dbWhere($w));
}
if($this->hotEmail[$mkey]){
if(!$item['is_hots']){
$ret = $this->db->update(listsSql::$table,['is_hots'=>1],dbWhere(['id'=>$item['id']]));
echo date('d H:i:s').' +==》 '.$item['id'].':'.$ret."\n";
}
}else{
if($item['is_hots']){
$ret = $this->db->update(listsSql::$table,['is_hots'=>0],dbWhere(['id'=>$item['id']]));
echo date('d H:i:s').' -==》 '.$item['id'].':'.$ret."\n";
}
}
}
}
}
swoole_set_process_name('hot-email-run-man');
$pm = new Swoole\Process\Manager();
$pm->addBatch(3,function (){
swoole_set_process_name('hot-email-run');
include_once "../vendor/autoload.php";
new HotMail();
exit();
},true);
$pm->start();