·设为首页收藏本站📧邮箱修改🎁免费下载专区💎积分✅卡密📒收藏夹👽聊天室
返回列表 发布新帖

DISCUZ X3.0 积分增减以及记录

654 0
发表于 2021-12-29 16:55:55 | 查看全部 阅读模式

马上注册,免费下载更多dz插件网资源。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
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();
}
}
我要说一句 收起回复

回复

 懒得打字嘛,点击右侧快捷回复【查看最新发布】   【应用商城享更多资源】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

图文热点
创宇盾启航版免费网站防御网站加速服务
投诉/建议联系

discuzaddons@vip.qq.com

未经授权禁止转载,复制和建立镜像,
如有违反,按照公告处理!!!
  • 联系QQ客服
  • 添加微信客服

联系DZ插件网微信客服|最近更新|Archiver|手机版|小黑屋|DZ插件网! ( 鄂ICP备20010621号-1 )|网站地图 知道创宇云防御

您的IP:3.149.251.26,GMT+8, 2024-11-23 21:15 , Processed in 0.271683 second(s), 76 queries , Gzip On, Redis On.

Powered by Discuz! X5.0 Licensed

© 2001-2024 Discuz! Team.

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表