discuz X3评分流程分析



一、涉及到的文件


discuzX3/source/template/default/forum/rate.htm

discuzX3/forum.php

discuzX3/source/module/forum/forum_misc.php


二、流程(注意:流程顺序也是按照上面文件依次向下)


如上图评分->进入到forum_misc.php文件中处理。大约第606行

elseif($_GET['action'] == 'rate' && $_GET['pid']) {


rate方法即为评分分值的加减操作。大约在672行

foreach($_G['group']['raterange'] as $id => $rating) {
    $score = intval($_GET['score'.$id]);
    if(isset($_G['setting']['extcredits'][$id]) && !empty($score)) {
                                                                                                                                     
        //showmessage($id);
        $arr_goldId[]=$id;
        $arr_goldValue[]=$score;
                                                                                                                                     
        if($rating['isself'] && (intval($_G['member']['extcredits'.$id]) - $score < 0)) {
            showmessage('thread_rate_range_self_invalid', '', array('extcreditstitle' => $_G['setting']['extcredits'][$id]['title']));
        }
        if(abs($score) <= $maxratetoday[$id]) {
            if($score > $rating['max'] || $score < $rating['min']) {
                showmessage('thread_rate_range_invalid');
            } else {
                $creditsarray[$id] = $score;
                if($rating['isself']) {
                    $sub_self_credit[$id] = -abs($score);
                }
                $rate += $score;
                $ratetimes += ceil(max(abs($rating['min']), abs($rating['max'])) / 5);
            }
        } else {
            showmessage('thread_rate_ctrl');
        }
    }
}

这里DZ通过foreach循环分别获取用户的评分种类及相应分值。

//showmessage($id);
$arr_goldId[]=$id;
$arr_goldValue[]=$score;

数组$arr_goldId评分种类id;数组$arr_goldValue评分分值。

这里对“金钱”做二次开发:


if($arr_goldId[0] == 2){
    $goldValue=$arr_goldValue[0];
}
elseif($arr_goldId[0] == 1 && $arr_goldId[1] == 2){
    $goldValue=$arr_goldValue[1];
}      
if($arr_goldId[0] == 2 || ($arr_goldId[0] != 2 && $arr_goldId[1] == 2)){
                    
    /*****************************
    /*
    /******   To do something
    /*
    /******************************/
                    
    //showmessage($goldValue); 
}
showmessage('thread_rate_succeed', dreferer());