正在显示
8 个修改的文件
包含
166 行增加
和
39 行删除
@@ -20,7 +20,7 @@ function start(){ | @@ -20,7 +20,7 @@ function start(){ | ||
20 | $table->create(); | 20 | $table->create(); |
21 | 21 | ||
22 | // 初始时,进行一次统计 | 22 | // 初始时,进行一次统计 |
23 | - $table->set('etotal',['val'=> db()->count(\Model\email::count())]); | 23 | + $table->set('etotal',['val'=> db()->count(\Model\emailSql::count())]); |
24 | 24 | ||
25 | // 进程管理器 | 25 | // 进程管理器 |
26 | $pm = new Process\Manager(); | 26 | $pm = new Process\Manager(); |
@@ -30,7 +30,7 @@ function start(){ | @@ -30,7 +30,7 @@ function start(){ | ||
30 | _echo("进程({$workerId})启动成功"); | 30 | _echo("进程({$workerId})启动成功"); |
31 | // 每10分钟统计一次邮箱数量 | 31 | // 每10分钟统计一次邮箱数量 |
32 | \Swoole\Timer::tick(600000,function () use (&$table){ | 32 | \Swoole\Timer::tick(600000,function () use (&$table){ |
33 | - $table->set('etotal',['val'=> db()->count(\Model\email::count())]); | 33 | + $table->set('etotal',['val'=> db()->count(\Model\emailSql::count())]); |
34 | }); | 34 | }); |
35 | 35 | ||
36 | // 每2秒执行一次 | 36 | // 每2秒执行一次 |
@@ -3,7 +3,8 @@ | @@ -3,7 +3,8 @@ | ||
3 | namespace Controller; | 3 | namespace Controller; |
4 | 4 | ||
5 | use Lib\Mail\Mail; | 5 | use Lib\Mail\Mail; |
6 | -use Model\email; | 6 | +use Model\emailSql; |
7 | +use Model\listsSql; | ||
7 | 8 | ||
8 | /** | 9 | /** |
9 | * @author:dc | 10 | * @author:dc |
@@ -44,7 +45,7 @@ class Home { | @@ -44,7 +45,7 @@ class Home { | ||
44 | Mail::login($formData['email'],$formData['password'],$formData['imap']); | 45 | Mail::login($formData['email'],$formData['password'],$formData['imap']); |
45 | 46 | ||
46 | // 是否存在 | 47 | // 是否存在 |
47 | - $id = db()->value(email::hasEmail($formData['email'])); | 48 | + $id = db()->value(emailSql::hasEmail($formData['email'])); |
48 | 49 | ||
49 | $data = [ | 50 | $data = [ |
50 | 'password' => base64_encode($formData['password']), | 51 | 'password' => base64_encode($formData['password']), |
@@ -58,10 +59,10 @@ class Home { | @@ -58,10 +59,10 @@ class Home { | ||
58 | 59 | ||
59 | if($id){ | 60 | if($id){ |
60 | // 修改 | 61 | // 修改 |
61 | - $ret = db()->update(email::$table,$data,dbWhere(['id'=>$id])); | 62 | + $ret = db()->update(emailSql::$table,$data,dbWhere(['id'=>$id])); |
62 | }else{ | 63 | }else{ |
63 | // 新增 | 64 | // 新增 |
64 | - $ret = db()->insert(email::$table,$data); | 65 | + $ret = db()->insert(emailSql::$table,$data); |
65 | } | 66 | } |
66 | 67 | ||
67 | 68 | ||
@@ -76,4 +77,50 @@ class Home { | @@ -76,4 +77,50 @@ class Home { | ||
76 | 77 | ||
77 | } | 78 | } |
78 | 79 | ||
80 | + | ||
81 | + /** | ||
82 | + * 邮件列表 | ||
83 | + * @author:dc | ||
84 | + * @time 2023/2/17 14:12 | ||
85 | + */ | ||
86 | + public function lists(){ | ||
87 | + $email = db()->first(emailSql::firstByToken(token())); | ||
88 | + if(!$email){ | ||
89 | + app()->e('token_verify_notfound'); | ||
90 | + } | ||
91 | + | ||
92 | + // 分页 页数 | ||
93 | + $page = app()->request('page',1,'intval'); | ||
94 | + $page = $page ? $page : 1; | ||
95 | + | ||
96 | + $lists = db()->all(listsSql::lists($email['id'],$page)); | ||
97 | + | ||
98 | + app()->_json(listsPage($lists,100,1,30)); | ||
99 | + | ||
100 | + } | ||
101 | + | ||
102 | + | ||
103 | + | ||
104 | + | ||
105 | + | ||
106 | + | ||
107 | + | ||
108 | + | ||
109 | + | ||
110 | + | ||
111 | + | ||
79 | } | 112 | } |
113 | + | ||
114 | + | ||
115 | + | ||
116 | + | ||
117 | + | ||
118 | + | ||
119 | + | ||
120 | + | ||
121 | + | ||
122 | + | ||
123 | + | ||
124 | + | ||
125 | + | ||
126 | + |
@@ -128,7 +128,15 @@ function my_filter($value,$filter=null){ | @@ -128,7 +128,15 @@ function my_filter($value,$filter=null){ | ||
128 | function dbWhere(array $where, string $ar = 'and'):string{ | 128 | function dbWhere(array $where, string $ar = 'and'):string{ |
129 | $sql = []; | 129 | $sql = []; |
130 | foreach ($where as $f=>$v){ | 130 | foreach ($where as $f=>$v){ |
131 | - $sql[] = "`{$f}` = '{$v}'"; | 131 | + if(is_array($v)){ |
132 | + $v = array_map(function ($n){ | ||
133 | + return "'".addslashes($n)."'"; | ||
134 | + },$v); | ||
135 | + $sql[] = "`{$f}` in (".implode(',',$v).")"; | ||
136 | + }else{ | ||
137 | + $sql[] = "`{$f}` = '".addslashes($v)."'"; | ||
138 | + } | ||
139 | + | ||
132 | } | 140 | } |
133 | return implode(' '.$ar.' ',$sql); | 141 | return implode(' '.$ar.' ',$sql); |
134 | } | 142 | } |
@@ -149,10 +157,40 @@ function dbUpdate(array $data):string { | @@ -149,10 +157,40 @@ function dbUpdate(array $data):string { | ||
149 | } | 157 | } |
150 | 158 | ||
151 | 159 | ||
160 | +/** | ||
161 | + * 获取token | ||
162 | + * @return string | ||
163 | + * @author:dc | ||
164 | + * @time 2023/2/17 14:24 | ||
165 | + */ | ||
166 | +function token():string { | ||
167 | + $toekn = app()->request('_token_'); | ||
152 | 168 | ||
169 | + if(!preg_match("/^[a-z0-9]{32}$/",$toekn)){ | ||
170 | + app()->e('token_verify_error'); | ||
171 | + } | ||
172 | + return $toekn; | ||
173 | +} | ||
153 | 174 | ||
154 | 175 | ||
155 | - | 176 | +/** |
177 | + * 分页数据 | ||
178 | + * @param $item | ||
179 | + * @param $total | ||
180 | + * @param $page | ||
181 | + * @param $limit | ||
182 | + * @return array | ||
183 | + * @author:dc | ||
184 | + * @time 2023/2/17 15:05 | ||
185 | + */ | ||
186 | +function listsPage($item,$total,$page,$limit){ | ||
187 | + return [ | ||
188 | + 'item' => $item, | ||
189 | + 'page' => $page, | ||
190 | + 'total' => $total, | ||
191 | + 'limit' => $limit, | ||
192 | + ]; | ||
193 | +} | ||
156 | 194 | ||
157 | 195 | ||
158 | 196 |
@@ -120,7 +120,7 @@ class App { | @@ -120,7 +120,7 @@ class App { | ||
120 | 120 | ||
121 | // 非 Err 错误类型 | 121 | // 非 Err 错误类型 |
122 | $app->data = [ | 122 | $app->data = [ |
123 | - 'message' => $app->debug ? $exception->getMessage().PHP_EOL.$exception->getTraceAsString() : __('server_error'), | 123 | + 'error_message' => $app->debug ? $exception->getMessage().PHP_EOL.$exception->getTraceAsString() : __('server_error'), |
124 | 'status' => $exception->getCode() ? $exception->getCode() : 500, | 124 | 'status' => $exception->getCode() ? $exception->getCode() : 500, |
125 | ]; | 125 | ]; |
126 | } | 126 | } |
@@ -188,7 +188,7 @@ class App { | @@ -188,7 +188,7 @@ class App { | ||
188 | * @time 2023/2/13 10:57 | 188 | * @time 2023/2/13 10:57 |
189 | */ | 189 | */ |
190 | public function e($message,$status=400){ | 190 | public function e($message,$status=400){ |
191 | - $this->data['message'] = __($message); | 191 | + $this->data['error_message'] = __($message); |
192 | $this->data['status'] = $status; | 192 | $this->data['status'] = $status; |
193 | throw new Err($message,500); | 193 | throw new Err($message,500); |
194 | } | 194 | } |
@@ -202,9 +202,8 @@ class App { | @@ -202,9 +202,8 @@ class App { | ||
202 | * @time 2023/2/13 11:03 | 202 | * @time 2023/2/13 11:03 |
203 | */ | 203 | */ |
204 | public function _json($data){ | 204 | public function _json($data){ |
205 | - $this->data['data'] = $data; | ||
206 | -// $this->data['message'] = __($message); | ||
207 | - throw new Err($message,200); | 205 | + $this->data = $data; |
206 | + throw new Err('',200); | ||
208 | } | 207 | } |
209 | 208 | ||
210 | 209 |
@@ -7,7 +7,7 @@ namespace Model; | @@ -7,7 +7,7 @@ namespace Model; | ||
7 | * @time 2023/2/13 14:11 | 7 | * @time 2023/2/13 14:11 |
8 | * Class email | 8 | * Class email |
9 | */ | 9 | */ |
10 | -class email { | 10 | +class emailSql { |
11 | 11 | ||
12 | public static $table = 'emails'; | 12 | public static $table = 'emails'; |
13 | 13 | ||
@@ -23,6 +23,22 @@ class email { | @@ -23,6 +23,22 @@ class email { | ||
23 | return "select {$filed} from `".static::$table."` where `".(is_numeric($email) ? 'id' : 'email')."` = '{$email}' limit 1"; | 23 | return "select {$filed} from `".static::$table."` where `".(is_numeric($email) ? 'id' : 'email')."` = '{$email}' limit 1"; |
24 | } | 24 | } |
25 | 25 | ||
26 | + | ||
27 | + /** | ||
28 | + * @param $token | ||
29 | + * @return array | ||
30 | + * @author:dc | ||
31 | + * @time 2023/2/17 14:21 | ||
32 | + */ | ||
33 | + public static function firstByToken($token):array { | ||
34 | + return [ | ||
35 | + "select * from `".static::$table."` where `token` = ? limit 1", | ||
36 | + [ | ||
37 | + $token | ||
38 | + ] | ||
39 | + ]; | ||
40 | + } | ||
41 | + | ||
26 | /** | 42 | /** |
27 | * 统计邮箱的数量 | 43 | * 统计邮箱的数量 |
28 | * @return string | 44 | * @return string |
@@ -50,30 +66,6 @@ class email { | @@ -50,30 +66,6 @@ class email { | ||
50 | ]; | 66 | ]; |
51 | } | 67 | } |
52 | 68 | ||
53 | - /** | ||
54 | - * 更新 | ||
55 | - * @param $data | ||
56 | - * @param $where | ||
57 | - * @return array | ||
58 | - * @author:dc | ||
59 | - * @time 2023/2/17 10:24 | ||
60 | - */ | ||
61 | - public static function update($data,$where){ | ||
62 | - | ||
63 | - return [ | ||
64 | - "update `".static::$table."` set ". dbUpdate($data) | ||
65 | - ." where ".(is_numeric($where) ? '`id` = '.$where : dbWhere($where)), | ||
66 | - $data | ||
67 | - ]; | ||
68 | - | ||
69 | - } | ||
70 | - | ||
71 | - | ||
72 | - public function insert(){ | ||
73 | - | ||
74 | - } | ||
75 | - | ||
76 | - | ||
77 | 69 | ||
78 | 70 | ||
79 | 71 |
model/listsSql.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace Model; | ||
4 | + | ||
5 | +/** | ||
6 | + * 邮件列表 | ||
7 | + * @author:dc | ||
8 | + * @time 2023/2/17 14:15 | ||
9 | + * Class lists | ||
10 | + * @package Model | ||
11 | + */ | ||
12 | +class listsSql { | ||
13 | + | ||
14 | + /** | ||
15 | + * 表 | ||
16 | + * @var string | ||
17 | + */ | ||
18 | + public static $table = 'lists'; | ||
19 | + | ||
20 | + | ||
21 | + /** | ||
22 | + * 查询列表 | ||
23 | + * @param $email_id | ||
24 | + * @param $p | ||
25 | + * @param int $folder_id | ||
26 | + * @return string | ||
27 | + * @author:dc | ||
28 | + * @time 2023/2/17 14:42 | ||
29 | + */ | ||
30 | + public static function lists($email_id, $p, $folder_id = null){ | ||
31 | + | ||
32 | + $where = ['email_id'=>$email_id]; | ||
33 | + if($folder_id) $where['folder_id'] = $folder_id; | ||
34 | + | ||
35 | + return "select * from `".static::$table."` where ".dbWhere($where)." order by `udate` desc limit 30 offset ".($p-1); | ||
36 | + | ||
37 | + } | ||
38 | + | ||
39 | + | ||
40 | + | ||
41 | + | ||
42 | + | ||
43 | +} |
@@ -4,5 +4,11 @@ use Controller\Home; | @@ -4,5 +4,11 @@ use Controller\Home; | ||
4 | 4 | ||
5 | 5 | ||
6 | return [ | 6 | return [ |
7 | - 'login' => [Home::class,'login'] | 7 | + |
8 | + /** 登录操作 @see Home::login() **/ | ||
9 | + 'login' => [Home::class,'login'], | ||
10 | + | ||
11 | + /** 邮件列表 @see Home::lists() **/ | ||
12 | + 'mail/list' => [Home::class,'lists'], | ||
13 | + | ||
8 | ]; | 14 | ]; |
-
请 注册 或 登录 后发表评论