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