<?php

namespace app\api\controller\Enrol;

use app\BaseController;
use app\common\model\Enrol\EnrolAq as ModelEnrolAq;
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 think\facade\Db;
use app\common\exception\Tool;
use think\facade\Env;


class EnrolAq extends BaseController
{
    /**
     * 获取招生问答列表
     */
    public function getEnrolAqList(Request $request): array
    {
        $params = $request->param();
        $con = [];

        $con = Tool::getOptionalQuery(['enrol_aq_question', 'LIKE']);

        $query = ModelEnrolAq::where($con)
            ->field([
                'enrol_aq_id',
                'enrol_aq_question',
                'enrol_aq_answer',
                'enrol_aq_sort',
            ])
            ->where('enrol_aq_status', 2)
            ->where('enrol_aq_answer_status', 2)
            ->order('enrol_aq_sort', 'asc')
            ->select();

        return msg(0, "获取招生问答列表成功!", [
            'data' => $query,
            'count' => count($query)
        ]);
    }


    /**
     * 添加招生问答
     */
    public function addEnrolAq(Request $request): array
    {
        $params = $request->param();
        $this->validate($params, [
            'enrol_aq_question|问题' => 'require',
        ]);

        $model = ModelEnrolAq::create($params, [
            'enrol_aq_guid',
            'enrol_aq_create_user_guid',
            'enrol_aq_update_user_guid',
            'enrol_aq_question',
            'enrol_aq_sort',
            'enrol_aq_status',
            'enrol_aq_answer_status'
        ]);
        return msg('添加成功!');
    }
}
