zoukankan      html  css  js  c++  java
  • phpcms 下载数统计

    phpcms系统自带阅读数,评论数,下载数需要修改一下,

    前端代码:

    <a href="{$download_url}" id="download" target="_blank">立即下载</a>
    <img src="/common/img/a1.png" title="下载数" /><span id='downcount'></span>
    

      

      

    前端js代码:

    /***统计获取下载数***/
    	function downcount(act){
            $.ajax({
                    type:"GET",
                    url:"{APP_PATH}api.php",
                    data:"op=dcount&id={$id}&modelid={$modelid}&act="+act,
                    async:true,
                    success:function(data){
                    if( act != "set" ){
                            var arr=data.split(",");
                            $("#downcount").html(arr[0]);
                           
                            }
                    }
              });
    	}
    
           $(document).ready(function(){
              downcount("get");
              $("#download").click(function(){
                  downcount("set");
              });
    	});
    

      

    注意js前面引入jquery库,类名要对应,然后根目录api文件加入dcount.php,内容如下

    <?php
    defined('IN_PHPCMS') or exit('No permission resources.'); 
    /**
     * 下载统计
     */
    $db = '';
    $db = pc_base::load_model('hits_model');
    if($_GET['modelid'] && $_GET['id'] && $_GET['act']) {
    	$modelid = intval($_GET['modelid']);
    	$hitsid = 'c-'.$modelid.'-'.intval($_GET['id']);
    	if($_GET['act']=="set"){
    		hits($hitsid);
    	}
    	$r = get_count($hitsid);
    	if(!$r) exit;
        extract($r);
        echo $downcount;
    }
    
    /**
     * 获取下载次数
     * @param $hitsid
     */
    function get_count($hitsid) {
    	global $db;
        $r = $db->get_one(array('hitsid'=>$hitsid));  
        if(!$r) return false;	
    	return $r;	
    }
    
    /**
     * 下载次数统计
     * @param $contentid
     */
    function hits($hitsid) {
    	global $db;
    	$r = $db->get_one(array('hitsid'=>$hitsid));
    	if(!$r) return false;
    	$downcount = $r['downcount'] + 1;
    	$sql = array('downcount'=>$downcount);
        return $db->update($sql, array('hitsid'=>$hitsid));
    }
    
    ?>
    

      

      

    注意数据库hits加downcount字段,基本就可以达到效果了。

    本文参考此文,http://bbs.phpcms.cn/thread-461933-1-1.html

  • 相关阅读:
    Typora的使用
    selenium中webdriver提供的八大定位元素方法
    JAVA的Data和Timestamp的相互转换
    Jmeter设置参数作为断言依据
    Springboot +Poi 导入Excel表格
    window.location.reload();
    带参数的链接跳转
    Layui结束时间不能小于开始时间
    后台返回数据渲染Layui表格
    Layui中layedit模板的使用
  • 原文地址:https://www.cnblogs.com/danche/p/5787816.html
Copyright © 2011-2022 走看看