<?php

namespace app\workerapi\controller;

use app\adminapi\logic\goods_category\GoodsCategoryLogic;
use app\common\logic\MasterWorkerExamineLogic;
use app\common\model\dict\DictData;
use app\workerapi\lists\MasterWorkerLists;
use app\workerapi\lists\ServiceWorkLists;
use app\workerapi\lists\TeamServiceWorkLists;
use app\workerapi\lists\TrainingCourseLists;
use app\workerapi\logic\LoginLogic;
use app\workerapi\logic\MasterWorkerInfoLogic;
use app\workerapi\logic\MasterWorkerLogic;
use app\workerapi\logic\MasterWorkerTeamLogic;
use app\workerapi\logic\TenantAgreeLogic;
use app\workerapi\logic\TrainingLogic;
use app\workerapi\validate\BankAccountValidate;
use app\workerapi\validate\MasterWokerInfoValidate;
use app\workerapi\validate\MasterWokerTeamValidate;
use app\workerapi\validate\MasterWokerValidate;
use app\workerapi\validate\MasterWorkerAgreeValidate;

class TrainingController extends BaseApiController
{
    /**
     * 获取培训信息
     * @return \think\response\Json
     */
    public function getTrainingInfo()
    {
        $result = TrainingLogic::getDetail($this->userId);
        return $this->data($result);
    }

    /**
     * 获取免费的课程列表
     * @return \think\response\Json
     */
    public function getFreeCourseList()
    {
        return $this->dataLists(new TrainingCourseLists());
    }

    /**
     * 获取工程师的课程列表
     * @return \think\response\Json
     */
    public function getCourseList()
    {
        $params  = request()->get();
        return $this->data(TrainingLogic::getCourseList($this->userId,$params));
    }

    /**
     * 获取工程师的课程详情
     * @return \think\response\Json
     */
    public function getCourseDetail()
    {
        $params  = request()->get();
        return $this->data(TrainingLogic::getCourseDetail($this->userId,$params));
    }


    /**
     * 修改学习视频记录状态
     * @return \think\response\Json
     */
    public function upWorkerVideoCourse()
    {
        $params  = request()->post();
        $result = TrainingLogic::upWorkerCourse($params);
        if($result === false){
            return $this->fail(TrainingLogic::getError());
        }
        return $this->success('', [], 1, 1);
    }


    /**
     * 获取考试列表（即开始考试）
     * @return \think\response\Json
     */
    public function getQuestionList()
    {
        try {
            $params  = request()->get();
            $params['user_id']  = $this->userId;
            $params['user_info']  = $this->userInfo;
            $result = TrainingLogic::getQuestionList($params);
            return $this->data($result);
        } catch (\Exception $e) {
            return $this->fail($e->getMessage());
        }
    }


    /**
     * 提交考试（即结束考试）
     * @return \think\response\Json
     */
    public function submitExam()
    {
        $params  = request()->post();
        $result = TrainingLogic::submitExam($params);
        if($result === false){
            return $this->fail(TrainingLogic::getError());
        }
        return $this->success('', [], 1, 1);
    }

    /**
     * 考试结果统计
     * @return \think\response\Json
     */
    public function examStatistics()
    {
        $params  = request()->get();
        $result = TrainingLogic::examStatistics($params);
        return $this->data($result);
    }

    /**
     * 获取团队协议详情
     * @return \think\response\Json
     */
    public function agreement_detail()
    {
        $result = TenantAgreeLogic::getAgreeByType('tenant_cooperate',$this->userId);
        return $this->data($result);
    }

    /**
     * 签署团队协议
     * @return \think\response\Json
     */
    public function agreeSign()
    {
        $params = (new MasterWorkerAgreeValidate())->post()->goCheck('sign', [
            'user_id' => $this->userId,
            'user_info' => $this->userInfo
        ]);
        $result = TenantAgreeLogic::sign($params);
        if (false === $result) {
            return $this->fail(TenantAgreeLogic::getError());
        }
        return $this->success('签名成功', [], 1, 1);
    }

    /**
     * 获取所有分类
     * @return \think\response\Json
     */
    public function getCategory()
    {
        $result = GoodsCategoryLogic::getTreeData();
        return $this->data($result);
    }

    /**
     * 提交三级ID分类
     * @return \think\response\Json
     */
    public function submitCategory()
    {
        $params  = request()->post();
        $params['user_id']  = $this->userId;
        $params['user_info']  = $this->userInfo;
        $result = TrainingLogic::submitCategory($params);
        if($result === false){
            return $this->fail(TrainingLogic::getError());
        }
        return $this->success('', [], 1, 1);
    }

    /**
     * 获取类目分类
     * @return \think\response\Json
     */
    public function getTrainingCategory()
    {
        $params  = request()->get();
        $params['user_id']  = $this->userId;
        $params['user_info']  = $this->userInfo;
        $result = TrainingLogic::getTrainingCategory($params);
        return $this->data($result);
    }

    /**
     * 获取某类目课程列表任务ID
     * @return \think\response\Json
     */
    public function getCategoryTaskId()
    {
        $params  = request()->get();
        $params['user_id']  = $this->userId;
        $params['user_info']  = $this->userInfo;
        $result = TrainingLogic::getCategoryCourse($params);
        if($result === false){
            return $this->fail(TrainingLogic::getError());
        }
        return $this->success('', ['training_task_id'=>$result], 1, 1);
    }


}