GameTask.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Jobs;
  3. use App\Game\GlobalUserInfo;
  4. use App\Models\AccountsInfo;
  5. use App\Util;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Queue\SerializesModels;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Support\Facades\DB;
  12. use Illuminate\Support\Facades\Redis;
  13. class GameTask implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. protected $data;
  17. /**
  18. * Create a new job instance.
  19. *
  20. * @return void
  21. */
  22. public function __construct($data)
  23. {
  24. $this->data = $data;
  25. }
  26. public $tries = 5;
  27. public function backoff(): array
  28. {
  29. return [30, 60, 120]; // wait 30s before 1st retry, 60s before 2nd, etc.
  30. }
  31. /**
  32. * The number of seconds the job can run before timing out.
  33. *
  34. * @var int
  35. */
  36. public $timeout = 300; // allow up to 5 minutes
  37. public function timeoutOn()
  38. {
  39. return now()->addMinutes(10);
  40. }
  41. /**
  42. * Execute the job.
  43. *
  44. * @return void
  45. */
  46. public function handle()
  47. {
  48. if (empty($this->data)) return;
  49. // return ;
  50. Util::WriteLog('24680task',$this->data);
  51. // 接收数据
  52. [$cmd,$data] = $this->data;
  53. switch ($cmd){
  54. case 'UpdateLogin':
  55. [$UserID,$LastLogonDate,$LastLogonIP,$FPID,$FF]=$data;
  56. Redis::del('UpdateLoginCheck_'.$UserID);
  57. $accountInfo = AccountsInfo::where('UserID', $UserID)->first();
  58. if(!$accountInfo)return;
  59. $LastFPID=$FPID;
  60. GlobalUserInfo::where('UserID',$UserID)->update(compact('LastLogonDate','LastLogonIP','FF','LastFPID'));
  61. AccountsInfo::where('UserID', $UserID)->update(compact('LastLogonDate','LastLogonIP'));
  62. DB::table('QPRecordDB.dbo.RecordUserLogonStatistics')->insert([
  63. 'UserID' => $UserID,
  64. 'LogonIP'=>$LastLogonIP,
  65. 'LastDate'=>$LastLogonDate,
  66. 'LogonCount'=>1,
  67. 'mac'=>$FPID??""
  68. ]);
  69. $channel = intval($accountInfo->Channel);
  70. Util::WriteLog('24680dispatch-xxxx', ['UpdateLogin', [$UserID, $LastLogonDate, $accountInfo->LastLogonDate,$accountInfo->Channel,strtotime($accountInfo->LastLogonDate)]]);
  71. if(date('Ymd',strtotime($LastLogonDate)) != date('Ymd',strtotime($accountInfo->LastLogonDate))){
  72. //DB::connection('write')->select("SET NOCOUNT ON use QPRecordDB exec GSP_GP_AddPlatformData 2,$channel,1");
  73. $result = DB::connection('write')->select("DECLARE @return_value int
  74. SET NOCOUNT ON use QPRecordDB exec GSP_GP_AddPlatformData 2,$channel,1,0
  75. SELECT 'ReturnValue' = @return_value
  76. ");
  77. }
  78. //DB::connection('write')->select("SET NOCOUNT ON use QPRecordDB exec GSP_GP_AddUserLogin $UserID");
  79. //EXEC QPRecordDB.dbo.GSP_GP_AddPlatformData 2,@Channel,1
  80. $result = DB::connection('write')->select("DECLARE @return_value int
  81. SET NOCOUNT ON use QPRecordDB exec GSP_GP_AddUserLogin $UserID
  82. SELECT 'ReturnValue' = @return_value
  83. ");
  84. break;
  85. }
  86. }
  87. }