| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- <?php
- namespace App\Http\Controllers\Game;
- use App\Game\Block;
- use App\Game\Config\GameBasicConfig;
- use App\Game\GameCard;
- use App\Game\GlobalUserInfo;
- use App\Game\Route;
- use App\Game\RouteModel;
- use App\Game\Services\BetbyService;
- use App\Game\Services\BetbyTestService;
- use App\Game\Services\OuroGameService;
- use App\Game\Services\RouteService;
- use App\Game\Services\TelegramAppService;
- use App\Game\Style;
- use App\Game\WebChannelConfig;
- use App\Http\Controllers\Controller;
- use App\Http\helper\NumConfig;
- use App\Models\AccountsInfo;
- use App\Models\SystemStatusInfo;
- use App\Services\ApkService;
- use App\Util;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Redis;
- // use Yansongda\Pay\Log;
- class WebRouteController extends Controller
- {
- protected $routeService;
- public function __construct(RouteService $routeService)
- {
- $this->routeService = $routeService;
- }
- public function Routes(Request $request)
- {
- GlobalUserInfo::UpdateLoginDate($request,true);
- $FPID=$request->input("bfp","");
- $inApp=$request->input('ia',0);
- // 仅加载顶层路由,并预加载所有嵌套子路由
- $routes= RouteModel::whereNull('parent_id')
- ->whereRaw(RouteService::getStateToWhereRaw($request))
- ->with('subs.subs.subs') // 根据实际层级深度调整
- ->orderBy('index')
- ->get();
- $styles=Style::all();
- $blocks=Block::all();
- $config=RouteService::getChannelConfig($request);
- $guestOpen=$config->isGuestOpen();
- $disablePromote=$config->isDisablePromote();
- //在fb内,节省时间,不快速注册
- //if($inApp)$guestOpen=false;
- $upgradeBonus=intval($config->BONUS_VERIFY_PHONE());
- if($guestOpen&&!$upgradeBonus) {
- //游客模式打开,随时可以登录
- $upgradeBonus = SystemStatusInfo::OnlyGetCacheValue('BindPhoneReward') ?? 500;
- }
- $user=GlobalUserInfo::$me;//LoginController::checkLogin($request);
- $hashadd=$request->input("hashadd","");
- $isreg=0;
- if(!empty($hashadd)){
- try{
- $hashadd=json_decode($hashadd,true);
- if($hashadd['type']=='tele'){
- $teleUser=TelegramAppService::decodeHash($hashadd['data']);
- if(intval($teleUser->UserID)){
- if(!$user||$user->UserID!=$teleUser->UserID) {
- $user = GlobalUserInfo::getGameUserInfo('UserID',$teleUser->UserID);
- }
- }else{
- //不存在用户
- if(!$user){
- $guestUser=(new LoginController())->registerUser($request,true);
- if(!is_array($guestUser)){
- $guestUser->NickName=$teleUser->first_name;
- $guestUser->save();
- $isreg = 1;
- $user=$guestUser;
- }
- }
- if($user){
- //绑定现有用户
- $teleUser->UserID=$user->UserID;
- $teleUser->GlobalUID=$user->GlobalUID;
- $teleUser->save();
- }
- }
- }
- }catch (\Exception $e){
- }
- }
- if($user){
- $user=GlobalUserInfo::toWebData($user);
- // $user['reg']=$isreg;
- }else if($guestOpen){
- //游客模式打开,随时可以登录
- $guestUser=GlobalUserInfo::getGameUserInfo('FPID',$FPID);
- if($guestUser)
- $user=GlobalUserInfo::toWebData($guestUser);
- // if(!$guestUser){
- //// $guestUser = GlobalUserInfo::getGameUserInfo('FPID', $FPID);
- //// if (!$guestUser) {
- // $guestUser=(new LoginController())->registerUser($request,true);
- // if(is_array($guestUser)){
- // //出现错误
- // }else{
- // $user=GlobalUserInfo::toWebData($guestUser);
- //// $user['Registed'] = 0;
- // }
- //// }
- // }else{
- // $user=GlobalUserInfo::toWebData($guestUser);
- // }
- }
- // 计算VIP等级
- //$user['vip'] = \App\Services\VipService::calculateVipLevel($user['UserID'] ?? 0);
-
- //LoginController::CheckTimeBonus($user);
- $data=['code'=>0,'data'=>$routes,'blocks'=>$blocks,'styles'=>$styles,'user'=>$user];
- $origin = $request->server('HTTP_ORIGIN') ?? $request->server('HTTP_REFERER')?? '*';
- $data['origin']=$origin;
- $BBService=new BetbyService();
- if(RouteService::isTestSite()) {
- $data['fpid'] = $FPID;
- $data['request']=$request->all();
- $data['gopen'] = $guestOpen;
- Util::WriteLog('pro','');
- $BBService=new BetbyTestService();
- }
- $isDesktop=($request->input('_d','m')=='d');
- $bb=[
- 'id'=>$BBService->brandId,
- 'theme'=>['demo-green-dark-card','bc-game-light-tile'],
- // 'theme'=>['default-table','default-table'],
- 'token'=>$user?$BBService->getDefaultJWT($user):null
- ];
- $firstBonus=1;
- if(env('CONFIG_24680_NFTD_99',0)==0)if($config->Channel==99)$firstBonus=0;
- $registerBonus = SystemStatusInfo::OnlyGetCacheValue('GrantScoreCountNew') ?? 1000;
- $chat = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
- ->where('StatusName', 'Telegram')
- ->first();
- // 默认推荐游戏
- $defaultGameId = 931;
- $recommendGame = '/game/' . $defaultGameId;
-
- // 如果用户信息存在,根据GameID的最后一位数字查询映射关系
- if ($user && isset($user['GameID'])) {
- $gameId = (string)$user['GameID'];
- $lastDigit = (int)substr($gameId, -1); // 获取最后一位数字
-
- // 查询映射关系
- $mapping = DB::connection('write')
- ->table('agent.dbo.game_number_mapping')
- ->where('number', $lastDigit)
- ->first();
-
- if ($mapping && $mapping->game_id) {
- $recommendGame = '/game/' . $mapping->game_id;
- }
- }
- $data['conf']=[
- 'bb'=>$bb,
- 'hall'=>env("CONFIG_24680_HALL")??GameBasicConfig::$HallServer,
- 'DOLLAR'=>env("CONFIG_24680_DOLLAR")??GameBasicConfig::$DOLLAR,
- 'currency'=>env("CONFIG_24680_CURRENCY","USD"),
- 'promoteInstall'=>$disablePromote?0:($inApp?1:((RouteService::isTestOrLocalSite()||$isDesktop)?0:25)),
- 'showInstall'=>$disablePromote?0:($inApp?1:((RouteService::isTestOrLocalSite()||$isDesktop)?0:25)),
- 'guest'=>$guestOpen?1:0,
- 'upgradeBonus'=>$upgradeBonus,
- 'registerBonus' =>$registerBonus,
- 'recommendGame' => $recommendGame,
- 'getStateToWhereRaw' =>RouteService::getStateToWhereRaw($request),
- 'serviceLink' => $chat?$chat->StatusString:'',
- 'popWheel'=>0,
- 'firstBonus'=>$firstBonus,
- 'popFirst'=>$firstBonus,
- 'openRelief'=>$firstBonus,
- 'popBindPhone'=>1,
- 'download'=>['light'=>$config->LightApk,'full'=>$config->FullApk,'bonus'=>$config->BONUS_PWA()],
- 'registerOpen'=>$config->RegOpen??env('CONFIG_REG_OPEN','sms,mail'),//id,phone,sms,mail,guest
- 'loginOpen'=>$config->LoginOpen??'id,phone,sms,mail,guest'
- ];
- $data['conf']['pf']=['type'=>$config->PlatformName,'id'=>$config->PlatformID];
- // $data['request']=$request->all();
- return response()->json($data);
- }
- public function getRegisterGold(Request $request)
- {
- try {
- $user = $request->user();
- $UserID = $user->UserID;
- if ($user->Registed == 1) {
- return apiReturnFail('Fail');
- }
- // 添加金币(10金币)
- $addResult = OuroGameService::AddScore($UserID, 10 * NumConfig::NUM_VALUE, null, false);
- // 更新 webgame.GlobalUserInfo 的 Registed 字段
- DB::connection('mysql')->table('webgame.GlobalUserInfo')
- ->where('UserID', $UserID)
- ->update(['Registed' => 1]);
- // 更新 QPAccountsDB.dbo.AccountsInfo 的 Registed 字段
- DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')
- ->where('UserID', $UserID)
- ->update(['Registed' => 1]);
- return apiReturnSuc([
- 'user' => [
- 'InsureScore' => 10,
- 'Registed' => 1,
- 'message' => 'Success'
- ]
- ]);
- } catch (\Exception $e) {
- \Log::error('注册送金币失败:' . $e->getMessage(), [
- 'UserID' => $UserID ?? 0,
- 'trace' => $e->getTraceAsString()
- ]);
- return apiReturnFail('领取失败:' . $e->getMessage());
- }
- }
- public function checkApkInstall(Request $request)
- {
- $user=$request->user();
- $FPID=$request->input("bfp","");
- $url_sign=$request->get('us')??"tf";
- $UserID=$user?$user->UserID:"";
- $ip=$request->ip();
- $agent=$request->userAgent();
- $alen=strlen($agent);
- $key="apktmp_{$url_sign}_$ip";
- if(isset($UserID)&&!empty($UserID)) {
- $cookieExist = ApkService::loadCookie($UserID);
- if ($cookieExist&&is_array($cookieExist)) {
- $data = [];
- $data['cookie'] = $cookieExist['Cookie']??"";
- $data['params'] = $cookieExist['Params']??"";
- $data['url_sign'] = $cookieExist['UrlSign']??"";
- $data['type'] = $cookieExist['Platform']??"";
- $data['agent'] = $cookieExist['ClickUA']??"";
- $data['origin'] = $_SERVER['HTTP_ORIGIN'] ??$_SERVER['HTTP_REFERER']?? '*';
- return apiReturnSuc($data);
- }
- }
- $datas=[];
- if(Redis::exists($key)){
- $datas=json_decode(Redis::get($key),true);
- Util::WriteLog("apkload",compact('ip','agent','datas'));
- //规则1,只有一个数据,直接归1
- if(count($datas)==1){
- Redis::del($key);
- ApkService::saveCookie($UserID,$datas[0],$FPID);
- return apiReturnSuc($datas[0]);
- }
- foreach ($datas as $k=>$v){
- if($v['agent']==$agent||substr($v['agent'],0,$alen)==$agent){
- array_splice($datas,$k,1);
- Redis::set($key,json_encode($datas));
- Redis::expire($key,7200);
- ApkService::saveCookie($UserID,$v,$FPID);
- return apiReturnSuc($v);
- }
- }
- }
- $recents=ApkService::getRecentsNew($url_sign);
- foreach ($recents as $v){
- if($v['agent']==$agent||substr($v['agent'],0,$alen)==$agent||$ip==$v['ip']){
- ApkService::saveCookie($UserID,$v,$FPID);
- return apiReturnSuc($v);
- }
- }
- return apiReturnFail("");
- }
- public function SaveRoutes(Request $request)
- {
- // Assuming $jsonData is your JSON data
- $jsonData = json_decode(file_get_contents('path_to_your_json_file.json'), true);
- foreach ($jsonData['data'] as $routeData) {
- $this->insertRoute($routeData);
- }
- }
- function insertRoute($routeData, $parentId = null) {
- $route = new RouteModel([
- 'parent_id' => $parentId,
- 'path' => $routeData['path'],
- 'type' => $routeData['type'],
- 'side' => $routeData['side'],
- 'block' => $routeData['block'],
- 'title' => $routeData['title'],
- 'icon' => $routeData['icon'],
- 'fill' => $routeData['fill'],
- 'component' => $routeData['component'],
- 'query' => $routeData['query'],
- 'login' => $routeData['login'],
- 'lpath' => $routeData['lpath']
- ]);
- $route->save();
- foreach ($routeData['subs'] as $sub) {
- $this->insertRoute($sub, $route->id);
- }
- }
- public function testScoreChange(Request $request)
- {
- $user=$request->user();
- $nowGolds=$request->input("nowGolds",4000);
- $AddNum=$request->input("AddNum",1000);
- // notifyWebHall($UserID,"",'pay_finish',["Golds"=>$NowScore,"PayNum"=>$GiftScore]);
- OuroGameService::notifyWebHall($user->UserID,"",'call_client',["Golds"=>$nowGolds,"AddNum"=>$AddNum,"type"=>"start_change"]);
- // ($user_id,$GlobalUID,'call_client',["type"=>"refresh_mail"]);
- return apiReturnSuc("");
- }
- }
|