|
@@ -144,7 +144,6 @@ class MailListV2Es extends Base { |
|
@@ -144,7 +144,6 @@ class MailListV2Es extends Base { |
144
|
}
|
144
|
}
|
145
|
}
|
145
|
}
|
146
|
// 搜索标题
|
146
|
// 搜索标题
|
147
|
- $where['subject'] = [];
|
|
|
148
|
$keyword = app()->request('keyword');
|
147
|
$keyword = app()->request('keyword');
|
149
|
if($keyword){
|
148
|
if($keyword){
|
150
|
$where['subject'] = $keyword;
|
149
|
$where['subject'] = $keyword;
|
|
@@ -193,12 +192,15 @@ class MailListV2Es extends Base { |
|
@@ -193,12 +192,15 @@ class MailListV2Es extends Base { |
193
|
];
|
192
|
];
|
194
|
foreach ($where as $k=>$v){
|
193
|
foreach ($where as $k=>$v){
|
195
|
if($k=='subject'){
|
194
|
if($k=='subject'){
|
196
|
- $query['bool']['must'][] = [
|
|
|
197
|
- 'query_string' => [
|
|
|
198
|
- 'query'=>'"'.addcslashes($keyword,'"').'"',
|
|
|
199
|
- "default_field"=> "subject"
|
|
|
200
|
- ]
|
|
|
201
|
- ];
|
195
|
+ if($v){
|
|
|
196
|
+ $query['bool']['must'][] = [
|
|
|
197
|
+ 'query_string' => [
|
|
|
198
|
+ 'query'=>'"'.addcslashes($v,'"').'"',
|
|
|
199
|
+ "default_field"=> "subject"
|
|
|
200
|
+ ]
|
|
|
201
|
+ ];
|
|
|
202
|
+ }
|
|
|
203
|
+
|
202
|
}else{
|
204
|
}else{
|
203
|
$query['bool']['must'][] = [
|
205
|
$query['bool']['must'][] = [
|
204
|
'term' => [
|
206
|
'term' => [
|
|
@@ -216,33 +218,41 @@ class MailListV2Es extends Base { |
|
@@ -216,33 +218,41 @@ class MailListV2Es extends Base { |
216
|
$query['bool']['must'][] = $this->assignSql2();
|
218
|
$query['bool']['must'][] = $this->assignSql2();
|
217
|
}
|
219
|
}
|
218
|
|
220
|
|
219
|
-
|
221
|
+ logs('请求es前');
|
220
|
$result = $this->es->search(['query'=>$query],($page-1) * $limit,$limit,['udate'=>"desc"]);
|
222
|
$result = $this->es->search(['query'=>$query],($page-1) * $limit,$limit,['udate'=>"desc"]);
|
221
|
- app()->_json($result);
|
223
|
+ logs('请求es后');
|
222
|
|
224
|
|
|
|
225
|
+ $total = $result['hits']['total']['value']??0;
|
|
|
226
|
+ $lists = $result['hits']['hits']??[];
|
223
|
// map
|
227
|
// map
|
224
|
-// $lists = array_map(function ($v){
|
|
|
225
|
-// $v['uuid'] = md5($v['email_id'].'-'.$v['folder_id'].'-'.$v['uid']);
|
|
|
226
|
-// if(!empty($v['description'])){
|
|
|
227
|
-// $v['description'] = @html_entity_decode($v['description'], ENT_COMPAT, 'UTF-8');
|
|
|
228
|
-// }
|
|
|
229
|
-// $v['to_name'] = @json_decode($v['to_name'],true);
|
|
|
230
|
-// $v['to_name'] = $v['to_name']?:[];
|
|
|
231
|
-// if($v['to_name']){
|
|
|
232
|
-// if(!empty($v['to_name'][0]['email'])){
|
|
|
233
|
-// $v['to'] = $v['to_name'][0]['email'];
|
|
|
234
|
-// }
|
|
|
235
|
-// $v['to_name'] = MailFun::mb_coding($v['to_name'][0]['name']??'');
|
|
|
236
|
-// }
|
|
|
237
|
-// if(is_array($v['to_name'])){
|
|
|
238
|
-// $v['to_name'] = '';
|
|
|
239
|
-// }
|
|
|
240
|
-// return $v;
|
|
|
241
|
-// },$lists?:[]);
|
|
|
242
|
-
|
|
|
243
|
-
|
|
|
244
|
-
|
|
|
245
|
-// app()->_json(listsPage($lists,$total,$page,$limit));
|
228
|
+ $lists = array_map(function ($v){
|
|
|
229
|
+ $v = $v['_source'];
|
|
|
230
|
+ $v['id'] = $v['uuid'];
|
|
|
231
|
+
|
|
|
232
|
+ $v['from_name'] = $v['from']['name']??'';
|
|
|
233
|
+ $v['from'] = $v['from']['email']??'';
|
|
|
234
|
+
|
|
|
235
|
+ $v['uuid'] = md5($v['email_id'].'-'.$v['folder_id'].'-'.$v['uid']);
|
|
|
236
|
+ if(!empty($v['description'])){
|
|
|
237
|
+ $v['description'] = @html_entity_decode($v['description'], ENT_COMPAT, 'UTF-8');
|
|
|
238
|
+ }
|
|
|
239
|
+ $v['to_name'] = @json_decode($v['to_name'],true);
|
|
|
240
|
+ $v['to_name'] = $v['to_name']?:[];
|
|
|
241
|
+ if($v['to_name']){
|
|
|
242
|
+ if(!empty($v['to_name'][0]['email'])){
|
|
|
243
|
+ $v['to'] = $v['to_name'][0]['email'];
|
|
|
244
|
+ }
|
|
|
245
|
+ $v['to_name'] = MailFun::mb_coding($v['to_name'][0]['name']??'');
|
|
|
246
|
+ }
|
|
|
247
|
+ if(is_array($v['to_name'])){
|
|
|
248
|
+ $v['to_name'] = '';
|
|
|
249
|
+ }
|
|
|
250
|
+ return $v;
|
|
|
251
|
+ },$lists?:[]);
|
|
|
252
|
+
|
|
|
253
|
+
|
|
|
254
|
+
|
|
|
255
|
+ app()->_json(listsPage($lists,$total,$page,$limit));
|
246
|
|
256
|
|
247
|
}
|
257
|
}
|
248
|
|
258
|
|
|
@@ -401,14 +411,20 @@ class MailListV2Es extends Base { |
|
@@ -401,14 +411,20 @@ class MailListV2Es extends Base { |
401
|
}
|
411
|
}
|
402
|
|
412
|
|
403
|
// 默认
|
413
|
// 默认
|
404
|
- return dbWhere(['email_id'=>$this->getEmails('id')]).' and ';
|
414
|
+ return [
|
|
|
415
|
+ 'query'=>[
|
|
|
416
|
+ 'bool'=> [
|
|
|
417
|
+ 'must'=>[['terms'=>['email_id'=> $this->getEmails('id')]]]
|
|
|
418
|
+ ]
|
|
|
419
|
+ ]
|
|
|
420
|
+ ];
|
405
|
|
421
|
|
406
|
}
|
422
|
}
|
|
|
423
|
+
|
407
|
private function assignSql3($folder){
|
424
|
private function assignSql3($folder){
|
408
|
// 被分配的
|
425
|
// 被分配的
|
409
|
$assign = app()->request('assign');
|
426
|
$assign = app()->request('assign');
|
410
|
- $sql = '';
|
|
|
411
|
- $fids = [];
|
427
|
+
|
412
|
if(!empty($assign['email_id'])){
|
428
|
if(!empty($assign['email_id'])){
|
413
|
// 此处请求中的
|
429
|
// 此处请求中的
|
414
|
$email = array_diff($this->getEmails('id'),$assign['email_id']);
|
430
|
$email = array_diff($this->getEmails('id'),$assign['email_id']);
|
|
@@ -416,15 +432,39 @@ class MailListV2Es extends Base { |
|
@@ -416,15 +432,39 @@ class MailListV2Es extends Base { |
416
|
$fids = $this->getFolderId($folder,$email);
|
432
|
$fids = $this->getFolderId($folder,$email);
|
417
|
// 有目录id和from
|
433
|
// 有目录id和from
|
418
|
if($fids){
|
434
|
if($fids){
|
419
|
- return dbWhere(['folder_id'=>$fids]).' and ';
|
435
|
+ return [
|
|
|
436
|
+ 'query'=>[
|
|
|
437
|
+ 'bool' =>[
|
|
|
438
|
+ 'must' =>[
|
|
|
439
|
+ ['terms'=>['folder_id'=>$fids]]
|
|
|
440
|
+ ]
|
|
|
441
|
+ ]
|
|
|
442
|
+ ]
|
|
|
443
|
+ ];
|
420
|
}
|
444
|
}
|
421
|
}
|
445
|
}
|
422
|
|
446
|
|
423
|
-
|
|
|
424
|
- return '`folder_id` = -1 and ';
|
447
|
+ return [
|
|
|
448
|
+ 'query'=>[
|
|
|
449
|
+ 'bool' =>[
|
|
|
450
|
+ 'must' =>[
|
|
|
451
|
+ ['term'=>['folder_id'=>-1]]
|
|
|
452
|
+ ]
|
|
|
453
|
+ ]
|
|
|
454
|
+ ]
|
|
|
455
|
+ ];
|
425
|
|
456
|
|
426
|
}
|
457
|
}
|
427
|
|
458
|
|
|
|
459
|
+ return [
|
|
|
460
|
+ 'query'=>[
|
|
|
461
|
+ 'bool' =>[
|
|
|
462
|
+ 'must' =>[
|
|
|
463
|
+ ['terms'=>['folder_id'=> $this->getFolderId($folder)]]
|
|
|
464
|
+ ]
|
|
|
465
|
+ ]
|
|
|
466
|
+ ]
|
|
|
467
|
+ ];
|
428
|
return dbWhere(['folder_id'=>$this->getFolderId($folder)]).' and ';
|
468
|
return dbWhere(['folder_id'=>$this->getFolderId($folder)]).' and ';
|
429
|
|
469
|
|
430
|
}
|
470
|
}
|
|
@@ -432,9 +472,133 @@ class MailListV2Es extends Base { |
|
@@ -432,9 +472,133 @@ class MailListV2Es extends Base { |
432
|
|
472
|
|
433
|
|
473
|
|
434
|
public function count(){
|
474
|
public function count(){
|
435
|
- return [];
|
475
|
+ if(!$this->getEmails('id')){
|
|
|
476
|
+ app()->e('email_request_required');
|
|
|
477
|
+ }
|
|
|
478
|
+
|
|
|
479
|
+ $body = [];
|
|
|
480
|
+ $body['query'] = [
|
|
|
481
|
+ 'bool'=>[
|
|
|
482
|
+ 'must'=>[
|
|
|
483
|
+ ['term'=>['deleted'=>0]]
|
|
|
484
|
+ ]
|
|
|
485
|
+ ]
|
|
|
486
|
+ ];
|
|
|
487
|
+ // 时间 必须是数组
|
|
|
488
|
+ $udate = app()->request('udate');
|
|
|
489
|
+ if($udate && is_array($udate) && count($udate) == 2){
|
|
|
490
|
+ $udate = array_values($udate);
|
|
|
491
|
+ $udate = array_map(function ($v){
|
|
|
492
|
+ if(is_numeric($v)) return $v;
|
|
|
493
|
+ return strtotime($v);
|
|
|
494
|
+ },$udate);
|
|
|
495
|
+ // 时间范围搜索
|
|
|
496
|
+ $body['query']['bool']['must'][] = [
|
|
|
497
|
+ 'query' => [
|
|
|
498
|
+ 'range' => [
|
|
|
499
|
+ 'udate' => [
|
|
|
500
|
+ 'gte' => $udate[0], // 大于等于开始日期
|
|
|
501
|
+ 'lte' => $udate[1] // 小于等于结束日期
|
|
|
502
|
+ ]
|
|
|
503
|
+ ]
|
|
|
504
|
+ ]
|
|
|
505
|
+ ];
|
|
|
506
|
+
|
|
|
507
|
+ }
|
|
|
508
|
+
|
|
|
509
|
+
|
|
|
510
|
+ // show_count_filed
|
|
|
511
|
+ $show_count_filed = app()->requestArr('show_count_filed',['inbox', 'send', 'unseen', 'flagged', 'junk', 'hot_inbox', 'hot_send']);
|
|
|
512
|
+
|
|
|
513
|
+
|
|
|
514
|
+ // 发件箱
|
|
|
515
|
+ if(in_array('hot_send',$show_count_filed)){
|
|
|
516
|
+ // 预热发件箱
|
|
|
517
|
+ $fCount = $this->countHot($body,'发件箱');
|
|
|
518
|
+ }
|
|
|
519
|
+
|
|
|
520
|
+ // 预热收件箱
|
|
|
521
|
+ if(in_array('hot_inbox',$show_count_filed)) {
|
|
|
522
|
+ $sCount = $this->countHot($body,'收件箱');
|
|
|
523
|
+ }
|
|
|
524
|
+
|
|
|
525
|
+ if(in_array('send',$show_count_filed)) {
|
|
|
526
|
+ $faCount = $this->countMail($body,'发件箱');
|
|
|
527
|
+ }
|
|
|
528
|
+// 垃圾箱
|
|
|
529
|
+ if(in_array('junk',$show_count_filed)) {
|
|
|
530
|
+ $lajiCount = $this->countMail($body,'垃圾箱');
|
|
|
531
|
+ }
|
|
|
532
|
+
|
|
|
533
|
+ // 收件箱
|
|
|
534
|
+ $lajiCount = $this->countMail($body,'收件箱');
|
|
|
535
|
+
|
|
|
536
|
+ // 收件箱
|
|
|
537
|
+ if(in_array('inbox',$show_count_filed) || in_array('replied',$show_count_filed)) {
|
|
|
538
|
+ $repliedCount = $shouCount = $this->countMail($body,'收件箱');
|
|
|
539
|
+ }
|
|
|
540
|
+
|
|
|
541
|
+ // 未读
|
|
|
542
|
+ if(in_array('unseen',$show_count_filed)) {
|
|
|
543
|
+ $seenCount = $shouCount = $this->countMail($body,'收件箱', 0);
|
|
|
544
|
+ }
|
|
|
545
|
+
|
|
|
546
|
+
|
|
|
547
|
+ // 星标
|
|
|
548
|
+ if(in_array('flagged',$show_count_filed)) {
|
|
|
549
|
+ $flaggedCount = $this->countFlagged($body);
|
|
|
550
|
+ }
|
|
|
551
|
+
|
|
|
552
|
+ $data = [];
|
|
|
553
|
+ if(isset($shouCount)) $data['inbox'] = $shouCount;
|
|
|
554
|
+ if(isset($repliedCount)) $data['replied'] = $repliedCount;
|
|
|
555
|
+ if(isset($faCount)) $data['send'] = $faCount;
|
|
|
556
|
+ if(isset($seenCount)) $data['unseen'] = $seenCount;
|
|
|
557
|
+ if(isset($flaggedCount)) $data['flagged'] = $flaggedCount;
|
|
|
558
|
+ if(isset($lajiCount)) $data['junk'] = $lajiCount;
|
|
|
559
|
+ if(isset($sCount)) $data['hot_inbox'] = $sCount;
|
|
|
560
|
+ if(isset($fCount)) $data['hot_send'] = $fCount;
|
|
|
561
|
+
|
|
|
562
|
+ app()->_json($data);
|
436
|
}
|
563
|
}
|
437
|
|
564
|
|
|
|
565
|
+ /**
|
|
|
566
|
+ * 统计预热邮件
|
|
|
567
|
+ * @param $body
|
|
|
568
|
+ * @param $folder
|
|
|
569
|
+ * @author:dc
|
|
|
570
|
+ * @time 2025/3/6 15:24
|
|
|
571
|
+ */
|
|
|
572
|
+ private function countHot($body,$folder){
|
|
|
573
|
+ $body['query']['bool']['must'][] = ['term'=>['is_hots'=>1]];
|
|
|
574
|
+ $body['query']['bool']['must'][] = $this->assignSql3($folder);
|
|
|
575
|
+ return $this->es->count($body);
|
|
|
576
|
+ }
|
|
|
577
|
+
|
|
|
578
|
+ private function countMail($body,$folder,$seen=null){
|
|
|
579
|
+ if($folder == '收件箱'){
|
|
|
580
|
+ $body['query']['bool']['must'][] = ['term'=>['is_auto'=>0]];
|
|
|
581
|
+ }
|
|
|
582
|
+ if($seen!==null){
|
|
|
583
|
+ $body['query']['bool']['must'][] = ['term'=>['seen'=>$seen]];
|
|
|
584
|
+ }
|
|
|
585
|
+ $body['query']['bool']['must'][] = ['term'=>['is_hots'=>0]];
|
|
|
586
|
+ $body['query']['bool']['must'][] = $this->assignSql($folder);
|
|
|
587
|
+ return $this->es->count($body);
|
|
|
588
|
+ }
|
|
|
589
|
+
|
|
|
590
|
+ /**
|
|
|
591
|
+ * 统计星标
|
|
|
592
|
+ * @param $body
|
|
|
593
|
+ * @return int|mixed
|
|
|
594
|
+ * @author:dc
|
|
|
595
|
+ * @time 2025/3/6 16:01
|
|
|
596
|
+ */
|
|
|
597
|
+ private function countFlagged($body){
|
|
|
598
|
+ $body['query']['bool']['must'][] = ['term'=>['flagged'=>1]];
|
|
|
599
|
+ $body['query']['bool']['must'][] = $this->assignSql2();
|
|
|
600
|
+ return $this->es->count($body);
|
|
|
601
|
+ }
|
438
|
|
602
|
|
439
|
}
|
603
|
}
|
440
|
|
604
|
|