<?php

namespace app\api\controller\AboutUs\TeachingEnvir;

use app\BaseController;
use app\common\model\AboutUs\TeachingEnvir\TeachingEnvir as ModelTeachingEnvir;
use app\common\model\AboutUs\TeachingEnvir\TeachingEnvirType as ModelTeachingEnvirType;
use app\Request;
use think\Validate;
use think\exception\ValidateException;
use think\facade\Filesystem;
use app\common\arw\adjfut\src\Excel;
use app\common\arw\adjfut\src\UploadFile;
use app\common\exception\Tool;
use think\facade\Db;
use think\facade\Env;


class TeachingEnvir extends BaseController
{
    /**
     * 获取教学环境列表接口
     *
     * @param Request request
     * @return array
     * @date 2023-04-22
     * @author xjh
     * @since 1.0.0
     */
    public function getTeachingEnvirList(Request $request): array
    {
        $params = $request->param();
        $this->validate($params, [
            'teaching_envir_type_id|教学环境类型id' => 'require',
        ]);

        $teaching_envir_type =  ModelTeachingEnvirType::where('teaching_envir_type_id', $params['teaching_envir_type_id'])->find();
        if (!$teaching_envir_type) throwErrorMsg('该教学环境类型不存在!');

        $con = [
            ['teaching_envir.teaching_envir_type_guid', '=', $teaching_envir_type->teaching_envir_type_guid],
            ['teaching_envir_type.teaching_envir_type_delete_time', 'NULL', null],
        ];
        $find = ModelTeachingEnvir::where($con)
            ->field([
                'teaching_envir_title',
                'teaching_envir_img',
                'teaching_envir_intro',
                'teaching_envir_details',
                'teaching_envir_type_name',
            ])
            ->leftJoin('teaching_envir_type', 'teaching_envir_type.teaching_envir_type_guid = teaching_envir.teaching_envir_type_guid')
            ->find();

        return msg(0, "获取教学环境列表成功!", ['data' => $find]);
    }
}
