ExemptReview.php 9.2 KB

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