| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace bizHd\stat\classes;
- use Yii;
- use bizHd\base\classes\BaseClass;
- /**
- * 零售端 -- 浏览记录与浏览统计
- * Class StatVisitClass
- * @package bizHd\stat\classes
- */
- class StatVisitClass extends BaseClass
- {
- //public static $baseFile = '\bizHd\stat\models\StatVisit';
- //零售记录访客
- public static function addHdCustomVisit($shopId, $userId, $date = null)
- {
- $date = isset($date) == false ? date("Ymd") : $date;
- $cacheKey = 'hd_visit:' . $shopId . '_' . $date;
- $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $userId]);
- if (empty($exists)) {
- Yii::$app->redis->executeCommand('SADD', [$cacheKey, $userId]);
- }
- // 只缓存1天:若未设置过期时间则设置为 86400 秒
- $ttl = (int)Yii::$app->redis->executeCommand('TTL', [$cacheKey]);
- if ($ttl === -1) {
- Yii::$app->redis->executeCommand('EXPIRE', [$cacheKey, 86400]);
- }
- }
- //保存访客数
- public static function saveVisit($shop, $visitNum, $date = null)
- {
- }
- //获取访客数
- public static function getVisitNum($shopId, $date = null)
- {
- $date = isset($date) == false ? date("Ymd") : $date;
- $cacheKey = 'hd_visit:' . $shopId . '_' . $date;
- $num = Yii::$app->redis->executeCommand('SCARD', [$cacheKey]);
- return intval($num);
- }
- //获取访客ID
- public static function getVisitCustomIds($shopId, $date = null)
- {
- $date = isset($date) ? $date : date("Ymd");
- $cacheKey = 'hd_visit:' . $shopId . '_' . $date;
- $userIds = Yii::$app->redis->executeCommand('SMEMBERS', [$cacheKey]);
- return $userIds;
- }
- }
|