WithdrawalController.php 59 KB

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