| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- declare(strict_types=1);
- /**
- * This file is part of Hyperf.
- *
- * @link https://www.hyperf.io
- * @document https://doc.hyperf.io
- * @contact group@hyperf.io
- * @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
- */
- namespace App\Jobs;
- use App\Repositories\UserRepository;
- use Carbon\Carbon;
- use Hyperf\AsyncQueue\Job;
- use Hyperf\Redis\Redis;
- class AddHyperLogLogJob extends Job
- {
- public $params;
- public function __construct($params)
- {
- // 这里最好是普通数据,不要使用携带 IO 的对象,比如 PDO 对象
- $this->params = $params;
- }
- public function handle()
- {
- try {
- $cachePrefix = env('SERVER_CACHE_PREFIX', 'c:');
- $redis = make(Redis::class);
- $prfix = $cachePrefix .'active:' . Carbon::now()->toDateString();
- //日活统计key
- $device = $prfix . ':' . $this->params['device_type'];
- //今天的单设备
- $redis->pfadd($device, array($this->params['user_id']));
- //用户是否为会员
- $info = make(UserRepository::class)
- ->getUserInfoFromCache($this->params['user_id']);
- $redis->pfadd(
- $prfix . ':' . $info['is_vip'],
- array($this->params['user_id']
- )
- );
- //今天的总设备
- $redis->pfadd($prfix, array($this->params['user_id']));
- } catch (\Exception $exception) {
- logger('AddHyperLogLogJob', [$exception->getMessage()]);
- }
- }
- }
|