ExemptReview.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Facade\TableName;
  4. use App\Models\AccountsInfo;
  5. use App\Models\Cpf;
  6. use App\Models\SystemStatusInfo;
  7. use App\Models\Withdrawal;
  8. use App\Models\WithdrawalChannelPositionConfig;
  9. use App\Services\CashService;
  10. use App\Util;
  11. use Illuminate\Console\Command;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\Log;
  14. use Illuminate\Support\Facades\Redis;
  15. class ExemptReview extends Command
  16. {
  17. /**
  18. * The name and signature of the console command.
  19. *
  20. * @var string
  21. */
  22. protected $signature = 'exempt_review';
  23. /**
  24. * The console command description.
  25. *
  26. * @var string
  27. */
  28. protected $description = '提现免审--定时扫表订单';
  29. /**
  30. * Create a new command instance.
  31. *
  32. * @return void
  33. */
  34. public function __construct()
  35. {
  36. parent::__construct();
  37. }
  38. /**
  39. * Execute the console command.
  40. *
  41. * @return mixed
  42. */
  43. public function handle()
  44. {
  45. $open=(int)SystemStatusInfo::OnlyGetCacheValue(SystemStatusInfo::$KEY_WithDrawSwitch);
  46. if(!$open)return;
  47. $WithdrawalModel = new Withdrawal();
  48. $OrderWithDraw = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('State', 1)
  49. ->whereRaw('locking = 0')->orderBy('CreateDate', 'desc')->get();
  50. foreach ($OrderWithDraw as $value) {
  51. if ($value->State != 1) {
  52. continue;
  53. }
  54. // 验证免审条件
  55. $verifyRes = (new \App\Services\Withdrawal())->configVerify($value->UserID, $value->WithDraw,
  56. $value->OrderId);
  57. if (!$verifyRes) {
  58. continue;
  59. }
  60. //防止刷子补充
  61. $AccountsInfoModel = new AccountsInfo();
  62. // $mailNums=DB::table(TableName::QPAccountsDB() . 'OrderWithDraw')
  63. // ->selectRaw('count(distinct (UserID)) as nums')
  64. // ->where("EmailAddress",$value->EmailAddress)
  65. // ->first();
  66. $sameCountCheck = 1;
  67. $sameCountCheckIP = 1;
  68. if ($verifyRes == 4) {
  69. $sameCountCheck = 2;
  70. $sameCountCheckIP = 3;
  71. } elseif ($verifyRes == 5) {
  72. $sameCountCheck = 10;
  73. $sameCountCheckIP = 200;
  74. } elseif ($verifyRes == 2) {
  75. $sameCountCheck = 3;
  76. $sameCountCheckIP = 100;
  77. } elseif ($verifyRes == 3) {
  78. $sameCountCheck = 3;
  79. $sameCountCheckIP = 100;
  80. }
  81. if(($verifyRes==1||$verifyRes==9)&&$value->WithDraw!=1000){
  82. Log::info('首次审核阻拦自动免审:'.$value->OrderId);
  83. continue;
  84. }
  85. if ($AccountsInfoModel->sameWithDrawEmail($value->EmailAddress) > $sameCountCheck) {
  86. Log::info('EMAIL重复过多阻拦自动免审:'.$value->OrderId.":::".$value->EmailAddress);
  87. continue;
  88. }
  89. // $nameNums=DB::table(TableName::QPAccountsDB() . 'OrderWithDraw')
  90. // ->selectRaw('count(distinct (UserID)) as nums')
  91. // ->where("EmailAddress",$value->BankUserName)
  92. // ->first();
  93. // if($AccountsInfoModel->sameWithDrawBankName($value->BankUserName)>4){
  94. // Log::info('名字重复过多阻拦自动免审:'.$value->OrderId.":::".$value->BankUserName);
  95. // continue;
  96. // }
  97. if ($AccountsInfoModel->sameRegisterIPCountByUserID($value->UserID) > $sameCountCheckIP) {
  98. Log::info('注册IP重复过多阻拦自动免审:'.$value->OrderId);
  99. continue;
  100. }
  101. if ($AccountsInfoModel->sameLoginIPCount($value->UserID) > $sameCountCheckIP) {
  102. Log::info('登录IP重复过多阻拦自动免审:'.$value->OrderId);
  103. continue;
  104. }
  105. if ($AccountsInfoModel->sameLoginMacCount($value->UserID) > $sameCountCheck) {
  106. Log::info('MAC地址码重复阻拦自动免审:'.$value->OrderId);
  107. continue;
  108. }
  109. if(Cpf::getCpfCount($value->UserID)>$sameCountCheck){
  110. Log::info("CPF重复阻拦自动免审:".$value->OrderId);
  111. continue;
  112. }
  113. // 读取免审配置
  114. $config = DB::table(TableName::agent().'withdrawal_position_config')->where('status', 1)->first();
  115. if ($config) {
  116. $agent = $config->agent;
  117. if (empty($agent)) { // 默认第一家
  118. $agent = DB::connection('write')->table('agent.dbo.admin_configs')->where('config_value', 1)
  119. ->where('type', 'cash')->where('status', 1)->first()->config_value;
  120. }
  121. // 验证用户提现方式
  122. $verifyAccountWithdrawal = $WithdrawalModel->AccountWithDrawInfo($value->UserID, $agent);
  123. if (!$verifyAccountWithdrawal) {
  124. Log::info('不支持的提现格式'.$value->OrderId);
  125. continue;
  126. }
  127. $redis = Redis::connection();
  128. $order_sn = $value->OrderId;
  129. if ($redis->exists($order_sn.'key1')) {
  130. continue;
  131. }
  132. $redis->set($order_sn.'key1', $order_sn, 3600 * 24);
  133. $log = ['user_id' => $value->UserID,
  134. 'config_id' => $config->id,
  135. 'use_quota' => intval($value->WithDraw),
  136. 'order_sn' => $value->OrderId];
  137. DB::connection('write')->table('agent.dbo.withdrawal_position_log')
  138. ->updateOrInsert(['order_sn' => $value->OrderId], $log);
  139. $state = 5;
  140. $RecordData = ['admin_id' => 0,
  141. 'before_state' => 1,
  142. 'after_state' => $state,
  143. 'RecordID' => $value->RecordID,
  144. 'create_at' => date('Y-m-d H:i:s'),
  145. 'update_at' => date('Y-m-d H:i:s')];
  146. !empty($data['remarks']) && $RecordData['remarks'] = $data['remarks'];
  147. // 添加用户提现操作记录
  148. DB::connection('write')->table('QPAccountsDB.dbo.AccountsRecord')
  149. ->updateOrInsert(['RecordID' => $value->RecordID, 'type' => 1], $RecordData);
  150. $RecordID = $value->RecordID;
  151. $amount = $value->WithDraw;
  152. $accountName = $value->BankUserName;
  153. $email = $value->EmailAddress;
  154. $phone = $value->PhoneNumber;
  155. $PixNum = $value->PixNum;
  156. $PixType = $value->PixType;
  157. $OrderId = $value->OrderId;
  158. $IFSCNumber = $value->IFSCNumber;
  159. $BranchBank = $value->BranchBank;
  160. $BankNO = $value->BankNO;
  161. // 改变状态处理中
  162. $agentID = DB::connection('write')->table('agent.dbo.admin_configs')->where('config_value', $agent)
  163. ->select('id')->first()->id ?? '';
  164. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderId', $OrderId)
  165. ->update(['State' => $state, 'agent' => $agentID]);
  166. Log::info('自动免审:'.$OrderId.'--'.$agentID);
  167. $service = CashService::payment($agent);
  168. $result = $service->payment($RecordID, $amount, $accountName, $phone, $email, $OrderId, $PixNum,
  169. $PixType, $IFSCNumber, $BranchBank, $BankNO);
  170. if ($result === 'fail') {
  171. Log::info('免审提现失败:'.$value->OrderId);
  172. }
  173. }
  174. }
  175. }
  176. }