正在显示
4 个修改的文件
包含
74 行增加
和
2 行删除
@@ -7,6 +7,7 @@ use Lib\Err; | @@ -7,6 +7,7 @@ use Lib\Err; | ||
7 | use Lib\Mail\Mail; | 7 | use Lib\Mail\Mail; |
8 | use Lib\Mail\MailFun; | 8 | use Lib\Mail\MailFun; |
9 | use Model\folderSql; | 9 | use Model\folderSql; |
10 | +use Model\listsSql; | ||
10 | 11 | ||
11 | /** | 12 | /** |
12 | * 文件夹管理 | 13 | * 文件夹管理 |
@@ -158,7 +159,54 @@ class Folder extends Base { | @@ -158,7 +159,54 @@ class Folder extends Base { | ||
158 | * @time 2023/3/3 17:38 | 159 | * @time 2023/3/3 17:38 |
159 | */ | 160 | */ |
160 | public function delete(){ | 161 | public function delete(){ |
162 | + $email = $this->getEmail(); | ||
163 | + | ||
164 | + $folder_id = app()->request('folder_id'); | ||
165 | + | ||
166 | + $folder = db()->first(folderSql::first(dbWhere(['id'=>$folder_id,'email_id'=>$email['id']]))); | ||
167 | + | ||
168 | + if(!$folder){ | ||
169 | + app()->e('folder_not_fount'); | ||
170 | + } | ||
171 | + // 是否存在下级 | ||
172 | + if(db()->count(folderSql::first(dbWhere(['pid'=>$folder['pid'],'email_id'=>$email['id']])))){ | ||
173 | + app()->e('folder_delete_exist_child'); | ||
174 | + } | ||
175 | + | ||
176 | + // 是否存在邮件 | ||
177 | + if(db()->count(listsSql::first(dbWhere(['folder_id'=>$folder['id'],'email_id'=>$email['id']])))){ | ||
178 | + app()->e('folder_delete_exist_mail'); | ||
179 | + } | ||
161 | 180 | ||
181 | + // 远程创建 | ||
182 | + $mail = new Mail( | ||
183 | + $email['email'], | ||
184 | + base64_decode($email['password']), | ||
185 | + $email['imap'] | ||
186 | + ); | ||
187 | + | ||
188 | + if(!$mail->login()){ | ||
189 | + app()->e('login_error_imap'); | ||
190 | + } | ||
191 | + | ||
192 | + // 远程创建 | ||
193 | + $ret = $mail->client->folderDelete($folder['origin_folder']); | ||
194 | + | ||
195 | + if($ret[0] === false){ | ||
196 | + app()->e($ret[1]); | ||
197 | + } | ||
198 | + | ||
199 | + // 插入数据 | ||
200 | + $row = db()->delete(folderSql::$table,[ | ||
201 | + 'id' => $folder['id'] | ||
202 | + ]); | ||
203 | + | ||
204 | + if(!$row){ | ||
205 | + app()->e('folder_delete_error'); | ||
206 | + } | ||
207 | + | ||
208 | + // 返回数据 | ||
209 | + app()->_json($folder); | ||
162 | } | 210 | } |
163 | 211 | ||
164 | 212 |
@@ -188,8 +188,7 @@ class Home extends Base { | @@ -188,8 +188,7 @@ class Home extends Base { | ||
188 | // 开始远程 | 188 | // 开始远程 |
189 | $mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']); | 189 | $mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']); |
190 | 190 | ||
191 | - $mailInstance->login(); | ||
192 | - | 191 | + if($mailInstance->login()){ |
193 | $mailInstance->seen(array_column($uid,'uid'),$folder['origin_folder'],$seen); | 192 | $mailInstance->seen(array_column($uid,'uid'),$folder['origin_folder'],$seen); |
194 | 193 | ||
195 | $mailInstance = null; | 194 | $mailInstance = null; |
@@ -199,6 +198,7 @@ class Home extends Base { | @@ -199,6 +198,7 @@ class Home extends Base { | ||
199 | ],dbWhere([ | 198 | ],dbWhere([ |
200 | 'id' => array_column($uid,'id') | 199 | 'id' => array_column($uid,'id') |
201 | ])); | 200 | ])); |
201 | + } | ||
202 | 202 | ||
203 | } | 203 | } |
204 | $folder = null; | 204 | $folder = null; |
@@ -28,6 +28,10 @@ return [ | @@ -28,6 +28,10 @@ return [ | ||
28 | 'folder_tree_max_two' => '文件夹最多2级', | 28 | 'folder_tree_max_two' => '文件夹最多2级', |
29 | 'folder_is_exist' => '文件夹已存在', | 29 | 'folder_is_exist' => '文件夹已存在', |
30 | 'folder_create_save_error' => '文件夹新增失败', | 30 | 'folder_create_save_error' => '文件夹新增失败', |
31 | + 'folder_not_fount' => '文件夹不存在', | ||
32 | + 'folder_delete_exist_child' => '无法删除带有子文件夹的目录', | ||
33 | + 'folder_delete_exist_mail' => '无法删除存在邮件的目录', | ||
34 | + 'folder_delete_error' => '文件夹删除失败', | ||
31 | 35 | ||
32 | 'sync_request_param_error' => '同步请求参数异常', | 36 | 'sync_request_param_error' => '同步请求参数异常', |
33 | 37 |
@@ -160,6 +160,26 @@ class DbPool { | @@ -160,6 +160,26 @@ class DbPool { | ||
160 | return 0; | 160 | return 0; |
161 | } | 161 | } |
162 | 162 | ||
163 | + /** | ||
164 | + * 删除语句 | ||
165 | + * @param string $table | ||
166 | + * @param array $where | ||
167 | + * @return int | ||
168 | + * @author:dc | ||
169 | + * @time 2023/3/17 18:04 | ||
170 | + */ | ||
171 | + public function delete(string $table, array $where){ | ||
172 | + $sql = "delete from `{$table}` where ".dbUpdate($where); | ||
173 | + | ||
174 | + $query = $this->query($sql); | ||
175 | + | ||
176 | + if($query){ | ||
177 | + return $query->rowCount(); | ||
178 | + } | ||
179 | + | ||
180 | + return 0; | ||
181 | + } | ||
182 | + | ||
163 | 183 | ||
164 | /** | 184 | /** |
165 | * 统计数量 | 185 | * 统计数量 |
-
请 注册 或 登录 后发表评论