<?php

namespace Controller;


use Model\emailSql;

/**
 * 基础控制器,根据需求 可以不继承此类
 * @author:dc
 * @time 2023/2/18 16:34
 * Class Base
 * @package Controller
 */
abstract class Base {


    /**
     * 多个邮箱前端提交
     * @param string $filed
     * @return mixed|null
     * @throws \Lib\Err
     * @author:dc
     * @time 2023/3/10 15:15
     */
    protected final function getEmails($filed='*'){
        static $data;
        if(empty($data)){
            $data = db()->all(emailSql::all(web_request_emails()));
            if(empty($data)){
                app()->e('email_request_required');
            }
        }

        if($filed == '*'){
            return $data;
        }

        return array_column($data,$filed);

    }

    /**
     * 一个邮箱前端提交
     * @param string $filed
     * @return mixed|string|null
     * @throws \Lib\Err
     * @author:dc
     * @time 2023/3/10 16:07
     */
    protected final function getEmail($filed='*'){
        static $data;
        if(empty($data)){
            $data = db()->first(emailSql::first(web_request_email()));
            if(empty($data)){
                app()->e('email_request_required');
            }
        }

        if($filed == '*'){
            return $data;
        }

        return $data[$filed]??'';
    }


}