123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?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 Patientinfo extends Base {
- public function index() {
- return $this->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";
- }
- }
|