success('请求成功'); } /** * 获取员工列表信息 * * @ApiMethod (GET) * @param string department_code * @param string mes_online * @param string u8_online * @param string limit * @param string page * */ public function getStaffList(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); $where = []; $where['在职状态'] = '在职'; if (isset($params['mes_online'])){ $where['在职状态'] = $params['mes_online'] > 1 ? '离职':'在职'; } $where['U8在职'] = '在职'; if (isset($params['u8_online'])){ $where['U8在职'] = $params['u8_online'] > 1 ? '离职':'在职'; } $where['员工编号|员工姓名'] = array('like','%'.$params['search'].'%'); $limit = $params['limit']; if (empty($limit)){ $limit = 15; } $pages = $params['page']; if (empty($pages)){ $pages = 1; } $field = '员工编号,rtrim(员工姓名) as 员工姓名,性别,聘用日期,转正日期,rtrim(所在部门) as 所在部门,rtrim(部门编码) as 部门编码,rtrim(职称职务) as 职称职务,rtrim(身份证号) as 身份证号,出生日期, rtrim(人员性质) as 人员性质,rtrim(人员类别) as 人员类别,班次类型,工资表类别,薪酬核算分组,rtrim(在职状态) as 在职状态,rtrim(U8在职) as U8在职,U8离职日期,rtrim(sys_id) as sys_id,sys_rq,mod_rq'; if (strlen($params['department_code']) > 1){ $list = db('人事_基本资料')->where($where)->where('部门编码',$params['department_code'])->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select(); $total = db('人事_基本资料')->where($where)->where('部门编码',$params['department_code'])->count(); }else if (strlen($params['department_code']) == 1){ $list = db('人事_基本资料')->where($where)->where('LEFT(部门编码,1)='.$params['department_code'])->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select(); $total = db('人事_基本资料')->where($where)->where('LEFT(部门编码,1)='.$params['department_code'])->count(); }else{ $list = db('人事_基本资料')->where($where)->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select(); $total = db('人事_基本资料')->where($where)->count(); } $data['list'] = $list; $data['total'] = $total; $this->success('请求成功',$data); } /** * 获取部门列表 * * @ApiMethod (GET) * */ public function getDepartment(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $sql = "select rtrim(编号) as 编号,rtrim(名称) as 名称 from 人事_组织结构 where 状态 = '' order by 编号 asc "; $list = Db::query($sql); $data = []; foreach ($list as $key => $value){ $number = $value['编号']; if (strlen($number) == 2 ){//一级菜单 $sql = "select count(*) as total from 人事_基本资料 where LEFT(部门编码,2)='{$number}' and 在职状态 = '在职' and U8在职 = '在职'"; $res = Db::query($sql); $value['num'] = $res[0]['total']; $list[$key] = $value; $data[$number] = $value; }else { //二级菜单 $sql = "select count(*) as total from 人事_基本资料 where 部门编码='{$number}' and 在职状态 = '在职' and U8在职 = '在职'"; $res = Db::query($sql); $value['num'] = $res[0]['total']; $list[$key] = $value; } } $six = db('人事_基本资料')->where('在职状态','在职')->where('U8在职','离职')->count(); $sixArr['编号'] = ''; $sixArr['名称'] = '离职工资结算中'; $sixArr['total'] = $six; $sev = db('人事_基本资料')->where('在职状态','离职')->where('U8在职','离职')->count(); $sevArr['编号'] = ''; $sevArr['名称'] = '离职清单'; $sevArr['total'] = $sev; array_push($data,$sixArr,$sevArr); foreach ($data as $k=>$v){ $i = 0; $data[$k]['children'] = []; foreach ($list as $item){ $num = $item['编号']; if (strlen($num) >= 4 && substr($num,0,2) == $k){ if ($item['num'] > 0){ $data[$k]['children'][$i] = $item; $i++; } } } } $data = array_values($data); $this->success('请求成功',$data); } /** * 获取员工资料 * @ApiMethod GET * @params string code */ public function getStaffInfo(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); $where = []; if (isset($params['code'])){ $where['员工编号'] = $params['code'] ; } $field = '员工编号,rtrim(员工姓名) as 员工姓名,性别,聘用日期,转正日期,rtrim(所在部门) as 所在部门,rtrim(部门编码) as 部门编码,rtrim(职称职务) as 职称职务,rtrim(身份证号) as 身份证号,出生日期, rtrim(人员性质) as 人员性质,rtrim(人员类别) as 人员类别,班次类型,工资表类别,薪酬核算分组,rtrim(在职状态) as 在职状态,rtrim(U8在职) as U8在职,U8离职日期,rtrim(sys_id) as sys_id,sys_rq,mod_rq'; $data = db('人事_基本资料')->where($where)->field($field)->find(); $this->success('请求成功',$data); } /** * 修改员工资料 * * @ApiMethod POST * */ public function edit(){ if (Request::instance()->isPost() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); if (empty($params['员工编号'])){ $this->error('参数不能为空'); } $staffCode = $params['员工编号']; unset($params['员工编号']); $sql = db('人事_基本资料')->where('员工编号',$staffCode)->fetchSql(true)->update($params); $res = Db::query($sql); if ($res !== false){ $this->success('更新成功'); }else{ $this->error('更新失败'); } } /** * 员工法定天数修改 * @return void * @throws \think\Exception * @throws \think\db\exception\BindParamException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function clockUpdate() { if (Request::instance()->isPost() === false){ $this->error('非法请求'); } $params = Request::instance()->post(); if (empty($params['month']) || empty($params['number'])){ $this->error('参数错误'); } $staffList = \db('人事_基本资料') ->field('rtrim(员工编号) as 员工编号,rtrim(班次类型) as 班次类型') ->where('在职状态','在职') ->select(); $status = \db('人事_考勤资料')->where('kqzl_ny',$params['month'])->count(); $data = []; foreach ($staffList as $key => $value){ if ($value['班次类型'] === 'A类(双休班)'){ $hours = $params['typeA']; }elseif ($value['班次类型'] === 'B类(7.5小时班)'){ $hours = $params['typeB']; }else{ $hours = $params['typeC']; } $data[$key] =[ 'kqzl_ygbh' => $value['员工编号'], 'kqzl_ny' => $params['month'], '法定天数' => $params['number'], '不计定额天数' => 0, '法定工时' => $hours, '非考勤天数' => 0, '非考勤工时' => 0, '工作日出勤天数' => 0, '工作日出勤标准工时' => 0, '工作日出勤总工时' => 0, '可享法定假小时数' => 0, '有薪假工时' => 0, '延时加班' => 0, '双休加班天数' => 0, '双休加班' => 0, '法定假加班' => 0, '夜班次数' => 0, '调休类加班' => 0, '调休' => 0, '病假工时' => 0, '工伤工时' => 0, 'X_旷工工时' => 0, 'sys_id' => $params['sys_id'], 'sys_rq' => date('Y-m-d H:i:s',time()), 'mod_rq' => '1900-01-01 00:00:00', ]; } $lastId = \db('人事_考勤资料')->order('UniqId desc')->value('UniqId'); if ($status === 0){ foreach ($data as $key=>$value){ $data[$key]['UniqId'] = $lastId + $key + 1; } $sql = \db('人事_考勤资料')->fetchSql(true)->insertAll($data); $res = \db()->query($sql); if ($res !== false){ $this->success('成功'); }else{ $this->error('失败'); } }else{ $i = 0; foreach ($data as $key=>$value){ $value['mod_rq'] = date('Y-m-d H:i:s',time()); $sql = \db('人事_考勤资料') ->where('kqzl_ygbh',$value['kqzl_ygbh']) ->where('kqzl_ny',$value['kqzl_ny']) ->fetchSql(true) ->update($value); $res = \db()->query($sql); if ($res === false){ $i++; } } if ($i === 0){ $this->success('成功'); }else{ $this->error('失败'); } } } }