<?php
/**
 * Notes:路由分发器
 * User: wsc
 * Time: 2020/4/30 12:03
 * Class router
 */

class router
{
    public function run() {
        $this->specialFeedBack();
        $pro = "services_2";
        $action = $_REQUEST['act'];
        $mod = $_REQUEST['mod'];
        $file = PATH_API."{$pro}/{$mod}.php";
        if (!file_exists($file)) {
            die('not find file');
        }
        require_once $file;
        $class = "{$mod}";
        $obj = new $class($_REQUEST);
        if (!method_exists($obj, $action)) {
            die();
        }
        //统一入口校验

        //调用具体的方法
        $res = $obj->$action();
        return $res;
    }

    /**
     * Notes:特殊接口处理-反馈(兼容老版本)
     * User: wsc
     * Time: 2020/4/30 12:35
     */
    public function specialFeedBack(){
        $arr = [
            '/v1_1/user/feedback/add'=>"Feedback.userAdd",//用户添加反馈
            '/v1_1/user/feedback/have_read'=>"Feedback.userRead",//用户设置反馈回复信息为已读状态
            '/v1_1/user/feedback/list'=>"Feedback.userGet",//获取反馈列表

            '/v1_1/sys/feedback/add'=>"Feedback.sysAdd",//系统回复反馈
            '/v1_1/sys/feedback/have_read'=>"Feedback.sysRead",//系统设置反馈信息为已读状态
            '/v1_1/sys/feedback/list'=>"Feedback.sysGet",//获取反馈列表
            '/v1_1/sys/feedback/detail/list'=>"controller/v1_1/Feedback@sys_detail_lll",//获取反馈列表
        ];
        if(!empty($arr[$_REQUEST['api']])){
            list($_REQUEST['mod'], $_REQUEST['act']) = explode('.', $arr[$_REQUEST['api']]);
        }
    }
}