UserRententionJob.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Jobs;
  3. use App\Consts\SysConsts;
  4. use App\Modules\User\Models\QappUserRententionLog;
  5. use GuzzleHttp\Client;
  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. /**
  12. * 用户留存
  13. */
  14. class UserRententionJob implements ShouldQueue
  15. {
  16. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  17. protected $uid;
  18. protected $read_time;
  19. protected $register_time;
  20. /**
  21. * Create a new job instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct(int $uid, string $read_time, string $register_time)
  26. {
  27. $this->uid = $uid;
  28. $this->read_time = $read_time;
  29. $this->register_time = $register_time;
  30. }
  31. /**
  32. * Execute the job.
  33. *
  34. * @return void
  35. */
  36. public function handle()
  37. {
  38. $date = date('Y-m-d', strtotime($this->read_time));
  39. $exists = QappUserRententionLog::where('uid', $this->uid)->exists();
  40. if ($exists) {
  41. return;
  42. }
  43. $client = new Client();
  44. $params = [
  45. 'uid' => $this->uid,
  46. 'source' => 'wdy'
  47. ];
  48. $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
  49. $url = 'https://newtrackapi.zhuishuyun.com/api/qappuser/rentention';
  50. $response = $client->post($url, ['form_params' => $params])->getBody()->getContents();
  51. myLog('new_user_rentention')->info($response);
  52. $result = json_decode($response);
  53. if ($result) {
  54. if ($result->code == 0) {
  55. QappUserRententionLog::create([
  56. 'date' => $date,
  57. 'uid' => $this->uid,
  58. 'register_time' => $this->register_time,
  59. 'read_time' => $this->read_time,
  60. ]);
  61. }
  62. }
  63. }
  64. }