hot_mail_3.php 2.3 KB
<?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());

        $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])).'000');
        if($list){
            $this->db->transaction(function () use ($list){
                foreach ($list as $item){
                    try {
                        $ret = $this->db->throw()->insert('lists_hot',$item,false);
                    }catch (Throwable $e){
                        $this->db->delete('lists_hot',['id'=>$item['id']]);
                        unset($item['updated_at']);
                        $ret = $this->db->throw()->insert('lists_hot',$item,false);
                    }
                    if($ret){
                        $this->db->delete(listsSql::$table,['id'=>$item['id']]);
                    }
                }
            });

            $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();