作者 邓超

x

@@ -131,6 +131,7 @@ class Login { @@ -131,6 +131,7 @@ class Login {
131 'smtp' => $formData['smtp'], 131 'smtp' => $formData['smtp'],
132 'status' => 1, 132 'status' => 1,
133 'pwd_error' => 0, 133 'pwd_error' => 0,
  134 + 'group_table' => get_request_origin(),
134 ]; 135 ];
135 136
136 if($id){ 137 if($id){
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 MailList 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 - $extSql = ''; // 扩展sql  
125 -// $origin_folder = $folder;  
126 - if($folder=='星标邮件'||$folder=='Starred'){  
127 - $folder = '收件箱';  
128 - $where['flagged'] = 1; // 星标  
129 - }elseif ($folder=='预热收件箱'){  
130 - $folder = '收件箱';  
131 - $extSql = "s";  
132 - }elseif ($folder=='预热发件箱'){  
133 - $folder = '发件箱';  
134 - $extSql = "f";  
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 - if($extSql){  
158 - $sql = "select %s from `lists` left join `fob_hot_mail` on `lists`.`id` = `fob_hot_mail`.`lists_id` where `fob_hot_mail`.`folder` = '{$extSql}' and ".dbWhere($where);  
159 - }else{  
160 - if(in_array($folder,['收件箱','发件箱','垃圾箱'])){  
161 - $sql = "select %s from `lists` left join `fob_hot_mail` on `lists`.`id` = `fob_hot_mail`.`lists_id` where ISNULL(`lists_id`) and ".dbWhere($where);  
162 - }else{  
163 - $sql = "select %s from `lists` where ".dbWhere($where);  
164 - }  
165 -  
166 - }  
167 -  
168 - // 查询列表数据  
169 - $lists = db()->all(sprintf($sql,$filed)." order by `udate` desc limit {$limit} offset ".(($page-1)*$limit));  
170 -  
171 - // map  
172 - $lists = array_map(function ($v){  
173 - $v['uuid'] = md5($v['email_id'].'-'.$v['folder_id'].'-'.$v['uid']);  
174 - if(!empty($v['description'])){  
175 - $v['description'] = @html_entity_decode($v['description'], ENT_COMPAT, 'UTF-8');  
176 - }  
177 - $v['to_name'] = @json_decode($v['to_name'],true);  
178 - $v['to_name'] = $v['to_name']?:[];  
179 - if($v['to_name']){  
180 - if(!empty($v['to_name'][0]['email'])){  
181 - $v['to'] = $v['to_name'][0]['email'];  
182 - }  
183 - $v['to_name'] = $v['to_name'][0]['name']??'';  
184 - }  
185 - if(is_array($v['to_name'])){  
186 - $v['to_name'] = '';  
187 - }  
188 - return $v;  
189 - },$lists?:[]);  
190 -  
191 - // 总数  
192 - $total = db()->cache(600)->count(sprintf($sql,"count(*)"));  
193 -  
194 - app()->_json(listsPage($lists,$total,$page,$limit));  
195 -  
196 - }  
197 -  
198 -  
199 - /**  
200 - * 统计收件箱的数量  
201 - * @author:dc  
202 - * @time 2024/7/19 10:15  
203 - */  
204 - public function count(){  
205 - $emails = $this->getEmails('id');  
206 -  
207 - // show_count_filed  
208 - $show_count_filed = app()->requestArr('show_count_filed',['inbox', 'send', 'unseen', 'flagged', 'junk', 'hot_inbox', 'hot_send']);  
209 -  
210 - $sql = "select count(*) from `lists` left join `fob_hot_mail` on `lists`.`id` = `fob_hot_mail`.`lists_id` where ";  
211 -  
212 - $where = ['lists|email_id'=>$emails];  
213 - $where['lists|deleted'] = 0; //未删状态  
214 - // 屏蔽哪些邮件  
215 - $where['from.notin'] = $this->from_not_in();  
216 - $where['_'] = "`from` not like 'postmaster@%'";  
217 - if(!$where['from.notin']) unset($where['from.notin']);  
218 -  
219 - // 发件箱  
220 - if(in_array('hot_send',$show_count_filed)){  
221 - $where['lists|folder_id'] = $this->getFolderId('发件箱');  
222 - // 预热发件箱  
223 - $where['fob_hot_mail|folder'] = 'f';  
224 - $fCount = db()->cache(600)->count($sql.dbWhere($where));  
225 - }  
226 -  
227 - // 预热收件箱  
228 - if(in_array('hot_inbox',$show_count_filed)) {  
229 - $where['lists|folder_id'] = $this->getFolderId('收件箱');  
230 - $where['fob_hot_mail|folder'] = 's';  
231 - $sCount = db()->cache(600)->count($sql . dbWhere($where));  
232 - }  
233 - unset($where['fob_hot_mail|folder']);  
234 -  
235 - $sql = $sql." ISNULL(`lists_id`) and ";  
236 - if(in_array('send',$show_count_filed)) {  
237 - $where['lists|folder_id'] = $this->getFolderId('发件箱');  
238 - $faCount = db()->cache(600)->count($sql . dbWhere($where));  
239 - }  
240 -// 垃圾箱  
241 - if(in_array('junk',$show_count_filed)) {  
242 - $where['lists|folder_id'] = $this->getFolderId('垃圾箱');  
243 - $lajiCount = db()->cache(600)->count($sql . dbWhere($where));  
244 - }  
245 -// 收件箱  
246 - if(in_array('inbox',$show_count_filed)) {  
247 - $where['lists|folder_id'] = $this->getFolderId('收件箱');  
248 - $shouCount = db()->cache(600)->count($sql . dbWhere($where));  
249 - }  
250 - // 未读  
251 - if(in_array('unseen',$show_count_filed)) {  
252 - $where['seen'] = 0;  
253 - $seenCount = db()->cache(600)->count($sql . dbWhere($where));  
254 - unset($where['seen']);  
255 - }  
256 - // 星标  
257 - if(in_array('flagged',$show_count_filed)) {  
258 - $where['flagged'] = 1;  
259 - $flaggedCount = db()->cache(600)->count($sql . dbWhere($where));  
260 - }  
261 - $data = [];  
262 - if(isset($shouCount)) $data['inbox'] = $shouCount;  
263 - if(isset($faCount)) $data['send'] = $faCount;  
264 - if(isset($seenCount)) $data['unseen'] = $seenCount;  
265 - if(isset($flaggedCount)) $data['flagged'] = $flaggedCount;  
266 - if(isset($lajiCount)) $data['junk'] = $lajiCount;  
267 - if(isset($sCount)) $data['hot_inbox'] = $sCount;  
268 - if(isset($fCount)) $data['hot_send'] = $fCount;  
269 -  
270 - app()->_json($data);  
271 -  
272 - }  
273 -  
274 -  
275 -  
276 -}  
277 -  
278 -  
279 -  
280 -  
281 -  
282 -  
283 -  
284 -  
285 -  
286 -  
287 -  
288 -  
289 -  
290 -  
@@ -510,3 +510,17 @@ function mb_iconv($str, $to, $from = null) { @@ -510,3 +510,17 @@ function mb_iconv($str, $to, $from = null) {
510 } 510 }
511 } 511 }
512 512
  513 +
  514 +/**
  515 + * 数据元,就是那个表 分表 list_xxxx body_xxx
  516 + * @return array|false|float|int|mixed|string|null
  517 + * @author:dc
  518 + * @time 2024/9/9 16:47
  519 + */
  520 +function get_request_origin(){
  521 + $request_origin = app()->request('request_origin');
  522 + if(preg_match("/^[a-z]{1,10}_\d{1,10}$/",$request_origin)){
  523 + return $request_origin;
  524 + }
  525 + return '';
  526 +}