进入 source/include/post/post_newreply.php 文件,在 438 行附近找到如下代码:
- if($thread['replycredit'] > 0 && $thread['authorid'] != $_G['uid'] && $_G['uid']) {
如果 $thread['replycredit'] 大于 0,同时帖子作者不是当前登录用户,则进入下面的处理流程。
$thread['replycredit'] 为当前帖子的回帖奖励总积分。
- $replycredit_rule = DB::fetch_first("SELECT * FROM ".DB::table('forum_replycredit')." WHERE tid = '$_G[tid]' LIMIT 1");
- $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 表中查询该帖的回帖奖励设置数组,具体格式为
- array(
- 'tid' => '帖子 tid',
- 'extcredits' => '每次回帖的奖励积分',
- 'times' => '奖励次数',
- 'membertimes' => '每个人最多奖励的次数',
- 'random' => '中奖率',
- 'extcreditstype' => '奖励的积分类型',
- )
$have_replycredit 为从 common_credit_log 表中查询该帖中当前登录用户的已奖励次数。
- if($replycredit_rule['membertimes']
- $have_replycredit > 0 && $thread['replycredit'] -
$replycredit_rule['extcredits'] >= 0) {
如
果该帖的每个人最多奖励次数 $replycredit_rule['membertimes'] 大于该帖中当前登录用户的已奖励次
数 $have_replycredit,同时该帖的回帖奖励总积分 $thread['replycredit'] 大于或等于该帖每次回帖的奖励积
分 $replycredit_rule['extcredits'] 。
- $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] 为后台-> 全局-> 积分设置下设置的回帖奖励使用的积分。
- if($replycredit_rule['random'] > 0) {
- $rand = rand(1, 100);
- $rand_replycredit = $rand <= $replycredit_rule['random'] ? true : false ;
- } else {
- $rand_replycredit = true;
- }
如果该帖回帖奖励的中奖率 $replycredit_rule['random'] 大于 0:
$rand 为在 1-100 中间生成的一个随机数,如果 $rand 小于或等于 $replycredit_rule['random'],则设置 $rand_replycredit 为 true,否则为 false 。
如果该帖回帖奖励的中奖率 $replycredit_rule['random'] 不大于 0:
设置 $rand_replycredit 为 true 。
- if($rand_replycredit) {
- if(!$posttable) {
- $posttable = getposttablebytid($_G['tid']);
- }
- updatemembercount($_G['uid'],
array($replycredit_rule['extcreditstype'] =>
$replycredit_rule['extcredits']), 1, 'RCA', $_G[tid]); - DB::update($posttable, array('replycredit' => $replycredit_rule['extcredits']), array('pid' => $pid));
- DB::update("forum_thread", array('replycredit'
=> $thread['replycredit'] - $replycredit_rule['extcredits']),
array('tid' => $_G[tid])); - }
如果存在 $rand_replycredit:
- if(!$posttable) {
- $posttable = getposttablebytid($_G['tid']);
- }
如果不存在回帖表 $posttable,则通过 tid 获取 $posttable 。
- updatemembercount($_G['uid'],
array($replycredit_rule['extcreditstype'] =>
$replycredit_rule['extcredits']), 1, 'RCA', $_G[tid]);
根
据回帖奖励的规则,更新当前登录用户的积分:在原有积分基础
上+$replycredit_rule['extcredits'] 。 $replycredit_rule['extcreditstype'] 为积分
类型,$replycredit_rule['extcredits'] 为奖励积分数。
- DB::update($posttable, array('replycredit' => $replycredit_rule['extcredits']), array('pid' => $pid));
更新回帖表 $posttable 中当前用户回复的积分奖励。
- DB::update("forum_thread",
array('replycredit' => $thread['replycredit'] -
$replycredit_rule['extcredits']), array('tid' => $_G[tid]));
$thread['replycredit'] - $replycredit_rule['extcredits'] 为计算回帖奖励的剩余总积分。
更新主题表 forum_thread 中当前帖子的回帖奖励总积分 replycredit 。