作者 邓超

x

@@ -201,6 +201,9 @@ class MailList extends Base { @@ -201,6 +201,9 @@ class MailList extends Base {
201 public function count(){ 201 public function count(){
202 $emails = $this->getEmails('id'); 202 $emails = $this->getEmails('id');
203 203
  204 + // show_count_filed
  205 + $show_count_filed = app()->requestArr('show_count_filed',['inbox', 'send', 'unseen', 'flagged', 'junk', 'hot_inbox', 'hot_send']);
  206 +
204 $sql = "select count(*) from `lists` left join `fob_hot_mail` on `lists`.`id` = `fob_hot_mail`.`lists_id` where "; 207 $sql = "select count(*) from `lists` left join `fob_hot_mail` on `lists`.`id` = `fob_hot_mail`.`lists_id` where ";
205 208
206 $where = ['lists|email_id'=>$emails]; 209 $where = ['lists|email_id'=>$emails];
@@ -209,43 +212,58 @@ class MailList extends Base { @@ -209,43 +212,58 @@ class MailList extends Base {
209 $where['from.notin'] = $this->from_not_in(); 212 $where['from.notin'] = $this->from_not_in();
210 if(!$where['from.notin']) unset($where['from.notin']); 213 if(!$where['from.notin']) unset($where['from.notin']);
211 214
212 - $where['lists|folder_id'] = $this->getFolderId('发件箱');  
213 - // 预热发件箱  
214 - $where['fob_hot_mail|folder'] = 'f';  
215 - $fCount = db()->count($sql.dbWhere($where));  
216 - // 预热收件箱  
217 - $where['lists|folder_id'] = $this->getFolderId('收件箱');  
218 - $where['fob_hot_mail|folder'] = 's';  
219 - $sCount = db()->count($sql.dbWhere($where)); 215 + // 发件箱
  216 + if(in_array('hot_send',$show_count_filed)){
  217 + $where['lists|folder_id'] = $this->getFolderId('发件箱');
  218 + // 预热发件箱
  219 + $where['fob_hot_mail|folder'] = 'f';
  220 + $fCount = db()->count($sql.dbWhere($where));
  221 + }
220 222
  223 + // 预热收件箱
  224 + if(in_array('hot_inbox',$show_count_filed)) {
  225 + $where['lists|folder_id'] = $this->getFolderId('收件箱');
  226 + $where['fob_hot_mail|folder'] = 's';
  227 + $sCount = db()->count($sql . dbWhere($where));
  228 + }
221 unset($where['fob_hot_mail|folder']); 229 unset($where['fob_hot_mail|folder']);
222 230
223 $sql = $sql." ISNULL(`lists_id`) and "; 231 $sql = $sql." ISNULL(`lists_id`) and ";
224 - $where['lists|folder_id'] = $this->getFolderId('发件箱');  
225 - $faCount = db()->count($sql.dbWhere($where)); 232 + if(in_array('send',$show_count_filed)) {
  233 + $where['lists|folder_id'] = $this->getFolderId('发件箱');
  234 + $faCount = db()->count($sql . dbWhere($where));
  235 + }
226 // 垃圾箱 236 // 垃圾箱
227 - $where['lists|folder_id'] = $this->getFolderId('垃圾箱');  
228 - $lajiCount = db()->count($sql.dbWhere($where)); 237 + if(in_array('junk',$show_count_filed)) {
  238 + $where['lists|folder_id'] = $this->getFolderId('垃圾箱');
  239 + $lajiCount = db()->count($sql . dbWhere($where));
  240 + }
229 // 收件箱 241 // 收件箱
230 - $where['lists|folder_id'] = $this->getFolderId('收件箱');  
231 - $shouCount = db()->count($sql.dbWhere($where)); 242 + if(in_array('inbox',$show_count_filed)) {
  243 + $where['lists|folder_id'] = $this->getFolderId('收件箱');
  244 + $shouCount = db()->count($sql . dbWhere($where));
  245 + }
232 // 未读 246 // 未读
233 - $where['seen'] = 0;  
234 - $seenCount = db()->count($sql.dbWhere($where));  
235 - unset($where['seen']); 247 + if(in_array('unseen',$show_count_filed)) {
  248 + $where['seen'] = 0;
  249 + $seenCount = db()->count($sql . dbWhere($where));
  250 + unset($where['seen']);
  251 + }
236 // 星标 252 // 星标
237 - $where['flagged'] = 1;  
238 - $flaggedCount = db()->count($sql.dbWhere($where));  
239 -  
240 - app()->_json([  
241 - 'inbox'=> $shouCount,  
242 - 'send'=> $faCount,  
243 - 'unseen'=> $seenCount,  
244 - 'flagged' => $flaggedCount,  
245 - 'junk' => $lajiCount,  
246 - 'hot_inbox'=> $sCount,  
247 - 'hot_send'=> $fCount,  
248 - ]); 253 + if(in_array('flagged',$show_count_filed)) {
  254 + $where['flagged'] = 1;
  255 + $flaggedCount = db()->count($sql . dbWhere($where));
  256 + }
  257 + $data = [];
  258 + if(isset($shouCount)) $data['inbox'] = $shouCount;
  259 + if(isset($faCount)) $data['send'] = $faCount;
  260 + if(isset($seenCount)) $data['unseen'] = $seenCount;
  261 + if(isset($flaggedCount)) $data['flagged'] = $flaggedCount;
  262 + if(isset($lajiCount)) $data['junk'] = $lajiCount;
  263 + if(isset($sCount)) $data['hot_inbox'] = $sCount;
  264 + if(isset($fCount)) $data['hot_send'] = $fCount;
  265 +
  266 + app()->_json($data);
249 267
250 } 268 }
251 269
@@ -191,6 +191,31 @@ class App { @@ -191,6 +191,31 @@ class App {
191 } 191 }
192 192
193 /** 193 /**
  194 + * 读取数组
  195 + * @param string $name
  196 + * @param array $default
  197 + * @param null $filter
  198 + * @return array|float|int|mixed|string[]
  199 + * @author:dc
  200 + * @time 2024/8/6 9:36
  201 + */
  202 + public function requestArr($name='*',array $default = [], $filter = null){
  203 + $value = $this->request($name,$default, $filter);
  204 + if(!is_array($value)){
  205 + $value = explode(',',$value);
  206 + }
  207 + foreach ($value as $k=>$v){
  208 + if($v===''){
  209 + unset($value[$k]);
  210 + }
  211 + }
  212 + if(!$value){
  213 + return $default;
  214 + }
  215 + return $value;
  216 + }
  217 +
  218 + /**
194 * 是否存在 219 * 是否存在
195 * @param string $name 220 * @param string $name
196 * @return bool 221 * @return bool