2
0

WithDrawInfoController.php 40 KB

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