zoukankan      html  css  js  c++  java
  • TP5.1 控制器(基类)

    直接上代码

    <?php
    /**
     * Created by PhpStorm.
     * User: Zhangyongfeng
     * Date: 2020/12/1
     * Time: 11:31
     *
     * ━━━━━━━━━神兽出没━━━━━━━━━
     *
     *        ┏┓   ┏┓+ +
     *       ┏┛┻━━━┛┻┓ + +
     *       ┃       ┃  
     *       ┃   ━   ┃ ++ + + +
     *       ████━████ ┃+
     *       ┃       ┃ +
     *       ┃   ┻   ┃
     *       ┃       ┃ + +
     *       ┗━┓   ┏━┛
     *         ┃   ┃           
     *         ┃   ┃ + + + +
     *         ┃   ┃    Code is far away from bug with the animal protecting       
     *         ┃   ┃ +     神兽保佑,代码无bug  
     *         ┃   ┃
     *         ┃   ┃  +         
     *         ┃    ┗━━━┓ + +
     *         ┃        ┣┓
     *         ┃        ┏┛
     *         ┗┓┓┏━┳┓┏┛ + + + +
     *          ┃┫┫ ┃┫┫
     *          ┗┻┛ ┗┻┛+ + + +
     *
     * ━━━━━━━━━感觉萌萌哒━━━━━━━━━
     */
    
    namespace appasecontroller;
    
    use thinkApp;
    use thinkController;
    
    use appasemodelLog;
    use appasemodelUrole;
    use appasemodelAdmin;
    use appasemodelMember;
    use appasemodelSystem;
    use appasemodelBanner;
    use appasemodelContent;
    use appasemodelUaction;
    use appasemodelClassify;
    
    abstract class Base extends Controller
    {
        protected $file = [];             // 操作文件
        protected $param = [];            // 所有参数
        protected $config = [];           // 系统配置
        protected $u_admin = [];          // 后台用户
        protected $u_index = [];          // 前台用户
        protected $diyConfig = [];        // 用户配置
    
        // 模型
        protected $log;
        protected $urole;
        protected $admin;
        protected $member;
        protected $system;
        protected $banner;
        protected $content;
        protected $uaction;
        protected $classify;
    
        public function __construct(App $app = null)
        {
            parent::__construct($app);
            $this->initialize();
        }
    
        protected function initialize()
        {
            parent::initialize(); // TODO: Change the autogenerated stub
    
            $this->log = new Log();
            $this->urole = new Urole();
            $this->admin = new Admin();
            $this->member = new Member();
            $this->system = new System();
            $this->banner = new Banner();
            $this->content = new Content();
            $this->uaction = new Uaction();
            $this->classify = new Classify();
    
            $this->file = new File();
            $this->param = request()->param();
            $this->config = $this->system->getAllList();
            $this->diyConfig = config('diy.diy');
            $this->u_admin = session('u_admin', '', 'admin');
            $this->u_index = session('u_index', '', 'index');
            $this->assign([
                'config' => $this->config,
                'diyConfig' => $this->diyConfig,
            ]);
        }
    
        /**
         * 返回请求码
         * Power: ZYF
         * Email:1322816443@qq.com
         * @param string $code
         * @param array $data
         * @param string $msg
         * @return array
         */
        static public function showReturnCode($code = '', $data = [], $msg = '')
        {
            $return_data = [
                'code' => '500',
                'msg' => '未定义消息',
                'data' => $code == 1001 ? $data : [],
            ];
            if (empty($code)) return $return_data;
            $return_data['code'] = $code;
            if(!empty($msg)){
                $return_data['msg'] = $msg;
            }else if (isset(ReturnCode::$return_code[$code]) ) {
                $return_data['msg'] = ReturnCode::$return_code[$code];
            }
            return $return_data;
        }
    
        /**
         * 获取返回码数组别名函数 以json格式返回
         * Power: ZYF
         * Email:1322816443@qq.com
         * @param string $code
         * @param string $msg
         * @return array
         */
        static public function showJsonReturnCode($code = '', $data = [], $msg = ''){
            config('default_return_type', 'json');
            return self::showReturnCode($code, $data, $msg);
        }
    
        /**
         * 获取返回码数组别名函数 以json格式返回 无返回值
         * Power: ZYF
         * Email:1322816443@qq.com
         * @param string $code
         * @param string $msg
         * @return array
         */
        static public function showJsonReturnCodeWithOutData($code = '', $msg = ''){
            config('default_return_type', 'json');
            return self::showReturnCode($code, [], $msg);
        }
    
        /**
         * 获取返回码数组别名函数 无返回值
         * Power: ZYF
         * Email:1322816443@qq.com
         * @param string $code
         * @param string $msg
         * @return array
         */
        static public function showReturnCodeWithOutData($code = '', $msg = '')
        {
            return self::showReturnCode($code,[],$msg);
        }
    
        /**
         * 获取当前类名称
         * Power: ZYF
         * Email:1322816443@qq.com
         * @param bool|false $all
         * @return string
         */
        public function getClassName($all = false){
            return $all
                ? get_called_class()
                : basename(str_replace('\', '/', get_called_class()),'.php');
        }
    
        /**
         * 数据库字段 网页字段转换
         * Power: ZYF
         * Email:1322816443@qq.com
         * @param array $array   标识为数据库字段 值为浏览器提交字段
         * @param bool|false $uuid  是否追加UUID信息
         * @return array
         */
        protected function buildParam($array, $uuid = false)
        {
            $data = [];
            foreach( $array as $item => $value ){
                $data[$item] = $this->request->param($value);
            }
            if ($uuid && isset($this->uuid)){
                $data['uuid'] = $this->uuid;
            }
            return $data;
        }
    
        /**
         * 获取上传文件的 文件名 和 存储路径
         * @param object file 文件
         * @return array|object
         */
        public function upfile(){
            $path = [];
            // 获取表单上传文件 例如上传了001.jpg
            $file = request()->file('file');
            // 移动到框架应用根目录/uploads/ 目录下
            $names = explode('.',$_FILES['file']['name']);
            $name = $names[0].'.'.$names[count($names)-1];
            $info = $file->move( './upload');
            if($info){
                $getSaveName = str_replace("\","/",$info->getSaveName());
                $path[] = [
                    'name' => $name,
                    'path' => '/upload/'.$getSaveName,
                ];
            }
            return json($path);
        }
    
    
    
    }
  • 相关阅读:
    使用Lua编写Wireshark插件解析KCP UDP包,解析视频RTP包
    开源自己用python封装的一个Windows GUI(UI Automation)自动化工具,支持MFC,Windows Forms,WPF,Metro,Qt
    2019 WebRtc AudioMixer混音流程
    记录一次定位视频通话 音视频卡顿的原因分析过程。
    C++标准库里自带的数值类型和字符串互相转换函数
    C++ raw string literal
    使用multiprocessing解决PyMuPDF不支持多线程加载导致的界面卡死无响应问题,及一个PyQt5实现的简易PDF阅读器例子
    使用ctypes调用系统C API函数需要注意的问题,函数参数中有指针或结构体的情况下最好不要修改argtypes
    使用python uiautomation从钉钉网页版提取公司所有联系人信息
    使用python UIAutomation从QQ2017(v8.9)群界面获取所有群成员详细资料,
  • 原文地址:https://www.cnblogs.com/zyfeng/p/14086807.html
Copyright © 2011-2022 走看看