作者 邓超

修复 分配邮箱后的操作

@@ -44,6 +44,7 @@ class MailListV2Es2 extends Base { @@ -44,6 +44,7 @@ class MailListV2Es2 extends Base {
44 * emails 邮箱 44 * emails 邮箱
45 * folder 文件夹 45 * folder 文件夹
46 * from_not_in 不在这些发件箱的邮件 46 * from_not_in 不在这些发件箱的邮件
  47 + * not_in_email_id 不在这些邮箱id的邮件(数组)
47 * @throws \Lib\Err 48 * @throws \Lib\Err
48 * @author:dc 49 * @author:dc
49 * @time 2024/7/18 11:40 50 * @time 2024/7/18 11:40
@@ -205,11 +206,16 @@ class MailListV2Es2 extends Base { @@ -205,11 +206,16 @@ class MailListV2Es2 extends Base {
205 } 206 }
206 } 207 }
207 if($notinquery){ 208 if($notinquery){
208 - $query['bool']['must_not'] = $notinquery; 209 + $query['bool']['must_not'] = array_merge($query['bool']['must_not'] ?? [], $notinquery);
209 } 210 }
210 } 211 }
211 } 212 }
212 213
  214 + // 排除指定邮箱id的邮件(数组,全部文件夹生效)
  215 + if($notInEmailId = $this->notInEmailIdQuery()){
  216 + $query['bool']['must_not'] = array_merge($query['bool']['must_not'] ?? [], $notInEmailId);
  217 + }
  218 +
213 // logs('lists '.json_encode(['query'=>['constant_score'=>['filter'=>$query]]])); 219 // logs('lists '.json_encode(['query'=>['constant_score'=>['filter'=>$query]]]));
214 $result = $this->es->search(['query'=>['constant_score'=>['filter'=>$query]]],($page-1) * $limit,$limit,['udate'=>"desc"],(($where['is_hots']??0)==1||($where['is_auto']??0)==1||$folder=='垃圾箱')?10000:true); 220 $result = $this->es->search(['query'=>['constant_score'=>['filter'=>$query]]],($page-1) * $limit,$limit,['udate'=>"desc"],(($where['is_hots']??0)==1||($where['is_auto']??0)==1||$folder=='垃圾箱')?10000:true);
215 221
@@ -303,6 +309,27 @@ class MailListV2Es2 extends Base { @@ -303,6 +309,27 @@ class MailListV2Es2 extends Base {
303 309
304 310
305 311
  312 + /**
  313 + * 排除指定邮箱id的条件(not_in_email_id,数组或逗号分隔)
  314 + * @return array
  315 + * @author:dc
  316 + */
  317 + private function notInEmailIdQuery(){
  318 + $not_in_email_id = app()->requestArr('assign')['not_in_email_id']??[];
  319 + if(!$not_in_email_id) return [];
  320 + if(!is_array($not_in_email_id)) $not_in_email_id = [$not_in_email_id];
  321 + $ids = [];
  322 + foreach ($not_in_email_id as $v){
  323 + if(is_numeric($v)) $ids[] = intval($v);
  324 + }
  325 + if(!$ids) return [];
  326 +
  327 + return [
  328 + ['terms'=>['email_id'=>array_values(array_unique($ids))]]
  329 + ];
  330 + }
  331 +
  332 +
306 private function assignSql($folder){ 333 private function assignSql($folder){
307 // 被分配的 334 // 被分配的
308 $assign = app()->requestArr('assign'); 335 $assign = app()->requestArr('assign');
@@ -372,6 +399,12 @@ class MailListV2Es2 extends Base { @@ -372,6 +399,12 @@ class MailListV2Es2 extends Base {
372 ] 399 ]
373 ]; 400 ];
374 if(count($this->getEmails('id')) == 1) $body['query']['bool']['must'][] = ['terms'=>['email_id'=>$this->getEmails('id')]]; 401 if(count($this->getEmails('id')) == 1) $body['query']['bool']['must'][] = ['terms'=>['email_id'=>$this->getEmails('id')]];
  402 +
  403 + // 排除指定邮箱id的邮件(计数也要同步排除)
  404 + if($notInEmailId = $this->notInEmailIdQuery()){
  405 + $body['query']['bool']['must_not'] = array_merge($body['query']['bool']['must_not'] ?? [], $notInEmailId);
  406 + }
  407 +
375 // 时间 必须是数组 408 // 时间 必须是数组
376 $udate = app()->request('udate'); 409 $udate = app()->request('udate');
377 if($udate && is_array($udate) && count($udate) == 2){ 410 if($udate && is_array($udate) && count($udate) == 2){
@@ -483,7 +516,7 @@ class MailListV2Es2 extends Base { @@ -483,7 +516,7 @@ class MailListV2Es2 extends Base {
483 } 516 }
484 } 517 }
485 if($notinquery){ 518 if($notinquery){
486 - $body['query']['bool']['must_not'] = $notinquery; 519 + $body['query']['bool']['must_not'] = array_merge($body['query']['bool']['must_not'] ?? [], $notinquery);
487 } 520 }
488 } 521 }
489 522