Discuz浏览主题扣分修改方法(代码版)

涉及到有些朋友做的站不是超级大众型,或者有付费浏览的需要,为网站增加收益,为好的资源分享加分,为原创埋单,为论坛积极发展贡献,分享下我找到的方法。适用于DZ7.2,测试通过,DZ X可能可以参考吧。

一、简介

功能:可以使会员在浏览某些版区的帖子,尤其是精华帖子的时候,扣除部分积分给作者

原理说明:采用cookies和数据表的双重记录,只要有任何一个记录存在都判定为通过。

例外的情况说明:管理员和超级版主不会受到浏览扣分的影响,版主在自己管辖区域内也不会被影响

二、修改方法(代码)

坏小子注:注意半角符号。
把viewthread_viewpay.htm上传到templates/default/目录中
SQL:

1
2
3
4
5
6
7
8
9
10
11
ALTER TABLE `cdb_forumfields` ADD `digest1credits` VARCHAR( 255 ) NOT NULL ,
ADD `digest2credits` VARCHAR( 255 ) NOT NULL ,
ADD `digest3credits` VARCHAR( 255 ) NOT NULL ,
ADD `viewcredits` VARCHAR( 255 ) NOT NULL ,
ADD `returnrate` INT( 3 ) NOT NULL ,
ADD `paydate` INT( 3 ) NOT NULL ;
ALTER TABLE `cdb_usergroups`
ADD `digest1free` tinyint(1) NOT NULL  default '0',
ADD `digest2free` tinyint(1) NOT NULL  default '0',
ADD `digest3free` tinyint(1) NOT NULL  default '0',
ADD `viewfree` tinyint(1) NOT NULL  default '0';

打开admin/forums.inc.php
找到:

1
'postattachcredits', 'getattachcredits',

在后面加:

1
'digest1credits', 'digest2credits', 'digest3credits', 'viewcredits',

找到:

1
$forum['getattachcredits'] = $forum['getattachcredits'] ? unserialize($forum['getattachcredits']) : array();

在下面加上:

1
2
3
4
            $forum['digest1credits'] = $forum['digest1credits'] ? unserialize($forum['digest1credits']) : array();
            $forum['digest2credits'] = $forum['digest2credits'] ? unserialize($forum['digest2credits']) : array();
            $forum['digest3credits'] = $forum['digest3credits'] ? unserialize($forum['digest3credits']) : array();
          $forum['viewcredits'] = $forum['viewcredits'] ? unserialize($forum['viewcredits']) : array();

找到:

1
'post', 'reply', 'digest', 'postattach', 'getattach'

替换成:(有两个结果,都这样做)

1
'post', 'reply', 'digest', 'postattach', 'getattach','digest1', 'digest2', 'digest3', 'view'

找到:

1
getattachcredits='$getattachcreditsnew',

在后面加:

1
digest1credits='$digest1creditsnew',digest2credits='$digest2creditsnew',digest3credits='$digest3creditsnew',viewcredits='$viewcreditsnew',

找到:

1
showsetting('forums_edit_posts_attach_ext', 'attachextensionsnew', $forum['attachextensions'], 'text');

在下面加:

1
2
            showsetting('settings_fs_returnrate', 'returnratenew', $forum['returnrate'], 'text');
            showsetting('settings_fs_paydate', 'paydatenew', $forum['paydate'], 'text');

找到:

1
$allowpostspecialtrade = intval($allowpostspecialnew[2]);

在上面加:

1
2
$returnratenew = intval($returnratenew);
$paydatenew = intval($paydatenew);

找到:

1
attachextensions='$attachextensionsnew',

在后面加:

1
returnrate='$returnratenew', paydate='$paydatenew',

打开admincp.lang.php(在templates/default中)
找到:

1
'settings_credits_policy_post' => '发主题(+)',

在上面加:

1
2
3
4
5
6
7
8
9
10
11
12
  'settings_fs_returnrate' => '返回比率(%)',
    'settings_fs_returnrate_comment' => '如果设置了浏览主题或者浏览精华主题扣取积分,那么这个比例的扣取积分会返回给作者,请在0~100之内设置,0为不返回',
    'settings_fs_paydate' => '支付有效期(天)',
    'settings_fs_paydate_comment' => '如果设置了浏览主题或者浏览精华主题扣分,那么在这个天数内重复浏览不再扣分,设置为0表示每次浏览均要扣分',    
    'settings_credits_policy_digest1' => '浏览精华I(-)',
    'settings_credits_policy_digest1_comment' => '浏览精华主题I时所扣减的积分',
    'settings_credits_policy_digest2' => '浏览精华II(-)',
    'settings_credits_policy_digest2_comment' => '浏览精华主题II时所扣减的积分',
    'settings_credits_policy_digest3' => '浏览精华III(-)',
    'settings_credits_policy_digest3_comment' => '浏览精华主题III时所扣减的积分',
    'settings_credits_policy_view' => '浏览主题(-)',
    'settings_credits_policy_view_comment' => '浏览普通主题时所扣减的积分',

打开admin/usergroups.inc.php
找到:

1
showsetting($lang['usergroups_edit_credit_exempt_inperm'].$lang['usergroups_edit_credit_exempt_threadpay'], 'exemptnew[7]', $group['exempt'][7], 'radio');

在下面加:

1
2
3
4
showsetting('管辖版区以外浏览普通主题不扣分', 'viewfreenew', $group['viewfree'], 'radio');
              showsetting('管辖版区以外浏览精华主题I不扣分', 'digest1freenew', $group['digest1free'], 'radio');
              showsetting('管辖版区以外浏览精华主题II不扣分', 'digest2freenew', $group['digest2free'], 'radio');
              showsetting('管辖版区以外浏览精华主题III不扣分', 'digest3freenew', $group['digest3free'], 'radio');

找到:

1
showsetting('usergroups_edit_credit_exempt_threadpay', 'exemptnew[4]', $group['exempt'][4], 'radio');

在下面加:

1
2
3
4
showsetting('浏览普通主题不扣分', 'viewfreenew', $group['viewfree'], 'radio');
            showsetting('浏览精华主题I不扣分', 'digest1freenew', $group['digest1free'], 'radio');
            showsetting('浏览精华主题II不扣分', 'digest2freenew', $group['digest2free'], 'radio');
            showsetting('浏览精华主题III不扣分', 'digest3freenew', $group['digest3free'], 'radio');

找到:

1
grouptitle='$grouptitlenew',

在后面加:

1
viewfree = '$viewfreenew',digest1free = '$digest1freenew',digest2free = '$digest2freenew',digest3free = '$digest3freenew',

打开viewthread.php(根目录)
找到:

1
$oldtopics = isset($_DCOOKIE['oldtopics']) ? $_DCOOKIE['oldtopics'] : 'D';

在上面加:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
///////浏览主题扣分
$query = $db->query("SELECT * FROM {$tablepre}forumfields WHERE fid='$fid' LIMIT 1");
if($fields = $db->fetch_array($query)) {
  $needpay = 1;    
 
    if($thread['digest'] == 3 && ($digest3free || !$fields['digest3credits']))$needpay = 0;
    if($thread['digest'] == 2 && ($digest2free || !$fields['digest2credits']))$needpay = 0;
    if($thread['digest'] == 1 && ($digest1free || !$fields['digest1credits']))$needpay = 0;
    if($thread['digest'] == 0 && ($viewfree || !$fields['viewcredits']))$needpay = 0;  
    if($forum['ismoderator'] || $thread['authorid'] == $discuz_uid)$needpay = 0;
 
    $fields['digest1credits'] = $fields['digest1credits'] && !$digest1free ? unserialize($fields['digest1credits']) : array();
    $fields['digest2credits'] = $fields['digest2credits'] && !$digest2free ? unserialize($fields['digest2credits']) : array();
    $fields['digest3credits'] = $fields['digest3credits'] && !$digest3free ? unserialize($fields['digest3credits']) : array();
    $fields['viewcredits'] = $fields['viewcredits'] && !$viewfree ? unserialize($fields['viewcredits']) : array();    
   
    if($needpay && !$discuz_uid)showmessage('对不起,浏览该主题必须要先登录,请返回');
  if($needpay){
      if($action == 'payfortheview') {
         
          if($thread['digest'] == 3){
            foreach($fields['digest3credits'] as $id => $value){
                 if($fields['digest3credits'][$id] > ${'extcredits'.$id})showmessage('对不起,您的积分不足','forumdisplay.php?fid='.$fid);
            }
          }elseif($thread['digest'] == 2){
            foreach($fields['digest2credits'] as $id => $value){
                 if($fields['digest2credits'][$id] > ${'extcredits'.$id})showmessage('对不起,您的积分不足','forumdisplay.php?fid='.$fid);
            }
          }elseif($thread['digest'] == 1){
            foreach($fields['digest1credits'] as $id => $value){
                 if($fields['digest1credits'][$id] > ${'extcredits'.$id})showmessage('对不起,您的积分不足','forumdisplay.php?fid='.$fid);
            }
          }elseif($thread['digest'] == 0){
            foreach($fields['viewcredits'] as $id => $value){
                 if($fields['viewcredits'][$id] > ${'extcredits'.$id})showmessage('对不起,您的积分不足','forumdisplay.php?fid='.$fid);
            }              
          }        
               
          $expdate = $fields['paydate'] ? 86400*$fields['paydate'] : 30;
            dsetcookie('viewpays'.$tid, $tid, $expdate);        
            $expdate += $timestamp;
            $query = $db->query("DELETE FROM {$tablepre}paymentlog WHERE uid='$discuz_uid' AND tid='$tid' AND amount='0'");
            $query = $db->query("INSERT INTO {$tablepre}paymentlog (`uid`,`tid`,`dateline`,`amount`) VALUES ('$discuz_uid','$tid','$expdate', '0')");
           
            if($thread['digest'] == 3){updatecredits($discuz_uid, $fields['digest3credits'], -1);updatecredits($thread['authorid'], $fields['digest3credits'], $fields['returnrate']/100);}
            if($thread['digest'] == 2){updatecredits($discuz_uid, $fields['digest2credits'], -1);updatecredits($thread['authorid'], $fields['digest2credits'], $fields['returnrate']/100);}
            if($thread['digest'] == 1){updatecredits($discuz_uid, $fields['digest1credits'], -1);updatecredits($thread['authorid'], $fields['digest1credits'], $fields['returnrate']/100);}
            if($thread['digest'] == 0){updatecredits($discuz_uid, $fields['viewcredits'], -1);updatecredits($thread['authorid'], $fields['viewcredits'], $fields['returnrate']/100);}
   
            showmessage('感谢您的支持,现在进入主题页面', "viewthread.php?tid=$tid");      
      } elseif($tid != $_DCOOKIE['viewpays'.$tid] && !$searchpay = $sdb->fetch_first("SELECT * FROM {$tablepre}paymentlog WHERE tid='$tid' AND uid='$discuz_uid' AND amount='0' AND dateline > $timestamp")) {
          include template('viewthread_viewpay');
          exit();
      }
  }
}

二、后台设置方法

1、后台–用户–用户组–积分相关(最后面四项“否”)
2、后台–版块(要付费的板块)–积分策略–设置“浏览主题”这一项(如浏览此板块主题扣一分,那么就填写数字1)。
3、后台–版块(要付费的板块)–帖子相关–设置“返回比率”和“支付有效期”(表示在设定的有效期内不用二次付费)。

OK,完了,试试吧,是不是很完美。上面修改的地方有点多,不要看花眼了。

发表评论

:?: :razz: :sad: :!: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: :smile: :evil:
贴图 表情 ( ps. 若要贴代码, 请將 "<" 改成 "&lt;" 即可. )

4 + 3 = ?

这篇文章上的评论的RSS feed TrackBack URL