2
0

WithdrawalController.php 57 KB

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