<?php
/**
 *	任务系统
 */
defined('IN_WEB') or die('Include Error!');
class Task
{
    /**
     *	获取任务列表
     */
    public function getList($param)
    {
        $data = array('code' => 1);
        $uid = oo::functions()->uint($param['uid']);
        if( !$uid ){
            return json_encode($data);
        }
        $data = oo::commonOprModel('task')->getList($uid);
        return json_encode($data,JSON_NUMERIC_CHECK);
    }

    public function getAchieveReward($param){
        $uid = oo::functions()->uint($param['uid']);
        $aid = oo::functions()->uint($param['aid']);
        $data = array('code' => -1,'msg'=>'uid empty');
        if( !$uid ){
            return json_encode($data);
        }
        $data = oo::commonOprModel('achievement')->getAchieveReward($uid,$aid);
        return json_encode($data);
    }

    /**
     * 每日任务领奖
     */
    public function reward($param) {
        $uid = (int)$param['uid']; //用户uid
        $taskType = trim($param['taskType']);
        if (!$uid || !$taskType) {
            return json_encode(array('code' => -1, 'msg' => '参数错误','data'=>[]));
        }
        $data = oo::commonOprModel('task')->reward($uid, $taskType);
        return json_encode($data,JSON_NUMERIC_CHECK);
    }
  
  	public function progressReward($param){
        $uid = oo::functions()->uint($param['uid']);
        $progress = oo::functions()->uint($param['progress']);
        $data = oo::commonOprModel('task')->getTaskProgressReward($uid, $progress);
        if($data){
            return oo::response(1,$data);
        }else{
            return oo::response(-1,$data);
        }
    }

    /**
     * 刷新当前任务
     * @param $param
     * @return mixed
     * Created by: Owen
     * Created on: 2020/1/8 19:46
     */
    public function refreshTaskList($param){
        $uid      = oo::functions()->uint($param['uid']);
        $taskType = oo::functions()->escape($param['taskType']);
        if (empty($uid) || empty($taskType)) {
            return oo::response(-1);
        }
        $data     = oo::commonOprModel('task')->refreshTaskList($uid,$taskType);
        return oo::response(1,$data,'',true);
    }
}