作者 邓超

1

@@ -5,6 +5,7 @@ namespace Controller; @@ -5,6 +5,7 @@ namespace Controller;
5 use Lib\Mail\MailFun; 5 use Lib\Mail\MailFun;
6 use Model\emailSql; 6 use Model\emailSql;
7 use Model\listsSql; 7 use Model\listsSql;
  8 +use function Swoole\Coroutine\Http\request;
8 9
9 /** 10 /**
10 * @author:dc 11 * @author:dc
@@ -50,6 +51,50 @@ class Home extends Base { @@ -50,6 +51,50 @@ class Home extends Base {
50 } 51 }
51 52
52 53
  54 + /**
  55 + * 收到前端的同步请求操作
  56 + * @author:dc
  57 + * @time 2023/3/10 10:38
  58 + */
  59 + public function sync(){
  60 + $emails = app()->request('emails');
  61 + if (empty($emails)){
  62 + $tokens = app()->request('tokens');
  63 + $tokens = is_array($tokens) ? $tokens : [$tokens];
  64 + foreach ($tokens as $k=>$token){
  65 + if(!preg_match('/^[0-9a-zA-Z]{32}$/',$token)){
  66 + unset($tokens[$k]);
  67 + }
  68 + }
  69 + if(!empty($tokens)){
  70 + $where['token'] = array_values($tokens);
  71 + }
  72 + }else{
  73 + $emails = is_array($emails) ? $emails : [$emails];
  74 + foreach ($emails as $k=>$email){
  75 + if(!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email)){
  76 + unset($emails[$k]);
  77 + }
  78 + }
  79 + if(!empty($emails)){
  80 + $where['email'] = array_values($emails);
  81 + }
  82 + }
  83 +
  84 + if(empty($where)){
  85 + app()->e('sync_request_param_error');
  86 + }else{
  87 + // 查询id
  88 + $ids = db()->all(emailSql::getValues($where));
  89 + foreach ($ids as $v){
  90 + redis()->rPush('sync_email_lists', $v['id']);
  91 + }
  92 + // 返回成功的参数值
  93 + app()->_json(array_values($where));
  94 + }
  95 +
  96 + }
  97 +
53 98
54 99
55 100
@@ -258,7 +258,7 @@ function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$em @@ -258,7 +258,7 @@ function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0,$em
258 * @author:dc 258 * @author:dc
259 * @time 2023/2/18 11:04 259 * @time 2023/2/18 11:04
260 */ 260 */
261 -function start_now_mail($email=null){ 261 +function start_now_mail(){
262 $id = 0; 262 $id = 0;
263 263
264 while (true){ 264 while (true){
@@ -25,4 +25,6 @@ return [ @@ -25,4 +25,6 @@ return [
25 'folder_tree_max_two' => '文件夹最多2级', 25 'folder_tree_max_two' => '文件夹最多2级',
26 'folder_is_exist' => '文件夹已存在', 26 'folder_is_exist' => '文件夹已存在',
27 27
  28 + 'sync_request_param_error' => '同步请求参数异常',
  29 +
28 ]; 30 ];
@@ -66,6 +66,17 @@ class emailSql { @@ -66,6 +66,17 @@ class emailSql {
66 ]; 66 ];
67 } 67 }
68 68
  69 + /**
  70 + * 获取字段值
  71 + * @param $where
  72 + * @param string $field
  73 + * @return string
  74 + * @author:dc
  75 + * @time 2023/3/10 10:46
  76 + */
  77 + public static function getValues($where,$field='id'){
  78 + return "select `{$field}` from `".static::$table."` where ".dbWhere($where);
  79 + }
69 80
70 81
71 82
@@ -29,42 +29,53 @@ return [ @@ -29,42 +29,53 @@ return [
29 * @param string _token_ token登录凭证 29 * @param string _token_ token登录凭证
30 * @param int page 当前页数 30 * @param int page 当前页数
31 */ 31 */
32 - 'mail/list' => [\Controller\Home::class, 'lists'], 32 + 'list' => [\Controller\Home::class, 'lists'],
33 33
34 /** 34 /**
35 * 邮件文件夹 35 * 邮件文件夹
36 * @see \Controller\Folder::lists() 36 * @see \Controller\Folder::lists()
37 * @param string _token_ token登录凭证 37 * @param string _token_ token登录凭证
38 */ 38 */
39 - 'mail/folder' => [\Controller\Folder::class, 'lists'], 39 + 'folder' => [\Controller\Folder::class, 'lists'],
40 40
41 /** 41 /**
42 * 邮件/创建文件夹 42 * 邮件/创建文件夹
43 * @see \Controller\Folder::create() 43 * @see \Controller\Folder::create()
44 * @param string _token_ token登录凭证 44 * @param string _token_ token登录凭证
45 */ 45 */
46 - 'mail/folder/create' => [\Controller\Folder::class, 'create'], 46 + 'folder/create' => [\Controller\Folder::class, 'create'],
47 47
48 /** 48 /**
49 * 邮件/重命名文件夹 49 * 邮件/重命名文件夹
50 * @see \Controller\Folder::rename() 50 * @see \Controller\Folder::rename()
51 * @param string _token_ token登录凭证 51 * @param string _token_ token登录凭证
52 */ 52 */
53 - 'mail/folder/rename' => [\Controller\Folder::class, 'rename'], 53 + 'folder/rename' => [\Controller\Folder::class, 'rename'],
54 54
55 /** 55 /**
56 * 邮件/删除文件夹 56 * 邮件/删除文件夹
57 * @see \Controller\Folder::delete() 57 * @see \Controller\Folder::delete()
58 * @param string _token_ token登录凭证 58 * @param string _token_ token登录凭证
59 */ 59 */
60 - 'mail/folder/delete' => [\Controller\Folder::class, 'delete'], 60 + 'folder/delete' => [\Controller\Folder::class, 'delete'],
61 61
62 /** 62 /**
63 * 发送邮件 63 * 发送邮件
64 * @see \Controller\Home::send_mail() 64 * @see \Controller\Home::send_mail()
65 * @param string _token_ token登录凭证 65 * @param string _token_ token登录凭证
66 */ 66 */
67 - 'mail/send' => [\Controller\Home::class, 'send_mail'], 67 + 'send' => [\Controller\Home::class, 'send_mail'],
  68 +
  69 +
  70 + /**
  71 + * 同步请求
  72 + * @see \Controller\Home::sync()
  73 + * @param string _token_ token登录凭证
  74 + */
  75 + 'sync' => [\Controller\Home::class, 'sync'],
  76 +
  77 +
  78 +
68 79
69 ]; 80 ];
70 81