WithDrawInfoController.php 37 KB

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