DISCUZ X3.0 积分增减以及记录
1、调用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; }
2、该方法中调用了source/function/function_credit.php 里面的_updatemembercount()方法,函数原型如下:
/* * @$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); } }
3、记录增加:引用了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)); } }
4、积分变更操作:引用了:source/class/class_credit.php类文件中的 与入口方法同名的updatemembercount()方法执行最后的变更操作:
/* * @$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(); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。