http://www.bubuko.com/infodetail-663248.htmlphp
DISCUZ X3.0 積分增減以及記錄html
一、調用source/function/function_core.php 裏面的 updatemembercount()方法,該方法只是一個簡單的入口方法算法
/*
* @$uids 用戶
* @$dataarr 操做規則,如扣減第二個積分2分:array (‘extcredits2‘ => -2);
* @$checkgroup 是否檢查用戶組升級,一般未true
* @$operation 操做類型,默認空,若是須要增長記錄,須要填充
* @$relatedid 關係ID,例如帖子ID
* @$ruletxt 積分規則文本(黃色框提示扣費的文字顯示)
* @$customtitle 若是沒有操做類型,則會默認顯示這個爲記錄的title
* @$custommemo 這個是記錄的詳情
**/
function updatemembercount($uids, $dataarr = array(), $checkgroup = true, $operation = ‘‘, $relatedid = 0, $ruletxt = ‘‘, $customtitle = ‘‘, $custommemo = ‘‘) {
if(!empty($uids) && (is_array($dataarr) && $dataarr)) {
require_once libfile(‘function/credit‘);
return _updatemembercount($uids, $dataarr, $checkgroup, $operation, $relatedid, $ruletxt, $customtitle, $custommemo);
}
return true;
}
二、該方法中調用了source/function/function_credit.php 裏面的_updatemembercount()方法,函數原型以下:sql
/*
* @$uids 用戶
* @$dataarr 操做規則,如扣減第二個積分2分:array (‘extcredits2‘ => -2);
* @$checkgroup 是否檢查用戶組升級,一般未true
* @$operation 操做類型,默認空,若是須要增長記錄,須要填充
* @$relatedid 關係ID,例如帖子ID
* @$ruletxt 積分規則文本(黃色框提示扣費的文字顯示)
* @$customtitle 若是沒有操做類型,則會默認顯示這個爲記錄的title
* @$custommemo 這個是記錄的詳情
* 以上傳入參數基本由上一個入口方法updatemembercount()引入
**/
function _updatemembercount($uids, $dataarr = array(), $checkgroup = true, $operation = ‘‘, $relatedid = 0, $ruletxt = ‘‘, $customtitle = ‘‘, $custommemo = ‘‘) {
if(empty($uids)) return;//用戶不能爲空
if(!is_array($dataarr) || empty($dataarr)) return;//操做數組不能爲空
if($operation && $relatedid || $customtitle) {
$writelog = true;//必需要有操做類型以及關聯ID或者有自定義的操做標題$customtitle才寫入記錄
} else {
$writelog = false;
}
$data = $log = array();
foreach($dataarr as $key => $val) {//操做數組解析算法
if(empty($val)) continue;
$val = intval($val);
$id = intval($key);
$id = !$id && substr($key, 0, -1) == ‘extcredits‘ ? intval(substr($key, -1, 1)) : $id;
if(0 < $id && $id < 9) {
$data[‘extcredits‘.$id] = $val;
if($writelog) {
$log[‘extcredits‘.$id] = $val;
}
} else {
$data[$key] = $val;
}
}
if($writelog) {//增長記錄
credit_log($uids, $operation, $relatedid, $log, $customtitle, $custommemo);
}
if($data) {//引入新的類中的同入口方法名的方法
include_once libfile(‘class/credit‘);
$credit = & credit::instance();
$credit->updatemembercount($data, $uids, $checkgroup, $ruletxt);
}
}
三、記錄增長:引用了source/function/function_credit.php 裏面的 credit_log() 方法,函數原型以下:數組
/*
* @$uids 用戶
* @$operation 操做類型,默認空,若是須要增長記錄,須要填充
* @$relatedid 關係ID,例如帖子ID
* @$data 積分增減記錄數組
* @$customtitle 若是沒有操做類型,則會默認顯示這個爲記錄的title
* @$custommemo 這個是記錄的詳情
* 以上傳入參數基本由入口方法updatemembercount()引入,至此積分操做記錄增長完畢
**/
function credit_log($uids, $operation, $relatedid, $data, $customtitle, $custommemo) {
if((!$operation || empty($relatedid)) && !strlen($customtitle) || empty($uids) || empty($data)) {
return;
}
$log = array(
‘uid‘ => $uids,
‘operation‘ => $operation,
‘relatedid‘ => $relatedid,
‘dateline‘ => TIMESTAMP,
);
foreach($data as $k => $v) {
$log[$k] = $v;
}
if(is_array($uids)) {
foreach($uids as $k => $uid) {
$log[‘uid‘] = $uid;
$log[‘relatedid‘] = is_array($relatedid) ? $relatedid[$k] : $relatedid;
$insertid = C::t(‘common_credit_log‘)->insert($log, true);
C::t(‘common_credit_log_field‘)->insert(array(‘logid‘ => $insertid, ‘title‘ => $customtitle, ‘text‘ => $custommemo));
}
} else {
$insertid = C::t(‘common_credit_log‘)->insert($log, true);
C::t(‘common_credit_log_field‘)->insert(array(‘logid‘ => $insertid, ‘title‘ => $customtitle, ‘text‘ => $custommemo));
}
}
四、積分變動操做:引用了:source/class/class_credit.php類文件中的 與入口方法同名的updatemembercount()方法執行最後的變動操做:cookie
/*
* @$uids 用戶
* @$creditarr 積分變動操做數組
* @$checkgroup 是否檢查用戶組升級,一般未true
* @$ruletxt 變動規則/提醒文本
* 以上傳入參數基本由入口方法updatemembercount()引入,至此積分增減執行完畢
**/
function updatemembercount($creditarr, $uids = 0, $checkgroup = true, $ruletxt = ‘‘) {
global $_G;函數
if(!$uids) $uids = intval($_G[‘uid‘]);
$uids = is_array($uids) ? $uids : array($uids);
if($uids && ($creditarr || $this->extrasql)) {
if($this->extrasql) $creditarr = array_merge($creditarr, $this->extrasql);
$sql = array();
$allowkey = array(‘extcredits1‘, ‘extcredits2‘, ‘extcredits3‘, ‘extcredits4‘, ‘extcredits5‘, ‘extcredits6‘, ‘extcredits7‘, ‘extcredits8‘, ‘friends‘, ‘posts‘, ‘threads‘, ‘oltime‘, ‘digestposts‘, ‘doings‘, ‘blogs‘, ‘albums‘, ‘sharings‘, ‘attachsize‘, ‘views‘, ‘todayattachs‘, ‘todayattachsize‘);
$creditnotice = $_G[‘setting‘][‘creditnotice‘] && $_G[‘uid‘] && $uids == array($_G[‘uid‘]);
if($creditnotice) {
if(!isset($_G[‘cookiecredits‘])) {
$_G[‘cookiecredits‘] = !empty($_COOKIE[‘creditnotice‘]) ? explode(‘D‘, $_COOKIE[‘creditnotice‘]) : array_fill(0, 9, 0);
for($i = 1; $i <= 8; $i++) {
$_G[‘cookiecreditsbase‘][$i] = getuserprofile(‘extcredits‘.$i);
}
}
if($ruletxt) {
$_G[‘cookiecreditsrule‘][$ruletxt] = $ruletxt;
}
}
foreach($creditarr as $key => $value) {
if(!empty($key) && $value && in_array($key, $allowkey)) {
$sql[$key] = $value;
if($creditnotice && substr($key, 0, 10) == ‘extcredits‘) {
$i = substr($key, 10);
$_G[‘cookiecredits‘][$i] += $value;
}
}
}
if($creditnotice) {
dsetcookie(‘creditnotice‘, implode(‘D‘, $_G[‘cookiecredits‘]).‘D‘.$_G[‘uid‘]);
dsetcookie(‘creditbase‘, ‘0D‘.implode(‘D‘, $_G[‘cookiecreditsbase‘]));
if(!empty($_G[‘cookiecreditsrule‘])) {
dsetcookie(‘creditrule‘, strip_tags(implode("\t", $_G[‘cookiecreditsrule‘])));
}
}
if($sql) {
C::t(‘common_member_count‘)->increase($uids, $sql);
}
if($checkgroup && count($uids) == 1) $this->checkusergroup($uids[0]);
$this->extrasql = array();
}
}
post