<?php

namespace app\admin\controller;

use app\admin\AdminBaseController;
use app\common\model\jucai\RecruitAppointInfoModel;
use app\common\model\jucai\RecruitModel;
use app\common\model\SettingModel;

class Recruit extends AdminBaseController
{

    /**
     * 列表
     */
    public function index()
    {
        return view();
    }

    public function listRecruit()
    {
        $map = $this->dealLikeInput(['name']);

        $list  = RecruitModel::where($map)
            ->order(['id' => 'desc'])
            ->limit(input('limit'))
            ->page(input('page'))
            ->select();
        $count = RecruitModel::where($map)->count();

        foreach ($list as $v) {
            $v['apply_count'] = RecruitAppointInfoModel::where('recruit_id',$v['id'])->count();
        }

        if ($count == 0) {
            ajax_return(1, '未查询到数据');
        }
        list_return($list, $count);
    }

    /**
     * 列表
     */
    public function setting()
    {
        $system = SettingModel::getConfigValue(SettingModel::ODD_JOB);
        return view('', [
            'system' => $system,
        ]);
    }

    public function editSetting()
    {
        $data = $this->_post(SettingModel::ODD_JOB);
        SettingModel::setConfigValue($data);
        ajax_return();
    }

    /**
     * 获取数据
     * @param array $param 要获取的数据
     * @return array
     */
    public function _post(array $param)
    {
        $res = [];
        foreach ($param as $v) {
            if (input($v) === '0' || !empty(input($v))) {
                $res[$v] = input($v);
            }
        }

        return $res;
    }
}