原理:
就是用个数据库保存会员下载信息,下次下载同一附件校验一下是否过期,没过期就不扣分。需要的字段,明白人都知道:aid,uid,dateline,再加个自增字段id
创建数据库脚本- --
- -- 表的结构 `pre_forum_attachment_once`
- --
- DROP TABLE IF EXISTS `pre_forum_attachment_once`;
- CREATE TABLE IF NOT EXISTS `pre_forum_attachment_once` (
- `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
- `aid` mediumint(8) unsigned NOT NULL DEFAULT '0',
- `uid` mediumint(8) unsigned NOT NULL DEFAULT '0',
- `dateline` int(10) unsigned NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`)
- ) TYPE=MyISAM AUTO_INCREMENT=8 ;
复制代码 2、修改forum_misc.php文件,路径:x:/你的网站目录/source/module/forum
查找代码- $getattachcredits = updatecreditbyaction('getattach', $_G['uid'], array(), '', 1, 1, $thread['fid']);
复制代码 替换为- $_G['policymsg'] = $p = '';
- //避免重复扣积分
- if(DB::fetch_first('SELECT * FROM '.DB::table('forum_attachment_once')." WHERE aid='$aid' AND uid='$_G[uid]'")) {
-
- $_G['policymsg'] = '积分不受影响';
-
- } else{
- $getattachcredits = updatecreditbyaction('getattach', $_G['uid'], array(), '', 1, 1, $thread['fid']);
-
- //forum_attachment_once插入下载记录
- DB::query('insert into '.DB::table('forum_attachment_once')." (`aid`, `uid`, `dateline`) VALUES ('$aid', '$_G[uid]', '$_G[timestamp]')");
- if($getattachcredits['updatecredit']) {
- if($getattachcredits['updatecredit']) for($i = 1;$i <= 8;$i++) {
- if($policy = $getattachcredits['extcredits'.$i]) {
- $_G['policymsg'] .= $p.($_G['setting']['extcredits'][$i]['img'] ? $_G['setting']['extcredits'][$i]['img'].' ' : '').$_G['setting']['extcredits'][$i]['title'].' '.$policy.' '.$_G['setting']['extcredits'][$i]['unit'];
- $p = ', ';
- }
- }
- }
- }
复制代码 3、光这些还不够,没有自动清除代码,下面我们在计划任务中添加个自动处理
将下面代码保存成文件cron_clean_forum_attachment_once.php,并放到x:/你的网站目录/source/include/cron目录
- /**
- * diy编程器论坛 liyf 编写
- * [url]http://kitebee.meibu.com[/url]
- * 2012.4.9
- * 清理forum_attachment_once表下载记录,默认保留1天
- * cron_clean_forum_attachment_once.php
- */
- if(!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
- //设置保留有效期天数
- $expire_date = 1; //默认设置为1天过期
- //将时间转为秒
- $deltime = $_G['timestamp'] - $expire_date*3600*24; //扣除有效期后剩余时间,秒
- //删除所有小于有效期的记录
- DB::query('delete from '.DB::table('forum_attachment_once')." where `dateline`<'$deltime'");
- ?>
复制代码
任务脚本就是上面建的那个文件
好了,全部搞定,自己去下个附件,第一次正常扣分,第二次嘛就是下面的效果了
最终效果图
|