success('员工资料接口'); } /** * 获取部门列表 */ public function getDepartment(){ if (Request::instance()->isGet() == false){ $this->error('非法请求'); } // 1. 查询所有有效人员(按部门+工序分组) $list = db('人员_基本资料') ->field('dept_name as 所在部门, big_process as 生产工序, COUNT(*) AS count') ->whereNull('mod_rq') ->group('所在部门, 生产工序') ->order('id asc') ->select(); // 2. 构建 部门 → 工序 二级结构 $tree = []; foreach ($list as $item) { $dept = $item['所在部门']; $process = $item['生产工序']; $count = $item['count']; // 初始化部门 if (!isset($tree[$dept])) { $tree[$dept] = [ 'label' => $dept, 'count' => 0, 'children' => [] ]; } // 总数量累加 $tree[$dept]['count'] += $count; // 有生产工序 → 加入二级 if (!empty($process)) { $tree[$dept]['children'][] = [ 'label' => $process, 'count' => $count ]; } } $result = array_values($tree); $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'].'%'); } $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 性别, team_id, team_name as 所在小组, big_process as 生产工序, position as 职称职务, dept_name as 所在部门, status as 状态, sys_rq as 创建日期, sys_id as 创建人员 ') ->where($where)->page($pages)->limit($limit)->order('id asc')->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['a.id'] = $params['id']; } // 1. 查询人员基础信息 $staffList = db('人员_基本资料')->alias('a') ->where($where) ->whereNull('a.mod_rq') ->select(); $this->success('获取员工资料', $staffList); } /** * 新增员工资料 */ public function PostStaffAdd(){ if (Request::instance()->isPost() == false){ $this->error('非法请求'); } $params = Request::instance()->param(); echo "
";
        print_r($params);
        echo "
";die;
    }


    /**
     * 修改员工资料
     * @ApiMethod POST
     *
    */
    public function PostStaffEdit(){
        if (Request::instance()->isPost() == false){
            $this->error('非法请求');
        }
        $params = Request::instance()->param();
        if (empty($params['id'])){
            $this->error('参数不能为空');
        }
        $staffCode = $params['id'];
        $sql = db('人员_基本资料')->where('员工编号',$staffCode)->fetchSql(true)->whereNull('mod_rq')->update($params);
        $res = Db::query($sql);
        if ($res !== false){
            $this->success('更新成功');
        }else{
            $this->error('更新失败');
        }
    }

    /**
     * 删除员工资料
     */
    public function delete()
    {
        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() == false){
            $this->error('非法请求');
        }
        $list = Db::name('设备_基本资料')
            ->field('UniqId,设备编组,生产工序,工序')
            ->where('设备名称','1')
            ->whereNull('mod_rq')
            ->group('设备编组')
            ->order('工序,UniqId asc')
            ->select();
        $this->success('获取设备编组成功', $list);
    }
}