审查视图

application/mobile/controller/CompanyJob.php 8.1 KB
何书鹏 authored
1 2 3 4 5 6 7
<?php
namespace app\mobile\controller;

use think\Db;
use app\common\controller\Api;
use app\mobile\model\UserJob;
use app\mobile\model\UserResume;
何书鹏 authored
8
use app\mobile\model\Company;
何书鹏 authored
9
use app\mobile\model\UserJobDownload;
何书鹏 authored
10 11 12 13 14 15 16 17 18 19

/**
 * 招聘接口
 * @ApiWeigh (90)
 */
class CompanyJob extends Api
{
	protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $model = null;
何书鹏 authored
20
    protected $company_id = 0;
何书鹏 authored
21 22 23 24 25

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('app\mobile\model\CompanyJob');
何书鹏 authored
26 27 28 29 30 31 32
        if(!$this->company_id){
            $user = $this->auth->getUser();
            if($user['group_id'] == 0){
                $this->error('您还不是企业管理员');
            }
            $this->company_id = Company::where('user_id',$user['id'])->value('id');
        }
何书鹏 authored
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    }

    /**
     * @ApiWeigh (99)
     * @ApiTitle    (招聘-首页)
     * @ApiSummary  (招聘-首页)
     * @ApiMethod   (POST)
     *
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
     * @ApiParams   (name="keyword", type="string", required=false, description="输入岗位名称")
     * @ApiParams   (name="type", type="inter", required=false, description="岗位类型:1=全职,2=兼职,3=其他")
     * @ApiParams   (name="user_job_ability_id", type="inter", required=false, description="能力ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
何书鹏 authored
50
        "time": "1602411802",
何书鹏 authored
51
        "data": {
何书鹏 authored
52 53 54 55
            "total": 1, //数据总条数
            "per_page": 15,
            "current_page": 1,
            "last_page": 1,
何书鹏 authored
56
            "data": [{
何书鹏 authored
57 58 59 60 61 62 63 64 65 66 67
                "id": 2, //职位ID
                "name": "怎么说", //职位名称
                "type": "1", //职位类型
                "salary": "9753.20", //工资
                "start_time": "2020.10.11", //开始工作日期
                "end_time": "2020.10.11", //结束工作日期
                "mobile": "15133120361", //电话
                "address": "测试地址", //地址
                "resume_name": "",
                "type_text": "全职",
                "qualification_arr": []
何书鹏 authored
68 69
            }]
        }
何书鹏 authored
70 71 72 73 74 75 76 77 78
    })
     */
    public function index()
    {
        $page = $this->request->param('page', 1, 'intval');
        $page_num = $this->request->param('page_num', 10, 'intval');
        $keyword = $this->request->param('keyword');
        $type = $this->request->param('type');
        $user_job_ability_id = $this->request->param('user_job_ability_id');
何书鹏 authored
79
        $where[] = ['status' , '1'];
何书鹏 authored
80 81 82 83 84 85 86 87
        // 搜索关键词
        if(!empty($keyword)){
            $where[] = ['name', 'like', "%{$keyword}%"];
        }
        // 求职类型
        if(!empty($type)){
            $where[] = ['type', $type];
        }
何书鹏 authored
88
        // 资质能力
何书鹏 authored
89 90 91 92 93 94 95 96 97 98 99 100 101
        if(!empty($user_job_ability_id)){
            $where[] = "FIND_IN_SET('{$user_job_ability_id}',user_job_ability_ids)";
        }
        // 整合where
        $where = function ($query) use ($where) {
            foreach ($where as $k => $v) {
                if (is_array($v)) {
                    call_user_func_array([$query, 'where'], $v);
                } else {
                    $query->where($v);
                }
            }
        };
何书鹏 authored
102
        $data = UserJob::where($where)
何书鹏 authored
103
            ->field('id,name,type,salary,start_time,end_time,mobile,address,resume_name,qualification')
何书鹏 authored
104 105
            ->order('createtime desc')
            ->paginate($page_num,false,['page'=>$page])
何书鹏 authored
106
            ->each(function($v){
何书鹏 authored
107
                $has = UserJobDownload::where('company_id',$this->company_id)->where('user_job_id',$v['id'])->field('id')->find();
何书鹏 authored
108 109
                $v->is_download = !empty($has) ? 1 : 0;
            })->toArray();
何书鹏 authored
110
        $this->success('成功', $data);
何书鹏 authored
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    }

    /**
     * @ApiWeigh (99)
     * @ApiTitle    (求职-详情)
     * @ApiSummary  (求职-详情)
     * @ApiMethod   (POST)
     *
     * @ApiParams   (name="user_job_id", type="inter", required=false, description="求职ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1599017563",
        "data": "用户协议内容" //协议内容
    })
     */
    public function info()
    {
        $user_job_id = $this->request->param('user_job_id');
        empty($user_job_id) && $this->error('缺少必需参数');
        $info = UserJob::get($user_job_id);
        empty($info) && $this->error('求职信息不存在');
        $this->success('成功', $info);
    }

    /**
     * @ApiWeigh (93)
何书鹏 authored
139
     * @ApiTitle    (下载简历)
何书鹏 authored
140 141 142
     * @ApiSummary  (投递简历)
     * @ApiMethod   (POST)
     *
何书鹏 authored
143
     * @ApiParams   (name="user_job_id", type="inter", required=true, description="求职ID")
何书鹏 authored
144 145 146 147 148 149 150 151 152 153
     *
     * @ApiReturn({
		"code": 1,
		"msg": "成功",
		"time": "1599017563",
		"data": 简历链接
	})
     */
    public function downloadResume()
    {
何书鹏 authored
154 155 156 157 158 159 160 161 162 163 164 165 166
        $user_job_id = $this->request->param('user_job_id');
        empty($user_job_id) && $this->error('缺少必需参数');
        $info = UserJob::get($user_job_id);
        empty($info) && $this->error('求职信息不存在');
        $where = [
            'company_id' => $this->company_id,
            'user_job_id' => $user_job_id
        ];
        $has = UserJobDownload::get($where);
        if(!$has){
            UserJobDownload::create($where);
        }
        $this->success('成功',$info['resume']);
何书鹏 authored
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    }

    /**
     * @ApiWeigh (91)
     * @ApiTitle    (发布招聘)
     * @ApiSummary  (发布招聘)
     * @ApiMethod   (POST)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams (name="name", type="string", required=true, description="岗位名称")
     * @ApiParams (name="type", type="string", required=true, description="岗位类型:1=全职,2=兼职,3=其他")
     * @ApiParams (name="start_time", type="string", required=true, description="开始工作日期")
     * @ApiParams (name="end_time", type="string", required=true, description="结束工作日期")
     * @ApiParams (name="salary", type="string", required=true, description="薪资待遇")
     * @ApiParams (name="address", type="string", required=true, description="工作地点")
     * @ApiParams (name="lng", type="string", required=true, description="工作地点经度")
     * @ApiParams (name="lat", type="string", required=true, description="工作地点纬度")
     * @ApiParams (name="house_number", type="string", required=true, description="详细地址")
     * @ApiParams (name="mobile", type="string", required=true, description="手机号")
     * @ApiParams (name="description", type="string", required=true, description="岗位职责及要求")
     * @ApiParams (name="other_desc", type="string", required=true, description="其他说明")
     *
     * @ApiReturn({
        "code": 1, 
        "msg": "登录成功", 
        "time": "1600498819", 
        "data": null
    })
     */
    public function addJob()
    {
        $post = $this->request->param();
        empty($post['name']) && $this->error('请输入岗位名称');
        empty($post['type']) && $this->error('请选择岗位类型');
        empty($post['start_time']) && $this->error('请选择开始工作日期');
        empty($post['end_time']) && $this->error('请选择结束工作日期');
        empty($post['salary']) && $this->error('请输入薪资待遇');
        empty($post['address']) && $this->error('请输入工作地点');
        empty($post['lng']) && $this->error('请输入工作地点经度');
        empty($post['lat']) && $this->error('请输入工作地点纬度');
        empty($post['house_number']) && $this->error('请输入详细地址');
        empty($post['mobile']) && $this->error('请输入手机号');
        empty($post['description']) && $this->error('请填写岗位职责及要求');
        $this->model->allowField(true)->save(array_merge([
            'user_id' => $this->auth->id,
何书鹏 authored
212
            'company_id' => $this->company_id
何书鹏 authored
213 214 215 216
        ],$post));
        $this->success('发布招聘成功');
    }
}