2
0

WithDrawInfoController.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  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. if(!$PhoneNumber||strlen($PhoneNumber)!=11){
  330. return apiReturnFail(['withdraw.account.tip.phone_error', 'The phone number is error']);
  331. }
  332. if (!$BranchBank || $BranchBank == 'undefined') {
  333. return apiReturnFail(['web.bank.branch_empty', 'The branch code cannot be empty']);
  334. }
  335. }
  336. $redisKey = 'withDrawInfo_withDrawInfo_' . $UserID;
  337. if (!SetNXLock::getExclusiveLock($redisKey)) {
  338. return apiReturnFail(['web.bank.try_again_later', 'Please try again later']);
  339. }
  340. if (!$UserID) {
  341. Log::info('miss UserID', $request->all());
  342. SetNXLock::release($redisKey);
  343. return apiReturnFail(['web.bank.missing_userid', 'params error']);
  344. }
  345. if (empty($PixType)) {
  346. SetNXLock::release($redisKey);
  347. return apiReturnFail(['web.bank.pix_type_missing', 'The PIX type is missing']);
  348. }
  349. // 验证PixNum绑定次数
  350. if (!empty($PixNum)) {
  351. $BindCount = DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  352. ->where('BankCard', $PixNum)
  353. ->lock('WITH(NOLOCK)')
  354. ->count();
  355. if ($BindCount >= 3) {
  356. SetNXLock::release($redisKey);
  357. return apiReturnFail(['web.bank.cpf_used_multiple_times', 'The CPF number has been used multiple times and cannot be saved'], [], 302);
  358. }
  359. }
  360. // 验证玩家信息
  361. if (!empty($user->InsurePass)&&!Hash::check($paypass,$user->InsurePass)) {
  362. return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  363. }
  364. $data = compact('PixType', 'BankUserName', 'PhoneNumber','BankNO', 'AccountsBank','BranchBank','PixNum');
  365. $PixNum = $BankNO;
  366. foreach ($data as $key => &$val) {
  367. $data[$key] = trim($val);
  368. }
  369. unset($val);
  370. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  371. ->lock('WITH(NOLOCK)')
  372. ->where('UserID', $UserID)
  373. ->first();
  374. if (!$AccountWithDrawInfo) {
  375. $data['UserID'] = $UserID;
  376. $data['Achieves'] = 0;
  377. $data['HistoryWithDraw'] = 0;
  378. try {
  379. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  380. ->where('UserID', $UserID)
  381. ->insert($data);
  382. } catch (\Exception $e) {
  383. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  384. }
  385. } else {
  386. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  387. ->where('UserID', $UserID)
  388. ->update($data);
  389. }
  390. // 添加绑定记录
  391. if (empty($AccountWithDrawInfo->PixNum) || $AccountWithDrawInfo->PixNum != $PixNum) {
  392. try {
  393. DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  394. ->insert([
  395. 'UserID' => $UserID,
  396. 'BankCard' => $PixNum ?: '',
  397. 'BindDate' => now()
  398. ]);
  399. } catch (\Exception $e) {
  400. Log::error('insert RecordBankCardBind failed', ['data' => $data]);
  401. }
  402. }
  403. SetNXLock::release($redisKey);
  404. return apiReturnSuc();
  405. }
  406. public function withDrawInfo(Request $request)
  407. {
  408. // return apiReturnFail('params error');
  409. $user = $request->user();
  410. $UserID=$user->UserID;
  411. // $UserID = (int)$request->globalUser->UserID;//$request->input('UserID');
  412. // $RequestDynamicPass = $request->input('DynamicPass');
  413. $PixType = $request->input('cbPixType');
  414. $BankUserName = urldecode($request->input('userName'));
  415. $EmailAddress = $request->input('email');
  416. $PixNum = $request->input('PixNum');
  417. if(!empty($EmailAddress))$EmailAddress=Util::cleanEmptyString($EmailAddress);
  418. if(!empty($PixNum))$PixNum=Util::cleanEmptyString($PixNum);
  419. if (!empty($EmailAddress)&&!Util::validateEmail($EmailAddress)) {
  420. return apiReturnFail(['web.user.email_fail','Wrong email format']);
  421. }
  422. $redisKey = 'withDrawInfo_withDrawInfo_'.$UserID;
  423. if (!SetNXLock::getExclusiveLock($redisKey)) {
  424. Util::WriteLog("withdrawInfo",[1, $request->all()]);
  425. return apiReturnFail(['web.withdraw.try_again_later','Tente novamente mais tarde']);
  426. }
  427. if (!$UserID) {
  428. Util::WriteLog("withdrawInfo",[2, $request->all()]);
  429. Log::info('miss UserID', $request->all());
  430. SetNXLock::release($redisKey);
  431. return apiReturnFail(['web.withdraw.params_error','params error']);
  432. }
  433. if (empty($PixType)) {
  434. Util::WriteLog("withdrawInfo",[3, $request->all()]);
  435. SetNXLock::release($redisKey);
  436. return apiReturnFail(["web.withdraw.pix_type_missing",'O tipo PIX está ausente']);
  437. }
  438. // 验证PixNum绑定次数
  439. // if (!empty($PixNum)) {
  440. // $BindCount = DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  441. // ->where('BankCard', $PixNum)
  442. // ->lock('WITH(NOLOCK)')
  443. // ->count();
  444. // if ($BindCount >= 6) {
  445. // Util::WriteLog("withdrawInfo",[4, $request->all()]);
  446. // SetNXLock::release($redisKey);
  447. // return apiReturnFail(['web.withdraw.cpf_number_used','O número do CPF foi usado várias vezes e não pode ser salvo'], [], 302);
  448. // }
  449. // }
  450. if ($PixType==1) {
  451. // 验证 cashapp
  452. if (!empty($PixNum)) {
  453. // 如果 PixNum 第一个字符不是 "$",则在前面添加 "$"
  454. if (substr($PixNum, 0, 1) !== '$') {
  455. $PixNum = '$' . $PixNum;
  456. }
  457. // 构建 cash.app URL
  458. $cashAppUrl = 'https://cash.app/' . $PixNum;
  459. try {
  460. // 使用 stream context 来获取 HTTP 响应头
  461. $context = stream_context_create([
  462. 'http' => [
  463. 'method' => 'GET',
  464. 'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\r\n",
  465. 'ignore_errors' => true
  466. ]
  467. ]);
  468. $htmlContent = @file_get_contents($cashAppUrl, false, $context);
  469. // 检查 HTTP 响应头中的状态码
  470. if ($htmlContent === false || (isset($http_response_header) && preg_match('/HTTP\/\d\.\d\s+404/', implode("\n", $http_response_header)))) {
  471. Util::WriteLog("withdrawInfo", [5, $request->all(), 'Invalid cashapp: ' . $PixNum]);
  472. SetNXLock::release($redisKey);
  473. return apiReturnFail(['web.withdraw.invalid_cashapp', 'Invalid CashApp account']);
  474. }
  475. if ($htmlContent !== false) {
  476. // 去除空格换行,转换成一行字符串
  477. $htmlContent = preg_replace('/\s+/', '', $htmlContent);
  478. Util::WriteLog("withdrawInfo", [5, $request->all(), 'CashApp verification response: ' . $htmlContent]);
  479. // 检查响应内容中是否包含 "404 Not Found"
  480. if (stripos($htmlContent, '404NotFound') !== false) {
  481. Util::WriteLog("withdrawInfo", [5, $request->all(), 'Invalid cashapp: ' . $PixNum]);
  482. SetNXLock::release($redisKey);
  483. return apiReturnFail(['web.withdraw.invalid_cashapp', 'Invalid CashApp account']);
  484. }
  485. }
  486. } catch (\Exception $e) {
  487. // 其他异常也记录日志但不阻止流程
  488. Util::WriteLog("withdrawInfo", [5, $request->all(), 'CashApp verification error: ' . $e->getMessage()]);
  489. }
  490. }
  491. $data = compact('PixType', 'BankUserName', 'PixNum');
  492. } else {
  493. $data = compact('PixType', 'EmailAddress');
  494. }
  495. foreach ($data as $key => &$val) {
  496. $data[$key] = trim($val);
  497. }
  498. unset($val);
  499. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  500. ->lock('WITH(NOLOCK)')
  501. ->where('UserID', $UserID)
  502. ->first();
  503. if (!$AccountWithDrawInfo) {
  504. $data['UserID'] = $UserID;
  505. $data['Achieves'] = 0;
  506. $data['HistoryWithDraw'] = 0;
  507. try {
  508. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  509. ->where('UserID', $UserID)
  510. ->insert($data);
  511. } catch (\Exception $e) {
  512. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  513. Util::WriteLog("withdrawInfo",[6, $request->all(),$data]);
  514. }
  515. } else {
  516. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  517. ->where('UserID', $UserID)
  518. ->update($data);
  519. }
  520. SetNXLock::release($redisKey);
  521. return apiReturnSuc();
  522. }
  523. public function withDrawInfoSA(Request $request)
  524. {
  525. // return apiReturnFail('params error');
  526. $UserID = $request->input('UserID');
  527. $RequestDynamicPass = $request->input('DynamicPass');
  528. $PixType = $request->input('cbPixType');
  529. $BankNO = $request->input('bank');
  530. $AccountsBank = urldecode($request->input('account'));
  531. $BankUserName = urldecode($request->input('userName'));
  532. // 原始代码
  533. $BankUserName = Util::filterNickName($BankUserName);
  534. // 新增处理:在大写字母前加空格
  535. $BankUserName = preg_replace('/(?<!^)([A-Z])/', ' $1', $BankUserName);
  536. $PhoneNumber = $request->input('phone');
  537. $EmailAddress = $request->input('email');
  538. $IFSCNumber = $request->input('IFSC');
  539. $PANNumber = $request->input('PAN');
  540. $AdhaarNumber = $request->input('adhaar');
  541. $BranchBank = $request->input('branceBank');
  542. $PixNum = $request->input('PixNum');
  543. $redisKey = 'withDrawInfo_withDrawInfo_'.$UserID;
  544. if (!SetNXLock::getExclusiveLock($redisKey)) {
  545. Util::WriteLog("withdrawInfo",[1, $request->all()]);
  546. return apiReturnFail('Tente novamente mais tarde');
  547. }
  548. if (!$UserID) {
  549. Util::WriteLog("withdrawInfo",[2, $request->all()]);
  550. Log::info('miss UserID', $request->all());
  551. SetNXLock::release($redisKey);
  552. return apiReturnFail('params error');
  553. }
  554. if (empty($PixType)) {
  555. Util::WriteLog("withdrawInfo",[3, $request->all()]);
  556. SetNXLock::release($redisKey);
  557. return apiReturnFail('O tipo PIX está ausente');
  558. }
  559. // Util::validateSouthAmericanPhone('',)
  560. // 验证PixNum绑定次数
  561. if (!empty($PixNum)) {
  562. $BindCount = DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  563. ->where('BankCard', $PixNum)
  564. ->lock('WITH(NOLOCK)')
  565. ->count();
  566. if ($BindCount >= 8) {
  567. Util::WriteLog("withdrawInfo",[4, $request->all()]);
  568. SetNXLock::release($redisKey);
  569. return apiReturnFail(['web.withdraw.cpf_number_used','The CPF number has been used several times and cannot be saved'], [], 302);
  570. }
  571. }
  572. // if(!is_numeric($PixNum)){
  573. // return apiReturnFail(['web.withdraw.pix_failed','The CPF number has been used several times and cannot be saved'], [], 302);
  574. // }
  575. // 验证玩家信息
  576. $DynamicPass = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  577. ->where('UserID', $UserID)
  578. ->lock('WITH(NOLOCK)')
  579. ->value('DynamicPass');
  580. if ($DynamicPass != $RequestDynamicPass || empty($DynamicPass)) {
  581. SetNXLock::release($redisKey);
  582. Util::WriteLog("withdrawInfo",[5, $request->all()]);
  583. return apiReturnFail('As informações do jogador são inconsistentes');
  584. }
  585. $data = compact('PixType', 'BankUserName', 'PhoneNumber', 'EmailAddress', 'PixNum','BankNO', 'AccountsBank', 'IFSCNumber', 'PANNumber', 'AdhaarNumber', 'BranchBank');
  586. foreach ($data as $key => &$val) {
  587. $data[$key] = trim($val);
  588. }
  589. unset($val);
  590. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  591. ->lock('WITH(NOLOCK)')
  592. ->where('UserID', $UserID)
  593. ->first();
  594. if (!$AccountWithDrawInfo) {
  595. $data['UserID'] = $UserID;
  596. $data['Achieves'] = 0;
  597. $data['HistoryWithDraw'] = 0;
  598. try {
  599. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  600. ->where('UserID', $UserID)
  601. ->insert($data);
  602. } catch (\Exception $e) {
  603. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  604. Util::WriteLog("withdrawInfo",[6, $request->all(),$data]);
  605. }
  606. } else {
  607. $data = array_filter($data, function ($value) {
  608. return !is_null($value) && $value !== '';
  609. });
  610. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  611. ->where('UserID', $UserID)
  612. ->update($data);
  613. }
  614. // 添加绑定记录
  615. if (empty($AccountWithDrawInfo->PixNum) || $AccountWithDrawInfo->PixNum != $PixNum) {
  616. try {
  617. if(!DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')->where('UserID', $UserID)->exists()&&is_numeric($PixNum)) {
  618. DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  619. ->insert([
  620. 'UserID' => $UserID,
  621. 'BankCard' => $PixNum ?? '',
  622. 'BindDate' => now()
  623. ]);
  624. Util::WriteLog('update_pix', [
  625. 'UserID' => $UserID,
  626. 'BankCard' => $PixNum ?? '',
  627. 'BindDate' => now()
  628. ]);
  629. }
  630. } catch (\Exception $e) {
  631. Log::error('insert RecordBankCardBind failed', ['data' => $data]);
  632. Util::WriteLog("withdrawInfo",[7, $request->all(),$data]);
  633. }
  634. }
  635. SetNXLock::release($redisKey);
  636. return apiReturnSuc();
  637. }
  638. public function kycSimpleEU(Request $request)
  639. {
  640. // return apiReturnFail('params error');
  641. $user = $request->user();
  642. $UserID=$user->UserID;
  643. $firstName = Util::filterNickName(urldecode($request->input('firstName')));
  644. $lastName = Util::filterNickName(urldecode($request->input('lastName')));
  645. // 原始代码
  646. $BankUserName = $firstName.'|'.$lastName;
  647. $PhoneNumber = $request->input('phone');
  648. $EmailAddress = $request->input('email');
  649. Util::WriteLog("kyc_eu",$request->all());
  650. if(isset($EmailAddress)&&!empty($EmailAddress)){
  651. $validator = Validator::make(
  652. ['email' => $EmailAddress],
  653. ['email' => 'required|email']
  654. );
  655. if ($validator->fails()) {
  656. return apiReturnFail(['web.user.email_fail','Wrong email format']);
  657. }
  658. }
  659. if (!$BankUserName || $BankUserName == 'undefined') {
  660. return apiReturnFail(['web.bank.username_empty', 'The name cannot be empty']);
  661. }
  662. $redisKey = 'withDrawInfo_withDrawInfo_' . $UserID;
  663. if (!SetNXLock::getExclusiveLock($redisKey)) {
  664. return apiReturnFail(['web.bank.try_again_later', 'Please try again later']);
  665. }
  666. if (!$UserID) {
  667. Log::info('miss UserID', $request->all());
  668. SetNXLock::release($redisKey);
  669. return apiReturnFail(['web.bank.missing_userid', 'params error']);
  670. }
  671. $data = compact('BankUserName', 'PhoneNumber', 'EmailAddress');
  672. foreach ($data as $key => &$val) {
  673. $data[$key] = trim($val);
  674. if(empty($val))unset($data[$key]);
  675. }
  676. unset($val);
  677. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  678. ->lock('WITH(NOLOCK)')
  679. ->where('UserID', $UserID)
  680. ->first();
  681. if (!$AccountWithDrawInfo) {
  682. $data['UserID'] = $UserID;
  683. $data['Achieves'] = 0;
  684. $data['HistoryWithDraw'] = 0;
  685. try {
  686. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  687. ->where('UserID', $UserID)
  688. ->insert($data);
  689. } catch (\Exception $e) {
  690. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  691. }
  692. } else {
  693. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  694. ->where('UserID', $UserID)
  695. ->update($data);
  696. }
  697. SetNXLock::release($redisKey);
  698. return apiReturnSuc();
  699. }
  700. public function withDrawInfoEU(Request $request)
  701. {
  702. // return apiReturnFail('params error');
  703. $user = $request->user();
  704. $UserID=$user->UserID;
  705. // $UserID = $request->input('UserID');
  706. // $RequestDynamicPass = $request->input('DynamicPass');
  707. $PixType = $request->input('cbPixType');
  708. $firstName = Util::filterNickName(urldecode($request->input('firstName')));
  709. $lastName = Util::filterNickName(urldecode($request->input('lastName')));
  710. // 原始代码
  711. $BankUserName = $firstName.'|'.$lastName;
  712. $BankNO = $request->input('account');
  713. $AccountsBank = $request->input('account');
  714. $PhoneNumber = $request->input('phone');
  715. $EmailAddress = $request->input('email');
  716. $IFSCNumber = $request->input('IFSCNumber');
  717. $BranchBank = $request->input('bank');//银行编号
  718. $PixNum = $request->input('account');
  719. Util::WriteLog("euwithdraw",$request->all());
  720. if(isset($EmailAddress)&&!empty($EmailAddress)){
  721. $validator = Validator::make(
  722. ['email' => $EmailAddress],
  723. ['email' => 'required|email']
  724. );
  725. if ($validator->fails()) {
  726. return apiReturnFail(['web.user.email_fail','Wrong email format']);
  727. }
  728. }
  729. if (!$AccountsBank || $AccountsBank == 'undefined') {
  730. return apiReturnFail(['web.bank.account_empty', 'The bank account cannot be empty']);
  731. }
  732. if (!(strlen($AccountsBank) == 16 || strlen($AccountsBank) == 18)) {
  733. return apiReturnFail(['web.bank.account_invalid_length', 'The bank number must have 16 or 18 digits']);
  734. }
  735. if (!(strlen($IFSCNumber) == 18 && $IFSCNumber)) {
  736. return apiReturnFail(['web.bank.clabe_invalid_length', 'The Clabe number must have 18 digits']);
  737. }
  738. if (!$BankUserName || $BankUserName == 'undefined') {
  739. return apiReturnFail(['web.bank.username_empty', 'The name cannot be empty']);
  740. }
  741. if (!$BranchBank || $BranchBank == 'undefined') {
  742. return apiReturnFail(['web.bank.branch_empty', 'The branch code cannot be empty']);
  743. }
  744. if (strlen($AccountsBank) == 16) {
  745. $PixType = 2;
  746. }
  747. if (strlen($AccountsBank) == 18) {
  748. $PixType = 1;
  749. }
  750. $redisKey = 'withDrawInfo_withDrawInfo_' . $UserID;
  751. if (!SetNXLock::getExclusiveLock($redisKey)) {
  752. return apiReturnFail(['web.bank.try_again_later', 'Please try again later']);
  753. }
  754. if (!$UserID) {
  755. Log::info('miss UserID', $request->all());
  756. SetNXLock::release($redisKey);
  757. return apiReturnFail(['web.bank.missing_userid', 'params error']);
  758. }
  759. if (empty($PixType)) {
  760. SetNXLock::release($redisKey);
  761. return apiReturnFail(['web.bank.pix_type_missing', 'The PIX type is missing']);
  762. }
  763. // 验证PixNum绑定次数
  764. if (!empty($PixNum)) {
  765. $BindCount = DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  766. ->where('BankCard', $PixNum)
  767. ->lock('WITH(NOLOCK)')
  768. ->count();
  769. if ($BindCount >= 3) {
  770. SetNXLock::release($redisKey);
  771. return apiReturnFail(['web.bank.cpf_used_multiple_times', 'The CPF number has been used multiple times and cannot be saved'], [], 302);
  772. }
  773. }
  774. // 验证玩家信息
  775. if (!empty($user->InsurePass)&&!Hash::check($paypass,$user->InsurePass)) {
  776. return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  777. }
  778. if ($PixType < 10 && false) {
  779. $data = compact('PixType', 'BankUserName', 'PhoneNumber', 'EmailAddress', 'PixNum');
  780. } else {
  781. $data = compact('PixType', 'BankUserName','IFSCNumber', 'PhoneNumber', 'EmailAddress','BankNO', 'AccountsBank','BranchBank','PixNum');
  782. $PixNum = $BankNO;
  783. }
  784. foreach ($data as $key => &$val) {
  785. $data[$key] = trim($val);
  786. }
  787. unset($val);
  788. $AccountWithDrawInfo = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  789. ->lock('WITH(NOLOCK)')
  790. ->where('UserID', $UserID)
  791. ->first();
  792. if (!$AccountWithDrawInfo) {
  793. $data['UserID'] = $UserID;
  794. $data['Achieves'] = 0;
  795. $data['HistoryWithDraw'] = 0;
  796. try {
  797. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  798. ->where('UserID', $UserID)
  799. ->insert($data);
  800. } catch (\Exception $e) {
  801. Log::error('insert AccountWithDrawInfo failed', ['data' => $data]);
  802. }
  803. } else {
  804. DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  805. ->where('UserID', $UserID)
  806. ->update($data);
  807. }
  808. // 添加绑定记录
  809. if (empty($AccountWithDrawInfo->PixNum) || $AccountWithDrawInfo->PixNum != $PixNum) {
  810. try {
  811. DB::table(TableName::QPRecordDB() . 'RecordBankCardBind')
  812. ->insert([
  813. 'UserID' => $UserID,
  814. 'BankCard' => $PixNum ?: '',
  815. 'BindDate' => now()
  816. ]);
  817. } catch (\Exception $e) {
  818. Log::error('insert RecordBankCardBind failed', ['data' => $data]);
  819. }
  820. }
  821. SetNXLock::release($redisKey);
  822. return apiReturnSuc();
  823. }
  824. // 获取提现信息
  825. public function getWithDrawInfo(Request $request)
  826. {
  827. // $UserID = (int)$request->globalUser->UserID;//$request->input('UserID');
  828. $user = $request->user();
  829. $UserID=$user->UserID;
  830. // $paypass = $request->input('paypass');
  831. // if (!empty($user->InsurePass)&&!Hash::check($paypass,$user->InsurePass)) {
  832. // return apiReturnFail(['web.user.paypass_fail', 'A senha original está errada, digite-a novamente.'], '', 2);
  833. // }
  834. $info = DB::table(TableName::QPAccountsDB() . 'AccountWithDrawInfo')
  835. ->where('UserID', $UserID)
  836. ->lock('WITH(NOLOCK)')
  837. ->first();
  838. if (!$info) { // 赋值 -- 避免客户端报错
  839. $info = [
  840. // 'BankNO' => '',
  841. // 'AccountsBank' => '',
  842. 'BankUserName' => '',
  843. // 'PhoneNumber' => '',
  844. // 'IFSCNumber' => '',
  845. 'EmailAddress' => '',
  846. // 'Achieves' => '',
  847. // 'PANNumber' => '',
  848. // 'AdhaarNumber' => '',
  849. // 'BranchBank' => '',
  850. 'PixNum' => '',
  851. 'PixType' => '',
  852. ];
  853. }
  854. $info = json_decode(json_encode($info),true);
  855. if(env('REGION_24680')=='na-mexico') {
  856. $info['bank_list'] = config('games.mex_bank_list');
  857. }else if(env('REGION_24680')=='eu-russian') {
  858. $info['bank_list'] = config('games.ru_bank_list');
  859. }
  860. $AccountsInfoModel = new AccountsInfo();
  861. $total = $AccountsInfoModel->accountTotalStatistics([$UserID]);
  862. $totalRecharge= @$total[0]->Recharge ?? 0;
  863. $info['total_recharge'] = intval($totalRecharge);
  864. $info['withdraw_level'] = env('MIN_RECHARGE',20);
  865. return apiReturnSuc(compact('info'));
  866. }
  867. }