ActivityController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\dao\Estatisticas\RechargeWithDraw;
  4. use App\Facade\TableName;
  5. use App\Game\GlobalUserInfo;
  6. use App\Game\RePayConfig;
  7. use App\Game\Services\AgentService;
  8. use App\Game\Services\LZCompressor\LZString as LZ;
  9. use App\Game\Services\OuroGameService;
  10. use App\Game\Services\RouteService;
  11. use App\Game\Services\ServerService;
  12. use App\Game\WebActivity;
  13. use App\Game\WebChannelConfig;
  14. use App\Http\Controllers\Controller;
  15. use App\Game\RedEnvelopeConfig;
  16. use App\Game\RedEnvelopeLog;
  17. use App\Http\helper\Helper;
  18. use App\Http\helper\NumConfig;
  19. use App\Jobs\AfEvent;
  20. use App\Models\AccountsInfo;
  21. use App\Models\Order;
  22. use App\Models\PrivateMail;
  23. use App\Models\RecordUserDataStatistics;
  24. use App\Models\Treasure\GameScoreInfo;
  25. use App\Notification\TelegramBot;
  26. use App\Services\OrderServices;
  27. use App\Services\PayConfig;
  28. use App\Services\SmartFastPay;
  29. use App\Services\StoredProcedure;
  30. use App\Util;
  31. use Illuminate\Http\Request;
  32. use Carbon\Carbon;
  33. use Illuminate\Support\Facades\DB;
  34. use Illuminate\Support\Facades\Hash;
  35. use Illuminate\Support\Facades\Log;
  36. use Illuminate\Support\Facades\Redis;
  37. use PDO;
  38. class ActivityController extends Controller
  39. {
  40. public function index()
  41. {
  42. }
  43. public function List(Request $request)
  44. {
  45. return apiReturnSuc(['list'=>WebActivity::query()->whereRaw(RouteService::getStateToWhereRaw($request))->get()->toArray()]);
  46. }
  47. public function GetProtectNum(Request $request)
  48. {
  49. $user=$request->user();
  50. if(ServerService::GetGlobalServerInfoByGUID($user->GlobalUID)['Subsite']=='Europe'){
  51. //欧洲暂时封闭
  52. return apiReturnSuc();
  53. }
  54. $UserID=$user->UserID;
  55. $res=DB::connection('sqlsrv')->select("exec QPAccountsDB.dbo.GSP_GP_QueryProtect $UserID");
  56. return apiReturnSuc($res);
  57. }
  58. public function AddProtectNum(Request $request)
  59. {
  60. $user=$request->user();
  61. $UserID=$user->UserID;
  62. if(ServerService::GetGlobalServerInfoByGUID($user->GlobalUID)['Subsite']=='Europe'){
  63. //欧洲暂时封闭
  64. return apiReturnSuc();
  65. }
  66. $dbh = DB::connection()->getPdo();
  67. $sql="
  68. set nocount on use QPAccountsDB;
  69. DECLARE @return_value INT;
  70. EXEC @return_value = QPAccountsDB.dbo.GSP_GP_AddProtect @dwUserID = $UserID;
  71. SELECT @return_value as ReturnValue;";
  72. $stmt = $dbh->prepare($sql);
  73. $stmt->execute();
  74. $result = $stmt->fetch(\PDO::FETCH_ASSOC);
  75. // dd($user,$result);
  76. // 获取返回值和错误描述
  77. $returnValue = $result['ReturnValue']??0;
  78. // $result=DB::connection('sqlsrv')->select('EXEC @return_value = QPAccountsDB.dbo.GSP_GP_AddProtect @dwUserID = '.$UserID.'; SELECT @return_value AS ReturnValue;');
  79. // 获取返回值
  80. // $returnValue = $result[1]->ReturnValue;
  81. if ($returnValue == 0) {
  82. return apiReturnSuc($result);
  83. } else if ($returnValue == 1) {
  84. return apiReturnFail(['web.protect.score_limit','Score limit reached']);
  85. } else if ($returnValue == 3) {
  86. return apiReturnFail(['web.protect.times_limit','Protect times limit reached']);
  87. } else {
  88. return apiReturnFail(['web.withdraw.try_again_later','Unknown error']);
  89. }
  90. }
  91. public function GetCheckInInfoConfig(Request $request)
  92. {
  93. $user=$request->user();
  94. $UserID=$user->UserID;
  95. $res=DB::connection('sqlsrv')->select("exec QPAccountsDB.dbo.GSP_GP_GetUserSignInInfo $UserID");
  96. $res2=DB::table('QPAccountsDB.dbo.UserSignInInfo')->where('UserID',$UserID)->first();
  97. $max=count($res);
  98. $res2=(array)$res2;
  99. if($res2['NextDayNumber']>$max) {
  100. $res2['NextDayNumber']= $res2['NextDayNumber'] % $max + 1;
  101. $res2['RecordDay']='';
  102. for($i=0;$i<$max;$i++) {
  103. $res2['RecordDay'].=$i<($res2['NextDayNumber']-1)?'1':'0';
  104. }
  105. }
  106. $res2['config']=$res;
  107. return apiReturnSuc($res2);
  108. }
  109. public function GetCheckInInfo(Request $request)
  110. {
  111. $user=$request->user();
  112. $UserID=$user->UserID;
  113. try {
  114. // 定义输出参数
  115. $errorDescribe = '';
  116. // 调用存储过程
  117. // $result = DB::connection('sqlsrv')->select('
  118. // use QPAccountsDB;
  119. // DECLARE @strErrorDescribe NVARCHAR(127);
  120. // DECLARE @return_value INT;
  121. // EXEC @return_value = QPAccountsDB.dbo.GSP_GP_UserSignIn @dwUserID = $UserID, @strErrorDescribe = @strErrorDescribe OUTPUT;
  122. // SELECT @return_value as ReturnValue, @strErrorDescribe as ErrorDescribe;
  123. // ', [$UserID]);
  124. //
  125. $dbh = DB::connection()->getPdo();
  126. $sql="
  127. set nocount on use QPAccountsDB;
  128. DECLARE @strErrorDescribe NVARCHAR(127);
  129. DECLARE @return_value INT;
  130. EXEC @return_value = QPAccountsDB.dbo.GSP_GP_UserSignIn @dwUserID = $UserID, @strErrorDescribe = @strErrorDescribe OUTPUT;
  131. SELECT @return_value as ReturnValue, @strErrorDescribe as ErrorDescribe;";
  132. $stmt = $dbh->prepare($sql);
  133. $stmt->execute();
  134. $result = $stmt->fetch(\PDO::FETCH_ASSOC);
  135. // dd($user,$result);
  136. // 获取返回值和错误描述
  137. $returnValue = $result['ReturnValue']??0;
  138. // $errorDescribe = $result['ErrorDescribe'];
  139. // 根据返回值和错误描述处理
  140. switch ($returnValue) {
  141. case 1:
  142. return apiReturnFail(['web.checkin.user_signin_error', 'Failed to get user sign-in information']);
  143. case 2:
  144. return apiReturnFail(['web.checkin.user_already_signed_in', 'You have already signed in today']);
  145. case 3:
  146. return apiReturnFail(['web.checkin.signin_event_ended', 'The sign-in activity has ended']);
  147. case 4:
  148. return apiReturnFail(['web.checkin.signin_data_error', 'Failed to read sign-in data']);
  149. case 5:
  150. return apiReturnFail(['web.checkin.recharge_required', 'Recharge is required to sign in'],[],777);
  151. case 0:
  152. return apiReturnSuc($result);
  153. default:
  154. return apiReturnFail(['web.checkin.unknown_error', 'Unknown error']);
  155. }
  156. } catch (\Exception $e) {
  157. TelegramBot::getDefault()->sendProgramNotify("Game Checkin:", $e->getMessage());
  158. // 捕获异常并返回错误响应
  159. return apiReturnFail(['web.checkin.exception_occurred', 'An error occurred while processing your request'], [], 500);
  160. }
  161. }
  162. public function RedConfig(Request $request){
  163. $config=Redis::get("RedEnvelopeConfig");
  164. if(!$config){
  165. $config=RedEnvelopeConfig::query()->get();
  166. Redis::set("RedEnvelopeConfig",json_encode($config));
  167. Redis::expire("RedEnvelopeConfig",600);
  168. }else{
  169. $config=json_decode($config,true);
  170. }
  171. return apiReturnSuc($config);
  172. }
  173. public function RedCheck(Request $request)
  174. {
  175. $maxRedpack=24680;
  176. $currentDateTime = Carbon::now();
  177. $currentTime = $currentDateTime->format('H:i:s');
  178. // 查找当前时间段内的红包配置
  179. $config = RedEnvelopeConfig::where('StartTime', '<=', $currentTime)
  180. ->where('EndTime', '>=', $currentTime)
  181. ->first();
  182. if ($config) {
  183. $getted=false;
  184. if($request->user()) {
  185. $userID=$request->user()->UserID;
  186. $checkKey = "redpack_$userID";
  187. $getted=Redis::exists($checkKey);
  188. }
  189. return apiReturnSuc(['status' => $getted?-1:1,'max'=>$maxRedpack]);
  190. } else {
  191. // 计算下一个红包时间
  192. $nextConfig = RedEnvelopeConfig::where('StartTime', '>', $currentTime)
  193. ->orderBy('StartTime', 'asc')
  194. ->first();
  195. if (!$nextConfig) {
  196. // 如果今天没有更多红包时间段,则查找明天的第一个红包时间段
  197. $nextConfig = RedEnvelopeConfig::orderBy('StartTime', 'asc')->first();
  198. $nextTime = Carbon::tomorrow()->setTimeFromTimeString($nextConfig->StartTime);
  199. } else {
  200. $nextTime = Carbon::today()->setTimeFromTimeString($nextConfig->StartTime);
  201. }
  202. $diffMinutes = $currentDateTime->diffInSeconds($nextTime);
  203. return apiReturnSuc(['status' => 0,'max'=>$maxRedpack, 'next_in_seconds' => $diffMinutes],['activity.redpack.please_wait','Please wait until next time.']);
  204. }
  205. }
  206. public function RedReceive(Request $request)
  207. {
  208. return apiReturnSuc(['status' => -1,'amount'=>0]);
  209. $user=$request->user();
  210. $userID = $user->UserID;
  211. $currentDateTime = Carbon::now();
  212. $currentTime = $currentDateTime->format('H:i:s');
  213. $checkKey="redpack_$userID";
  214. if(Redis::exists($checkKey)){
  215. return apiReturnSuc(['status' => -1,'amount'=>0]);
  216. }
  217. // 查找当前时间段内的红包配置
  218. $config = RedEnvelopeConfig::where('StartTime', '<=', $currentTime)
  219. ->where('EndTime', '>=', $currentTime)
  220. ->first();
  221. if ($config) {
  222. // 在红包活动时间段内,生成红包金额
  223. $amount = $this->generateRedEnvelopeAmount($user,$config);
  224. if(is_array($amount))return $amount;
  225. // 记录领取日志
  226. RedEnvelopeLog::create([
  227. 'UserID' => $userID,
  228. 'ReceivedAt' => $currentDateTime,
  229. 'Amount' => $amount,
  230. 'Comment' => '红包雨活动'
  231. ]);
  232. Redis::set($checkKey,1);
  233. Redis::expire($checkKey,3600);
  234. return apiReturnSuc(['amount' => $amount,'status' => 1]);
  235. } else {
  236. // 不在红包活动时间段内
  237. return apiReturnFail(['web.activity.redpack_not_available','There is no RedPack']);
  238. }
  239. }
  240. /**
  241. * @param $user
  242. * @param RedEnvelopeConfig $config
  243. * @return array|int
  244. */
  245. private function generateRedEnvelopeAmount($user, $config)
  246. {
  247. //超过限额
  248. if($config->PrizePool>=3000){
  249. return 0;
  250. }
  251. $UserID=$user->UserID;
  252. // $recharinfo=DB::connection('write')->table('QPAccountsDB.dbo.YN_VIPAccount')
  253. // ->where('UserID', $UserID)->first();
  254. // // 根据用户的充值金额决定红包金额
  255. $userTotal = DB::connection('write')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  256. ->where('UserID', $UserID)
  257. ->first();
  258. $deposit = 0;
  259. $withdraw = 0;
  260. $revenue = 0;
  261. if($userTotal){
  262. $deposit = $userTotal->Recharge;
  263. $withdraw = $userTotal->Withdraw;
  264. $revenue = $userTotal->Revenue;
  265. }
  266. $amount = 0;
  267. if ($deposit == 0) {
  268. // 未充值用户无法领取红包
  269. return apiReturnFail(['web.activity.redpack_no_recharge', 'message' => 'You need deposit first!']);
  270. } elseif ($deposit < 50) {
  271. // 50以下
  272. if (rand(1, 100) <= 50) {
  273. $amount=0;
  274. } else {
  275. $amount = rand(1, 2);
  276. }
  277. } elseif ($deposit < 100) {
  278. // 50-100
  279. if (rand(1, 100) <= 40) {
  280. $amount=0;
  281. } else {
  282. $amount = rand(1, 5);
  283. }
  284. } elseif ($deposit < 500) {
  285. // 100-500
  286. if (rand(1, 100) <= 25) {
  287. $amount=0;
  288. } else {
  289. $amount = rand(5, 10);
  290. }
  291. } elseif ($deposit < 1000) {
  292. // 500-1000
  293. if (rand(1, 100) <= 20) {
  294. $amount=0;
  295. } else {
  296. $amount = rand(5, 15);
  297. }
  298. } elseif ($deposit < 5000) {
  299. // 1000-5000
  300. if (rand(1, 100) <= 10) {
  301. $amount=0;
  302. } else {
  303. $amount = rand(10, 30);
  304. }
  305. } elseif ($deposit < 20000) {
  306. // 5000-20000
  307. $amount = rand(20, 100);
  308. } elseif ($deposit < 200000) {
  309. // 20000-200000
  310. $amount = rand(100, 150);
  311. } else {
  312. // 200000以上
  313. $amount = rand(100, 300);
  314. }
  315. if($amount){
  316. //平台资产》充 减半
  317. if($withdraw + $revenue > $deposit*100 && $deposit>1000){
  318. $rate = max(($withdraw + $revenue) / ($deposit*100) * 2,2);
  319. $amount = intval($amount/$rate);
  320. }
  321. //出》入 0
  322. if($withdraw > $deposit*100){
  323. $amount = 0;
  324. }
  325. }
  326. if($amount){
  327. $config->increment('PrizePool', $amount);
  328. OuroGameService::AddScore($UserID,$amount*NumConfig::NUM_VALUE,OuroGameService::REASON_RedEnvelope);
  329. // OuroGameService::AddDrawBase($UserID,$amount*100,2);
  330. }
  331. return $amount;
  332. }
  333. public function repayFirst()
  334. {
  335. $str="10014268,2000,BRA2851903748065310014268
  336. 10014270,2000,BRA2855489212693610014270
  337. 10014271,2000,BRA2852393071882610014271
  338. 10014274,1000,BRA2853030100749910014274
  339. 10014276,1000,BRA2853245554392310014276
  340. 10014277,2000,BRA2853344779876810014277
  341. 10014277,2000,BRA2855290186893810014277
  342. 10014277,2000,BRA2864525856913410014277
  343. 10014281,1000,BRA2854641828657010014281
  344. 10014282,2000,BRA2854744724737410014282
  345. 10014285,2000,BRA2855039889866610014285
  346. 10014287,2000,BRA2855391649287010014287
  347. 10014288,1000,BRA2855464384803010014288
  348. 10014292,2000,BRA2856246492161510014292
  349. 10014297,1000,BRA2857229048633010014297
  350. 10014300,2000,BRA2858261561088610014300
  351. 10014301,2000,BRA2858433689840310014301
  352. 10014302,1000,BRA2858522897364510014302
  353. 10014305,2000,BRA2859083559189210014305
  354. 10014306,2000,BRA2859074387476010014306
  355. 10014308,2000,BRA2859253433784710014308
  356. 10014309,2000,BRA2859266221396810014309
  357. 10014311,1000,BRA2859721671820010014311
  358. 10014314,2000,BRA2860714714541810014314
  359. 10014316,2000,BRA2861078506701410014316
  360. 10014318,2000,BRA2861340050408610014318
  361. 10014324,2000,BRA2863987369403910014324
  362. 10014326,2000,BRA2862573151411810014326
  363. 10014327,2000,BRA2862997500499910014327
  364. 10014330,1000,BRA2863297592217210014330
  365. 10014332,2000,BRA2863120608306010014332
  366. 10014335,1000,BRA2975317980447310014335
  367. 10014339,2000,BRA2864730304211810014339
  368. 10014351,2000,BRA2869670282797610014351
  369. 10014352,2000,BRA2971319703907510014352
  370. 10014358,2000,BRA2973553150552010014358
  371. 10014372,2000,BRA2995159192410010014372
  372. 10014373,2000,BRA2995376698241510014373
  373. 10014375,2000,BRA2996350286730710014375
  374. 10014383,2000,BRA2902200217093410014383";
  375. $arr=explode("\n",$str);
  376. $sort=[];
  377. $g201 = DB::table('agent.dbo.recharge_gear')->where('gift_id', 201)->select('gift_id', 'money', 'give', 'favorable_price', 'second_give')->first();
  378. $g211 = DB::table('agent.dbo.recharge_gear')->where('gift_id', 211)->select('gift_id', 'money', 'give', 'favorable_price', 'second_give')->first();
  379. foreach ($arr as $k=>$v){
  380. [$UserID,$amount,$sn]=explode(',',$v);
  381. if(isset($sort[$UserID]))continue;
  382. $sort[$UserID]=$amount;
  383. if($amount==1000)$first=$g201;
  384. else $first=$g211;
  385. if ($first && $first->second_give > 0) {
  386. $bonus = '30000,' . $amount;
  387. PrivateMail::sendMail(2, $UserID, "Suplemento de erro de primeiro depósito", "Nós adicionamos para você, por favor, aceite.", $bonus, $sn, $amount);
  388. $fpkey = 'Firstpay_' . $UserID;
  389. $data = (array)$first;
  390. $data['buytime'] = time();
  391. $data['czReason'] = 1;
  392. $data['cjReason'] = 45;
  393. Redis::set($fpkey, json_encode($data));
  394. DB::table(TableName::agent() . 'guide_payment')->updateOrInsert([
  395. 'UserID' => $UserID,
  396. 'GiftID' => $amount==1000?201:211,
  397. 'CreateTime' => now()
  398. ], ['UserID' => $UserID]);
  399. }
  400. }
  401. dd($sort);
  402. }
  403. public static function decrypt($str){
  404. if (!isset($str)||!$str||empty($str)) {
  405. # code...
  406. return '';
  407. }
  408. $str=implode("+",explode(" ",$str));
  409. try {
  410. $destr=LZ::decompressFromBase64($str);
  411. }catch (\Exception $exception){
  412. Util::WriteLog('gamelz',$str);
  413. TelegramBot::getDefault()->sendProgramNotify("Game LZ decrypt:".$str);
  414. TelegramBot::getDefault()->sendProgramNotify("Game LZ decrypt:", $exception->getMessage().$exception->getTraceAsString());
  415. $destr=$str;
  416. }
  417. return $destr;
  418. }
  419. public function test(Request $request){
  420. // $this->repayFirst();
  421. // $config=RouteService::getChannelConfig($request);
  422. //
  423. // dd($config->toArray());
  424. dd(1);
  425. $countrys=['COL','PER','ARG','ECU','CHL'];
  426. $service = new SmartFastPay();
  427. $country=$request->input('country','');
  428. if(!empty($country)) {
  429. $json = $service->curlGet('https://api.smartfastpay.com/documents-type?country=' . $country);
  430. // 将 JSON 字符串转换为 PHP 数组
  431. $decodedJson = json_decode($json, true);
  432. // 获取 data 部分
  433. $data = $decodedJson['data'] ?? [];
  434. // 传递数据到视图
  435. return view('other.datatable', compact('data', 'country'));
  436. }else{
  437. $datas=[];
  438. foreach ($countrys as $country){
  439. $json = $service->curlGet('https://api.smartfastpay.com/documents-type?country=' . $country);
  440. // 将 JSON 字符串转换为 PHP 数组
  441. $decodedJson = json_decode($json, true);
  442. // 获取 data 部分
  443. $data = $decodedJson['data'] ?? [];
  444. $datas[$country]=$data;
  445. }
  446. // echo json_encode($datas);die;
  447. return view('other.datatables', compact('datas'));
  448. }
  449. // $user = GlobalUserInfo::getGameUserInfoToWeb('UserID',$user_id);
  450. // LoginController::CheckTimeBonus($user);
  451. // $datas = RePayConfig::CacheDatas();
  452. //
  453. // if (isset($datas) && is_array($datas) && count($datas)) {
  454. // $datas = array_filter($datas, function ($v) use ($user) {
  455. // return $user['Score'] < $v['LessThan'];
  456. // });
  457. // }
  458. // dd($user,$datas,date("Y-m-d H:i:s",$user['bonus_pack']['settime']));
  459. //
  460. // dd(Util::validateCpf('47285044171'));
  461. // $newid=AccountsInfo::whereBetween('UserID',[10000,100000])->max('UserID')??10000;
  462. // TelegramBot::getDefault()->sendMsgWithEnv('test123');
  463. // Log::error("test123");
  464. // AgentService::SetUserAgent("5ce7c4e17c-b53b-eb1a-0004581854",4581854,"fw9tdk");
  465. // AgentService::recordPerformance(4581854,100*NumConfig::NUM_VALUE);
  466. // OuroGameService::notifyWebHall(4478930,"",'pay_finish',["Golds"=>1000,"PayNum"=>10]);
  467. // $key='ingame_state_'.$request->input('uid');
  468. // $exist=Redis::exists($key);
  469. // $ingame_state=Redis::get($key)??-1;
  470. //
  471. // exit(json_encode(compact('exist','ingame_state')));
  472. // DB::connection('write')->select("SET NOCOUNT ON use QPRecordDB exec GSP_GP_AddUserLogin $UserID");
  473. /*try {
  474. $str='N4IgRgZgDiBcIAYD2A5KATFAbAqgWQEEBnARgBcAnLAJQBUBRAdQEcQAaEIgSwHMA7OCACmATwBSGLgEkAbFIDWZABJ4AVugDCKVVgAidMQDEAyo0MAWAIoAvABZ50ANQDuAN0byxAIQAKtBFwAMhpiAEwAmowAHiQAWsayUlixAMaB1igajqHoPimq1F4AhnxYtCm0UuaxhjS01mJI6ADM1HyMSmJKjoYojLGhjq4AGhoAnM7UAOJQac2GEQC26OFCWFgkAPJTZEQ4Lq4oSoYIxoaOKEX0bbHD1JdTWGTGfFA+YDhYAKwDKQg4dz4KXkUGajkY6BEsWsCDGUi4zi4YDMqikqiQXBQ1nkX3CixwCG0OBIKFoOJQoXo1jw+JEeGxzk2DGa4R0qk2uhwGX6XCZPAyunoUMW4QQsUWsVU4qkzXF2nC1h4zlZ6ExoRw5lJlmaKC4YjG7BAKUEX1ChoA+uhBIsLWRBCQAOyhBAIB1jZqu0IyL7m8wkULmsYkL6GgCuRUEeCQ1i46yKAHovgA6BAAAgAFIEuHxQ1EANypgh8dAUDHoVMkZoF4x4AC0UzGAA4SF4AJSFqBQLBCRhCMAAaS4ZETzQdSeaMgz/aUtDwgTYqawXHkQlTUyEwKQ7Y0tlLiyE8ZIJBkKdPaajYFjq+MRQgRQoXBHY4nIAAvkA===';
  475. $destr=LZ::decompressFromBase64($str);
  476. // dd($destr);
  477. }catch (\Exception $exception){
  478. TelegramBot::getDefault()->sendProgramNotify("Game LZ decrypt:", $exception->getMessage().$exception->getTraceAsString());
  479. $destr=$str;
  480. }
  481. return $destr;*/
  482. // $pass='$2y$10$THuv5qMoBlCi2uIZLiR7k.7j/ixywIgZ/th49pJKxtkQjBz4mBtlm';
  483. // return json_encode(['res'=>Hash::check('',$pass)]);
  484. /* $users=GlobalUserInfo::where("RegisterDate",'>','2024-06-18')->get();
  485. foreach ($users as $user){
  486. $UserID=$user->UserID;
  487. $startDate=Carbon::parse($user->RegisterDate)->format('Ymd');
  488. $endDate=Carbon::parse($user->LastLogonDate)->format('Ymd');
  489. for($i=$startDate;$i<=$endDate;$i++){
  490. // DB::table('QPRecordDB.dbo.RecordUserLogin')->insert(['UserID'=>$UserID,'DateID'=>$i,'Cnt'=>1]);
  491. }
  492. }*/
  493. }
  494. public function tes11t()
  495. {
  496. $dbh = DB::connection()->getPdo();
  497. $sql="SELECT ID,UserID,ChangeScore
  498. FROM QPRecordDB.dbo.RecordUserScoreChange t
  499. WHERE UpdateTime>'2024-06-05 03:53:12' and UpdateTime<'2024-06-05 09:57:19' and ChangeScore>=1000 and Reason=1 order by UpdateTime";
  500. // echo $sql;die;
  501. $stmt = $dbh->prepare($sql);
  502. $stmt->execute();
  503. $addmoneys = $stmt->fetchAll(\PDO::FETCH_ASSOC);
  504. $asorts=[];
  505. foreach ($addmoneys as $addmoney) {
  506. if(!isset($asorts[$addmoney['UserID']]))$asorts[$addmoney['UserID']]=[];
  507. $asorts[$addmoney['UserID']][]=$addmoney;
  508. }
  509. $orders=Order::whereRaw('id>9978316 and id<9979949 and pay_status=1 and payment_sn is null')->get();
  510. $osorts=[];
  511. foreach ($orders as $order){
  512. if(!isset($osorts[$order->UserID]))$osorts[$order->UserID]=[];
  513. $osorts[$order->UserID][]=(array)$order;
  514. }
  515. $channels=[];
  516. foreach ($osorts as $UserID=>$osort) {
  517. if(isset($asorts[$UserID])){
  518. $asort=$asorts[$UserID];
  519. if(count($asort)>count($osort)){
  520. $ChangeScore=0;
  521. foreach ($asort as $k=>$v){
  522. $ChangeScore+=$v['ChangeScore'];
  523. }
  524. $pay=0;
  525. foreach ($osort as $k=>$v){
  526. $pay+=$order['amount'];
  527. }
  528. $Channel = DB::connection('write')->table(TableName::QPAccountsDB() . 'AccountsInfo')
  529. ->where('UserID', $UserID)->select('Channel', 'RegisterDate')->first();
  530. echo json_encode([$UserID,count($asort),$ChangeScore,count($osort),$pay,($ChangeScore-$pay)/100,$Channel])."\r\n";
  531. if(!isset($channels[$Channel->Channel]))$channels[$Channel->Channel]=['NewPayPeple'=>0,'OldUserPayCount'=>0,'PayPeple'=>0,'PayCount'=>0,'PayTotal'=>0,'OldUserPayBi'=>0,'OldUserPaySum'=>0,'NewPayPepleBi'=>0,'NewPayTotal'=>0];
  532. if(date('Ymd',strtotime($Channel->RegisterDate))!='20240605'){
  533. $channels[$Channel->Channel]['OldUserPayCount']+=count($asort)-1;
  534. }else{
  535. $channels[$Channel->Channel]['NewPayPeple']+=count($asort)-count($osort);
  536. }
  537. $channels[$Channel->Channel]['PayPeple']+=count($asort)-1;
  538. // if(date('Ymd',strtotime($Channel->RegisterDate))!='20240605'){
  539. // $channels[$Channel->Channel]['OldUserPayBi']+=count($asort)-count($osort);
  540. // $channels[$Channel->Channel]['OldUserPaySum']+=($ChangeScore-$pay);
  541. // }else{
  542. // $channels[$Channel->Channel]['NewPayPepleBi']+=count($asort)-count($osort);
  543. // $channels[$Channel->Channel]['NewPayTotal']+=($ChangeScore-$pay);
  544. // }
  545. // $channels[$Channel->Channel]['PayCount']+=count($asort)-count($osort);
  546. // $channels[$Channel->Channel]['PayTotal']+=($ChangeScore-$pay);
  547. // $callback = DB::table(TableName::agent() . 'UserCallBack')->where('UserID', $UserID)->first();
  548. // if($callback)DB::table(TableName::agent() . 'UserCallBack')->where('UserID', $UserID)->decrement('recharge',($ChangeScore-$pay));
  549. // DB::table('QPRecordDB.dbo.RecordUserTotalStatistics')->where('UserID',$UserID)->increment('Recharge',($ChangeScore-$pay)/100);
  550. //
  551. // DB::connection('write')->table('QPRecordDB.dbo.RecordUserScoreStatisticsNew')->where('ScoreType', 1)
  552. // ->where('UserID', $UserID)
  553. // ->where('DateID', 20240605)
  554. // ->decrement('ScoreCount',count($asort)-count($osort));
  555. // DB::connection('write')->table('QPRecordDB.dbo.RecordUserScoreStatisticsNew')->where('ScoreType', 1)
  556. // ->where('UserID', $UserID)
  557. // ->where('DateID', 20240605)
  558. // ->decrement('Score',($ChangeScore-$pay));
  559. $total=$ChangeScore-$pay;
  560. while($total>0){
  561. $arr=array_shift($asort);
  562. $ID=$arr['ID'];
  563. $ChangeScore=$arr['ChangeScore'];
  564. echo $ID."|".$ChangeScore."\r\n";
  565. $total-=$ChangeScore;
  566. // DB::table('QPRecordDB.dbo.RecordUserScoreChange')->where('ID',$ID)->delete();
  567. }
  568. }
  569. }
  570. }
  571. // print_r($channels);
  572. // ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['OldUserPayCount' => DB::raw("OldUserPayCount+$addPayPeple"), 'OldUserPayBi' => DB::raw('OldUserPayBi+1'), 'OldUserPaySum' => DB::raw("OldUserPaySum+$money")]);
  573. // ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['NewPayPeple' => DB::raw("NewPayPeple+$addPayPeple"), 'NewPayPepleBi' => DB::raw('NewPayPepleBi+1'), 'NewPayTotal' => DB::raw("NewPayTotal+$money")]);
  574. // print_r($channels);
  575. // foreach ($channels as $Channel=>$ChannelData){
  576. // DB::connection('write')->table(TableName::QPRecordDB() . 'RecordPlatformData')
  577. // ->where('DateID', '20240605')
  578. // ->where('Channel', -1)->update([
  579. // 'OldUserPayBi'=>DB::raw("OldUserPayBi-$ChannelData[OldUserPayBi]"),
  580. // 'OldUserPaySum'=>DB::raw("OldUserPaySum-$ChannelData[OldUserPaySum]"),
  581. // 'NewPayPepleBi'=>DB::raw("NewPayPepleBi-$ChannelData[NewPayPepleBi]"),
  582. // 'NewPayTotal'=>DB::raw("NewPayTotal-$ChannelData[NewPayTotal]")
  583. // ]);
  584. // DB::connection('write')->table(TableName::QPRecordDB() . 'RecordPlatformData')
  585. // ->where('DateID', '20240605')
  586. // ->where('Channel', $Channel)->update([
  587. // 'OldUserPayBi'=>DB::raw("OldUserPayBi-$ChannelData[OldUserPayBi]"),
  588. // 'OldUserPaySum'=>DB::raw("OldUserPaySum-$ChannelData[OldUserPaySum]"),
  589. // 'NewPayPepleBi'=>DB::raw("NewPayPepleBi-$ChannelData[NewPayPepleBi]"),
  590. // 'NewPayTotal'=>DB::raw("NewPayTotal-$ChannelData[NewPayTotal]")
  591. // ]);
  592. //
  593. // }
  594. foreach ($channels as $Channel=>$ChannelData){
  595. // DB::connection('write')->table(TableName::QPRecordDB() . 'RecordPlatformData')
  596. // ->where('DateID', '20240605')
  597. // ->where('Channel', -1)->update([
  598. // 'NewPayPeple'=>DB::raw("NewPayPeple-$ChannelData[NewPayPeple]"),
  599. // 'OldUserPayCount'=>DB::raw("OldUserPayCount-$ChannelData[OldUserPayCount]"),
  600. // 'PayPeple'=>DB::raw("PayPeple-$ChannelData[PayPeple]"),
  601. // ]);
  602. // DB::connection('write')->table(TableName::QPRecordDB() . 'RecordPlatformData')
  603. // ->where('DateID', '20240605')
  604. // ->where('Channel', $Channel)->update([
  605. // 'NewPayPeple'=>DB::raw("NewPayPeple-$ChannelData[NewPayPeple]"),
  606. // 'OldUserPayCount'=>DB::raw("OldUserPayCount-$ChannelData[OldUserPayCount]"),
  607. // 'PayPeple'=>DB::raw("PayPeple-$ChannelData[PayPeple]"),
  608. // ]);
  609. }
  610. // UPDATE RecordPlatformData SET PayTotal=PayTotal+@Cnt,PayPeple=PayPeple+@PayPeple,PayCount=PayCount+1 WHERE DateID=@DateID AND Channel=-1
  611. //
  612. //
  613. // UPDATE RecordPlatformData SET PayTotal=PayTotal+@Cnt,PayPeple=PayPeple+@PayPeple,PayCount=PayCount+1 WHERE DateID=@DateID AND Channel=@Channel
  614. die;
  615. }
  616. }