hot_mail_3.php
2.9 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
<?php
use Model\listsSql;
/**
 * 把预热的邮件进行归档处理 减少数量量
 * @author:dc
 * @time 2025/1/17 17:10
 * Class HotMail
 */
class HotMailArchive {
    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());
//         $fid = [235623,235628,235633,235638,235643,235648,235653,235658,235663,235668,235673,235678,235683,235688,235693,235698,235703,235708,235713,235718,235723,235728,235733,235738,235743,235748,235753,235758,235763,235768,235773,235778,235783,235788,235793,235798,235803,235808,235813,235818,235823,235828,235833,235838,235843,235848,235853,235858,235863,235868,235873,235878,235883,235888,235893,235898,235903,235908,235913,235918,235923,235928,235933,235938,235943,235948,235953,235958,235963,235968,235973,235978,235983,235988,235993,235998,236003,236008,236013,236018];
//         foreach ($fid as $i){
//             $this->move($i);
//         }
// return 0;
        $id = 0;
        while (1){
            $id = $this->run($id);
            if($id === 0){
                break;
            }
        }
    }
    private function run($id):int {
        $floder = $this->db->first(\Model\folderSql::first(['id.>'=>$id]));
        if($floder){
            $this->move($floder['id']);
            return $floder['id'];
        }else{
            return 0;
        }
    }
    public function move($fid){
        _echo('正在移动 '.$fid);
        $list = $this->db->all(\Model\listsSql::first(dbWhere(['folder_id'=>$fid,'is_hots'=>1])).'0000');
        if($list){
            $this->db->transaction(function () use ($list){
                foreach ($list as $item){
                    try {
                        $ret = $this->db->throw()->insert('lists_hot',$item,false);
                        if($ret){
                            $this->db->delete(listsSql::$table,['id'=>$item['id']]);
                        }
                    }catch (Throwable $e){
                        $this->db->update('lists_hot',$item,dbWhere(['id'=>$item['id']]));
                    }
                }
                return true;
            });
            $list = null;
            $this->move($fid);
        }
    }
}
include_once "../vendor/autoload.php";
new HotMailArchive();
_echo('执行完成 等待下次执行');
//
//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();