<?php

namespace app\api\controller\ContactUs;

use app\BaseController;
use app\common\model\ContactUs\Signup as ModelSignup;
use app\common\model\Dictionary\Dictionary as ModelDictionary;
use app\common\model\Enrol\Classes as ModelClasses;
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;
use think\captcha\facade\Captcha;
use think\helper\Arr;

class Signup extends BaseController
{
    /**
     * 获取在线报名验证码接口
     *
     * @return \think\response\Html
     * @date 2023-04-25
     * @author xjh
     * @since 1.0.0
     */
    public function getCaptcha(): \think\response\Html
    {
        return Captcha::create('verify');
    }

    /**
     * 新增在线报名接口
     *
     * @param Request request
     * @return array
     * @date 2023-04-25
     * @author xjh
     * @since 1.0.0
     */
    public function addSignup(Request $request): array
    {
        $params = $request->param();
        $this->validate($params, [
            'signup_user_name|报名用户名称' => 'require',
            'captcha|验证码' => 'require|captcha',
            'signup_user_phone|报名用户电话' => 'require',
            'signup_user_parents_phone|报名用户家长电话' => 'require',
            'signup_user_home_address|报名用户家庭地址' => 'require',
            'signup_user_original_school|报名用户原就读学校' => 'require',
            'signup_user_arrival_time|报名用户预计到校时间' => 'require',
            'classes_guid|报名用户选择班型' => 'require',
            'signup_user_grad_type|报名用户毕业类型' => 'require',
        ]);

        ModelSignup::create($params, [
            'signup_guid',
            'signup_status',
            'signup_create_user_guid',
            'signup_update_user_guid',
            'signup_user_name',
            'signup_user_phone',
            'signup_user_parents_phone',
            'signup_user_home_address',
            'signup_user_original_school',
            'signup_user_arrival_time',
            'classes_guid',
            'signup_user_grad_type',
        ]);

        return msg('提交成功!');
    }

    /**
     * 获取毕业类型接口
     *
     * @return array
     * @date 2023-04-25
     * @author xjh
     * @since 1.0.0
     */
    public function getGradType(): array
    {
        $data = ModelDictionary::getDictionaryData(
            'graduation_type',
            [
                'dictionary_name ' => 'graduation_type_name',
                'dictionary_value ' => ' graduation_type_value'
            ]
        );
        return msg('获取毕业类型成功!', $data);
    }


    /**
     * 获取班级类型接口
     *
     * @return array
     * @date 2023-04-25
     * @author xjh
     * @since 1.0.0
     */
    public function getClasses(): array
    {
        $data = ModelClasses::field([
            'classes_guid',
            'classes_name',
        ])
        ->select();

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