ExemptReview.php 8.9 KB

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