正在显示
1 个修改的文件
包含
283 行增加
和
0 行删除
controller/fob_ai/MailListV2.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace Controller\fob_ai; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | + | ||
| 7 | +use Controller\Base; | ||
| 8 | +use Lib\Verify; | ||
| 9 | +use Model\folderSql; | ||
| 10 | +use function Swoole\Coroutine\Http\request; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 黑格 fob 那边专用 业务 | ||
| 14 | + * 为定制逻辑 | ||
| 15 | + * @author:dc | ||
| 16 | + * @time 2024/7/18 11:40 | ||
| 17 | + * Class MailList | ||
| 18 | + * @package Controller\fob_ai | ||
| 19 | + */ | ||
| 20 | +class MailListV2 extends Base { | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 当前邮箱下指定的文件夹 | ||
| 24 | + * @param string $folder | ||
| 25 | + * @return array | ||
| 26 | + * @throws \Lib\Err | ||
| 27 | + * @author:dc | ||
| 28 | + * @time 2024/7/19 11:37 | ||
| 29 | + */ | ||
| 30 | + private function getFolderId(string $folder){ | ||
| 31 | + // 查询 文件夹 | ||
| 32 | + static $folderList; | ||
| 33 | + if(!$folderList){ | ||
| 34 | + $folderList = db()->all(folderSql::all($this->getEmails('id'))); | ||
| 35 | + } | ||
| 36 | + $folder_id = []; | ||
| 37 | + // 文件夹id | ||
| 38 | + if($folderList){ | ||
| 39 | + foreach ($folderList as $item){ | ||
| 40 | + if(folderAlias($item['folder']) == $folder){ | ||
| 41 | + $folder_id[] = $item['id']; | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + if(!$folder_id){ | ||
| 46 | + app()->e('folder_not_fount'); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + return $folder_id; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + | ||
| 53 | + private function from_not_in(){ | ||
| 54 | + $where = []; | ||
| 55 | + /** | ||
| 56 | + * 不查询哪些发件人的邮件 | ||
| 57 | + */ | ||
| 58 | + $form_not_in = app()->request('from_not_in'); | ||
| 59 | + if($form_not_in){ | ||
| 60 | + if(is_string($form_not_in)){ | ||
| 61 | + $form_not_in = explode(',',$form_not_in); | ||
| 62 | + } | ||
| 63 | + $form_not_in = is_array($form_not_in) ? $form_not_in : [$form_not_in]; | ||
| 64 | + $form_not_in = array_filter($form_not_in,function ($v){ | ||
| 65 | + if(is_string($v) && Verify::sEmail($v)){ | ||
| 66 | + return true; | ||
| 67 | + } | ||
| 68 | + return false; | ||
| 69 | + }); | ||
| 70 | + if($form_not_in){ | ||
| 71 | + $where = array_merge($where,$form_not_in); | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + // 过滤掉 | ||
| 75 | + foreach ($where as $k=>$item){ | ||
| 76 | + if(stripos($item,'postmaster@') === 0){ | ||
| 77 | + unset($where[$k]); | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + return $where; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 邮件列表 | ||
| 86 | + * 接收参数 | ||
| 87 | + * page 分页 | ||
| 88 | + * limit 每页数量 | ||
| 89 | + * mail_id 指定邮件id | ||
| 90 | + * attachment 是否附件 | ||
| 91 | + * emails 邮箱 | ||
| 92 | + * folder 文件夹 | ||
| 93 | + * from_not_in 不在这些发件箱的邮件 | ||
| 94 | + * @throws \Lib\Err | ||
| 95 | + * @author:dc | ||
| 96 | + * @time 2024/7/18 11:40 | ||
| 97 | + */ | ||
| 98 | + public function lists(){ | ||
| 99 | + | ||
| 100 | + // 分页 页数 | ||
| 101 | + $page = app()->request('page',1,'intval'); | ||
| 102 | + $page = $page ? $page : 1; | ||
| 103 | + | ||
| 104 | + $limit = app()->request('limit',20,'intval'); | ||
| 105 | + $limit = $limit ? $limit : 1; | ||
| 106 | + | ||
| 107 | + // 指定id | ||
| 108 | + $ids = app()->request('mail_id'); | ||
| 109 | + $ids = is_array($ids) ? $ids : [$ids]; | ||
| 110 | + foreach ($ids as $i=>$d){ | ||
| 111 | + if(!is_numeric($d)){ | ||
| 112 | + unset($ids[$i]); | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + $where = ['lists|email_id'=>$this->getEmails('id')]; | ||
| 117 | + | ||
| 118 | + // 目录 | ||
| 119 | + $folder = app()->request('folder','收件箱'); | ||
| 120 | + // 只允许查询这里文件夹 | ||
| 121 | + if(!in_array($folder,['收件箱','发件箱','垃圾箱','星标邮件','预热收件箱','预热发件箱','Starred'])){ | ||
| 122 | + app()->e('folder_not_fount'); | ||
| 123 | + } | ||
| 124 | + $where['is_hots'] = 0; | ||
| 125 | + | ||
| 126 | + if($folder=='星标邮件'||$folder=='Starred'){ | ||
| 127 | + $folder = '收件箱'; | ||
| 128 | + $where['flagged'] = 1; // 星标 | ||
| 129 | + }elseif ($folder=='预热收件箱'){ | ||
| 130 | + $folder = '收件箱'; | ||
| 131 | + $where['is_hots'] = 1; | ||
| 132 | + }elseif ($folder=='预热发件箱'){ | ||
| 133 | + $folder = '发件箱'; | ||
| 134 | + $where['is_hots'] = 1; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + $folder_id = $this->getFolderId($folder); | ||
| 138 | + | ||
| 139 | + //目录 | ||
| 140 | + $where['folder_id'] = $folder_id; | ||
| 141 | + if($ids) $where['id'] = $ids; | ||
| 142 | + | ||
| 143 | + if(app()->request('attachment',0,'bool_Val')){ | ||
| 144 | + // 附件 | ||
| 145 | + $where['is_file'] = 1; //附件 | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + // 软删 | ||
| 149 | + $where['deleted'] = 0; | ||
| 150 | + | ||
| 151 | + $where['from.notin'] = $this->from_not_in(); | ||
| 152 | + $where['_'] = "`from` not like 'postmaster@%%'"; | ||
| 153 | + if(!$where['from.notin']) unset($where['from.notin']); | ||
| 154 | + | ||
| 155 | + $filed = '`id`,`uid`,`subject`,`from`,`from_name`,`flagged`,`seen`,`udate`,`folder_id`,`is_file`,`description`,`lists`.`email_id`,`to_name`'; | ||
| 156 | + | ||
| 157 | + $sql = "select %s from `lists` where ".dbWhere($where); | ||
| 158 | + | ||
| 159 | + // 查询列表数据 | ||
| 160 | + $lists = db()->all(sprintf($sql,$filed)." order by `udate` desc limit {$limit} offset ".(($page-1)*$limit)); | ||
| 161 | + | ||
| 162 | + // map | ||
| 163 | + $lists = array_map(function ($v){ | ||
| 164 | + $v['uuid'] = md5($v['email_id'].'-'.$v['folder_id'].'-'.$v['uid']); | ||
| 165 | + if(!empty($v['description'])){ | ||
| 166 | + $v['description'] = @html_entity_decode($v['description'], ENT_COMPAT, 'UTF-8'); | ||
| 167 | + } | ||
| 168 | + $v['to_name'] = @json_decode($v['to_name'],true); | ||
| 169 | + $v['to_name'] = $v['to_name']?:[]; | ||
| 170 | + if($v['to_name']){ | ||
| 171 | + if(!empty($v['to_name'][0]['email'])){ | ||
| 172 | + $v['to'] = $v['to_name'][0]['email']; | ||
| 173 | + } | ||
| 174 | + $v['to_name'] = $v['to_name'][0]['name']??''; | ||
| 175 | + } | ||
| 176 | + if(is_array($v['to_name'])){ | ||
| 177 | + $v['to_name'] = ''; | ||
| 178 | + } | ||
| 179 | + return $v; | ||
| 180 | + },$lists?:[]); | ||
| 181 | + | ||
| 182 | + // 总数 | ||
| 183 | + $total = db()->cache(600)->count(sprintf($sql,"count(*)")); | ||
| 184 | + | ||
| 185 | + app()->_json(listsPage($lists,$total,$page,$limit)); | ||
| 186 | + | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + | ||
| 190 | + /** | ||
| 191 | + * 统计收件箱的数量 | ||
| 192 | + * @author:dc | ||
| 193 | + * @time 2024/7/19 10:15 | ||
| 194 | + */ | ||
| 195 | + public function count(){ | ||
| 196 | + $emails = $this->getEmails('id'); | ||
| 197 | + | ||
| 198 | + // show_count_filed | ||
| 199 | + $show_count_filed = app()->requestArr('show_count_filed',['inbox', 'send', 'unseen', 'flagged', 'junk', 'hot_inbox', 'hot_send']); | ||
| 200 | + | ||
| 201 | + $sql = "select count(*) from `lists` where "; | ||
| 202 | + | ||
| 203 | + $where = ['email_id'=>$emails]; | ||
| 204 | + $where['deleted'] = 0; //未删状态 | ||
| 205 | + // 屏蔽哪些邮件 | ||
| 206 | + $where['from.notin'] = $this->from_not_in(); | ||
| 207 | + $where['_'] = "`from` not like 'postmaster@%'"; | ||
| 208 | + if(!$where['from.notin']) unset($where['from.notin']); | ||
| 209 | + | ||
| 210 | + // 发件箱 | ||
| 211 | + if(in_array('hot_send',$show_count_filed)){ | ||
| 212 | + $where['folder_id'] = $this->getFolderId('发件箱'); | ||
| 213 | + // 预热发件箱 | ||
| 214 | + $where['is_hots'] = 1; | ||
| 215 | + $fCount = db()->cache(600)->count($sql.dbWhere($where)); | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + // 预热收件箱 | ||
| 219 | + if(in_array('hot_inbox',$show_count_filed)) { | ||
| 220 | + $where['folder_id'] = $this->getFolderId('收件箱'); | ||
| 221 | + $where['is_hots'] = 1; | ||
| 222 | + $sCount = db()->cache(600)->count($sql . dbWhere($where)); | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + if(in_array('send',$show_count_filed)) { | ||
| 226 | + $where['folder_id'] = $this->getFolderId('发件箱'); | ||
| 227 | + $where['is_hots'] = 0; | ||
| 228 | + $faCount = db()->cache(600)->count($sql . dbWhere($where)); | ||
| 229 | + } | ||
| 230 | +// 垃圾箱 | ||
| 231 | + if(in_array('junk',$show_count_filed)) { | ||
| 232 | + $where['folder_id'] = $this->getFolderId('垃圾箱'); | ||
| 233 | + $where['is_hots'] = 0; | ||
| 234 | + $lajiCount = db()->cache(600)->count($sql . dbWhere($where)); | ||
| 235 | + } | ||
| 236 | +// 收件箱 | ||
| 237 | + if(in_array('inbox',$show_count_filed)) { | ||
| 238 | + $where['folder_id'] = $this->getFolderId('收件箱'); | ||
| 239 | + $where['is_hots'] = 0; | ||
| 240 | + $shouCount = db()->cache(600)->count($sql . dbWhere($where)); | ||
| 241 | + } | ||
| 242 | + // 未读 | ||
| 243 | + if(in_array('unseen',$show_count_filed)) { | ||
| 244 | + $where['seen'] = 0; | ||
| 245 | + $where['is_hots'] = 0; | ||
| 246 | + $seenCount = db()->cache(600)->count($sql . dbWhere($where)); | ||
| 247 | + unset($where['seen']); | ||
| 248 | + } | ||
| 249 | + // 星标 | ||
| 250 | + if(in_array('flagged',$show_count_filed)) { | ||
| 251 | + $where['flagged'] = 1; | ||
| 252 | + $flaggedCount = db()->cache(600)->count($sql . dbWhere($where)); | ||
| 253 | + } | ||
| 254 | + $data = []; | ||
| 255 | + if(isset($shouCount)) $data['inbox'] = $shouCount; | ||
| 256 | + if(isset($faCount)) $data['send'] = $faCount; | ||
| 257 | + if(isset($seenCount)) $data['unseen'] = $seenCount; | ||
| 258 | + if(isset($flaggedCount)) $data['flagged'] = $flaggedCount; | ||
| 259 | + if(isset($lajiCount)) $data['junk'] = $lajiCount; | ||
| 260 | + if(isset($sCount)) $data['hot_inbox'] = $sCount; | ||
| 261 | + if(isset($fCount)) $data['hot_send'] = $fCount; | ||
| 262 | + | ||
| 263 | + app()->_json($data); | ||
| 264 | + | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + | ||
| 268 | + | ||
| 269 | +} | ||
| 270 | + | ||
| 271 | + | ||
| 272 | + | ||
| 273 | + | ||
| 274 | + | ||
| 275 | + | ||
| 276 | + | ||
| 277 | + | ||
| 278 | + | ||
| 279 | + | ||
| 280 | + | ||
| 281 | + | ||
| 282 | + | ||
| 283 | + |
-
请 注册 或 登录 后发表评论