123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- <?php
- namespace app\manage\controller;
- use think\Controller;
- use think\Db;
- use think\Session;
- use think\Config;
- use think\Cookie;
- use think\Request;
- use app\common\library\SysLogs;
- use app\common\library\UUIDs;
- class Doctors extends Base {
- public function index() {
- return $this->fetch();
- }
- public function datas() {
- $request = Request::instance()->param();
- $username = isset($request["username"]) ? $request["username"] : null;
- $status = isset($request["status"]) ? $request["status"] : null;
- $institution_id = isset($request["insId"]) ? $request["insId"] : null;
- $whereArr = array();
- if (!empty($username)) {
- $whereArr["username"] = array("like", $username . "%");
- }
- if ($status != null) {
- $whereArr["status"] = $status;
- }
- if (!empty($institution_id)) {
- $whereArr["institution_id"] = $institution_id;
- }
- $page = empty($_GET["page"]) ? 1 : $_GET["page"];
- $pagesize = empty($_GET["rows"]) ? 1 : $_GET["rows"];
- if (empty($page) || $page < 1) {
- $page = 1;
- }
- if (empty($pagesize) || $pagesize < 1) {
- $pagesize = 30;
- }
- $info = DB::table('doctors')->where($whereArr)->page($page, $pagesize)->select();
- foreach ($info as $k => $v) {
- $iname = DB::table('institution')->where('id', $v['institution_id'])->field('name')->find();
- $info[$k]['institution_name'] = $iname['name'];
- $dname = DB::table('department')->where('id', $v['department_id'])->field('department_name')->find();
- $info[$k]['department_name'] = $dname['department_name'];
- }
- $num = DB::table('doctors')->where($whereArr)->count();
- $data = array();
- $data['total'] = $num;
- $data['rows'] = $info;
- echo json_encode($data);
- }
- /**
- * 编辑窗口
- * @return type
- */
- public function edit() {
- $doctors = null;
- if (isset($_GET["id"])) {
- $id = $_GET["id"];
- if ($id != null) {
- $doctors = Db::table("doctors")->where("id", $id)->find();
- if (count($doctors) > 0) {
- if (empty($doctors['doctor_role'])) {
- $doctors['doctor_role'] = array();
- } else {
- $doctors['doctor_role'] = explode(',', $doctors['doctor_role']);
- }
- $this->assign("doctors", $doctors);
- // 查询医生的分类
- $doctorsCla = Db::table("doctor_class")->where("doctor_id", $id)->find();
- if (!empty($doctorsCla)) {
- $doctorClaStr = $doctorsCla["doctor_class"];
- if (!empty($doctorClaStr)) {
- $dc_arr = explode(",", $doctorClaStr);
- $this->assign("doctorcla", $dc_arr);
- }
- }
- }
- }
- }
- $doctorClas = Db::table("constant")->where("parent_id", "doctor_class")->order("ordernum", "1")->select();
- $this->assign('doctorclas', $doctorClas);
- $institution = DB::table('institution')->select();
- $this->assign('institution', $institution);
- $depWheres = array();
- if ($doctors != null) {
- $depWheres["institution_id"] = $doctors["institution_id"];
- }
- $department = DB::table('department')->where($depWheres)->select();
- $this->assign('department', $department);
- return $this->fetch('edit');
- }
- public function save() {
- $request = Request::instance();
- $params = $request->param();
- if (!isset($params["doctorcla"])) {
- echo "fail:doctorcla";
- return;
- }
- $doctorcla = $params["doctorcla"];
- unset($params["doctorcla"]);
- $params['doctor_role'] = implode(',', $params['doctor_role']);
- $password = $params['password'];
- if (!empty($password) && strlen($password) < 30) {
- $params['password'] = md5($password);
- } else {
- unset($params['password']);
- }
- if (empty($params['id'])) {
- unset($params['id']);
- $id = UUIDs::uuid16();
- $params['id'] = $id;
- $a = DB::table('doctors')->insert($params);
- if (isset($params["department_id"])) {
- $this->saveDoctorCla($id, $doctorcla, $params["department_id"]);
- SysLogs::log("doctors", "C", json_encode($params));
- }
- return 'insert_ok;' . $id;
- } else {
- $a = DB::table('doctors')->where('id', $params['id'])->update($params);
- if (isset($params["department_id"])) {
- $this->saveDoctorCla($params["id"], $doctorcla, $params["department_id"]);
- }
- SysLogs::log("doctors", "U", $params['id'] . " --> " . json_encode($params));
- return 'success';
- }
- }
- protected function saveDoctorCla($doctor_id, $doctorcla, $depid) {
- // doctorcla
- Db::table("doctor_class")->where("doctor_id", $doctor_id)->delete();
- if (isset($doctorcla) && count($doctorcla) > 0) {
- $newrow = array();
- $newrow["id"] = UUIDs::uuid16();
- $newrow["doctor_id"] = $doctor_id;
- $newrow["department_id"] = $depid;
- $doctorclaStr = json_encode($doctorcla);
- $doctorclaStr = str_replace('"', '', $doctorclaStr);
- $doctorclaStr = str_replace('[', '', $doctorclaStr);
- $doctorclaStr = str_replace(']', '', $doctorclaStr);
- $doctorclaStr = str_replace(" ", "", $doctorclaStr);
- $newrow["doctor_class"] = $doctorclaStr;
- $newrow["status"] = "1";
- Db::table("doctor_class")->insert($newrow);
- SysLogs::log("doctors", "C", $doctor_id . " doctorclass --> " . $doctorclaStr);
- }
- }
- /**
- * 软删除记录
- */
- public function delete() {
- if (isset($_GET["ids"])) {
- $ids = $_GET["ids"];
- if (!empty($ids)) {
- $idArr = explode(",", $ids);
- if (count($idArr) > 0) {
- Db::table("doctors")->where("id", "in", $idArr)->update(['status' => 1]);
- SysLogs::log("doctors", "U", $ids . " status 修改为 1 ");
- }
- echo "delete_ok";
- return;
- }
- }
- echo "fail";
- }
- /**
- * 显示权限编辑窗口
- * @return type
- */
- public function permissions() {
- $id = is_string($_GET["id"]) ? $_GET["id"] : null;
- if ($id != null) {
- // 得到医生信息
- $doctor = Db::table("doctors")->where("id", $id)->find();
- if (empty($doctor)) {
- echo "no doctor !";
- return;
- }
- $this->assign("doctor", $doctor);
- $this->assign("id", $id);
- }
- // 查找已有权限(菜单)
- $permitsMenus = Db::table("dr_cla_permission")->where("doctor_id", $id)->where("type", "1")->select();
- $permitMenuIdArr = array();
- if (count($permitsMenus) > 0) {
- foreach ($permitsMenus as $key => $val) {
- array_push($permitMenuIdArr, $val["pass"]);
- }
- $this->assign("permitMenuIdArr", json_encode($permitMenuIdArr));
- }
- // 查找已有权限(写报告)
- $permitsReport = Db::table("dr_cla_permission")->where("doctor_id", $id)->where("type", "2")->find();
- if (!empty($permitsReport)) {
- $this->assign("permitReport", $permitsReport["pass"]);
- } else {
- $this->assign("permitReport", "0");
- }
- return $this->fetch("permissions");
- }
- /**
- * 保存菜单权限
- */
- public function saveMenuPermit() {
- $doctorId = empty($_GET["id"]) ? null : $_GET["id"];
- $menuIds = empty($_GET["ids"]) ? null : $_GET["ids"];
- if (empty($doctorId) || empty($menuIds)) {
- echo "fail, empty doctorId or menuId";
- return;
- }
- $menuIdArr = explode(",", $menuIds);
- $menus = Db::table("menu")->whereIn("id", $menuIdArr)->select();
- if (count($menus) < 1) {
- // 没有找到菜单
- echo "fail, no menu found ";
- return;
- } else {
- // 给用户赋值
- // 查看是否已经有了权限
- $menuIdArr = array();
- foreach ($menus as $key => $val) {
- array_push($menuIdArr, $val["id"]);
- }
- // 将已有权限全部清空
- Db::table("dr_cla_permission")->where("doctor_id", $doctorId)->where("type", "1")->delete();
- SysLogs::log("dr_cla_permission", "D", "where (doctor_id = " . $doctorId . "type = 1) delete ");
- // 如果没有,添加
- foreach ($menuIdArr as $key => $val) {
- $newRow = array();
- $newRow["id"] = UUIDs::uuid16();
- $newRow["type"] = "1";
- $newRow["pass"] = $val;
- $newRow["doctor_id"] = $doctorId;
- Db::table("dr_cla_permission")->insert($newRow);
- SysLogs::log("dr_cla_permission", "C", json_encode($newRow));
- }
- }
- echo "ok";
- }
- /**
- * 保存报告权限
- */
- public function saveReportPermit() {
- $doctorId = isset($_GET["id"]) ? $_GET["id"] : null;
- $permitReport = isset($_GET["report"]) ? $_GET["report"] : null;
- if ($doctorId == null || $permitReport == null) {
- echo "fail";
- return;
- }
- $permitData = Db::table("dr_cla_permission")->where("doctor_id", $doctorId)->where("type", "2")->find();
- if (!empty($permitData)) {
- // 如果已经有报告权限的配置,
- // 只更新就好
- $permitData["pass"] = $permitReport;
- Db::table("dr_cla_permission")->update($permitData);
- SysLogs::log("dr_cla_permission", "U", json_encode($permitData));
- } else {
- // 新建权限记录
- $newRow = array();
- $newRow["id"] = UUIDs::uuid16();
- $newRow["doctor_id"] = $doctorId;
- $newRow["type"] = "2";
- $newRow["pass"] = $permitReport;
- Db::table("dr_cla_permission")->insert($newRow);
- SysLogs::log("dr_cla_permission", "C", json_encode($newRow));
- }
- echo "ok";
- }
- /**
- * 查询全部菜单
- */
- public function menudata() {
- $rootMenuData = array();
- // 准备根节点
- $rootMenuData["id"] = "root";
- $rootMenuData["pId"] = "0";
- $rootMenuData["name"] = "菜单(根节点)";
- $rootMenuData["url"] = "";
- $rootMenuData["open"] = "true";
- // 查询全部数据
- $menuData = $info = DB::table('menu')->select();
- $jsonarray = array();
- if ($menuData != null) {
- foreach ($menuData as $k => $val) {
- $parent_id = $val["parent_id"];
- unset($val["parent_id"]);
- // 处理parent_id为pId,为前端菜单上下级关系展示处理
- $val['pId'] = $parent_id;
- $val['open '] = "true";
- array_push($jsonarray, $val);
- }
- }
- // 将根节点添加到树
- array_unshift($jsonarray, $rootMenuData);
- // 返回JSON数据
- echo json_encode($jsonarray);
- }
- public function import(){
- include_once LIB_ROOT_PATH."3rdParty/phpexcel/PHPExcel.php";
- $objReader = PHPExcel_IOFactory::createReader('Excel2007');
- $objPHPExcel = $objReader->load($file_name,$encode='utf-8');
- $sheet = $objPHPExcel->getSheet(0);
- $highestRow = $sheet->getHighestRow();//取得总行数
- $highestColumn = $sheet->getHighestColumn();//取得总列数
- $data = array();
- for($i=2;$i<=$highestRow;$i++){
- for($j='A';$j<=$highestColumn;$j++){
- $data[$i][] = $objPHPExcel->getActiveSheet()->getCell("$j$i")->getValue();
- }
- }
- var_dump($data);
- var_dump($_FILES);die;
- if (!empty($_FILES)) {
- import("@.ORG.UploadFile");
- $config=array(
- 'allowExts'=>array('xlsx','xls'),
- 'savePath'=>'./Public/upload/',
- 'saveRule'=>'time',
- );
- $upload = new UploadFile($config);
- if (!$upload->upload()) {
- $this->error($upload->getErrorMsg());
- } else {
- $info = $upload->getUploadFileInfo();
- }
- vendor("PHPExcel.PHPExcel");
- $file_name=$info[0]['savepath'].$info[0]['savename'];
- $objReader = PHPExcel_IOFactory::createReader('Excel5');
- $objPHPExcel = $objReader->load($file_name,$encode='utf-8');
- $sheet = $objPHPExcel->getSheet(0);
- $highestRow = $sheet->getHighestRow(); // 取得总行数
- $highestColumn = $sheet->getHighestColumn(); // 取得总列数
- for($i=3;$i<=$highestRow;$i++)
- {
- $data['account']= $data['truename'] = $objPHPExcel->getActiveSheet()->getCell("B".$i)->getValue();
- $sex = $objPHPExcel->getActiveSheet()->getCell("C".$i)->getValue();
- // $data['res_id'] = $objPHPExcel->getActiveSheet()->getCell("D".$i)->getValue();
- $data['class'] = $objPHPExcel->getActiveSheet()->getCell("E".$i)->getValue();
- $data['year'] = $objPHPExcel->getActiveSheet()->getCell("F".$i)->getValue();
- $data['city']= $objPHPExcel->getActiveSheet()->getCell("G".$i)->getValue();
- $data['company']= $objPHPExcel->getActiveSheet()->getCell("H".$i)->getValue();
- $data['zhicheng']= $objPHPExcel->getActiveSheet()->getCell("I".$i)->getValue();
- $data['zhiwu']= $objPHPExcel->getActiveSheet()->getCell("J".$i)->getValue();
- $data['jibie']= $objPHPExcel->getActiveSheet()->getCell("K".$i)->getValue();
- $data['honor']= $objPHPExcel->getActiveSheet()->getCell("L".$i)->getValue();
- $data['tel']= $objPHPExcel->getActiveSheet()->getCell("M".$i)->getValue();
- $data['qq']= $objPHPExcel->getActiveSheet()->getCell("N".$i)->getValue();
- $data['email']= $objPHPExcel->getActiveSheet()->getCell("O".$i)->getValue();
- $data['remark']= $objPHPExcel->getActiveSheet()->getCell("P".$i)->getValue();
- $data['sex']=$sex=='男'?1:0;
- $data['res_id'] =1;
- $data['last_login_time']=0;
- $data['create_time']=$data['last_login_ip']=$_SERVER['REMOTE_ADDR'];
- $data['login_count']=0;
- $data['join']=0;
- $data['avatar']='';
- $data['password']=md5('123456');
- M('Member')->add($data);
- }
- $this->success('导入成功!');
- }else
- {
- $this->error("请选择上传的文件");
- }
- }
- }
|