123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- <?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 Order extends Base {
- public function local() {
- // 查询出全部的机构,显示上级机构使用
- $rs = Db::table("institution")->select();
- $this->assign("institutions", $rs);
- $manage = Session::get('session_manager');
- // 取出所有上级医院
- $up = DB::table('institution')->where('id',$manage['institution_id'])->value('parent_institution');
- //取出所有下级医院
- $down = DB::table('institution')->where('parent_institution','like','%'.$manage['institution_id'].'%')->column('id');
- $string = implode(',',$down);
- $agents = Db::table("doctors")->where("institution_id",'in', ','.$up.','.$string.','.$manage['institution_id'].',')->field("id,realname as 'text',institution_id")->select();
- $this->assign("agents", $agents);
- return $this->fetch('local');
- }
- public function remote() {
- // 查询出全部的机构,显示上级机构使用
- $rs = Db::table("institution")->select();
- $this->assign("institutions", $rs);
- $manage = Session::get('session_manager');
- // 取出所有上级医院
- $up = DB::table('institution')->where('id',$manage['institution_id'])->value('parent_institution');
- //取出所有下级医院
- $down = DB::table('institution')->where('parent_institution','like','%'.$manage['institution_id'].'%')->column('id');
- $string = implode(',',$down);
- $agents = Db::table("doctors")->where("institution_id",'in', ','.$up.','.$string.','.$manage['institution_id'].',')->field("id,realname as 'text',institution_id")->select();
- $this->assign("agents", $agents);
- return $this->fetch('remote');
- }
- /**
- * 列表数据
- */
- public function localdatas() {
- $request = Request::instance();
- $params = $request->param();
- $ins = isset($params["ins"]) ? $params["ins"] : null;
- $time1 = isset($params["time1"]) ? $params["time1"] : null;
- $time2 = isset($params["time2"]) ? $params["time2"] : null;
- $whereArr = array();
- if ($ins != null) {
- $whereArr["super_hospital_id"] = $ins;
- }
- $timeWhere = [];
- if($time2 == $time1 && $time1 != null){
- $timeWhere["createdAt"] =["between",[$time1." 00:00:00",$time2." 23:59:59"]];
- }elseif($time2 == null && $time1 != null){
- $timeWhere["createdAt"] = [">",$time1." 00:00:00"];
- }elseif ($time1 == null && $time2 != null) {
- $timeWhere["createdAt"] = ["<",$time2." 23:59:59"];
- }elseif($time1 != null && $time2 != null && $time1<$time2){
- $timeWhere["createdAt"] = ["between",[$time1." 00:00:00",$time2." 23:59:59"]];
- }
- $manage = Session::get('session_manager');
- $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;
- }
- $rs = Db::table("remote_order")->where('hospital_id','in',$manage['institution_id'])->where($whereArr)->where($timeWhere)->page($page, $pagesize)->select();
- $row = Db::table("remote_order")->where('hospital_id','in',$manage['institution_id'])->where($whereArr)->where($timeWhere)->count();
- $data['total'] = $row;
- $data['rows'] = $rs;
- echo json_encode($data);
- }
- public function remotedatas() {
- $request = Request::instance();
- $params = $request->param();
- $ins = isset($params["ins"]) ? $params["ins"] : null;
- $time1 = isset($params["time1"]) ? $params["time1"] : null;
- $time2 = isset($params["time2"]) ? $params["time2"] : null;
- $whereArr = array();
- if ($ins != null) {
- $whereArr["super_hospital_id"] = $ins;
- }
- $timeWhere = [];
- if($time2 == $time1 && $time1 != null){
- $timeWhere["createdAt"] =["between",[$time1." 00:00:00",$time2." 23:59:59"]];
- }elseif($time2 == null && $time1 != null){
- $timeWhere["createdAt"] = [">",$time1." 00:00:00"];
- }elseif ($time1 == null && $time2 != null) {
- $timeWhere["createdAt"] = ["<",$time2." 23:59:59"];
- }elseif($time1 != null && $time2 != null && $time1<$time2){
- $timeWhere["createdAt"] = ["between",[$time1." 00:00:00",$time2." 23:59:59"]];
- }
- $manage = Session::get('session_manager');
- $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;
- }
- $rs = Db::table("remote_order")->where('super_hospital_id','in',$manage['institution_id'])->where($whereArr)->where($timeWhere)->page($page, $pagesize)->select();
- $row = Db::table("remote_order")->where('super_hospital_id','in',$manage['institution_id'])->where($whereArr)->where($timeWhere)->count();
- $data['total'] = $row;
- $data['rows'] = $rs;
- // foreach ()
- echo json_encode($data);
- }
- /**
- * 更新或创建机构信息
- */
- public function save() {
- $request = Request::instance();
- $parms = $request->param();
- $id = $parms["id"];
- $data = array();
- $data["name"] = $parms["name"];
- $data["address"] = $parms["address"];
- $data["remark"] = $parms["remark"];
- $data["status"] = $parms["status"];
- $data["institution_level"] = $parms["institution_level"];
- $data["parent_institution"] = $parms["parent_institution"];
- $data["agent_id"] = isset($parms["agent_id"]) ? $parms["agent_id"] : "";
- if (is_array($data["parent_institution"])) {
- $pids = "";
- foreach ($data["parent_institution"] as $key => $val) {
- $pids = $pids . "," . $val;
- }
- if (strlen($pids) > 0) {
- $data["parent_institution"] = substr($pids, 1);
- } else {
- $data["parent_institution"] = "";
- }
- }
- $data["charge_mode"] = $parms["charge_mode"];
- $data["local_domain"] = $parms["local_domain"];
- // ID有值,认为是更新
- if (empty($id)) {
- // 无值,认为是添加
- if(empty($parms['yid'])){
- $data["id"] = UUIDs::uuid16();
- }else{
- $data["id"] = $parms['yid'];
- }
- $data["createdAt"] = date("Y-m-d H:i:s");
- $id = Db::table("institution")->insertGetId($data);
- $this->saveContact($data["parent_institution"],$id);
- echo "insert_ok;" . $data["id"];
- SysLogs::log("institution", "C", json_encode($data));
- } else {
- if(!empty($parms['yid'])){
- $data["id"] = $parms['yid'];
- }
- $data["updatedAt"] = date("Y-m-d H:i:s");
- // 更新
- Db::table("institution")->where("id", $id)->update($data);
- $this->saveContact($data["parent_institution"],$id);
- SysLogs::log("institution", "U", "id = " . $id . " --> " . json_encode($data));
- echo "update_ok";
- }
- }
- public function saveContact($parent,$id)
- {
- if(empty($parent)){
- return '';
- }
- $local_name = DB::table('institution')->where('id',$id)->value('name');
- foreach ($parent as $k=>$v){
- $data = DB::table('remote_contact')->where('hospital_id',$id)->where('super_hospital_id',$v)->find();
- if(!empty($data)){
- return '';
- }
- $parent_name = DB::table('institution')->where('id',$v)->value('name');
- $info = [
- 'hospital_id'=>$id,
- 'super_hospital_id'=>$v,
- 'timestamp'=>time(),
- 'hospital_name'=>$local_name,
- 'super_hospital_name'=>$parent_name
- ];
- DB::table('remote_contact')->insert($info);
- }
- }
-
- /**
- * 编辑窗口
- * @return type
- */
- public function edit() {
- // 查询出全部的机构,显示上级机构使用
- $insRs = Db::table("institution")->field("id,name as 'text'")->select();
- $this->assign("insJson", json_encode($insRs));
- if (isset($_GET["id"])) {
- $id = $_GET["id"];
- if ($id != null) {
- $institutions = Db::table("institution")->where("id", $id)->find();
- if (count($institutions) > 0) {
- $this->assign("institution", $institutions);
- }
- }
- }
- return $this->fetch('edit');
- }
- /**
- * 删除记录
- */
- public function delete() {
- if (isset($_GET["ids"])) {
- $ids = $_GET["ids"];
- if (!empty($ids)) {
- $idArr = explode(",", $ids);
- if (count($idArr) > 0) {
- Db::table("institution")->where("id", "in", $idArr)->delete();
- }
- SysLogs::log("institution", "D", $ids);
- echo "delete_ok";
- return;
- }
- }
- echo "fail";
- }
- /**
- * 代理商树
- */
- public function agents() {
- $treeData = array();
- $rows = Db::table("manager")->where("role_id", "2")->field("id,username as 'text'")->select();
- $parentTree = array();
- $parentTree["id"] = "";
- $parentTree["text"] = "请选择";
- array_push($treeData, $parentTree);
- if (!empty($rows)) {
- foreach ($rows as $key => $val) {
- array_push($treeData, $val);
- }
- }
- echo json_encode($treeData);
- }
- public function deptview() {
- $request = Request::instance();
- $params = $request->param();
- if (isset($params["insId"])) {
- $this->assign("insId", $params["insId"]);
- } else {
- echo "parameter insId error!";
- return;
- }
- return $this->fetch('dept');
- }
- /**
- * 获取医院科室数据
- * @return type
- */
- public function deptdatas() {
- $request = Request::instance();
- $params = $request->param();
- if (!isset($params["insId"])) {
- echo "please change a institution!";
- return;
- }
- $ins = Db::table("institution")->where("id", $params["insId"])->find();
- if (empty($ins)) {
- echo "please change a institution(2)!";
- return;
- }
- $whereArr = array();
- $whereArr["institution_id"] = $params["insId"];
- $rootMenuData = array();
- // 准备根节点
- $rootMenuData["id"] = "root";
- $rootMenuData["pId"] = "0";
- $rootMenuData["name"] = "科室管理(" . $ins["name"] . ")";
- $rootMenuData["url"] = "";
- $rootMenuData["open"] = "true";
- // 查询全部数据
- $menuData = $info = DB::table('department')->where($whereArr)->select();
- $jsonarray = array();
- if ($menuData != null) {
- foreach ($menuData as $k => $val) {
- $data = array();
- $data["id"] = $val["id"];
- $data['pId'] = $val["parent_id"];
- $data['name'] = $val["department_name"];
- $data['institutionid'] = $val["institution_id"];
- $data['isreport'] = $val["is_report"];
- $data['ordernum'] = $val["order_num"];
- array_push($jsonarray, $data);
- }
- }
- // 将根节点添加到树
- array_unshift($jsonarray, $rootMenuData);
- // 返回JSON数据
- echo json_encode($jsonarray);
- }
- /**
- * 添加或修改
- */
- public function deptupd() {
- $id = $_GET["id"];
- // id=&pid=root&name=%E5%A4%96%E7%A7%91&institutionid=&=0&ordernum=11
- // ID有值,认为是更新
- if (empty($id)) {
- $data = array();
- // 无值,认为是添加
- $data["id"] = UUIDs::uuid16();
- $data["parent_id"] = $_GET["pid"];
- $data["department_name"] = $_GET["name"];
- $data["institution_id"] = $_GET["institutionid"];
- $data["order_num"] = $_GET["ordernum"];
- $data["is_report"] = $_GET["isreport"];
- Db::table("department")->insert($data);
- echo "insert_ok";
- SysLogs::log("constant", "C", json_encode($data));
- } else {
- // 更新
- $data["id"] = $_GET["id"];
- $data["parent_id"] = $_GET["pid"];
- $data["department_name"] = $_GET["name"];
- $data["institution_id"] = $_GET["institutionid"];
- $data["order_num"] = $_GET["ordernum"];
- $data["is_report"] = $_GET["isreport"];
- Db::table("department")->where("id", $id)->update(["parent_id" => $data["parent_id"], "department_name" => $data["department_name"], "institution_id" => $data["institution_id"], "is_report" => $data["is_report"], "order_num" => $data["order_num"]]);
- echo "update_ok";
- SysLogs::log("constant", "U", $id . " --> " . json_encode($data));
- }
- }
- public function deptdel() {
- $id = $_GET["id"];
- $result = Db::table("department")->delete($id);
- if ($result) {
- echo "delete_ok";
- SysLogs::log("department", "D", $id . " --> delete_ok");
- } else {
- echo "delete_fail";
- SysLogs::log("department", "D", $id . " --> delete_fail");
- }
- }
- }
|