WithdrawalController.php 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\dao\Estatisticas\RechargeWithDraw;
  4. use App\Facade\RedisConnect;
  5. use App\Facade\TableName;
  6. use App\Http\helper\Helper;
  7. use App\Http\helper\NumConfig;
  8. use App\Http\logic\admin\AccountsRecordLogic;
  9. use App\Http\logic\admin\WithdrawalLogic;
  10. use App\Models\AccountsInfo;
  11. use App\Models\AddDrawBase;
  12. use App\Models\PrivateMail;
  13. use App\Models\RecordScoreInfo;
  14. use App\Models\RecordUserDataStatistics;
  15. use App\Models\SystemStatusInfo;
  16. use App\Services\CashierMessage;
  17. use App\Services\CreateLog;
  18. use App\Services\LogDayStatisticalByDayAndChannel;
  19. use App\Services\StoredProcedure;
  20. use App\Utility\SetNXLock;
  21. use Carbon\Carbon;
  22. use Illuminate\Http\Request;
  23. use Illuminate\Support\Facades\DB;
  24. use Illuminate\Support\Facades\Log;
  25. use Illuminate\Support\Facades\Redis;
  26. use Illuminate\Support\Facades\Validator;
  27. class WithdrawalController extends BaseController
  28. {
  29. protected $logic;
  30. public function __construct()
  31. {
  32. $this->logic = new WithdrawalLogic();
  33. }
  34. // 待审核列表
  35. public function waitWithdrawal(Request $request)
  36. {
  37. $create_time_sort = $request->create_time_sort ?: '';
  38. $GameID = (int)$request->get('GameID') ?: '';
  39. $withdraw_search = (int)$request->get('withdraw_search') ?: '';
  40. $withdraw = $request->get('withdraw') ?? '';
  41. $state = $request->get('state') ?? '';
  42. $start_time = $request->get('start_time') ?? '';
  43. $end_time = $request->get('end_time') ?? '';
  44. $final_start_time = $request->get('final_start_time') ?? '';
  45. $final_end_time = $request->get('final_end_time') ?? '';
  46. $orderID = $request->get('orderID') ?? '';
  47. $excel = $request->get('excel') ?? '';
  48. $Channel = $request->get('Channel');
  49. $payState = $request->get('payState');
  50. $PackgeName = $request->PackgeName ?: '';
  51. $toNormalCs=Redis::get("normalCsOpen")??"close";
  52. $list = $this->logic->waitWithdrawal($GameID, $withdraw_search, $withdraw, $state, $start_time, $end_time, '', false, $create_time_sort, $orderID, $final_start_time, $final_end_time, $excel, $Channel, $payState, '', 0, '', '', $PackgeName,$toNormalCs=="open"?2:0);
  53. $list['api_url']='/admin/withdrawal/waitWithdrawal';
  54. $list['normalCsOpen']=$toNormalCs;
  55. $list['specialCs']=false;
  56. return view('admin.Withdrawal.waitWithdrawal', $list);
  57. }
  58. public function changeNewWithdrawOpen(Request $request)
  59. {
  60. //普通客服开放新用户审核开关
  61. $toNormalCs=$request->input("normalCsOpen");
  62. Redis::set("normalCsOpen",$toNormalCs);
  63. return apiReturnSuc([],"","操作成功:".($toNormalCs=="open"?"开启":"关闭"));
  64. }
  65. public function waitWithdrawalNewPlayer(Request $request)
  66. {
  67. $toNormalCs=Redis::get("normalCsOpen")??"close";
  68. $create_time_sort = $request->create_time_sort ?: '';
  69. $GameID = (int)$request->get('GameID') ?: '';
  70. $withdraw_search = (int)$request->get('withdraw_search') ?: '';
  71. $withdraw = $request->get('withdraw') ?? '';
  72. $state = $request->get('state') ?? '';
  73. $start_time = $request->get('start_time') ?? '';
  74. $end_time = $request->get('end_time') ?? '';
  75. $final_start_time = $request->get('final_start_time') ?? '';
  76. $final_end_time = $request->get('final_end_time') ?? '';
  77. $orderID = $request->get('orderID') ?? '';
  78. $excel = $request->get('excel') ?? '';
  79. $Channel = $request->get('Channel');
  80. $payState = $request->get('payState');
  81. $PackgeName = $request->PackgeName ?: '';
  82. $list = $this->logic->waitWithdrawal($GameID, $withdraw_search, $withdraw, $state, $start_time, $end_time, '', false, $create_time_sort, $orderID, $final_start_time, $final_end_time, $excel, $Channel, $payState, '', 0, '', '', $PackgeName,1);
  83. $list['api_url']='/admin/withdrawal/waitWithdrawalNewPlayer';
  84. $list['normalCsOpen']=$toNormalCs;
  85. $list['specialCs']=true;
  86. return view('admin.Withdrawal.waitWithdrawal', $list);
  87. }
  88. public function state5List(Request $request){
  89. $data = $request->all();
  90. if ($request->isMethod('post')) {
  91. $ID=$data['OrderId'];
  92. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderId',$ID)->update(['State'=>1]);
  93. return json_encode(['id'=>$ID]);
  94. }
  95. $list=DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')
  96. ->where('State','=',5)
  97. ->get()->toArray();
  98. // print_r($list);die;
  99. return view('admin.Withdrawal.statelist', ['list'=>$list]);
  100. }
  101. // 提现审核
  102. public function verify(Request $request)
  103. {
  104. $data = $request->all();
  105. if ($request->isMethod('get')) {
  106. if ($data['type'] == 'agree') { // 通过
  107. $open=(int)SystemStatusInfo::OnlyGetCacheValue(SystemStatusInfo::$KEY_WithDrawSwitch);
  108. $list = $this->logic->verify_agree($data['ids']);
  109. $list['open']=$open;
  110. return view('admin.Withdrawal.verify_agree', $list);
  111. } elseif ($data['type'] == 'refuse') { // 清退
  112. $list = $this->logic->verify_agree($data['ids']);
  113. return view('admin.Withdrawal.verify_refuse', $list);
  114. } elseif ($data['type'] == 'turn_down') { // 拒绝
  115. $list = $this->logic->verify_agree($data['ids']);
  116. return view('admin.Withdrawal.turn_down', $list);
  117. }
  118. } else {
  119. $admin_id = $request->session()->get('admin')->id;
  120. $save = $this->logic->save($data, $admin_id);
  121. return $save;
  122. }
  123. }
  124. // 已审核提现订单查询
  125. public function verify_finish(Request $request)
  126. {
  127. $GameID = (int)$request->get('GameID') ?: '';
  128. $withdraw_search = (int)$request->get('withdraw_search') ?: '';
  129. $withdraw = $request->get('withdraw') ?: '';
  130. $state = $request->get('state') ?? '';
  131. $agent = $request->get('agent') ?? '';
  132. $start_time = $request->get('start_time') ?? '';
  133. $end_time = $request->get('end_time') ?? '';
  134. $orderID = $request->get('orderID') ?? '';
  135. $excel = $request->get('excel') ?? '';
  136. $final_start_time = $request->get('final_start_time') ?? '';
  137. $final_end_time = $request->get('final_end_time') ?? '';
  138. $take_effect = $request->get('take_effect') ?? '';
  139. $Channel = $request->get('Channel');
  140. $payState = $request->get('payState');
  141. $start_time = str_replace('T', ' ', $start_time);
  142. $end_time = str_replace('T', ' ', $end_time);
  143. $isEmpty = $request->get('isEmpty') ?: '';
  144. $PackgeName = $request->PackgeName ?: '';
  145. $register_start_time = $request->input('register_start_time');
  146. $register_end_time = $request->input('register_end_time');
  147. $list = $this->logic->waitWithdrawal($GameID, $withdraw_search, $withdraw, $state, $start_time, $end_time, $agent, true, '', $orderID, $final_start_time, $final_end_time, $excel, $Channel, $payState, $take_effect, $isEmpty, $register_start_time, $register_end_time, $PackgeName,2);
  148. $list['agents'] = DB::table('agent.dbo.admin_configs')
  149. ->where('type', 'cash')
  150. ->get();
  151. $list['request'] = $request;
  152. $admin = session('admin');
  153. $list['viewAll'] = $admin && isset($admin->roles[0]->id) && in_array($admin->roles[0]->id, [1, 12, 2010, 2011]) ? 1 : 0;
  154. return view('admin.Withdrawal.verify_finish', $list);
  155. }
  156. // 提现拒绝
  157. public function turn_down(Request $request)
  158. {
  159. $redis = new RedisConnect();
  160. $limitKey = 'turn_down';
  161. $res = $redis->redis()->set($limitKey, 1, 3);
  162. if (empty($res)) return apiReturnFail('频繁操作');
  163. $post = $request->post();
  164. $ids = explode(',', $post['ids']);
  165. if (count($ids) < 1) {
  166. return apiReturnFail('数据不存在!');
  167. }
  168. foreach ($ids as $val) {
  169. // 查找订单
  170. $OrderWithDraw = DB::table(TableName::QPAccountsDB() . 'OrderWithDraw')
  171. ->where('RecordID', $val)
  172. ->selectRaw('UserID,OrderID,WithDraw,ServiceFee')
  173. ->first();
  174. // 修改订单状态 locking=>[2清退不返打码量 3 拒绝返打码量]
  175. DB::table(TableName::QPAccountsDB() . 'OrderWithDraw')
  176. ->where('RecordID', $val)
  177. ->update(['State' => -1, 'locking' => 3]);
  178. $remarks = $post['remarks'] ?? '';
  179. $admin_id = session('admin')['id'];
  180. // 添加用户提现操作记录
  181. (new AccountsRecordLogic())->create_record($val, 1, -2, $remarks, $admin_id, 1);
  182. $amount = $OrderWithDraw->WithDraw + $OrderWithDraw->ServiceFee;
  183. PrivateMail::refuseMail($OrderWithDraw->UserID, $OrderWithDraw->OrderID, $amount, true);
  184. }
  185. $redis->redis()->del($limitKey);
  186. return apiReturnSuc();
  187. }
  188. // 提现数值修改
  189. public function config()
  190. {
  191. // $fee = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo as si')
  192. // ->leftJoin('agent.dbo.SystemStatusInfo_log as log', function($join) {
  193. // $join->on(DB::raw('si.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'), '=', DB::raw('log.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'));
  194. // })
  195. // ->leftJoin('agent.dbo.admin_users as au', 'log.admin_id', '=', 'au.id')
  196. // ->where('si.StatusName', 'WithDrawTax')
  197. // ->select('StatusValue', 'account', 'create_at')
  198. // ->first();
  199. $fee = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo as si')
  200. ->leftJoin('agent.dbo.SystemStatusInfo_log as log', function($join) {
  201. $join->on(DB::raw('si.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'), '=', DB::raw('log.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'));
  202. })
  203. ->leftJoin('agent.dbo.admin_users as au', 'log.admin_id', '=', 'au.id')
  204. ->where('si.StatusName', 'WithDrawTax')
  205. ->select('StatusValue', 'account', 'create_at')
  206. ->first();
  207. $artificial = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo as si')
  208. ->leftJoin('agent.dbo.SystemStatusInfo_log as log', function($join) {
  209. $join->on(DB::raw('si.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'), '=', DB::raw('log.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'));
  210. })
  211. ->leftJoin('agent.dbo.admin_users as au', 'log.admin_id', '=', 'au.id')
  212. ->where('si.StatusName', 'WithDrawAILimit')
  213. ->select('StatusValue', 'account', 'create_at')
  214. ->first();
  215. $proportion = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo as si')
  216. ->leftJoin('agent.dbo.SystemStatusInfo_log as log', function($join) {
  217. $join->on(DB::raw('si.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'), '=', DB::raw('log.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'));
  218. })
  219. ->leftJoin('agent.dbo.admin_users as au', 'log.admin_id', '=', 'au.id')
  220. ->where('si.StatusName', 'WithDrawRate')
  221. ->select('StatusValue', 'account', 'create_at')
  222. ->first();
  223. $WithDrawMin = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo as si')
  224. ->leftJoin('agent.dbo.SystemStatusInfo_log as log', function($join) {
  225. $join->on(DB::raw('si.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'), '=', DB::raw('log.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'));
  226. })
  227. ->leftJoin('agent.dbo.admin_users as au', 'log.admin_id', '=', 'au.id')
  228. ->where('si.StatusName', 'WithDrawMin')
  229. ->select('StatusValue', 'account', 'create_at')
  230. ->first();
  231. $WithDrawMax = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo as si')
  232. ->leftJoin('agent.dbo.SystemStatusInfo_log as log', function($join) {
  233. $join->on(DB::raw('si.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'), '=', DB::raw('log.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'));
  234. })
  235. ->leftJoin('agent.dbo.admin_users as au', 'log.admin_id', '=', 'au.id')
  236. ->where('si.StatusName', 'WithDrawMax')
  237. ->select('StatusValue', 'account', 'create_at')
  238. ->first();
  239. $WithDrawPoint = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo as si')
  240. ->leftJoin('agent.dbo.SystemStatusInfo_log as log', function($join) {
  241. $join->on(DB::raw('si.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'), '=', DB::raw('log.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'));
  242. })
  243. ->leftJoin('agent.dbo.admin_users as au', 'log.admin_id', '=', 'au.id')
  244. ->where('si.StatusName', 'WithDrawPoint')
  245. ->select('StatusValue', 'account', 'create_at')
  246. ->first();
  247. $MaxTXNotRecharge = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo as si')
  248. ->leftJoin('agent.dbo.SystemStatusInfo_log as log', function($join) {
  249. $join->on(DB::raw('si.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'), '=', DB::raw('log.StatusName COLLATE SQL_Latin1_General_CP1_CI_AS'));
  250. })
  251. ->leftJoin('agent.dbo.admin_users as au', 'log.admin_id', '=', 'au.id')
  252. ->where('si.StatusName', 'MaxTXNotRecharge')
  253. ->select('StatusValue', 'account', 'create_at')
  254. ->first();
  255. $fee->StatusValue = number_float(-$fee->StatusValue / NumConfig::NUM_VALUE);
  256. $artificial->StatusValue = number_float($artificial->StatusValue / NumConfig::NUM_VALUE);
  257. $proportion->StatusValue = number_float((10000 - $proportion->StatusValue) / NumConfig::NUM_VALUE);
  258. $WithDrawMin->StatusValue = number_float(($WithDrawMin->StatusValue) / NumConfig::NUM_VALUE);
  259. $WithDrawMax->StatusValue = number_float(($WithDrawMax->StatusValue) / NumConfig::NUM_VALUE);
  260. $WithDrawPoint->StatusValue = number_float(($WithDrawPoint->StatusValue) / NumConfig::NUM_VALUE);
  261. $MaxTXNotRecharge->StatusValue = number_float(($MaxTXNotRecharge->StatusValue) / NumConfig::NUM_VALUE);
  262. $compact = compact('fee', 'artificial', 'proportion', 'WithDrawMin', 'WithDrawMax', 'WithDrawPoint', 'MaxTXNotRecharge');
  263. return view('admin.Withdrawal.config', $compact);
  264. }
  265. // 提现保底额度
  266. public function WithDrawPoint(Request $request)
  267. {
  268. if ($request->isMethod('post')) {
  269. $StatusValue = abs((int)$request->StatusValue * 100) ?: '';
  270. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawPoint')->update(['StatusValue' => $StatusValue]);
  271. $admin_id = session('admin')->id;
  272. CreateLog::SystemStatusInfo_log($admin_id, 'WithDrawPoint');
  273. return apiReturnSuc('success');
  274. }
  275. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawPoint')->value('StatusValue') / 100 ?? 0;
  276. return view('admin.Withdrawal.WithDrawPoint', ['info' => $result]);
  277. }
  278. // 提现手续费设置
  279. public function fee(Request $request)
  280. {
  281. if ($request->isMethod('post')) {
  282. $StatusValue = abs((int)$request->StatusValue) ?: '';
  283. if ($StatusValue > 1000) {
  284. return apiReturnFail('手续费最大值为1000');
  285. }
  286. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawTax')->update(['StatusValue' => $StatusValue]);
  287. $admin_id = session('admin')->id;
  288. CreateLog::SystemStatusInfo_log($admin_id, 'WithDrawPoint');
  289. return apiReturnSuc('success');
  290. }
  291. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawTax')->value('StatusValue');
  292. return view('admin.Withdrawal.fee', ['info' => $result]);
  293. }
  294. // 提现金额比例设置
  295. public function artificial(Request $request)
  296. {
  297. if ($request->isMethod('post')) {
  298. $StatusValue = abs((int)$request->StatusValue) ?: '';
  299. $StatusValue *= 100;
  300. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawAILimit')->update(['StatusValue' => $StatusValue]);
  301. $admin_id = session('admin')->id;
  302. CreateLog::SystemStatusInfo_log($admin_id, 'WithDrawPoint');
  303. return apiReturnSuc('success');
  304. }
  305. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawAILimit')->value('StatusValue');
  306. $result = $result / 100;
  307. return view('admin.Withdrawal.artificial', ['info' => $result]);
  308. }
  309. //人工审核额度设置
  310. public function proportion(Request $request)
  311. {
  312. if ($request->isMethod('post')) {
  313. $StatusValue = (int)$request->StatusValue ?: '';
  314. $StatusValue = abs($StatusValue);
  315. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawRate')->update(['StatusValue' => $StatusValue]);
  316. $admin_id = session('admin')->id;
  317. CreateLog::SystemStatusInfo_log($admin_id, 'WithDrawPoint');
  318. return apiReturnSuc('success');
  319. }
  320. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawRate')->value('StatusValue');
  321. return view('admin.Withdrawal.proportion', ['info' => $result]);
  322. }
  323. // 0充玩家提现限制最高额度
  324. public function MaxTXNotRecharge(Request $request)
  325. {
  326. if ($request->isMethod('post')) {
  327. $StatusValue = (int)$request->StatusValue ?: '';
  328. $StatusValue = $StatusValue * NumConfig::NUM_VALUE;
  329. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'MaxTXNotRecharge')->update(['StatusValue' => $StatusValue]);
  330. $admin_id = session('admin')->id;
  331. CreateLog::SystemStatusInfo_log($admin_id, 'MaxTXNotRecharge');
  332. return apiReturnSuc('success');
  333. } else {
  334. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'MaxTXNotRecharge')->value('StatusValue');
  335. $result = $result > 0 ? floatval($result / NumConfig::NUM_VALUE) : 0;
  336. return view('admin.Withdrawal.max_tx_not_recharge', ['info' => $result]);
  337. }
  338. }
  339. // 查看返回值
  340. public function show($sn = '')
  341. {
  342. $notify = DB::table('QPAccountsDB.dbo.withdraw_notify')->where('order_sn', $sn)->select('extra')->first()->extra ?? '';
  343. if ($notify) {
  344. $notify = \GuzzleHttp\json_decode($notify);
  345. }
  346. return view('admin.Withdrawal.show', ['info' => $notify]);
  347. }
  348. // 提现最大值修改
  349. public function WithDrawMax(Request $request)
  350. {
  351. if ($request->isMethod('post')) {
  352. $StatusValue = (int)$request->StatusValue ?: '';
  353. $StatusValue = abs($StatusValue) * NumConfig::NUM_VALUE;
  354. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawMax')->update(['StatusValue' => $StatusValue]);
  355. $admin_id = session('admin')->id;
  356. CreateLog::SystemStatusInfo_log($admin_id, 'WithDrawPoint');
  357. return apiReturnSuc('success');
  358. }
  359. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawMax')->value('StatusValue');
  360. $result /= 100;
  361. return view('admin.Withdrawal.WithDrawMax', ['info' => $result]);
  362. }
  363. // 提现最小值修改
  364. public function WithDrawMin(Request $request)
  365. {
  366. if ($request->isMethod('post')) {
  367. $StatusValue = (int)$request->StatusValue ?: '';
  368. $StatusValue = abs($StatusValue) * NumConfig::NUM_VALUE;
  369. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawMin')->update(['StatusValue' => $StatusValue]);
  370. $admin_id = session('admin')->id;
  371. CreateLog::SystemStatusInfo_log($admin_id, 'WithDrawPoint');
  372. return apiReturnSuc('success');
  373. }
  374. $result = DB::table('QPAccountsDB.dbo.SystemStatusInfo')->where('StatusName', 'WithDrawMin')->value('StatusValue');
  375. $result /= 100;
  376. return view('admin.Withdrawal.WithDrawMin', ['info' => $result]);
  377. }
  378. // 风险评估
  379. public function risk_assessment(Request $request, $UserID)
  380. {
  381. $gear = $request->gear ?: '';
  382. $info = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo as ai')
  383. ->join('QPAccountsDB.dbo.AccountsInfo as ain', 'ai.RegisterIP', 'ain.RegisterIP')
  384. ->where('ai.UserID', $UserID)
  385. ->whereNotNull('ai.RegisterIP')
  386. ->selectRaw('count(1) count,ai.RegisterIP,ai.RegisterDate,ai.GameID,ai.NickName')
  387. ->groupBy('ai.GameID', 'ai.NickName', 'ai.RegisterIP', 'ai.RegisterDate')
  388. ->first();
  389. // 总对局数
  390. $info->playerNum = DB::connection('read')->table(TableName::QPRecordDB() . 'RecordUserGameCount')
  391. ->where('UserID', $UserID)
  392. ->sum('Cnt');
  393. // 推广佣金已领取 。
  394. $info->commission = DB::connection('read')->table('QPRecordDB.dbo.RecordUserScoreStatisticsNew')
  395. ->where('ScoreType', 53)
  396. ->where('UserID', $UserID)
  397. ->selectRaw('IsNull(sum(Score),0) Score')
  398. ->first()->Score / NumConfig::NUM_VALUE ?? 0;
  399. // 推广佣金可领取 。
  400. $waitCommission = DB::connection('read')->table('QPAccountsDB.dbo.UserAgent')
  401. ->where('UserID', $UserID)
  402. ->selectRaw('IsNull((Balance1 + Balance2),0) as Balance')
  403. ->first()->Balance ?? 0;
  404. $info->waitCommission = $waitCommission > 0 ? $waitCommission / NumConfig::NUM_VALUE : 0;
  405. //今日彩金 -- 今日提现 -- 今日盈利 -- 今日充值
  406. $info->today = DB::connection('read')->table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
  407. ->where('UserID', $UserID)
  408. ->where('DateID', date('Ymd'))
  409. ->selectRaw('IsNull(sum(Handsel),0)Handsel,IsNull(sum(Withdraw),0) Withdraw,IsNull((sum(WinScore) + sum(LostScore)), 0) Score,sum(Recharge) Recharge')
  410. ->first();
  411. // 全部彩金 -- 总提现 -- 总盈利 -- 总充值
  412. $info->total = DB::connection('read')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  413. ->where('UserID', $UserID)
  414. ->selectRaw('IsNull(sum(Handsel),0)Handsel,IsNull(sum(Withdraw),0) Withdraw,IsNull((sum(WinScore) + sum(LostScore)) , 0) Score,sum(Recharge) Recharge')
  415. ->first();
  416. isset($info->total->Score) && $info->total->Score = number_float($info->total->Score / NumConfig::NUM_VALUE);
  417. isset($info->total->Handsel) && $info->total->Handsel = number_float($info->total->Handsel / NumConfig::NUM_VALUE);
  418. isset($info->total->Withdraw) && $info->total->Withdraw = number_float($info->total->Withdraw / NumConfig::NUM_VALUE);
  419. isset($info->total->Recharge) && $info->total->Recharge = number_float($info->total->Recharge);
  420. isset($info->today->Score) && $info->today->Score = number_float($info->today->Score / NumConfig::NUM_VALUE);
  421. isset($info->today->Handsel) && $info->today->Handsel = number_float($info->today->Handsel / NumConfig::NUM_VALUE);
  422. isset($info->today->Withdraw) && $info->today->Withdraw = number_float($info->today->Withdraw / NumConfig::NUM_VALUE);
  423. isset($info->today->Recharge) && $info->today->Recharge = number_float($info->today->Recharge);
  424. // 游戏对局数--分游戏
  425. $gameCount = DB::connection('read')->table(TableName::QPRecordDB() . 'RecordUserGameCount')
  426. ->where('UserID', $UserID)
  427. ->select('Cnt', 'GameID')
  428. ->pluck('Cnt', 'GameID')->toArray();
  429. // 提现完成时间
  430. $info->finalTime = DB::connection('read')->table('QPAccountsDB.dbo.withdraw_notify')->where('user_id', $UserID)->orderByDesc('created_at')->value('finish_at');
  431. $accountsInfo=new AccountsInfo();
  432. $info->BankNO=$accountsInfo->sameBankNo($UserID);
  433. $info->sameWithDrawName=$accountsInfo->sameWithDrawBankNameByUserID($UserID);
  434. $info->sameWithDrawMail=$accountsInfo->sameWithDrawEmailByUserID($UserID);
  435. // 用户标签
  436. $getUserTab = StoredProcedure::getUserTab($UserID);
  437. $TabType = $getUserTab[0]->TabType ?? '';
  438. // if (!empty($getUserTab) && $TabType == 1) {
  439. //
  440. // $Type12 = $getUserTab[0]->Type12 ?? 0;
  441. //
  442. // $userTab = DB::connection('read')->table('QPAccountsDB.dbo.AccountsTabExplain as el')
  443. // ->where('TabID', $Type12)
  444. // ->first()->TypeName;
  445. // }
  446. return view('admin.Withdrawal.risk_assessment', [
  447. 'info' => $info,
  448. 'gear' => $gear,
  449. 'userTab' => $userTab ?? '',
  450. 'gameCount' => $gameCount,
  451. 'gameName'=>config("games.gameName")
  452. ]);
  453. }
  454. // 数据查重
  455. public function duplicate_checking(Request $request)
  456. {
  457. $type = $request->type ?: '';
  458. $val = $request->val ?: '';
  459. $list = [];
  460. switch ($type) {
  461. case 'RegisterIP':
  462. $type = '注册IP';
  463. $list = DB::table('QPAccountsDB.dbo.AccountsInfo')
  464. ->where('RegisterIP', $val)
  465. ->where('IsAndroid', 0)
  466. ->select('GameID', 'UserID')
  467. ->get();
  468. break;
  469. case 'BankNo':
  470. $type = '卡号';
  471. $list = DB::table('QPAccountsDB.dbo.AccountWithDrawInfo as di')
  472. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'di.UserID', 'ai.UserID')
  473. ->select('ai.GameID', 'ai.UserID')
  474. ->where('di.BankNo', $val)
  475. ->where('IsAndroid', 0)
  476. ->get();
  477. break;
  478. case 'LastLogonIP':
  479. $type = '登录IP';
  480. $list = DB::table('QPAccountsDB.dbo.AccountsInfo')
  481. ->where('LastLogonIP', $val)
  482. ->where('IsAndroid', 0)
  483. ->select('GameID', 'UserID')
  484. ->get();
  485. break;
  486. }
  487. return view('admin.Withdrawal.duplicate_checking', ['list' => $list, 'type' => $type]);
  488. }
  489. // 添加备注
  490. public function remarks(Request $request, $id)
  491. {
  492. $remark = $request->remark ?: '';
  493. $type = $request->type ?: 1;
  494. $admin_id = session('admin')->id;
  495. $RecordData = [
  496. 'admin_id' => $admin_id,
  497. 'remarks' => $remark,
  498. 'RecordID' => $id,
  499. 'create_at' => date('Y-m-d H:i:s'),
  500. 'update_at' => date('Y-m-d H:i:s'),
  501. 'type' => $type
  502. ];
  503. DB::connection('write')->table('QPAccountsDB.dbo.AccountsRecord')->updateOrInsert(['RecordID' => $id, 'type' => $type], $RecordData);
  504. return apiReturnSuc();
  505. }
  506. // 提现回收
  507. public function recovery($id)
  508. {
  509. $admin_id = session('admin')->id;
  510. $first = DB::table('QPAccountsDB.dbo.OrderWithDraw')
  511. ->where('RecordID', $id)
  512. ->select('UserID', 'WithDraw', 'State', 'ServiceFee', 'OrderId', 'RecordID', 'locking')
  513. ->first();
  514. if (!$first) {
  515. return apiReturnFail('订单不存在');
  516. }
  517. if ($first->State != 1) {
  518. return apiReturnFail('订单重复操作');
  519. }
  520. // 添加提现回收数据
  521. $data = [
  522. 'UserID' => $first->UserID,
  523. 'WithDraw' => $first->WithDraw,
  524. 'ServiceFee' => $first->ServiceFee,
  525. 'OrderId' => $first->OrderId,
  526. 'admin_id' => $admin_id
  527. ];
  528. // DB::table('QPAccountsDB.dbo.WithDrawRecovery')->insert($data);
  529. // 添加提现记录
  530. $RecordData = [
  531. 'admin_id' => $admin_id,
  532. 'before_state' => $first->State,
  533. 'after_state' => 4,
  534. 'RecordID' => $first->RecordID,
  535. 'create_at' => date('Y-m-d H:i:s'),
  536. 'update_at' => date('Y-m-d H:i:s')
  537. ];
  538. // 添加用户提现操作记录
  539. DB::table('QPAccountsDB.dbo.AccountsRecord')->updateOrInsert(['RecordID' => $first->RecordID, 'type' => 1], $RecordData);
  540. // 修改订单状态
  541. DB::table('QPAccountsDB.dbo.OrderWithDraw')
  542. ->where('RecordID', $first->RecordID)
  543. ->update(['State' => 4, 'locking' => 0]);
  544. // 发送邮件
  545. // $TitleString = 'Your withdrawal order application failed';
  546. // $TextString = "1.Your withdrawal order: {$first->OrderId} application failed.
  547. // 2.Reasons for order submission failure:The system has detected malicious cheating on your account and recovered your chips
  548. // 3.If you have any questions, please contact customer service.
  549. // ";
  550. PrivateMail::RecoveryMail($first->UserID,$first->OrderId);
  551. return apiReturnSuc();
  552. }
  553. // 锁定订单
  554. public function locking($id)
  555. {
  556. $first = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $id)->first();
  557. if (!$first) {
  558. return apiReturnFail('订单不存在!');
  559. }
  560. if ($first->locking == 1) { // 解锁
  561. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')
  562. ->where('RecordID', $id)
  563. ->update(['locking' => 0]);
  564. } else { // 加锁
  565. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')
  566. ->where('RecordID', $id)
  567. ->update(['locking' => 1]);
  568. }
  569. return apiReturnSuc();
  570. }
  571. // 提现免审
  572. public function exempt_review()
  573. {
  574. $list = DB::connection('read')->table('agent.dbo.withdrawal_position_config as wp')
  575. ->leftJoin('agent.dbo.admin_configs as cf', function ($join) {
  576. $join->on('cf.config_value', '=', 'wp.agent');
  577. $join->where('cf.type', 'cash');
  578. })
  579. ->select('wp.*', 'cf.name as agent_name')
  580. ->paginate(10);
  581. foreach ($list as $value) {
  582. // $value->quota = $value->quota / NumConfig::NUM_VALUE;
  583. // $value->total_quota = $value->total_quota / NumConfig::NUM_VALUE;
  584. $value->useQuota = DB::connection('read')->table('agent.dbo.withdrawal_position_log')
  585. ->whereDate('create_at', date('Y-m-d'))
  586. ->where('config_id', $value->id)
  587. ->sum('use_quota') / NumConfig::NUM_VALUE;
  588. }
  589. return view('admin.Withdrawal.exempt_review', [
  590. 'list' => $list,
  591. ]);
  592. }
  593. // 免审添加
  594. public function exempt_review_add(Request $request)
  595. {
  596. if ($request->isMethod('get')) {
  597. $agent = DB::table('agent.dbo.admin_configs')
  598. ->where('type', 'cash')
  599. ->where('status', 1)
  600. ->get();
  601. return view('admin.Withdrawal.exempt_review_add', [
  602. 'agent' => $agent
  603. ]);
  604. } else {
  605. $admin_id = session('admin')['id'];
  606. $post = $request->all();
  607. if (isset($post['recharge_checkbox'])) {
  608. $first = DB::table('agent.dbo.withdrawal_position_config')
  609. ->where('recharge_min', '>=', $post['recharge_min'])
  610. ->where('recharge_max', '<=', $post['recharge_max'])
  611. ->first();
  612. if ($first) {
  613. return apiReturnFail('已有重复的充值额度档位!');
  614. }
  615. }
  616. $data = [
  617. 'name' => $post['name'],
  618. 'recharge_min' => $post['recharge_min'],
  619. 'recharge_max' => $post['recharge_max'],
  620. 'type' => $post['type'],
  621. 'quota' => $post['quota'] ?: 0,
  622. 'total_quota' => $post['total_quota'],
  623. 'admin_id' => $admin_id,
  624. 'status' => $post['status'],
  625. 'agent' => $post['agent'],
  626. 'draw_gt_recharge' => $post['draw_gt_recharge'],
  627. 'draw_total' => $post['draw_total'],
  628. 'draw_bi' => $post['draw_bi'],
  629. 'game_time' => $post['game_time'] * 60, // 小时转换分
  630. 'recharge_checkbox' => isset($post['recharge_checkbox']) ? 1 : 0 // 小时转换分
  631. ];
  632. DB::table('agent.dbo.withdrawal_position_config')->insert($data);
  633. return apiReturnSuc();
  634. }
  635. }
  636. // 免审修改
  637. public function exempt_review_update(Request $request, $id)
  638. {
  639. if ($request->isMethod('get')) {
  640. // 获取所有代付渠道配置(包括关闭的)
  641. $agent = DB::table('agent.dbo.admin_configs')
  642. ->where('type', 'cash')
  643. ->get();
  644. $info = DB::table('agent.dbo.withdrawal_position_config')->find($id);
  645. $info->game_time = $info->game_time > 0 ? $info->game_time / 60 : 0;
  646. return view('admin.Withdrawal.exempt_review_update', [
  647. 'info' => $info,
  648. 'agent' => $agent
  649. ]);
  650. } else {
  651. $admin_id = session('admin')['id'];
  652. $post = $request->all();
  653. if (isset($post['recharge_checkbox'])) {
  654. $first = DB::table('agent.dbo.withdrawal_position_config')
  655. ->where('recharge_min', '>=', $post['recharge_min'])
  656. ->where('recharge_max', '<=', $post['recharge_max'])
  657. ->first();
  658. if ($first && $id != $first->id) {
  659. return apiReturnFail('已有重复的充值额度档位!');
  660. }
  661. }
  662. $data = [
  663. 'name' => $post['name'],
  664. 'recharge_min' => $post['recharge_min'],
  665. 'recharge_max' => $post['recharge_max'],
  666. 'type' => $post['type'],
  667. 'quota' => $post['quota'] ?: 0,
  668. 'total_quota' => $post['total_quota'],
  669. 'admin_id' => $admin_id,
  670. 'status' => $post['status'],
  671. 'draw_gt_recharge' => $post['draw_gt_recharge'],
  672. 'draw_total' => $post['draw_total'],
  673. 'draw_bi' => $post['draw_bi'],
  674. 'game_time' => $post['game_time'] * 60, // 小时转换分
  675. 'recharge_checkbox' => isset($post['recharge_checkbox']) ? 1 : 0
  676. ];
  677. DB::table('agent.dbo.withdrawal_position_config')->where('id', $id)->update($data);
  678. return apiReturnSuc();
  679. }
  680. }
  681. // 提现渠道配置(新增和修改权重)
  682. public function cashier_channel_config(Request $request)
  683. {
  684. if ($request->isMethod('get')) {
  685. // 获取所有提现渠道
  686. $list = DB::table('agent.dbo.admin_configs')
  687. ->leftJoin('agent.dbo.admin_users as u', 'admin_configs.admin_id', '=', 'u.id')
  688. ->select('admin_configs.*', 'u.account')
  689. ->where('admin_configs.type', 'cash')
  690. ->orderBy('admin_configs.id', 'asc')
  691. ->get();
  692. return view('admin.Withdrawal.cashier_channel_config', ['list' => $list]);
  693. } else {
  694. // POST 提交 - 修改权重
  695. $validator = Validator::make($request->all(), [
  696. 'config.*.sort' => 'required|int',
  697. 'config.*.status' => 'required|in:1,-1',
  698. ]);
  699. if ($validator->fails()) {
  700. return apiReturnFail($validator->errors()->first());
  701. }
  702. $config = $request->input('config');
  703. // 验证权重总和
  704. $opened = array_filter($config, function ($item) {
  705. return $item['status'] == 1;
  706. });
  707. if (empty($opened)) {
  708. return apiReturnFail('至少需要开启一个提现渠道');
  709. }
  710. if (array_sum(array_column($opened, 'sort')) != 100) {
  711. return apiReturnFail('权重值分配不正确,开启的渠道权重总和必须为100');
  712. }
  713. // 更新配置
  714. foreach ($config as $id => $v) {
  715. $v['admin_id'] = session('admin')['id'];
  716. $v['updated_at'] = date('Y-m-d H:i:s');
  717. if ($v['status'] == -1) {
  718. $v['sort'] = 0;
  719. }
  720. DB::table('agent.dbo.admin_configs')->where('id', $id)->update($v);
  721. }
  722. return apiReturnSuc();
  723. }
  724. }
  725. // 新增提现渠道
  726. public function cashier_channel_add(Request $request)
  727. {
  728. if ($request->isMethod('get')) {
  729. return view('admin.Withdrawal.cashier_channel_add');
  730. } else {
  731. // POST 提交
  732. $validator = Validator::make($request->all(), [
  733. 'name' => 'required',
  734. 'config_value' => 'required',
  735. 'status' => 'required|in:1,-1',
  736. ]);
  737. if ($validator->fails()) {
  738. return apiReturnFail($validator->errors()->first());
  739. }
  740. // 获取最大ID
  741. $maxId = DB::table('agent.dbo.admin_configs')->max('id');
  742. $data = [
  743. 'id' => $maxId + 1,
  744. 'name' => $request->name,
  745. 'config_key' => $request->config_key ?: $request->name,
  746. 'config_value' => $request->config_value,
  747. 'type' => 'cash',
  748. 'status' => $request->status,
  749. 'sort' => (int)($request->sort ?: 0),
  750. 'remarks' => $request->remarks ?: '',
  751. 'admin_id' => session('admin')['id'],
  752. 'created_at' => date('Y-m-d H:i:s'),
  753. 'updated_at' => date('Y-m-d H:i:s'),
  754. ];
  755. try {
  756. DB::table('agent.dbo.admin_configs')->insert($data);
  757. return apiReturnSuc();
  758. } catch (\Exception $e) {
  759. return apiReturnFail('添加失败:' . $e->getMessage());
  760. }
  761. }
  762. }
  763. // 修改提现渠道
  764. public function cashier_channel_update(Request $request, $id)
  765. {
  766. if ($request->isMethod('get')) {
  767. $info = DB::table('agent.dbo.admin_configs')
  768. ->where('id', $id)
  769. ->where('type', 'cash')
  770. ->first();
  771. if (!$info) {
  772. return redirect()->back()->with('error', '渠道不存在');
  773. }
  774. return view('admin.Withdrawal.cashier_channel_update', ['info' => $info]);
  775. } else {
  776. // POST 提交
  777. $validator = Validator::make($request->all(), [
  778. 'name' => 'required',
  779. 'config_value' => 'required',
  780. 'status' => 'required|in:1,-1',
  781. ]);
  782. if ($validator->fails()) {
  783. return apiReturnFail($validator->errors()->first());
  784. }
  785. $data = [
  786. 'name' => $request->name,
  787. 'config_key' => $request->config_key ?: $request->name,
  788. 'config_value' => $request->config_value,
  789. 'status' => $request->status,
  790. 'sort' => (int)($request->sort ?: 0),
  791. 'remarks' => $request->remarks ?: '',
  792. 'admin_id' => session('admin')['id'],
  793. 'updated_at' => date('Y-m-d H:i:s'),
  794. ];
  795. try {
  796. DB::table('agent.dbo.admin_configs')
  797. ->where('id', $id)
  798. ->where('type', 'cash')
  799. ->update($data);
  800. return apiReturnSuc();
  801. } catch (\Exception $e) {
  802. return apiReturnFail('修改失败:' . $e->getMessage());
  803. }
  804. }
  805. }
  806. // 免审开关
  807. public function block(Request $request, $id)
  808. {
  809. $status = $request->status ?: '';
  810. if (empty($status)) {
  811. return apiReturnFail('参数错误!');
  812. }
  813. DB::table('agent.dbo.withdrawal_position_config')->where('id', $id)->update(['status' => $status]);
  814. return apiReturnSuc();
  815. }
  816. // 用户提充统计
  817. public function userWithdrawalStatistics(Request $request)
  818. {
  819. $date = $request->date ?: date('Y-m-d');
  820. $excel = $request->excel ?: 0;
  821. $gameID = $request->GameID ?: '';
  822. $channel = $request->Channel ?: '';
  823. [$list, $channelList] = $this->logic->userWithdrawalStatistics($date, $excel, $gameID, $channel);
  824. return view('admin.Withdrawal.userWithdrawalStatistics', compact('list', 'channelList', 'date', 'gameID','channel'));
  825. }
  826. // 回调补偿
  827. public function compensateNotify($RecordID, Request $request)
  828. {
  829. $redisKey = 'Withdrawal_compensateNotify_'.$RecordID;
  830. $res = SetNXLock::getExclusiveLock($redisKey, 5);
  831. if (!$res) {
  832. return apiReturnFail('操作频繁');
  833. }
  834. $withdrawOrder = DB::table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $RecordID)
  835. ->first();
  836. if (!$withdrawOrder) {
  837. SetNXLock::release($redisKey);
  838. return apiReturnFail('订单不存在');
  839. }
  840. if ($withdrawOrder->State != 5 && $withdrawOrder->State != 7) {
  841. SetNXLock::release($redisKey);
  842. return apiReturnFail('订单状态不正确, 请刷新页面重试');
  843. }
  844. Log::info('提现模拟回调', [
  845. 'recordID' => $RecordID,
  846. 'params' => $request->all()
  847. ]);
  848. /** @var WithdrawalLogic $logic */
  849. $logic = app()->make(WithdrawalLogic::class);
  850. $res = $logic->compensateNotify($withdrawOrder);
  851. SetNXLock::release($redisKey);
  852. if ($res) {
  853. return apiReturnSuc();
  854. }
  855. return apiReturnFail('修改失败');
  856. }
  857. public function monitorOrderFailCall($OrderID, Request $request)
  858. {
  859. $redisKey = 'Withdrawal_monitorOrderFailCall_' . $OrderID;
  860. $res = SetNXLock::getExclusiveLock($redisKey, 5);
  861. if (!$res) {
  862. return apiReturnFail('操作频繁');
  863. }
  864. $withdrawOrder = DB::table('QPAccountsDB.dbo.OrderWithDraw')
  865. ->where('OrderId', $OrderID)
  866. ->first();
  867. if (!$withdrawOrder) {
  868. SetNXLock::release($redisKey);
  869. return apiReturnFail('订单不存在');
  870. }
  871. if ($withdrawOrder->State != 5 && $withdrawOrder->State != 7) {
  872. SetNXLock::release($redisKey);
  873. return apiReturnFail('订单状态不正确, 请刷新页面重试');
  874. }
  875. Log::info('提现手动设置失败', [
  876. 'OrderID' => $OrderID,
  877. 'params' => $request->all()
  878. ]);
  879. $agent = $withdrawOrder->agent;
  880. $TakeMoney = $withdrawOrder->WithDraw + $withdrawOrder->ServiceFee;
  881. $msg = (new CashierMessage())
  882. ->returnMsg($agent)
  883. ->msgStr('Encomenda rejeitada pelo banco');
  884. $bonus = '30000,' . $TakeMoney;
  885. PrivateMail::failMail($withdrawOrder->UserID, $OrderID, $TakeMoney, $msg, $bonus);
  886. // 修改订单状态为失败
  887. $withdraw_data = ['State' => 6, 'agent' => $agent];
  888. $notify_data = ['state' => 2];
  889. $RecordData = [
  890. 'before_state' => $withdrawOrder->State,
  891. 'after_state' => $withdraw_data['State'] ?? 0,
  892. 'RecordID' => $withdrawOrder->RecordID,
  893. 'update_at' => date('Y-m-d H:i:s')
  894. ];
  895. // 添加用户提现操作记录
  896. DB::connection('write')->table('QPAccountsDB.dbo.AccountsRecord')->updateOrInsert(['RecordID' => $withdrawOrder->RecordID, 'type' => 1], $RecordData);
  897. DB::connection('write')->table('QPAccountsDB.dbo.withdraw_notify')->updateOrInsert(['order_sn' => $OrderID], $notify_data);
  898. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderId', $withdrawOrder->OrderId)->update($withdraw_data);
  899. if (isset($withdraw_data['State']) && $withdraw_data['State'] == 2) {
  900. // 单控标签
  901. StoredProcedure::user_label($withdrawOrder->UserID, 2, $TakeMoney);
  902. // 渠道后台埋点
  903. (new LogDayStatisticalByDayAndChannel())->updateData($withdrawOrder->UserID, 2);
  904. }
  905. SetNXLock::release($redisKey);
  906. return apiReturnSuc();
  907. }
  908. public function drawBaseChangeLog(Request $request)
  909. {
  910. $query = AddDrawBase::query();
  911. if ($request->input('GameID')) {
  912. $userID = AccountsInfo::where('GameID', $request->input('GameID'))->value('UserID');
  913. $query->where('user_id', intval($userID));
  914. }
  915. $officials = DB::table('QPAccountsDB.dbo.IDWhiteUser')->pluck('UserID')->toArray();
  916. $list = $query->orderBy('id', 'desc')->paginate(20);
  917. return view('admin.Withdrawal.draw_base_change_log', [
  918. 'list' => $list,
  919. 'request' => $request,
  920. 'officials' => $officials
  921. ]);
  922. }
  923. // 回调补偿
  924. public function initData($RecordID, Request $request)
  925. {
  926. $redisKey = 'Withdrawal_init_'.$RecordID;
  927. $res = SetNXLock::getExclusiveLock($redisKey, 5);
  928. if (!$res) {
  929. return apiReturnFail('操作频繁');
  930. }
  931. $withdrawOrder = DB::table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $RecordID)
  932. ->first();
  933. if (!$withdrawOrder) {
  934. SetNXLock::release($redisKey);
  935. return apiReturnFail('订单不存在');
  936. }
  937. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')
  938. ->where('RecordID', $withdrawOrder->RecordID)
  939. ->update(['State' => 1,'OrderId' => $withdrawOrder->OrderId.rand(1,9)]);
  940. SetNXLock::release($redisKey);
  941. return apiReturnSuc();
  942. }
  943. /**
  944. * 同步最新提款账号信息
  945. * 只针对第三方订单失败(State=6)且金额小于30的订单
  946. */
  947. public function syncAccountInfo(Request $request, $RecordID)
  948. {
  949. try {
  950. // 获取订单信息
  951. $order = DB::connection('read')->table('QPAccountsDB.dbo.OrderWithDraw')
  952. ->where('RecordID', $RecordID)
  953. ->first();
  954. if (!$order) {
  955. return apiReturnFail('订单不存在');
  956. }
  957. // 检查订单状态和金额
  958. if ($order->State != 6) {
  959. return apiReturnFail('只能同步第三方订单失败的订单');
  960. }
  961. // 金额小于30(WithDraw字段是decimal(10,2),所以30就是30.00)
  962. if ($order->WithDraw >= 3000) {
  963. return apiReturnFail('只能同步金额小于30的订单');
  964. }
  965. // 获取最新的账号信息
  966. $latestInfo = DB::connection('read')->table('QPAccountsDB.dbo.AccountWithDrawInfo')
  967. ->where('UserID', $order->UserID)
  968. ->first();
  969. if (!$latestInfo) {
  970. return apiReturnFail('用户账号信息不存在');
  971. }
  972. // 比较需要同步的字段
  973. $fieldsToCompare = [
  974. 'BankUserName',
  975. 'EmailAddress',
  976. 'PhoneNumber',
  977. 'PixNum',
  978. 'PixType',
  979. 'BankNO',
  980. 'AccountsBank',
  981. 'IFSCNumber',
  982. 'PANNumber',
  983. 'AdhaarNumber',
  984. 'BranchBank'
  985. ];
  986. $isSame = true;
  987. $updateData = [];
  988. foreach ($fieldsToCompare as $field) {
  989. $orderValue = trim($order->$field ?? '');
  990. $latestValue = trim($latestInfo->$field ?? '');
  991. if ($orderValue !== $latestValue) {
  992. $isSame = false;
  993. $updateData[$field] = $latestValue;
  994. }
  995. }
  996. // 如果信息一致,返回失败
  997. if ($isSame) {
  998. return apiReturnFail('账号信息一致,无需同步');
  999. }
  1000. // 更新订单信息
  1001. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')
  1002. ->where('RecordID', $RecordID)
  1003. ->update($updateData);
  1004. return apiReturnSuc(['updated_fields' => array_keys($updateData)], '同步成功');
  1005. } catch (\Exception $e) {
  1006. Log::error('同步账号信息失败', [
  1007. 'RecordID' => $RecordID,
  1008. 'error' => $e->getMessage()
  1009. ]);
  1010. return apiReturnFail('同步失败:' . $e->getMessage());
  1011. }
  1012. }
  1013. /**
  1014. * 获取订单账号信息(用于编辑)
  1015. */
  1016. public function getAccountInfo($RecordID)
  1017. {
  1018. try {
  1019. $order = DB::connection('read')->table('QPAccountsDB.dbo.OrderWithDraw')
  1020. ->where('RecordID', $RecordID)
  1021. ->first();
  1022. if (!$order) {
  1023. return apiReturnFail('订单不存在');
  1024. }
  1025. // 检查订单状态
  1026. if ($order->State != 6) {
  1027. return apiReturnFail('只能编辑失败订单的账号信息');
  1028. }
  1029. return apiReturnSuc([
  1030. 'RecordID' => $order->RecordID,
  1031. 'UserID' => $order->UserID,
  1032. 'BankUserName' => $order->BankUserName ?? '',
  1033. 'EmailAddress' => $order->EmailAddress ?? '',
  1034. 'PhoneNumber' => $order->PhoneNumber ?? '',
  1035. 'PixNum' => $order->PixNum ?? '',
  1036. 'PixType' => $order->PixType ?? 0,
  1037. 'BankNO' => $order->BankNO ?? '',
  1038. 'AccountsBank' => $order->AccountsBank ?? '',
  1039. 'IFSCNumber' => $order->IFSCNumber ?? '',
  1040. 'PANNumber' => $order->PANNumber ?? '',
  1041. 'AdhaarNumber' => $order->AdhaarNumber ?? '',
  1042. 'BranchBank' => $order->BranchBank ?? '',
  1043. ]);
  1044. } catch (\Exception $e) {
  1045. Log::error('获取订单账号信息失败', [
  1046. 'RecordID' => $RecordID,
  1047. 'error' => $e->getMessage()
  1048. ]);
  1049. return apiReturnFail('获取信息失败:' . $e->getMessage());
  1050. }
  1051. }
  1052. /**
  1053. * 更新订单账号信息(同时更新OrderWithDraw和AccountWithDrawInfo)
  1054. */
  1055. public function updateAccountInfo(Request $request, $RecordID)
  1056. {
  1057. try {
  1058. $validator = Validator::make($request->all(), [
  1059. 'BankUserName' => 'nullable|string|max:100',
  1060. 'EmailAddress' => 'nullable|string|max:80',
  1061. 'PhoneNumber' => 'nullable|string|max:20',
  1062. 'PixNum' => 'nullable|string|max:32',
  1063. 'PixType' => 'nullable|integer|in:0,1,2,3',
  1064. 'BankNO' => 'nullable|string|max:30',
  1065. 'AccountsBank' => 'nullable|string|max:100',
  1066. 'IFSCNumber' => 'nullable|string|max:20',
  1067. 'PANNumber' => 'nullable|string|max:10',
  1068. 'AdhaarNumber' => 'nullable|string|max:80',
  1069. 'BranchBank' => 'nullable|string|max:100',
  1070. ]);
  1071. if ($validator->fails()) {
  1072. return apiReturnFail($validator->errors()->first());
  1073. }
  1074. // 获取订单信息
  1075. $order = DB::connection('read')->table('QPAccountsDB.dbo.OrderWithDraw')
  1076. ->where('RecordID', $RecordID)
  1077. ->first();
  1078. if (!$order) {
  1079. return apiReturnFail('订单不存在');
  1080. }
  1081. // 检查订单状态
  1082. if ($order->State != 6) {
  1083. return apiReturnFail('只能编辑失败订单的账号信息');
  1084. }
  1085. // 准备更新数据
  1086. $updateData = [];
  1087. $fields = [
  1088. 'BankUserName', 'EmailAddress', 'PhoneNumber', 'PixNum', 'PixType',
  1089. 'BankNO', 'AccountsBank', 'IFSCNumber', 'PANNumber', 'AdhaarNumber', 'BranchBank'
  1090. ];
  1091. foreach ($fields as $field) {
  1092. if ($request->has($field)) {
  1093. $updateData[$field] = trim($request->input($field, ''));
  1094. }
  1095. }
  1096. if (empty($updateData)) {
  1097. return apiReturnFail('没有需要更新的数据');
  1098. }
  1099. DB::beginTransaction();
  1100. try {
  1101. // 更新 OrderWithDraw 表
  1102. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')
  1103. ->where('RecordID', $RecordID)
  1104. ->update($updateData);
  1105. // 更新 AccountWithDrawInfo 表
  1106. DB::connection('write')->table('QPAccountsDB.dbo.AccountWithDrawInfo')
  1107. ->where('UserID', $order->UserID)
  1108. ->update($updateData);
  1109. DB::commit();
  1110. // 记录操作日志
  1111. $admin_id = session('admin')->id ?? 0;
  1112. (new AccountsRecordLogic())->create_record($RecordID, $order->State, $order->State, '编辑提款账号信息', $admin_id, 2);
  1113. return apiReturnSuc(['updated_fields' => array_keys($updateData)], '更新成功');
  1114. } catch (\Exception $e) {
  1115. DB::rollBack();
  1116. throw $e;
  1117. }
  1118. } catch (\Exception $e) {
  1119. Log::error('更新订单账号信息失败', [
  1120. 'RecordID' => $RecordID,
  1121. 'error' => $e->getMessage(),
  1122. 'data' => $request->all()
  1123. ]);
  1124. return apiReturnFail('更新失败:' . $e->getMessage());
  1125. }
  1126. }
  1127. public function withdrawRank(Request $request)
  1128. {
  1129. $date = Carbon::now();
  1130. $start_time = $request->input('start_time', $date->format('Y-m-d'));
  1131. $end_time = $request->input('end_time', $date->format('Y-m-d'));
  1132. $where = [];
  1133. !empty($start_time) && $where[] = ['DateID', '>=', Carbon::parse($start_time)->format('Ymd')];
  1134. !empty($end_time) && $where[] = ['DateID', '<', Carbon::parse($end_time)->addDay(1)->format('Ymd')];
  1135. $order_sql = 'Withdraw DESC';
  1136. if (true) {
  1137. $list = DB::table(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as ds')
  1138. ->where('Withdraw', '>', 0)
  1139. ->where($where)
  1140. ->join(TableName::QPAccountsDB() . 'AccountsInfo as ai', 'ds.UserID', 'ai.UserID')
  1141. ->leftjoin('QPAccountsDB.dbo.AccountPhone as ap', 'ds.UserID', 'ap.UserID')
  1142. ->select('ai.UserID', 'ai.GameID', 'ai.NickName', 'ai.Channel', 'ap.PhoneNum', 'ai.PlayTimeCount', 'ai.LastLogonDate', 'ai.RegisterDate')
  1143. ->orderByRaw($order_sql)
  1144. ->paginate(10);
  1145. $rechargeSum = DB::table(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as ds')
  1146. ->where('Withdraw', '>', 0)
  1147. ->where($where)
  1148. ->selectRaw('sum(ds.Withdraw) Withdraw,UserID')
  1149. ->groupBy('UserID')
  1150. ->pluck('Withdraw', 'UserID')->toArray();
  1151. $UserIDs = [];
  1152. foreach ($list as $value) {
  1153. $UserIDs[] = $value->UserID;
  1154. }
  1155. foreach ($list as $key => &$value) {
  1156. $second = $value->PlayTimeCount;
  1157. $day = floor($second / (3600 * 24));
  1158. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  1159. $hour = floor($second / 3600);
  1160. $second = $second % 3600;//除去整小时之后剩余的时间
  1161. $minute = floor($second / 60);
  1162. //返回字符串
  1163. $value->Experience = $day . '天' . $hour . '小时' . $minute . '分';
  1164. $value->type = '玩家';
  1165. $value->rank = $key + 1;
  1166. $value->money = $rechargeSum[$value->UserID] ?? 0;
  1167. $value->money = $value->money /100;
  1168. $value->time = Carbon::parse(now())->diffInDays($value->LastLogonDate, true);
  1169. }
  1170. return view('admin.Withdrawal.rank', [
  1171. 'list' => $list,
  1172. 'end_time' => $end_time,
  1173. 'start_time' => $start_time,
  1174. ]);
  1175. }
  1176. }
  1177. public function nameStatics(){
  1178. // DB::table(TableName::QPAccountsDB() . 'OrderWithDraw')
  1179. // ->selectRaw('count(distinct (UserID)) as nums,BankUserName')
  1180. // ->groupBy("BankUserName")
  1181. // ->orderBy("nums","desc");
  1182. $sql = "select nums,BankUserName from (select count(distinct (UserID)) as nums,BankUserName from QPAccountsDB.dbo.OrderWithDraw group by BankUserName ) s where nums>1";
  1183. // $sql = "select * from OrderWithDraw where BankUserName in (select BankUserName from (select count(distinct (UserID)) as nums,BankUserName from QPAccountsDB.dbo.OrderWithDraw group by BankUserName ) s where nums>1) order by BankUserName";
  1184. $multiNames = DB::select($sql);
  1185. $sql="select nums,EmailAddress from (select count(distinct (UserID)) as nums,EmailAddress from QPAccountsDB.dbo.OrderWithDraw group by EmailAddress ) s where nums>1";
  1186. $multiEmails = DB::select($sql);
  1187. // $res=DB::table(TableName::QPAccountsDB() . 'OrderWithDraw')
  1188. // ->selectRaw('count(distinct (UserID)) as nums')
  1189. // ->where("EmailAddress","ciceroedsondasilvasantos19@gmail.com")
  1190. // ->first();
  1191. // print_r($res)
  1192. return view('admin.Withdrawal.statics', [
  1193. 'names' => $multiNames,
  1194. 'emails' => $multiEmails,
  1195. ]);
  1196. // select count(distinct (UserID)) as nums,BankUserName from QPAccountsDB.dbo.OrderWithDraw group by BankUserName order by nums desc;
  1197. }
  1198. }