Doctors.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <?php
  2. namespace app\manage\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use think\Session;
  6. use think\Config;
  7. use think\Cookie;
  8. use think\Request;
  9. use app\common\library\SysLogs;
  10. use app\common\library\UUIDs;
  11. class Doctors extends Base {
  12. public function index() {
  13. return $this->fetch();
  14. }
  15. public function datas() {
  16. $request = Request::instance()->param();
  17. $username = isset($request["username"]) ? $request["username"] : null;
  18. $status = isset($request["status"]) ? $request["status"] : null;
  19. $institution_id = isset($request["insId"]) ? $request["insId"] : null;
  20. $whereArr = array();
  21. if (!empty($username)) {
  22. $whereArr["username"] = array("like", $username . "%");
  23. }
  24. if ($status != null) {
  25. $whereArr["status"] = $status;
  26. }
  27. if (!empty($institution_id)) {
  28. $whereArr["institution_id"] = $institution_id;
  29. }
  30. $page = empty($_GET["page"]) ? 1 : $_GET["page"];
  31. $pagesize = empty($_GET["rows"]) ? 1 : $_GET["rows"];
  32. if (empty($page) || $page < 1) {
  33. $page = 1;
  34. }
  35. if (empty($pagesize) || $pagesize < 1) {
  36. $pagesize = 30;
  37. }
  38. $info = DB::table('doctors')->where($whereArr)->page($page, $pagesize)->select();
  39. foreach ($info as $k => $v) {
  40. $iname = DB::table('institution')->where('id', $v['institution_id'])->field('name')->find();
  41. $info[$k]['institution_name'] = $iname['name'];
  42. $dname = DB::table('department')->where('id', $v['department_id'])->field('department_name')->find();
  43. $info[$k]['department_name'] = $dname['department_name'];
  44. }
  45. $num = DB::table('doctors')->where($whereArr)->count();
  46. $data = array();
  47. $data['total'] = $num;
  48. $data['rows'] = $info;
  49. echo json_encode($data);
  50. }
  51. /**
  52. * 编辑窗口
  53. * @return type
  54. */
  55. public function edit() {
  56. $doctors = null;
  57. if (isset($_GET["id"])) {
  58. $id = $_GET["id"];
  59. if ($id != null) {
  60. $doctors = Db::table("doctors")->where("id", $id)->find();
  61. if (count($doctors) > 0) {
  62. if (empty($doctors['doctor_role'])) {
  63. $doctors['doctor_role'] = array();
  64. } else {
  65. $doctors['doctor_role'] = explode(',', $doctors['doctor_role']);
  66. }
  67. $this->assign("doctors", $doctors);
  68. // 查询医生的分类
  69. $doctorsCla = Db::table("doctor_class")->where("doctor_id", $id)->find();
  70. if (!empty($doctorsCla)) {
  71. $doctorClaStr = $doctorsCla["doctor_class"];
  72. if (!empty($doctorClaStr)) {
  73. $dc_arr = explode(",", $doctorClaStr);
  74. $this->assign("doctorcla", $dc_arr);
  75. }
  76. }
  77. }
  78. }
  79. }
  80. $doctorClas = Db::table("constant")->where("parent_id", "doctor_class")->order("ordernum", "1")->select();
  81. $this->assign('doctorclas', $doctorClas);
  82. $institution = DB::table('institution')->select();
  83. $this->assign('institution', $institution);
  84. $depWheres = array();
  85. if ($doctors != null) {
  86. $depWheres["institution_id"] = $doctors["institution_id"];
  87. }
  88. $department = DB::table('department')->where($depWheres)->select();
  89. $this->assign('department', $department);
  90. return $this->fetch('edit');
  91. }
  92. public function save() {
  93. $request = Request::instance();
  94. $params = $request->param();
  95. if (!isset($params["doctorcla"])) {
  96. echo "fail:doctorcla";
  97. return;
  98. }
  99. $doctorcla = $params["doctorcla"];
  100. unset($params["doctorcla"]);
  101. $params['doctor_role'] = implode(',', $params['doctor_role']);
  102. $password = $params['password'];
  103. if (!empty($password) && strlen($password) < 30) {
  104. $params['password'] = md5($password);
  105. } else {
  106. unset($params['password']);
  107. }
  108. if (empty($params['id'])) {
  109. unset($params['id']);
  110. $id = UUIDs::uuid16();
  111. $params['id'] = $id;
  112. $a = DB::table('doctors')->insert($params);
  113. if (isset($params["department_id"])) {
  114. $this->saveDoctorCla($id, $doctorcla, $params["department_id"]);
  115. SysLogs::log("doctors", "C", json_encode($params));
  116. }
  117. return 'insert_ok;' . $id;
  118. } else {
  119. $a = DB::table('doctors')->where('id', $params['id'])->update($params);
  120. if (isset($params["department_id"])) {
  121. $this->saveDoctorCla($params["id"], $doctorcla, $params["department_id"]);
  122. }
  123. SysLogs::log("doctors", "U", $params['id'] . " --> " . json_encode($params));
  124. return 'success';
  125. }
  126. }
  127. protected function saveDoctorCla($doctor_id, $doctorcla, $depid) {
  128. // doctorcla
  129. Db::table("doctor_class")->where("doctor_id", $doctor_id)->delete();
  130. if (isset($doctorcla) && count($doctorcla) > 0) {
  131. $newrow = array();
  132. $newrow["id"] = UUIDs::uuid16();
  133. $newrow["doctor_id"] = $doctor_id;
  134. $newrow["department_id"] = $depid;
  135. $doctorclaStr = json_encode($doctorcla);
  136. $doctorclaStr = str_replace('"', '', $doctorclaStr);
  137. $doctorclaStr = str_replace('[', '', $doctorclaStr);
  138. $doctorclaStr = str_replace(']', '', $doctorclaStr);
  139. $doctorclaStr = str_replace(" ", "", $doctorclaStr);
  140. $newrow["doctor_class"] = $doctorclaStr;
  141. $newrow["status"] = "1";
  142. Db::table("doctor_class")->insert($newrow);
  143. SysLogs::log("doctors", "C", $doctor_id . " doctorclass --> " . $doctorclaStr);
  144. }
  145. }
  146. /**
  147. * 软删除记录
  148. */
  149. public function delete() {
  150. if (isset($_GET["ids"])) {
  151. $ids = $_GET["ids"];
  152. if (!empty($ids)) {
  153. $idArr = explode(",", $ids);
  154. if (count($idArr) > 0) {
  155. Db::table("doctors")->where("id", "in", $idArr)->update(['status' => 1]);
  156. SysLogs::log("doctors", "U", $ids . " status 修改为 1 ");
  157. }
  158. echo "delete_ok";
  159. return;
  160. }
  161. }
  162. echo "fail";
  163. }
  164. /**
  165. * 显示权限编辑窗口
  166. * @return type
  167. */
  168. public function permissions() {
  169. $id = is_string($_GET["id"]) ? $_GET["id"] : null;
  170. if ($id != null) {
  171. // 得到医生信息
  172. $doctor = Db::table("doctors")->where("id", $id)->find();
  173. if (empty($doctor)) {
  174. echo "no doctor !";
  175. return;
  176. }
  177. $this->assign("doctor", $doctor);
  178. $this->assign("id", $id);
  179. }
  180. // 查找已有权限(菜单)
  181. $permitsMenus = Db::table("dr_cla_permission")->where("doctor_id", $id)->where("type", "1")->select();
  182. $permitMenuIdArr = array();
  183. if (count($permitsMenus) > 0) {
  184. foreach ($permitsMenus as $key => $val) {
  185. array_push($permitMenuIdArr, $val["pass"]);
  186. }
  187. $this->assign("permitMenuIdArr", json_encode($permitMenuIdArr));
  188. }
  189. // 查找已有权限(写报告)
  190. $permitsReport = Db::table("dr_cla_permission")->where("doctor_id", $id)->where("type", "2")->find();
  191. if (!empty($permitsReport)) {
  192. $this->assign("permitReport", $permitsReport["pass"]);
  193. } else {
  194. $this->assign("permitReport", "0");
  195. }
  196. return $this->fetch("permissions");
  197. }
  198. /**
  199. * 保存菜单权限
  200. */
  201. public function saveMenuPermit() {
  202. $doctorId = empty($_GET["id"]) ? null : $_GET["id"];
  203. $menuIds = empty($_GET["ids"]) ? null : $_GET["ids"];
  204. if (empty($doctorId) || empty($menuIds)) {
  205. echo "fail, empty doctorId or menuId";
  206. return;
  207. }
  208. $menuIdArr = explode(",", $menuIds);
  209. $menus = Db::table("menu")->whereIn("id", $menuIdArr)->select();
  210. if (count($menus) < 1) {
  211. // 没有找到菜单
  212. echo "fail, no menu found ";
  213. return;
  214. } else {
  215. // 给用户赋值
  216. // 查看是否已经有了权限
  217. $menuIdArr = array();
  218. foreach ($menus as $key => $val) {
  219. array_push($menuIdArr, $val["id"]);
  220. }
  221. // 将已有权限全部清空
  222. Db::table("dr_cla_permission")->where("doctor_id", $doctorId)->where("type", "1")->delete();
  223. SysLogs::log("dr_cla_permission", "D", "where (doctor_id = " . $doctorId . "type = 1) delete ");
  224. // 如果没有,添加
  225. foreach ($menuIdArr as $key => $val) {
  226. $newRow = array();
  227. $newRow["id"] = UUIDs::uuid16();
  228. $newRow["type"] = "1";
  229. $newRow["pass"] = $val;
  230. $newRow["doctor_id"] = $doctorId;
  231. Db::table("dr_cla_permission")->insert($newRow);
  232. SysLogs::log("dr_cla_permission", "C", json_encode($newRow));
  233. }
  234. }
  235. echo "ok";
  236. }
  237. /**
  238. * 保存报告权限
  239. */
  240. public function saveReportPermit() {
  241. $doctorId = isset($_GET["id"]) ? $_GET["id"] : null;
  242. $permitReport = isset($_GET["report"]) ? $_GET["report"] : null;
  243. if ($doctorId == null || $permitReport == null) {
  244. echo "fail";
  245. return;
  246. }
  247. $permitData = Db::table("dr_cla_permission")->where("doctor_id", $doctorId)->where("type", "2")->find();
  248. if (!empty($permitData)) {
  249. // 如果已经有报告权限的配置,
  250. // 只更新就好
  251. $permitData["pass"] = $permitReport;
  252. Db::table("dr_cla_permission")->update($permitData);
  253. SysLogs::log("dr_cla_permission", "U", json_encode($permitData));
  254. } else {
  255. // 新建权限记录
  256. $newRow = array();
  257. $newRow["id"] = UUIDs::uuid16();
  258. $newRow["doctor_id"] = $doctorId;
  259. $newRow["type"] = "2";
  260. $newRow["pass"] = $permitReport;
  261. Db::table("dr_cla_permission")->insert($newRow);
  262. SysLogs::log("dr_cla_permission", "C", json_encode($newRow));
  263. }
  264. echo "ok";
  265. }
  266. /**
  267. * 查询全部菜单
  268. */
  269. public function menudata() {
  270. $rootMenuData = array();
  271. // 准备根节点
  272. $rootMenuData["id"] = "root";
  273. $rootMenuData["pId"] = "0";
  274. $rootMenuData["name"] = "菜单(根节点)";
  275. $rootMenuData["url"] = "";
  276. $rootMenuData["open"] = "true";
  277. // 查询全部数据
  278. $menuData = $info = DB::table('menu')->select();
  279. $jsonarray = array();
  280. if ($menuData != null) {
  281. foreach ($menuData as $k => $val) {
  282. $parent_id = $val["parent_id"];
  283. unset($val["parent_id"]);
  284. // 处理parent_id为pId,为前端菜单上下级关系展示处理
  285. $val['pId'] = $parent_id;
  286. $val['open '] = "true";
  287. array_push($jsonarray, $val);
  288. }
  289. }
  290. // 将根节点添加到树
  291. array_unshift($jsonarray, $rootMenuData);
  292. // 返回JSON数据
  293. echo json_encode($jsonarray);
  294. }
  295. public function import(){
  296. include_once LIB_ROOT_PATH."3rdParty/phpexcel/PHPExcel.php";
  297. $objReader = PHPExcel_IOFactory::createReader('Excel2007');
  298. $objPHPExcel = $objReader->load($file_name,$encode='utf-8');
  299. $sheet = $objPHPExcel->getSheet(0);
  300. $highestRow = $sheet->getHighestRow();//取得总行数
  301. $highestColumn = $sheet->getHighestColumn();//取得总列数
  302. $data = array();
  303. for($i=2;$i<=$highestRow;$i++){
  304. for($j='A';$j<=$highestColumn;$j++){
  305. $data[$i][] = $objPHPExcel->getActiveSheet()->getCell("$j$i")->getValue();
  306. }
  307. }
  308. var_dump($data);
  309. var_dump($_FILES);die;
  310. if (!empty($_FILES)) {
  311. import("@.ORG.UploadFile");
  312. $config=array(
  313. 'allowExts'=>array('xlsx','xls'),
  314. 'savePath'=>'./Public/upload/',
  315. 'saveRule'=>'time',
  316. );
  317. $upload = new UploadFile($config);
  318. if (!$upload->upload()) {
  319. $this->error($upload->getErrorMsg());
  320. } else {
  321. $info = $upload->getUploadFileInfo();
  322. }
  323. vendor("PHPExcel.PHPExcel");
  324. $file_name=$info[0]['savepath'].$info[0]['savename'];
  325. $objReader = PHPExcel_IOFactory::createReader('Excel5');
  326. $objPHPExcel = $objReader->load($file_name,$encode='utf-8');
  327. $sheet = $objPHPExcel->getSheet(0);
  328. $highestRow = $sheet->getHighestRow(); // 取得总行数
  329. $highestColumn = $sheet->getHighestColumn(); // 取得总列数
  330. for($i=3;$i<=$highestRow;$i++)
  331. {
  332. $data['account']= $data['truename'] = $objPHPExcel->getActiveSheet()->getCell("B".$i)->getValue();
  333. $sex = $objPHPExcel->getActiveSheet()->getCell("C".$i)->getValue();
  334. // $data['res_id'] = $objPHPExcel->getActiveSheet()->getCell("D".$i)->getValue();
  335. $data['class'] = $objPHPExcel->getActiveSheet()->getCell("E".$i)->getValue();
  336. $data['year'] = $objPHPExcel->getActiveSheet()->getCell("F".$i)->getValue();
  337. $data['city']= $objPHPExcel->getActiveSheet()->getCell("G".$i)->getValue();
  338. $data['company']= $objPHPExcel->getActiveSheet()->getCell("H".$i)->getValue();
  339. $data['zhicheng']= $objPHPExcel->getActiveSheet()->getCell("I".$i)->getValue();
  340. $data['zhiwu']= $objPHPExcel->getActiveSheet()->getCell("J".$i)->getValue();
  341. $data['jibie']= $objPHPExcel->getActiveSheet()->getCell("K".$i)->getValue();
  342. $data['honor']= $objPHPExcel->getActiveSheet()->getCell("L".$i)->getValue();
  343. $data['tel']= $objPHPExcel->getActiveSheet()->getCell("M".$i)->getValue();
  344. $data['qq']= $objPHPExcel->getActiveSheet()->getCell("N".$i)->getValue();
  345. $data['email']= $objPHPExcel->getActiveSheet()->getCell("O".$i)->getValue();
  346. $data['remark']= $objPHPExcel->getActiveSheet()->getCell("P".$i)->getValue();
  347. $data['sex']=$sex=='男'?1:0;
  348. $data['res_id'] =1;
  349. $data['last_login_time']=0;
  350. $data['create_time']=$data['last_login_ip']=$_SERVER['REMOTE_ADDR'];
  351. $data['login_count']=0;
  352. $data['join']=0;
  353. $data['avatar']='';
  354. $data['password']=md5('123456');
  355. M('Member')->add($data);
  356. }
  357. $this->success('导入成功!');
  358. }else
  359. {
  360. $this->error("请选择上传的文件");
  361. }
  362. }
  363. }