فهرست منبع

add:次留上报:

Wang Chen 4 سال پیش
والد
کامیت
213c8167c5

+ 4 - 0
app/Cache/CacheKeys.php

@@ -33,6 +33,10 @@ class CacheKeys
         'activity' => [
         'activity' => [
             'statsPv' => 'Activity:pv:%s:%s',
             'statsPv' => 'Activity:pv:%s:%s',
             'statsUv' => 'Activity:uv:%s:%s',
             'statsUv' => 'Activity:uv:%s:%s',
+        ],
+        'user'     => [
+            'info' => 'User:i:%s',
+            'data' => 'User:d:%s',
         ]
         ]
     ];
     ];
 }
 }

+ 45 - 0
app/Cache/User/UserCache.php

@@ -0,0 +1,45 @@
+<?php
+
+
+namespace App\Cache\User;
+
+
+use App\Libs\Utils;
+use Illuminate\Support\Facades\Redis;
+
+class UserCache
+{
+    /**
+     * 获取用户信息
+     * @param $uid
+     * @return mixed
+     */
+    public static function getUserInfo($uid)
+    {
+        $cacheKey = Utils::getCacheKey('user.info', [$uid]);
+        return Redis::hgetAll($cacheKey);
+    }
+
+    /**
+     * @param $uid
+     * @param $field
+     * @return mixed
+     */
+    public static function getUserInfoByField($uid, $field)
+    {
+        $cacheKey = Utils::getCacheKey('user.info', [$uid]);
+        return Redis::hmget($cacheKey, $field);
+    }
+
+    /**
+     * 修改用户信息
+     * @param $uid
+     * @param $data
+     * @return mixed
+     */
+    public static function setUserInfo($uid, $data)
+    {
+        $cacheKey = Utils::getCacheKey('user.info', [$uid]);
+        return Redis::hmset($cacheKey, $data);
+    }
+}

+ 0 - 2
app/Http/Controllers/QuickApp/Push/PushController.php

@@ -39,8 +39,6 @@ class PushController extends BaseController
             Utils::throwError(ErrorConst::SIGN_NOT_ACCESS);
             Utils::throwError(ErrorConst::SIGN_NOT_ACCESS);
         }
         }
 
 
-        myLog('pushToUser')->info('1', $all);
-
         // 更新用户reg_id
         // 更新用户reg_id
         $result = PushMessageService::pushMessageToUser($uid, $title, $content, $url);
         $result = PushMessageService::pushMessageToUser($uid, $title, $content, $url);
 
 

+ 7 - 4
app/Http/Middleware/QuickAppGetUserFromToken.php

@@ -4,6 +4,7 @@ namespace App\Http\Middleware;
 
 
 use App\Cache\Push\PushCache;
 use App\Cache\Push\PushCache;
 use App\Modules\Push\Services\PushService;
 use App\Modules\Push\Services\PushService;
+use App\Modules\Report\Services\ReportService;
 use App\Modules\SendOrder\Services\SendOrderService;
 use App\Modules\SendOrder\Services\SendOrderService;
 use App\Modules\User\Services\QappUserService;
 use App\Modules\User\Services\QappUserService;
 use App\Modules\User\Services\UserService;
 use App\Modules\User\Services\UserService;
@@ -40,13 +41,12 @@ class QuickAppGetUserFromToken extends BaseMiddleware
             $user = $this->auth->authenticate($token);
             $user = $this->auth->authenticate($token);
             if ($sendOrderId) {
             if ($sendOrderId) {
                 UserService::setUserSendOrder($user->id, $sendOrderId);
                 UserService::setUserSendOrder($user->id, $sendOrderId);
-                try{
-                    SendOrderService::recordUserSendOrder($user->id,$sendOrderId);
-                }catch (\Exception $e){
+                try {
+                    SendOrderService::recordUserSendOrder($user->id, $sendOrderId);
+                } catch (\Exception $e) {
                 }
                 }
             }
             }
 
 
-
             // 设置全局信息
             // 设置全局信息
             (new QappUserService)->setGolableUser($user->id, $package);
             (new QappUserService)->setGolableUser($user->id, $package);
         } catch (TokenExpiredException $e) {
         } catch (TokenExpiredException $e) {
@@ -68,6 +68,9 @@ class QuickAppGetUserFromToken extends BaseMiddleware
             PushCache::zAddPushUv($pushId, date('Ymd'), $uid);
             PushCache::zAddPushUv($pushId, date('Ymd'), $uid);
         }
         }
 
 
+        // 头条次留回传
+        ReportService::reportActive($uid);
+
         return $next($request);
         return $next($request);
     }
     }
 }
 }

+ 85 - 0
app/Modules/Report/Services/ReportService.php

@@ -0,0 +1,85 @@
+<?php
+
+
+namespace App\Modules\Report\Services;
+
+
+use Psr\Http\Message\ResponseInterface;
+use App\Cache\User\UserCache;
+use App\Modules\User\Services\UserService;
+use GuzzleHttp\Client;
+
+class ReportService
+{
+    /**
+     * 次留回传
+     * @param $uid
+     * @return false|mixed
+     */
+    public static function reportActive($uid)
+    {
+        if (empty($uid) || (int)$uid !== 198678241) {
+            return false;
+        }
+
+        // 获取用户缓存
+        $now       = date('Y-m-d H:i:s');
+        $userCache = UserCache::getUserInfo($uid);
+        if (empty($userCache)) {
+            $user = UserService::getById($uid);
+            if ($user === null) {
+                return false;
+            }
+
+            // 初始化缓存
+            $userCache = [
+                'uid'           => $uid,
+                'channel_id'    => getProp($user, 'distribution_channel_id', 0),
+                'send_order_id' => getProp($user, 'send_order_id', 0),
+                'register_time' => $user->created_at->format('Y-m-d H:i:s'),
+                'active_time'   => $now
+            ];
+            UserCache::setUserInfo($uid, $userCache);
+        }
+
+        // 获取注册时间、活跃时间
+        $registerAt      = getProp($userCache, 'register_time');
+        $activeAt        = getProp($userCache, 'active_time');
+        $registerYmd     = date('Y-m-d', strtotime($registerAt));
+        $registerNextYmd = date('Y-m-d', strtotime($registerYmd . ' +1 day'));
+        $activeYmd       = date('Y-m-d', strtotime($activeAt));
+        $todayYmd        = date('Y-m-d');
+
+        // 判断是否是次留回传
+        if ($registerYmd === $activeYmd && $todayYmd === $registerNextYmd) {
+            self::report($userCache);
+        }
+
+        // 更新用户活跃时间
+        return UserCache::setUserInfo($uid, ['active_time' => $now]);
+    }
+
+    /**
+     * 上报
+     * @param $userCache
+     * @return ResponseInterface
+     */
+    private static function report($userCache)
+    {
+        $client = new Client(['timeout' => 3, 'verify' => false]);
+
+        // 执行上报
+        return $client->post(env('REPORT_URI') . '/api/reportSActive', [
+            'headers' => [
+                'x-code' => 'Mvnx1Yr3O8i!TS5u'
+            ],
+            'json'    => [
+                'uid'           => getProp($userCache, 'uid'),
+                'channel_id'    => getProp($userCache, 'channel_id'),
+                'register_time' => getProp($userCache, 'register_time'),
+                'active_time'   => getProp($userCache, 'active_time'),
+                'platform'      => 'zhuishuyun',
+            ]
+        ]);
+    }
+}