本帖最后由 evenzhou 于 2011-7-31 20:53 编辑
下面以推广任务为例进行分析
首先,在后台安装任务,如果出现安装失败(提示“指定的任务脚本已安装”)。进入数据库找到表pre_common_task,将该任务对应的记录删除
打开home_task.php,
- if(empty($do)) {
- $_G['gp_item'] = empty($_G['gp_item']) ? 'new' : $_G['gp_item'];
- $actives = array($_G['gp_item'] => ' class="a"');
- $tasklist = $tasklib->tasklist($_G['gp_item']);
- $listdata = $tasklib->listdata;
- if($_G['gp_item'] == 'doing' && empty($tasklist)) {
- dsetcookie('taskdoing_'.$_G['uid']);
- }
- }
复制代码 当传入的do值为空时,程序将根据item动作调取数据,item可以分别:new、doing、done、failed、canapply 首先进行任务申请,申请任务有5种状态:需要执行相关任务、用户组受限制、重复申请、任务过期、申请成功。如果任务申请成功,处理方式:打开class_task.php
- } elseif($this->task['period']) {
- $mytask = DB::fetch_first("SELECT mt.*, t.period, t.periodtype FROM ".DB::table('common_mytask')." mt
- INNER JOIN ".DB::table('common_task')." t USING(taskid)
- WHERE mt.uid='$_G[uid]' AND mt.taskid='$id' ORDER BY mt.dateline DESC");
- list($allowapply) = $this->checknextperiod($mytask);
- if($allowapply < 0) {
- return -4;
- }
- }
- require_once libfile('task/'.$this->task['scriptname'], 'class');
- $taskclassname = 'task_'.$this->task['scriptname'];
- $taskclass = new $taskclassname;
- if(method_exists($taskclass, 'condition')) {
- $taskclass->condition();
- }
- DB::query("REPLACE INTO ".DB::table('common_mytask')." (uid, username, taskid, csc, dateline)
- VALUES ('$_G[uid]', '$_G[username]', '".$this->task['taskid']."', '0\t$_G[timestamp]', '$_G[timestamp]')");
- DB::query("UPDATE ".DB::table('common_task')." SET applicants=applicants+1 WHERE taskid='".$this->task['taskid']."'", 'UNBUFFERED');
- if(method_exists($taskclass, 'preprocess')) {
- $taskclass->preprocess($this->task);
- }
- return true;
- }
复制代码 其中$taskclass->preprocess($this->task)这行代码是初始化任务推广数。 推广任务的处理代码如下:
- function preprocess($task) {
- global $_G;
- $promotions = DB::result_first("SELECT COUNT(*) FROM ".DB::table('forum_promotion')." WHERE uid='$_G[uid]'");
- DB::query("REPLACE INTO ".DB::table('forum_spacecache')." (uid, variable, value, expiration) VALUES ('$_G[uid]', 'promotion$task[taskid]', '$promotions', '$_G[timestamp]')");
- }
复制代码 推广数有计划务,会每日定期清理掉。如果用户在一天之内没有完成推广任务,那么上次的推广数是会被清理掉,重新计数
下面介绍推广的处理方法:当用户访问网站的时候会首先调用class_core.php文件,我们来看看推广处理代码:
- if((!empty($this->var['gp_fromuid']) || !empty($this->var['gp_fromuser'])) && ($this->var['setting']['creditspolicy']['promotion_visit'] || $this->var['setting']['creditspolicy']['promotion_register'])) {
- require_once libfile('misc/promotion', 'include');
- }
复制代码 推广分为:推广访问和注册推广,管理员需要设置推广访问和注册推广奖励才会给予推广计数。这也是为什么很多站长说推广任务为什么完成不了的原因
|