WebRouteController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\Game\Block;
  4. use App\Game\Config\GameBasicConfig;
  5. use App\Game\GameCard;
  6. use App\Game\GlobalUserInfo;
  7. use App\Game\Route;
  8. use App\Game\RouteModel;
  9. use App\Game\Services\BetbyService;
  10. use App\Game\Services\BetbyTestService;
  11. use App\Game\Services\OuroGameService;
  12. use App\Game\Services\RouteService;
  13. use App\Game\Services\TelegramAppService;
  14. use App\Game\Style;
  15. use App\Game\WebChannelConfig;
  16. use App\Http\Controllers\Controller;
  17. use App\Http\helper\NumConfig;
  18. use App\Models\AccountsInfo;
  19. use App\Models\SystemStatusInfo;
  20. use App\Services\ApkService;
  21. use App\Util;
  22. use Illuminate\Http\Request;
  23. use Illuminate\Support\Facades\DB;
  24. use Illuminate\Support\Facades\Redis;
  25. // use Yansongda\Pay\Log;
  26. class WebRouteController extends Controller
  27. {
  28. protected $routeService;
  29. public function __construct(RouteService $routeService)
  30. {
  31. $this->routeService = $routeService;
  32. }
  33. public function Routes(Request $request)
  34. {
  35. GlobalUserInfo::UpdateLoginDate($request,true);
  36. $FPID=$request->input("bfp","");
  37. $inApp=$request->input('ia',0);
  38. // 仅加载顶层路由,并预加载所有嵌套子路由
  39. $routes= RouteModel::whereNull('parent_id')
  40. ->whereRaw(RouteService::getStateToWhereRaw($request))
  41. ->with('subs.subs.subs') // 根据实际层级深度调整
  42. ->orderBy('index')
  43. ->get();
  44. $styles=Style::all();
  45. $blocks=Block::all();
  46. $config=RouteService::getChannelConfig($request);
  47. $guestOpen=$config->isGuestOpen();
  48. $disablePromote=$config->isDisablePromote();
  49. //在fb内,节省时间,不快速注册
  50. //if($inApp)$guestOpen=false;
  51. $upgradeBonus=intval($config->BONUS_VERIFY_PHONE());
  52. if($guestOpen&&!$upgradeBonus) {
  53. //游客模式打开,随时可以登录
  54. $upgradeBonus = SystemStatusInfo::OnlyGetCacheValue('BindPhoneReward') ?? 500;
  55. }
  56. $user=GlobalUserInfo::$me;//LoginController::checkLogin($request);
  57. $hashadd=$request->input("hashadd","");
  58. $isreg=0;
  59. if(!empty($hashadd)){
  60. try{
  61. $hashadd=json_decode($hashadd,true);
  62. if($hashadd['type']=='tele'){
  63. $teleUser=TelegramAppService::decodeHash($hashadd['data']);
  64. if(intval($teleUser->UserID)){
  65. if(!$user||$user->UserID!=$teleUser->UserID) {
  66. $user = GlobalUserInfo::getGameUserInfo('UserID',$teleUser->UserID);
  67. }
  68. }else{
  69. //不存在用户
  70. if(!$user){
  71. $guestUser=(new LoginController())->registerUser($request,true);
  72. if(!is_array($guestUser)){
  73. $guestUser->NickName=$teleUser->first_name;
  74. $guestUser->save();
  75. $isreg = 1;
  76. $user=$guestUser;
  77. }
  78. }
  79. if($user){
  80. //绑定现有用户
  81. $teleUser->UserID=$user->UserID;
  82. $teleUser->GlobalUID=$user->GlobalUID;
  83. $teleUser->save();
  84. }
  85. }
  86. }
  87. }catch (\Exception $e){
  88. }
  89. }
  90. if($user){
  91. $user=GlobalUserInfo::toWebData($user);
  92. // $user['reg']=$isreg;
  93. }else if($guestOpen){
  94. //游客模式打开,随时可以登录
  95. $guestUser=GlobalUserInfo::getGameUserInfo('FPID',$FPID);
  96. if($guestUser)
  97. $user=GlobalUserInfo::toWebData($guestUser);
  98. // if(!$guestUser){
  99. //// $guestUser = GlobalUserInfo::getGameUserInfo('FPID', $FPID);
  100. //// if (!$guestUser) {
  101. // $guestUser=(new LoginController())->registerUser($request,true);
  102. // if(is_array($guestUser)){
  103. // //出现错误
  104. // }else{
  105. // $user=GlobalUserInfo::toWebData($guestUser);
  106. //// $user['Registed'] = 0;
  107. // }
  108. //// }
  109. // }else{
  110. // $user=GlobalUserInfo::toWebData($guestUser);
  111. // }
  112. }
  113. // 计算VIP等级
  114. //$user['vip'] = \App\Services\VipService::calculateVipLevel($user['UserID'] ?? 0);
  115. //LoginController::CheckTimeBonus($user);
  116. $data=['code'=>0,'data'=>$routes,'blocks'=>$blocks,'styles'=>$styles,'user'=>$user];
  117. $origin = $request->server('HTTP_ORIGIN') ?? $request->server('HTTP_REFERER')?? '*';
  118. $data['origin']=$origin;
  119. $BBService=new BetbyService();
  120. if(RouteService::isTestSite()) {
  121. $data['fpid'] = $FPID;
  122. $data['request']=$request->all();
  123. $data['gopen'] = $guestOpen;
  124. Util::WriteLog('pro','');
  125. $BBService=new BetbyTestService();
  126. }
  127. $isDesktop=($request->input('_d','m')=='d');
  128. $bb=[
  129. 'id'=>$BBService->brandId,
  130. 'theme'=>['demo-green-dark-card','bc-game-light-tile'],
  131. // 'theme'=>['default-table','default-table'],
  132. 'token'=>$user?$BBService->getDefaultJWT($user):null
  133. ];
  134. $firstBonus=1;
  135. if(env('CONFIG_24680_NFTD_99',0)==0)if($config->Channel==99)$firstBonus=0;
  136. $registerBonus = SystemStatusInfo::OnlyGetCacheValue('GrantScoreCountNew') ?? 1000;
  137. $chat = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  138. ->where('StatusName', 'Telegram')
  139. ->first();
  140. // 默认推荐游戏
  141. $defaultGameId = 931;
  142. $recommendGame = '/game/' . $defaultGameId;
  143. // 如果用户信息存在,根据GameID的最后一位数字查询映射关系
  144. if ($user && isset($user['GameID'])) {
  145. $gameId = (string)$user['GameID'];
  146. $lastDigit = (int)substr($gameId, -1); // 获取最后一位数字
  147. // 查询映射关系
  148. $mapping = DB::connection('write')
  149. ->table('agent.dbo.game_number_mapping')
  150. ->where('number', $lastDigit)
  151. ->first();
  152. if ($mapping && $mapping->game_id) {
  153. $recommendGame = '/game/' . $mapping->game_id;
  154. }
  155. }
  156. $data['conf']=[
  157. 'bb'=>$bb,
  158. 'hall'=>env("CONFIG_24680_HALL")??GameBasicConfig::$HallServer,
  159. 'DOLLAR'=>env("CONFIG_24680_DOLLAR")??GameBasicConfig::$DOLLAR,
  160. 'currency'=>env("CONFIG_24680_CURRENCY","USD"),
  161. 'promoteInstall'=>$disablePromote?0:($inApp?1:((RouteService::isTestOrLocalSite()||$isDesktop)?0:25)),
  162. 'showInstall'=>$disablePromote?0:($inApp?1:((RouteService::isTestOrLocalSite()||$isDesktop)?0:25)),
  163. 'guest'=>$guestOpen?1:0,
  164. 'upgradeBonus'=>$upgradeBonus,
  165. 'registerBonus' =>$registerBonus,
  166. 'recommendGame' => $recommendGame,
  167. 'LandscapeGames' => [962,963,964,965,966,967,972,973,974,975, 976, 977, 978, 979, 980, 982, 983,
  168. 962, 941, 942, 943, 945, 946, 947, 948, 949, 950, 951, 952, 953,
  169. 936, 938, 939,940,934],
  170. 'getStateToWhereRaw' =>RouteService::getStateToWhereRaw($request),
  171. 'serviceLink' => $chat?$chat->StatusString:'',
  172. 'popWheel'=>0,
  173. 'firstBonus'=>$firstBonus,
  174. 'popFirst'=>$firstBonus,
  175. 'openRelief'=>$firstBonus,
  176. 'popBindPhone'=>1,
  177. 'download'=>['light'=>$config->LightApk,'full'=>$config->FullApk,'bonus'=>$config->BONUS_PWA()],
  178. 'registerOpen'=>$config->RegOpen??env('CONFIG_REG_OPEN','sms,mail'),//id,phone,sms,mail,guest
  179. 'loginOpen'=>$config->LoginOpen??'id,phone,sms,mail,guest'
  180. ];
  181. $data['conf']['pf']=['type'=>$config->PlatformName,'id'=>$config->PlatformID];
  182. // $data['request']=$request->all();
  183. return response()->json($data);
  184. }
  185. public function getRegisterGold(Request $request)
  186. {
  187. try {
  188. $user = $request->user();
  189. $UserID = $user->UserID;
  190. if ($user->Registed == 1) {
  191. return apiReturnFail('Fail');
  192. }
  193. // 添加金币(10金币)
  194. $addResult = OuroGameService::AddScore($UserID, 10 * NumConfig::NUM_VALUE, null, false);
  195. // 更新 webgame.GlobalUserInfo 的 Registed 字段
  196. DB::connection('mysql')->table('webgame.GlobalUserInfo')
  197. ->where('UserID', $UserID)
  198. ->update(['Registed' => 1]);
  199. // 更新 QPAccountsDB.dbo.AccountsInfo 的 Registed 字段
  200. DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')
  201. ->where('UserID', $UserID)
  202. ->update(['Registed' => 1]);
  203. return apiReturnSuc([
  204. 'user' => [
  205. 'InsureScore' => 10,
  206. 'Registed' => 1,
  207. 'message' => 'Success'
  208. ]
  209. ]);
  210. } catch (\Exception $e) {
  211. \Log::error('注册送金币失败:' . $e->getMessage(), [
  212. 'UserID' => $UserID ?? 0,
  213. 'trace' => $e->getTraceAsString()
  214. ]);
  215. return apiReturnFail('领取失败:' . $e->getMessage());
  216. }
  217. }
  218. public function checkApkInstall(Request $request)
  219. {
  220. $user=$request->user();
  221. $FPID=$request->input("bfp","");
  222. $url_sign=$request->get('us')??"tf";
  223. $UserID=$user?$user->UserID:"";
  224. $ip=$request->ip();
  225. $agent=$request->userAgent();
  226. $alen=strlen($agent);
  227. $key="apktmp_{$url_sign}_$ip";
  228. if(isset($UserID)&&!empty($UserID)) {
  229. $cookieExist = ApkService::loadCookie($UserID);
  230. if ($cookieExist&&is_array($cookieExist)) {
  231. $data = [];
  232. $data['cookie'] = $cookieExist['Cookie']??"";
  233. $data['params'] = $cookieExist['Params']??"";
  234. $data['url_sign'] = $cookieExist['UrlSign']??"";
  235. $data['type'] = $cookieExist['Platform']??"";
  236. $data['agent'] = $cookieExist['ClickUA']??"";
  237. $data['origin'] = $_SERVER['HTTP_ORIGIN'] ??$_SERVER['HTTP_REFERER']?? '*';
  238. return apiReturnSuc($data);
  239. }
  240. }
  241. $datas=[];
  242. if(Redis::exists($key)){
  243. $datas=json_decode(Redis::get($key),true);
  244. Util::WriteLog("apkload",compact('ip','agent','datas'));
  245. //规则1,只有一个数据,直接归1
  246. if(count($datas)==1){
  247. Redis::del($key);
  248. ApkService::saveCookie($UserID,$datas[0],$FPID);
  249. return apiReturnSuc($datas[0]);
  250. }
  251. foreach ($datas as $k=>$v){
  252. if($v['agent']==$agent||substr($v['agent'],0,$alen)==$agent){
  253. array_splice($datas,$k,1);
  254. Redis::set($key,json_encode($datas));
  255. Redis::expire($key,7200);
  256. ApkService::saveCookie($UserID,$v,$FPID);
  257. return apiReturnSuc($v);
  258. }
  259. }
  260. }
  261. $recents=ApkService::getRecentsNew($url_sign);
  262. foreach ($recents as $v){
  263. if($v['agent']==$agent||substr($v['agent'],0,$alen)==$agent||$ip==$v['ip']){
  264. ApkService::saveCookie($UserID,$v,$FPID);
  265. return apiReturnSuc($v);
  266. }
  267. }
  268. return apiReturnFail("");
  269. }
  270. public function SaveRoutes(Request $request)
  271. {
  272. // Assuming $jsonData is your JSON data
  273. $jsonData = json_decode(file_get_contents('path_to_your_json_file.json'), true);
  274. foreach ($jsonData['data'] as $routeData) {
  275. $this->insertRoute($routeData);
  276. }
  277. }
  278. function insertRoute($routeData, $parentId = null) {
  279. $route = new RouteModel([
  280. 'parent_id' => $parentId,
  281. 'path' => $routeData['path'],
  282. 'type' => $routeData['type'],
  283. 'side' => $routeData['side'],
  284. 'block' => $routeData['block'],
  285. 'title' => $routeData['title'],
  286. 'icon' => $routeData['icon'],
  287. 'fill' => $routeData['fill'],
  288. 'component' => $routeData['component'],
  289. 'query' => $routeData['query'],
  290. 'login' => $routeData['login'],
  291. 'lpath' => $routeData['lpath']
  292. ]);
  293. $route->save();
  294. foreach ($routeData['subs'] as $sub) {
  295. $this->insertRoute($sub, $route->id);
  296. }
  297. }
  298. public function testScoreChange(Request $request)
  299. {
  300. $user=$request->user();
  301. $nowGolds=$request->input("nowGolds",4000);
  302. $AddNum=$request->input("AddNum",1000);
  303. // notifyWebHall($UserID,"",'pay_finish',["Golds"=>$NowScore,"PayNum"=>$GiftScore]);
  304. OuroGameService::notifyWebHall($user->UserID,"",'call_client',["Golds"=>$nowGolds,"AddNum"=>$AddNum,"type"=>"start_change"]);
  305. // ($user_id,$GlobalUID,'call_client',["type"=>"refresh_mail"]);
  306. return apiReturnSuc("");
  307. }
  308. }