作者 邓超

优化 同步

正在显示 1 个修改的文件 包含 23 行增加6 行删除
@@ -40,12 +40,29 @@ function start(){ @@ -40,12 +40,29 @@ function start(){
40 $email = db()->cache(3600)->first(\Model\emailSql::first($id)); 40 $email = db()->cache(3600)->first(\Model\emailSql::first($id));
41 if($email){ 41 if($email){
42 $sync = new \Service\SyncMail($email); 42 $sync = new \Service\SyncMail($email);
43 - if(db()->count("select count(*) from `hot_mail` where `email` = '{$email['email']}'")){  
44 - // ai邮件只同步2天内的  
45 - $sync->search(  
46 - (new \Lib\Imap\ImapSearch())  
47 - ->dateGt(date('Y-m-d',strtotime("-2 day")))  
48 - ); 43 + $search = new \Lib\Imap\ImapSearch();
  44 + // 第一次同步 只同步当天的
  45 + if(!db()->cache(600)->count(\Model\listsSql::first('`id` > 0'))){
  46 + $sync->search($search->dateGt($email['created_at']));
  47 + }else{
  48 + // 是否是ai邮箱
  49 + if(db()->count("select count(*) from `hot_mail` where `email` = '{$email['email']}'")){
  50 + // ai邮件只同步2天内的
  51 + if(strtotime("-2 day") > strtotime($email['created_at'])){
  52 + $sync->search(
  53 + $search->dateGt(
  54 + date('Y-m-d',
  55 + strtotime("-2 day")
  56 + )
  57 + )
  58 + );
  59 + }else{
  60 + $sync->search(
  61 + $search->dateGt($email['created_at'])
  62 + );
  63 + }
  64 +
  65 + }
49 } 66 }
50 67
51 $sync->sync(); 68 $sync->sync();