ExemptReview.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. $userIDChannelMap = AccountsInfo::whereIn('UserID', $OrderWithDraw->pluck('UserID'))
  51. ->pluck('Channel', 'UserID');
  52. $channelConfigs = WithdrawalChannelPositionConfig::where('status', 1)->pluck('agent', 'channel');
  53. foreach ($OrderWithDraw as $value) {
  54. if ($value->State != 1) {
  55. continue;
  56. }
  57. // 验证免审条件
  58. $verifyRes = (new \App\Services\Withdrawal())->configVerify($value->UserID, $value->WithDraw,
  59. $value->OrderId);
  60. if (!$verifyRes) {
  61. continue;
  62. }
  63. //防止刷子补充
  64. $AccountsInfoModel = new AccountsInfo();
  65. // $mailNums=DB::table(TableName::QPAccountsDB() . 'OrderWithDraw')
  66. // ->selectRaw('count(distinct (UserID)) as nums')
  67. // ->where("EmailAddress",$value->EmailAddress)
  68. // ->first();
  69. $sameCountCheck = 1;
  70. $sameCountCheckIP = 1;
  71. if ($verifyRes == 4) {
  72. $sameCountCheck = 2;
  73. $sameCountCheckIP = 3;
  74. } elseif ($verifyRes == 5) {
  75. $sameCountCheck = 10;
  76. $sameCountCheckIP = 200;
  77. } elseif ($verifyRes == 2) {
  78. $sameCountCheck = 3;
  79. $sameCountCheckIP = 100;
  80. } elseif ($verifyRes == 3) {
  81. $sameCountCheck = 3;
  82. $sameCountCheckIP = 100;
  83. }
  84. if($verifyRes==1||$verifyRes==9){
  85. Log::info('首次审核阻拦自动免审:'.$value->OrderId);
  86. continue;
  87. }
  88. if ($AccountsInfoModel->sameWithDrawEmail($value->EmailAddress) > $sameCountCheck) {
  89. Log::info('EMAIL重复过多阻拦自动免审:'.$value->OrderId.":::".$value->EmailAddress);
  90. continue;
  91. }
  92. // $nameNums=DB::table(TableName::QPAccountsDB() . 'OrderWithDraw')
  93. // ->selectRaw('count(distinct (UserID)) as nums')
  94. // ->where("EmailAddress",$value->BankUserName)
  95. // ->first();
  96. // if($AccountsInfoModel->sameWithDrawBankName($value->BankUserName)>4){
  97. // Log::info('名字重复过多阻拦自动免审:'.$value->OrderId.":::".$value->BankUserName);
  98. // continue;
  99. // }
  100. if ($AccountsInfoModel->sameRegisterIPCountByUserID($value->UserID) > $sameCountCheckIP) {
  101. Log::info('注册IP重复过多阻拦自动免审:'.$value->OrderId);
  102. continue;
  103. }
  104. if ($AccountsInfoModel->sameLoginIPCount($value->UserID) > $sameCountCheckIP) {
  105. Log::info('登录IP重复过多阻拦自动免审:'.$value->OrderId);
  106. continue;
  107. }
  108. if ($AccountsInfoModel->sameLoginMacCount($value->UserID) > $sameCountCheck) {
  109. Log::info('MAC地址码重复阻拦自动免审:'.$value->OrderId);
  110. continue;
  111. }
  112. if(Cpf::getCpfCount($value->UserID)>$sameCountCheck){
  113. Log::info("CPF重复阻拦自动免审:".$value->OrderId);
  114. continue;
  115. }
  116. // 读取免审配置
  117. $config = DB::table(TableName::agent().'withdrawal_position_config')->where('status', 1)->first();
  118. if ($config) {
  119. $agent = $config->agent;
  120. //如果独立配置了,就走这个
  121. $channelConfig = $channelConfigs[$userIDChannelMap[$value->UserID]] ?? null;
  122. if ($channelConfig) {
  123. $agent = $channelConfig;
  124. }
  125. if (empty($agent)) { // 默认第一家
  126. $agent = DB::connection('write')->table('agent.dbo.admin_configs')->where('config_value', 1)
  127. ->where('type', 'cash')->where('status', 1)->first()->config_value;
  128. }
  129. // 验证用户提现方式
  130. $verifyAccountWithdrawal = $WithdrawalModel->AccountWithDrawInfo($value->UserID, $agent);
  131. if (!$verifyAccountWithdrawal) {
  132. Log::info('不支持的提现格式'.$value->OrderId);
  133. continue;
  134. }
  135. $redis = Redis::connection();
  136. $order_sn = $value->OrderId;
  137. if ($redis->exists($order_sn.'key1')) {
  138. continue;
  139. }
  140. $redis->set($order_sn.'key1', $order_sn, 3600 * 24);
  141. $log = ['user_id' => $value->UserID,
  142. 'config_id' => $config->id,
  143. 'use_quota' => $value->WithDraw,
  144. 'order_sn' => $value->OrderId];
  145. DB::connection('write')->table('agent.dbo.withdrawal_position_log')
  146. ->updateOrInsert(['order_sn' => $value->OrderId], $log);
  147. $state = 5;
  148. $RecordData = ['admin_id' => 0,
  149. 'before_state' => 1,
  150. 'after_state' => $state,
  151. 'RecordID' => $value->RecordID,
  152. 'create_at' => date('Y-m-d H:i:s'),
  153. 'update_at' => date('Y-m-d H:i:s')];
  154. !empty($data['remarks']) && $RecordData['remarks'] = $data['remarks'];
  155. // 添加用户提现操作记录
  156. DB::connection('write')->table('QPAccountsDB.dbo.AccountsRecord')
  157. ->updateOrInsert(['RecordID' => $value->RecordID, 'type' => 1], $RecordData);
  158. $RecordID = $value->RecordID;
  159. $amount = $value->WithDraw;
  160. $accountName = $value->BankUserName;
  161. $email = $value->EmailAddress;
  162. $phone = $value->PhoneNumber;
  163. $PixNum = $value->PixNum;
  164. $PixType = $value->PixType;
  165. $OrderId = $value->OrderId;
  166. $IFSCNumber = $value->IFSCNumber;
  167. $BranchBank = $value->BranchBank;
  168. $BankNO = $value->BankNO;
  169. if($PixType>10){
  170. Util::WriteLog("pixerror",$value);
  171. $oldRecord=DB::table('QPAccountsDB.dbo.OrderWithDraw')->where('UserID', $value->UserID)->where('State',2)->first();
  172. if(isset($oldRecord)&&isset($oldRecord->PixType)){
  173. $PixType=$oldRecord->PixType;
  174. }else{
  175. $PixType=1;
  176. }
  177. }
  178. // 改变状态处理中
  179. $agentID = DB::connection('write')->table('agent.dbo.admin_configs')->where('config_value', $agent)
  180. ->select('id')->first()->id ?? '';
  181. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderId', $OrderId)
  182. ->update(['State' => $state, 'agent' => $agentID]);
  183. Log::info('自动免审:'.$OrderId.'--'.$agentID);
  184. $service = CashService::payment($agent);
  185. $result = $service->payment($RecordID, $amount, $accountName, $phone, $email, $OrderId, $PixNum,
  186. $PixType, $IFSCNumber, $BranchBank, $BankNO);
  187. if ($result === 'fail') {
  188. Log::info('免审提现失败:'.$value->OrderId);
  189. }
  190. }
  191. }
  192. }
  193. }