WebRouteController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. $data['conf']=[
  144. 'bb'=>$bb,
  145. 'hall'=>env("CONFIG_24680_HALL")??GameBasicConfig::$HallServer,
  146. 'DOLLAR'=>env("CONFIG_24680_DOLLAR")??GameBasicConfig::$DOLLAR,
  147. 'currency'=>env("CONFIG_24680_CURRENCY","USD"),
  148. 'promoteInstall'=>$disablePromote?0:($inApp?1:((RouteService::isTestOrLocalSite()||$isDesktop)?0:25)),
  149. 'showInstall'=>$disablePromote?0:($inApp?1:((RouteService::isTestOrLocalSite()||$isDesktop)?0:25)),
  150. 'guest'=>$guestOpen?1:0,
  151. 'upgradeBonus'=>$upgradeBonus,
  152. 'registerBonus' =>$registerBonus,
  153. 'recommendGame' => $recommendGame,
  154. 'LandscapeGames' => [962,963,964,965,966,967,972,973,974,975, 976, 977, 978, 979, 980, 982, 983,
  155. 962, 941, 942, 943, 945, 946, 947, 948, 949, 950, 951, 952, 953,
  156. 936, 938, 939,940,934],
  157. 'getStateToWhereRaw' =>RouteService::getStateToWhereRaw($request),
  158. 'serviceLink' => $chat?$chat->StatusString:'',
  159. 'popWheel'=>0,
  160. 'firstBonus'=>$firstBonus,
  161. 'popFirst'=>$firstBonus,
  162. 'openRelief'=>$firstBonus,
  163. 'popBindPhone'=>1,
  164. 'download'=>['light'=>$config->LightApk,'full'=>$config->FullApk,'bonus'=>$config->BONUS_PWA()],
  165. 'registerOpen'=>$config->RegOpen??env('CONFIG_REG_OPEN','sms,mail'),//id,phone,sms,mail,guest
  166. 'loginOpen'=>$config->LoginOpen??'id,phone,sms,mail,guest'
  167. ];
  168. $data['conf']['pf']=['type'=>$config->PlatformName,'id'=>$config->PlatformID];
  169. // $data['request']=$request->all();
  170. return response()->json($data);
  171. }
  172. public function getRegisterGold(Request $request)
  173. {
  174. try {
  175. $user = $request->user();
  176. $UserID = $user->UserID;
  177. if ($user->Registed == 1) {
  178. return apiReturnFail('Fail');
  179. }
  180. // 添加金币(10金币)
  181. $addResult = OuroGameService::AddScore($UserID, 10 * NumConfig::NUM_VALUE, null, false);
  182. // 更新 webgame.GlobalUserInfo 的 Registed 字段
  183. DB::connection('mysql')->table('webgame.GlobalUserInfo')
  184. ->where('UserID', $UserID)
  185. ->update(['Registed' => 1]);
  186. // 更新 QPAccountsDB.dbo.AccountsInfo 的 Registed 字段
  187. DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')
  188. ->where('UserID', $UserID)
  189. ->update(['Registed' => 1]);
  190. return apiReturnSuc([
  191. 'user' => [
  192. 'InsureScore' => 10,
  193. 'Registed' => 1,
  194. 'message' => 'Success'
  195. ]
  196. ]);
  197. } catch (\Exception $e) {
  198. \Log::error('注册送金币失败:' . $e->getMessage(), [
  199. 'UserID' => $UserID ?? 0,
  200. 'trace' => $e->getTraceAsString()
  201. ]);
  202. return apiReturnFail('领取失败:' . $e->getMessage());
  203. }
  204. }
  205. public function checkApkInstall(Request $request)
  206. {
  207. $user=$request->user();
  208. $FPID=$request->input("bfp","");
  209. $url_sign=$request->get('us')??"tf";
  210. $UserID=$user?$user->UserID:"";
  211. $ip=$request->ip();
  212. $agent=$request->userAgent();
  213. $alen=strlen($agent);
  214. $key="apktmp_{$url_sign}_$ip";
  215. if(isset($UserID)&&!empty($UserID)) {
  216. $cookieExist = ApkService::loadCookie($UserID);
  217. if ($cookieExist&&is_array($cookieExist)) {
  218. $data = [];
  219. $data['cookie'] = $cookieExist['Cookie']??"";
  220. $data['params'] = $cookieExist['Params']??"";
  221. $data['url_sign'] = $cookieExist['UrlSign']??"";
  222. $data['type'] = $cookieExist['Platform']??"";
  223. $data['agent'] = $cookieExist['ClickUA']??"";
  224. $data['origin'] = $_SERVER['HTTP_ORIGIN'] ??$_SERVER['HTTP_REFERER']?? '*';
  225. return apiReturnSuc($data);
  226. }
  227. }
  228. $datas=[];
  229. if(Redis::exists($key)){
  230. $datas=json_decode(Redis::get($key),true);
  231. Util::WriteLog("apkload",compact('ip','agent','datas'));
  232. //规则1,只有一个数据,直接归1
  233. if(count($datas)==1){
  234. Redis::del($key);
  235. ApkService::saveCookie($UserID,$datas[0],$FPID);
  236. return apiReturnSuc($datas[0]);
  237. }
  238. foreach ($datas as $k=>$v){
  239. if($v['agent']==$agent||substr($v['agent'],0,$alen)==$agent){
  240. array_splice($datas,$k,1);
  241. Redis::set($key,json_encode($datas));
  242. Redis::expire($key,7200);
  243. ApkService::saveCookie($UserID,$v,$FPID);
  244. return apiReturnSuc($v);
  245. }
  246. }
  247. }
  248. $recents=ApkService::getRecentsNew($url_sign);
  249. foreach ($recents as $v){
  250. if($v['agent']==$agent||substr($v['agent'],0,$alen)==$agent||$ip==$v['ip']){
  251. ApkService::saveCookie($UserID,$v,$FPID);
  252. return apiReturnSuc($v);
  253. }
  254. }
  255. return apiReturnFail("");
  256. }
  257. public function SaveRoutes(Request $request)
  258. {
  259. // Assuming $jsonData is your JSON data
  260. $jsonData = json_decode(file_get_contents('path_to_your_json_file.json'), true);
  261. foreach ($jsonData['data'] as $routeData) {
  262. $this->insertRoute($routeData);
  263. }
  264. }
  265. function insertRoute($routeData, $parentId = null) {
  266. $route = new RouteModel([
  267. 'parent_id' => $parentId,
  268. 'path' => $routeData['path'],
  269. 'type' => $routeData['type'],
  270. 'side' => $routeData['side'],
  271. 'block' => $routeData['block'],
  272. 'title' => $routeData['title'],
  273. 'icon' => $routeData['icon'],
  274. 'fill' => $routeData['fill'],
  275. 'component' => $routeData['component'],
  276. 'query' => $routeData['query'],
  277. 'login' => $routeData['login'],
  278. 'lpath' => $routeData['lpath']
  279. ]);
  280. $route->save();
  281. foreach ($routeData['subs'] as $sub) {
  282. $this->insertRoute($sub, $route->id);
  283. }
  284. }
  285. public function testScoreChange(Request $request)
  286. {
  287. $user=$request->user();
  288. $nowGolds=$request->input("nowGolds",4000);
  289. $AddNum=$request->input("AddNum",1000);
  290. // notifyWebHall($UserID,"",'pay_finish',["Golds"=>$NowScore,"PayNum"=>$GiftScore]);
  291. OuroGameService::notifyWebHall($user->UserID,"",'call_client',["Golds"=>$nowGolds,"AddNum"=>$AddNum,"type"=>"start_change"]);
  292. // ($user_id,$GlobalUID,'call_client',["type"=>"refresh_mail"]);
  293. return apiReturnSuc("");
  294. }
  295. }