12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\main\service;
- use app\common\library\Redis;
- use app\common\model\AdminExtend;
- class PvuvCollectService extends BaseService
- {
- /**
- * @var PvuvCollectService
- */
- protected static $self = null;
- public static function instance()
- {
- if (self::$self == null) {
- self::$self = new self();
- }
- return self::$self;
- }
- /**
- * pv的redis key
- * @param $adminId
- * @param null $date
- * @return string
- */
- public function getPvKey($adminId, $date = null)
- {
- $date = empty($date) ? date('Ymd') : $date;
- return sprintf('PVCL:%s:%s', $date, $adminId);
- }
- /**
- * uv的redis key
- * @param $adminId
- * @param null $date
- * @return string
- */
- public function getUvKey($adminId, $date = null)
- {
- $date = empty($date) ? date('Ymd') : $date;
- return sprintf('UVCL:%s:%s', $date, $adminId);
- }
- public function indexDot()
- {
- $timeOutStamp = strtotime(date('Y-m-d 01:00:00', strtotime('+1 day')));
- $userInfo = UserService::instance()->getUserInfo();
- $userId = $userInfo->id;
- $adminId = empty($userInfo->agent_id) ? $userInfo->channel_id : $userInfo->agent_id;
- if (!$userId) {
- return false;
- }
- #region 全站pvuv
- $wholePvKey = $this->getPvKey(0);
- $wholeUvKey = $this->getUvKey(0);
- Redis::instance()->pfAdd($wholeUvKey, $userId);
- if (Redis::instance()->incr($wholePvKey) == 1) {
- Redis::instance()->expireAt($wholePvKey, $timeOutStamp);
- Redis::instance()->expireAt($wholeUvKey, $timeOutStamp);
- }
- #endregion
- // 判断是代理还是渠道
- if ($userInfo->agent_id) { // 存在代理,给代理加
- // amdin_id = agent_id and type = 1 and flag = 1 and createdate
- $agentId = $userInfo->agent_id;
- $adminPvKey = $this->getPvKey($agentId);
- Redis::instance()->incr($adminPvKey);
- Redis::instance()->expireAt($adminPvKey, $timeOutStamp);
- $adminUvKey = $this->getUvKey($agentId);
- Redis::instance()->pfAdd($adminUvKey, $userId);
- Redis::instance()->expireAt($adminUvKey, $timeOutStamp);
- }
- if ($channel_id = AdminService::instance()->getAdminExtendModel()->getChannelId($userInfo->channel_id)) {
- // 渠道 amdin_id = channel_id and type = 1 and flag = 3 and createdate
- $adminPvKey = $this->getPvKey($adminId);
- Redis::instance()->incr($adminPvKey);
- Redis::instance()->expireAt($adminPvKey, $timeOutStamp);
- $adminUvKey = $this->getUvKey($adminId);
- Redis::instance()->pfAdd($adminUvKey, $userId);
- Redis::instance()->expireAt($adminUvKey, $timeOutStamp);
- }
- // 给全局加 admin_id = 0 and type = 1 and flag = 3
- }
- }
|