You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
3.9 KiB
144 lines
3.9 KiB
4 years ago
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\Api;
|
||
|
|
||
|
use App\Http\Resources\EmployeeGroup;
|
||
|
use App\Http\Resources\EmployeeGroupCollection;
|
||
|
use App\Models\EmployeeGroupT;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
/**
|
||
|
* @title 岗位管理
|
||
|
* @description 岗位管理
|
||
|
* @package App\Http\Controllers\Api
|
||
|
* @author zcstatham
|
||
|
* @time 2021/2/3
|
||
|
*/
|
||
|
class EmployeeGroupController extends BaseController
|
||
|
{
|
||
|
|
||
|
protected $rules = [
|
||
|
'store' => [
|
||
|
'rules' => [
|
||
|
'title' => 'required',
|
||
|
'pid' => 'required',
|
||
|
]
|
||
|
],
|
||
|
'show' => [
|
||
|
'rules' => [
|
||
|
'id' => 'bail|min:1',
|
||
|
],
|
||
|
'custom' => 'exists,App\Models\EmployeeGroupT,id'
|
||
|
],
|
||
|
'update' => [
|
||
|
'rules' => [
|
||
|
'id' => 'bail|min:1',
|
||
|
'pid' => 'required',
|
||
|
'title' => 'required',
|
||
|
],
|
||
|
'custom' => [
|
||
|
'exists,App\Models\EmployeeGroupT,id',
|
||
|
]
|
||
|
],
|
||
|
'destroy' => [
|
||
|
'rules' => [
|
||
|
'id' => 'bail|min:1',
|
||
|
],
|
||
|
'custom' => [
|
||
|
'exists,App\Models\EmployeeGroupT,id',
|
||
|
]
|
||
|
]
|
||
|
];
|
||
|
|
||
|
public function __construct(Request $request)
|
||
|
{
|
||
|
$this->model = new EmployeeGroupT();
|
||
|
parent::__construct($request);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 岗位列表
|
||
|
* @description 岗位列表
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function index()
|
||
|
{
|
||
|
$data = $this->model->getTree($this->params['status'] ?? null, $this->params['pid'] ?? 0);
|
||
|
|
||
|
return $this->success($data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 岗位保存
|
||
|
* @description 岗位保存
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function store()
|
||
|
{
|
||
|
$this->model->pid = $this->params['pid'];
|
||
|
$this->model->title = $this->params['title'];
|
||
|
$this->model->level = $this->params['level'];
|
||
|
$this->model->description = $this->params['description'] ?? '';
|
||
|
$this->model->base_salary = $this->params['base_salary'] ?? 0;
|
||
|
$this->model->status = $this->params['status'] ?? 2;
|
||
|
if($this->model->save()){
|
||
|
return $this->success(new EmployeeGroup($this->model));
|
||
|
} else {
|
||
|
return $this->error(500, '岗位信息保存失败');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 岗位详情
|
||
|
* @description 岗位详情
|
||
|
* @param $id
|
||
|
* @return mixed
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function show($id)
|
||
|
{
|
||
|
return $this->success(new EmployeeGroup($this->model->where('id', $id)->first()));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 岗位更新
|
||
|
* @description 岗位更新
|
||
|
* @param $id
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function update($id)
|
||
|
{
|
||
|
$this->model = $this->model->where('id', $id)->first();
|
||
|
$this->model->pid = $this->params['pid'];
|
||
|
$this->model->title = $this->params['title'];
|
||
|
$this->model->level = $this->params['level'] ?? $this->model->level;
|
||
|
$this->model->description = $this->params['description'] ?? $this->model->description;
|
||
|
$this->model->base_salary = $this->params['base_salary'] ?? $this->model->base_salary;
|
||
|
$this->model->status = $this->params['status'] ?? $this->model->status;
|
||
|
if($this->model->save()){
|
||
|
return $this->success(new EmployeeGroup($this->model));
|
||
|
} else {
|
||
|
return $this->error(500, '岗位信息保存失败');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @title 岗位删除
|
||
|
* @description 岗位删除
|
||
|
* @param $id
|
||
|
* @return \Illuminate\Http\JsonResponse
|
||
|
* @author zcstatham
|
||
|
*/
|
||
|
public function destroy($id)
|
||
|
{
|
||
|
if($this->model->where('id', $id)->update(['status' => 0])){
|
||
|
return $this->success();
|
||
|
} else {
|
||
|
return $this->error(500, '岗位信息保存失败');
|
||
|
}
|
||
|
}
|
||
|
}
|