PvuvCollectService.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\main\service;
  3. use app\common\library\Redis;
  4. use app\common\model\AdminExtend;
  5. class PvuvCollectService extends BaseService
  6. {
  7. /**
  8. * @var PvuvCollectService
  9. */
  10. protected static $self = null;
  11. public static function instance()
  12. {
  13. if (self::$self == null) {
  14. self::$self = new self();
  15. }
  16. return self::$self;
  17. }
  18. /**
  19. * pv的redis key
  20. * @param $adminId
  21. * @param null $date
  22. * @return string
  23. */
  24. public function getPvKey($adminId, $date = null)
  25. {
  26. $date = empty($date) ? date('Ymd') : $date;
  27. return sprintf('PVCL:%s:%s', $date, $adminId);
  28. }
  29. /**
  30. * uv的redis key
  31. * @param $adminId
  32. * @param null $date
  33. * @return string
  34. */
  35. public function getUvKey($adminId, $date = null)
  36. {
  37. $date = empty($date) ? date('Ymd') : $date;
  38. return sprintf('UVCL:%s:%s', $date, $adminId);
  39. }
  40. public function indexDot()
  41. {
  42. $timeOutStamp = strtotime(date('Y-m-d 01:00:00', strtotime('+1 day')));
  43. $userInfo = UserService::instance()->getUserInfo();
  44. $userId = $userInfo->id;
  45. $adminId = empty($userInfo->agent_id) ? $userInfo->channel_id : $userInfo->agent_id;
  46. if (!$userId) {
  47. return false;
  48. }
  49. #region 全站pvuv
  50. $wholePvKey = $this->getPvKey(0);
  51. $wholeUvKey = $this->getUvKey(0);
  52. Redis::instance()->pfAdd($wholeUvKey, $userId);
  53. if (Redis::instance()->incr($wholePvKey) == 1) {
  54. Redis::instance()->expireAt($wholePvKey, $timeOutStamp);
  55. Redis::instance()->expireAt($wholeUvKey, $timeOutStamp);
  56. }
  57. #endregion
  58. // 判断是代理还是渠道
  59. if ($userInfo->agent_id) { // 存在代理,给代理加
  60. // amdin_id = agent_id and type = 1 and flag = 1 and createdate
  61. $agentId = $userInfo->agent_id;
  62. $adminPvKey = $this->getPvKey($agentId);
  63. Redis::instance()->incr($adminPvKey);
  64. Redis::instance()->expireAt($adminPvKey, $timeOutStamp);
  65. $adminUvKey = $this->getUvKey($agentId);
  66. Redis::instance()->pfAdd($adminUvKey, $userId);
  67. Redis::instance()->expireAt($adminUvKey, $timeOutStamp);
  68. }
  69. if ($channel_id = AdminService::instance()->getAdminExtendModel()->getChannelId($userInfo->channel_id)) {
  70. // 渠道 amdin_id = channel_id and type = 1 and flag = 3 and createdate
  71. $adminPvKey = $this->getPvKey($adminId);
  72. Redis::instance()->incr($adminPvKey);
  73. Redis::instance()->expireAt($adminPvKey, $timeOutStamp);
  74. $adminUvKey = $this->getUvKey($adminId);
  75. Redis::instance()->pfAdd($adminUvKey, $userId);
  76. Redis::instance()->expireAt($adminUvKey, $timeOutStamp);
  77. }
  78. // 给全局加 admin_id = 0 and type = 1 and flag = 3
  79. }
  80. }