WithdrawalLogic.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <?php
  2. namespace App\Http\logic\admin;
  3. use App\dao\Estatisticas\RechargeWithDraw;
  4. use App\Facade\RedisConnect;
  5. use App\Facade\TableName;
  6. use App\Game\Services\AgentSystemService;
  7. use App\Http\helper\Helper;
  8. use App\Http\helper\NumConfig;
  9. use App\Models\AccountsInfo;
  10. use App\Models\AccountWithDrawInfo;
  11. use App\Models\PrivateMail;
  12. use App\Models\Cpf;
  13. use App\Models\RecordUserDataStatistics;
  14. use App\Models\Withdrawal;
  15. use App\Models\WithdrawalChannelPositionConfig;
  16. use App\Services\CashService;
  17. use App\Services\LogDayStatisticalByDayAndChannel;
  18. use App\Services\StoredProcedure;
  19. use App\Util;
  20. use Carbon\Carbon;
  21. use Illuminate\Support\Facades\DB;
  22. use Illuminate\Support\Facades\Redis;
  23. use Illuminate\Support\Facades\Request;
  24. use Mockery\Exception;
  25. class WithdrawalLogic extends BaseLogicController
  26. {
  27. protected $agent; // 代付方
  28. public function __construct()
  29. {
  30. $this->agent = DB::table('agent.dbo.admin_configs')
  31. ->where('type', 'cash')
  32. ->where('status', 1)
  33. ->get();
  34. }
  35. public function waitWithdrawal($GameID, $withdraw_search, $withdraw, $state, $start_time, $end_time, $agent = '', $flag = false, $create_time_sort = '', $orderID = '', $final_start_time = '', $final_end_time = '', $excel = '', $Channel = '', $payState = '', $take_effect = '', $isEmpty = 0, $register_start_time = '', $register_end_time = '', $PackgeName = '',$firstWithDraw=0)
  36. {
  37. $SQL = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw as ow')
  38. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ow.UserID', 'ai.UserID')
  39. ->leftJoin('QPAccountsDB.dbo.withdraw_notify as wn', 'ow.OrderID', '=', 'wn.order_sn')
  40. ->leftJoin('QPAccountsDB.dbo.AccountsRecord as ar', function ($join) {
  41. $join->on('ow.RecordID', 'ar.RecordID');
  42. $join->where('ar.type', 1);
  43. });
  44. if($firstWithDraw<2){
  45. $SQL->join(TableName::QPRecordDB() . 'RecordUserTotalStatistics as rds', function ($join) use ($firstWithDraw) {
  46. $join->on('rds.UserID', 'ow.UserID');
  47. $join->where('rds.Withdraw', $firstWithDraw>0?'=':'<>',0);
  48. });
  49. }
  50. if (!$flag) {
  51. empty($state) && $state = 1;
  52. } else {
  53. empty($state) && $state = 100;
  54. if ($isEmpty == 0) {
  55. empty($start_time) && $start_time = date('Y-m-d 00:00:00');
  56. empty($end_time) && $end_time = date('Y-m-d 23:59:59');
  57. } elseif ($isEmpty == 2) {
  58. empty($final_start_time) && $final_start_time = date('Y-m-d 00:00:00');
  59. empty($final_end_time) && $final_end_time = date('Y-m-d 23:59:59');
  60. }
  61. }
  62. !empty($GameID) && $where[] = ['ai.GameID', $GameID];
  63. // !empty($withdraw_search) && $SQL->whereRaw("ow.WithDraw+ow.ServiceFee=$withdraw_search");
  64. // switch ($withdraw) {
  65. // case 100:
  66. // $SQL = $SQL->havingRaw('sum(ow.WithDraw + ow.ServiceFee) < ?', [100]);
  67. // break;
  68. // case 500:
  69. // $SQL = $SQL->havingRaw('sum(ow.WithDraw + ow.ServiceFee) >= ?', [100]);
  70. // $SQL = $SQL->havingRaw('sum(ow.WithDraw + ow.ServiceFee) <= ?', [500]);
  71. // break;
  72. // case 1000:
  73. // $SQL = $SQL->havingRaw('sum(ow.WithDraw + ow.ServiceFee) >= ?', [500]);
  74. // $SQL = $SQL->havingRaw('sum(ow.WithDraw + ow.ServiceFee) <= ?', [1000]);
  75. // break;
  76. // case 1001:
  77. // $SQL = $SQL->havingRaw('sum(ow.WithDraw + ow.ServiceFee) > ?', [1000]);
  78. // break;
  79. // }
  80. if (empty($state)) {
  81. $where[] = ['ow.State', '=', 0];
  82. } elseif ($state == 100) {
  83. $where[] = ['ow.State', '<>', ''];
  84. } elseif ($state == 4) {
  85. $where[] = ['ow.State', '=', $state];
  86. } else {
  87. $where[] = ['ow.State', '=', $state];
  88. }
  89. !empty($start_time) && $where[] = ['CreateDate', '>=', str_replace('T', ' ', $start_time)];
  90. !empty($end_time) && $where[] = ['CreateDate', '<=', str_replace('T', ' ', $end_time)];
  91. if (!empty($agent)) {
  92. $SQL = $SQL->join('agent.dbo.admin_configs as ac', 'ow.agent', '=', 'ac.id');
  93. $where[] = ['agent', $agent];
  94. }
  95. !empty($orderID) && $where[] = ['OrderID', $orderID];
  96. !empty($final_start_time) && $where[] = ['finishDate', '>=', str_replace('T', ' ', $final_start_time)];
  97. !empty($final_end_time) && $where[] = ['finishDate', '<=', str_replace('T', ' ', $final_end_time)];
  98. if(Request::input('final_start_time_cn')) {
  99. $where[] = ['finishDate', '>=',
  100. date('Y-m-d H:i:s', strtotime(
  101. str_replace('T', ' ', Request::input('final_start_time_cn')). ' - 11 hours'
  102. ))
  103. ];
  104. }
  105. if(Request::input('final_end_time_cn')) {
  106. $where[] = ['finishDate', '<=',
  107. date('Y-m-d H:i:s', strtotime(
  108. str_replace('T', ' ', Request::input('final_end_time_cn')). ' - 11 hours'
  109. ))
  110. ];
  111. }
  112. (!empty($Channel) || $Channel === '0') && $where[] = ['ai.Channel', $Channel];
  113. if ($payState == 1) {
  114. $SQL = $SQL->join('QPRecordDB.dbo.RecordUserTotalStatistics as rs', 'ow.UserID', 'rs.UserID')->where('Recharge', '>', 0);
  115. }
  116. if ($take_effect == -1) {
  117. $SQL = $SQL->join('agent.dbo.withdrawal_position_log as log', function ($join) {
  118. $join->on('log.order_sn', '=', 'ow.OrderID');
  119. });
  120. } else {
  121. if (!empty($take_effect)) {
  122. $SQL = $SQL->Join('agent.dbo.admin_users as us', 'ar.admin_id', '=', 'us.id');
  123. $where[] = ['ar.admin_id', '=', $take_effect];
  124. }
  125. }
  126. !empty($register_start_time) && $where[] = ['RegisterDate', '>=', str_replace('T', ' ', $register_start_time) ];
  127. !empty($register_end_time) && $where[] = ['RegisterDate', '<=', str_replace('T', ' ', $register_end_time)];
  128. if (!empty($PackgeName)) {
  129. $SQL = $SQL->leftJoin('QPRecordDB.dbo.RecordPackageName as rn', 'ai.UserID', 'rn.UserID');
  130. $where[] = ['PackgeName', $PackgeName];
  131. }
  132. $adminChannels=session('admin_channels');
  133. if(count($adminChannels)<5)$SQL=$SQL->whereIn('ai.Channel', $adminChannels);
  134. // dd($where);
  135. if (!$flag && $excel) {
  136. AccountWithDrawInfo::verifyOrderDownExcel($SQL, $where);
  137. } elseif ($flag && $excel) {
  138. AccountWithDrawInfo::orderOverDownExcel($SQL, $where);
  139. } else {
  140. $field = ['ai.RegisterIP','ow.locking', 'ar.remarks','ow.remark', 'ow.RecordID', 'ar.RecordID as ar_RecordID', 'wn.state as wn_state', 'ai.NickName', 'ow.AccountsBank', 'ow.BankUserName', 'ow.WithDraw', 'ow.State', 'ow.BankNO', 'ow.ServiceFee', 'OrderId', 'ai.GameID', 'ai.UserID', 'ai.Channel', 'ar.admin_id', 'ow.agent', 'finishDate', 'PixNum', 'PixType', 'ow.EmailAddress', 'ow.PhoneNumber', 'ow.AdhaarNumber', 'ow.IFSCNumber'];
  141. $SQL1 = clone $SQL;
  142. $SQL2 = clone $SQL;
  143. $model = new AccountWithDrawInfo();
  144. $list = $SQL
  145. ->where($where)
  146. ->lock('with(nolock)')
  147. ->select($field)
  148. ->selectRaw('ar.update_at, CreateDate')
  149. ->orderBy('ow.RecordID', 'desc')
  150. ->paginate(10);
  151. // 申请人数,笔数,金额
  152. $applyUserCount = $SQL1
  153. ->where($where)
  154. ->lock('with(nolock)')
  155. ->selectRaw('count(distinct(ow.UserID)) userCount,(sum(cast(ow.WithDraw as bigint))+sum(cast(ow.ServiceFee as bigint))) WithDraw,count(ow.RecordID) count')->lock('with(nolock)')->first();
  156. if (isset($applyUserCount->WithDraw)) {
  157. $applyUserCount->WithDraw = number_float($applyUserCount->WithDraw / NumConfig::NUM_VALUE);
  158. }
  159. // 到账人数,金额
  160. $overUserCount = $SQL2->where($where)->where('ow.State', 2)->selectRaw('count(distinct(ow.UserID)) userCount,sum(cast(ow.WithDraw as bigint)) WithDraw,count(ow.RecordID) count')
  161. ->lock('with(nolock)')
  162. ->first();
  163. if (isset($overUserCount->WithDraw)) {
  164. $overUserCount->WithDraw = number_float($overUserCount->WithDraw / NumConfig::NUM_VALUE);
  165. }
  166. $userIDs = [];
  167. $adminIDs = [];
  168. $agentIDs = [];
  169. $accountsInfo=new AccountsInfo();
  170. foreach ($list as &$val) {
  171. $val->actual_arrival = number_float(($val->WithDraw + $val->ServiceFee) / 100); // 实际提现金额
  172. $val->ServiceFee = number_float($val->ServiceFee / 100);
  173. $val->WithDraw = number_float($val->WithDraw / 100);
  174. $val->sameNameNum=$accountsInfo->sameWithDrawBankName($val->BankUserName);
  175. $val->sameEmailNum=$accountsInfo->sameWithDrawEmail($val->EmailAddress);
  176. $val->sameMac=$accountsInfo->sameLoginMacCount($val->UserID);
  177. $val->sameCpfCount=Cpf::getCpfCount($val->UserID);
  178. $val->sameIP=$accountsInfo->sameRegisterIPCount($val->RegisterIP);
  179. // $val->sameLIP=$accountsInfo->sameLoginIPCount($val->UserID);
  180. $userIDs[] = $val->UserID;
  181. !empty($val->admin_id) && $adminIDs[] = $val->admin_id;
  182. !empty($val->agent) && $agentIDs[] = $val->agent;
  183. }
  184. unset($val);
  185. $agentName = DB::connection('write')->table('agent.dbo.admin_configs')
  186. ->whereIn('id', $agentIDs)
  187. ->pluck('name', 'id')->toArray();
  188. $adminName = DB::connection('write')->table('agent.dbo.admin_users')
  189. ->whereIn('id', $adminIDs)
  190. ->pluck('account', 'id')->toArray();
  191. $userIDs = array_unique($userIDs);
  192. // 银行卡绑定信息评估
  193. $BankNO = $model->BankNO($userIDs);
  194. $IP = $model->ip($userIDs);
  195. $orders = DB::connection('read')->table('QPAccountsDB.dbo.YN_VIPAccount')->whereIn('UserID', $userIDs)
  196. ->selectRaw('Recharge,UserID')
  197. ->lock('with(nolock)')
  198. ->pluck('Recharge', 'UserID')->toArray();
  199. $Withdrawal_M = new Withdrawal();
  200. // 评估档位
  201. foreach ($list as &$val) {
  202. /*
  203. * 评估档位 累计充值金额 获得佣金
  204. * 低 ≥100 ≥100
  205. * 普通 >0<100 >0<100
  206. * 较高 0 >0
  207. * 高 0 0
  208. * */
  209. $cz_money = $orders[$val->UserID] ?? 0;
  210. if (isset($IP[$val->UserID]) && $IP[$val->UserID] > 1) {
  211. $gear = '高';
  212. } elseif (isset($BankNO[$val->UserID]) && $BankNO[$val->UserID] > 1) {
  213. $gear = '高';
  214. } elseif ($cz_money >= 100) {
  215. $gear = '低';
  216. } elseif ($cz_money > 0 && $cz_money < 100) {
  217. $gear = '普通';
  218. } elseif ($cz_money > 0) {
  219. $gear = '较高';
  220. } elseif ($cz_money == 0) {
  221. $gear = '高';
  222. }
  223. $val->gear = $gear ?? '';
  224. $val->assessment = $Withdrawal_M->assessment($cz_money);
  225. $val->States = $Withdrawal_M->stateText($val->State, $val->locking);
  226. $val->account = isset($adminName[$val->admin_id]) ? $adminName[$val->admin_id] : '';
  227. $val->name = isset($agentName[$val->agent]) ? $agentName[$val->agent] : '';
  228. }
  229. }
  230. // 改已读
  231. // DB::table('QPAccountsDB.dbo.OrderWithDraw')->update(['admin_read' => 1]);
  232. $allChannel = $adminChannels;//DB::connection('read')->table('QPPlatformDB.dbo.ChannelPackageName')->selectRaw('Channel')->groupBy('Channel')->pluck('Channel');
  233. $start_time = Helper::timeChange($start_time);
  234. $end_time = Helper::timeChange($end_time);
  235. $final_start_time = Helper::timeChange($final_start_time);
  236. $final_end_time = Helper::timeChange($final_end_time);
  237. // 提现管理员
  238. $withdrawal_administrator = DB::connection('write')->table('agent.dbo.withdrawal_administrator')->pluck('account', 'admin_id');
  239. // 获取包名
  240. $ChannelPackageName = DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  241. ->select('PackageName', 'Channel')
  242. ->pluck('PackageName', 'Channel');
  243. return compact('applyUserCount', 'overUserCount', 'list', 'payState', 'allChannel', 'Channel', 'GameID', 'withdraw_search', 'withdraw', 'state', 'start_time', 'end_time', 'agent', 'orderID', 'final_start_time', 'final_end_time', 'take_effect', 'withdrawal_administrator', 'isEmpty', 'register_start_time', 'register_end_time', 'PackgeName', 'ChannelPackageName');
  244. }
  245. public function verify_agree($ids)
  246. {
  247. $id_arr = explode(',', $ids);
  248. $order = ['WithDraw', 'ServiceFee', 'ow.RecordID', 'ai.GameID', 'ai.UserID', 'ai.Channel','PixType'];
  249. $list = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw as ow')
  250. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ow.UserID', 'ai.UserID')
  251. ->whereIn('RecordID', $id_arr)
  252. ->select($order)
  253. ->lock('with(nolock)')
  254. ->paginate(10);
  255. $channelConfigs = [];
  256. $res = WithdrawalChannelPositionConfig::where('status', 1)->get();
  257. foreach ($res as $v) {
  258. $channelConfigs[$v->channel] = $v;
  259. }
  260. // $config = DB::table(TableName::agent() . 'withdrawal_position_config')
  261. // ->where('status', 1)
  262. // ->first();
  263. foreach ($list as &$value) {
  264. $value->WithDraw = number_float(($value->WithDraw + $value->ServiceFee) / 100);
  265. if($value->PixType==66){
  266. //代理订单
  267. $value->agent=
  268. $this->agent=[(object)[
  269. "id" => "6666",
  270. "name" => "代理申请为玩家提现",
  271. "config_key" => "AgentCashOut",
  272. "config_value" => "66",
  273. "type" => "cash",
  274. "created_at" => null,
  275. "updated_at" => null,
  276. "admin_id" => "11",
  277. "status" => "1",
  278. "sort" => "0",
  279. "remarks" => null,
  280. "new_pay_type" => "0",
  281. "pic_num" => null,
  282. "pay_error" => "0",
  283. "cpf_first" => "0"
  284. ]];
  285. continue;
  286. }
  287. if(isset($channelConfigs[$value->Channel]) && $channelConfigs[$v->channel]->limit_manual_review_show) {
  288. $c = $channelConfigs[$value->Channel];
  289. $value->agent = array_filter($this->agent->toArray(), function ($item) use ($c) {
  290. return $item->config_value == $c->agent;
  291. });
  292. }
  293. }
  294. $agent = $this->agent;
  295. return compact('list', 'agent');
  296. }
  297. public function save($data, $admin_id)
  298. {
  299. $redis = new RedisConnect();
  300. $limitKey = 'withdraw';
  301. $res = $redis->redis()->set($limitKey, 1, 3);
  302. if (empty($res)) return apiReturnFail('频繁操作');
  303. $WithdrawalModel = new Withdrawal();
  304. $id_arr = explode(',', $data['ids']);
  305. // 代付方
  306. $agent = $data['agent'] ?? '';
  307. if (empty($agent) && $data['agree'] == 'true') {
  308. return apiReturnFail('请选择代付方');
  309. }
  310. if ($data['agree'] == 'true') {
  311. $state = 2;
  312. } else {
  313. $state = -1;
  314. }
  315. try {
  316. foreach ($id_arr as $val) {
  317. $query = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $val)->first();
  318. if($query->PixType!=66) {
  319. if ($query->State != 1) {
  320. return apiReturnFail('订单重复操作');
  321. }
  322. if ($query->locking == 1) {
  323. return apiReturnFail('订单已被锁定');
  324. }
  325. $redis1 = Redis::connection();
  326. $order_sn = $query->OrderId;
  327. if ($redis1->exists($order_sn . 'key1')) {
  328. return apiReturnFail('订单已被锁定new');
  329. }
  330. $redis1->set($order_sn.'key1', $order_sn, 3600 * 24);
  331. }
  332. // 拒绝提现 ,发邮件给用户
  333. if ($state == -1) {
  334. // 发送邮件给玩家
  335. $WithDraw = $query->WithDraw + $query->ServiceFee;
  336. PrivateMail::ClearDrawMail($query->UserID, $query->OrderId, $WithDraw);
  337. // 修改订单状态
  338. DB::table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $val)->update(['State' => $state, 'locking' => 2]);
  339. $remarks = $data['remarks'] ?? '';
  340. // 添加用户提现操作记录
  341. (new AccountsRecordLogic())->create_record($val, 1, $state, $remarks, $admin_id, 1);
  342. if($query->PixType==66)AgentSystemService::FailWithdraw($query);
  343. } else if($query->PixType==66){
  344. DB::table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $val)->update(['State' => 5, 'agent' => 660000+$query->AccountsBank]);
  345. //通知AgentSystem完成,并锁定
  346. AgentSystemService::FinishWithdraw($query);
  347. } else { // 发起提现
  348. // 验证用户提现方式
  349. $verifyAccountWithdrawal = $WithdrawalModel->AccountWithDrawInfo($query->PixNum, $agent);
  350. if (!$verifyAccountWithdrawal) return apiReturnFail('不支持的提现格式!');
  351. $state = 5;
  352. # 获取哪个三方提现
  353. $orderAgent = $WithdrawalModel->getAgentChannel($agent);
  354. // 改变状态处理中
  355. DB::table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $val)->update(['State' => $state, 'agent' => $orderAgent]);
  356. // 添加用户提现操作记录
  357. (new AccountsRecordLogic())->create_record($val, 1, $state, '', $admin_id, 1);
  358. $RecordID = $query->RecordID;
  359. $amount = $query->WithDraw;
  360. $accountName = $query->BankUserName;
  361. $email = $query->EmailAddress;
  362. $phone = $query->PhoneNumber;
  363. $PixNum = $query->PixNum;
  364. $PixType = $query->PixType;
  365. $OrderId = $query->OrderId;
  366. $IFSCNumber = $query->IFSCNumber;
  367. $BranchBank = $query->BranchBank;
  368. $BankNO = $query->BankNO;
  369. if($PixType>10){
  370. Util::WriteLog("pixerror",$query);
  371. $oldRecord=DB::table('QPAccountsDB.dbo.OrderWithDraw')->where('UserID', $query->UserID)->where('State',2)->first();
  372. if(isset($oldRecord)&&isset($oldRecord->PixType)){
  373. $PixType=$oldRecord->PixType;
  374. }else{
  375. $PixType=1;
  376. }
  377. }
  378. $service = CashService::payment($agent);
  379. $result = $service->payment($RecordID, $amount, $accountName, $phone, $email, $OrderId, $PixNum, $PixType, $IFSCNumber, $BranchBank, $BankNO);
  380. if ($result === 'fail') {
  381. return apiReturnFail('订单提现失败');
  382. }
  383. }
  384. // 判断管理员是否已经存在
  385. $withdrawal_administrator = DB::connection('write')->table('agent.dbo.withdrawal_administrator')->where('admin_id', $admin_id)->first();
  386. if (!$withdrawal_administrator) {
  387. $dataArr = [
  388. 'admin_id' => $admin_id,
  389. 'account' => session('admin')->account ?? ''
  390. ];
  391. DB::connection('write')->table('agent.dbo.withdrawal_administrator')->insert($dataArr);
  392. }
  393. }
  394. $redis->redis()->del($limitKey);
  395. return apiReturnSuc();
  396. } catch (Exception $e) {
  397. $redis->redis()->del($limitKey);
  398. return apiReturnFail($e->getMessage());
  399. }
  400. }
  401. // 用户提充统计
  402. public function userWithdrawalStatistics($date, $excel, $gameID, $channel)
  403. {
  404. $dateID = Carbon::parse($date)->format('Ymd');
  405. $where[] = ['Withdraw', '>', 0];
  406. !empty($date) && $where[] = ['DateID', $dateID];
  407. !empty($gameID) && $where[] = ['GameID', $gameID];
  408. (!empty($channel) || $channel === 0) && $where[] = ['Channel', $channel];
  409. $buildSql = DB::table(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as rn')
  410. ->where($where)
  411. ->join(TableName::QPAccountsDB() . 'AccountsInfo as ai', 'rn.UserID', 'ai.UserID')
  412. ->select('GameID', 'rn.UserID', 'Withdraw', 'Recharge')
  413. ->orderBy('Withdraw', 'desc');
  414. // 昨天的提现用户,昨日提现多少,昨日充值多少,历史充值多少,历史提现多少
  415. $list = $excel ? $buildSql->get() : $buildSql->paginate(15);
  416. $UserIDs = [];
  417. foreach ($list as $value) {
  418. $UserIDs[] = $value->UserID;
  419. }
  420. $total = DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')
  421. ->whereIn('UserID', $UserIDs)
  422. ->select('Withdraw', 'Recharge', 'UserID')
  423. ->get();
  424. foreach ($list as &$value) {
  425. $value->Withdraw = number_float($value->Withdraw / 100);
  426. foreach ($total as $val) {
  427. if ($val->UserID == $value->UserID) {
  428. $value->HisWithdraw = number_float($val->Withdraw / 100);
  429. $value->HisRecharge = $val->Recharge;
  430. }
  431. }
  432. }
  433. if ($excel) {
  434. $title = ['游戏ID', '用户ID', '今日提现', '今日充值', '历史提现', '历史充值'];
  435. $list = json_decode(json_encode($list), true);
  436. downloadExcel($list, $title, '统计' . date('YmdHis'));
  437. return;
  438. } else {
  439. $channelList = DB::table(TableName::QPPlatformDB().'ChannelPackageName')
  440. ->select('Channel')
  441. ->groupBy('Channel')
  442. ->pluck('Channel','Channel')->toArray();
  443. return [$list,$channelList];
  444. }
  445. }
  446. /**
  447. * 后台模拟触发提现回调
  448. * @param $withdrawOrder
  449. * @return bool
  450. */
  451. public function compensateNotify($withdrawOrder)
  452. {
  453. $withdraw_data = [
  454. 'State' => 2,
  455. 'finishDate' => now(),
  456. ];
  457. $UserID = $withdrawOrder->UserID;
  458. $TakeMoney = $withdrawOrder->WithDraw + $withdrawOrder->ServiceFee;
  459. // 增加提现记录
  460. $first = DB::connection('write')->table('QPAccountsDB.dbo.UserTabData')->where('UserID', $UserID)->first();
  461. if ($first) {
  462. DB::connection('write')->table('QPAccountsDB.dbo.UserTabData')->where('UserID', $UserID)->increment('TakeMoney', $TakeMoney);
  463. } else {
  464. DB::connection('write')->table('QPAccountsDB.dbo.UserTabData')->insert(['TakeMoney' => $TakeMoney, 'UserID' => $UserID]);
  465. }
  466. // 免审的时候,修改免审状态
  467. $withdrawal_position_log = DB::connection('write')
  468. ->table('agent.dbo.withdrawal_position_log')->where('order_sn', $withdrawOrder->OrderId)
  469. ->first();
  470. if ($withdrawal_position_log) {
  471. DB::connection('write')->table('agent.dbo.withdrawal_position_log')
  472. ->where('order_sn', $withdrawOrder->OrderId)
  473. ->update(['take_effect' => 2, 'update_at' => date('Y-m-d H:i:s')]);
  474. }
  475. $ServiceFee = $withdrawOrder->ServiceFee;
  476. // 增加用户提现值
  477. RecordUserDataStatistics::updateOrAdd($UserID, $TakeMoney, 0, $ServiceFee);
  478. // 给用户发邮件
  479. PrivateMail::successMail($UserID, $withdrawOrder->OrderId, $TakeMoney);
  480. StoredProcedure::addPlatformData($UserID, 4, $TakeMoney);
  481. // 数据统计后台 -- 提现记录添加
  482. (new RechargeWithDraw())->withDraw($UserID, $TakeMoney);
  483. $redis = Redis::connection();
  484. $redis->incr('draw_'.date('Ymd').$UserID);
  485. $RecordData = [
  486. 'before_state' => $withdrawOrder->State,
  487. 'after_state' => $withdraw_data['State'] ?? 0,
  488. 'RecordID' => $withdrawOrder->RecordID,
  489. 'update_at' => date('Y-m-d H:i:s')
  490. ];
  491. $notify_data = [
  492. 'state' => 1,
  493. 'finish_at' => now(),
  494. 'casOrdNo' => '',
  495. 'extra' => '{}',
  496. 'created_at' => now(),
  497. 'updated_at' => now(),
  498. 'order_sn' => $withdrawOrder->OrderId,
  499. 'amount' => $TakeMoney,
  500. ];
  501. // 添加用户提现操作记录
  502. DB::connection('write')->table('QPAccountsDB.dbo.AccountsRecord')
  503. ->updateOrInsert(['RecordID' => $withdrawOrder->RecordID, 'type' => 1], $RecordData);
  504. DB::connection('write')->table('QPAccountsDB.dbo.withdraw_notify')
  505. ->updateOrInsert(['order_sn' => $withdrawOrder->OrderId], $notify_data);
  506. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')
  507. ->where('OrderId', $withdrawOrder->OrderId)
  508. ->update($withdraw_data);
  509. if (isset($withdraw_data['State']) && $withdraw_data['State'] == 2) {
  510. // 单控标签
  511. StoredProcedure::user_label($UserID, 2, $TakeMoney);
  512. // 渠道后台埋点
  513. (new LogDayStatisticalByDayAndChannel())->updateData($UserID, 2);
  514. }
  515. return true;
  516. }
  517. }