fetch(); } public function datas() { $request = Request::instance(); $params = $request->param(); $wheres = array(); $insid = isset($params["insid"]) ? $params["insid"] : null; $username = isset($params["username"]) ? $params["username"] : null; $tel = isset($params["tel"]) ? $params["tel"] : null; if ($insid != null && $insid != "") { $wheres["institution_id"] = $insid; } if ($username != null && $username != "") { $wheres["name"] = array("like", "%" . $username . "%"); } if ($tel != null && $tel != "") { $wheres["phone"] = array("like", $tel . "%"); } $insMap = array(); $insArr = Db::table("institution")->field("id, name")->select(); if (!empty($insArr)) { foreach ($insArr as $key => $val) { $insMap[$val["id"]] = $val["name"]; } } $page = empty($params["page"]) ? 1 : $params["page"]; $pagesize = empty($params["rows"]) ? 1 : $params["rows"]; if (empty($page) || $page < 1) { $page = 1; } if (empty($pagesize) || $pagesize < 1) { $pagesize = 30; } $resultArr = array(); $info = DB::table('patient_infos')->where($wheres)->page($page, $pagesize)->select(); if (!empty($info)) { foreach ($info as $key => $val) { if (isset($insMap[$val["institution_id"]])) { $val["institution_name"] = $insMap[$val["institution_id"]]; } else { $val["institution_name"] = $val["institution_id"]; } array_push($resultArr, $val); } } $num = DB::table('patient_infos')->where($wheres)->count(); $data = array(); $data['total'] = $num; $data['rows'] = $resultArr; echo json_encode($data); } /** * 编辑窗口 * @return type */ public function edit() { if (isset($_GET["id"])) { $id = $_GET["id"]; if ($id != null) { $patient_info = Db::table("patient_info")->where("id", $id)->find(); if (count($patient_info) > 0) { $this->assign("patient_info", $patient_info); } } } return $this->fetch('edit'); } public function save() { $request = Request::instance(); $params = $request->param(); $id = isset($params["id"]) ? $params["id"] : null; if ($id != null && $id != "") { // 更新 // 判断下birthday if ($params["birthday"] == "") { $params["birthday"] = null; } $a = DB::table('patient_infos')->where('id', $params['id'])->update($params); SysLogs::log("patient_info", "U", 'id = ' . $params['id'] . " --> " . json_encode($params)); if ($a) { return 'success'; } else { return 'fail'; } } else { // 或许是新增 } return "fail"; } /** * 软删除记录 */ public function delete() { if (isset($_GET["ids"])) { $ids = $_GET["ids"]; if (!empty($ids)) { $idArr = explode(",", $ids); if (count($idArr) > 0) { Db::table("patient_info")->where("id", "in", $idArr)->update(['status' => "0"]); SysLogs::log("patient_info", "U", 'id in ' . $ids . " --> status = 0"); } echo "delete_ok"; return; } } echo "fail"; } }