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