|
|
@@ -1,574 +1,576 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-namespace app\api\controller;
|
|
|
-
|
|
|
-use app\common\controller\Api;
|
|
|
-use \think\Request;
|
|
|
-use \think\Db;
|
|
|
-/**
|
|
|
- * 员工资料接口
|
|
|
- */
|
|
|
-class Staff extends Api
|
|
|
-{
|
|
|
- protected $noNeedLogin = ['*'];
|
|
|
- protected $noNeedRight = ['*'];
|
|
|
- /**
|
|
|
- * 首页
|
|
|
- */
|
|
|
- public function index()
|
|
|
- {
|
|
|
- $this->success('员工资料接口');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取部门列表
|
|
|
- * 一级:部门 dept_name
|
|
|
- * 二级:工序 big_process(按固定顺序:裁剪、车缝、手工、大烫、总检、包装、其他)
|
|
|
- * 空工序 = 其他
|
|
|
- */
|
|
|
- public function getDepartment()
|
|
|
- {
|
|
|
- if (Request::instance()->isGet() == false) {
|
|
|
- $this->error('非法请求');
|
|
|
- }
|
|
|
-
|
|
|
- // 1. 查询数据,空工序转为"其他"
|
|
|
- $list = db('人员_基本资料')
|
|
|
- ->field('dept_name, IF(big_process IS NULL OR big_process = "", "其他", big_process) as big_process, COUNT(*) AS count')
|
|
|
- ->whereNull('mod_rq')
|
|
|
- ->group('dept_name, big_process')
|
|
|
- ->select();
|
|
|
-
|
|
|
- // 2. 构建树形结构(一级:部门,二级:工序)
|
|
|
- $tree = [];
|
|
|
- foreach ($list as $item) {
|
|
|
- $dept = $item['dept_name'];
|
|
|
- $process = $item['big_process'];
|
|
|
- $count = $item['count'];
|
|
|
-
|
|
|
- // 初始化部门节点
|
|
|
- if (!isset($tree[$dept])) {
|
|
|
- $tree[$dept] = [
|
|
|
- 'label' => $dept,
|
|
|
- 'count' => 0,
|
|
|
- 'children' => []
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- // 部门总人数累加
|
|
|
- $tree[$dept]['count'] += $count;
|
|
|
-
|
|
|
- // 工序加入children
|
|
|
- $tree[$dept]['children'][] = [
|
|
|
- 'label' => $process,
|
|
|
- 'count' => $count
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- // 3. 对每个部门下的工序,按固定顺序排序
|
|
|
- $sortList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装', '其他'];
|
|
|
- foreach ($tree as &$deptNode) {
|
|
|
- $sortedChildren = [];
|
|
|
- foreach ($sortList as $process) {
|
|
|
- foreach ($deptNode['children'] as $child) {
|
|
|
- if ($child['label'] === $process) {
|
|
|
- $sortedChildren[] = $child;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $deptNode['children'] = $sortedChildren;
|
|
|
- }
|
|
|
-
|
|
|
- // 4. 转成索引数组返回
|
|
|
- $result = array_values($tree);
|
|
|
-
|
|
|
- $this->success('获取部门数据', $result);
|
|
|
- }
|
|
|
-// public function getDepartment()
|
|
|
-// {
|
|
|
-// if (Request::instance()->isGet() == false) {
|
|
|
-// $this->error('非法请求');
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 1. 查询数据
|
|
|
-// $list = db('人员_基本资料')
|
|
|
-// ->field('big_process, dept_name, COUNT(*) AS count')
|
|
|
-// ->whereNull('mod_rq')
|
|
|
-// ->group('big_process, dept_name')
|
|
|
-// ->select();
|
|
|
-//
|
|
|
-// // 2. 构建树形结构
|
|
|
-// $tree = [];
|
|
|
-// foreach ($list as $item) {
|
|
|
-// $process = $item['big_process'] ?: '其他'; // 空工序 = 其他
|
|
|
-// $dept = $item['dept_name'];
|
|
|
-// $count = $item['count'];
|
|
|
-//
|
|
|
-// if (!isset($tree[$process])) {
|
|
|
-// $tree[$process] = [
|
|
|
-// 'label' => $process,
|
|
|
-// 'count' => 0,
|
|
|
-// 'children' => []
|
|
|
-// ];
|
|
|
-// }
|
|
|
-//
|
|
|
-// $tree[$process]['count'] += $count;
|
|
|
-// $tree[$process]['children'][] = [
|
|
|
-// 'label' => $dept,
|
|
|
-// 'count' => $count
|
|
|
-// ];
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 3. 固定排序:裁剪、车缝、手工、大烫、总检、包装、其他
|
|
|
-// $sortList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装', '其他'];
|
|
|
-// $result = [];
|
|
|
-// foreach ($sortList as $item) {
|
|
|
-// if (isset($tree[$item])) {
|
|
|
-// $result[] = $tree[$item];
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// $this->success('获取部门数据', $result);
|
|
|
-// }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取员工列表信息
|
|
|
- */
|
|
|
- public function getStaffList(){
|
|
|
- if (Request::instance()->isGet() == false){
|
|
|
- $this->error('非法请求');
|
|
|
- }
|
|
|
- $params = Request::instance()->param();
|
|
|
- $where = [];
|
|
|
-
|
|
|
- if (!empty($params['search'])){
|
|
|
- $where['staff_no|staff_name'] = array('like','%'.$params['search'].'%');
|
|
|
- }
|
|
|
- if (!empty($params['department_code'])){
|
|
|
- $where['big_process|dept_name'] = $params['department_code'];
|
|
|
- }
|
|
|
-
|
|
|
- $limit = $params['limit'];
|
|
|
- if (empty($limit)){
|
|
|
- $limit = 15;
|
|
|
- }
|
|
|
- $pages = $params['page'];
|
|
|
- if (empty($pages)){
|
|
|
- $pages = 1;
|
|
|
- }
|
|
|
- $list = db('人员_基本资料')
|
|
|
- ->field('
|
|
|
- id,
|
|
|
- staff_no as 员工编号,
|
|
|
- staff_name as 员工姓名,
|
|
|
- gender as 性别,
|
|
|
- big_process as 生产工序,
|
|
|
- dept_name as 所在部门,
|
|
|
- status as 状态,
|
|
|
- sys_rq as 创建日期,
|
|
|
- sys_id as 创建人员
|
|
|
- ')
|
|
|
- ->where($where)->page($pages)->limit($limit)->order('id desc')->whereNull('mod_rq')->select();
|
|
|
- $total = db('人员_基本资料')->where($where)->whereNull('mod_rq')->count();
|
|
|
- $data['list'] = $list;
|
|
|
- $data['total'] = $total;
|
|
|
- $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['id'])){
|
|
|
- $where['id'] = $params['id'];
|
|
|
- }
|
|
|
-
|
|
|
- // 1. 查询人员基础信息
|
|
|
- $staffList = db('人员_基本资料')
|
|
|
- ->field('
|
|
|
- id,
|
|
|
- staff_no as 员工编号,
|
|
|
- staff_name as 员工姓名,
|
|
|
- gender as 性别,
|
|
|
- big_process as 生产工序,
|
|
|
- dept_name as 所在部门,
|
|
|
- status as 状态,
|
|
|
- sys_rq as 创建日期,
|
|
|
- sys_id as 创建人员
|
|
|
- ')
|
|
|
- ->where($where)
|
|
|
- ->whereNull('mod_rq')
|
|
|
- ->select();
|
|
|
-
|
|
|
- $this->success('获取员工资料', $staffList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增员工资料
|
|
|
- */
|
|
|
- public function PostStaffAdd(){
|
|
|
- if (Request::instance()->isPost() == false){
|
|
|
- $this->error('非法请求');
|
|
|
- }
|
|
|
-
|
|
|
- $params = Request::instance()->param();
|
|
|
-
|
|
|
- $staff_no = $params['员工编号'] ?? '';
|
|
|
- if(empty($staff_no)){
|
|
|
- $this->error('员工编号不能为空');
|
|
|
- }
|
|
|
-
|
|
|
- // 查询数据库是否已存在
|
|
|
- $Find_list = Db::name('人员_基本资料')->where('staff_no', $staff_no)->whereNull('mod_rq')->find();
|
|
|
- if($Find_list){
|
|
|
- $this->error('员工编号已存在');
|
|
|
- }
|
|
|
-
|
|
|
- $data = [];
|
|
|
- $data['staff_no'] = $params['员工编号'];
|
|
|
- $data['staff_name'] = $params['员工姓名'];
|
|
|
- $data['gender'] = $params['性别'];
|
|
|
- $data['big_process'] = $params['生产工序'];
|
|
|
- $data['dept_name'] = '生产部';
|
|
|
- $data['status'] = 1;
|
|
|
- $data['sys_rq'] = date('Y-m-d H:i:s');
|
|
|
- $data['sys_id'] = $params['sys_id'];
|
|
|
-
|
|
|
- $res = Db::name('人员_基本资料')->insert($data);
|
|
|
-
|
|
|
- if ($res !== false){
|
|
|
- $this->success('新增成功');
|
|
|
- }else{
|
|
|
- $this->error('新增失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改员工资料
|
|
|
- * @ApiMethod POST
|
|
|
- *
|
|
|
- */
|
|
|
- public function PostStaffEdit(){
|
|
|
- if (!Request::instance()->isPost()){
|
|
|
- $this->error('非法请求');
|
|
|
- }
|
|
|
-
|
|
|
- $params = Request::instance()->param();
|
|
|
-
|
|
|
- //必传参数校验
|
|
|
- if (empty($params['id'])){
|
|
|
- $this->error('参数不能为空');
|
|
|
- }
|
|
|
- if (empty($params['员工编号'])){
|
|
|
- $this->error('员工编号不能为空');
|
|
|
- }
|
|
|
-
|
|
|
- //查询员工是否存在(未删除)
|
|
|
- $info = db('人员_基本资料')
|
|
|
- ->where('id', $params['id'])
|
|
|
- ->whereNull('mod_rq')
|
|
|
- ->find();
|
|
|
- if (!$info){
|
|
|
- $this->error('员工不存在');
|
|
|
- }
|
|
|
-
|
|
|
- //员工编号重复判断(排除自身)
|
|
|
- $exist = db('人员_基本资料')
|
|
|
- ->where('staff_no', $params['员工编号'])
|
|
|
- ->where('id', '<>', $params['id']) // 排除自己
|
|
|
- ->whereNull('mod_rq')
|
|
|
- ->find();
|
|
|
- if ($exist) {
|
|
|
- $this->error('员工编号已存在');
|
|
|
- }
|
|
|
-
|
|
|
- //修改数据
|
|
|
- $data = [];
|
|
|
- $data['staff_no'] = $params['员工编号'];
|
|
|
- $data['staff_name'] = $params['员工姓名'];
|
|
|
- $data['gender'] = $params['性别'];
|
|
|
- $data['big_process'] = $params['生产工序'];
|
|
|
- $data['dept_name'] = '生产部';
|
|
|
- $data['updatetime'] = date('Y-m-d H:i:s');
|
|
|
- $data['sys_id'] = $params['sys_id'];
|
|
|
-
|
|
|
- $res = db('人员_基本资料')
|
|
|
- ->where('id', $params['id'])
|
|
|
- ->update($data);
|
|
|
- if ($res !== false){
|
|
|
- $this->success('更新成功');
|
|
|
- }else{
|
|
|
- $this->error('更新失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除员工资料
|
|
|
- */
|
|
|
- public function PostStaffDelete()
|
|
|
- {
|
|
|
- if (Request::instance()->isPost() == false){
|
|
|
- $this->error('非法请求');
|
|
|
- }
|
|
|
- $params = Request::instance()->param();
|
|
|
- if (empty($params['id'])){
|
|
|
- $this->error('参数不能为空');
|
|
|
- }
|
|
|
- $staffCode = $params['id'];
|
|
|
- $sql = db('人员_基本资料')->where('id',$staffCode)->fetchSql(true)->update(['mod_rq'=>date('Y-m-d H:i:s')]);
|
|
|
- $res = Db::query($sql);
|
|
|
- if ($res !== false){
|
|
|
- $this->success('删除成功');
|
|
|
- }else{
|
|
|
- $this->error('删除失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取小组
|
|
|
- */
|
|
|
- public function GetDeviceNameList(){
|
|
|
- if (!Request::instance()->isGet()){
|
|
|
- $this->error('非法请求');
|
|
|
- }
|
|
|
-
|
|
|
- // 定义需要过滤、不返回给前端的设备编组
|
|
|
- $filterGroups = [
|
|
|
- '自动裁床01组',
|
|
|
- '自动裁床02组',
|
|
|
- '模板机01组',
|
|
|
- '模板机02组',
|
|
|
- '上袖机01组',
|
|
|
- '上袖机02组',
|
|
|
- '裁床1',
|
|
|
- '裁床2',
|
|
|
- '模版机'
|
|
|
- ];
|
|
|
-
|
|
|
- $list = Db::name('设备_基本资料')
|
|
|
- ->field('UniqId,设备编组,生产工序,工序')
|
|
|
- ->where('设备名称', 1)
|
|
|
- ->whereNull('mod_rq')
|
|
|
- ->whereNotIn('设备编组', $filterGroups) // 过滤不想要的数据
|
|
|
- ->group('设备编组')
|
|
|
- ->order('工序,UniqId asc')
|
|
|
- ->select();
|
|
|
-
|
|
|
- $this->success('获取设备编组成功', $list);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取小组及人员列表
|
|
|
- * 支持按工序/小组名称搜索,返回每个小组下的成员信息
|
|
|
- */
|
|
|
- public function GetTeamStaffList()
|
|
|
- {
|
|
|
- if (Request::instance()->isGet() == false) {
|
|
|
- $this->error('非法请求');
|
|
|
- }
|
|
|
- $params = Request::instance()->param();
|
|
|
-
|
|
|
- $where = [];
|
|
|
- if (!empty($params['search'])) {
|
|
|
- $where['b.staff_no|b.staff_name|a.team_name|b.big_process'] = array('like', '%' . $params['search'] . '%');
|
|
|
- }
|
|
|
-
|
|
|
- $list = Db::name('人员_小组资料')->alias('a')
|
|
|
- ->field('
|
|
|
- b.staff_no as 员工编号,
|
|
|
- b.staff_name as 员工姓名,
|
|
|
- a.*
|
|
|
- ')
|
|
|
- ->join('人员_基本资料 b', 'a.staff_no = b.staff_no')
|
|
|
- ->where($where)
|
|
|
- ->whereNull('a.mod_rq')
|
|
|
- ->whereNull('b.mod_rq')
|
|
|
- ->order('a.id asc')
|
|
|
- ->select();
|
|
|
-
|
|
|
- // 整理成"小组+成员"的树形结构
|
|
|
- $result = [];
|
|
|
- foreach ($list as $item) {
|
|
|
- $teamId = $item['team_id'];
|
|
|
- if (!isset($result[$teamId])) {
|
|
|
- $result[$teamId] = [
|
|
|
- '小组ID' => $teamId,
|
|
|
- '小组名称' => $item['team_name'],
|
|
|
- '生产工序' => $item['big_process'],
|
|
|
- 'staff_list' => []
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- $member = [
|
|
|
- 'id' => $item['id'],
|
|
|
- '员工编号' => $item['员工编号'],
|
|
|
- '员工姓名' => $item['员工姓名'],
|
|
|
- '小组名称' => $item['team_name'],
|
|
|
- '职位' => $item['position']
|
|
|
- ];
|
|
|
-
|
|
|
- // 组长排第一个
|
|
|
- if ($item['position'] == '组长') {
|
|
|
- array_unshift($result[$teamId]['staff_list'], $member);
|
|
|
- } else {
|
|
|
- $result[$teamId]['staff_list'][] = $member;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 转为索引数组返回
|
|
|
- $data = array_values($result);
|
|
|
- $this->success('获取成功', $data);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增小组人员
|
|
|
- */
|
|
|
- public function AddTeamStaff()
|
|
|
- {
|
|
|
- if (!Request::instance()->isPost()) {
|
|
|
- $this->error('非法请求');
|
|
|
- }
|
|
|
-
|
|
|
- $params = Request::instance()->param();
|
|
|
-
|
|
|
- // 1. 校验员工是否存在
|
|
|
- $staffInfo = Db::name('人员_基本资料')
|
|
|
- ->where('staff_no', $params['staff_no'])
|
|
|
- ->whereNull('mod_rq')
|
|
|
- ->find();
|
|
|
- if (!$staffInfo) {
|
|
|
- $this->error('员工不存在或已删除');
|
|
|
- }
|
|
|
-
|
|
|
- // 2. 校验该员工是否已在小组中
|
|
|
- $exist = Db::name('人员_小组资料')
|
|
|
- ->where('staff_no', $params['staff_no'])
|
|
|
- ->whereNull('mod_rq')
|
|
|
- ->find();
|
|
|
- if ($exist) {
|
|
|
- $this->error('该员工已在'.$exist['team_name'].'小组中');
|
|
|
- }
|
|
|
-
|
|
|
- // 3. 组装数据
|
|
|
- $data = [
|
|
|
- 'big_process' => $params['big_process'],
|
|
|
- 'team_id' => $params['team_id'],
|
|
|
- 'team_name' => $params['team_name'],
|
|
|
- 'staff_no' => $params['staff_no'],
|
|
|
- 'position' => $params['position'],
|
|
|
- 'status' => 1,
|
|
|
- 'sys_id' => $params['sys_id'],
|
|
|
- 'createtime' => date('Y-m-d H:i:s')
|
|
|
- ];
|
|
|
-
|
|
|
- $res = Db::name('人员_小组资料')->insert($data);
|
|
|
- if ($res) {
|
|
|
- $this->success('新增成功');
|
|
|
- } else {
|
|
|
- $this->error('新增失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改小组人员
|
|
|
- */
|
|
|
- public function EditTeamStaff()
|
|
|
- {
|
|
|
- if (!Request::instance()->isPost()) {
|
|
|
- $this->error('非法请求');
|
|
|
- }
|
|
|
-
|
|
|
- $params = Request::instance()->param();
|
|
|
-
|
|
|
- // 必传参数校验
|
|
|
- if (empty($params['id'])) {
|
|
|
- $this->error('参数不完整');
|
|
|
- }
|
|
|
-
|
|
|
- // 1. 校验该记录是否存在
|
|
|
- $info = Db::name('人员_小组资料')
|
|
|
- ->where('id', $params['id'])
|
|
|
- ->whereNull('mod_rq')
|
|
|
- ->find();
|
|
|
- if (!$info) {
|
|
|
- $this->error('记录不存在或已删除');
|
|
|
- }
|
|
|
-
|
|
|
- // 2. 如果修改了员工ID,校验新员工是否已在该小组中(排除自身)
|
|
|
- if (!empty($params['staff_id']) && $params['staff_id'] != $info['staff_id']) {
|
|
|
- $exist = Db::name('人员_小组资料')
|
|
|
- ->where('team_id', $params['team_id'] ?? $info['team_id'])
|
|
|
- ->where('staff_id', $params['staff_id'])
|
|
|
- ->where('id', '<>', $params['id'])
|
|
|
- ->whereNull('mod_rq')
|
|
|
- ->find();
|
|
|
- if ($exist) {
|
|
|
- $this->error('该员工已在此小组中');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 3. 组装更新数据
|
|
|
- $data = [];
|
|
|
- if (isset($params['big_process'])) $data['big_process'] = $params['big_process'];
|
|
|
- if (isset($params['team_id'])) $data['team_id'] = $params['team_id'];
|
|
|
- if (isset($params['team_name'])) $data['team_name'] = $params['team_name'];
|
|
|
- if (isset($params['position'])) $data['position'] = $params['position'];
|
|
|
- if (isset($params['staff_id'])) {
|
|
|
- $data['staff_id'] = $params['staff_id'];
|
|
|
- // 更新员工姓名
|
|
|
- $staffInfo = Db::name('人员_基本资料')->where('id', $params['staff_id'])->find();
|
|
|
- if ($staffInfo) {
|
|
|
- $data['staff_name'] = $staffInfo['staff_name'];
|
|
|
- }
|
|
|
- }
|
|
|
- if (isset($params['position'])) $data['position'] = $params['position'];
|
|
|
- $data['updatetime'] = date('Y-m-d H:i:s');
|
|
|
-
|
|
|
- $res = Db::name('人员_小组资料')
|
|
|
- ->where('id', $params['id'])
|
|
|
- ->update($data);
|
|
|
-
|
|
|
- if ($res !== false) {
|
|
|
- $this->success('小组更换成功');
|
|
|
- } else {
|
|
|
- $this->error('小组更换失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除小组人员
|
|
|
- */
|
|
|
- public function DelTeamStaff()
|
|
|
- {
|
|
|
- if (!Request::instance()->isPost()) {
|
|
|
- $this->error('非法请求');
|
|
|
- }
|
|
|
-
|
|
|
- $params = Request::instance()->param();
|
|
|
-
|
|
|
- $res = Db::name('人员_小组资料')
|
|
|
- ->where('id', $params['id'])
|
|
|
- ->update([
|
|
|
- 'mod_rq' => date('Y-m-d H:i:s')
|
|
|
- ]);
|
|
|
-
|
|
|
- if ($res !== false) {
|
|
|
- $this->success('删除成功');
|
|
|
- } else {
|
|
|
- $this->error('删除失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use \think\Request;
|
|
|
+use \think\Db;
|
|
|
+use Overtrue\Pinyin\Pinyin;
|
|
|
+/**
|
|
|
+ * 员工资料接口
|
|
|
+ */
|
|
|
+class Staff extends Api
|
|
|
+{
|
|
|
+ protected $noNeedLogin = ['*'];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+ /**
|
|
|
+ * 首页
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $this->success('员工资料接口');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取部门列表
|
|
|
+ * 一级:部门 dept_name
|
|
|
+ * 二级:工序 big_process(按固定顺序:裁剪、车缝、手工、大烫、总检、包装、其他)
|
|
|
+ * 空工序 = 其他
|
|
|
+ */
|
|
|
+ public function getDepartment()
|
|
|
+ {
|
|
|
+ if (Request::instance()->isGet() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 查询数据,空工序转为"其他"
|
|
|
+ $list = db('人员_基本资料')
|
|
|
+ ->field('dept_name, IF(big_process IS NULL OR big_process = "", "其他", big_process) as big_process, COUNT(*) AS count')
|
|
|
+ ->whereNull('mod_rq')
|
|
|
+ ->group('dept_name, big_process')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ // 2. 构建树形结构(一级:部门,二级:工序)
|
|
|
+ $tree = [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $dept = $item['dept_name'];
|
|
|
+ $process = $item['big_process'];
|
|
|
+ $count = $item['count'];
|
|
|
+
|
|
|
+ // 初始化部门节点
|
|
|
+ if (!isset($tree[$dept])) {
|
|
|
+ $tree[$dept] = [
|
|
|
+ 'label' => $dept,
|
|
|
+ 'count' => 0,
|
|
|
+ 'children' => []
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 部门总人数累加
|
|
|
+ $tree[$dept]['count'] += $count;
|
|
|
+
|
|
|
+ // 工序加入children
|
|
|
+ $tree[$dept]['children'][] = [
|
|
|
+ 'label' => $process,
|
|
|
+ 'count' => $count
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 对每个部门下的工序,按固定顺序排序
|
|
|
+ $sortList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装', '其他'];
|
|
|
+ foreach ($tree as &$deptNode) {
|
|
|
+ $sortedChildren = [];
|
|
|
+ foreach ($sortList as $process) {
|
|
|
+ foreach ($deptNode['children'] as $child) {
|
|
|
+ if ($child['label'] === $process) {
|
|
|
+ $sortedChildren[] = $child;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $deptNode['children'] = $sortedChildren;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 转成索引数组返回
|
|
|
+ $result = array_values($tree);
|
|
|
+
|
|
|
+ $this->success('获取部门数据', $result);
|
|
|
+ }
|
|
|
+// public function getDepartment()
|
|
|
+// {
|
|
|
+// if (Request::instance()->isGet() == false) {
|
|
|
+// $this->error('非法请求');
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 1. 查询数据
|
|
|
+// $list = db('人员_基本资料')
|
|
|
+// ->field('big_process, dept_name, COUNT(*) AS count')
|
|
|
+// ->whereNull('mod_rq')
|
|
|
+// ->group('big_process, dept_name')
|
|
|
+// ->select();
|
|
|
+//
|
|
|
+// // 2. 构建树形结构
|
|
|
+// $tree = [];
|
|
|
+// foreach ($list as $item) {
|
|
|
+// $process = $item['big_process'] ?: '其他'; // 空工序 = 其他
|
|
|
+// $dept = $item['dept_name'];
|
|
|
+// $count = $item['count'];
|
|
|
+//
|
|
|
+// if (!isset($tree[$process])) {
|
|
|
+// $tree[$process] = [
|
|
|
+// 'label' => $process,
|
|
|
+// 'count' => 0,
|
|
|
+// 'children' => []
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $tree[$process]['count'] += $count;
|
|
|
+// $tree[$process]['children'][] = [
|
|
|
+// 'label' => $dept,
|
|
|
+// 'count' => $count
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 3. 固定排序:裁剪、车缝、手工、大烫、总检、包装、其他
|
|
|
+// $sortList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装', '其他'];
|
|
|
+// $result = [];
|
|
|
+// foreach ($sortList as $item) {
|
|
|
+// if (isset($tree[$item])) {
|
|
|
+// $result[] = $tree[$item];
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// $this->success('获取部门数据', $result);
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取员工列表信息
|
|
|
+ */
|
|
|
+ public function getStaffList(){
|
|
|
+ if (Request::instance()->isGet() == false){
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->param();
|
|
|
+ $where = [];
|
|
|
+
|
|
|
+ if (!empty($params['search'])){
|
|
|
+ $where['staff_no|staff_name|pinyin'] = array('like','%'.$params['search'].'%');
|
|
|
+ }
|
|
|
+ if (!empty($params['department_code'])){
|
|
|
+ $where['big_process|dept_name'] = $params['department_code'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $limit = $params['limit'];
|
|
|
+ if (empty($limit)){
|
|
|
+ $limit = 15;
|
|
|
+ }
|
|
|
+ $pages = $params['page'];
|
|
|
+ if (empty($pages)){
|
|
|
+ $pages = 1;
|
|
|
+ }
|
|
|
+ $list = db('人员_基本资料')
|
|
|
+ ->field('
|
|
|
+ id,
|
|
|
+ staff_no as 员工编号,
|
|
|
+ staff_name as 员工姓名,
|
|
|
+ gender as 性别,
|
|
|
+ big_process as 生产工序,
|
|
|
+ dept_name as 所在部门,
|
|
|
+ status as 状态,
|
|
|
+ sys_rq as 创建日期,
|
|
|
+ pinyin as pinyin,
|
|
|
+ sys_id as 创建人员
|
|
|
+ ')
|
|
|
+ ->where($where)->page($pages)->limit($limit)->order('id desc')->whereNull('mod_rq')->select();
|
|
|
+ $total = db('人员_基本资料')->where($where)->whereNull('mod_rq')->count();
|
|
|
+ $data['list'] = $list;
|
|
|
+ $data['total'] = $total;
|
|
|
+ $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['id'])){
|
|
|
+ $where['id'] = $params['id'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 查询人员基础信息
|
|
|
+ $staffList = db('人员_基本资料')
|
|
|
+ ->field('
|
|
|
+ id,
|
|
|
+ staff_no as 员工编号,
|
|
|
+ staff_name as 员工姓名,
|
|
|
+ gender as 性别,
|
|
|
+ big_process as 生产工序,
|
|
|
+ dept_name as 所在部门,
|
|
|
+ status as 状态,
|
|
|
+ sys_rq as 创建日期,
|
|
|
+ sys_id as 创建人员
|
|
|
+ ')
|
|
|
+ ->where($where)
|
|
|
+ ->whereNull('mod_rq')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $this->success('获取员工资料', $staffList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增员工资料
|
|
|
+ */
|
|
|
+ public function PostStaffAdd(){
|
|
|
+ if (Request::instance()->isPost() == false){
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = Request::instance()->param();
|
|
|
+
|
|
|
+ $staff_no = $params['员工编号'] ?? '';
|
|
|
+ if(empty($staff_no)){
|
|
|
+ $this->error('员工编号不能为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询数据库是否已存在
|
|
|
+ $Find_list = Db::name('人员_基本资料')->where('staff_no', $staff_no)->whereNull('mod_rq')->find();
|
|
|
+ if($Find_list){
|
|
|
+ $this->error('员工编号已存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+ $data['staff_no'] = $params['员工编号'];
|
|
|
+ $data['staff_name'] = $params['员工姓名'];
|
|
|
+ $data['gender'] = $params['性别'];
|
|
|
+ $data['big_process'] = $params['生产工序'];
|
|
|
+ $data['dept_name'] = '生产部';
|
|
|
+ $data['status'] = 1;
|
|
|
+ $data['sys_rq'] = date('Y-m-d H:i:s');
|
|
|
+ $data['sys_id'] = $params['sys_id'];
|
|
|
+
|
|
|
+ $res = Db::name('人员_基本资料')->insert($data);
|
|
|
+
|
|
|
+ if ($res !== false){
|
|
|
+ $this->success('新增成功');
|
|
|
+ }else{
|
|
|
+ $this->error('新增失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改员工资料
|
|
|
+ * @ApiMethod POST
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function PostStaffEdit(){
|
|
|
+ if (!Request::instance()->isPost()){
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = Request::instance()->param();
|
|
|
+
|
|
|
+ //必传参数校验
|
|
|
+ if (empty($params['id'])){
|
|
|
+ $this->error('参数不能为空');
|
|
|
+ }
|
|
|
+ if (empty($params['员工编号'])){
|
|
|
+ $this->error('员工编号不能为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询员工是否存在(未删除)
|
|
|
+ $info = db('人员_基本资料')
|
|
|
+ ->where('id', $params['id'])
|
|
|
+ ->whereNull('mod_rq')
|
|
|
+ ->find();
|
|
|
+ if (!$info){
|
|
|
+ $this->error('员工不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ //员工编号重复判断(排除自身)
|
|
|
+ $exist = db('人员_基本资料')
|
|
|
+ ->where('staff_no', $params['员工编号'])
|
|
|
+ ->where('id', '<>', $params['id']) // 排除自己
|
|
|
+ ->whereNull('mod_rq')
|
|
|
+ ->find();
|
|
|
+ if ($exist) {
|
|
|
+ $this->error('员工编号已存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改数据
|
|
|
+ $data = [];
|
|
|
+ $data['staff_no'] = $params['员工编号'];
|
|
|
+ $data['staff_name'] = $params['员工姓名'];
|
|
|
+ $data['gender'] = $params['性别'];
|
|
|
+ $data['big_process'] = $params['生产工序'];
|
|
|
+ $data['dept_name'] = '生产部';
|
|
|
+ $data['updatetime'] = date('Y-m-d H:i:s');
|
|
|
+ $data['sys_id'] = $params['sys_id'];
|
|
|
+
|
|
|
+ $res = db('人员_基本资料')
|
|
|
+ ->where('id', $params['id'])
|
|
|
+ ->update($data);
|
|
|
+ if ($res !== false){
|
|
|
+ $this->success('更新成功');
|
|
|
+ }else{
|
|
|
+ $this->error('更新失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除员工资料
|
|
|
+ */
|
|
|
+ public function PostStaffDelete()
|
|
|
+ {
|
|
|
+ if (Request::instance()->isPost() == false){
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->param();
|
|
|
+ if (empty($params['id'])){
|
|
|
+ $this->error('参数不能为空');
|
|
|
+ }
|
|
|
+ $staffCode = $params['id'];
|
|
|
+ $sql = db('人员_基本资料')->where('id',$staffCode)->fetchSql(true)->update(['mod_rq'=>date('Y-m-d H:i:s')]);
|
|
|
+ $res = Db::query($sql);
|
|
|
+ if ($res !== false){
|
|
|
+ $this->success('删除成功');
|
|
|
+ }else{
|
|
|
+ $this->error('删除失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取小组
|
|
|
+ */
|
|
|
+ public function GetDeviceNameList(){
|
|
|
+ if (!Request::instance()->isGet()){
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 定义需要过滤、不返回给前端的设备编组
|
|
|
+ $filterGroups = [
|
|
|
+ '自动裁床01组',
|
|
|
+ '自动裁床02组',
|
|
|
+ '模板机01组',
|
|
|
+ '模板机02组',
|
|
|
+ '上袖机01组',
|
|
|
+ '上袖机02组',
|
|
|
+ '裁床1',
|
|
|
+ '裁床2',
|
|
|
+ '模版机'
|
|
|
+ ];
|
|
|
+
|
|
|
+ $list = Db::name('设备_基本资料')
|
|
|
+ ->field('UniqId,设备编组,生产工序,工序')
|
|
|
+ ->where('设备名称', 1)
|
|
|
+ ->whereNull('mod_rq')
|
|
|
+ ->whereNotIn('设备编组', $filterGroups) // 过滤不想要的数据
|
|
|
+ ->group('设备编组')
|
|
|
+ ->order('工序,UniqId asc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $this->success('获取设备编组成功', $list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取小组及人员列表
|
|
|
+ * 支持按工序/小组名称搜索,返回每个小组下的成员信息
|
|
|
+ */
|
|
|
+ public function GetTeamStaffList()
|
|
|
+ {
|
|
|
+ if (Request::instance()->isGet() == false) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+ $params = Request::instance()->param();
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if (!empty($params['search'])) {
|
|
|
+ $where['b.staff_no|b.staff_name|a.team_name|b.big_process'] = array('like', '%' . $params['search'] . '%');
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = Db::name('人员_小组资料')->alias('a')
|
|
|
+ ->field('
|
|
|
+ b.staff_no as 员工编号,
|
|
|
+ b.staff_name as 员工姓名,
|
|
|
+ a.*
|
|
|
+ ')
|
|
|
+ ->join('人员_基本资料 b', 'a.staff_no = b.staff_no')
|
|
|
+ ->where($where)
|
|
|
+ ->whereNull('a.mod_rq')
|
|
|
+ ->whereNull('b.mod_rq')
|
|
|
+ ->order('a.id asc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ // 整理成"小组+成员"的树形结构
|
|
|
+ $result = [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $teamId = $item['team_id'];
|
|
|
+ if (!isset($result[$teamId])) {
|
|
|
+ $result[$teamId] = [
|
|
|
+ '小组ID' => $teamId,
|
|
|
+ '小组名称' => $item['team_name'],
|
|
|
+ '生产工序' => $item['big_process'],
|
|
|
+ 'staff_list' => []
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $member = [
|
|
|
+ 'id' => $item['id'],
|
|
|
+ '员工编号' => $item['员工编号'],
|
|
|
+ '员工姓名' => $item['员工姓名'],
|
|
|
+ '小组名称' => $item['team_name'],
|
|
|
+ '职位' => $item['position']
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 组长排第一个
|
|
|
+ if ($item['position'] == '组长') {
|
|
|
+ array_unshift($result[$teamId]['staff_list'], $member);
|
|
|
+ } else {
|
|
|
+ $result[$teamId]['staff_list'][] = $member;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转为索引数组返回
|
|
|
+ $data = array_values($result);
|
|
|
+ $this->success('获取成功', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增小组人员
|
|
|
+ */
|
|
|
+ public function AddTeamStaff()
|
|
|
+ {
|
|
|
+ if (!Request::instance()->isPost()) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = Request::instance()->param();
|
|
|
+
|
|
|
+ // 1. 校验员工是否存在
|
|
|
+ $staffInfo = Db::name('人员_基本资料')
|
|
|
+ ->where('staff_no', $params['staff_no'])
|
|
|
+ ->whereNull('mod_rq')
|
|
|
+ ->find();
|
|
|
+ if (!$staffInfo) {
|
|
|
+ $this->error('员工不存在或已删除');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 校验该员工是否已在小组中
|
|
|
+ $exist = Db::name('人员_小组资料')
|
|
|
+ ->where('staff_no', $params['staff_no'])
|
|
|
+ ->whereNull('mod_rq')
|
|
|
+ ->find();
|
|
|
+ if ($exist) {
|
|
|
+ $this->error('该员工已在'.$exist['team_name'].'小组中');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 组装数据
|
|
|
+ $data = [
|
|
|
+ 'big_process' => $params['big_process'],
|
|
|
+ 'team_id' => $params['team_id'],
|
|
|
+ 'team_name' => $params['team_name'],
|
|
|
+ 'staff_no' => $params['staff_no'],
|
|
|
+ 'position' => $params['position'],
|
|
|
+ 'status' => 1,
|
|
|
+ 'sys_id' => $params['sys_id'],
|
|
|
+ 'createtime' => date('Y-m-d H:i:s')
|
|
|
+ ];
|
|
|
+
|
|
|
+ $res = Db::name('人员_小组资料')->insert($data);
|
|
|
+ if ($res) {
|
|
|
+ $this->success('新增成功');
|
|
|
+ } else {
|
|
|
+ $this->error('新增失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改小组人员
|
|
|
+ */
|
|
|
+ public function EditTeamStaff()
|
|
|
+ {
|
|
|
+ if (!Request::instance()->isPost()) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = Request::instance()->param();
|
|
|
+
|
|
|
+ // 必传参数校验
|
|
|
+ if (empty($params['id'])) {
|
|
|
+ $this->error('参数不完整');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 校验该记录是否存在
|
|
|
+ $info = Db::name('人员_小组资料')
|
|
|
+ ->where('id', $params['id'])
|
|
|
+ ->whereNull('mod_rq')
|
|
|
+ ->find();
|
|
|
+ if (!$info) {
|
|
|
+ $this->error('记录不存在或已删除');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 如果修改了员工ID,校验新员工是否已在该小组中(排除自身)
|
|
|
+ if (!empty($params['staff_id']) && $params['staff_id'] != $info['staff_id']) {
|
|
|
+ $exist = Db::name('人员_小组资料')
|
|
|
+ ->where('team_id', $params['team_id'] ?? $info['team_id'])
|
|
|
+ ->where('staff_id', $params['staff_id'])
|
|
|
+ ->where('id', '<>', $params['id'])
|
|
|
+ ->whereNull('mod_rq')
|
|
|
+ ->find();
|
|
|
+ if ($exist) {
|
|
|
+ $this->error('该员工已在此小组中');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 组装更新数据
|
|
|
+ $data = [];
|
|
|
+ if (isset($params['big_process'])) $data['big_process'] = $params['big_process'];
|
|
|
+ if (isset($params['team_id'])) $data['team_id'] = $params['team_id'];
|
|
|
+ if (isset($params['team_name'])) $data['team_name'] = $params['team_name'];
|
|
|
+ if (isset($params['position'])) $data['position'] = $params['position'];
|
|
|
+ if (isset($params['staff_id'])) {
|
|
|
+ $data['staff_id'] = $params['staff_id'];
|
|
|
+ // 更新员工姓名
|
|
|
+ $staffInfo = Db::name('人员_基本资料')->where('id', $params['staff_id'])->find();
|
|
|
+ if ($staffInfo) {
|
|
|
+ $data['staff_name'] = $staffInfo['staff_name'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isset($params['position'])) $data['position'] = $params['position'];
|
|
|
+ $data['updatetime'] = date('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ $res = Db::name('人员_小组资料')
|
|
|
+ ->where('id', $params['id'])
|
|
|
+ ->update($data);
|
|
|
+
|
|
|
+ if ($res !== false) {
|
|
|
+ $this->success('小组更换成功');
|
|
|
+ } else {
|
|
|
+ $this->error('小组更换失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除小组人员
|
|
|
+ */
|
|
|
+ public function DelTeamStaff()
|
|
|
+ {
|
|
|
+ if (!Request::instance()->isPost()) {
|
|
|
+ $this->error('非法请求');
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = Request::instance()->param();
|
|
|
+
|
|
|
+ $res = Db::name('人员_小组资料')
|
|
|
+ ->where('id', $params['id'])
|
|
|
+ ->update([
|
|
|
+ 'mod_rq' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($res !== false) {
|
|
|
+ $this->success('删除成功');
|
|
|
+ } else {
|
|
|
+ $this->error('删除失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|