查看: 5070|回复: 0
打印 上一主题 下一主题

DISCUZ架构:积分系统代码分析二

[复制链接]
跳转到指定楼层
1#
发表于 2008-10-30 14:34:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
第二部分:include/newthread.inc.php

以下为引用的内容:
这个文件处理发新帖的特定请求。
if(isset($poll)) {
        $special = 1;
} elseif(isset($trade)) {
        $special = 2;
} elseif(isset($reward)) {
        $special = 3;
} elseif(isset($activity)) {
        $special = 4;
} else {
        $special = 0;
}
这一部分的代码是用来判断帖子的类型的,1为投票,2为交易帖,3为悬赏,4为活动,0为普通帖。
        $price = intval($price);
        $price = $maxprice && !$special ? ($price <= $maxprice ? $price : $maxprice) : 0;
这里是帖子价格的赋值,超过了最大的价格的处理,特殊帖子的价格处理。
} elseif($special == 3 && $allowpostreward) {
                $rewardprice = intval($rewardprice);
                if(!$rewardprice) {
                        showmessage('reward_credits_please');
                } elseif($rewardprice > 32767) {
                        showmessage('reward_credits_overflow');
                } elseif($rewardprice < $minrewardprice || ($maxrewardprice > 0 && $rewardprice > $maxrewardprice)) {
                        showmessage('reward_credits_between');
                } elseif(($realprice = $rewardprice + ceil($rewardprice * $creditstax)) > $_DSESSION["extcredits$creditstrans"]) {
                        showmessage('reward_credits_shortage');
                }


                $price = $rewardprice;

                $db->query("UPDATE {$tablepre}members SET extcredits$creditstrans=extcredits$creditstrans-$realprice WHERE uid='$discuz_uid'");
前面说过3表示悬赏帖子,那么当你发表成功了一个悬赏帖子后,就会相应在cdb_members表中减少相应的扩展积分,便是上面的代码的作用了。
elseif($special == 3 && $allowpostreward) {
                $db->query("INSERT INTO {$tablepre}rewardlog (tid, authorid, netamount, dateline) VALUES ('$tid', '$discuz_uid', $realprice, '$timestamp')");
        }
后续判断如果为悬赏帖子的话就往cdb_rewardlog(悬赏记录表)里写入一条记录。
        if($attachment) {
                $searcharray = $pregarray = $replacearray = array();
                foreach($attachments as $key => $attach) {
                        $db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, price, filename, description, filetype, filesize, attachment, downloads, isimage, uid, thumb, remote)
                                VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[price]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0', '$attach[isimage]', '$attach[uid]', '$attach[thumb]', '$attach[remote]')");
                        $searcharray[] = '[local]'.$localid[$key].'[/local]';
                        $pregarray[] = '/\[localimg=(\d{1,3}),(\d{1,3})\]'.$localid[$key].'\[\/localimg\]/is';
                        $replacearray[] = '[attach]'.$db->insert_id().'[/attach]';
                }
                $message = str_replace($searcharray, $replacearray, preg_replace($pregarray, $replacearray, $message));
                $db->query("UPDATE {$tablepre}posts SET message='$message' WHERE pid='$pid'");
                updatecredits($discuz_uid, $postattachcredits, count($attachments));
        }
如果帖子中带有附件的话,就把附件插入cdb_attachments表,然后注意到$message这一个变量在这里用到了替换,这里的作用是图文混排。接下来往cdb_posts写一条记录,再用include/global.func.php定义到一个函数updatecredits来更新积分。
给Discuz的一个小建议:可以判断是不是postattachcredits为0,为0就可以不执行updatecredits这个函数,虽然在函数定义的时候也有判断,不过在这里判断似乎更好。
if($modnewthreads) {

                $db->query("UPDATE {$tablepre}forums SET todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
                $allowuseblog && $isblog && $blog ? showmessage('post_newthread_mod_blog_succeed', "blog.php?uid=$discuz_uid") :
                        showmessage('post_newthread_mod_succeed', "forumdisplay.php?fid=$fid");

        } else {

                if($digest) {
                        foreach($digestcredits as $id => $addcredits) {
                                $postcredits[$id] = (isset($postcredits[$id]) ? $postcredits[$id] : 0) + $addcredits;
                        }
                }
                updatepostcredits('+', $discuz_uid, $postcredits);

                $lastpost = "$tid\t$subject\t$timestamp\t$author";
                $db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost', threads=threads+1, posts=posts+1, todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
                if($forum['type'] == 'sub') {
                        $db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost' WHERE fid='$forum[fup]'", 'UNBUFFERED');
                }

                if($allowuseblog && $isblog && $blog) {
                        showmessage('post_newthread_blog_succeed', "blog.php?tid=$tid");
                } else {
                        showmessage('post_newthread_succeed', "viewthread.php?tid=$tid&extra=$extra");
                }

        }
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表