進入 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 。