赞
踩
- <?php
- namespace app\news\controller;
- use app\login\model\News;
- use think\facade\Cache;
- /**
- * Class ViewCount
- * @package app\news\controller
- * 文章浏览量类
- */
- class ViewCount extends News
- {
- protected $redis = null;
- protected $hash_prefix; //浏览数hash前缀
- protected $field_prefix; //字段前缀
- protected $id;
- protected $date;
- public function __construct()
- {
- $this->redis = Cache::store('redis');
- $this->hash_prefix = 'news_view_counts_';
- $this->field_prefix = 'news_';
- $this->date = date('Y-m-d');
- }
- /**
- * 设置文章浏览数
- * 每天的文章浏览数存在redis hash,如news_view_counts_2020-07-13
- * hash字段存储的是每个文章的浏览数,如news_1
- * 获取hash字段的值,如存在+1,不存在设置1
- * @param int $id 文章id
- * @return bool
- *
- */
- public function viewCountIncrement($id)
- {
- if (empty($id)) {
- return
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。