<?php

namespace Controller;

use Model\emailSql;
use Model\listsSql;

/**
 * @author:dc
 * @time 2023/2/13 11:28
 * Class Home
 * @package Controller
 */
class Home {

    /**
     * 当前登录的邮箱
     * @var array[]
     */
    private $login_email;

    /**
     * 构造
     * Home constructor.
     */
    public function __construct()
    {
        // 获取 当前请求的 邮箱
        $this->login_email   = db()->first(emailSql::firstByToken(token()));
        if(!$this->login_email){
            app()->e('token_verify_notfound');
        }

    }

    /**
     * 邮件列表
     * @author:dc
     * @time 2023/2/17 14:12
     */
    public function lists(){

        // 分页 页数
        $page   =   app()->request('page',1,'intval');
        $page   =   $page ? $page : 1;

        $lists = db()->all(listsSql::lists($this->login_email['id'],$page));

        app()->_json(listsPage($lists,100,1,30));

    }


    /**
     * 邮箱文件夹
     * @author:dc
     * @time 2023/2/18 10:58
     */
    public function folder(){
        // 查询
        $folders = db()->all(
            \Model\folderSql::all(
                $this->login_email['id'],
                '`id`,`folder`,`pid`'
            )
        );

        // 转tree
        $folders = list_to_tree($folders);

        app()->_json($folders);
    }










}