|
@@ -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',
|
|
|
|
+ ]
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+}
|