<?php

namespace app\home\controller;

use app\common\model\RecruitModel;
use app\common\model\RecruitNewsModel;
use app\home\HomeBaseController;

class Recruit extends HomeBaseController
{
    protected function init()
    {
        $this->tab = 'recruit';
    }

    public function index()
    {
        $keyword = input('keyword', '');

        $limit = 10;
        $where = [
            ['status', '=', RecruitModel::STATUS_YES],
            ['name', 'like', "%$keyword%"],
        ];
        $total = RecruitModel::where($where)
            ->count();
        return view('', [
            'keyword' => $keyword,
            'total'   => $total,
            'limit'   => $limit,
        ]);
    }

    public function list()
    {
        $page    = input('page', 1);
        $limit   = input('limit', 10);
        $keyword = input('keyword', '');

        $where = [
            ['status', '=', RecruitModel::STATUS_YES],
        ];
        if (!empty($keyword)) {
            $where[] = ['name', 'like', "%$keyword%"];
        }
        $list  = RecruitModel::where($where)
            ->page($page, $limit)
            ->order(['priority' => 'desc', 'update_time' => 'desc'])
            ->append(['current_text','apply_time'])
            ->select();

        ajax_success($list);
    }

    public function detail()
    {
        $id = input('id', 0);
        if (empty($id)) {
            jump('该招聘不存在或已经删除');
        }

        $info = RecruitModel::where('status', RecruitModel::STATUS_YES)
            ->find($id);
        if (empty($info)) {
            jump('该招聘不存在或已经删除');
        }

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