323 lines
10 KiB
PHP
323 lines
10 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use think\Config;
|
|
use think\Controller;
|
|
use think\Db;
|
|
use think\Log;
|
|
use think\Model;
|
|
use think\Request;
|
|
use think\cache\driver\Memcache;
|
|
|
|
|
|
header("Access-Control-Allow-Origin:*");
|
|
header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
|
|
header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
|
|
|
|
|
|
class Hr extends Common
|
|
{
|
|
//获取分级部门类型列表
|
|
public function GetGradeDeptList()
|
|
{
|
|
|
|
$FirstLeveType = db('hr_dept')->where('super_dept_id', 0)->select();
|
|
|
|
for ($i = 0; $i < count($FirstLeveType); $i++) {
|
|
$SecondLeveType = db('hr_dept')->where('super_dept_id', $FirstLeveType[$i]['dept_id'])->select();
|
|
|
|
for ($j = 0; $j < count($SecondLeveType); $j++) {
|
|
$ThridLeveType = db('hr_dept')->where('super_dept_id', $SecondLeveType[$j]['dept_id'])->select();
|
|
|
|
$SecondLeveType[$j]['sub_dept'] = $ThridLeveType;
|
|
}
|
|
|
|
$FirstLeveType[$i]['sub_dept'] = $SecondLeveType;
|
|
}
|
|
|
|
return $this->sendSuccess($FirstLeveType);
|
|
}
|
|
|
|
//获取所有部门类型列表
|
|
public function GetDeptList()
|
|
{
|
|
$DeptType = db('hr_dept')->select();
|
|
return $this->sendSuccess($DeptType);
|
|
}
|
|
|
|
|
|
//根据部门ID获取员工信息
|
|
public function GetStaffInfoList()
|
|
{
|
|
|
|
$param = request()->post();
|
|
|
|
$result = db('hr_staff')->alias('i')
|
|
->join('hr_staff_type t', 'i.staff_type=t.id', 'left')
|
|
->where('i.del_time',null)
|
|
->field('i.*, t.desp as staff_type_desp')
|
|
->select();
|
|
|
|
//查找员工所属部门信息
|
|
for ($i=0; $i<count($result); $i++)
|
|
{
|
|
$dept_arr = explode(",", $result[$i]['staff_dept']);
|
|
$dept_desp = db('hr_dept')->where('dept_id', 'in', $dept_arr)->column('dept_name');
|
|
$result[$i]['staff_dept_desp'] = implode(',', $dept_desp);
|
|
}
|
|
|
|
|
|
$StaffList = [];
|
|
if (isset($param['type']))
|
|
{
|
|
for ($i=0; $i<count($result); $i++)
|
|
{
|
|
$dept_arr = explode(",", $result[$i]['staff_dept']);
|
|
if (in_array($param['type'], $dept_arr))
|
|
{
|
|
$StaffList[] = $result[$i];
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$StaffList = $result;
|
|
}
|
|
|
|
return $this->sendSuccess($StaffList);
|
|
}
|
|
public function GetStaffPage()
|
|
{
|
|
|
|
$param = request()->post();
|
|
|
|
$currPage = isset($param['currPage']) ? $param['currPage'] : 1;
|
|
$pageSize = isset($param['pageSize']) ? $param['pageSize'] : 20;
|
|
|
|
$result = db('hr_staff')->alias('i')
|
|
->join('hr_staff_type t', 'i.staff_type=t.id', 'left')
|
|
->where('i.del_time',null)
|
|
->field('i.*, t.desp as staff_type_desp')
|
|
->page($currPage, $pageSize)
|
|
->select();
|
|
|
|
|
|
$total = db('hr_staff')->alias('i')
|
|
->join('hr_staff_type t', 'i.staff_type=t.id', 'left')
|
|
->where('i.del_time',null)
|
|
->field('i.*, t.desp as staff_type_desp')
|
|
->count();
|
|
//查找员工所属部门信息
|
|
for ($i=0; $i<count($result); $i++)
|
|
{
|
|
$dept_arr = explode(",", $result[$i]['staff_dept']);
|
|
$dept_desp = db('hr_dept')->where('dept_id', 'in', $dept_arr)->column('dept_name');
|
|
$result[$i]['staff_dept_desp'] = implode(',', $dept_desp);
|
|
}
|
|
|
|
|
|
$StaffList = [];
|
|
if (isset($param['type']))
|
|
{
|
|
for ($i=0; $i<count($result); $i++)
|
|
{
|
|
$dept_arr = explode(",", $result[$i]['staff_dept']);
|
|
if (in_array($param['type'], $dept_arr))
|
|
{
|
|
$StaffList[] = $result[$i];
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$StaffList = $result;
|
|
}
|
|
$res['list'] = $StaffList;
|
|
$res['total'] = $total;
|
|
return $this->sendSuccess($res);
|
|
}
|
|
|
|
//获取项目部门所有的员工信息
|
|
public function GetProjectDeptStaffList()
|
|
{
|
|
|
|
$param = request()->post();
|
|
|
|
$result = db('hr_staff')->alias('i')
|
|
->join('hr_staff_type t', 'i.staff_type=t.id', 'left')
|
|
->field('i.*, t.desp as staff_type_desp')
|
|
->select();
|
|
|
|
//查找员工所属部门信息
|
|
for ($i=0; $i<count($result); $i++)
|
|
{
|
|
$dept_arr = explode(",", $result[$i]['staff_dept']);
|
|
$dept_desp = db('hr_dept')->where('dept_id', 'in', $dept_arr)->column('dept_name');
|
|
$result[$i]['staff_dept_desp'] = implode(',', $dept_desp);
|
|
}
|
|
|
|
|
|
$StaffList = [];
|
|
|
|
//工程项目部员工
|
|
$project_detp_id = 3;
|
|
for ($i=0; $i<count($result); $i++)
|
|
{
|
|
$dept_arr = explode(",", $result[$i]['staff_dept']);
|
|
if (in_array($project_detp_id, $dept_arr))
|
|
{
|
|
$StaffList[] = $result[$i];
|
|
}
|
|
}
|
|
|
|
//技术研发部员工
|
|
$project_detp_id = 4;
|
|
for ($i=0; $i<count($result); $i++)
|
|
{
|
|
$dept_arr = explode(",", $result[$i]['staff_dept']);
|
|
if (in_array($project_detp_id, $dept_arr))
|
|
{
|
|
$StaffList[] = $result[$i];
|
|
}
|
|
}
|
|
|
|
return $this->sendSuccess($StaffList);
|
|
}
|
|
|
|
//根据员工类型列表
|
|
public function GetStaffTypeList()
|
|
{
|
|
|
|
$param = request()->post();
|
|
$result = db('hr_staff_type')->select();
|
|
return $this->sendSuccess($result);
|
|
}
|
|
|
|
public function AddDeptType()
|
|
{
|
|
$param = request()->post();
|
|
$ret = [];
|
|
|
|
if ($param['dept_id']>0)
|
|
{
|
|
//添加子类型
|
|
$ret = db('hr_dept')->where('dept_id', $param['dept_id'])->field('dept_id,super_dept_id')->find();
|
|
}
|
|
else
|
|
{
|
|
//添加基类型
|
|
$ret['dept_id'] = 0;
|
|
}
|
|
|
|
if ($ret != null) {
|
|
$insert = [];
|
|
$insert['dept_name'] = $param['dept_name'];
|
|
$insert['super_dept_id'] = $ret['dept_id'];
|
|
//$insert['create_time'] = date('Y-m-d H:i:s');
|
|
db('hr_dept')->insert($insert);
|
|
}
|
|
}
|
|
|
|
//根据资产类型获取资产列表
|
|
public function AddStaffInfo()
|
|
{
|
|
$param = request()->post();
|
|
|
|
if ($param != null)
|
|
{
|
|
$insert_info = [];
|
|
$insert_info['staff_idcard'] = $param['staff_idcard'];
|
|
$insert_info['staff_name'] = $param['staff_name'];
|
|
$insert_info['staff_phone'] = $param['staff_phone'];
|
|
$insert_info['staff_dept'] = implode(',', $param['staff_dept']);
|
|
$insert_info['entry_date'] = $param['entry_date'];
|
|
$insert_info['staff_type'] = $param['staff_type'];
|
|
$insert_info['staff_email'] = $param['staff_email'];
|
|
|
|
$ret = db('hr_staff')->insert($insert_info);
|
|
return $this->sendSuccess($ret);
|
|
}
|
|
else
|
|
{
|
|
return $this->sendError('部门不存在');
|
|
}
|
|
|
|
}
|
|
|
|
public function updateStaffInfo()
|
|
{
|
|
$param = request()->post();
|
|
if($param != null){
|
|
$update = [];
|
|
$update['staff_idcard'] = $param['staff_idcard'];
|
|
$update['staff_name'] = $param['staff_name'];
|
|
$update['staff_phone'] = $param['staff_phone'];
|
|
$update['staff_dept'] = implode(',', $param['staff_dept']);
|
|
$update['entry_date'] = $param['entry_date'];
|
|
$update['staff_type'] = $param['staff_type'];
|
|
$update['staff_email'] = $param['staff_email'];
|
|
$ret = db('hr_staff')->where('staff_id',$param['staff_id'])->update($update);
|
|
if($ret){
|
|
return $this->sendSuccess('修改成功');
|
|
}else{
|
|
return $this->sendError('修改失败');
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public function SetDeptManager()
|
|
{
|
|
$param = request()->post();
|
|
if($param != null){
|
|
$update = [];
|
|
$update['dept_leader'] = $param['staff_id'];
|
|
$ret = db('hr_dept')->where('dept_id',$param['dept_id'])->update($update);
|
|
if($ret){
|
|
return $this->sendSuccess('设置成功');
|
|
}else{
|
|
return $this->sendError('设置失败');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function delHrStaff()
|
|
{
|
|
$param = request()->post();
|
|
if($param){
|
|
$update = [];
|
|
$update['staff_id'] = $param['staff_id'];
|
|
$update['del_time'] = date('Y-m-d H:i:s');
|
|
$ret = db('hr_staff')->where('staff_id',$param['staff_id'])->update($update);
|
|
if($ret){
|
|
return $this->sendSuccess('删除成功');
|
|
}else{
|
|
return $this->sendError('删除失败');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public function GetOperationDeptStaff()
|
|
{
|
|
$operation_dept_id = 2;
|
|
$ret = db('hr_staff')->alias('p')
|
|
->join('system_user s', 's.user_id =p.staff_id', 'left')
|
|
->where('s.user_type', 1)
|
|
->where(function ($query) use ($operation_dept_id) {
|
|
$query->where('p.staff_dept', $operation_dept_id)
|
|
->whereor('p.staff_dept', 'like', $operation_dept_id . ',%')
|
|
->whereor('p.staff_dept', 'like', '%,' . $operation_dept_id . ',%')
|
|
//->whereor('p.staff_dept', 'like', $operation_dept_id . '')
|
|
->whereor('p.staff_dept', 'like', '%,' . $operation_dept_id);
|
|
})
|
|
->field('p.staff_name as name , s.id as id')
|
|
->select();
|
|
|
|
return $this->sendSuccess($ret);
|
|
}
|
|
|
|
|
|
|
|
} |