<?php

namespace app\common\model;

use think\Model;

class Recruit extends Model
{
    public $page_info;

    /**
     * 获取单个招聘岗位
     */
    public function getOneRecruit($condition, $field = '*')
    {
        return db('recruit')->field($field)->where($condition)->find();
    }



    /**
     * 招聘岗位列表
     */
    public function getRecruit($condition, $field = '*', $page = 0, $order = 'sort', $limit = '')
    {
        if ($limit) {
            return db('recruit')->where($condition)->field($field)->order($order,'desc')->page($page)->limit($limit)->select();
        } else {
            $res = db('recruit')->where($condition)->field($field)->order($order,'desc')->paginate($page);
            $this->page_info = $res;
            return $res->items();
        }
    }
    /**
     * 新增招聘岗位
     */
    public function addRecruit($param)
    {
        return db('recruit')->insertGetId($param);
    }

    /**
     * 修改招聘岗位
     */
    public function edit($condition, $update)
    {
        return db('recruit')->where($condition)->update($update);
    }

    /**
     * 删除招聘岗位
     * @param unknown $condition
     * @return boolean
     */
    public function deleteRecruit($condition)
    {
        $recruit_array = $this->getRecruit($condition, 'id');
        $id_array = array();
        foreach ($recruit_array as $value) {
            $id_array[] = $value['id'];
            // @unlink(BASE_UPLOAD_PATH . DS . ATTACH_PRODUCT . DS . $value['product_img']);
        }
        return db('recruit')->where(array('id' => array('in', $id_array)))->delete();
    }



}

?>
