<?php
/**
 *	任务系统
 */
defined('IN_WEB') or die('Include Error!');
class Task
{
    /**
     * 任务列表
     * @param $param
     * @return false|string
     * Created by: Owen
     * Created on: 2020/3/27 20:04
     */
    public function listFunction($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        $data = oo::commonOprModel('task')->getList($uid);
        return json_encode($data,JSON_NUMERIC_CHECK);
    }

    /**
     * 任務中心
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/5/9 15:31
     */
    public function center($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        return oo::commonOprModel('task')->getList2($uid,true);
    }

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

    /**
     * 邀請任务列表
     * @param $param
     * @return string
     * Created by: Owen
     * Created on: 2020/4/9 10:11
     */
    public function invite($param){
        $uid = oo::functions()->uint($param['uid']);
        if(empty($uid)){
            return oo::response(-1);
        }
        $data = [
            'invite' =>[
                'reward'      => ['type'=>2, 'num' =>oo::commonOprModel('invite')->inviteConfig($uid)['base']],
                'friendsList' => oo::commonOprModel('invite')->getInviteRewardList($uid)
            ]
        ];
        return oo::response(1,$data,'',true);
    }

    /**
     * Notes:通用任务
     * User: wsc
     * Time: 2021/3/23 12:27
     * @param $param [5=>"分享",6=>"fb邀请"]
     * @return string
     */
    public function doCommonTask($param){
        $uid = oo::functions()->uint($param['uid']);
        $tid = oo::functions()->uint($param['taskType']);
        if(empty($uid)||empty($tid)){
            return oo::response(errorCode::REQUEST_PARAM_ERROR);
        }
        if(!funs::concurrentLock($uid,'doCommonTask',1)){
            return oo::response(errorCode::API_FREQUENT_REQUESTS,[],'频繁操作');
        }
        if(in_array($tid,[5,6])){//召回任务
            oo::commonOprModel('callback')->doTask($uid, $tid, 1);
        }

        $tid == 5 && oo::commonOprModel('activitynew')->addTrafficPermitNum($uid,10);//通行证任务10 分享游戏

        return oo::response(1);
    }
}