野生大熊猫

discuz 任务相关文件和函数
首先dz的任务是source/class/task/task_xxx.php文件中,用户可以自己添加相关文件来新建...
扫描右侧二维码阅读全文
01
2019/11

discuz 任务相关文件和函数

首先dz的任务是source/class/task/task_xxx.php文件中,用户可以自己添加相关文件来新建站点任务。
比如推广任务

class task_promotion {

    var $version = '1.0';//版本号
    var $name = 'promotion_name';//任务名称,这里用了语言包,下面同理
    var $description = 'promotion_desc';//任务描述
    var $copyright = '<a href="http://www.comsenz.com" target="_blank">Comsenz Inc.</a>';//版权
    var $icon = '';//图标
    var $period = '';
    var $periodtype = 0;
    var $conditions = array(
        'num' => array(
            'title' => 'promotion_complete_var_iplimit',
            'type' => 'text',
            'value' => '',
            'default' => 100,
            'sort' => 'complete',
        ),
    );//默认配置
    //任务进度
    function preprocess($task) {
        global $_G;

        $promotions = C::t('forum_promotion')->count_by_uid($_G['uid']);
        C::t('forum_spacecache')->insert(array(
            'uid' => $_G['uid'],
            'variable' => 'promotion'.$task['taskid'],
            'value' => $promotions,
            'expiration' => $_G['timestamp'],
        ), false, true);
    }
    //任务是否完成
    function csc($task = array()) {
        global $_G;

        $promotion = C::t('forum_spacecache')->fetch($_G['uid'], 'promotion'.$task['taskid']);
        $promotion = $promotion['value'];
        $num = C::t('forum_promotion')->count_by_uid($_G['uid']) - $promotion;
        $numlimit = C::t('common_taskvar')->get_value_by_taskid($task['taskid'], 'num');
        if($num && $num >= $numlimit) {
            DB::insert('task', array("uid"=>$_G['uid'],"username"=>$_G['username'],"datetime"=>time(),"value"=>0), 1);
            return TRUE;
        } else {
            return array('csc' => $num > 0 && $numlimit ? sprintf("%01.2f", $num / $numlimit * 100) : 0, 'remaintime' => 0);
        }
    }

    function sufprocess($task) {
        global $_G;

        C::t('forum_spacecache')->delete($_G['uid'], 'promotion'.$task['taskid']);
    }

}

并且当用户完成任务以后,会触发source/class/class_task.php文件中的draw函数,该函数在开启积分奖励的时候会增加积分
通过这个class,我们可以写一个相关的扩展,比如任务完成列表之类的。

Last modification:November 1st, 2019 at 02:59 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment