WithDrawInfoController.php 39 KB

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