<?php

use Illuminate\Support\Facades\Route;


App::setLocale(env('DEFAULT_LOCALE','en'));

Route::any('/apk/ios', 'Api\AutoApkController@iosJump');
Route::any('/h5', 'Api\AutoApkController@h5jump');
Route::any('/apk/health', 'Api\AutoApkController@health');
Route::any('/apk/inside', 'Api\AutoApkController@inside');
Route::any('/apk/make', 'Api\AutoApkController@createApk');
Route::any('/apk/getsign', 'Api\AutoApkController@findUrlSign');

Route::any('/app/{package}', 'Api\ApkController@download');
Route::any('/appconfig', 'Api\ApkController@appconfig');
Route::any('/apk/log', 'Api\ApkController@log');
Route::any('/apk/checkpay', 'Api\ApkController@check_user_pay');
Route::any('/apk/act', 'Api\ApkController@check_action');
Route::any('/apk/save', 'Api\ApkController@save_data');
Route::any('/apk/load', 'Api\ApkController@load_data');
Route::any('/apk/savenew', 'Api\ApkController@save_data_new');
Route::any('/apk/loadnew', 'Api\ApkController@load_data_new');
Route::any('/apk/test', 'Api\ApkController@test');
Route::any('/apk/checkpay2', 'Api\ApkController@check_user_pay2');
Route::post('/user/message', 'Api\ApiController@userMessageAdd');
Route::any('/log', 'Api\ApiController@log');
Route::any('/callback_start', 'Api\AccCallbackController@send');
Route::any('/error_report', 'Api\ApiController@errorReport');
Route::any('/adjust_test', 'Api\ApiController@adjust');
Route::any('/repay_orders', 'Api\ApiController@repayOrders');
Route::any('/telehook', 'Api\TelegramController@hook');
Route::any('/teletest', 'Api\TelegramController@test');
Route::any('/rate_us', 'Api\ApiController@rateUs');
Route::group([
    'middleware' => 'newApiSign'
], function ($route) {
    // 支付入口 -- 总入口
    $route->any('/payment_entry/pay', 'Api\PaymentEntryController@pay');
    $route->any('/payment_entry/iospay', 'Api\PaymentEntryController@iospay');
    $route->any('/payment_entry/googlepay', 'Api\PaymentEntryController@googlepay');

});

// 根据支付档位获取渠道
//Route::get('/test_tele', 'Api\TestController@tele');
//Route::get('/test', 'Api\TestController@index');
Route::any('/game_api/update_user_info', 'Api\GameApiController@updateUserInfo');
Route::any('/game_api/user_source', 'Api\GameApiController@UserSource');

//在线数据
Route::any('/game_api/billboard', 'Api\GameApiController@billBoard');
Route::any('/game_api/billboard2', 'Api\GameApiController@billBoard2');

//在线数据
Route::any('/game_api/online_list', 'Api\GameApiController@onlineList');

// 文件上传
Route::any('/upload/upload_file', 'Api\UploadController@uploadFile');

// AB面，单独开关
//Route::any('/other/switch', 'Api\OtherController@switch');

//Route::any('/appflyer/event', 'Api\AppflyerEventController@index');
//Route::any('/appflyer/test', 'Api\AppflyerEventController@test');
// 加载注册页面
//Route::get('/rev/register_view', 'Api\RegisterController@registerView');
// 下载页面
//Route::get('/rev/download', 'Api\RegisterController@download');
// 注册提交页面
//Route::any('/rev/index', 'Api\RegisterController@index');
//Route::any('/rev/customer_service', 'Api\RegisterController@customerService');
Route::any('/send_code/send_verify', 'Api\SendCodeController@send_verify');
//Route::any('/send_code/send', 'Api\SendCodeController@send');

Route::any('/send_code/get_code', 'Api\SendCodeController@getCode');

Route::any('/send_code/kmi_send', 'Api\SendCodeController@kmiSend');

// 渠道管理-- 根据包开放不同的游戏和充值
Route::any('/channel/channel_open_recharge', 'Api\ChannelController@ChannelOpenRecharge');
Route::any('/channel/channel_game_open', 'Api\ChannelController@ChannelGameOpen');
Route::any('/channel/channel_second_stage', 'Api\ChannelController@ChannelSecondStage');
Route::any('/channel/shareUrl', 'Api\ChannelController@shareUrl');  // 分渠道展示不同分享链接


// 大厅活动公告
Route::any('/notice/hall_announcement', 'Api\NoticeController@hallAnnouncement');
Route::any('/notice/hall_announcement_info/{id}', 'Api\NoticeController@hallAnnouncementInfo');
Route::any('/notice/remind', 'Api\NoticeController@remind');

// 谷歌支付
Route::any('/google_pay/confirm', 'Api\GooglePayController@confirm');


Route::any('/apple_store_pay/confirm', 'Api\AppleStorePayController@confirm');

// 裂变 -- 分享
//Route::any('/extension/getScore', 'Api\ExtensionsController@getScore');
//Route::any('/extension/receiveScore', 'Api\ExtensionsController@receiveScore');
//Route::any('/extension/list', 'Api\ExtensionsController@list');
//Route::any('/extension/recharge_rate', 'Api\ExtensionsController@rechargeRate');

// 裂变 -- 分享新接口
Route::any('/new_extension/getScore', 'Api\ExtensionsController@getScore');
Route::any('/new_extension/receiveScore', 'Api\ExtensionsController@receiveScore');
Route::any('/new_extension/list', 'Api\ExtensionsController@list');

// 获取版本信息
Route::get('/get_version/index', 'Api\GetVersionController@index');
Route::get('/game_version/ruby', 'Api\GetVersionController@indexRuby');
Route::get('/del_version', 'Api\GetVersionController@delVersion');

// 支付绑定信息修改
Route::any('/api/update_accounts_pay_info', 'Api\ApiController@updateAccountsPayInfo');
// 支付绑定信息获取
Route::any('/api/get_accounts_pay_info', 'Api\ApiController@getAccountsPayInfo');
//提现手续费返回
Route::any('/api/withDrawTax', 'Api\ApiController@withDrawTax');

//新手引导
//Route::any('/api/new_guide', 'Api\ApiController@newGuide');

// 版本
//Route::any('/query_version_new', 'Api\QueryVersionNewController@index');
Route::get('/gear/get_channels', 'Api\RechargeController@getPayChannel');
Route::any('/config/index', 'Api\ConfigController@index');

// 客服功能管理
Route::any('/api/customer_service', 'Api\ApiController@customer_service');
Route::any('/pgsoft/leave', 'Game\PgSimController@leaveOrg');
Route::any('/jiligames/leave', 'Game\JiliSimController@leaveOrg');

Route::any('/jiligames/lunchorg2', 'Game\JiliSimController@gameLunchOrg');
Route::group([

    'middleware' => 'apiSign'

], function (\Illuminate\Routing\Router $route) {
    $route->any('/web_login', 'Api\ApkController@WebLogin');
    $route->any('/launch9x', 'Game\JiliSimController@launch9x');

    Route::any('/jiligames/lunchorg', 'Game\JiliSimController@gameLunchOrg');

    $route->any('/bind_country', 'Api\ApiController@bindCountry'); // 返回首充金额
    $route->any('/check_country', 'Api\ApiController@checkCountry'); // 返回首充金额

    $route->any('/bind_locale', 'Api\ApiController@bindLocale'); // 返回首充金额
    $route->any('/check_locale', 'Api\ApiController@checkLocale'); // 返回首充金额

    $route->any('/pay/first_pay_multi', 'Api\PayRechargeController@firstPayMulti'); // 返回首充金额

    $route->any('/pay/get_second', 'Api\PayRechargeController@getSecondGive'); // 返回首充金额
    $route->any('/pay/time_bonus', 'Api\PayRechargeController@timeBonus'); // 返回首充金额

    $route->any('/pgsoft/lunchorg', 'Game\PgSimController@gameLunchOrg');


    $route->any('/jackpot', 'Api\ApiController@jackpot');
    $route->any('/changeapk/check', 'Api\ApkController@checkDownloadNotice');
    $route->any('/changeapk/click', 'Api\ApkController@clickDownloadNotice');
    $route->any('/send_code/send2', 'Api\SendCodeController@send2');

    $route->post('/commission', 'Api\ApiController@setCommission');//点位设置

    $route->get('/user/message', 'Api\ApiController@userMessageList');
    $route->get('/user/wait_read', 'Api\ApiController@wait_read');
    $route->get('/login_ip_map', 'Api\ApiController@LoginIPMap');
    $route->get('/login_ip', 'Api\ApiController@LoginIP');
    $route->get('/sign_in/{ip_check_key}', 'Api\ApiController@LoginIP_Hand');
    $route->get('/findready/{ip_check_key}', 'Api\ApiController@LoginIP_Mask');

    // ID白名单
    $route->any('/channel/channel_shield_id_white', 'Api\ApiController@channel_shield_id_white');

    // 公告
    $route->any('/notice/system_maintenance', 'Api\NoticeController@systemMaintenance');


    /*支付相关接口*/
    // 充值记录
    $route->get('/pay/orderList', 'Api\PayRechargeController@orderList');

    // 支付相关

    // 支付入口 -- 总入口
    $route->any('/payment/pay', 'Api\PaymentController@pay');

    /*返回所有可用支付渠道类型*/
    $route->get('/payapi/pay_type', 'Api\PayController@pay_type');
    /*返回充值档位*/
    // 返回充值金额
    $route->get('/recharge/gear', 'Api\RechargeController@gear');
    $route->get('/recharge/gearAct', 'Api\RechargeController@gearAct');
    $route->get('/recharge/pay_channel', 'Api\RechargeController@payChannel');
    $route->get('/recharge/firstPayConfig', 'Api\RechargeController@firstPayConfig');
    $route->get('/channel/list', 'Api\ChannelController@index');

});

Route::get('/gear/get_channel', 'Api\RechargeController@getPayChannel');
Route::get('/recharge/vipConfig', 'Api\RechargeController@vipConfig');//vip配置信息
Route::get('/recharge/userTotalRecharge', 'Api\RechargeController@userTotalRecharge');//用户总充值
Route::get('/recharge/guidePayment', 'Api\RechargeController@guidePayment');//引导付费
//Route::get('/pay/orderList', 'Api\PayRechargeController@orderList')->middleware('throttle:60,1'); // 充值记录
Route::get('/pay/first_pay', 'Api\PayRechargeController@firstPay'); // 返回首充金额
Route::post('/withDraw/withDrawInfo', 'Api\WithDrawInfoController@withDrawInfo');//提现信息完善
Route::post('/withDraw/withDrawInfoSA', 'Api\WithDrawInfoController@withDrawInfoSA');//提现信息完善
Route::get('/withDraw/getWithDrawInfo', 'Api\WithDrawInfoController@getWithDrawInfo');//获取提现信息
//
// 支付-提现 相关

//
//Route::any('/Pagsmilepay/notify', 'Api\PagsmilePayController@notify');
//Route::any('/Pagsmilepay/sync_notify', 'Api\PagsmilePayController@sync_notify');
//Route::any('/Pagsmilepay/cash_notify', 'Api\PagsmilePayController@cash_notify');
//
//Route::any('/Pagsmilepay/notify_new', 'Api\PagsmileNewPayController@notify');
//
//// YY Pay
//Route::any('/foxpay/notify', 'Api\FoxPayController@notify');
//Route::any('/foxpay/sync_notify', 'Api\FoxPayController@sync_notify');
//Route::any('/foxpay/cash_notify', 'Api\FoxPayController@cash_notify');
//
//
//Route::any('/uupay/notify', 'Api\UuPayController@notify');
//Route::any('/uupay/sync_notify', 'Api\UuPayController@sync_notify');
//Route::any('/uupay/cash_notify', 'Api\UuPayController@cash_notify');
//
//
Route::any('/goopago/notify', 'Api\GoopagoController@notify');
Route::any('/goopago/sync_notify', 'Api\GoopagoController@sync_notify');
Route::any('/goopago/cash_notify', 'Api\GoopagoController@cash_notify');
//
//
//Route::any('/oteapaynew/notify', 'Api\OTeaPayNewController@notify');
//Route::any('/oteapaynew/sync_notify', 'Api\OTeaPayNewController@sync_notify');
//Route::any('/oteapaynew/cash_notify', 'Api\OTeaPayNewController@cash_notify');
//
//Route::any('/bpay/notify', 'Api\OTeaPayController@notify');
//Route::any('/bpay/sync_notify', 'Api\OTeaPayController@sync_notify');
//Route::any('/bpay/cash_notify', 'Api\OTeaPayController@cash_notify');


Route::any('/lqpay/notify', 'Api\LQPayController@notify');
Route::any('/lqpay/cash_notify', 'Api\LQPayController@cash_notify');

Route::any('/ppay/notify', 'Api\PPayController@notify');
Route::any('/ppay/cash_notify', 'Api\PPayController@cash_notify');


Route::any('/cashpay/notify', 'Api\FastPayController@notify');
Route::any('/cashpay/sync_notify', 'Api\FastPayController@sync_notify');
Route::any('/cashpay/cash_notify', 'Api\FastPayController@cash_notify');
Route::any('/cashpay/agent_cash_notify', 'Api\FastPayController@cash_notify');

Route::any('/n_cashpay/notify', 'Api\CashPayController@notify');
Route::any('/n_cashpay/sync_notify', 'Api\CashPayController@sync_notify');
Route::any('/n_cashpay/cash_notify', 'Api\CashPayController@cash_notify');
Route::any('/n_cashpay/agent_cash_notify', 'Api\CashPayController@cash_notify');



Route::any('/fastpay/notify', 'Api\FastPayController@notify');
Route::any('/fastpay/sync_notify', 'Api\FastPayController@sync_notify');
Route::any('/fastpay/cash_notify', 'Api\FastPayController@cash_notify');
Route::any('/fastpay/agent_cash_notify', 'Api\FastPayController@cash_notify');


Route::any('/nicepay/notify', 'Api\NicePayController@notify');
Route::any('/nicepay/sync_notify', 'Api\NicePayController@sync_notify');
Route::any('/nicepay/cash_notify', 'Api\NicePayController@cash_notify');
Route::any('/nicepay/agent_cash_notify', 'Api\NicePayController@cash_notify');

Route::any('/aegpay/notify', 'Api\AegPayController@notify');
Route::any('/aegpay/payout_notify', 'Api\AegPayController@cash_notify');


Route::any('/toppay/notify', 'Api\TopPayController@notify');
Route::any('/toppay/payout_notify', 'Api\TopPayController@cash_notify');

Route::any('/clickpay/notify', 'Api\ClickPayController@notify');
Route::any('/clickpay/payout_notify', 'Api\ClickPayController@cash_notify');


Route::any('/sitobank/notify', 'Api\SitoBankController@notify');
Route::any('/sitobank/payout_notify', 'Api\SitoBankController@cash_notify');

// WiwiPay支付渠道
Route::any('/wiwipay/notify', 'Api\WiwiPayController@notify');
Route::any('/wiwipay/payout_notify', 'Api\WiwiPayController@cash_notify');
Route::any('/wiwipay/return', 'Api\WiwiPayController@sync_notify');


Route::any('/russia/notify', 'Api\RussiaPayController@notify');
Route::any('/russia/cash_notify', 'Api\RussiaPayController@cash_notify');

Route::any('/stanpay/notify', 'Api\StanPayController@notify');
Route::any('/stanpay/cash_notify', 'Api\StanPayController@cash_notify');

Route::any('/smartfast/notify', 'Api\SmartFastPayController@notify');
Route::any('/smartfast/payout_notify', 'Api\SmartFastPayController@cash_notify');

//Route::any('/smartfastperu/notify', 'Api\SmartFastPeruController@notify');
//Route::any('/smartfastperu/payout_notify', 'Api\SmartFastPeruController@cash_notify');


Route::any('/smartfast_uni/notify/{country}', 'Api\SmartFastPeruController@notify');
Route::any('/smartfast_uni/payout_notify/{country}', 'Api\SmartFastPeruController@cash_notify');


Route::any('/smart/notify', 'Api\SmartPayController@notify');
Route::any('/smart/payout_notify', 'Api\SmartPayController@cash_notify');

Route::any('/sfp/proxy', 'Api\SmartFastColController@proxy');
Route::any('/smartfastcol/notify', 'Api\SmartFastColController@notify');
Route::any('/smartfastcol/payout_notify', 'Api\SmartFastColController@cash_notify');

Route::any('/crypto/notify', 'Api\CryptoController@notify');
Route::any('/crypto/payout_notify', 'Api\CryptoController@cash_notify');

Route::any('/hhpay/notify', 'Api\HHPayColController@notify');
Route::any('/hhpay/payout_notify', 'Api\HHPayColController@cash_notify');

Route::any('/wwpay/notify', 'Api\WWPayColController@notify');
Route::any('/wwpay/payout_notify', 'Api\WWPayColController@cash_notify');

Route::any('/dopay/notify', 'Api\DoPayController@notify');
Route::any('/dopay/payout_notify', 'Api\DoPayController@cash_notify');

Route::any('/starpago/notify', 'Api\StarpagoController@notify');
Route::any('/starpago/payout_notify', 'Api\StarpagoController@cash_notify');

Route::any('/starpagobd/notify', 'Api\StarpagoBDController@notify');
Route::any('/starpagobd/payout_notify', 'Api\StarpagoBDController@cash_notify');

Route::any('/pkpay/notify', 'Api\PKpayController@notify');
Route::any('/pkpay/payout_notify', 'Api\PKpayController@cash_notify');

Route::any('/all2pay/notify', 'Api\ALL2payController@notify');
Route::any('/all2pay/sync_notify', 'Api\ALL2payController@sync_notify');
Route::any('/all2pay/cash_notify', 'Api\ALL2payController@cash_notify');

Route::any('/karopay/notify', 'Api\KaroPayController@notify');
Route::any('/karopay/sync_notify', 'Api\KaroPayController@sync_notify');
Route::any('/karopay/cash_notify', 'Api\KaroPayController@cash_notify');

//
//Route::any('/bet_cat_pay/notify', 'Api\BetCatPayController@notify');
//Route::any('/bet_cat_pay/sync_notify', 'Api\BetCatPayController@sync_notify');
//Route::any('/bet_cat_pay/cash_notify', 'Api\BetCatPayController@cash_notify');
//Route::any('/bet_cat_pay/agent_cash_notify', 'Api\BetCatPayController@agent_cash_notify');


Route::any('/clear_cache', function () {
    $path = app()->basePath('/public/cache/');
    $dir = opendir($path);
    if (!$dir) {
        return apiReturnFail('open dir failed');
    }
    do {
        $file = readdir($dir);
        if (!$file) {
            break;
        }
        if ($file == '.' || $file == '..') {
            continue;
        }
        unlink($path.$file);
    } while ($file);
    return apiReturnSuc();
});

Route::any('/opcache/clear', 'Api\OpcacheController@index');

Route::any('/adjust/report', 'Api\AdjustController@report');

// Apcopay支付路由
Route::prefix('apcopay')->group(function () {
    // 支付相关
    Route::post('pay_order', 'Api\ApcopayController@pay_order');

    // 支付回调
    Route::post('notify', 'Api\ApcopayController@notify');
    Route::post('callback', 'Api\ApcopayController@notify');

    // 同步通知
    Route::get('sync_notify', 'Api\ApcopayController@sync_notify');

    // 重定向路由 - 新增
    Route::get('redirect', 'Api\ApcopayController@sync_notify');

    // 提现回调
    Route::post('cash_notify', 'Api\ApcopayController@cash_notify');

    // 提现回调 - 新增
    Route::post('cash_callback', 'Api\ApcopayController@cash_callback');

    // 测试接口
    Route::get('test/payment', 'Api\ApcopayController@test_payment');
    Route::get('test/notify', 'Api\ApcopayController@test_notify');

    // 测试提现接口 - 新增
    Route::get('test/cashier', 'Api\ApcopayController@test_cashier');

    // 测试交易验证接口 - 新增
    Route::get('test/verify', 'Api\ApcopayController@test_verify_transaction');
});

/*
|--------------------------------------------------------------------------
| Agent Routes
|--------------------------------------------------------------------------
*/

Route::prefix('agent')->group(function () {
    Route::get('/info', 'Api\AgentController@getInfo');
    Route::get('/referrals', 'Api\AgentController@getReferrals');
    Route::get('/commissions', 'Api\AgentController@getCommissions');
    Route::get('/materials', 'Api\AgentController@getMaterials');
    Route::get('/tasks', 'Api\AgentController@getTasks');
    Route::post('/claim-reward', 'Api\AgentController@claimTaskReward');

    // 添加提现相关路由
    Route::get('/withdrawal-balance', 'Api\AgentController@getWithdrawalBalance');
    Route::get('/withdrawal-history', 'Api\AgentController@getWithdrawalHistory');
    Route::post('/request-withdrawal', 'Api\AgentController@requestWithdrawal');
    Route::post('/cancel-withdrawal', 'Api\AgentController@cancelWithdrawal');
});

// Public route for resetting daily commission (should be called via cron)
Route::get('/agent/reset-daily-commission', 'Api\AgentController@resetDailyCommission');

/*
|--------------------------------------------------------------------------
| Agent Click Tracking Routes
|--------------------------------------------------------------------------
*/

// 记录点击 - 公开访问（无需认证）
Route::get('/click', 'Api\AgentClickController@recordClick');
Route::get('/click2', 'Api\AgentClickController@recordClickPage');

// 获取点击统计 - 需要认证
Route::get('/agent/click-stats', 'Api\AgentClickController@getClickStats');

// 公开获取成功提现记录展示
//Route::get('/agent/recent-withdrawals', 'Api\AgentController@getRecentWithdrawals');
