<?php
//新版代理分享链接路由控制 2018-12-08 anton liu
if (isset($_GET['invita']) && !empty($_GET['invita'])) {
    \Biz\Account\Invite::init()->setInvitaId($_GET['invita']);

    if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
        $uri = 'https://'.$_SERVER['HTTP_HOST'];
    } else {
        $uri = 'http://'.$_SERVER['HTTP_HOST'];
    }

    if(is_mobile()){ //手机
        $link = lm('setinfo', 'commons')->select('infocontent')->where('infotype', 2005)->first();
        if(strpos($link->infocontent,'http') !== false || strpos($link->infocontent,'https') !== false)
        {
            $uri = $link->infocontent;
            header("Location:".$uri."?invita=".$_GET['invita']);
            exit();
        }else{
            if($link->infocontent){
                header("Location:".$uri.$link->infocontent."?invita=".$_GET['invita']);
                exit();
            }else{
                header("Location:".$uri."/m/#/shareReg?invita=".$_GET['invita']);
                exit();
            }
        }
    }else{
        //pc版
        //获取是否开启分享推广页面
        $data = lm('setinfo', 'commons')->select('status')->where('infotype', 1024)->first();
        if($data->status == 1){
            header("Location:".$uri."/Home-Register/Share"); //分享
            exit();
        }elseif($data->status == 0){
            header("Location:".$uri."/Home-Register/Index"); //注册
            exit();
        }else{
            header("Location:".$uri."/Home-Index/Index"); // 首页
            exit();
        }
    }
}


if(isset($_GET['invite_id']) && intval($_GET['invite_id'])>0){
	\Biz\Account\Invite::init()->setInviteId(intval($_GET['invite_id']));
}
if (isset($_GET['invite']) && intval($_GET['invite']) > 0) {
	\Biz\Account\Invite::init()->setInviteId(intval($_GET['invite']));
}
// toDomain();
Route::any("/close", function () {
	return appExec("api", "close", "CloseWeb");
});

Route::any("/login", function () {
    return appExec("Sports","Login","login");
});

Route::any("/rollingball", function () {
    return appExec("Sports","RollingBall","getrollingball");
});

Route::any("/time", function () {
	return appExec("api", "common", "getTime");
});
Route::any("/", function () {
	checkClose();
	header('location:/home-index/index');
});
//Route::any("/", function () {
//    header("Location:/home-web/index"); // 首页
//});

Route::any("/pay", function () {
	return appExec("Payment", "Pay", "Index");
});
Route::any("/pay-(:any)", function ($method) {
	//toLog($_REQUEST);
	return appExec("Payment", "Pay", $method, 1);
});

Route::any("/prize", function () {
	return appExec("api", "prize", "prize");
});
//邀请路由
Route::any("/invite/(:any)", function ($id) {
    //toLog($_REQUEST);
	\Biz\Account\Invite::init()->setInviteId(intval($id));

	if(is_mobile()){
		return appExec("Mobile", "Recommend", 'Index');
	}
    return appExec("Home", "Recommend", 'Index');
});

Route::any("/recommend/(:any)", function ($id) {
    //toLog($_REQUEST);
	\Biz\Account\Invite::init()->setInviteId(intval($id));

	if(is_mobile()){
		return appExec("Mobile", "Register", 'Index');
	}
    return appExec("Home", "Register", 'Index');
});


Route::any("/inprize", function () {
	return appExec("api", "prize", "pull");
});
Route::any("/open", function () {
	return appExec("api", "prize", "open");
});
Route::any("/dataSeeds", "App\Home\Controller\DataSeeds@Index");

Route::any("/(:any)-(:any)/(:any)\.(:any)", function ($proj, $controller, $method, $format) {
	checkClose();
	S('CUR_RETURN_FORMAT', $format);
	return appExec($proj, $controller, $method);
});
Route::any("/(:any)-(:any)/(:any)", function ($proj, $controller, $method) {
	checkClose();
	return appExec($proj, $controller, $method);
});
Route::any("/(:any)/(:any)/(:any)\.(:any)", function ($proj, $controller, $method, $format) {
    checkClose();
    S('CUR_RETURN_FORMAT', $format);
	return appExec($proj, $controller, $method);
});
Route::any("/(:any)/(:any)/(:any)", function ($proj, $controller, $method) {
	checkClose();
	return appExec($proj, $controller, $method);
});

Route::any("/(:any)/(:any)/(:any)/", function ($proj, $controller, $method) {
	checkClose();
	return appExec($proj, $controller, $method);
});


//支付回调地址
// Route::any("/(:any)/notify\.php", function ($paymentName) {
//     S('CUR_PAYMENT_NAME', $paymentName);
//     return appExec("Payment", "Pay", 'Notify');
// });
// Route::any("/(:any)/redirect\.php", function ($paymentName) {
//     S('CUR_PAYMENT_NAME', $paymentName);
//     return appExec("Payment", "Pay", 'Redirect');
// });
// Route::dispatch();