作者 邓超

x

正在显示 1 个修改的文件 包含 32 行增加130 行删除
1 <?php 1 <?php
2 2
  3 +use Model\listsSql;
  4 +
3 5
4 /** 6 /**
5 * 只有黑格 在使用此业务 7 * 只有黑格 在使用此业务
@@ -15,7 +17,10 @@ @@ -15,7 +17,10 @@
15 */ 17 */
16 class HotMail { 18 class HotMail {
17 19
18 - public function __construct(){$this->start();} 20 + public function __construct(){
  21 + $this->db = db();
  22 + $this->start();
  23 + }
19 24
20 /** 25 /**
21 * shopk那边的预热邮箱 26 * shopk那边的预热邮箱
@@ -24,6 +29,12 @@ class HotMail { @@ -24,6 +29,12 @@ class HotMail {
24 private $shopkHotEmail = []; 29 private $shopkHotEmail = [];
25 30
26 /** 31 /**
  32 + * @var \Lib\Db|\Lib\DbPool
  33 + */
  34 + private $db;
  35 +
  36 +
  37 + /**
27 * @author:dc 38 * @author:dc
28 * @time 2024/7/18 14:04 39 * @time 2024/7/18 14:04
29 */ 40 */
@@ -41,140 +52,48 @@ class HotMail { @@ -41,140 +52,48 @@ class HotMail {
41 52
42 $this->shopkHotEmail['job@aicc-email.com'] = 1; 53 $this->shopkHotEmail['job@aicc-email.com'] = 1;
43 54
44 - $db = db();  
45 foreach ($this->shopkHotEmail as $e=>$i){ 55 foreach ($this->shopkHotEmail as $e=>$i){
46 try { 56 try {
47 - if(!$db->count("select count(*) from `hot_mail` where ".dbWhere(['email'=>$e]))){  
48 - $db->throw()->insert('hot_mail',['email'=>$e],false); 57 + if(!$this->db->count("select count(*) from `hot_mail` where ".dbWhere(['email'=>$e]))){
  58 + $this->db->throw()->insert('hot_mail',['email'=>$e],false);
49 } 59 }
50 60
51 }catch (Throwable $e){} 61 }catch (Throwable $e){}
52 } 62 }
53 63
54 64
55 -// if($this->shopkHotEmail){  
56 -// array_map([$this,'moveMail'],$fob);  
57 -// } 65 + $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
  66 + for ($i=0;$i<ceil($maxId/1000);$i++){
  67 + $this->run(rand($i*1000,($i+1)*1000));
  68 + }
58 69
59 echo '已执行完成'.PHP_EOL; 70 echo '已执行完成'.PHP_EOL;
60 } 71 }
61 72
62 - /**  
63 - * 邮件检查及移动  
64 - * @param string $email 检查的邮箱  
65 - * @author:dc  
66 - * @time 2024/7/18 14:06  
67 - */  
68 - private function moveMail(string $email){  
69 - echo '正在处理 '.$email."\n";  
70 - // 读取邮箱在表里的id  
71 - $email_id = db()->value(sprintf("select `id` from `%s` where `email` = '%s' limit 1",\Model\emailSql::$table, $email));  
72 -  
73 - if($email_id){  
74 - $this->findFolder($email_id,'收件箱','s');  
75 - $this->findFolder($email_id,'发件箱','f');  
76 - $this->findFolder($email_id,'垃圾箱','l');  
77 - }  
78 73
79 - return true;  
80 - } 74 + private $folder = [];
81 75
82 - /**  
83 - * 查找文件夹  
84 - * @param int $email_id 邮箱id  
85 - * @param string $folder 那个文件夹  
86 - * @author:dc  
87 - * @time 2024/7/18 15:10  
88 - */  
89 - private function findFolder(int $email_id, string $folder,string $type){  
90 - // 查询 文件夹  
91 - $folders = db()->all(\Model\folderSql::all($email_id,'`id`,`folder`'));  
92 - if(!$folders){  
93 - return true;  
94 - }  
95 - foreach ($folders as $f){  
96 - if(folderAlias($f['folder']) == $folder){  
97 - // 最后记录的id  
98 -// $last_id = db()->value('select max(`lists_id`) from `fob_hot_mail` where `email_id` = '.$email_id.' and `folder` = "'.$type.'" limit 1');  
99 -// $last_id = $last_id?$last_id:0;  
100 - $this->findList(new Data($email_id,$f['id'],$type,0));  
101 - }  
102 - }  
103 - return true; 76 + private function run($id){
  77 + $list = $this->db->all(\Model\listsSql::first(dbWhere(['id'=>$id,'is_hots'=>0]),'`id`,`from`,`to`,`folder_id`'));
  78 + foreach ($list as $item){
  79 + if(empty($this->folder[$item['folder_id']])){
  80 + $this->folder[$item['folder_id']] = folderAlias($this->db->value(\Model\folderSql::first($item['folder_id'],'folder')));
104 } 81 }
105 82
106 - /**  
107 - * 查找 邮件  
108 - * @author:dc  
109 - * @time 2024/7/18 15:11  
110 - */  
111 - private function findList(Data $data, int $p = 1){  
112 - $lists = db()->throw()->all(  
113 - sprintf(  
114 - "select `id`,`folder_id`,`lists`.`email_id`,`%s` from `lists` left join `fob_hot_mail` on `fob_hot_mail`.`lists_id` = `lists`.`id` where `lists`.`email_id` = %d and `folder_id` = %d and `fob_hot_mail`.`lists_id` is null order by `id` asc limit 1000 offset ".(($p-1)*1000),  
115 - $data->type=='f' ? 'to_name':'from', // 收件箱查询 from字段 发件箱 查询 to_name字段  
116 - $data->email_id,  
117 - $data->folder_id  
118 - )  
119 - );  
120 -  
121 - if($lists){  
122 - echo '找到邮件 '.count($lists)."\n";  
123 - // 处理数据  
124 - foreach ($lists as $list){  
125 - $list['folder'] = $data->type;  
126 - $this->insertData($list);  
127 - }  
128 - $lists = null;  
129 - $list = null;  
130 - // 再次查找  
131 - $this->findList($data,$p + 1);  
132 - }  
133 - return true;  
134 - }  
135 -  
136 - /**  
137 - * 插入数据  
138 - * @param array $data  
139 - * @author:dc  
140 - * @time 2024/7/18 15:25  
141 - */  
142 - private function insertData(array $data){  
143 -  
144 - $isInsert = false;  
145 - if($data['folder'] != 'f'){  
146 - // 收件箱 匹配 from 字段  
147 - $isInsert = isset($this->shopkHotEmail[strtolower($data['from'])]); 83 + // 是否是发件箱
  84 + if($this->folder[$item['folder_id']] == '发件箱'){
  85 + $w = ['email' => explode(',',$item['to'])];
148 }else{ 86 }else{
149 - // 发件箱 匹配 to_name字段  
150 - $to_name = is_array($data['to_name']) ? $data['to_name'] : @json_decode($data['to_name'],1);  
151 - if($to_name){  
152 - foreach ($to_name as $item){  
153 - // 找到了就退出去  
154 - if(isset($this->shopkHotEmail[strtolower($item['email'])])){  
155 - $isInsert = true;  
156 - $data['from'] = $item['email'];  
157 - break; 87 + $w = ['email' =>$item['from']];
158 } 88 }
  89 + // 是否在 预热邮箱中
  90 + if($this->db->count('select count(*) from `hot_mail` where '.dbWhere($w))){
  91 + echo date('d H:i:s').' ==》 '.$item['id']."\n";
  92 + $this->db->update(listsSql::$table,['is_hots'=>1],dbWhere(['id'=>$item['id']]));
159 } 93 }
160 } 94 }
161 } 95 }
162 96
163 - // 是预热 邮箱发来的邮件  
164 - if($isInsert){  
165 - // 不存在 数据  
166 - if(db()->count("select count(*) from `fob_hot_mail` where `lists_id` = ".$data['id']) == 0){  
167 - db()->insert('fob_hot_mail',[  
168 - 'lists_id' => $data['id'],  
169 - 'email_id' => $data['email_id'],  
170 - 'hot_form' => $data['from']??'',  
171 - 'folder' => $data['folder']  
172 - ],false);  
173 - }  
174 - }  
175 - return true;  
176 - }  
177 -  
178 97
179 /** 98 /**
180 * 获取预热邮箱 99 * 获取预热邮箱
@@ -221,23 +140,6 @@ class HotMail { @@ -221,23 +140,6 @@ class HotMail {
221 } 140 }
222 141
223 142
224 -class Data {  
225 -  
226 - public int $email_id = 0;  
227 - public int $folder_id = 0;  
228 - public string $type = '';  
229 - public int $last_id = 0;  
230 -  
231 - public function __construct(int $email_id,int $folder_id, string $type,int $last_id)  
232 - {  
233 - $this->email_id = $email_id;  
234 - $this->folder_id = $folder_id;  
235 - $this->type = $type;  
236 - $this->last_id = $last_id;  
237 - }  
238 -  
239 -}  
240 -  
241 swoole_set_process_name('hot-email-run-man'); 143 swoole_set_process_name('hot-email-run-man');
242 144
243 $pm = new Swoole\Process\Manager(); 145 $pm = new Swoole\Process\Manager();