token; $user = User::where([['id', '=', $token['uid']], ['root_id', '=', $token['root_org']]])->find(); if (empty($user->phone)) { $msg = '请授权手机号信息'; return false; } $employee_obj = (new Employee())->where([['uid', '=', $user->id], ['root_id', '=', $user->root_id], ['state', 'in', ['在职', '待审核']]])->findOrEmpty(); if (!$employee_obj->isEmpty()) { $msg = '已邀请,无需重复提交'; return false; } // 根据用户手机号同步员工信息 $employee_obj = (new Employee())->where(['phone' => cypherphone($user->phone), 'root_id' => $user->root_id])->order('id desc')->findOrEmpty(); $saveData = [ 'uid' => $user->id, 'root_id' => $user->root_id, 'org_id' => $data['orgid'], 'role' => $data['is_manager'] == 1 ? '领导' : '员工', 'is_manager' => $data['is_manager'], 'name' => $data['name'], 'state' => '待审核', 'verified' => 0, 'recruit' => $data['recruit'], 'initials' => strtoupper(substr(hanzi2pinyin($data['name']),0,1)) ]; if ($employee_obj->isEmpty()) { $saveData['name'] = $data['name']; $saveData['phone'] = $user->phone; } $employee_obj->save($saveData); return $employee_obj; } public static function employeelist4resource($orgid, $condition = [], $page = 1, $limit = 10) { $theorg = Org::find($orgid); $orgids = []; if (!empty($theorg)) { $orgids = Org::where([['path', 'like', $theorg->path . '%']])->column('id'); } $condition[] = ['org_id', 'in', $orgids]; $condition[] = ['state', '=', '在职']; $condition[] = ['uid', '<>', 0]; $list = Employee::where($condition)->with(['org', 'grant', 'user'])->order('org_id asc, is_manager desc')->page($page, $limit)->select()->toArray(); return $list; } public static function employeelistfront($orgid, $condition = [], $page = 1, $limit = 10, $state = '在职') { $theorg = Org::find($orgid); $orgids = []; if (!empty($theorg)) { $where = [['path', 'like', $theorg->path . '%']]; $orgids = Org::where($where)->column('id'); } $condition[] = ['org_id', 'in', $orgids]; //$condition[] = ['state', '<>', '离职']; $condition[] = ['uid', '<>', 0]; $list = Employee::where($condition)->with(['org', 'grant', 'user'])->order('org_id asc, is_manager desc')->page($page, $limit)->select(); $final_list = []; if (!empty($list)) { foreach ($list as $emp) { if ($state == '在职') { if ($emp->state == '在职' && $emp->verified == 1) { $final_list[] = $emp; } } if ($state == '待审核') { if ($emp->state == '待审核' && $emp->verified == 0) { if ($emp->org_id != $orgid) { $final_list[] = $emp; } if ($emp->org_id == $orgid && $emp->is_manager == 0) { $final_list[] = $emp; } } } } } return $final_list; } public static function employeelist($orgid, $condition = [], $page = 1, $limit = 10, $state = '在职') { $theorg = Org::find($orgid); $orgids = []; if (!empty($theorg)) { $o_where = $state == '在职' ? [['path', 'like', $theorg->path . '%']] : [['path', 'like', $theorg->path . '%'], ['path', '<>', $theorg->path]]; $orgids = Org::where($o_where)->column('id'); } $have_state = false; foreach ($condition as $k => $v) { if (isset($v[0]) && $v[0] == 'state'){ $have_state = true; } } $condition[] = ['org_id', 'in', $orgids]; $condition[] = ['uid', '<>', 0]; if (!$have_state){ $condition[] = ['state', '=', $state]; } $list = Employee::where($condition)->with(['org', 'grant', 'user'])->order('org_id asc, is_manager desc')->page($page, $limit)->select()->toArray(); return $list; } public static function count($orgid, $state = "在职", $keyword = 'null') { $request = request(); // $states = $request->controller()=='Employee'&&$state=='待审核' ? '在职' : $state; $states = app('http')->getName() != 'api' && $state == '待审核' ? '在职' : $state; if ($orgid) { $theorg = Org::find($orgid); $orgids = []; if (!empty($theorg)) { $o_where = $states == '在职' ? [['path', 'like', $theorg->path . '%']] : [['path', 'like', $theorg->path . '%'], ['path', '<>', $theorg->path]]; $orgids = Org::where($o_where)->column('id'); } if (!empty($keyword)) { $count = Employee::where([['org_id', 'in', $orgids], ['state', '=', $state], ['uid', '<>', 0], ['name', 'like', '%' . $keyword . '%']])->count(); } else { $count = Employee::where([['org_id', 'in', $orgids], ['state', '=', $state], ['uid', '<>', 0]])->count(); } } else { if (!empty($keyword)) { $count = Employee::where(['state' => ['eq', $state], 'name' => ['like', '%' . $keyword . '%']])->count(); } else { $count = Employee::where(['state' => ['eq', $state]])->count(); } } return $count; } public static function linkgrant($employeeid, $grantid) { return Employee::where('id', $employeeid)->update(['grant_id' => $grantid]); } public static function list($condition = [], $field = '*') { return Employee::where($condition)->field($field)->select(); } public static function getEmployee($openid) { // if ($openid == 'adminopenid') { // $employee = Employee::find(1); // } else { $currentUser = User::where('openid', $openid)->find(); if (!$currentUser) { return false; } $employee = Employee::where('uid', $currentUser->id)->find(); // } return $employee; } public static function delete($id) { $openid = session('openid', '', 'live'); $currentUser = User::where('openid', $openid)->find(); if (!$currentUser) { return false; } $employee = Employee::where('uid', $currentUser->id)->find(); if ($id == $employee->id) { return false; } else { return Employee::where(['id' => $id])->delete(); } } public static function getEmpInSameNode($handled_id) { $handled_emp = Employee::where('id', $handled_id)->find(); $theorg = Org::find($handled_emp->org_id); if ($theorg->pid == 0) { $parent_org = $theorg; } else { $parent_org = Org::find($theorg->pid); } $orgids = Org::where([['path', 'like', $parent_org->path . '%']])->column('id'); $target_emp_list = Employee::where([['org_id', 'in', $orgids], ['id', '<>', $handled_id], ['state', '=', '在职']])->column('id', 'name'); return $target_emp_list; } }