2
0

WithDrawInfoController.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. <?php
  2. namespace App\Http\Controllers\Game;
  3. use App\Facade\TableName;
  4. use App\Game\GlobalUserInfo;
  5. use App\Http\helper\NumConfig;
  6. use App\Models\AccountsInfo;
  7. use App\Models\Treasure\GameScoreLocker;
  8. use App\Notification\TelegramBot;
  9. use App\Util;
  10. use App\Utility\SetNXLock;
  11. use GuzzleHttp\Client;
  12. use GuzzleHttp\Exception\RequestException;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Support\Facades\DB;
  15. use Illuminate\Support\Facades\Hash;
  16. use Illuminate\Support\Facades\Log;
  17. use Illuminate\Support\Facades\Validator;
  18. class WithDrawInfoController
  19. {
  20. public function FreeWithDrawInfo(Request $request)
  21. {
  22. $user = $request->user();
  23. $userScoreData = GlobalUserInfo::getScoreDataByUserID($user->UserID);
  24. if(!$userScoreData['Recharge']){
  25. $totalWithdraw = max($userScoreData['InsureScore'],40);
  26. if($userScoreData['InsureScore']<40){
  27. //第一种状态,我免费领了10块钱,但是金额不足40,点进去页面填信息后点击提现,提示我去玩游戏
  28. return apiReturnSuc(['state' => 1, 'total' => $totalWithdraw,'InsureScore' => $userScoreData['InsureScore']]);
  29. }else{
  30. //第二种状态,我免费金额足够40,提现按钮会点亮,告知用户点击进去
  31. return apiReturnSuc(['state' => 2, 'total' => $totalWithdraw,'InsureScore' => $userScoreData['InsureScore']]);
  32. }
  33. }else{
  34. //第四种状态,VIP状态下,金额不足了,进度条颜色红色,按钮灰色(不可点击),次日整个消失
  35. if($userScoreData['InsureScore']<10){
  36. return apiReturnSuc(['state' => 4, 'total' => max($userScoreData['InsureScore'],40),'InsureScore' => max($userScoreData['InsureScore'],40)]);
  37. }else{
  38. //第三种状态,进去完成了充值未提现,提现按钮会高光,引导用户完成提现
  39. return apiReturnSuc(['state' => 3, 'total' => max($userScoreData['InsureScore'],40),'InsureScore' => max($userScoreData['InsureScore'],40)]);
  40. }
  41. }
  42. }
  43. public function WithDrawRecord(Request $request)
  44. {
  45. $user = $request->user();
  46. $UserID=$user->UserID;
  47. // $paypass = $request->input('paypass');
  48. // if (!empty($user->InsurePass)&&!Hash::check($paypass,$user->InsurePass)) {
  49. // return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  50. // }
  51. $list=DB::table('QPAccountsDB.dbo.OrderWithDraw')
  52. ->where('UserID', $UserID)
  53. ->selectRaw("CreateDate,OrderId,[State],WithDraw,ServiceFee,PixType")
  54. ->paginate(10);
  55. return apiReturnSuc($list);
  56. }
  57. public function GetWithDrawBaseInfo(Request $request)
  58. {
  59. $user = $request->user();
  60. $UserID=$user->UserID;
  61. // $paypass = $request->input('paypass');
  62. //
  63. // if (empty($user->InsurePass)||!Hash::check($paypass,$user->InsurePass)) {
  64. // return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  65. // }
  66. $dbh = DB::connection()->getPdo();
  67. $sql="DECLARE @return_value int
  68. set nocount on use QPAccountsDB
  69. EXEC @return_value = GSP_GR_GetWithDrawBaseInfo '$UserID'
  70. SELECT 'ReturnValue' = @return_value";
  71. // echo $sql;die;
  72. $stmt = $dbh->prepare($sql);
  73. $stmt->execute();
  74. $retval = $stmt->fetch(\PDO::FETCH_ASSOC);
  75. $retval['srate']=env('CONFIG_24680_RATE',1);
  76. return apiReturnSuc($retval);
  77. }
  78. public function GoWithDraw(Request $request)
  79. {
  80. $user = $request->user();
  81. $UserID=$user->UserID;
  82. // $paypass = $request->input('paypass');
  83. //
  84. // if (empty($user->InsurePass)||!Hash::check($paypass,$user->InsurePass)) {
  85. // return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  86. // }
  87. $score=$request->input('score',0);
  88. if(!$score||is_float($score)||$score<=0){
  89. return apiReturnFail(['web.withdraw.score_fail', 'Amount must be an integer value.']);
  90. }
  91. $redisKey = 'withdraw_'.$UserID;
  92. if (!SetNXLock::getExclusiveLock($redisKey)) {
  93. return apiReturnFail(['web.withdraw.try_again_later','Tente novamente mais tarde']);
  94. }
  95. GameScoreLocker::where('UserID',$UserID)->delete();
  96. $dbh = DB::connection()->getPdo();
  97. // $score=$score*NumConfig::NUM_VALUE;
  98. $sql="DECLARE @return_value int
  99. set nocount on use QPAccountsDB
  100. EXEC @return_value = GSP_GR_GetWithDraw '$UserID','$score'
  101. SELECT 'ReturnValue' = @return_value";
  102. // echo $sql;die;
  103. $stmt = $dbh->prepare($sql);
  104. $stmt->execute();
  105. SetNXLock::release($redisKey);
  106. $retval = $stmt->fetch(\PDO::FETCH_ASSOC);
  107. try {
  108. // set @ret = 1 --可提额度不足
  109. // set @ret = 2 --低于最低可提现金额
  110. // set @ret = 3 --高于最高可提现金额
  111. // set @ret = 4 --超过每天提现次数上限
  112. // set @ret = 5 --身上钱不够
  113. // set @ret = 6 --开在游戏里面
  114. // set @ret = 7 --未充值的用户TX额度
  115. if (isset($retval['ReturnValue'])) {
  116. $ReturnValue = $retval['ReturnValue'];
  117. // set @ret = 1 -- Insufficient withdrawal amount
  118. // set @ret = 2 -- Lower than the minimum withdrawal amount
  119. // set @ret = 3 -- Higher than the maximum withdrawal amount
  120. // set @ret = 4 -- Exceeded the daily withdrawal limit
  121. // set @ret = 5 -- Not enough money on hand
  122. // set @ret = 6 -- Opened in the game
  123. // set @ret = 7 -- Undeposited user TX amount
  124. $errors = [
  125. [],
  126. ['web.withdraw.no_withdraw_value', "The withdrawable amount is not enough"],
  127. ['web.withdraw.too_low', 'Lower than the minimum withdrawal amount'],
  128. ['web.withdraw.too_high', 'Higher than the maximum withdrawal amount'],
  129. ['web.withdraw.day_max', 'Exceeded the daily withdrawal limit'],
  130. ['web.withdraw.no_enouth_score', 'Not enough money on hand'],
  131. ['web.withdraw.in_game', 'Sorry, You\'re in game for now'],
  132. ['web.withdraw.no_deposit', ' You need deposit first!'],
  133. ];
  134. return apiReturnFail($errors[$ReturnValue], [], $ReturnValue == 7 ? 777 : 301);
  135. }else{
  136. return apiReturnSuc($retval);
  137. }
  138. }catch (\Exception $e){
  139. TelegramBot::getDefault()->sendProgramNotify("WithDraw Error:", var_export($retval,true).':'.$e->getTraceAsString());
  140. return apiReturnSuc($retval);
  141. }
  142. }
  143. public function saveCpf(Request $request)
  144. {
  145. // $user = $request->user();
  146. // $UserID=$user->UserID;
  147. //
  148. // $account = $request->Account ?: '';
  149. // $phone = $request->Phone ?: '';
  150. // $email = $request->Email ?: '';
  151. // $PixNum = $request->PixNum ?: '';
  152. //
  153. // if(!Util::validateCpf($PixNum)){
  154. // return apiReturnFail(['withdraw.account.tip.cpf_error','Cpf error format']);
  155. // }
  156. //
  157. // $redisKey = 'Api_updateAccountsPayInfo_'.$UserID;
  158. // $lock = SetNXLock::getExclusiveLock($redisKey);
  159. // if (!$lock) {
  160. // return apiReturnFail(['web.withdraw.try_again_later','Tente novamente mais tarde']);
  161. // }
  162. // $exist = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')->where('UserID', $UserID)->first();
  163. //
  164. // if ($exist) {
  165. // DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')->where('UserID', $UserID)->update(['PixNum' => $PixNum]);
  166. // } else {
  167. //
  168. // $data = ['BankUserName' => $account, 'PhoneNumber' => $phone, 'EmailAddress' => $email, 'UserID' => $UserID, 'PixNum' => $PixNum, 'Achieves' => '', 'HistoryWithDraw' => 0];
  169. // DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  170. // ->insert($data);
  171. // }
  172. // SetNXLock::release($redisKey);
  173. return apiReturnSuc();
  174. }
  175. public function MexWithDrawInfo(Request $request)
  176. {
  177. $user = $request->user();
  178. $UserID=$user->UserID;
  179. $paypass = $request->input('paypass');
  180. $PixType = $request->input('cbPixType');;
  181. $BankNO = $request->input('account');
  182. $AccountsBank = $request->input('account');
  183. $BankUserName = $request->input('userName');
  184. $PhoneNumber = $request->input('phone');
  185. $EmailAddress = $request->input('email');
  186. $IFSCNumber = $request->input('IFSCNumber');
  187. // $PANNumber = $request->input('PAN');
  188. // $AdhaarNumber = $request->input('adhaar');
  189. // $BranchBank = $request->input('branceBank');
  190. $BranchBank = $request->input('bank');//银行编号
  191. $PixNum = $request->input('account');
  192. Util::WriteLog("mexwithdraw",$request->all());
  193. if(isset($EmailAddress)&&!empty($EmailAddress)){
  194. $validator = Validator::make(
  195. ['email' => $EmailAddress],
  196. ['email' => 'required|email']
  197. );
  198. if ($validator->fails()) {
  199. return apiReturnFail(['web.user.email_fail','Wrong email format']);
  200. }
  201. }
  202. if (!$AccountsBank || $AccountsBank == 'undefined') {
  203. return apiReturnFail(['web.bank.account_empty', 'The bank account cannot be empty']);
  204. }
  205. if (!(strlen($AccountsBank) == 16 || strlen($AccountsBank) == 18)) {
  206. return apiReturnFail(['web.bank.account_invalid_length', 'The bank number must have 16 or 18 digits']);
  207. }
  208. if (!(strlen($IFSCNumber) == 18 && $IFSCNumber)) {
  209. return apiReturnFail(['web.bank.clabe_invalid_length', 'The Clabe number must have 18 digits']);
  210. }
  211. if (!$BankUserName || $BankUserName == 'undefined') {
  212. return apiReturnFail(['web.bank.username_empty', 'The name cannot be empty']);
  213. }
  214. if (!$BranchBank || $BranchBank == 'undefined') {
  215. return apiReturnFail(['web.bank.branch_empty', 'The branch code cannot be empty']);
  216. }
  217. if (strlen($AccountsBank) == 16) {
  218. $PixType = 2;
  219. }
  220. if (strlen($AccountsBank) == 18) {
  221. $PixType = 1;
  222. }
  223. $redisKey = 'withDrawInfo_withDrawInfo_' . $UserID;
  224. if (!SetNXLock::getExclusiveLock($redisKey)) {
  225. return apiReturnFail(['web.bank.try_again_later', 'Please try again later']);
  226. }
  227. if (!$UserID) {
  228. Log::info('miss UserID', $request->all());
  229. SetNXLock::release($redisKey);
  230. return apiReturnFail(['web.bank.missing_userid', 'params error']);
  231. }
  232. if (empty($PixType)) {
  233. SetNXLock::release($redisKey);
  234. return apiReturnFail(['web.bank.pix_type_missing', 'The PIX type is missing']);
  235. }
  236. // 验证PixNum绑定次数
  237. if (!empty($PixNum)) {
  238. $BindCount = DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  239. ->where('BankCard', $PixNum)
  240. ->lock('WITH(NOLOCK)')
  241. ->count();
  242. if ($BindCount >= 3) {
  243. SetNXLock::release($redisKey);
  244. return apiReturnFail(['web.bank.cpf_used_multiple_times', 'The CPF number has been used multiple times and cannot be saved'], [], 302);
  245. }
  246. }
  247. // 验证玩家信息
  248. if (!empty($user->InsurePass)&&!Hash::check($paypass,$user->InsurePass)) {
  249. return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  250. }
  251. if ($PixType < 10 && false) {
  252. $data = compact('PixType', 'BankUserName', 'PhoneNumber', 'EmailAddress', 'PixNum');
  253. } else {
  254. $data = compact('PixType', 'BankUserName','IFSCNumber', 'PhoneNumber', 'EmailAddress','BankNO', 'AccountsBank','BranchBank','PixNum');
  255. $PixNum = $BankNO;
  256. }
  257. foreach ($data as $key => &$val) {
  258. $data[$key] = trim($val);
  259. }
  260. unset($val);
  261. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  262. ->lock('WITH(NOLOCK)')
  263. ->where('UserID', $UserID)
  264. ->first();
  265. if (!$AccountWithDrawInfo) {
  266. $data['UserID'] = $UserID;
  267. $data['Achieves'] = 0;
  268. $data['HistoryWithDraw'] = 0;
  269. try {
  270. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  271. ->where('UserID', $UserID)
  272. ->insert($data);
  273. } catch (\Exception $e) {
  274. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  275. }
  276. } else {
  277. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  278. ->where('UserID', $UserID)
  279. ->update($data);
  280. }
  281. // 添加绑定记录
  282. if (empty($AccountWithDrawInfo->PixNum) || $AccountWithDrawInfo->PixNum != $PixNum) {
  283. try {
  284. DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  285. ->insert([
  286. 'UserID' => $UserID,
  287. 'BankCard' => $PixNum ?: '',
  288. 'BindDate' => now()
  289. ]);
  290. } catch (\Exception $e) {
  291. Log::error('insert RecordBankCardBind failed', ['data' => $data]);
  292. }
  293. }
  294. SetNXLock::release($redisKey);
  295. return apiReturnSuc();
  296. }
  297. public function RuWithDrawInfo(Request $request)
  298. {
  299. $user = $request->user();
  300. $UserID=$user->UserID;
  301. $paypass = $request->input('paypass');
  302. $PixType = $request->input('PixType');;
  303. $BankNO = $request->input('account');
  304. $BankUserName = $request->input('userName');
  305. $PhoneNumber = $request->input('phone');
  306. // $EmailAddress = $request->input('email');
  307. // $IFSCNumber = $request->input('IFSCNumber');
  308. // $PANNumber = $request->input('PAN');
  309. // $AdhaarNumber = $request->input('adhaar');
  310. // $BranchBank = $request->input('branceBank');
  311. $BranchBank = $request->input('bank');//银行编号
  312. $PixNum = $BankNO;
  313. $AccountsBank = $BankNO;
  314. Util::WriteLog("ruwithdraw",$request->all());
  315. if (!$BankUserName || $BankUserName == 'undefined') {
  316. return apiReturnFail(['web.bank.username_empty', 'The name cannot be empty']);
  317. }
  318. if($PixType==1) {
  319. if (!$AccountsBank || $AccountsBank == 'undefined') {
  320. return apiReturnFail(['web.bank.account_empty', 'The bank account cannot be empty']);
  321. }
  322. if (!(strlen($AccountsBank) == 16 )) {
  323. return apiReturnFail(['web.bank.account_invalid_length', 'The bank number must have 16 digits']);
  324. }
  325. // if (!(strlen($IFSCNumber) == 11 && $IFSCNumber)) {
  326. // return apiReturnFail(['web.bank.clabe_invalid_length', 'The Clabe number must have 18 digits']);
  327. // }
  328. }else{
  329. // 墨西哥 +52 手机号 10 位(可带区号总长 12 位);其他地区 11 位
  330. $digits = preg_replace('/\D/', '', $PhoneNumber ?? '');
  331. $isMexico = (env('COUNTRY_CODE', '52') === '52');
  332. $valid = $isMexico
  333. ? (strlen($digits) === 10 || strlen($digits) === 12)
  334. : (strlen($digits) === 11);
  335. if (!$PhoneNumber || !$valid) {
  336. return apiReturnFail(['withdraw.account.tip.phone_error', $isMexico ? 'The phone number must be 10 digits (Mexico)' : 'The phone number is error']);
  337. }
  338. if (!$BranchBank || $BranchBank == 'undefined') {
  339. return apiReturnFail(['web.bank.branch_empty', 'The branch code cannot be empty']);
  340. }
  341. }
  342. $redisKey = 'withDrawInfo_withDrawInfo_' . $UserID;
  343. if (!SetNXLock::getExclusiveLock($redisKey)) {
  344. return apiReturnFail(['web.bank.try_again_later', 'Please try again later']);
  345. }
  346. if (!$UserID) {
  347. Log::info('miss UserID', $request->all());
  348. SetNXLock::release($redisKey);
  349. return apiReturnFail(['web.bank.missing_userid', 'params error']);
  350. }
  351. if (empty($PixType)) {
  352. SetNXLock::release($redisKey);
  353. return apiReturnFail(['web.bank.pix_type_missing', 'The PIX type is missing']);
  354. }
  355. // 验证PixNum绑定次数
  356. if (!empty($PixNum)) {
  357. $BindCount = DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  358. ->where('BankCard', $PixNum)
  359. ->lock('WITH(NOLOCK)')
  360. ->count();
  361. if ($BindCount >= 3) {
  362. SetNXLock::release($redisKey);
  363. return apiReturnFail(['web.bank.cpf_used_multiple_times', 'The CPF number has been used multiple times and cannot be saved'], [], 302);
  364. }
  365. }
  366. // 验证玩家信息
  367. if (!empty($user->InsurePass)&&!Hash::check($paypass,$user->InsurePass)) {
  368. return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  369. }
  370. $data = compact('PixType', 'BankUserName', 'PhoneNumber','BankNO', 'AccountsBank','BranchBank','PixNum');
  371. $PixNum = $BankNO;
  372. foreach ($data as $key => &$val) {
  373. $data[$key] = trim($val);
  374. }
  375. unset($val);
  376. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  377. ->lock('WITH(NOLOCK)')
  378. ->where('UserID', $UserID)
  379. ->first();
  380. if (!$AccountWithDrawInfo) {
  381. $data['UserID'] = $UserID;
  382. $data['Achieves'] = 0;
  383. $data['HistoryWithDraw'] = 0;
  384. try {
  385. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  386. ->where('UserID', $UserID)
  387. ->insert($data);
  388. } catch (\Exception $e) {
  389. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  390. }
  391. } else {
  392. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  393. ->where('UserID', $UserID)
  394. ->update($data);
  395. }
  396. // 添加绑定记录
  397. if (empty($AccountWithDrawInfo->PixNum) || $AccountWithDrawInfo->PixNum != $PixNum) {
  398. try {
  399. DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  400. ->insert([
  401. 'UserID' => $UserID,
  402. 'BankCard' => $PixNum ?: '',
  403. 'BindDate' => now()
  404. ]);
  405. } catch (\Exception $e) {
  406. Log::error('insert RecordBankCardBind failed', ['data' => $data]);
  407. }
  408. }
  409. SetNXLock::release($redisKey);
  410. return apiReturnSuc();
  411. }
  412. public function withDrawInfo(Request $request)
  413. {
  414. // return apiReturnFail('params error');
  415. $user = $request->user();
  416. $UserID=$user->UserID;
  417. // $UserID = (int)$request->globalUser->UserID;//$request->input('UserID');
  418. // $RequestDynamicPass = $request->input('DynamicPass');
  419. $PixType = $request->input('cbPixType');
  420. $BankUserName = urldecode($request->input('userName'));
  421. $EmailAddress = $request->input('email');
  422. $PixNum = $request->input('PixNum');
  423. if(!empty($EmailAddress))$EmailAddress=Util::cleanEmptyString($EmailAddress);
  424. if(!empty($PixNum))$PixNum=Util::cleanEmptyString($PixNum);
  425. if (!empty($EmailAddress)&&!Util::validateEmail($EmailAddress)) {
  426. return apiReturnFail(['web.user.email_fail','Wrong email format']);
  427. }
  428. $redisKey = 'withDrawInfo_withDrawInfo_'.$UserID;
  429. if (!SetNXLock::getExclusiveLock($redisKey)) {
  430. Util::WriteLog("withdrawInfo",[1, $request->all()]);
  431. return apiReturnFail(['web.withdraw.try_again_later','Tente novamente mais tarde']);
  432. }
  433. if (!$UserID) {
  434. Util::WriteLog("withdrawInfo",[2, $request->all()]);
  435. Log::info('miss UserID', $request->all());
  436. SetNXLock::release($redisKey);
  437. return apiReturnFail(['web.withdraw.params_error','params error']);
  438. }
  439. if (empty($PixType)) {
  440. Util::WriteLog("withdrawInfo",[3, $request->all()]);
  441. SetNXLock::release($redisKey);
  442. return apiReturnFail(["web.withdraw.pix_type_missing",'O tipo PIX está ausente']);
  443. }
  444. // 验证PixNum绑定次数
  445. // if (!empty($PixNum)) {
  446. // $BindCount = DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  447. // ->where('BankCard', $PixNum)
  448. // ->lock('WITH(NOLOCK)')
  449. // ->count();
  450. // if ($BindCount >= 6) {
  451. // Util::WriteLog("withdrawInfo",[4, $request->all()]);
  452. // SetNXLock::release($redisKey);
  453. // return apiReturnFail(['web.withdraw.cpf_number_used','O número do CPF foi usado várias vezes e não pode ser salvo'], [], 302);
  454. // }
  455. // }
  456. if ($PixType==1) {
  457. // 验证 cashapp
  458. if (!empty($PixNum)) {
  459. // 如果 PixNum 第一个字符不是 "$",则在前面添加 "$"
  460. if (substr($PixNum, 0, 1) !== '$') {
  461. $PixNum = '$' . $PixNum;
  462. }
  463. // 构建 cash.app URL
  464. $cashAppUrl = 'https://cash.app/' . $PixNum;
  465. try {
  466. // 使用 stream context 来获取 HTTP 响应头
  467. $context = stream_context_create([
  468. 'http' => [
  469. 'method' => 'GET',
  470. 'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\r\n",
  471. 'ignore_errors' => true
  472. ]
  473. ]);
  474. $htmlContent = @file_get_contents($cashAppUrl, false, $context);
  475. // 检查 HTTP 响应头中的状态码
  476. if ($htmlContent === false || (isset($http_response_header) && preg_match('/HTTP\/\d\.\d\s+404/', implode("\n", $http_response_header)))) {
  477. Util::WriteLog("withdrawInfo", [5, $request->all(), 'Invalid cashapp: ' . $PixNum]);
  478. SetNXLock::release($redisKey);
  479. return apiReturnFail(['web.withdraw.invalid_cashapp', 'Invalid CashApp account']);
  480. }
  481. if ($htmlContent !== false) {
  482. // 去除空格换行,转换成一行字符串
  483. $htmlContent = preg_replace('/\s+/', '', $htmlContent);
  484. Util::WriteLog("withdrawInfo", [5, $request->all(), 'CashApp verification response: ' . $htmlContent]);
  485. // 检查响应内容中是否包含 "404 Not Found"
  486. if (stripos($htmlContent, '404NotFound') !== false) {
  487. Util::WriteLog("withdrawInfo", [5, $request->all(), 'Invalid cashapp: ' . $PixNum]);
  488. SetNXLock::release($redisKey);
  489. return apiReturnFail(['web.withdraw.invalid_cashapp', 'Invalid CashApp account']);
  490. }
  491. }
  492. } catch (\Exception $e) {
  493. // 其他异常也记录日志但不阻止流程
  494. Util::WriteLog("withdrawInfo", [5, $request->all(), 'CashApp verification error: ' . $e->getMessage()]);
  495. }
  496. }
  497. $data = compact('PixType', 'BankUserName', 'PixNum');
  498. } else {
  499. $data = compact('PixType', 'EmailAddress');
  500. }
  501. foreach ($data as $key => &$val) {
  502. $data[$key] = trim($val);
  503. }
  504. unset($val);
  505. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  506. ->lock('WITH(NOLOCK)')
  507. ->where('UserID', $UserID)
  508. ->first();
  509. if (!$AccountWithDrawInfo) {
  510. $data['UserID'] = $UserID;
  511. $data['Achieves'] = 0;
  512. $data['HistoryWithDraw'] = 0;
  513. try {
  514. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  515. ->where('UserID', $UserID)
  516. ->insert($data);
  517. } catch (\Exception $e) {
  518. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  519. Util::WriteLog("withdrawInfo",[6, $request->all(),$data]);
  520. }
  521. } else {
  522. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  523. ->where('UserID', $UserID)
  524. ->update($data);
  525. }
  526. SetNXLock::release($redisKey);
  527. return apiReturnSuc();
  528. }
  529. public function withDrawInfoSA(Request $request)
  530. {
  531. // return apiReturnFail('params error');
  532. $UserID = $request->input('UserID');
  533. $RequestDynamicPass = $request->input('DynamicPass');
  534. $PixType = $request->input('cbPixType');
  535. $BankNO = $request->input('bank');
  536. $AccountsBank = urldecode($request->input('account'));
  537. $BankUserName = urldecode($request->input('userName'));
  538. // 原始代码
  539. $BankUserName = Util::filterNickName($BankUserName);
  540. // 新增处理:在大写字母前加空格
  541. $BankUserName = preg_replace('/(?<!^)([A-Z])/', ' $1', $BankUserName);
  542. $PhoneNumber = $request->input('phone');
  543. $EmailAddress = $request->input('email');
  544. $IFSCNumber = $request->input('IFSC');
  545. $PANNumber = $request->input('PAN');
  546. $AdhaarNumber = $request->input('adhaar');
  547. $BranchBank = $request->input('branceBank');
  548. $PixNum = $request->input('PixNum');
  549. $redisKey = 'withDrawInfo_withDrawInfo_'.$UserID;
  550. if (!SetNXLock::getExclusiveLock($redisKey)) {
  551. Util::WriteLog("withdrawInfo",[1, $request->all()]);
  552. return apiReturnFail('Tente novamente mais tarde');
  553. }
  554. if (!$UserID) {
  555. Util::WriteLog("withdrawInfo",[2, $request->all()]);
  556. Log::info('miss UserID', $request->all());
  557. SetNXLock::release($redisKey);
  558. return apiReturnFail('params error');
  559. }
  560. if (empty($PixType)) {
  561. Util::WriteLog("withdrawInfo",[3, $request->all()]);
  562. SetNXLock::release($redisKey);
  563. return apiReturnFail('O tipo PIX está ausente');
  564. }
  565. // Util::validateSouthAmericanPhone('',)
  566. // 验证PixNum绑定次数
  567. if (!empty($PixNum)) {
  568. $BindCount = DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  569. ->where('BankCard', $PixNum)
  570. ->lock('WITH(NOLOCK)')
  571. ->count();
  572. if ($BindCount >= 8) {
  573. Util::WriteLog("withdrawInfo",[4, $request->all()]);
  574. SetNXLock::release($redisKey);
  575. return apiReturnFail(['web.withdraw.cpf_number_used','The CPF number has been used several times and cannot be saved'], [], 302);
  576. }
  577. }
  578. // if(!is_numeric($PixNum)){
  579. // return apiReturnFail(['web.withdraw.pix_failed','The CPF number has been used several times and cannot be saved'], [], 302);
  580. // }
  581. // 验证玩家信息
  582. $DynamicPass = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  583. ->where('UserID', $UserID)
  584. ->lock('WITH(NOLOCK)')
  585. ->value('DynamicPass');
  586. if ($DynamicPass != $RequestDynamicPass || empty($DynamicPass)) {
  587. SetNXLock::release($redisKey);
  588. Util::WriteLog("withdrawInfo",[5, $request->all()]);
  589. return apiReturnFail('As informações do jogador são inconsistentes');
  590. }
  591. $data = compact('PixType', 'BankUserName', 'PhoneNumber', 'EmailAddress', 'PixNum','BankNO', 'AccountsBank', 'IFSCNumber', 'PANNumber', 'AdhaarNumber', 'BranchBank');
  592. foreach ($data as $key => &$val) {
  593. $data[$key] = trim($val);
  594. }
  595. unset($val);
  596. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  597. ->lock('WITH(NOLOCK)')
  598. ->where('UserID', $UserID)
  599. ->first();
  600. if (!$AccountWithDrawInfo) {
  601. $data['UserID'] = $UserID;
  602. $data['Achieves'] = 0;
  603. $data['HistoryWithDraw'] = 0;
  604. try {
  605. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  606. ->where('UserID', $UserID)
  607. ->insert($data);
  608. } catch (\Exception $e) {
  609. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  610. Util::WriteLog("withdrawInfo",[6, $request->all(),$data]);
  611. }
  612. } else {
  613. $data = array_filter($data, function ($value) {
  614. return !is_null($value) && $value !== '';
  615. });
  616. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  617. ->where('UserID', $UserID)
  618. ->update($data);
  619. }
  620. // 添加绑定记录
  621. if (empty($AccountWithDrawInfo->PixNum) || $AccountWithDrawInfo->PixNum != $PixNum) {
  622. try {
  623. if(!DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')->where('UserID', $UserID)->exists()&&is_numeric($PixNum)) {
  624. DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  625. ->insert([
  626. 'UserID' => $UserID,
  627. 'BankCard' => $PixNum ?? '',
  628. 'BindDate' => now()
  629. ]);
  630. Util::WriteLog('update_pix', [
  631. 'UserID' => $UserID,
  632. 'BankCard' => $PixNum ?? '',
  633. 'BindDate' => now()
  634. ]);
  635. }
  636. } catch (\Exception $e) {
  637. Log::error('insert RecordBankCardBind failed', ['data' => $data]);
  638. Util::WriteLog("withdrawInfo",[7, $request->all(),$data]);
  639. }
  640. }
  641. SetNXLock::release($redisKey);
  642. return apiReturnSuc();
  643. }
  644. public function kycSimpleEU(Request $request)
  645. {
  646. // return apiReturnFail('params error');
  647. $user = $request->user();
  648. $UserID=$user->UserID;
  649. $firstName = Util::filterNickName(urldecode($request->input('firstName')));
  650. $lastName = Util::filterNickName(urldecode($request->input('lastName')));
  651. // 原始代码
  652. $BankUserName = $firstName.'|'.$lastName;
  653. $PhoneNumber = $request->input('phone');
  654. $EmailAddress = $request->input('email');
  655. Util::WriteLog("kyc_eu",$request->all());
  656. if(isset($EmailAddress)&&!empty($EmailAddress)){
  657. $validator = Validator::make(
  658. ['email' => $EmailAddress],
  659. ['email' => 'required|email']
  660. );
  661. if ($validator->fails()) {
  662. return apiReturnFail(['web.user.email_fail','Wrong email format']);
  663. }
  664. }
  665. if (!$BankUserName || $BankUserName == 'undefined') {
  666. return apiReturnFail(['web.bank.username_empty', 'The name cannot be empty']);
  667. }
  668. $redisKey = 'withDrawInfo_withDrawInfo_' . $UserID;
  669. if (!SetNXLock::getExclusiveLock($redisKey)) {
  670. return apiReturnFail(['web.bank.try_again_later', 'Please try again later']);
  671. }
  672. if (!$UserID) {
  673. Log::info('miss UserID', $request->all());
  674. SetNXLock::release($redisKey);
  675. return apiReturnFail(['web.bank.missing_userid', 'params error']);
  676. }
  677. $data = compact('BankUserName', 'PhoneNumber', 'EmailAddress');
  678. foreach ($data as $key => &$val) {
  679. $data[$key] = trim($val);
  680. if(empty($val))unset($data[$key]);
  681. }
  682. unset($val);
  683. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  684. ->lock('WITH(NOLOCK)')
  685. ->where('UserID', $UserID)
  686. ->first();
  687. if (!$AccountWithDrawInfo) {
  688. $data['UserID'] = $UserID;
  689. $data['Achieves'] = 0;
  690. $data['HistoryWithDraw'] = 0;
  691. try {
  692. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  693. ->where('UserID', $UserID)
  694. ->insert($data);
  695. } catch (\Exception $e) {
  696. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  697. }
  698. } else {
  699. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  700. ->where('UserID', $UserID)
  701. ->update($data);
  702. }
  703. SetNXLock::release($redisKey);
  704. return apiReturnSuc();
  705. }
  706. public function withDrawInfoEU(Request $request)
  707. {
  708. // return apiReturnFail('params error');
  709. $user = $request->user();
  710. $UserID=$user->UserID;
  711. // $UserID = $request->input('UserID');
  712. // $RequestDynamicPass = $request->input('DynamicPass');
  713. $PixType = $request->input('cbPixType');
  714. $firstName = Util::filterNickName(urldecode($request->input('firstName')));
  715. $lastName = Util::filterNickName(urldecode($request->input('lastName')));
  716. // 原始代码
  717. $BankUserName = $firstName.'|'.$lastName;
  718. $BankNO = $request->input('account');
  719. $AccountsBank = $request->input('account');
  720. $PhoneNumber = $request->input('phone');
  721. $EmailAddress = $request->input('email');
  722. $IFSCNumber = $request->input('IFSCNumber');
  723. $BranchBank = $request->input('bank');//银行编号
  724. $PixNum = $request->input('account');
  725. Util::WriteLog("euwithdraw",$request->all());
  726. if(isset($EmailAddress)&&!empty($EmailAddress)){
  727. $validator = Validator::make(
  728. ['email' => $EmailAddress],
  729. ['email' => 'required|email']
  730. );
  731. if ($validator->fails()) {
  732. return apiReturnFail(['web.user.email_fail','Wrong email format']);
  733. }
  734. }
  735. if (!$AccountsBank || $AccountsBank == 'undefined') {
  736. return apiReturnFail(['web.bank.account_empty', 'The bank account cannot be empty']);
  737. }
  738. if (!(strlen($AccountsBank) == 16 || strlen($AccountsBank) == 18)) {
  739. return apiReturnFail(['web.bank.account_invalid_length', 'The bank number must have 16 or 18 digits']);
  740. }
  741. if (!(strlen($IFSCNumber) == 18 && $IFSCNumber)) {
  742. return apiReturnFail(['web.bank.clabe_invalid_length', 'The Clabe number must have 18 digits']);
  743. }
  744. if (!$BankUserName || $BankUserName == 'undefined') {
  745. return apiReturnFail(['web.bank.username_empty', 'The name cannot be empty']);
  746. }
  747. if (!$BranchBank || $BranchBank == 'undefined') {
  748. return apiReturnFail(['web.bank.branch_empty', 'The branch code cannot be empty']);
  749. }
  750. if (strlen($AccountsBank) == 16) {
  751. $PixType = 2;
  752. }
  753. if (strlen($AccountsBank) == 18) {
  754. $PixType = 1;
  755. }
  756. $redisKey = 'withDrawInfo_withDrawInfo_' . $UserID;
  757. if (!SetNXLock::getExclusiveLock($redisKey)) {
  758. return apiReturnFail(['web.bank.try_again_later', 'Please try again later']);
  759. }
  760. if (!$UserID) {
  761. Log::info('miss UserID', $request->all());
  762. SetNXLock::release($redisKey);
  763. return apiReturnFail(['web.bank.missing_userid', 'params error']);
  764. }
  765. if (empty($PixType)) {
  766. SetNXLock::release($redisKey);
  767. return apiReturnFail(['web.bank.pix_type_missing', 'The PIX type is missing']);
  768. }
  769. // 验证PixNum绑定次数
  770. if (!empty($PixNum)) {
  771. $BindCount = DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  772. ->where('BankCard', $PixNum)
  773. ->lock('WITH(NOLOCK)')
  774. ->count();
  775. if ($BindCount >= 3) {
  776. SetNXLock::release($redisKey);
  777. return apiReturnFail(['web.bank.cpf_used_multiple_times', 'The CPF number has been used multiple times and cannot be saved'], [], 302);
  778. }
  779. }
  780. // 验证玩家信息
  781. if (!empty($user->InsurePass)&&!Hash::check($paypass,$user->InsurePass)) {
  782. return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  783. }
  784. if ($PixType < 10 && false) {
  785. $data = compact('PixType', 'BankUserName', 'PhoneNumber', 'EmailAddress', 'PixNum');
  786. } else {
  787. $data = compact('PixType', 'BankUserName','IFSCNumber', 'PhoneNumber', 'EmailAddress','BankNO', 'AccountsBank','BranchBank','PixNum');
  788. $PixNum = $BankNO;
  789. }
  790. foreach ($data as $key => &$val) {
  791. $data[$key] = trim($val);
  792. }
  793. unset($val);
  794. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  795. ->lock('WITH(NOLOCK)')
  796. ->where('UserID', $UserID)
  797. ->first();
  798. if (!$AccountWithDrawInfo) {
  799. $data['UserID'] = $UserID;
  800. $data['Achieves'] = 0;
  801. $data['HistoryWithDraw'] = 0;
  802. try {
  803. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  804. ->where('UserID', $UserID)
  805. ->insert($data);
  806. } catch (\Exception $e) {
  807. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  808. }
  809. } else {
  810. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  811. ->where('UserID', $UserID)
  812. ->update($data);
  813. }
  814. // 添加绑定记录
  815. if (empty($AccountWithDrawInfo->PixNum) || $AccountWithDrawInfo->PixNum != $PixNum) {
  816. try {
  817. DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  818. ->insert([
  819. 'UserID' => $UserID,
  820. 'BankCard' => $PixNum ?: '',
  821. 'BindDate' => now()
  822. ]);
  823. } catch (\Exception $e) {
  824. Log::error('insert RecordBankCardBind failed', ['data' => $data]);
  825. }
  826. }
  827. SetNXLock::release($redisKey);
  828. return apiReturnSuc();
  829. }
  830. // 获取提现信息
  831. public function getWithDrawInfo(Request $request)
  832. {
  833. // $UserID = (int)$request->globalUser->UserID;//$request->input('UserID');
  834. $user = $request->user();
  835. $UserID=$user->UserID;
  836. // $paypass = $request->input('paypass');
  837. // if (!empty($user->InsurePass)&&!Hash::check($paypass,$user->InsurePass)) {
  838. // return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  839. // }
  840. $info = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  841. ->where('UserID', $UserID)
  842. ->lock('WITH(NOLOCK)')
  843. ->first();
  844. if (!$info) { // 赋值 -- 避免客户端报错
  845. $info = [
  846. // 'BankNO' => '',
  847. // 'AccountsBank' => '',
  848. 'BankUserName' => '',
  849. // 'PhoneNumber' => '',
  850. // 'IFSCNumber' => '',
  851. 'EmailAddress' => '',
  852. // 'Achieves' => '',
  853. // 'PANNumber' => '',
  854. // 'AdhaarNumber' => '',
  855. // 'BranchBank' => '',
  856. 'PixNum' => '',
  857. 'PixType' => '',
  858. ];
  859. }
  860. $info = json_decode(json_encode($info),true);
  861. if(env('REGION_24680')=='na-mexico') {
  862. $info['bank_list'] = config('games.mex_bank_list');
  863. }else if(env('REGION_24680')=='eu-russian') {
  864. $info['bank_list'] = config('games.ru_bank_list');
  865. }
  866. $AccountsInfoModel = new AccountsInfo();
  867. $total = $AccountsInfoModel->accountTotalStatistics([$UserID]);
  868. $totalRecharge= @$total[0]->Recharge ?? 0;
  869. $info['total_recharge'] = intval($totalRecharge);
  870. $info['withdraw_level'] = env('MIN_RECHARGE',20);
  871. return apiReturnSuc(compact('info'));
  872. }
  873. }