onlinetest 4 年之前
父節點
當前提交
cd9033a005
共有 2 個文件被更改,包括 33 次插入33 次删除
  1. 5 2
      app/Http/Controllers/QuickApp/Book/ChapterController.php
  2. 28 31
      app/Jobs/UserRententionJob.php

+ 5 - 2
app/Http/Controllers/QuickApp/Book/ChapterController.php

@@ -262,8 +262,11 @@ class ChapterController extends BaseController
             return response()->error('QAPP_SYS_ERROR');
         }
 
-        $job = new UserRententionJob($this->uid, now());
-        dispatch($job)->onConnection('rabbitmq')->onQueue('user_rentention_queue');
+        $is_next_day = date('Y-m-d', strtotime($this->user_info->created_at)) == date('Y-m-d', strtotime('-1 days'));
+        if ($is_next_day) {
+            $job = new UserRententionJob($this->uid, now(), $this->user_info->created_at);
+            dispatch($job)->onConnection('rabbitmq')->onQueue('user_rentention_queue');
+        }
 
         if ($chapter->is_vip == 0) {
             ReadRecordService::addReadRecord([

+ 28 - 31
app/Jobs/UserRententionJob.php

@@ -20,18 +20,19 @@ class UserRententionJob implements ShouldQueue
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
     protected $uid;
-
-    protected $time;
+    protected $read_time;
+    protected $register_time;
 
     /**
      * Create a new job instance.
      *
      * @return void
      */
-    public function __construct(int $uid, string $time)
+    public function __construct(int $uid, string $read_time, string $register_time)
     {
         $this->uid = $uid;
-        $this->time = $time;
+        $this->read_time = $read_time;
+        $this->register_time = $register_time;
     }
 
     /**
@@ -41,33 +42,29 @@ class UserRententionJob implements ShouldQueue
      */
     public function handle()
     {
-        $user = User::find($this->uid);
-        $date = date('Y-m-d', strtotime($this->time));
-        $is_next_day = date('Y-m-d', strtotime($user->created_at)) == date('Y-m-d', strtotime('-1 days', strtotime($this->time)));
-        if ($is_next_day) {
-            $exists = QappUserRententionLog::where('uid', $this->uid)->exists();
-            if ($exists) {
-                return;
-            }
-            $client = new Client();
-            $params = [
-                'uid' => $this->uid,
-                'source' => 'zsy'
-            ];
-            $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
-            $url = 'https://newtrackapi.zhuishuyun.com/api/qappuser/rentention';
-            $response =  $client->post($url, ['form_params' => $params])->getBody()->getContents();
-            myLog('new_user_rentention')->info($response);
-            $result =  json_decode($response);
-            if ($result) {
-                if ($result->code == 0) {
-                    QappUserRententionLog::create([
-                        'date' => $date,
-                        'uid' => $this->uid,
-                        'register_time' => $user->created_at,
-                        'read_time' => $this->time,
-                    ]);
-                }
+        $date = date('Y-m-d', strtotime($this->read_time));
+        $exists = QappUserRententionLog::where('uid', $this->uid)->exists();
+        if ($exists) {
+            return;
+        }
+        $client = new Client();
+        $params = [
+            'uid' => $this->uid,
+            'source' => 'zsy'
+        ];
+        $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
+        $url = 'https://newtrackapi.zhuishuyun.com/api/qappuser/rentention';
+        $response =  $client->post($url, ['form_params' => $params])->getBody()->getContents();
+        myLog('new_user_rentention')->info($response);
+        $result =  json_decode($response);
+        if ($result) {
+            if ($result->code == 0) {
+                QappUserRententionLog::create([
+                    'date' => $date,
+                    'uid' => $this->uid,
+                    'register_time' => $this->register_time,
+                    'read_time' => $this->read_time,
+                ]);
             }
         }
     }