作者 邓超

fob 接口调整

@@ -30,11 +30,11 @@ class MailListV2 extends Base { @@ -30,11 +30,11 @@ class MailListV2 extends Base {
30 * @author:dc 30 * @author:dc
31 * @time 2024/7/19 11:37 31 * @time 2024/7/19 11:37
32 */ 32 */
33 - private function getFolderId(string $folder){ 33 + private function getFolderId(string $folder,$emails=[]){
34 // 查询 文件夹 34 // 查询 文件夹
35 static $folderList; 35 static $folderList;
36 if(!$folderList){ 36 if(!$folderList){
37 - $folderList = db()->all(folderSql::all($this->getEmails('id'))); 37 + $folderList = db()->all(folderSql::all($emails?:$this->getEmails('id')));
38 } 38 }
39 $folder_id = []; 39 $folder_id = [];
40 // 文件夹id 40 // 文件夹id
@@ -53,39 +53,6 @@ class MailListV2 extends Base { @@ -53,39 +53,6 @@ class MailListV2 extends Base {
53 } 53 }
54 54
55 55
56 - private function from_not_in(){  
57 - $where = [];  
58 - /**  
59 - * 不查询哪些发件人的邮件  
60 - */  
61 - $form_not_in = app()->request('from_not_in');  
62 - if($form_not_in){  
63 - if(is_string($form_not_in)){  
64 - $form_not_in = explode(',',$form_not_in);  
65 - }  
66 - $form_not_in = is_array($form_not_in) ? $form_not_in : [$form_not_in];  
67 - $form_not_in = array_filter($form_not_in,function ($v){  
68 - if(is_string($v) && Verify::sEmail($v)){  
69 - return true;  
70 - }  
71 - return false;  
72 - });  
73 - if($form_not_in){  
74 - $where = array_merge($where,$form_not_in);  
75 - }  
76 - }  
77 - // 过滤掉  
78 - foreach ($where as $k=>$item){  
79 - if(stripos($item,'postmaster@') === 0){  
80 - unset($where[$k]);  
81 - }  
82 - }  
83 -  
84 - $where[] = 'noreply@google.com';  
85 -  
86 - return $where;  
87 - }  
88 -  
89 /** 56 /**
90 * 处理like条件 57 * 处理like条件
91 * @param $str 58 * @param $str
@@ -167,12 +134,14 @@ class MailListV2 extends Base { @@ -167,12 +134,14 @@ class MailListV2 extends Base {
167 134
168 // 星标就不加文件夹赛选 135 // 星标就不加文件夹赛选
169 if(empty($where['flagged'])){ 136 if(empty($where['flagged'])){
170 - $folder_id = $this->getFolderId($folder); 137 +// $folder_id = $this->getFolderId($folder);
171 138
172 //目录 139 //目录
173 - $where['folder_id'] = $folder_id; 140 +// $where['folder_id'] = $folder_id;
  141 + $where['_'] = $this->assignSql($folder);
174 }else{ 142 }else{
175 - $where['lists|email_id'] = $this->getEmails('id'); 143 +// $where['lists|email_id'] = $this->getEmails('id');
  144 + $where['_'] = $this->assignSql2();
176 } 145 }
177 146
178 if($ids) $where['id'] = $ids; 147 if($ids) $where['id'] = $ids;
@@ -268,6 +237,98 @@ class MailListV2 extends Base { @@ -268,6 +237,98 @@ class MailListV2 extends Base {
268 } 237 }
269 238
270 239
  240 +
  241 + private function assignSql($folder){
  242 + // 被分配的
  243 + $assign = app()->request('assign');
  244 + $sql = '';
  245 + $fids = [];
  246 + if(!empty($assign['email_id'])){
  247 + // 此处请求中的
  248 + $email = array_values(array_intersect($assign['email_id'],$this->getEmails('id')));
  249 + if($email){
  250 + $fids = $this->getFolderId($folder,$email);
  251 + // 有目录id和from
  252 + if($fids && !empty($assign['from'])){
  253 + $sql = dbWhere(['folder_id'=>$fids, $folder=='发件箱'?'to':'from'=>$assign['from']]);
  254 + }
  255 + }
  256 +
  257 + // 返回 不在assign中的目录
  258 + $afids = array_values(array_diff($this->getFolderId($folder),$fids));
  259 +
  260 + if($sql && $afids){
  261 + return '(('.dbWhere(['folder_id'=>$afids]).') or ('.$sql.')) and ';
  262 + }else if($afids){
  263 + return dbWhere(['folder_id'=>$afids]).' and ';
  264 + }else if($sql&&!$afids){
  265 + return '('.$sql.') and ';
  266 + }
  267 +
  268 + return '`folder_id` = 0 and ';
  269 +
  270 + }
  271 +
  272 + return dbWhere(['folder_id'=>$this->getFolderId($folder)]).' and ';
  273 +
  274 + }
  275 + private function assignSql2(){
  276 + // 被分配的
  277 + $assign = app()->request('assign');
  278 + $sql = '';
  279 + if(!empty($assign['email_id'])){
  280 + // 分配的联系人
  281 + $email = array_values(array_intersect($assign['email_id'],$this->getEmails('id')));
  282 + if($email&&!empty($assign['from'])){
  283 + $sql = dbWhere(['email_id'=>$email]).' and ('.dbWhere(['from'=>$assign['from']]).' or '.dbWhere(['to'=>$assign['from']]).')';
  284 + }
  285 +
  286 + // 分配的邮箱
  287 + $email2 = array_diff($this->getEmails('id'),$assign['email_id']);
  288 + if($email2){
  289 + if($sql){
  290 + return '('.dbWhere(['email_id'=>$email2]).' or ('.$sql.')) and ';
  291 + }
  292 + return dbWhere(['email_id'=>$email2]);
  293 + }
  294 +
  295 + if($sql){
  296 + return '('.$sql.') and ';
  297 + }
  298 +
  299 +
  300 + return '`email_id` = 0 and ';
  301 + }
  302 +
  303 + // 默认
  304 + return dbWhere(['email_id'=>$this->getEmails('id')]).' and ';
  305 +
  306 + }
  307 + private function assignSql3($folder){
  308 + // 被分配的
  309 + $assign = app()->request('assign');
  310 + $sql = '';
  311 + $fids = [];
  312 + if(!empty($assign['email_id'])){
  313 + // 此处请求中的
  314 + $email = array_diff($this->getEmails('id'),$assign['email_id']);
  315 + if($email){
  316 + $fids = $this->getFolderId($folder,$email);
  317 + // 有目录id和from
  318 + if($fids){
  319 + return dbWhere(['folder_id'=>$fids]);
  320 + }
  321 + }
  322 +
  323 +
  324 + return '`folder_id` = 0 and ';
  325 +
  326 + }
  327 +
  328 + return dbWhere(['folder_id'=>$this->getFolderId($folder)]).' and ';
  329 +
  330 + }
  331 +
271 /** 332 /**
272 * 统计收件箱的数量 333 * 统计收件箱的数量
273 * @author:dc 334 * @author:dc
@@ -282,42 +343,39 @@ class MailListV2 extends Base { @@ -282,42 +343,39 @@ class MailListV2 extends Base {
282 $sql = "select count(*) from `lists` where "; 343 $sql = "select count(*) from `lists` where ";
283 344
284 $where['deleted'] = 0; //未删状态 345 $where['deleted'] = 0; //未删状态
285 - // 屏蔽哪些邮件  
286 -// $where['from.notin'] = $this->from_not_in();  
287 -// $where['_'] = "`from` not like 'postmaster@%'";  
288 -// if(!$where['from.notin']) unset($where['from.notin']);  
289 346
290 // 发件箱 347 // 发件箱
291 if(in_array('hot_send',$show_count_filed)){ 348 if(in_array('hot_send',$show_count_filed)){
292 - $where['folder_id'] = $this->getFolderId('发件箱'); 349 +// $where['folder_id'] = $this->getFolderId('发件箱');
293 // 预热发件箱 350 // 预热发件箱
294 $where['is_hots'] = 1; 351 $where['is_hots'] = 1;
295 - $fCount = db()->cache($this->cache)->count($sql.dbWhere($where)); 352 + $fCount = db()->cache($this->cache)->count($sql.$this->assignSql3('发件箱').dbWhere($where));
296 } 353 }
297 354
298 // 预热收件箱 355 // 预热收件箱
299 if(in_array('hot_inbox',$show_count_filed)) { 356 if(in_array('hot_inbox',$show_count_filed)) {
300 - $where['folder_id'] = $this->getFolderId('收件箱'); 357 +// $where['folder_id'] = $this->getFolderId('收件箱');
301 $where['is_hots'] = 1; 358 $where['is_hots'] = 1;
302 - $sCount = db()->cache($this->cache)->count($sql . dbWhere($where)); 359 + $sCount = db()->cache($this->cache)->count($sql .$this->assignSql3('收件箱'). dbWhere($where));
303 } 360 }
  361 + unset($where['folder_id']);
304 362
305 if(in_array('send',$show_count_filed)) { 363 if(in_array('send',$show_count_filed)) {
306 - $where['folder_id'] = $this->getFolderId('发件箱'); 364 +// $where['folder_id'] = $this->getFolderId('发件箱');
307 $where['is_hots'] = 0; 365 $where['is_hots'] = 0;
308 - $faCount = db()->cache($this->cache)->count($sql . dbWhere($where)); 366 + $faCount = db()->cache($this->cache)->count($sql . $this->assignSql('发件箱').dbWhere($where));
309 } 367 }
310 // 垃圾箱 368 // 垃圾箱
311 if(in_array('junk',$show_count_filed)) { 369 if(in_array('junk',$show_count_filed)) {
312 - $where['folder_id'] = $this->getFolderId('垃圾箱'); 370 +// $where['folder_id'] = $this->getFolderId('垃圾箱');
313 $where['is_hots'] = 0; 371 $where['is_hots'] = 0;
314 - $lajiCount = db()->cache($this->cache)->count($sql . dbWhere($where)); 372 + $lajiCount = db()->cache($this->cache)->count($sql . $this->assignSql('垃圾箱').dbWhere($where));
315 } 373 }
316 374
317 // 收件箱 375 // 收件箱
318 - $where['folder_id'] = $this->getFolderId('收件箱'); 376 +// $where['folder_id'] = $this->getFolderId('收件箱');
319 $where['is_hots'] = 0; 377 $where['is_hots'] = 0;
320 - $sql = "select count(*) from `lists` left join `lists_auto` on `lists`.`id`= `lists_auto`.`list_id` where `lists_auto`.`list_id` IS NULL and "; 378 + $sql = "select count(*) from `lists` left join `lists_auto` on `lists`.`id`= `lists_auto`.`list_id` where `lists_auto`.`list_id` IS NULL and ".$this->assignSql('收件箱');
321 379
322 // 模糊标题搜索 380 // 模糊标题搜索
323 $subject = app()->request('subject'); 381 $subject = app()->request('subject');
@@ -361,9 +419,9 @@ class MailListV2 extends Base { @@ -361,9 +419,9 @@ class MailListV2 extends Base {
361 if(in_array('flagged',$show_count_filed)) { 419 if(in_array('flagged',$show_count_filed)) {
362 $where['flagged'] = 1; 420 $where['flagged'] = 1;
363 unset($where['folder_id']); 421 unset($where['folder_id']);
364 - $where['email_id'] = $emails; 422 +// $where['email_id'] = $emails;
365 unset($where['is_hots']); 423 unset($where['is_hots']);
366 - $flaggedCount = db()->cache($this->cache)->count("SELECT COUNT(*) FROM (select `id` from `lists` where " . dbWhere($where).' group by `udate`) as c'); 424 + $flaggedCount = db()->cache($this->cache)->count("SELECT COUNT(*) FROM (select `id` from `lists` where " . $this->assignSql2().dbWhere($where).' group by `udate`) as c');
367 } 425 }
368 426
369 $data = []; 427 $data = [];