| 1 | -<?php |  |  | 
| 2 | - |  |  | 
| 3 | -namespace Controller\fob_ai; |  |  | 
| 4 | - |  |  | 
| 5 | - |  |  | 
| 6 | - |  |  | 
| 7 | -use Controller\Base; |  |  | 
| 8 | -use Lib\Mail\MailFun; |  |  | 
| 9 | -use Lib\Verify; |  |  | 
| 10 | -use Model\folderSql; |  |  | 
| 11 | -use function Swoole\Coroutine\Http\request; |  |  | 
| 12 | - |  |  | 
| 13 | -/** |  |  | 
| 14 | - * 黑格 fob 那边专用 业务 |  |  | 
| 15 | - * 为定制逻辑 |  |  | 
| 16 | - * @author:dc |  |  | 
| 17 | - * @time 2024/7/18 11:40 |  |  | 
| 18 | - * Class MailList |  |  | 
| 19 | - * @package Controller\fob_ai |  |  | 
| 20 | - */ |  |  | 
| 21 | -class MailListV2 extends Base { |  |  | 
| 22 | - |  |  | 
| 23 | -    private $cache = 600; |  |  | 
| 24 | - |  |  | 
| 25 | -    private function getTable(){ |  |  | 
| 26 | -        if(app()->request('table')=='lists2'){ |  |  | 
| 27 | -            return 'lists_2'; |  |  | 
| 28 | -        } |  |  | 
| 29 | -        return 'lists'; |  |  | 
| 30 | -    } |  |  | 
| 31 | - |  |  | 
| 32 | -    /** |  |  | 
| 33 | -     * 当前邮箱下指定的文件夹 |  |  | 
| 34 | -     * @param string $folder |  |  | 
| 35 | -     * @return array |  |  | 
| 36 | -     * @throws \Lib\Err |  |  | 
| 37 | -     * @author:dc |  |  | 
| 38 | -     * @time 2024/7/19 11:37 |  |  | 
| 39 | -     */ |  |  | 
| 40 | -    private function getFolderId(string $folder,$emails=[]){ |  |  | 
| 41 | -        if(!$emails){ |  |  | 
| 42 | -            $emails = $this->getEmails('id'); |  |  | 
| 43 | -        } |  |  | 
| 44 | -        $k = md5(json_encode($emails)); |  |  | 
| 45 | -        // 查询 文件夹 |  |  | 
| 46 | -        static $folderList; |  |  | 
| 47 | -        if(empty($folderList[$k])){ |  |  | 
| 48 | -            $folderList[$k] = db()->all(folderSql::all($emails)); |  |  | 
| 49 | -        } |  |  | 
| 50 | -        $folder_id = []; |  |  | 
| 51 | -        // 文件夹id |  |  | 
| 52 | -        if($folderList[$k]){ |  |  | 
| 53 | -            foreach ($folderList[$k] as $item){ |  |  | 
| 54 | -                if(folderAlias($item['folder']) == $folder){ |  |  | 
| 55 | -                    $folder_id[] = $item['id']; |  |  | 
| 56 | -                } |  |  | 
| 57 | -            } |  |  | 
| 58 | -        } |  |  | 
| 59 | -        if(!$folder_id){ |  |  | 
| 60 | -            app()->e('folder_not_fount'); |  |  | 
| 61 | -        } |  |  | 
| 62 | - |  |  | 
| 63 | -        return $folder_id; |  |  | 
| 64 | -    } |  |  | 
| 65 | - |  |  | 
| 66 | - |  |  | 
| 67 | -    /** |  |  | 
| 68 | -     * 处理like条件 |  |  | 
| 69 | -     * @param $str |  |  | 
| 70 | -     * @return string |  |  | 
| 71 | -     * @author:dc |  |  | 
| 72 | -     * @time 2024/9/4 11:14 |  |  | 
| 73 | -     */ |  |  | 
| 74 | -    private function getLikeStr($str){ |  |  | 
| 75 | -        if(str_starts_with($str, '^')){ |  |  | 
| 76 | -            return addslashes(mb_substr($str,1,99)).'%%'; |  |  | 
| 77 | -        } |  |  | 
| 78 | -        return '%%'.addslashes($str).'%%'; |  |  | 
| 79 | -    } |  |  | 
| 80 | - |  |  | 
| 81 | -    /** |  |  | 
| 82 | -     * 邮件列表 |  |  | 
| 83 | -     * 接收参数 |  |  | 
| 84 | -     *  page 分页 |  |  | 
| 85 | -     * limit 每页数量 |  |  | 
| 86 | -     * mail_id 指定邮件id |  |  | 
| 87 | -     * attachment 是否附件 |  |  | 
| 88 | -     * emails 邮箱 |  |  | 
| 89 | -     * folder 文件夹 |  |  | 
| 90 | -     * from_not_in 不在这些发件箱的邮件 |  |  | 
| 91 | -     * @throws \Lib\Err |  |  | 
| 92 | -     * @author:dc |  |  | 
| 93 | -     * @time 2024/7/18 11:40 |  |  | 
| 94 | -     */ |  |  | 
| 95 | -    public function lists(){ |  |  | 
| 96 | - |  |  | 
| 97 | -        // 分页 页数 |  |  | 
| 98 | -        $page   =   app()->request('page',1,'intval'); |  |  | 
| 99 | -        $page   =   $page ? $page : 1; |  |  | 
| 100 | - |  |  | 
| 101 | -        $limit   =   app()->request('limit',20,'intval'); |  |  | 
| 102 | -        $limit   =   $limit ? $limit : 1; |  |  | 
| 103 | - |  |  | 
| 104 | -        // 指定id |  |  | 
| 105 | -        $ids = app()->requestArr('mail_id'); |  |  | 
| 106 | -        foreach ($ids as $i=>$d){ |  |  | 
| 107 | -            if(!is_numeric($d)){ |  |  | 
| 108 | -                unset($ids[$i]); |  |  | 
| 109 | -            } |  |  | 
| 110 | -        } |  |  | 
| 111 | - |  |  | 
| 112 | -        $where = []; |  |  | 
| 113 | -        // 目录 |  |  | 
| 114 | -        $folder = app()->request('folder','收件箱'); |  |  | 
| 115 | -        // 只允许查询这里文件夹 |  |  | 
| 116 | -        if(!in_array($folder,['收件箱','发件箱','垃圾箱','星标邮件','预热收件箱','预热发件箱','自动回复收件箱','Starred','草稿箱'])){ |  |  | 
| 117 | -            app()->e('folder_not_fount'); |  |  | 
| 118 | -        } |  |  | 
| 119 | -        $where['is_hots'] = 0; |  |  | 
| 120 | - |  |  | 
| 121 | -        if($folder=='星标邮件'||$folder=='Starred'){ |  |  | 
| 122 | -            $folder = '收件箱'; |  |  | 
| 123 | -            $where['flagged'] = 1; // 星标 |  |  | 
| 124 | -            unset($where['is_hots']); |  |  | 
| 125 | -        }elseif ($folder=='预热收件箱'){ |  |  | 
| 126 | -            $folder = '收件箱'; |  |  | 
| 127 | -            $where['is_hots'] = 1; |  |  | 
| 128 | -        }elseif ($folder=='预热发件箱'){ |  |  | 
| 129 | -            $folder = '发件箱'; |  |  | 
| 130 | -            $where['is_hots'] = 1; |  |  | 
| 131 | -        } elseif ($folder=='自动回复收件箱'){ |  |  | 
| 132 | -            $is_auto_inbox = 1; |  |  | 
| 133 | -            $folder = '收件箱'; |  |  | 
| 134 | -            $where['is_hots'] = 0; |  |  | 
| 135 | -        }elseif ($folder=='草稿箱'){ |  |  | 
| 136 | -            $folder = '草稿箱'; |  |  | 
| 137 | -            $where['is_hots'] = 0; |  |  | 
| 138 | -        } |  |  | 
| 139 | - |  |  | 
| 140 | -        $seen =   app()->request('seen',-1,'intval'); |  |  | 
| 141 | -        // 已读/未读 |  |  | 
| 142 | -        if(paramHas('seen')){ |  |  | 
| 143 | -            if(in_array($seen,[0,1])){ |  |  | 
| 144 | -                $where['seen'] = $seen; |  |  | 
| 145 | -            } |  |  | 
| 146 | -        } |  |  | 
| 147 | -        // 搜索标题 |  |  | 
| 148 | -        $keyword = app()->request('keyword'); |  |  | 
| 149 | -        if($keyword){ |  |  | 
| 150 | -            $where['subject.like'] = "%%".addcslashes(str_replace('%','',$keyword),"'\"")."%%"; |  |  | 
| 151 | -        } |  |  | 
| 152 | -        // 联系人 |  |  | 
| 153 | -        $address = app()->request('address'); |  |  | 
| 154 | -        if($address){ |  |  | 
| 155 | -            if(is_array($address)){ |  |  | 
| 156 | -                // 发贱人 |  |  | 
| 157 | -                if(Verify::sEmail($address['from']??'')){ |  |  | 
| 158 | -                    if($folder=='发件箱'){ |  |  | 
| 159 | -                        $where['to'] = $address['from']; |  |  | 
| 160 | -                    }else{ |  |  | 
| 161 | -                        $where['from'] = $address['from']; |  |  | 
| 162 | -                    } |  |  | 
| 163 | -                } |  |  | 
| 164 | -            } |  |  | 
| 165 | -        } |  |  | 
| 166 | - |  |  | 
| 167 | -        // 星标就不加文件夹赛选 |  |  | 
| 168 | -        if(empty($where['flagged'])){ |  |  | 
| 169 | -            $where['_'] = trim(trim($this->assignSql($folder)),'and'); |  |  | 
| 170 | -        }else{ |  |  | 
| 171 | -            $where['_'] = trim(trim($this->assignSql2()),'and'); |  |  | 
| 172 | -        } |  |  | 
| 173 | - |  |  | 
| 174 | -        if($ids) $where['id'] = $ids; |  |  | 
| 175 | - |  |  | 
| 176 | -        if(app()->request('attachment',0,'bool_Val')){ |  |  | 
| 177 | -            // 附件 |  |  | 
| 178 | -            $where['is_file'] = 1; //附件 |  |  | 
| 179 | -        } |  |  | 
| 180 | - |  |  | 
| 181 | -        // 软删 |  |  | 
| 182 | -        $where['deleted'] = 0; |  |  | 
| 183 | - |  |  | 
| 184 | -        $filed = '`id`,`uid`,`subject`,`from`,`from_name`,`flagged`,`seen`,`udate`,`folder_id`,`is_file`,`description`,`'.$this->getTable().'`.`email_id`,`to_name`,`draft`'; |  |  | 
| 185 | -        $filedhot = '`id`,`uid`,`subject`,`from`,`from_name`,`flagged`,`seen`,`udate`,`folder_id`,`is_file`,`description`,`lists_hot`.`email_id`,`to_name`'; |  |  | 
| 186 | - |  |  | 
| 187 | -        $sql = "select %s from `".$this->getTable()."` where ".dbWhere($where); |  |  | 
| 188 | -        $sqlhot = "select %s from `lists_hot` where ".dbWhere($where); |  |  | 
| 189 | - |  |  | 
| 190 | -        /************ 2024-09-02 *************/ |  |  | 
| 191 | -        if($folder=='收件箱' && empty($where['flagged']) && !$ids) { |  |  | 
| 192 | - |  |  | 
| 193 | -            $sql = "select %s from `".$this->getTable()."` left join `lists_auto` on `".$this->getTable()."`.`id`= `lists_auto`.`list_id` where ".dbWhere($where); |  |  | 
| 194 | -            if(!empty($is_auto_inbox)){ |  |  | 
| 195 | -                $sql.= ' and `lists_auto`.`list_id` IS NOT NULL'; |  |  | 
| 196 | -            }else{ |  |  | 
| 197 | -                $sql.= ' and `lists_auto`.`list_id` IS NULL'; |  |  | 
| 198 | - |  |  | 
| 199 | -                // 模糊标题搜索 |  |  | 
| 200 | -                $subject = app()->request('subject'); |  |  | 
| 201 | -                if ($subject) { |  |  | 
| 202 | -                    $subject = is_array($subject) ? $subject : [$subject]; |  |  | 
| 203 | -                    foreach ($subject as $k => $sub) { |  |  | 
| 204 | -                        $subject[$k] = '`subject` ' . (empty($is_auto_inbox) ? ' not ' : '') . 'like "' . $this->getLikeStr($sub) . '"'; |  |  | 
| 205 | -                    } |  |  | 
| 206 | -                } |  |  | 
| 207 | -                // 不在此邮箱中的 |  |  | 
| 208 | -                $from_not_in_like = app()->request('from_not_in_like'); |  |  | 
| 209 | -                if ($from_not_in_like) { |  |  | 
| 210 | -                    $from_not_in_like = is_array($from_not_in_like) ? $from_not_in_like : [$from_not_in_like]; |  |  | 
| 211 | -                    foreach ($from_not_in_like as $k => $sub) { |  |  | 
| 212 | -                        $from_not_in_like[$k] = '`from` ' . (empty($is_auto_inbox) ? ' not ' : '') . 'like "' . $this->getLikeStr($sub) . '"'; |  |  | 
| 213 | -                    } |  |  | 
| 214 | -                } |  |  | 
| 215 | - |  |  | 
| 216 | -                if ($subject || $from_not_in_like) { |  |  | 
| 217 | -                    $sql .= ' and ('; |  |  | 
| 218 | -                    if ($subject) $sql .= implode(empty($is_auto_inbox) ? ' and ' : ' or ', $subject); |  |  | 
| 219 | -                    if ($from_not_in_like) $sql .= ' and (' . implode(empty($is_auto_inbox) ? ' and ' : ' or ', $from_not_in_like) . ')'; |  |  | 
| 220 | -                    $sql .= ')'; |  |  | 
| 221 | -                } |  |  | 
| 222 | - |  |  | 
| 223 | -            } |  |  | 
| 224 | - |  |  | 
| 225 | -        } |  |  | 
| 226 | - |  |  | 
| 227 | -        /************ 2024-09-02 *************/ |  |  | 
| 228 | - |  |  | 
| 229 | -        // 查询列表数据 |  |  | 
| 230 | -        $lists = db()->all(sprintf(empty($where['is_hots'])?$sql:$sqlhot,empty($where['is_hots'])?$filed:$filedhot).(empty($where['flagged'])?'':' group by `udate`')." order by `udate` desc limit {$limit} offset ".(($page-1)*$limit)); |  |  | 
| 231 | - |  |  | 
| 232 | -        // map |  |  | 
| 233 | -        $lists = array_map(function ($v){ |  |  | 
| 234 | -            $v['uuid'] = md5($v['email_id'].'-'.$v['folder_id'].'-'.$v['uid']); |  |  | 
| 235 | -            if(!empty($v['description'])){ |  |  | 
| 236 | -                $v['description'] = @html_entity_decode($v['description'], ENT_COMPAT, 'UTF-8'); |  |  | 
| 237 | -            } |  |  | 
| 238 | -            $v['to_name'] = @json_decode($v['to_name'],true); |  |  | 
| 239 | -            $v['to_name'] = $v['to_name']?:[]; |  |  | 
| 240 | -            if($v['to_name']){ |  |  | 
| 241 | -                if(!empty($v['to_name'][0]['email'])){ |  |  | 
| 242 | -                    $v['to'] = $v['to_name'][0]['email']; |  |  | 
| 243 | -                } |  |  | 
| 244 | -                $v['to_name'] = MailFun::mb_coding($v['to_name'][0]['name']??''); |  |  | 
| 245 | -            } |  |  | 
| 246 | -            if(is_array($v['to_name'])){ |  |  | 
| 247 | -                $v['to_name'] = ''; |  |  | 
| 248 | -            } |  |  | 
| 249 | -            return $v; |  |  | 
| 250 | -        },$lists?:[]); |  |  | 
| 251 | - |  |  | 
| 252 | -        if($lists){ |  |  | 
| 253 | -            // 总数 |  |  | 
| 254 | -            if(empty($where['flagged'])){ |  |  | 
| 255 | -                $total  = db()->cache($this->cache)->count(sprintf(empty($where['is_hots'])?$sql:$sqlhot,"count(*)")); |  |  | 
| 256 | -            }else{ |  |  | 
| 257 | -                $total  = db()->cache($this->cache)->count("select count(*) from (".sprintf($sql,"`id`").' group by `udate`) as t'); |  |  | 
| 258 | -            } |  |  | 
| 259 | - |  |  | 
| 260 | -        }else{ |  |  | 
| 261 | -            $total = 0; |  |  | 
| 262 | -        } |  |  | 
| 263 | - |  |  | 
| 264 | - |  |  | 
| 265 | -        app()->_json(listsPage($lists,$total,$page,$limit)); |  |  | 
| 266 | - |  |  | 
| 267 | -    } |  |  | 
| 268 | - |  |  | 
| 269 | - |  |  | 
| 270 | - |  |  | 
| 271 | -    private function assignSql($folder){ |  |  | 
| 272 | -        // 被分配的 |  |  | 
| 273 | -        $assign = app()->request('assign'); |  |  | 
| 274 | -        $sql = ''; |  |  | 
| 275 | -        $fids = []; |  |  | 
| 276 | -        if(!empty($assign['email_id'])){ |  |  | 
| 277 | -            // 此处请求中的 |  |  | 
| 278 | -            $email = array_values(array_intersect($assign['email_id'],$this->getEmails('id'))); |  |  | 
| 279 | -            if($email){ |  |  | 
| 280 | -                $fids = $this->getFolderId($folder,$email); |  |  | 
| 281 | -                // 有目录id和from |  |  | 
| 282 | -                if($fids && !empty($assign['from'])){ |  |  | 
| 283 | -                    if($folder=='发件箱'){ |  |  | 
| 284 | -                        $assign['from'] = is_array($assign['from']) ? array_map(function ($v){ |  |  | 
| 285 | -                            return '`to` like "%%'.$v.'%%"'; |  |  | 
| 286 | -                        },$assign['from']) : ['`to` like "%%'.$assign['from'].'%%"']; |  |  | 
| 287 | - |  |  | 
| 288 | -                        $sql = dbWhere(['folder_id'=>$fids, '_'=> '('.implode(' or ',$assign['from']).')']); |  |  | 
| 289 | -                    }else{ |  |  | 
| 290 | -                        $sql = dbWhere(['folder_id'=>$fids, 'from'=>$assign['from']]); |  |  | 
| 291 | -                    } |  |  | 
| 292 | -                } |  |  | 
| 293 | -            } |  |  | 
| 294 | - |  |  | 
| 295 | -            // 返回 不在assign中的目录 |  |  | 
| 296 | -            $afids = array_values(array_diff($this->getFolderId($folder),$fids)); |  |  | 
| 297 | - |  |  | 
| 298 | -            if($sql && $afids){ |  |  | 
| 299 | -                return '(('.dbWhere(['folder_id'=>$afids]).') or ('.$sql.')) and '; |  |  | 
| 300 | -            }else if($afids){ |  |  | 
| 301 | -                return dbWhere(['folder_id'=>$afids]).' and '; |  |  | 
| 302 | -            }else if($sql&&!$afids){ |  |  | 
| 303 | -                return '('.$sql.') and '; |  |  | 
| 304 | -            } |  |  | 
| 305 | - |  |  | 
| 306 | -            return '`folder_id` = -1 and '; |  |  | 
| 307 | - |  |  | 
| 308 | -        } |  |  | 
| 309 | - |  |  | 
| 310 | -        return dbWhere(['folder_id'=>$this->getFolderId($folder)]).' and '; |  |  | 
| 311 | - |  |  | 
| 312 | -    } |  |  | 
| 313 | -    private function assignSql2(){ |  |  | 
| 314 | -        // 被分配的 |  |  | 
| 315 | -        $assign = app()->request('assign'); |  |  | 
| 316 | -        $sql = ''; |  |  | 
| 317 | -        if(!empty($assign['email_id'])){ |  |  | 
| 318 | -            // 分配的联系人 |  |  | 
| 319 | -            $email = array_values(array_intersect($assign['email_id'],$this->getEmails('id'))); |  |  | 
| 320 | -            if($email&&!empty($assign['from'])){ |  |  | 
| 321 | -                $sql = dbWhere(['email_id'=>$email]).' and ('.dbWhere(['from'=>$assign['from']]).' or '.dbWhere(['to'=>$assign['from']]).')'; |  |  | 
| 322 | -            } |  |  | 
| 323 | - |  |  | 
| 324 | -            // 分配的邮箱 |  |  | 
| 325 | -            $email2 = array_diff($this->getEmails('id'),$assign['email_id']); |  |  | 
| 326 | -            if($email2){ |  |  | 
| 327 | -                if($sql){ |  |  | 
| 328 | -                    return '('.dbWhere(['email_id'=>$email2]).' or ('.$sql.')) and '; |  |  | 
| 329 | -                } |  |  | 
| 330 | -                return dbWhere(['email_id'=>$email2]).' and '; |  |  | 
| 331 | -            } |  |  | 
| 332 | - |  |  | 
| 333 | -            if($sql){ |  |  | 
| 334 | -                return '('.$sql.') and '; |  |  | 
| 335 | -            } |  |  | 
| 336 | - |  |  | 
| 337 | - |  |  | 
| 338 | -            return '`email_id` = -1 and '; |  |  | 
| 339 | -        } |  |  | 
| 340 | - |  |  | 
| 341 | -        // 默认 |  |  | 
| 342 | -        return dbWhere(['email_id'=>$this->getEmails('id')]).' and '; |  |  | 
| 343 | - |  |  | 
| 344 | -    } |  |  | 
| 345 | -    private function assignSql3($folder){ |  |  | 
| 346 | -        // 被分配的 |  |  | 
| 347 | -        $assign = app()->request('assign'); |  |  | 
| 348 | -        $sql = ''; |  |  | 
| 349 | -        $fids = []; |  |  | 
| 350 | -        if(!empty($assign['email_id'])){ |  |  | 
| 351 | -            // 此处请求中的 |  |  | 
| 352 | -            $email = array_diff($this->getEmails('id'),$assign['email_id']); |  |  | 
| 353 | -            if($email){ |  |  | 
| 354 | -                $fids = $this->getFolderId($folder,$email); |  |  | 
| 355 | -                // 有目录id和from |  |  | 
| 356 | -                if($fids){ |  |  | 
| 357 | -                    return dbWhere(['folder_id'=>$fids]).' and '; |  |  | 
| 358 | -                } |  |  | 
| 359 | -            } |  |  | 
| 360 | - |  |  | 
| 361 | - |  |  | 
| 362 | -            return '`folder_id` = -1 and '; |  |  | 
| 363 | - |  |  | 
| 364 | -        } |  |  | 
| 365 | - |  |  | 
| 366 | -        return dbWhere(['folder_id'=>$this->getFolderId($folder)]).' and '; |  |  | 
| 367 | - |  |  | 
| 368 | -    } |  |  | 
| 369 | - |  |  | 
| 370 | -    /** |  |  | 
| 371 | -     * 统计收件箱的数量 |  |  | 
| 372 | -     * @author:dc |  |  | 
| 373 | -     * @time 2024/7/19 10:15 |  |  | 
| 374 | -     */ |  |  | 
| 375 | -    public function count(){ |  |  | 
| 376 | -        if(!$this->getEmails('id')){ |  |  | 
| 377 | -            app()->e('email_request_required'); |  |  | 
| 378 | -        } |  |  | 
| 379 | - |  |  | 
| 380 | -        // 时间 必须是数组 |  |  | 
| 381 | -        $udate = app()->request('udate'); |  |  | 
| 382 | -        if($udate && is_array($udate) && count($udate) == 2){ |  |  | 
| 383 | -            $udate = array_values($udate); |  |  | 
| 384 | -            $where['udate.between'] = array_map(function ($v){ |  |  | 
| 385 | -                if(is_numeric($v)) return $v; |  |  | 
| 386 | -                return strtotime($v); |  |  | 
| 387 | -            },$udate); |  |  | 
| 388 | -        } |  |  | 
| 389 | - |  |  | 
| 390 | - |  |  | 
| 391 | -        // show_count_filed |  |  | 
| 392 | -        $show_count_filed = app()->requestArr('show_count_filed',['inbox', 'send', 'unseen', 'flagged', 'junk', 'hot_inbox', 'hot_send']); |  |  | 
| 393 | - |  |  | 
| 394 | -        $sql = "select count(*) from `".$this->getTable()."` where "; |  |  | 
| 395 | -        $sqlhot = "select count(*) from `lists_hot` where "; |  |  | 
| 396 | - |  |  | 
| 397 | -        $where['deleted']   =   0; //未删状态 |  |  | 
| 398 | - |  |  | 
| 399 | -        // 发件箱 |  |  | 
| 400 | -        if(in_array('hot_send',$show_count_filed)){ |  |  | 
| 401 | -//            $where['folder_id'] = $this->getFolderId('发件箱'); |  |  | 
| 402 | -            // 预热发件箱 |  |  | 
| 403 | -            $where['is_hots'] = 1; |  |  | 
| 404 | -            $fCount = db()->cache(86400)->count($sql.$this->assignSql3('发件箱').dbWhere($where)); |  |  | 
| 405 | -            $fCount += db()->cache(86400)->count($sqlhot.$this->assignSql3('发件箱').dbWhere($where)); |  |  | 
| 406 | -        } |  |  | 
| 407 | - |  |  | 
| 408 | -        // 预热收件箱 |  |  | 
| 409 | -        if(in_array('hot_inbox',$show_count_filed)) { |  |  | 
| 410 | -//            $where['folder_id'] = $this->getFolderId('收件箱'); |  |  | 
| 411 | -            $where['is_hots'] = 1; |  |  | 
| 412 | -            $sCount = db()->cache(86400)->count($sql .$this->assignSql3('收件箱'). dbWhere($where)); |  |  | 
| 413 | -            $sCount += db()->cache(86400)->count($sqlhot .$this->assignSql3('收件箱'). dbWhere($where)); |  |  | 
| 414 | -        } |  |  | 
| 415 | -        unset($where['folder_id']); |  |  | 
| 416 | - |  |  | 
| 417 | -        if(in_array('send',$show_count_filed)) { |  |  | 
| 418 | -//            $where['folder_id'] = $this->getFolderId('发件箱'); |  |  | 
| 419 | -            $where['is_hots'] = 0; |  |  | 
| 420 | -            $faCount = db()->cache($this->cache)->count($sql . $this->assignSql('发件箱').dbWhere($where)); |  |  | 
| 421 | -        } |  |  | 
| 422 | -// 垃圾箱 |  |  | 
| 423 | -        if(in_array('junk',$show_count_filed)) { |  |  | 
| 424 | -//            $where['folder_id'] = $this->getFolderId('垃圾箱'); |  |  | 
| 425 | -            $where['is_hots'] = 0; |  |  | 
| 426 | -            $lajiCount = db()->cache($this->cache)->count($sql . $this->assignSql('垃圾箱').dbWhere($where)); |  |  | 
| 427 | -        } |  |  | 
| 428 | - |  |  | 
| 429 | -        // 收件箱 |  |  | 
| 430 | -//        $where['folder_id'] = $this->getFolderId('收件箱'); |  |  | 
| 431 | -        $where['is_hots'] = 0; |  |  | 
| 432 | -        $sql = "select count(*) from `".$this->getTable()."` left join `lists_auto` on `".$this->getTable()."`.`id`= `lists_auto`.`list_id` where `lists_auto`.`list_id` IS NULL and ".$this->assignSql('收件箱'); |  |  | 
| 433 | - |  |  | 
| 434 | -        // 模糊标题搜索 |  |  | 
| 435 | -        $subject = app()->request('subject'); |  |  | 
| 436 | -        if($subject){ |  |  | 
| 437 | -            $subject = is_array($subject) ? $subject : [$subject]; |  |  | 
| 438 | -            foreach ($subject as $k=>$sub){ |  |  | 
| 439 | -                $subject[$k] = '`subject` not like "'.$this->getLikeStr($sub).'"'; |  |  | 
| 440 | -            } |  |  | 
| 441 | -        } |  |  | 
| 442 | -        // 不在此邮箱中的 |  |  | 
| 443 | -        $from_not_in_like = app()->request('from_not_in_like'); |  |  | 
| 444 | -        if($from_not_in_like){ |  |  | 
| 445 | -            $from_not_in_like = is_array($from_not_in_like) ? $from_not_in_like : [$from_not_in_like]; |  |  | 
| 446 | -            foreach ($from_not_in_like as $k=>$sub){ |  |  | 
| 447 | -                $from_not_in_like[$k] = '`from`  not like "'.$this->getLikeStr($sub).'"'; |  |  | 
| 448 | -            } |  |  | 
| 449 | -        } |  |  | 
| 450 | - |  |  | 
| 451 | -        if($subject || $from_not_in_like){ |  |  | 
| 452 | -            $sql .= ' ('; |  |  | 
| 453 | -            if($subject) $sql.= implode(' and ',$subject); |  |  | 
| 454 | -            if($from_not_in_like) $sql.= ' and ('.implode(' and ',$from_not_in_like).')'; |  |  | 
| 455 | -            $sql .= ') and '; |  |  | 
| 456 | -        } |  |  | 
| 457 | - |  |  | 
| 458 | -        // 收件箱 |  |  | 
| 459 | -        if(in_array('inbox',$show_count_filed)) { |  |  | 
| 460 | -            $shouCount = db()->cache($this->cache)->count($sql . dbWhere($where)); |  |  | 
| 461 | -        } |  |  | 
| 462 | - |  |  | 
| 463 | -        // 收件箱中标记为已回复的邮件 |  |  | 
| 464 | -        if(in_array('replied',$show_count_filed)){ |  |  | 
| 465 | -//            $where['answered'] = 1; |  |  | 
| 466 | -            $repliedCount = isset($shouCount) ? $shouCount : db()->cache($this->cache)->count($sql . dbWhere($where)); |  |  | 
| 467 | -//            unset($where['answered']); |  |  | 
| 468 | -        } |  |  | 
| 469 | - |  |  | 
| 470 | -        // 未读 |  |  | 
| 471 | -        if(in_array('unseen',$show_count_filed)) { |  |  | 
| 472 | -            $where['seen'] = 0; |  |  | 
| 473 | -            $where['is_hots'] = 0; |  |  | 
| 474 | -            $seenCount = db()->cache($this->cache)->count($sql . dbWhere($where)); |  |  | 
| 475 | -            unset($where['seen']); |  |  | 
| 476 | -        } |  |  | 
| 477 | - |  |  | 
| 478 | - |  |  | 
| 479 | -        // 星标 |  |  | 
| 480 | -        if(in_array('flagged',$show_count_filed)) { |  |  | 
| 481 | -            $where['flagged'] = 1; |  |  | 
| 482 | -            unset($where['folder_id']); |  |  | 
| 483 | -//            $where['email_id'] = $emails; |  |  | 
| 484 | -            unset($where['is_hots']); |  |  | 
| 485 | -            $flaggedCount = db()->cache($this->cache)->count("SELECT COUNT(*) FROM (select `id` from `".$this->getTable()."` where " . $this->assignSql2().dbWhere($where).' group by `udate`) as c'); |  |  | 
| 486 | -        } |  |  | 
| 487 | - |  |  | 
| 488 | -        $data = []; |  |  | 
| 489 | -        if(isset($shouCount)) $data['inbox'] = $shouCount; |  |  | 
| 490 | -        if(isset($repliedCount)) $data['replied'] = $repliedCount; |  |  | 
| 491 | -        if(isset($faCount)) $data['send'] = $faCount; |  |  | 
| 492 | -        if(isset($seenCount)) $data['unseen'] = $seenCount; |  |  | 
| 493 | -        if(isset($flaggedCount)) $data['flagged'] = $flaggedCount; |  |  | 
| 494 | -        if(isset($lajiCount)) $data['junk'] = $lajiCount; |  |  | 
| 495 | -        if(isset($sCount)) $data['hot_inbox'] = $sCount; |  |  | 
| 496 | -        if(isset($fCount)) $data['hot_send'] = $fCount; |  |  | 
| 497 | - |  |  | 
| 498 | -        app()->_json($data); |  |  | 
| 499 | - |  |  | 
| 500 | -    } |  |  | 
| 501 | - |  |  | 
| 502 | - |  |  | 
| 503 | - |  |  | 
| 504 | -} |  |  | 
| 505 | - |  |  | 
| 506 | - |  |  | 
| 507 | - |  |  | 
| 508 | - |  |  | 
| 509 | - |  |  | 
| 510 | - |  |  | 
| 511 | - |  |  | 
| 512 | - |  |  | 
| 513 | - |  |  | 
| 514 | - |  |  | 
| 515 | - |  |  | 
| 516 | - |  |  | 
| 517 | - |  |  | 
| 518 | - |  |  |