OnLineMax.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Facade\TableName;
  4. use Carbon\Carbon;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Log;
  8. use Illuminate\Support\Facades\Redis;
  9. class OnLineMax extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'online_max';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = '最高在线人数统计';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. $carbon = Carbon::now();
  40. $Sql = DB::table(TableName::QPPlatformDB() . 'OnLineStreamInfo');
  41. $date = $carbon->format('Y-m-d');
  42. if (Redis::exists('LastID')) {
  43. $LastID = Redis::get('LastID');
  44. $Sql = $Sql->where('ID', '>=', $LastID)->whereDate('InsertDateTime', $date);
  45. } else {
  46. $Sql = $Sql->whereDate('InsertDateTime', $date);
  47. }
  48. $maxNum = $Sql->select('ID', 'OnLineCountSum')->orderBy('OnLineCountSum', 'desc')->first();
  49. if (!$maxNum) {
  50. return false;
  51. }
  52. Redis::set('LastID', $maxNum->ID);
  53. $first = DB::connection('write')->table(TableName::QPRecordDB() . 'RecordPlatformData')
  54. ->where('DateID', $carbon->format('Ymd'))
  55. ->where('Channel', -1)
  56. ->first();
  57. if ($first && $maxNum->OnLineCountSum > $first->MaxOnLine) {
  58. DB::connection('write')->table(TableName::QPRecordDB() . 'RecordPlatformData')
  59. ->where('DateID', $carbon->format('Ymd'))
  60. ->where('Channel', -1)
  61. ->update(['MaxOnLine' => $maxNum->OnLineCountSum]);
  62. }
  63. $lastAccountId = DB::connection('read')->table(TableName::QPAccountsDB() . 'AccountsInfo')
  64. ->max('UserID');
  65. $lastIdentifyId = DB::connection('read')->table(TableName::QPAccountsDB() . 'GameIdentifier')
  66. ->max('UserID');
  67. try {
  68. if($lastAccountId+3000>$lastIdentifyId && $lastIdentifyId>10000){
  69. $result = DB::connection('write')->select("SET NOCOUNT ON use QPAccountsDB exec GSP_GP_AddUserID 3000");
  70. Log::info('自动添加用户ID'.json_encode($result));
  71. }
  72. }catch (\Exception $e){
  73. Log::info('自动添加用户ID'.json_encode($e));
  74. }
  75. }
  76. }