AgentSystemService.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Game\Services;
  3. use App\dao\Estatisticas\RechargeWithDraw;
  4. use App\Models\PrivateMail;
  5. use App\Models\RecordUserDataStatistics;
  6. use App\Services\LogDayStatisticalByDayAndChannel;
  7. use App\Services\StoredProcedure;
  8. use App\Util;
  9. use GuzzleHttp\Client;
  10. use Illuminate\Support\Facades\DB;
  11. class AgentSystemService
  12. {
  13. public static function callAgentBackofficeApi($postData,$path='/agent_notify')
  14. {
  15. $apiurl = 'http://agent.24680.org';
  16. $client = new Client();
  17. $response = $client->post($apiurl . $path, [
  18. 'verify'=>false,
  19. 'form_params' => $postData, // 传递 POST 数据// 'query' => $getData, // 传递 GET 数据
  20. ]);
  21. $res = json_decode($response->getBody(), true);
  22. // Util::WriteLog('subserver',$res);
  23. return $res;
  24. }
  25. public static function FailWithdraw($orderWithDraw){
  26. self::callAgentBackofficeApi(['agentID'=>$orderWithDraw->BankNO,'sn'=>$orderWithDraw->BranchBank,'status'=>4],'/agent_notify');
  27. }
  28. public static function FinishWithdraw($orderWithDraw)
  29. {
  30. $query=$orderWithDraw;
  31. $UserID=$orderWithDraw->UserID;
  32. Util::WriteLog('AgentSystem','AgentSystem提现成功');
  33. $now = now();
  34. $withdraw_data = [
  35. 'State' => 2,
  36. 'agent' => 6666,
  37. 'finishDate' => $now
  38. ];
  39. $TakeMoney = $orderWithDraw->WithDraw + $orderWithDraw->ServiceFee;
  40. $OrderId=$orderWithDraw->OrderId;
  41. // 增加提现记录
  42. $first = DB::connection('write')->table('QPAccountsDB.dbo.UserTabData')->where('UserID', $UserID)->first();
  43. if ($first) {
  44. DB::connection('write')->table('QPAccountsDB.dbo.UserTabData')->where('UserID', $UserID)->increment('TakeMoney', $TakeMoney);
  45. } else {
  46. DB::connection('write')->table('QPAccountsDB.dbo.UserTabData')->insert(['TakeMoney' => $TakeMoney, 'UserID' => $UserID]);
  47. try {
  48. PrivateMail::praiseSendMail($UserID);
  49. }catch (\Exception $e){
  50. }
  51. }
  52. // 免审的时候,修改免审状态
  53. $withdrawal_position_log = DB::connection('write')->table('agent.dbo.withdrawal_position_log')->where('order_sn', $OrderId)->first();
  54. if ($withdrawal_position_log) {
  55. DB::connection('write')->table('agent.dbo.withdrawal_position_log')->where('order_sn', $OrderId)->update(['take_effect' => 2, 'update_at' => date('Y-m-d H:i:s')]);
  56. }
  57. try {
  58. StoredProcedure::addPlatformData($UserID, 4, $TakeMoney);
  59. }catch (\Exception $exception){
  60. Util::WriteLog('StoredProcedure',$exception);
  61. }
  62. $ServiceFee = $orderWithDraw->ServiceFee;
  63. // 增加用户提现值
  64. RecordUserDataStatistics::updateOrAdd($UserID, $TakeMoney, 0, $ServiceFee);
  65. // 给用户发邮件
  66. //PrivateMail::successMail($UserID, $OrderId, $TakeMoney);
  67. //StoredProcedure::addPlatformData($UserID, 4, $TakeMoney);
  68. // 数据统计后台 -- 提现记录添加
  69. (new RechargeWithDraw())->withDraw($UserID, $TakeMoney);
  70. $RecordData = [
  71. 'before_state' => $query->State,
  72. 'after_state' => $withdraw_data['State'] ?? 0,
  73. 'RecordID' => $query->RecordID,
  74. 'update_at' => date('Y-m-d H:i:s')
  75. ];
  76. // 添加用户提现操作记录
  77. DB::connection('write')->table('QPAccountsDB.dbo.AccountsRecord')->updateOrInsert(['RecordID' => $query->RecordID, 'type' => 1], $RecordData);
  78. // DB::connection('write')->table('QPAccountsDB.dbo.withdraw_notify')->updateOrInsert(['order_sn' => $OrderId], $notify_data);
  79. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderId', $query->OrderId)->update($withdraw_data);
  80. if (isset($withdraw_data['State']) && $withdraw_data['State'] == 2) {
  81. // 单控标签
  82. // StoredProcedure::user_label($UserID, 2, $TakeMoney);
  83. // 渠道后台埋点
  84. (new LogDayStatisticalByDayAndChannel())->updateData($UserID, 2);
  85. }
  86. self::callAgentBackofficeApi(['agentID'=>$orderWithDraw->BankNO,'sn'=>$orderWithDraw->BranchBank,'status'=>2],'/agent_notify');
  87. }
  88. }