<?php

namespace app\mobile\controller;

use app\common\model\Broker as BrokerModel;
use app\common\model\OutResume as OutResumeModel;
use app\mobile\MobileBaseController;
use app\mobile\validate\CandidateValidate;
use think\exception\ValidateException;

class Candidate extends MobileBaseController
{
    public function info()
    {
        $broker_id = input('get.broker_id');
        empty($broker_id) && jump('无法获取经纪人信息');

        $broker = BrokerModel::where('id', $broker_id)->find();
        empty($broker) && jump('无法获取经纪人信息');
        $broker['type'] != 3 && jump('无法获取经纪人信息');

        return view('candidate/info', ['broker' => $broker]);
    }

    public function infoPost()
    {
        $data = input('post.');
        try {
            validate(CandidateValidate::class)->check($data);
        } catch (ValidateException $e) {
            ajax_return(1, $e->getError());
        }

        $mobile_check = OutResumeModel::where('mobile', $data['mobile'])->find();
        $mobile_check && ajax_return(1, '该手机号已被登记！');

        $data['updatetime'] = $data['createtime'] = time();
        OutResumeModel::create($data);

        ajax_return();
    }
}
