UCHOME2.0积分机制分析
A:管理员在后台修改积分规则
B:数据被写入数据表creditrule 中,其中rewardtype=1表示奖励措施rewardtype=0表示处罚措施并将数据写入缓存文件data/data_creditrule.php 中
C:用户发表文章或者进行其他操作的时候,通过getreward函数来获取奖罚积分
D:然后通过SQL语句将数据写入用户数据库表space中,从而增加或减少用户积分
E:getreward函数部分通过包含data/data_creditrule.php 缓存文件来调用积分规则
UCHOME积分变动提示是通过footer.htm监控的,代码如下:
<script type="text/javascript">
showreward();
</script>
showreward();
</script>
查下source/script_common.js中showreward函数,找到AJAX处理页面为source/do_ajax.php中的getreward部分,代码如下
代码
} elseif($op == 'getreward') {
$reward = '';
if($_SCOOKIE['reward_log']) {
$log = explode(',', $_SCOOKIE['reward_log']);
if(count($log) == 2 && $log[1]) {
@include_once(S_ROOT.'./data/data_creditrule.php');
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('creditlog')." WHERE clid='$log[1]'");
$creditlog = $_SGLOBAL['db']->fetch_array($query);
$rule = $_SGLOBAL['creditrule'][$log[0]];
$rule['cyclenum'] = $rule['rewardnum']? $rule['rewardnum'] - $creditlog['cyclenum'] : 0;
}
ssetcookie('reward_log', '');
}
}
$reward = '';
if($_SCOOKIE['reward_log']) {
$log = explode(',', $_SCOOKIE['reward_log']);
if(count($log) == 2 && $log[1]) {
@include_once(S_ROOT.'./data/data_creditrule.php');
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('creditlog')." WHERE clid='$log[1]'");
$creditlog = $_SGLOBAL['db']->fetch_array($query);
$rule = $_SGLOBAL['creditrule'][$log[0]];
$rule['cyclenum'] = $rule['rewardnum']? $rule['rewardnum'] - $creditlog['cyclenum'] : 0;
}
ssetcookie('reward_log', '');
}
}
功能都在这里了,下面就开始往表creditlog里插条数据,我这里加的是天声人语的奖励规则。SQL如下:
代码
INSERT INTO `前缀_creditrule` (`rid` ,`rulename` ,`action` ,`cycletype` ,`cycletime` ,`rewardnum` ,`rewardtype` ,`norepeat` ,`credit` ,`experience`)VALUES (NULL , '天声人语', 'publishtsry', '1', '0', 1', '1', '0', '10', '1');
你也可直接用PHPMYADMIN进行添加,值的含义参照后台其他积分的规则,更新一下缓存(重要)。
然后在需要显示积分提示的地方加上:(注意红色地方是自定义的积分动作)
//积分提示
代码
$reward = getreward('publishtsry', 0);
$_SGLOBAL['db']->query('UPDATE '.tname('space')." SET credit=credit+$reward[credit], experience=experience+$reward[experience] WHERE uid='{$_SGLOBAL['supe_uid']}'");
$_SGLOBAL['db']->query('UPDATE '.tname('space')." SET credit=credit+$reward[credit], experience=experience+$reward[experience] WHERE uid='{$_SGLOBAL['supe_uid']}'");