<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

$apiRoute = [
    /*
     * 画册路由
     */
    'api/album/get-banner' => ['real' => 'Api/V1/Album/albumGetBanner','method'=>'get','auth'=>false],
    'api/album/xyx_login' => ['real' => 'Api/V1/Album/albumXyxLogin','method'=>'post','auth'=>false],
    'api/album/cat' => ['real' => 'Api/V1/Album/albumCat','method'=>'get','auth'=>false],
    'api/album/setting' => ['real' => 'Api/V1/Album/albumSetting','method'=>'get','auth'=>false],

    'api/album/customer-goods' => ['real' => 'Api/V1/Album/albumCustomerGoods','method'=>'post','auth'=>true],
    'api/album/customer-goods-detail' => ['real' => 'Api/V1/Album/albumCustomerGoodsDetail','method'=>'post','auth'=>true],
    'api/album/get-count-favorite' => ['real' => 'Api/V1/Album/albumGetCountOfFavorite','method'=>'post','auth'=>true],
    'api/album_boss/get_top' => ['real' => 'Api/V1/AlbumBoss/getTop','method'=>'get','auth'=>true],
    'api/album_boss/agent_customer' => ['real' => 'Api/V1/AlbumBoss/agentCustomer','method'=>'post','auth'=>true],
    'api/album_boss/agent_statistical' => ['real' => 'Api/V1/AlbumBoss/agentStatistical','method'=>'post','auth'=>true],
    'api/album_boss/agent_overview_active' => ['real' => 'Api/V1/AlbumBoss/albumOverviewActive','method'=>'post','auth'=>true],
    'api/album_boss/agent_overview_left' => ['real' => 'Api/V1/AlbumBoss/albumOverviewLeft','method'=>'post','auth'=>true],
    'api/album_boss/agent_overview_favorite' => ['real' => 'Api/V1/AlbumBoss/albumOverviewFavorite','method'=>'post','auth'=>true],
    'api/album_boss/agent_overview_new' => ['real' => 'Api/V1/AlbumBoss/albumOverviewNew','method'=>'post','auth'=>true],
    'api/album_boss/agent_analysis' => ['real' => 'Api/V1/AlbumBoss/agentAnalysis','method'=>'post','auth'=>true],
    'api/album_boss/agent_overview_call' => ['real' => 'Api/V1/AlbumBoss/albumOverviewCall','method'=>'post','auth'=>true],
    'api/album_boss/agent_overview_funnel' => ['real' => 'Api/V1/AlbumBoss/albumOverviewFunnel','method'=>'post','auth'=>true],
    'api/album_boss/boss_interactive' => ['real' => 'Api/V1/AlbumBoss/BossInteractive','method'=>'get','auth'=>true],
    'api/album/get_data_goods' => ['real' => 'Api/V1/Album/albumGetDataGoods','method'=>'post','auth'=>true],
    'api/album_post/info' => ['real' => 'Api/V1/AlbumPoster/posterInfo','method'=>'post','auth'=>true],
    'api/album_post/download' => ['real' => 'Api/V1/AlbumPoster/posterDownload','method'=>'post','auth'=>true],
    'api/album/get-customer' => ['real' => 'Api/V1/Album/albumGetCustomer','method'=>'get','auth'=>true],
    'api/album/set-customer' => ['real' => 'Api/V1/Album/albumSetCustomer','method'=>'post','auth'=>true],
    'api/album/statistical' => ['real' => 'Api/V1/Album/albumStatistical','method'=>'post','auth'=>true],
    'api/album/get_statistical' => ['real' => 'Api/V1/Album/albumGetStatistical','method'=>'post','auth'=>true],
    'api/album/get_data_cat' => ['real' => 'Api/V1/Album/albumGetDataCat','method'=>'post','auth'=>true],
    'api/album/get_data_cat_single' => ['real' => 'Api/V1/Album/albumGetDataCatSingle','method'=>'post','auth'=>true],
    'api/album/favorite_list' => ['real' => 'Api/V1/Album/albumFavoriteList','method'=>'get','auth'=>true],
    'api/album/favorite_del' => ['real' => 'Api/V1/Album/albumFavoriteDel','method'=>'get','auth'=>true],
    'api/album/get_user_info' => ['real' => 'Api/V1/Album/albumGetUserInfo','method'=>'get','auth'=>true],
    'api/album/goods' => ['real' => 'Api/V1/Album/albumGoods','method'=>'get','auth'=>true],
    'api/album/goods-detail' => ['real' => 'Api/V1/Album/albumGoodsDetail','method'=>'get','auth'=>true],
    'api/album/set-price' => ['real' => 'Api/V1/Album/albumSetPrice','method'=>'get','auth'=>true],
    'api/album/agent_price_set' => ['real' => 'Api/V1/Album/albumAgentPriceSet','method'=>'post','auth'=>true],
    'api/album/content_list' => ['real' => 'Api/V1/Album/albumContentList','method'=>'get','auth'=>true],
    'api/album/content_detail' => ['real' => 'Api/V1/Album/albumContentDetail','method'=>'get','auth'=>true],
    'api/album/set-phone' => ['real' => 'Api/V1/Album/albumSavePhone','method'=>'post','auth'=>true],
    'api/album/add_agent' => ['real' => 'Api/V1/Album/albumAddAgent','method'=>'post','auth'=>true],
    'api/album/get-cart-of-watch' => ['real' => 'Api/V1/Album/albumGetCartOfWatch','method'=>'post','auth'=>true],
    'api/album/get-watch-recored' => ['real' => 'Api/V1/Album/albumGetWatchRecord','method'=>'post','auth'=>true],
    'api/album/set-watch' => ['real' => 'Api/V1/Album/albumSetWatch','method'=>'post','auth'=>true],
    'api/album/save_form_id' => ['real' => 'Api/V1/Album/albumSaveFormId','method'=>'post','auth'=>true],
    'api/album/search_goods' => ['real' => 'Api/V1/Album/albumSearchGoods','method'=>'get','auth'=>true],
    'api/album/add_favorite' => ['real' => 'Api/V1/Album/albumAddFavorite','method'=>'get','auth'=>true],
    'api/album/get-agent-address' => ['real' => 'Api/V1/Album/albumGetAgentAdress','method'=>'get','auth'=>true],


    /*
     * 家具路由
     */

    'api/attachment/upload' => ['real' => 'Api/V1/Attachment/upload','method'=>'post','auth'=>false],
    'api/furniture/setting' => ['real' => 'Api/V1/Furniture/furnitureSetting','method'=>'get','auth'=>false],
    'api/furniture/news_detail' => ['real' => 'Api/V1/Furniture/furnitureNewsDetail','method'=>'get','auth'=>false],
    'api/furniture/news_list' => ['real' => 'Api/V1/Furniture/furnitureNewsList','method'=>'get','auth'=>false],
    'api/furniture/goods_list' => ['real' => 'Api/V1/Furniture/furnitureGoodsList','method'=>'get','auth'=>false],
    'api/furniture/service_login' => ['real' => 'Api/V1/Furniture/serviceLogin','method'=>'post','auth'=>false],
    'api/furniture/getfurnitureads' => ['real' => 'Api/V1/Furniture/getFurnitureAds','method'=>'get','auth'=>false],
    'api/furniture/newgoods_list' => ['real' => 'Api/V1/Furniture/newgoods_list','method'=>'get','auth'=>false],
    'api/furniture/newgoods_index' => ['real' => 'Api/V1/Furniture/newgoods_index','method'=>'get','auth'=>false],


    'api/furniture/getattr' => ['real' => 'Api/V1/Furniture/getAttr','method'=>'get','auth'=>true],
    'api/furniture/add_comments' => ['real' => 'Api/V1/Furniture/furnitureAddComments','method'=>'any','auth'=>true],
    'api/furniture/createorder' => ['real' => 'Api/V1/Furniture/createOrder','method'=>'post','auth'=>true],
    'api/furniture/getorder' => ['real' => 'Api/V1/Furniture/getOrder','method'=>'get','auth'=>true],
    'api/furniture/getorderdetail' => ['real' => 'Api/V1/Furniture/getOrderDetail','method'=>'get','auth'=>true],
    'api/furniture/getprogress' => ['real' => 'Api/V1/Furniture/getProgress','method'=>'get','auth'=>true],
    'api/furniture/getreviewcount' => ['real' => 'Api/V1/Furniture/getReviewCount','method'=>'get','auth'=>true],
    'api/furniture/addreview' => ['real' => 'Api/V1/Furniture/addReview','method'=>'post','auth'=>true],
    'api/furniture/updatestatus' => ['real' => 'Api/V1/Furniture/updateStatus','method'=>'post','auth'=>true],
    'api/furniture/getphonenumber' => ['real' => 'Api/V1/Furniture/getPhoneNumber','method'=>'post','auth'=>true],
    'api/furniture/getqrcode' => ['real' => 'Api/V1/Furniture/getQrcode','method'=>'get','auth'=>true],
    'api/furniture/ordercount' => ['real' => 'Api/V1/Furniture/orderCount','method'=>'get','auth'=>true],
    'api/furniture/searchlist' => ['real' => 'Api/V1/Furniture/searchList','method'=>'get','auth'=>true],
    'api/furniture/printorder' => ['real' => 'Api/V1/Furniture/printOrder','method'=>'any','auth'=>true],
    'api/furniture/saveformid' => ['real' => 'Api/V1/Furniture/saveFormId','method'=>'post','auth'=>true],
    'api/furniture/getmorecomments' => ['real' => 'Api/V1/Furniture/getMoreComments','method'=>'get','auth'=>true],
    'api/furniture/addtolike' => ['real' => 'Api/V1/Furniture/addToLike','method'=>'get','auth'=>true],
    'api/furniture/newgoods_addcomment' => ['real' => 'Api/V1/Furniture/newgoods_addcomment','method'=>'post','auth'=>true],
    'api/furniture/newgoods_addbooking' => ['real' => 'Api/V1/Furniture/newgoods_addbooking','method'=>'post','auth'=>true],
];
/*$auth = [
    'Api/V1/Album/albumGoods' => 'post',
    'Api/V1/Album/albumCustomerGoods' => 'post',
    'Api/V1/Album/albumCustomerGoodsDetail' => 'post',
    'Api/V1/Album/albumGetCountOfFavorite' => 'post',
    'Api/V1/AlbumBoss/getTop' => 'post',
    'Api/V1/AlbumBoss/agentCustomer' => 'post',
    'Api/V1/AlbumBoss/agentStatistical' => 'post',
    'Api/V1/AlbumBoss/albumOverviewActive' => 'post',
    'Api/V1/Album/albumGoods' => 'post',
    'Api/V1/Album/albumGoods' => 'post',
];*/
Route::get('/addons/online_album/public/', [
    'as' => 'attachment.download',
    'uses' => 'Web\AttachmentController@download',
]);
Route::get('image/{md5}', [
    'as' => 'attachment.image',
    'uses' => 'Web\AttachmentController@image',
]);


if (request()->input('route') == 'geetest') {
    Route::any('/', 'Germey\Geetest\GeetestController@getGeetest');
}

//后台
if (strpos(request()->getRequestUri(), '/addons/') !== false) {
    //如未设置当前公众号则加到选择公众号列表
    if (strpos(request()->getRequestUri(), 'Admin/Auth/Login/wxLogin') !== false) {
        session_start();
        if (empty($_SESSION['store_id']) || empty($_SESSION['wUser'])) {
            return redirect('../../../web/index.php?c=wxapp&a=display');
        }
        session()->forget('wUser');
        session()->forget('store_id');
        session()->put('store_id', $_SESSION['store_id']);
        session()->put('wUser', $_SESSION['wUser']);
        session()->put('groupid', $_SESSION['wUser']['groupid']);
    };

    if (strpos(request()->getRequestUri(), 'api') !== false) {
        //$api = app('Dingo\Api\Routing\Router');
     /*   $api->version('v1', ['namespace' => 'App\Http\Controllers'], function ($api) {
            $api->group(['middleware' => ['auth.api']], function ($api) {*/
// Furniture::parseRoute();
                //$route_url = $_SESSION['route'];
        $route_url = request()->input('route');
        if (isset($apiRoute[$route_url])) {
            $route_url_r = $apiRoute[$route_url]['real'];
            $route_url_r = ucfirst($route_url_r);
            $route = $baseRoute = explode('/',$route_url_r);
            if (count($route) > 1) {
                unset($route[count($route) - 1]);
                $file = app_path() . '/Http/Controllers/' . implode("/", $route) . "Controller.php";
                if (file_exists($file)) {
                    $controller = implode("\\", $route) . "Controller";
                    $action = $controller . "@" . $baseRoute[count($route)];
                    if ($apiRoute[$route_url]['auth'] == true) {
                        Route::middleware(['auth.api'])->group(function () use ($action, $route, $apiRoute, $route_url) {
                            switch ($apiRoute[$route_url]['method']) {
                                case 'get':
                                    Route::get('/', ['as' => $route[0],
                                        'uses' => $action]);
                                    break;
                                case 'post':
                                    Route::post('/', ['as' => $route[0],
                                        'uses' => $action]);
                                    break;
                                case 'any':
                                    Route::any('/', ['as' => $route[0],
                                        'uses' => $action]);
                                    break;
                            }
                        });
                    } else {
                        switch ($apiRoute[$route_url]['method']) {
                            case 'get':
                                Route::get('/', ['as' => $route[0],
                                    'uses' => $action]);
                                break;
                            case 'post':
                                Route::post('/', ['as' => $route[0],
                                    'uses' => $action]);
                                break;
                            case 'any':
                                Route::any('/', ['as' => $route[0],
                                    'uses' => $action]);
                                break;
                        }
                    }

                }
            }
        }

        /*    });
        });*/

    } else if (strpos(request()->getRequestUri(), 'Admin') !== false || strpos(request()->getRequestUri(), 'admin') !== false) {
        $route_url = request()->input('route');
        $route_url = ucfirst($route_url);
        $route = $baseRoute = explode('/',$route_url);
        if (count($route) > 1) {
            unset($route[count($route) - 1]);
            $file = app_path() . '/Http/Controllers/' . implode("/", $route) . "Controller.php";
            if (file_exists($file)) {
                $controller = implode("\\", $route) . "Controller";
                $action = $controller . "@" . $baseRoute[count($route)];
                Route::any('/', ['as' => $route[0],
                    'uses' => $action]);
            }
        }
    }


}
