审查视图

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

use think\Db;
use app\common\controller\Api;
use app\mobile\model\UserJobBanner;
use app\mobile\model\CompanyJob;
use app\mobile\model\CompanyJobResume;
何书鹏 authored
9
use app\mobile\model\UserJobAbility;
何书鹏 authored
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

/**
 * 求职接口
 * @ApiWeigh (91)
 */
class UserJob extends Api
{
	protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('app\mobile\model\UserJob');
    }

    /**
何书鹏 authored
28
     * @ApiWeigh (99)
何书鹏 authored
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
     * @ApiTitle    (求职-轮播图)
     * @ApiSummary  (求职-轮播图)
     * @ApiMethod   (POST)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1599907184",
        "data": [{
            "id": 1, // 轮播图ID
            "image": "https://img02.mockplus.cn/idoc/sketch/2020-08-06/006324c3-e5d3-4206-be48-52a7c7468e74.7C1FC40C-CED5-4B08-9506-3E48A2732B2C.png", // 图片地址
            "user_job_id": 1, // 求职ID
        }]
    })
     */
    public function banner()
    {
        $list = UserJobBanner::order('createtime desc')
            ->field('id,image,user_job_id')
            ->select();
        $this->success('成功',$list);
    }

    /**
何书鹏 authored
53
     * @ApiWeigh (97)
何书鹏 authored
54 55 56 57 58 59 60 61 62 63 64 65
     * @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=其他")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
何书鹏 authored
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
        "time": "1602411573",
        "data": {
            "total": 1, //数据总数
            "per_page": 15,
            "current_page": 1,
            "last_page": 1,
            "data": [{
                "id": 1, //招聘ID
                "name": "123", //职位名称
                "type": "1", //职位类型
                "salary": "9753.20", //工资
                "start_time": "1970.01.01", //开始工作日期
                "end_time": "1970.01.01", //结束工作日期
                "address": "测试地址", //职位地址
                "type_text": "全职" //职位类型说明
            }]
        }
何书鹏 authored
83 84 85 86 87 88 89 90
    })
     */
    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');
何书鹏 authored
91
        $where['status'] = '1';
何书鹏 authored
92 93 94 95 96 97 98 99 100
        // 搜索关键词
        if(!empty($keyword)){
            $where['name'] = ['like','%'.$keyword.'%'];
        }
        // 求职类型
        if(!empty($type)){
            $where['type'] = $type;
        }
        $data = CompanyJob::where($where)
何书鹏 authored
101
            ->field('id,name,type,salary,start_time,end_time,address')
何书鹏 authored
102 103 104
            ->order('createtime desc')
            ->paginate($page_num,false,['page'=>$page])
            ->toArray();
何书鹏 authored
105
        $this->success('成功', $data);
何书鹏 authored
106 107 108
    }

    /**
何书鹏 authored
109
     * @ApiWeigh (95)
何书鹏 authored
110 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
     * @ApiTitle    (求职-详情)
     * @ApiSummary  (求职-详情)
     * @ApiMethod   (POST)
     *
     * @ApiParams   (name="company_job_id", type="inter", required=false, description="招聘职位ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1599017563",
        "data": "用户协议内容" //协议内容
    })
     */
    public function info()
    {
        $company_job_id = $this->request->param('company_job_id');
        empty($company_job_id) && $this->error('缺少必需参数');
        $info = CompanyJob::get($company_job_id);
        empty($info) && $this->error('招聘信息不存在');
        $this->success('成功', $info);
    }

    /**
     * @ApiWeigh (93)
     * @ApiTitle    (投递简历)
     * @ApiSummary  (投递简历)
     * @ApiMethod   (POST)
     *
何书鹏 authored
138 139
     * @ApiParams   (name="company_job_id", type="inter", required=true, description="招聘职位ID")
     * @ApiParams   (name="resume", type="inter", required=true, description="简历文件地址")
何书鹏 authored
140 141 142 143 144 145 146 147 148 149 150
     *
     * @ApiReturn({
		"code": 1,
		"msg": "成功",
		"time": "1599017563",
		"data": null
	})
     */
    public function sendResume()
    {
        $company_job_id = $this->request->param('company_job_id');
何书鹏 authored
151
        $resume = $this->request->param('resume');
何书鹏 authored
152
        if(!$company_job_id || !$resume){
何书鹏 authored
153 154
            $this->error('缺少必需参数');
        }
何书鹏 authored
155 156 157 158
        $info = CompanyJob::get($company_job_id);
        empty($info) && $this->error('职位信息不存在');
        $has = CompanyJobResume::get(['user_id'=>$this->auth->id,'company_job_id'=>$company_job_id]);
        !empty($has) && $this->error('已投递,请勿重复操作');
何书鹏 authored
159
        CompanyJobResume::create([
何书鹏 authored
160 161
            'user_id' => $this->auth->id,
            'company_id' => $info['company_id'],
何书鹏 authored
162
            'company_job_id' => $company_job_id,
何书鹏 authored
163
            'resume' => $resume
何书鹏 authored
164 165 166 167 168 169
        ]);
        $this->success('投递成功');
    }

    /**
     * @ApiWeigh (91)
何书鹏 authored
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
     * @ApiTitle    (资质能力)
     * @ApiSummary  (资质能力)
     * @ApiMethod   (POST)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1599018234",
        "data": [{
            "id": 1, //一级ID
            "pid": 0,
            "name": "建筑工程", //一级名称
            "children": [{ //二级
                "id": 3, //二级ID
                "pid": 1, //父ID
                "name": "一级建造师", //二级名称
            }]
        }]
    })
     */
    public function userJobAbility()
    {
        $list = UserJobAbility::where('pid',0)->field('id,pid,name')->select();
        foreach($list as &$v){
            $v['children'] = UserJobAbility::where('pid',$v['id'])->field('id,pid,name')->select();
        }
        $this->success('成功', $list);
    }

    /**
     * @ApiWeigh (89)
何书鹏 authored
201 202 203 204 205 206 207 208 209 210 211 212 213 214
     * @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="mobile", type="string", required=true, description="手机号")
     * @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="user_job_ability_ids", type="string", required=true, description="资质能力")
     * @ApiParams (name="qualification", type="string", required=true, description="资质证明(多文件用英文逗号隔开)")
何书鹏 authored
215
     * @ApiParams (name="resume", type="string", required=true, description="简历文件路径")
何书鹏 authored
216
     * @ApiParams (name="resume_name", type="inter", required=true, description="简历文件原始名称")
何书鹏 authored
217 218 219 220 221 222 223 224 225 226 227 228 229 230
     *
     * @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['mobile']) && $this->error('请输入手机号');
何书鹏 authored
231
        if($post['type'] != '1'){
何书鹏 authored
232 233 234 235 236 237 238 239 240
            empty($post['start_time']) && $this->error('请选择开始工作日期');
            empty($post['end_time']) && $this->error('请选择结束工作日期');
        }
        if(!empty($post['start_time'])){
            $post['start_time'] = strtotime($post['start_time']);
        }
        if(!empty($post['end_time'])){
            $post['end_time'] = strtotime($post['end_time']);
        }
何书鹏 authored
241 242 243
        empty($post['salary']) && $this->error('请输入薪资待遇');
        empty($post['address']) && $this->error('请输入期望工作地点');
        empty($post['user_job_ability_ids']) && $this->error('请选择资质能力');
何书鹏 authored
244
        empty($post['resume']) && $this->error('请选择简历');
何书鹏 authored
245
        empty($post['resume_name']) && $this->error('请传入简历原始名称');
何书鹏 authored
246
        $this->model->allowField(true)->save(array_merge([
何书鹏 authored
247 248
            'user_id' => $this->auth->id,
            'phone' => $post['mobile'],
何书鹏 authored
249 250 251 252
        ],$post));
        $this->success('发布求职成功');
    }
}