isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 //排序 $sortRow = input('sidx','u.id','trim'); //排序列 $sort = input('sord','desc','trim'); //排序方式 $order = $sortRow.' '.$sort; $title = input('title','','trim'); if($title){ $map[] = ['u.account|u.real_name|u.mobile','like','%'.$title.'%']; } $enable = input('enable','','trim'); if($enable != ''){ $map[] = ['u.enable','=',$enable]; } $depId = input('depId','','trim'); if($depId != ''){ // $map[] = ['ud.dep_id','=',$depId]; $uids = Db::name('user_dep')->where('dep_id',$depId)->column('user_id'); $map[] = ['u.id','in',$uids]; } $rolesId = input('rolesId','','trim'); if($rolesId != ''){ $userRolesId = Db::name('user_roles') ->where('roles_id',$rolesId) ->column('user_id'); $map[] = ['u.id','in',$userRolesId]; } $map[] = ['u.del','=',0]; $map[] = ['u.type','=',0]; $map[] = ['uo.org_id','=',$this->orgId]; $map= empty($map) ? true: $map; //数据查询 // $lists = db('user') // ->alias('u') // ->join('user_dep ud','u.id=ud.user_id') // ->join('user_roles ur','u.id=ur.user_id') // ->join('user_org uo','u.id=uo.user_id') // ->field('u.*,ud.dep_id,ur.roles_id,uo.org_id') // ->where($map) // ->limit($start,$length) // ->order(['u.sort'=>'asc','u.id'=>'desc']) // ->select(); // foreach ($lists as $k=>$v){ // $lists[$k]['dep_name'] = Db::name('dep')->where('id',$v['dep_id'])->value('title'); // $lists[$k]['roles_name'] = Db::name('roles')->where('id',$v['roles_id'])->value('name'); // } $mm = new \app\common\model\User(); $lists = db('user') ->alias('u') ->join('user_org uo','u.id=uo.user_id') ->where($map) ->field('u.*,uo.org_id') ->limit($start,$length) ->order(['u.sort'=>'asc','u.id'=>'desc']) ->select(); foreach ($lists as $k=>$v){ $lists[$k]['dep_name'] = Db::name('user_dep') ->alias('ud') ->join('dep d','d.id=ud.dep_id') ->where('ud.user_id',$v['id']) ->where('d.org_id',$v['org_id']) ->value('d.title'); $lists[$k]['roles_name'] = Db::name('user_roles') ->alias('ur') ->join('roles r','r.id=ur.roles_id') ->where('ur.user_id',$v['id']) ->where('r.org_id',$v['org_id']) ->value('r.name'); $lists[$k]['sex_name'] = isset($mm->sex[$v['sex']])?$mm->sex[$v['sex']]:""; } //数据返回 $totalCount = db('user') ->alias('u') ->join('user_org uo','u.id=uo.user_id') ->where($map) ->count(); $totalPage = ceil($totalCount/$length); $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $totalCount; $result['rows'] = $lists; return json($result); }else{ $deps = model('Dep')->getList(); $this->assign('deps',$deps); $roles = model('Roles')->getList(); $this->assign('roles',$roles); return $this->fetch(); } } public function wxlist(){ if(request()->isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 //排序 $sortRow = input('sidx','u.id','trim'); //排序列 $sort = input('sord','desc','trim'); //排序方式 $order = $sortRow.' '.$sort; $title = input('title','','trim'); if($title){ $map[] = ['u.account|u.real_name|u.mobile','like','%'.$title.'%']; } $enable = input('enable','','trim'); if($enable != ''){ $map[] = ['u.enable','=',$enable]; } $depId = input('depId','','trim'); if($depId != ''){ $map[] = ['ud.dep_id','=',$depId]; } $rolesId = input('rolesId','','trim'); if($rolesId != ''){ $map[] = ['ur.roles_id','=',$rolesId]; } $map[] = ['u.del','=',0]; $map[] = ['u.type','=',2]; $map[] = ['uo.org_id','=',$this->orgId]; $map= empty($map) ? true: $map; //数据查询 $lists = db('user') ->alias('u') ->join('user_dep ud','u.id=ud.user_id') ->join('user_roles ur','u.id=ur.user_id','left') ->join('user_org uo','u.id=uo.user_id') ->field('u.*,ud.dep_id,ur.roles_id,uo.org_id') ->where($map) ->limit($start,$length) ->order(['u.sort'=>'asc','u.id'=>'desc']) ->select(); foreach ($lists as $k=>$v){ $lists[$k]['dep_name'] = Db::name('dep')->where('id',$v['dep_id'])->value('title'); $lists[$k]['roles_name'] = Db::name('roles')->where('id',$v['roles_id'])->value('name'); } //数据返回 $totalCount = db('user') ->alias('u') ->join('user_dep ud','ud.user_id = u.id') ->join('user_roles ur','ur.user_id = u.id') ->join('user_org uo','uo.user_id = u.id') ->where($map)->count(); $totalPage = ceil($totalCount/$length); $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $totalCount; $result['rows'] = $lists; return json($result); }else{ $deps = model('Dep')->getList(); $this->assign('deps',$deps); $roles = model('Roles')->getList(); $this->assign('roles',$roles); return $this->fetch(); } } /** * 新增/编辑 */ public function add($id=0){ if(request()->isPost()){ $res = model('User')->addUser(); if($res){ $this->success('操作成功',url('index')); }else{ $this->error(model('User')->getError()); } }else{ if($id){ $info = db('user') ->alias('u') ->join('user_dep ud','ud.user_id = u.id','left') ->join('user_roles ur','ur.user_id = u.id','left') ->field('u.*,ud.dep_id,ur.roles_id') ->where('u.id',$id)->find(); $role = Db::name('roles') ->where('id',$info['roles_id']) ->find(); $info['is_bx'] = ($role['parent_id']==7 || $info['roles_id']==7)?1:0; $this->assign('info',$info); } $deps = model('Dep')->getList(); $this->assign('deps',$deps); $address = (new \app\common\model\Address())->getListByType(2); $roles = model('Roles')->getList(); $this->assign('roles',$roles); $this->assign('address',$address); $orderType =model('OrderType')->list(); $this->assign('orderType',$orderType); return $this->fetch(); } } /** * 新增/编辑 */ public function wxadd($id=0){ if(request()->isPost()){ $res = model('User')->wxaddUser(); if($res){ $this->success('操作成功',url('index')); }else{ $this->error(model('User')->getError()); } }else{ if($id){ $info = db('user') ->alias('u') ->join('user_dep ud','ud.user_id = u.id') ->join('user_roles ur','ur.user_id = u.id','left') ->field('u.*,ud.dep_id,ur.roles_id') ->where('u.id',$id)->find(); $this->assign('info',$info); } $deps = model('Dep')->getList(); $this->assign('deps',$deps); // $address = (new \app\common\model\Address())->getListByType(2); $roles = model('Roles')->getList(); $this->assign('roles',$roles); // $this->assign('address',$address); return $this->fetch(); } } /** * 新增/编辑 */ public function wxzadd($id=0){ if(request()->isPost()){ $res = model('User')->addUser(); if($res){ $this->success('操作成功',url('index')); }else{ $this->error(model('User')->getError()); } }else{ if($id){ $info = db('user') ->alias('u') ->join('user_dep ud','ud.user_id = u.id') ->join('user_roles ur','ur.user_id = u.id','left') ->field('u.*,ud.dep_id,ur.roles_id') ->where('u.id',$id)->find(); $this->assign('info',$info); } $deps = model('Dep')->getList(); $this->assign('deps',$deps); $address = (new \app\common\model\Address())->getListByType(2); $roles = model('Roles')->getList(); $this->assign('roles',$roles); $this->assign('address',$address); return $this->fetch(); } } /** * 删除记录 * @param int $id */ public function del($id=0){ if(!$id){ $this->error('参数错误'); } $res = db('user')->where('id',$id)->setField('del',1); if($res){ $this->success('删除成功'); }else{ $this->error('删除失败'); } } /** * 改变字段值 * @param int $fv * @param string $fn * @param int $fv */ public function changeField($id=0,$fn='',$fv=0){ if(!$fn||!$id){ $this->error('参数错误'); } $res = db('user')->where('id',$id)->setField($fn,$fv); if($res){ $this->success('操作成功'); }else{ $this->error('操作失败'); } } public function company(){ if(request()->isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 //排序 $sortRow = input('sidx','u.id','trim'); //排序列 $sort = input('sord','desc','trim'); //排序方式 $order = $sortRow.' '.$sort; $title = input('title','','trim'); if($title){ $map[] = ['u.account|u.real_name|u.mobile','like','%'.$title.'%']; } $enable = input('enable','','trim'); if($enable != ''){ $map[] = ['u.enable','=',$enable]; } $rolesId = input('rolesId','','trim'); if($rolesId != ''){ $map[] = ['ur.roles_id','=',$rolesId]; } $map[] = ['u.del','=',0]; $map[] = ['u.type','=',1]; $map= empty($map) ? true: $map; //数据查询 $lists = db('user') ->alias('u') ->join('user_roles ur','ur.user_id = u.id') ->field('u.*,ur.roles_id') ->where($map) ->limit($start,$length) ->order($order)->select(); foreach ($lists as $k=>$v){ $lists[$k]['roles_name'] = Db::name('roles')->where('id',$v['roles_id'])->value('name'); } //数据返回 $totalCount = db('user') ->alias('u') ->join('user_roles ur','ur.user_id = u.id') ->where($map)->count(); $totalPage = ceil($totalCount/$length); $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $totalCount; $result['rows'] = $lists; return json($result); }else{ $roles = model('Roles')->getCommonList(2); $this->assign('roles',$roles); $type = Db::name('user')->where('id',$this->userId)->value('type'); $this->assign('type',$type); return $this->fetch(); } } /** * 新增/编辑 */ public function addcompany($id=0){ if(request()->isPost()){ $res = model('User')->addCompany(); if($res){ $this->success('操作成功',url('index')); }else{ $this->error(model('User')->getError()); } }else{ if($id){ $info = db('user') ->alias('u') ->join('user_roles ur','ur.user_id = u.id') ->field('u.*,ur.roles_id') ->where('u.id',$id)->find(); if($info){ $orgs = $info['orgs']?explode(',',$info['orgs']):[]; $info['orgs'] = []; if($orgs){ $ids = []; foreach ($orgs as $k=>$v){ $t = $this->getAllLastId($v); //获取所有上级id 数组是倒序 array_unshift($t,(int)$v); //把组织插入数组的开头 $c = array_reverse($t); //数组反转 $ids[] = $c; } $info['orgs'] = $ids; } } $this->assign('info',$info); } $orgs = model('Org')->getAllOrgs(); $this->assign('orgs',$orgs); $tree = $this->orgTree(); $this->assign('orgs',$tree); $roles = model('Roles')->getCommonList(2); $this->assign('roles',$roles); return $this->fetch(); } } //获取所有上级id public function getAllLastId($id,$data=[]){ $pids = DB::name('org')->where('id',$id)->value('parent_id'); if($pids > 0){ $data[] = $pids; $data = $this->getAllLastId($pids,$data); } if(count($data)>0){ return $data; }else{ return []; } } public function orgTree(){ $lists = Db::name('org') ->field('id as value,name as label,parent_id') ->where('del',0) ->where('enable',1) ->order('sort asc,id asc') ->select(); if (empty($lists)) { return array(); } $tree = []; if($lists){ $tree = Phptree::makeTree(($lists), array( 'primary_key'=>'value', 'parent_key'=>'parent_id', 'expanded' => true )); } return $tree; } public function modifyPass(){ if(request()->isAjax()){ $data = [ 'oldpass' => input('oldpass','','trim'), 'pass' => input('pass','','trim'), 'pass_confirm' => input('pass_confirm','','trim'), 'id' => $this->userId ]; $ret = model('User')->modifyPass($data); if(!$ret){ $this->error(model('User')->getError()); } // 清除登录信息,重新登录 session('user_auth',null); session('user_auth_sign',null); $this->success('操作成功'); }else{ return $this->fetch(); } } /* * 考勤设置*/ public function set($id=0){ if(request()->isPost()){ $data = request()->post(); if(!$data['kq_name']){ $this->error('考勤姓名不能为空'); } if(!isset($data['kq_img']) && empty($data['kq_img'])){ $this->error('考勤图片不能为空'); } $uid = $data['id']; unset($data['id']); db('user')->where('id',$uid)->update($data); $this->success('操作成功',url('index')); }else{ if($id>0){ $info = db('user')->where('id',$id)->find(); $this->assign('info',$info); } } return $this->fetch(); } /* * 重置设备编号*/ public function reset($id=0){ if($id < 1){ $this->error('参数错误'); } db('user')->where('id',$id)->update(['device_sn'=>'']); $this->success('重置成功',url('index')); } /** * 排序 * @param int $id * @param int $sort */ public function changeSort($id=0,$sort=0){ if($id<0||$sort<0){ $this->error('参数错误'); } $res = db('user')->where('id',$id)->setField('sort',$sort); if($res){ $this->success('操作成功'); }else{ $this->error('操作失败'); } } public function batchSort(){ $data = input('data','','trim'); if(!$data){ $this->error('参数错误'); } $data = json_decode($data,true); if(!$data){ $this->error('参数错误'); } Db::startTrans(); try{ foreach ($data as $k=>$v){ Db::name('user')->where('id',$v['id'])->setField('sort',$v['sort']); } Db::commit(); }catch (Exception $e){ Db::rollback(); $this->error('操作失败'); } $this->success('操作成功'); } public function copyRoles(){ if(request()->isPost()){ $orgId = input('orgId',0); if($orgId < 1 ){ $this->error('请选择复制的项目'); } $rolesList = Db::name('roles') ->where('org_id',$orgId) ->where('enable',1) ->where('del',0) ->select(); foreach ($rolesList as $k=>$v){ $rolesInfo = Db::name('roles') ->where('org_id',$this->orgId) ->where('del',0) ->where('parent_id',$v['parent_id']) ->where('name',$v['name']) ->find(); if(!$rolesInfo){ $data = [ 'name'=>$v['name'], 'content'=>$v['content'], 'org_id'=>$this->orgId, 'parent_id'=>$v['parent_id'], 'work_type_mode'=>$v['work_type_mode'], 'type'=>$v['type'], 'auths'=>$v['auths'], 'appauths'=>$v['appauths'], 'level'=>$v['level'], ]; Db::name('roles')->insert($data); } } $this->success('操作成功',url('index')); }else{ $orgList = Db::name('org') ->where('del',0) ->where('type',2) ->select(); foreach ($orgList as $k=>$v){ $orgList[$k]['title'] = $v['name']; } $this->assign('orgList',$orgList); return $this->fetch(); } } public function workCard($id){ $info = Db::name('user')->where('id',$id)->find(); if (!$info) { exit('数据不存在'); } $info['dep'] = Db::name('user_dep') ->alias('ud') ->join('dep d','d.id = ud.dep_id') ->where('ud.user_id',$info['id']) ->where('d.del',0) ->value('d.title'); $orgName = Db::name('org')->where('id',$this->orgId)->value('name'); $code = get_qrcode_str('work_card', $id); $this->assign('code',$code); $this->assign('info',$info); $this->assign('orgName',$orgName); return $this->fetch(); } public function import(){ return $this->fetch(); } /** * 下载点模板 */ public function downloadtem(){ set_time_limit(0); ini_set("memory_limit","512M"); $header = [ ['title' => '账号', 'name' => 'account','width'=>'30'], ['title' => '姓名', 'name' => 'real_name','width'=>'30'], ['title' => '性别', 'name' => 'sex_name','width'=>'30'], ['title' => '手机号', 'name' => 'mobile','width'=>'30'], ['title' => '部门ID(默认0)', 'name' => 'depId','width'=>'30'], ['title' => '角色ID(默认0)', 'name' => 'rolesId','width'=>'30'], ]; $filename = '用户导入'; ExcelUtil::export($filename,$header,[]); } /** * 导入 */ public function importexcel_bak(){ set_time_limit(0); ini_set("memory_limit", -1); ob_flush();//清空缓存 flush();//刷新缓存 $orgId = $this->orgId; if(request()->file()) { $file = request()->file('file'); // 移动到框架应用根目录/uploads/ 目录下 $info = $file->validate([ 'size'=>50*1024*1024,'ext'=>'xls,xlsx' ]) ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'temp'); if(!$info){ exit('文件上传失败'); } $img = './uploads/temp/' . $info->getSaveName(); $filePath = str_replace('\\', '/', $img); $excelArray = ExcelUtil::read($filePath, ['id','real_name','mobile','dep','roles'] ); unset($excelArray[0]); if(empty($excelArray)){ exit('文件内容为空'); } $succ = []; foreach ($excelArray as $k => $v) { $v['account'] = $v['mobile']; if(!$v['real_name']){ echo "第".($k+1)."行,姓名为空,未导入
"; continue; } if(!$v['mobile']){ echo "第".($k+1)."行,手机号为空,未导入
"; continue; } $v['id'] = 0; $result = validate('User')->check($v, [], 'bachAdd'); if (true !== $result) { echo "第".($k+1)."行,".validate('User')->getError()."
"; continue; } $v['depId'] = 130; $rolesId = 145; // $rolesId = Db::name('roles') // ->where('name', $v['roles']) // ->where('org_id', $this->orgId) // ->value('id'); // if(empty($rolesId)){ // echo "第".($k+1)."行,角色不存在
"; // continue; // } $rData = [ 'account'=>$v['mobile'], 'real_name'=>$v['real_name'], 'mobile'=>$v['mobile'], 'ip'=>request()->ip(), 'password'=>password_hash('Aa123456', PASSWORD_DEFAULT), 'create_time'=>getTime() ]; $v['rolesId'] = $rolesId; $ret = Db::name('user')->insertGetId($rData); if($ret){ $succ[] = $ret; $ids = $ret; Db::name('user_org')->insert(['user_id' => $ids, 'org_id' => $this->orgId]); if(!empty($v['depId'])){ Db::name('user_dep')->insert(['user_id' => $ids, 'dep_id' => $v['depId']]); } if(!empty($v['rolesId'])){ Db::name('user_roles')->insert(['user_id' => $ids, 'roles_id' => $v['rolesId']]); } echo "第".($k+1)."行,导入成功
"; }else{ echo "第".($k+1)."行,导入失败
"; } } }else{ exit('请上传文件'); } } public function importexcel(){ set_time_limit(0); ini_set("memory_limit", -1); ob_flush();//清空缓存 flush();//刷新缓存 $orgId = $this->orgId; if(request()->file()) { $file = request()->file('file'); // 移动到框架应用根目录/uploads/ 目录下 $info = $file->validate([ 'size'=>50*1024*1024,'ext'=>'xls,xlsx' ]) ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'temp'); if(!$info){ exit('文件上传失败'); } $img = './uploads/temp/' . $info->getSaveName(); $filePath = str_replace('\\', '/', $img); $excelArray = ExcelUtil::read($filePath, ['account','real_name','sex_name','mobile','depId','rolesId'] ); if(empty($excelArray)){ exit('文件内容为空'); } $succ = []; $m = new \app\common\model\User(); foreach ($excelArray as $k => $v) { if(!$v['account']){ echo "第".($k+1)."行,账号为空,未导入
"; continue; } if(!$v['real_name']){ echo "第".($k+1)."行,姓名为空,未导入
"; continue; } if(!$v['mobile']){ echo "第".($k+1)."行,手机号为空,未导入
"; continue; } $v['id'] = 0; $result = validate('User')->check($v, [], 'bachAdd'); if (true !== $result) { echo "第".($k+1)."行,".validate('User')->getError()."
"; continue; } if(!empty($v['depId'])){ $checkDep = Db::name('dep') ->where('org_id',$this->orgId) ->where('id',$v['depId']) ->where('del',0) ->find(); if(!$checkDep){ echo "第".($k+1)."行,部门不存在
"; continue; } } if(!empty($v['rolesId'])){ $checkRoles = Db::name('roles') ->where('org_id',$this->orgId) ->where('id',$v['rolesId']) ->where('del',0) ->where('parent_id','>',0) ->find(); if(!$checkRoles){ echo "第".($k+1)."行,角色不存在
"; continue; } } $s = array_flip($m->sex); $sex = isset($s[$v['sex_name']])?$s[$v['sex_name']]:0; $rData = [ 'account'=>$v['account'], 'sex'=>$sex, 'real_name'=>$v['real_name'], 'mobile'=>$v['mobile'], 'ip'=>request()->ip(), 'password'=>password_hash('Aa123456', PASSWORD_DEFAULT), 'create_time'=>getTime() ]; $ret = Db::name('user')->insertGetId($rData); if($ret){ $succ[] = $ret; $ids = $ret; Db::name('user_org')->insert(['user_id' => $ids, 'org_id' => $this->orgId]); if(!empty($v['depId'])){ Db::name('user_dep')->insert(['user_id' => $ids, 'dep_id' => $v['depId']]); } if(!empty($v['rolesId'])){ Db::name('user_roles')->insert(['user_id' => $ids, 'roles_id' => $v['rolesId']]); } $rolesParentId = Db::name('roles') ->where('id', $v['rolesId']) ->value('parent_id'); if ($rolesParentId == 11) { Db::name('worker') ->where('user_id',$ids) ->delete(); $a = [ 'user_id' => $ids ]; Db::name('worker') ->insertGetId($a); } echo "第".($k+1)."行,导入成功
"; }else{ echo "第".($k+1)."行,导入失败
"; } } }else{ exit('请上传文件'); } } public function getRole(){ $id = input('id',''); $info = Db::name('roles') ->where('id',$id) ->find(); $data = [ 'show'=>($info['parent_id']==7 || $id==7)?1:0, ]; $this->success('操作成功','',$data); } public function importexcel1(){ set_time_limit(0); ini_set("memory_limit", -1); ob_flush();//清空缓存 flush();//刷新缓存 $orgId = $this->orgId; if(request()->file()) { $file = request()->file('file'); // 移动到框架应用根目录/uploads/ 目录下 $info = $file->validate([ 'size'=>50*1024*1024,'ext'=>'xls,xlsx' ]) ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'temp'); if(!$info){ exit('文件上传失败'); } $img = './uploads/temp/' . $info->getSaveName(); $filePath = str_replace('\\', '/', $img); $excelArray = ExcelUtil::read($filePath, ['','real_name','account','dep','roles'] ); if(empty($excelArray)){ exit('文件内容为空'); } $succ = []; foreach ($excelArray as $k => $v) { if($k < 1){ continue; } if(!$v['account']){ echo "第".($k+1)."行,账号为空,未导入
"; continue; } if(!$v['real_name']){ echo "第".($k+1)."行,姓名为空,未导入
"; continue; } if(!$v['dep']){ echo "第".($k+1)."行,部门为空,未导入
"; continue; } $depId = Db::name('dep') ->where('org_id',$this->orgId) ->where('title',$v['dep']) ->where('del',0) ->value('id'); if($depId < 1){ $depId = Db::name('dep') ->insertGetId([ 'title'=>$v['dep'], 'org_id'=>$orgId, 'del'=>0, 'sort'=>50, 'create_time'=>date('Y-m-d H:i:s') ]); } if(!$v['roles']){ echo "第".($k+1)."行,角色为空,未导入
"; continue; } $rPid = 0; //父级角色id $gl = ['']; //管理 $zh = ['项目经理','项目副经理','经理','文员','公共事务主管','主任','电梯主管','班长','后勤主任','后勤干事','后勤主管','项目副经理/文员','电梯导乘','送检工','保障处助理','主管','总务科科长','分管物业,工会主席','科长','副科长','院长','客服','院方后勤主任','服务中心副经理','领班','项目主管','环境服务主管','服务中心经理','配送主管','公共事务主管兼文员','司梯主管','电梯礼仪','项目总经理','综合部主管','仓管','医辅部主管','护理主任']; //综合 pid=4 $bj = ['保洁主管','保洁班长','保洁工','保洁员','外围保洁员','医废垃圾清运员','生活垃圾清运员','医废站管理员','专项保洁员','五院保洁']; // pid=8 $wx = ['维修主管','维修工','院方后勤维修工','电工','水暖工','经理,维修工','工程维修员']; // pid=7 $kh = ['']; // 客户 pid=3 $ys = ['运送主管','运送班长','垃圾运送','配送','夜班配送']; //运送 pid=6 if(in_array($v['roles'],$zh)){ $rPid = 4; } if(in_array($v['roles'],$bj)){ $rPid = 8; } if(in_array($v['roles'],$wx)){ $rPid = 7; } if(in_array($v['roles'],$ys)){ $rPid = 6; } // if($v['dep'] == '保洁部' && !in_array($v['roles'],$zh)){ // $rPid = 8; // $v['roles'] = '保洁'; // } // if($v['dep'] == '运送部' && !in_array($v['roles'],$ys)){ // $rPid = 6; // $v['roles'] = '运送'; // } // // if($v['dep'] == '导梯部' && !in_array($v['roles'],$zh)){ // $rPid = 4; // $v['roles'] = '综合'; // } $rolesId = Db::name('roles') ->where('org_id',$this->orgId) ->where('name',$v['roles']) ->where('del',0) ->where('parent_id',$rPid) ->value('id'); if(!$rolesId){ $rolesId = Db::name('roles') ->insertGetId([ 'name'=>$v['roles'], 'org_id'=>$orgId, 'parent_id'=>$rPid, 'type'=>1, 'del'=>0, 'sort'=>0, ]); } $mobile = strlen($v['account']) == 11 ?$v['account']:''; $rData = [ 'account'=>$v['account'], 'real_name'=>$v['real_name'], 'mobile'=>$mobile, 'ip'=>request()->ip(), 'password'=>password_hash('123456', PASSWORD_DEFAULT), 'create_time'=>getTime() ]; $ret = Db::name('user')->insertGetId($rData); if($ret){ $succ[] = $ret; $ids = $ret; Db::name('user_org')->insert(['user_id' => $ids, 'org_id' => $this->orgId]); if(!empty($depId)){ Db::name('user_dep')->insert(['user_id' => $ids, 'dep_id' => $depId]); } if(!empty($rolesId)){ Db::name('user_roles')->insert(['user_id' => $ids, 'roles_id' => $rolesId]); } // $rolesParentId = Db::name('roles') // ->where('id', $v['rolesId']) // ->value('parent_id'); // if ($rolesParentId == 11) { // Db::name('worker') // ->where('user_id',$ids) // ->delete(); // $a = [ // 'user_id' => $ids // ]; // Db::name('worker') // ->insertGetId($a); // } // echo "第".($k+1)."行,导入成功
"; }else{ echo "第".($k+1)."行,导入失败
"; } } }else{ exit('请上传文件'); } } //464 public function delDepUser(){ $userIds = Db::name('user') ->alias('u') ->join('user_dep ud','ud.user_id=u.id') ->where('ud.dep_id',464) ->where('u.del',0) ->where('u.enable',1) ->column('u.id'); $ret = Db::name('user')->where('id','in',$userIds)->setField('del',1); echo $ret; } public function delOrgUser(){ $userIds = Db::name('user') ->alias('u') ->join('user_org uo','uo.user_id=u.id') ->where('uo.org_id',85) ->where('u.del',0) ->column('u.id'); $ret = Db::name('user')->where('id','in',$userIds)->setField('del',1); echo $ret; } public function saveUserPassWord(){ $p = 'Md123456'; $pw = password_hash($p, PASSWORD_DEFAULT); // $user = Db::name('user') // ->where('del',0) // ->update(['password'=>$pw]); // // echo $user; } }