WithDrawInfoController.php 37 KB

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