PayError.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\dao\Pay;
  3. use App\Facade\TableName;
  4. use Carbon\Carbon;
  5. use Illuminate\Support\Facades\DB;
  6. class PayError
  7. {
  8. public function create($UserID, $PayConfigValue)
  9. {
  10. return true;
  11. $PollSwitch = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  12. ->where('StatusName', 'PollSwitch')
  13. ->value('StatusValue');
  14. if (!$PollSwitch) {
  15. return true;
  16. }
  17. $data = [
  18. 'UserID' => $UserID,
  19. 'PayConfigValue' => $PayConfigValue,
  20. 'CreateTime' => now()
  21. ];
  22. DB::table(TableName::agent() . 'pay_error')->insert($data);
  23. $where[] = ['PayConfigValue', $PayConfigValue];
  24. $map[] = ['type', 'pay'];
  25. // 查近四个小时出现用户有多少 【大于2,切换通道】
  26. $date = Carbon::now()->subHours(4)->format('Y-m-d H:i:s');
  27. if (DB::table(TableName::agent() . 'pay_error')->where($where)->where('CreateTime', '>=', $date)->distinct()->count('UserID') >= 2) {
  28. DB::table(TableName::agent() . 'admin_configs')->where($map)->where('config_key', $PayConfigValue)->update(['pay_error' => 1]);
  29. }
  30. $date = Carbon::now()->subHours(2)->format('Y-m-d H:i:s');
  31. if (DB::table(TableName::agent() . 'pay_error')->where($where)->where('CreateTime', '>=', $date)->distinct()->count('UserID') < 2) {
  32. DB::table(TableName::agent() . 'admin_configs')->where($map)->update(['pay_error' => 0]);
  33. }
  34. return true;
  35. }
  36. }