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.
 
 
user_center/app/Http/Controllers/Api/EmployeeSocialItemsControll...

157 lines
4.8 KiB

<?php
namespace App\Http\Controllers\Api;
use App\Http\Resources\EmployeeSocialItemsCollection;
use App\Http\Resources\EmployeeSocialItems;
use App\Models\EmployeeSocialItemsT;
use Illuminate\Http\Request;
/**
* @title 社保管理
* @description 社保管理
* @package App\Http\Controllers\Api
* @author zcstatham
* @time 2021/2/3
*/
class EmployeeSocialItemsController extends BaseController
{
protected $rules = [
'store' => [
'rules' => [
'employee_id' => 'required',
'social_type' => 'required',
'base_price' => 'required',
'personal_rate' => 'required',
'unit_rate' => 'required',
]
],
'show' => [
'rules' => [
'id' => 'bail|min:1',
],
'custom' => 'exists,App\Models\EmployeeSocialItemsT,id'
],
'update' => [
'rules' => [
'id' => 'bail|min:1',
'employee_id' => 'required',
'social_type' => 'required',
'base_price' => 'required',
'personal_rate' => 'required',
'unit_rate' => 'required',
],
'custom' => [
'exists,App\Models\EmployeeSocialItemsT,id',
]
],
'destroy' => [
'rules' => [
'id' => 'bail|min:1',
],
'custom' => [
'exists,App\Models\EmployeeSocialItemsT,id',
]
]
];
public function __construct(Request $request)
{
$this->model = new EmployeeSocialItemsT();
parent::__construct($request);
}
/**
* @title 社保列表
* @description 社保列表
* @return \Illuminate\Http\JsonResponse
* @author zcstatham
*/
public function index()
{
$query = $this->model->query();
if(isset($this->params['name']) && $this->params['name'] != ''){
$query->where('name', $this->params['name']);
}
$data = $query->paginate();
return $this->success(new EmployeeSocialItemsCollection($data));
}
/**
* @title 社保保存
* @description 社保保存
* @return \Illuminate\Http\JsonResponse
* @author zcstatham
*/
public function store()
{
$this->model->employee_id = $this->params['employee_id'];
$this->model->social_type = $this->params['social_type'];
$this->model->base_price = $this->params['base_price'];
$this->model->personal_rate = $this->params['personal_rate'];
$this->model->unit_rate = $this->params['unit_rate'];
$this->model->personal_price = $this->params['personal_price'] ?: route($this->params['base_price'] * $this->params['personal_rate'] / 100);
$this->model->unit_price = $this->params['unit_price'] ?: route($this->params['base_price'] * $this->params['unit_rate'] / 100);
if($this->model->save()){
return $this->success(new EmployeeSocialItems($this->model));
} else {
return $this->error(500, '社保信息保存失败');
}
}
/**
* @title 社保详情
* @description 社保详情
* @param $id
* @return mixed
* @author zcstatham
*/
public function show($id)
{
return $this->success(new EmployeeSocialItems($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->employee_id = $this->params['employee_id'];
$this->model->social_type = $this->params['social_type'];
$this->model->base_price = $this->params['base_price'];
$this->model->personal_rate = $this->params['personal_rate'];
$this->model->unit_rate = $this->params['unit_rate'];
$this->model->personal_price = $this->params['personal_price'] ?: route($this->params['base_price'] * $this->params['personal_price'] / 100);
$this->model->unit_price = $this->params['unit_price'] ?: route($this->params['base_price'] * $this->params['unit_rate'] / 100);
if($this->model->save()){
return $this->success(new EmployeeSocialItems($this->model));
} else {
return $this->error(500, '社保信息保存失败');
}
}
/**
* @title 社保删除
* @description 社保删除
* @param $id
* @return \Illuminate\Http\JsonResponse
* @author zcstatham
*/
public function destroy($id)
{
if($this->model->destroy($id)){
return $this->success();
} else {
return $this->error(500, '社保信息保存失败');
}
}
}