WithDrawInfoController.php 40 KB

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