DISCUZ积分增减以及记录-Discuz教程下载

DISCUZ积分增减以及记录

开通本站Svip会员,全站资源免费下
1、调用source/function/function_core.php 里面的 updatemembercount()方法,该方法只是一个简单的入口方法
  1. /*
  2.     * @$uids    用户
  3.     * @$dataarr    操作规则,如扣减第二个积分2分:array ('extcredits2' => -2);
  4.     * @$checkgroup    是否检查用户组升级,通常未true
  5.     * @$operation    操作类型,默认空,如果需要增加记录,需要填充
  6.     * @$relatedid    关系ID,例如帖子ID
  7.     * @$ruletxt    积分规则文本(黄色框提示扣费的文字显示)
  8.     * @$customtitle    如果没有操作类型,则会默认显示这个为记录的title
  9.     * @$custommemo     这个是记录的详情
  10.     **/
  11.     function updatemembercount($uids, $dataarr = array(), $checkgroup = true, $operation = '', $relatedid = 0, $ruletxt = '', $customtitle = '', $custommemo = '') {
  12.         if(!empty($uids) && (is_array($dataarr) && $dataarr)) {
  13.             require_once libfile('function/credit');
  14.             return _updatemembercount($uids, $dataarr, $checkgroup, $operation, $relatedid, $ruletxt, $customtitle, $custommemo);
  15.         }
  16.         return true;
  17.     }
复制代码
2、该方法中调用了source/function/function_credit.php 里面的_updatemembercount()方法,函数原型如下:
  1. /*
  2.     * @$uids    用户
  3.     * @$dataarr    操作规则,如扣减第二个积分2分:array ('extcredits2' => -2);
  4.     * @$checkgroup    是否检查用户组升级,通常未true
  5.     * @$operation    操作类型,默认空,如果需要增加记录,需要填充
  6.     * @$relatedid    关系ID,例如帖子ID
  7.     * @$ruletxt    积分规则文本(黄色框提示扣费的文字显示)
  8.     * @$customtitle    如果没有操作类型,则会默认显示这个为记录的title
  9.     * @$custommemo     这个是记录的详情
  10.     * 以上传入参数基本由上一个入口方法updatemembercount()引入
  11.     **/
  12.     function _updatemembercount($uids, $dataarr = array(), $checkgroup = true, $operation = '', $relatedid = 0, $ruletxt = '', $customtitle = '', $custommemo = '') {
  13.         if(empty($uids)) return;//用户不能为空
  14.         if(!is_array($dataarr) || empty($dataarr)) return;//操作数组不能为空
  15.         if($operation && $relatedid || $customtitle) {
  16.             $writelog = true;//必须要有操作类型以及关联ID或者有自定义的操作标题$customtitle才写入记录
  17.         } else {
  18.             $writelog = false;
  19.         }
  20.         $data = $log = array();
  21.         foreach($dataarr as $key => $val) {//操作数组解析算法
  22.             if(empty($val)) continue;
  23.             $val = intval($val);
  24.             $id = intval($key);
  25.             $id = !$id && substr($key, 0, -1) == 'extcredits' ? intval(substr($key, -1, 1)) : $id;
  26.             if(0 < $id && $id < 9) {
  27.                 $data['extcredits'.$id] = $val;
  28.                 if($writelog) {
  29.                     $log['extcredits'.$id] = $val;
  30.                 }
  31.             } else {
  32.                 $data[$key] = $val;
  33.             }
  34.         }
  35.         if($writelog) {//增加记录
  36.             credit_log($uids, $operation, $relatedid, $log, $customtitle, $custommemo);
  37.         }
  38.         if($data) {//引入新的类中的同入口方法名的方法
  39.             include_once libfile('class/credit');
  40.             $credit = & credit::instance();
  41.             $credit->updatemembercount($data, $uids, $checkgroup, $ruletxt);
  42.         }
  43.     }
复制代码
3、记录增加:引用了source/function/function_credit.php 里面的 credit_log() 方法,函数原型如下:
  1. /*
  2.     * @$uids    用户
  3.     * @$operation    操作类型,默认空,如果需要增加记录,需要填充
  4.     * @$relatedid    关系ID,例如帖子ID
  5.     * @$data    积分增减记录数组
  6.     * @$customtitle    如果没有操作类型,则会默认显示这个为记录的title
  7.     * @$custommemo     这个是记录的详情
  8.     * 以上传入参数基本由入口方法updatemembercount()引入,至此积分操作记录增加完毕
  9.     **/
  10.     function credit_log($uids, $operation, $relatedid, $data, $customtitle, $custommemo) {
  11.         if((!$operation || empty($relatedid)) && !strlen($customtitle) || empty($uids) || empty($data)) {
  12.             return;
  13.         }
  14.         $log = array(
  15.             'uid' => $uids,
  16.             'operation' => $operation,
  17.             'relatedid' => $relatedid,
  18.             'dateline' => TIMESTAMP,
  19.         );
  20.         foreach($data as $k => $v) {
  21.             $log[$k] = $v;
  22.         }
  23.         if(is_array($uids)) {
  24.             foreach($uids as $k => $uid) {
  25.                 $log['uid'] = $uid;
  26.                 $log['relatedid'] = is_array($relatedid) ? $relatedid[$k] : $relatedid;
  27.                 $insertid = C::t('common_credit_log')->insert($log, true);
  28.                 C::t('common_credit_log_field')->insert(array('logid' => $insertid, 'title' => $customtitle, 'text' => $custommemo));
  29.             }
  30.         } else {
  31.             $insertid = C::t('common_credit_log')->insert($log, true);
  32.             C::t('common_credit_log_field')->insert(array('logid' => $insertid, 'title' => $customtitle, 'text' => $custommemo));
  33.         }
  34.     }
复制代码
4、积分变更操作:引用了:source/class/class_credit.php类文件中的 与入口方法同名的updatemembercount()方法执行最后的变更操作:
  1. /*
  2.     * @$uids    用户
  3.     * @$creditarr    积分变更操作数组
  4.     * @$checkgroup    是否检查用户组升级,通常未true
  5.     * @$ruletxt    变更规则/提醒文本
  6.     * 以上传入参数基本由入口方法updatemembercount()引入,至此积分增减执行完毕
  7.     **/
  8.     function updatemembercount($creditarr, $uids = 0, $checkgroup = true, $ruletxt = '') {
  9.         global $_G;

  10.         if(!$uids) $uids = intval($_G['uid']);
  11.         $uids = is_array($uids) ? $uids : array($uids);
  12.         if($uids && ($creditarr || $this->extrasql)) {
  13.             if($this->extrasql) $creditarr = array_merge($creditarr, $this->extrasql);
  14.             $sql = array();
  15.             $allowkey = array('extcredits1', 'extcredits2', 'extcredits3', 'extcredits4', 'extcredits5', 'extcredits6', 'extcredits7', 'extcredits8', 'friends', 'posts', 'threads', 'oltime', 'digestposts', 'doings', 'blogs', 'albums', 'sharings', 'attachsize', 'views', 'todayattachs', 'todayattachsize');
  16.             $creditnotice = $_G['setting']['creditnotice'] && $_G['uid'] && $uids == array($_G['uid']);
  17.             if($creditnotice) {
  18.                 if(!isset($_G['cookiecredits'])) {
  19.                     $_G['cookiecredits'] = !empty($_COOKIE['creditnotice']) ? explode('D', $_COOKIE['creditnotice']) : array_fill(0, 9, 0);
  20.                     for($i = 1; $i <= 8; $i++) {
  21.                         $_G['cookiecreditsbase'][$i] = getuserprofile('extcredits'.$i);
  22.                     }
  23.                 }
  24.                 if($ruletxt) {
  25.                     $_G['cookiecreditsrule'][$ruletxt] = $ruletxt;
  26.                 }
  27.             }
  28.             foreach($creditarr as $key => $value) {
  29.                 if(!empty($key) && $value && in_array($key, $allowkey)) {
  30.                     $sql[$key] = $value;
  31.                     if($creditnotice && substr($key, 0, 10) == 'extcredits') {
  32.                         $i = substr($key, 10);
  33.                         $_G['cookiecredits'][$i] += $value;
  34.                     }
  35.                 }
  36.             }
  37.             if($creditnotice) {
  38.                 dsetcookie('creditnotice', implode('D', $_G['cookiecredits']).'D'.$_G['uid']);
  39.                 dsetcookie('creditbase', '0D'.implode('D', $_G['cookiecreditsbase']));
  40.                 if(!empty($_G['cookiecreditsrule'])) {
  41.                     dsetcookie('creditrule', strip_TAGs(implode("\t", $_G['cookiecreditsrule'])));
  42.                 }
  43.             }
  44.             if($sql) {
  45.                 C::t('common_member_count')->increase($uids, $sql);
  46.             }
  47.             if($checkgroup && count($uids) == 1) $this->checkusergroup($uids[0]);
  48.             $this->extrasql = array();
  49.         }
  50.     }
复制代码

全部评论 0

您需要登录后才可以回帖 立即登录
登录
0
0
0
返回顶部