进入 source/include/post/post_newreply.php 文件,在 438 行附近找到如下代码:

  1. if($thread['replycredit'] > 0 && $thread['authorid'] != $_G['uid'] && $_G['uid']) {

如果 $thread['replycredit'] 大于 0,同时帖子作者不是当前登录用户,则进入下面的处理流程。
$thread['replycredit'] 为当前帖子的回帖奖励总积分。

  1. $replycredit_rule = DB::fetch_first("SELECT * FROM ".DB::table('forum_replycredit')." WHERE tid = '$_G[tid]' LIMIT 1");
  2. $have_replycredit = DB::result_first("SELECT COUNT(*) FROM
    ".DB::table('common_credit_log')." WHERE relatedid = '{$_G[tid]}' AND
    uid = '{$_G[uid]}' AND operation = 'RCA' LIMIT
    {$replycredit_rule['times']} ");

$replycredit_rule 为从 forum_replycredit 表中查询该帖的回帖奖励设置数组,具体格式为

  1. array(
  2.         'tid' => '帖子 tid',
  3.         'extcredits' => '每次回帖的奖励积分',
  4.         'times' => '奖励次数',
  5.         'membertimes' => '每个人最多奖励的次数',
  6.         'random' => '中奖率',
  7.         'extcreditstype' => '奖励的积分类型',
  8. )

$have_replycredit 为从 common_credit_log 表中查询该帖中当前登录用户的已奖励次数。

  1. if($replycredit_rule['membertimes']
    - $have_replycredit > 0 && $thread['replycredit'] -
    $replycredit_rule['extcredits'] >= 0) {


果该帖的每个人最多奖励次数 $replycredit_rule['membertimes'] 大于该帖中当前登录用户的已奖励次
数 $have_replycredit,同时该帖的回帖奖励总积分 $thread['replycredit'] 大于或等于该帖每次回帖的奖励积
分 $replycredit_rule['extcredits'] 。

  1. $replycredit_rule['extcreditstype']
    = $replycredit_rule['extcreditstype'] ?
    $replycredit_rule['extcreditstype'] :
    $_G['setting']['creditstransextra'][10];

$replycredit_rule['extcreditstype']
为该帖奖励积分的积分类型,如果存在 $replycredit_rule['extcreditstype'] 的话就
为 $replycredit_rule['extcreditstype'],否则为 $_G['setting']
['creditstransextra'][10] 。
$_G['setting']['creditstransextra'][10] 为后台-> 全局-> 积分设置下设置的回帖奖励使用的积分。

  1. if($replycredit_rule['random'] > 0) {
  2.                 $rand = rand(1, 100);
  3.                 $rand_replycredit = $rand <= $replycredit_rule['random'] ? true : false ;
  4. } else {
  5.                 $rand_replycredit = true;
  6. }

如果该帖回帖奖励的中奖率 $replycredit_rule['random'] 大于 0:
$rand 为在 1-100 中间生成的一个随机数,如果 $rand 小于或等于 $replycredit_rule['random'],则设置 $rand_replycredit 为 true,否则为 false 。
如果该帖回帖奖励的中奖率 $replycredit_rule['random'] 不大于 0:
设置 $rand_replycredit 为 true 。

  1. if($rand_replycredit) {
  2.                 if(!$posttable) {
  3.                                 $posttable = getposttablebytid($_G['tid']);
  4.                 }
  5.                 updatemembercount($_G['uid'],
    array($replycredit_rule['extcreditstype'] =>
    $replycredit_rule['extcredits']), 1, 'RCA', $_G[tid]);
  6.                 DB::update($posttable, array('replycredit' => $replycredit_rule['extcredits']), array('pid' => $pid));
  7.                 DB::update("forum_thread", array('replycredit'
    => $thread['replycredit'] - $replycredit_rule['extcredits']),
    array('tid' => $_G[tid]));
  8. }

如果存在 $rand_replycredit:

  1. if(!$posttable) {
  2. $posttable = getposttablebytid($_G['tid']);
  3. }

如果不存在回帖表 $posttable,则通过 tid 获取 $posttable 。

  1. updatemembercount($_G['uid'],
    array($replycredit_rule['extcreditstype'] =>
    $replycredit_rule['extcredits']), 1, 'RCA', $_G[tid]);


据回帖奖励的规则,更新当前登录用户的积分:在原有积分基础
上+$replycredit_rule['extcredits'] 。 $replycredit_rule['extcreditstype'] 为积分
类型,$replycredit_rule['extcredits'] 为奖励积分数。

  1. DB::update($posttable, array('replycredit' => $replycredit_rule['extcredits']), array('pid' => $pid));

更新回帖表 $posttable 中当前用户回复的积分奖励。

  1. DB::update("forum_thread",
    array('replycredit' => $thread['replycredit'] -
    $replycredit_rule['extcredits']), array('tid' => $_G[tid]));

$thread['replycredit'] - $replycredit_rule['extcredits'] 为计算回帖奖励的剩余总积分。
更新主题表 forum_thread 中当前帖子的回帖奖励总积分 replycredit 。