作者 邓超

fob 接口调整

... ... @@ -30,11 +30,11 @@ class MailListV2 extends Base {
* @author:dc
* @time 2024/7/19 11:37
*/
private function getFolderId(string $folder){
private function getFolderId(string $folder,$emails=[]){
// 查询 文件夹
static $folderList;
if(!$folderList){
$folderList = db()->all(folderSql::all($this->getEmails('id')));
$folderList = db()->all(folderSql::all($emails?:$this->getEmails('id')));
}
$folder_id = [];
// 文件夹id
... ... @@ -53,39 +53,6 @@ class MailListV2 extends Base {
}
private function from_not_in(){
$where = [];
/**
* 不查询哪些发件人的邮件
*/
$form_not_in = app()->request('from_not_in');
if($form_not_in){
if(is_string($form_not_in)){
$form_not_in = explode(',',$form_not_in);
}
$form_not_in = is_array($form_not_in) ? $form_not_in : [$form_not_in];
$form_not_in = array_filter($form_not_in,function ($v){
if(is_string($v) && Verify::sEmail($v)){
return true;
}
return false;
});
if($form_not_in){
$where = array_merge($where,$form_not_in);
}
}
// 过滤掉
foreach ($where as $k=>$item){
if(stripos($item,'postmaster@') === 0){
unset($where[$k]);
}
}
$where[] = 'noreply@google.com';
return $where;
}
/**
* 处理like条件
* @param $str
... ... @@ -167,12 +134,14 @@ class MailListV2 extends Base {
// 星标就不加文件夹赛选
if(empty($where['flagged'])){
$folder_id = $this->getFolderId($folder);
// $folder_id = $this->getFolderId($folder);
//目录
$where['folder_id'] = $folder_id;
// $where['folder_id'] = $folder_id;
$where['_'] = $this->assignSql($folder);
}else{
$where['lists|email_id'] = $this->getEmails('id');
// $where['lists|email_id'] = $this->getEmails('id');
$where['_'] = $this->assignSql2();
}
if($ids) $where['id'] = $ids;
... ... @@ -268,6 +237,98 @@ class MailListV2 extends Base {
}
private function assignSql($folder){
// 被分配的
$assign = app()->request('assign');
$sql = '';
$fids = [];
if(!empty($assign['email_id'])){
// 此处请求中的
$email = array_values(array_intersect($assign['email_id'],$this->getEmails('id')));
if($email){
$fids = $this->getFolderId($folder,$email);
// 有目录id和from
if($fids && !empty($assign['from'])){
$sql = dbWhere(['folder_id'=>$fids, $folder=='发件箱'?'to':'from'=>$assign['from']]);
}
}
// 返回 不在assign中的目录
$afids = array_values(array_diff($this->getFolderId($folder),$fids));
if($sql && $afids){
return '(('.dbWhere(['folder_id'=>$afids]).') or ('.$sql.')) and ';
}else if($afids){
return dbWhere(['folder_id'=>$afids]).' and ';
}else if($sql&&!$afids){
return '('.$sql.') and ';
}
return '`folder_id` = 0 and ';
}
return dbWhere(['folder_id'=>$this->getFolderId($folder)]).' and ';
}
private function assignSql2(){
// 被分配的
$assign = app()->request('assign');
$sql = '';
if(!empty($assign['email_id'])){
// 分配的联系人
$email = array_values(array_intersect($assign['email_id'],$this->getEmails('id')));
if($email&&!empty($assign['from'])){
$sql = dbWhere(['email_id'=>$email]).' and ('.dbWhere(['from'=>$assign['from']]).' or '.dbWhere(['to'=>$assign['from']]).')';
}
// 分配的邮箱
$email2 = array_diff($this->getEmails('id'),$assign['email_id']);
if($email2){
if($sql){
return '('.dbWhere(['email_id'=>$email2]).' or ('.$sql.')) and ';
}
return dbWhere(['email_id'=>$email2]);
}
if($sql){
return '('.$sql.') and ';
}
return '`email_id` = 0 and ';
}
// 默认
return dbWhere(['email_id'=>$this->getEmails('id')]).' and ';
}
private function assignSql3($folder){
// 被分配的
$assign = app()->request('assign');
$sql = '';
$fids = [];
if(!empty($assign['email_id'])){
// 此处请求中的
$email = array_diff($this->getEmails('id'),$assign['email_id']);
if($email){
$fids = $this->getFolderId($folder,$email);
// 有目录id和from
if($fids){
return dbWhere(['folder_id'=>$fids]);
}
}
return '`folder_id` = 0 and ';
}
return dbWhere(['folder_id'=>$this->getFolderId($folder)]).' and ';
}
/**
* 统计收件箱的数量
* @author:dc
... ... @@ -282,42 +343,39 @@ class MailListV2 extends Base {
$sql = "select count(*) from `lists` where ";
$where['deleted'] = 0; //未删状态
// 屏蔽哪些邮件
// $where['from.notin'] = $this->from_not_in();
// $where['_'] = "`from` not like 'postmaster@%'";
// if(!$where['from.notin']) unset($where['from.notin']);
// 发件箱
if(in_array('hot_send',$show_count_filed)){
$where['folder_id'] = $this->getFolderId('发件箱');
// $where['folder_id'] = $this->getFolderId('发件箱');
// 预热发件箱
$where['is_hots'] = 1;
$fCount = db()->cache($this->cache)->count($sql.dbWhere($where));
$fCount = db()->cache($this->cache)->count($sql.$this->assignSql3('发件箱').dbWhere($where));
}
// 预热收件箱
if(in_array('hot_inbox',$show_count_filed)) {
$where['folder_id'] = $this->getFolderId('收件箱');
// $where['folder_id'] = $this->getFolderId('收件箱');
$where['is_hots'] = 1;
$sCount = db()->cache($this->cache)->count($sql . dbWhere($where));
$sCount = db()->cache($this->cache)->count($sql .$this->assignSql3('收件箱'). dbWhere($where));
}
unset($where['folder_id']);
if(in_array('send',$show_count_filed)) {
$where['folder_id'] = $this->getFolderId('发件箱');
// $where['folder_id'] = $this->getFolderId('发件箱');
$where['is_hots'] = 0;
$faCount = db()->cache($this->cache)->count($sql . dbWhere($where));
$faCount = db()->cache($this->cache)->count($sql . $this->assignSql('发件箱').dbWhere($where));
}
// 垃圾箱
if(in_array('junk',$show_count_filed)) {
$where['folder_id'] = $this->getFolderId('垃圾箱');
// $where['folder_id'] = $this->getFolderId('垃圾箱');
$where['is_hots'] = 0;
$lajiCount = db()->cache($this->cache)->count($sql . dbWhere($where));
$lajiCount = db()->cache($this->cache)->count($sql . $this->assignSql('垃圾箱').dbWhere($where));
}
// 收件箱
$where['folder_id'] = $this->getFolderId('收件箱');
// $where['folder_id'] = $this->getFolderId('收件箱');
$where['is_hots'] = 0;
$sql = "select count(*) from `lists` left join `lists_auto` on `lists`.`id`= `lists_auto`.`list_id` where `lists_auto`.`list_id` IS NULL and ";
$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('收件箱');
// 模糊标题搜索
$subject = app()->request('subject');
... ... @@ -361,9 +419,9 @@ class MailListV2 extends Base {
if(in_array('flagged',$show_count_filed)) {
$where['flagged'] = 1;
unset($where['folder_id']);
$where['email_id'] = $emails;
// $where['email_id'] = $emails;
unset($where['is_hots']);
$flaggedCount = db()->cache($this->cache)->count("SELECT COUNT(*) FROM (select `id` from `lists` where " . dbWhere($where).' group by `udate`) as c');
$flaggedCount = db()->cache($this->cache)->count("SELECT COUNT(*) FROM (select `id` from `lists` where " . $this->assignSql2().dbWhere($where).' group by `udate`) as c');
}
$data = [];
... ...