exec 导入导出方法

    //csv导入文件 在职人员 部分信息
    public function csvHumanList(){
        header("Content-Type:text/html; charset=utf-8");
        if (request()->isPost()) {
            $file = request()->file('csv'); 
            if (empty($file)) { 
              $this->error('请选择上传文件'); 
            } 
            //移动到框架应用根目录/public/uploads/ 目录下 
            $info = $file->move(ROOT_PATH . 'upload' . DS . 'Excel','excel'); 
            if ($info) { 
              // $this->success('文件上传成功'); 
              $name =  $info->getSaveName(); 
              $filename = 'upload/Excel/'.$name;
            } else { 
              //上传失败获取错误信息 
              $this->error($file->getError()); 
            } 
            $field = array(
                // '员工编号'=>'job_number', //不使用导入工号,直接生成工号
                '入职日期'=>'entry_time',
                '工龄'=>'working_years',
                '姓名'=>'name',
                '部门'=>'department',
                '科室/车间'=>'keshi',
                '职务/工种'=>'type_of_work',
                '联系电话'=>'phone',
                '身份证号'=>'id_number',
                '出生年月日'=>'birthday',
                '年龄'=>'age',
                '性别'=>'sex',
                '名族'=>'nation',
                '学历'=>'education',
                '籍贯省'=>'place_of_origin_province',
                '籍贯市'=>'place_of_origin_city',
                '籍贯区'=>'place_of_origin_district',
                '现住地址'=>'present_address',
                '紧急联系人'=>'landlord_or_landlady',
                '紧急联系人电话'=>'landlord_phone',
                '保险'=>'insurance',//个人信息 end
                '工作经历开始时间'=>'start_time_jl',
                '工作经历结束时间'=>'end_time_jl',
                '公司名称'=>'company_name_jl',
                '公司性质'=>'company_type_jl',
                // '职能'=>'function_jl',
                // '行业'=>'industry_jl',
                '公司部门'=>'department_jl',
                '公司职位'=>'position_jl',
                '职位描述'=>'describe_jl',//工作经历end
                '培训开始时间'=>'training_start_time',
                '培训结束时间'=>'training_end_time',
                '培训机构'=>'training_institution',
                '培训项目'=>'training_project',
                '培训地点'=>'training_address',
                '证书名称'=>'certificate_name',
                '详细描述'=>'detailed_description',//培训信息end
            );
            $res = readExcel($filename,$field);
            // dump($res);die;
            $msg_array = array();
            $member = new MemberService();
            $address = new Address();
            if(!empty($res)){
                @unlink($filename);
                foreach ($res as $key => $value) {
                    //验证身份证号码
                    if(isIdCard($value['id_number']) == false){
                        $msg_array['error'][] = array('name'=>$res[$key]['name'],'msg'=>'身份证格式错误');
                        continue;//跳过此次循环
                    }
                    //验证身份证号码和工号唯一性
                    $check = $this->human->checkUserInfo(['id_number'=>$value['id_number']]);
                    if($check){
                       $msg_array['error'][] = array('name'=>$res[$key]['name'],'msg'=>'身份证号码信息已经存在');
                        continue;//跳过此次循环
                    }
                    $res[$key]['job_number'] = $this->createJobNumber();
                    //性别
                    $res[$key]['sex'] = get_sex($value['id_number']); //1为男 2为女 
                    $res[$key]['birthday'] = get_birthday($value['id_number']);//从身份证上获取生日
                    $res[$key]['age'] = get_age($value['id_number']); //获取年龄
                    // $res[$key]['birthday'] = excelTime($value['birthday']);
                    $res[$key]['start_time_jl'] = excelTime($value['start_time_jl']);
                    $res[$key]['end_time_jl'] = excelTime($value['end_time_jl']);
                    $res[$key]['training_start_time'] = excelTime($value['training_start_time']);
                    $res[$key]['training_end_time'] = excelTime($value['training_end_time']);
                    $res[$key]['entry_time'] = excelTime($value['entry_time']);
                    $res[$key]['department'] = $this->human->getPositionId($value['department'],1);
                    $res[$key]['keshi'] = $this->human->getPositionId($value['keshi'],2);
                    $res[$key]['type_of_work'] = $this->human->getPositionId($value['type_of_work'],3);
                    $province = $address->getProvinceId($value['place_of_origin_province']);//籍贯省
                    if($province){
                        $res[$key]['place_of_origin_province'] = $province['province_id'];
                    }else{
                        $res[$key]['place_of_origin_province']=0;
                    }
                    $city = $address->getCityId($value['place_of_origin_city']);
                    if($city){
                        $res[$key]['place_of_origin_city'] = $city['city_id'];
                    }else{
                        $res[$key]['place_of_origin_city'] = 0;
                    }
                    $district = $address->getDistrictId($value['place_of_origin_district'])['district_id'];
                    if($district){
                        $res[$key]['place_of_origin_district'] = $district['district_id'];
                    }else{
                        $res[$key]['place_of_origin_district'] =0;
                    }
                    
                    switch ($value['education']) {
                        case '小学': $education = 1;break;
                        case '初中': $education = 2;break;
                        case '中专': $education = 3;break;
                        case '高中': $education = 4;break;
                        case '专科': $education = 5;break;
                        case '本科': $education = 6;break;
                        case '硕士': $education = 7;break;
                        case '博士': $education = 8;break;
                        default:
                            $education = 1;
                            break;
                    }
                    $res[$key]['education'] = $education;

                    $phoneinfo = $this->human->getPhoneInfo($res[$key]['phone']);//查看次手机号是否已经成为平台账户
                    if(!$phoneinfo){ //
                        //先添加到平台用户表  默认密码身份证后后六位
                        $password = substr($res[$key]['id_number'], -6);//身份证后六位
                        $member = new MemberService();
                        $retval = $member->addMember($res[$key]['phone'], $password, $res[$key]['email'], $res[$key]['sex'], 1, $res[$key]['phone'], 47,$this->instance_id,$res[$key]['id_number']);//人员账号(这里使用手机号),密码,邮箱,性别,状态(1ok,0锁定),手机号,会员级别id,公司实例id,身份证
                        
                        if(!$retval){
                            //注册前台账号失败
                            $msg_array['error'][] = array('name'=>$res[$key]['name'],'msg'=>'注册前台账号失败');
                            continue;//跳过此次循环
                        }$member = new MemberService();
                        $result = $member->updateNickNameByUid($retval, $res[$key]['name']);//修改昵称
                        $res[$key]['uid'] = $retval;
                    }else{
                        $res[$key]['uid'] = $phoneinfo['uid'];
                    }
                    
                    $res[$key]['is_job'] = 1;
                    $res[$key]['enterprise_id'] = $this->instance_id;
                    //用户简历信息 添加 ,$res[$key]['']
                    $this->human = new Human();
                    $res2 = $this->human->excelAddResume($res[$key]);
                   
                    if($res2 ==1){
                        $msg_array['success'][] = array('name'=>$res[$key]['name'],'msg'=>'导入成功');
                    }else{
                        $msg_array['error'][] = array('name'=>$res[$key]['name'],'msg'=>'导入个人信息失败');
                    }
                }
            }
            $this->assign('msg_array',$msg_array);
            return view($this->style . 'Human/csvHumanList');
           
        }
        // dump($msg_array);die;
        return view($this->style . 'Human/csvHumanList');
        
    }


//导出

    public function demissionDataExcel(){
        $xlsName  = "离职人员导出数据";
        $xlsCell  = array(
            array('uid','序号'),
            array('departure_date','申请离职日期'),
            array('leave_date','离职时间'),
            // array('uid','离职类型'),
            array('reasons_for_leaving','离职原因'),
            array('recruitment','是否招聘'),
            array('financial_borrowing','财务借款'),
            array('administrative_sanction','行政罚款'),
            array('clothing_deduction','工作服扣款'),
            array('work_surrender','工商退保'),
            array('retirement_surrender','养老退保'),
            array('is_back','是否返录'),
            array('end_of_job','离职状态'),
            array('job_number','员工编号'),
            array('entry_time','入职日期'),
            array('working_years','工龄'),
            array('name','姓名'),
            array('department','部门'),
            array('keshi','科室'),
            array('type_of_work','职务/工种'),
            array('phone','联系电话'),//
            array('id_number','身份证号码'),
            array('birthday','出生年月'),
            array('age','年龄'),
            array('sex','性别'),
            array('nation','名族'),
            array('education','学历'),
            array('place_of_origin_province','籍贯省'),
            array('place_of_origin_city','籍贯市'),
            array('place_of_origin_district','籍贯区'),
            array('permanent_address','联系地址'),//常住地址
            array('start_time_jl','工作经历开始时间'),
            array('end_time_jl','工作经历结束时间'),
            array('company_name_jl','公司名称'),
            array('company_type_jl','公司性质'),
            // array('function_jl','职能'),
            // array('industry_jl','行业'),
            array('department_jl','公司部门'),
            array('position_jl','公司职位'),
            array('describe_jl','职位描述'),//工作经历end
            array('training_start_time','培训开始时间'),
            array('training_end_time','培训结束时间'),
            array('training_institution','培训机构'),
            array('training_project','培训项目'),
            array('training_address','培训地点'),
            array('certificate_name','证书名称'),
            array('detailed_description','详细描述'),//培训信息end
        );

        $work = request()->get('work', 0);
        $work_level = request()->get('work_level', 0);
        $search_text = request()->get('search_text', '');
        $leave_date = request()->get('leave_date', '');
        $condition=array(
            'ru.job_number|ru.name' => array(
                    'like',
                    '%' . $search_text . '%'
                ),
        );
        if($leave_date){
            $condition['ru.leave_date'] = $leave_date;
        }
        $condition['is_job'] =0;//在职
        $condition['enterprise_id'] = $this->instance_id;//公司
        if($work >0){
            if($work_level == 1){
                $condition['ru.department']=$work;
            }elseif($work_level == 2){
                $condition['ru.keshi']=$work;
            }elseif($work_level == 3){
                $condition['ru.team']=$work;
            }elseif($work_level == 4){
                $condition['ru.type_of_work']=$work;
            }
        }
        $member = new RsUserInfoModel();
        // $list = $member->pageQuery(1, 0, $condition, 'entry_time desc',"*");
        $list = $member->getViewList(1, 0, $condition, 'ru.entry_time desc,rtr.add_time desc,rwe.add_time desc');
        $arr = $list['data'];
        $address = new Address();
        foreach ($arr as $k => $v) {
           $department = $this->human->getCompanyPositionInfo($v['department']);
            if($department){
                $arr[$k]['department'] = $department['position_name'];
            }else{
                $arr[$k]['department'] = '';
            }
            $keshi = $this->human->getCompanyPositionInfo($v['keshi']);
            if($keshi){
                $arr[$k]['keshi'] = $keshi['position_name'];
            }else{
                $arr[$k]['keshi']='';
            }
            if($v['type_of_work']==0 && $v['team'] >0){//工种为空 班组不为空,把班组放到工种位置上
                $type_of_work = $this->human->getCompanyPositionInfo($v['team']);//班组边工种
            }else{
                $type_of_work = $this->human->getCompanyPositionInfo($v['type_of_work']);//工种
            }
            if($type_of_work){
                $arr[$k]['type_of_work'] = $type_of_work['position_name'];
            }else{
                $arr[$k]['type_of_work'] = '';
            }
            if($v['sex'] == 1){
                $sex= '男';
            }else{
                $sex = '女';
            }
            $arr[$k]['sex'] =  $sex;
            if($v['is_back'] == 1){
                $is_back= '是';
            }else{
                $is_back = '否';
            }
            $arr[$k]['is_back'] =  $is_back;
            switch ($v['education']) {
                case '1': $education = '小学';break;
                case '2': $education = '初中';break;
                case '3': $education = '中专';break;
                case '4': $education = '高中';break;
                case '5': $education = '专科';break;
                case '6': $education = '本科';break;
                case '7': $education = '硕士';break;
                case '8': $education = '博士';break;
                default:
                    $education = '未知';
                    break;
            }
            $arr[$k]['education'] = $education;
            if($v['end_of_job'] == 1){
                $arr[$k]['end_of_job'] = '完结';
            }else{
                $arr[$k]['end_of_job'] = '未完结';
            }
            $province = $address->getProvinceName($v['place_of_origin_province']);
            if($province){
                $arr[$k]['place_of_origin_province'] = $province;//籍贯省
            }else{
                $arr[$k]['place_of_origin_province'] = '';
            }
            $city = $address->getCityName($v['place_of_origin_city']);
            if($city){
                $arr[$k]['place_of_origin_city'] = $city;
            }else{
                $arr[$k]['place_of_origin_city'] = '';
            }
            $district = $address->getDistrictName($v['place_of_origin_district']);
            if($district){
                $arr[$k]['place_of_origin_district'] = $district;
            }else{
                $arr[$k]['place_of_origin_district'] = '';
            }
            $describe = htmlspecialchars_decode($v['describe_jl']);//解析html代码
            $arr[$k]['describe_jl'] = str_replace("<br/>","\r",$describe);//br替换成换行符

            $detailed_description= htmlspecialchars_decode($v['detailed_description']);
            $arr[$k]['detailed_description'] =  str_replace("<br/>","\r",$detailed_description);
        }
        dataExcel($xlsName,$xlsCell,$arr);
    }

代码鱼社区资源论坛博客
请先登录后发表评论
  • latest comments
  • 总共0条评论