<?php

namespace app\admin\controller\Enrol;

use app\BaseController;
use app\common\model\Enrol\SignUpIntro as ModelSignUpIntro;
use app\Request;
use think\Validate;
use think\exception\ValidateException;
use think\facade\Filesystem;
use app\common\exception\Tool;


class SignUpIntro extends BaseController
{
    /**
     * 获取报名简介内容
     */
    public function getSignUpIntro(Request $request): array
    {
        $params = $request->param();

        $query = ModelSignUpIntro::field([
            'sign_up_intro_id',
            'sign_up_intro_guid',
            'sign_up_intro_title',
            'sign_up_intro_subtitle',
            'sign_up_intro_desc',
            'sign_up_intro_content',
            'sign_up_intro_img'
        ])->where(1)->find();

        return [
            'code' => 0,
            'data' => $query,
            'msg' => 'ok'
        ];
    }

    /**
     * 编辑报名简介
     */
    public function editSignUpIntro(Request $request): array
    {
        $params = $request->param();
        $this->validate($params, [
            'sign_up_intro_title|标题' => 'require',
            'sign_up_intro_subtitle|副标题' => 'require',
            'sign_up_intro_desc|简介' => 'require',
            'sign_up_intro_content|内容' => 'require',
            'sign_up_intro_img|描述图片' => 'require'
        ]);
        $model = ModelSignUpIntro::where(1)->find();
        $model->allowField([
            'sign_up_intro_update_user_guid',
            'sign_up_intro_title',
            'sign_up_intro_subtitle',
            'sign_up_intro_desc',
            'sign_up_intro_content',
            'sign_up_intro_img'
        ])->save($params);
        return msg('编辑成功!');
    }
}
