Order.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. /*
  12. *
  13. */
  14. class Order extends Base {
  15. public function local() {
  16. // 查询出全部的机构,显示上级机构使用
  17. $rs = Db::table("institution")->select();
  18. $this->assign("institutions", $rs);
  19. $manage = Session::get('session_manager');
  20. // 取出所有上级医院
  21. $up = DB::table('institution')->where('id',$manage['institution_id'])->value('parent_institution');
  22. //取出所有下级医院
  23. $down = DB::table('institution')->where('parent_institution','like','%'.$manage['institution_id'].'%')->column('id');
  24. $string = implode(',',$down);
  25. $agents = Db::table("doctors")->where("institution_id",'in', ','.$up.','.$string.','.$manage['institution_id'].',')->field("id,realname as 'text',institution_id")->select();
  26. $this->assign("agents", $agents);
  27. return $this->fetch('local');
  28. }
  29. public function remote() {
  30. // 查询出全部的机构,显示上级机构使用
  31. $rs = Db::table("institution")->select();
  32. $this->assign("institutions", $rs);
  33. $manage = Session::get('session_manager');
  34. // 取出所有上级医院
  35. $up = DB::table('institution')->where('id',$manage['institution_id'])->value('parent_institution');
  36. //取出所有下级医院
  37. $down = DB::table('institution')->where('parent_institution','like','%'.$manage['institution_id'].'%')->column('id');
  38. $string = implode(',',$down);
  39. $agents = Db::table("doctors")->where("institution_id",'in', ','.$up.','.$string.','.$manage['institution_id'].',')->field("id,realname as 'text',institution_id")->select();
  40. $this->assign("agents", $agents);
  41. return $this->fetch('remote');
  42. }
  43. /**
  44. * 列表数据
  45. */
  46. public function localdatas() {
  47. $request = Request::instance();
  48. $params = $request->param();
  49. // $pid = isset($params["pid"]) ? $params["pid"] : null;
  50. // $status = isset($params["status"]) ? $params["status"] : null;
  51. // $name = isset($params["name"]) ? $params["name"] : null;
  52. // $whereArr = array();
  53. // if ($pid != null) {
  54. // $whereArr["parent_institution"] = array("like", "%" . $pid . "%");
  55. // }
  56. // if ($status != null) {
  57. // $whereArr["status"] = $status;
  58. // }
  59. // if ($name != null) {
  60. // $whereArr["name"] = array("like", "%" . $name . "%");
  61. // }
  62. $manage = Session::get('session_manager');
  63. $rs = Db::table("remote_order")->where('hospital_id','in',$manage['institution_id'])->select();
  64. echo json_encode($rs);
  65. }
  66. public function remotedatas() {
  67. $request = Request::instance();
  68. $params = $request->param();
  69. // $pid = isset($params["pid"]) ? $params["pid"] : null;
  70. // $status = isset($params["status"]) ? $params["status"] : null;
  71. // $name = isset($params["name"]) ? $params["name"] : null;
  72. // $whereArr = array();
  73. // if ($pid != null) {
  74. // $whereArr["parent_institution"] = array("like", "%" . $pid . "%");
  75. // }
  76. // if ($status != null) {
  77. // $whereArr["status"] = $status;
  78. // }
  79. // if ($name != null) {
  80. // $whereArr["name"] = array("like", "%" . $name . "%");
  81. // }
  82. $manage = Session::get('session_manager');
  83. $rs = Db::table("remote_order")->where('super_hospital_id','in',$manage['institution_id'])->buildSql();
  84. var_dump($rs);die;
  85. // foreach ()
  86. echo json_encode($rs);
  87. }
  88. /**
  89. * 更新或创建机构信息
  90. */
  91. public function save() {
  92. $request = Request::instance();
  93. $parms = $request->param();
  94. $id = $parms["id"];
  95. $data = array();
  96. $data["name"] = $parms["name"];
  97. $data["address"] = $parms["address"];
  98. $data["remark"] = $parms["remark"];
  99. $data["status"] = $parms["status"];
  100. $data["institution_level"] = $parms["institution_level"];
  101. $data["parent_institution"] = $parms["parent_institution"];
  102. $data["agent_id"] = isset($parms["agent_id"]) ? $parms["agent_id"] : "";
  103. if (is_array($data["parent_institution"])) {
  104. $pids = "";
  105. foreach ($data["parent_institution"] as $key => $val) {
  106. $pids = $pids . "," . $val;
  107. }
  108. if (strlen($pids) > 0) {
  109. $data["parent_institution"] = substr($pids, 1);
  110. } else {
  111. $data["parent_institution"] = "";
  112. }
  113. }
  114. $data["charge_mode"] = $parms["charge_mode"];
  115. $data["local_domain"] = $parms["local_domain"];
  116. // ID有值,认为是更新
  117. if (empty($id)) {
  118. // 无值,认为是添加
  119. if(empty($parms['yid'])){
  120. $data["id"] = UUIDs::uuid16();
  121. }else{
  122. $data["id"] = $parms['yid'];
  123. }
  124. $data["createdAt"] = date("Y-m-d H:i:s");
  125. $id = Db::table("institution")->insertGetId($data);
  126. $this->saveContact($data["parent_institution"],$id);
  127. echo "insert_ok;" . $data["id"];
  128. SysLogs::log("institution", "C", json_encode($data));
  129. } else {
  130. if(!empty($parms['yid'])){
  131. $data["id"] = $parms['yid'];
  132. }
  133. $data["updatedAt"] = date("Y-m-d H:i:s");
  134. // 更新
  135. Db::table("institution")->where("id", $id)->update($data);
  136. $this->saveContact($data["parent_institution"],$id);
  137. SysLogs::log("institution", "U", "id = " . $id . " --> " . json_encode($data));
  138. echo "update_ok";
  139. }
  140. }
  141. public function saveContact($parent,$id)
  142. {
  143. if(empty($parent)){
  144. return '';
  145. }
  146. $local_name = DB::table('institution')->where('id',$id)->value('name');
  147. foreach ($parent as $k=>$v){
  148. $data = DB::table('remote_contact')->where('hospital_id',$id)->where('super_hospital_id',$v)->find();
  149. if(!empty($data)){
  150. return '';
  151. }
  152. $parent_name = DB::table('institution')->where('id',$v)->value('name');
  153. $info = [
  154. 'hospital_id'=>$id,
  155. 'super_hospital_id'=>$v,
  156. 'timestamp'=>time(),
  157. 'hospital_name'=>$local_name,
  158. 'super_hospital_name'=>$parent_name
  159. ];
  160. DB::table('remote_contact')->insert($info);
  161. }
  162. }
  163. /**
  164. * 编辑窗口
  165. * @return type
  166. */
  167. public function edit() {
  168. // 查询出全部的机构,显示上级机构使用
  169. $insRs = Db::table("institution")->field("id,name as 'text'")->select();
  170. $this->assign("insJson", json_encode($insRs));
  171. if (isset($_GET["id"])) {
  172. $id = $_GET["id"];
  173. if ($id != null) {
  174. $institutions = Db::table("institution")->where("id", $id)->find();
  175. if (count($institutions) > 0) {
  176. $this->assign("institution", $institutions);
  177. }
  178. }
  179. }
  180. return $this->fetch('edit');
  181. }
  182. /**
  183. * 删除记录
  184. */
  185. public function delete() {
  186. if (isset($_GET["ids"])) {
  187. $ids = $_GET["ids"];
  188. if (!empty($ids)) {
  189. $idArr = explode(",", $ids);
  190. if (count($idArr) > 0) {
  191. Db::table("institution")->where("id", "in", $idArr)->delete();
  192. }
  193. SysLogs::log("institution", "D", $ids);
  194. echo "delete_ok";
  195. return;
  196. }
  197. }
  198. echo "fail";
  199. }
  200. /**
  201. * 代理商树
  202. */
  203. public function agents() {
  204. $treeData = array();
  205. $rows = Db::table("manager")->where("role_id", "2")->field("id,username as 'text'")->select();
  206. $parentTree = array();
  207. $parentTree["id"] = "";
  208. $parentTree["text"] = "请选择";
  209. array_push($treeData, $parentTree);
  210. if (!empty($rows)) {
  211. foreach ($rows as $key => $val) {
  212. array_push($treeData, $val);
  213. }
  214. }
  215. echo json_encode($treeData);
  216. }
  217. public function deptview() {
  218. $request = Request::instance();
  219. $params = $request->param();
  220. if (isset($params["insId"])) {
  221. $this->assign("insId", $params["insId"]);
  222. } else {
  223. echo "parameter insId error!";
  224. return;
  225. }
  226. return $this->fetch('dept');
  227. }
  228. /**
  229. * 获取医院科室数据
  230. * @return type
  231. */
  232. public function deptdatas() {
  233. $request = Request::instance();
  234. $params = $request->param();
  235. if (!isset($params["insId"])) {
  236. echo "please change a institution!";
  237. return;
  238. }
  239. $ins = Db::table("institution")->where("id", $params["insId"])->find();
  240. if (empty($ins)) {
  241. echo "please change a institution(2)!";
  242. return;
  243. }
  244. $whereArr = array();
  245. $whereArr["institution_id"] = $params["insId"];
  246. $rootMenuData = array();
  247. // 准备根节点
  248. $rootMenuData["id"] = "root";
  249. $rootMenuData["pId"] = "0";
  250. $rootMenuData["name"] = "科室管理(" . $ins["name"] . ")";
  251. $rootMenuData["url"] = "";
  252. $rootMenuData["open"] = "true";
  253. // 查询全部数据
  254. $menuData = $info = DB::table('department')->where($whereArr)->select();
  255. $jsonarray = array();
  256. if ($menuData != null) {
  257. foreach ($menuData as $k => $val) {
  258. $data = array();
  259. $data["id"] = $val["id"];
  260. $data['pId'] = $val["parent_id"];
  261. $data['name'] = $val["department_name"];
  262. $data['institutionid'] = $val["institution_id"];
  263. $data['isreport'] = $val["is_report"];
  264. $data['ordernum'] = $val["order_num"];
  265. array_push($jsonarray, $data);
  266. }
  267. }
  268. // 将根节点添加到树
  269. array_unshift($jsonarray, $rootMenuData);
  270. // 返回JSON数据
  271. echo json_encode($jsonarray);
  272. }
  273. /**
  274. * 添加或修改
  275. */
  276. public function deptupd() {
  277. $id = $_GET["id"];
  278. // id=&pid=root&name=%E5%A4%96%E7%A7%91&institutionid=&=0&ordernum=11
  279. // ID有值,认为是更新
  280. if (empty($id)) {
  281. $data = array();
  282. // 无值,认为是添加
  283. $data["id"] = UUIDs::uuid16();
  284. $data["parent_id"] = $_GET["pid"];
  285. $data["department_name"] = $_GET["name"];
  286. $data["institution_id"] = $_GET["institutionid"];
  287. $data["order_num"] = $_GET["ordernum"];
  288. $data["is_report"] = $_GET["isreport"];
  289. Db::table("department")->insert($data);
  290. echo "insert_ok";
  291. SysLogs::log("constant", "C", json_encode($data));
  292. } else {
  293. // 更新
  294. $data["id"] = $_GET["id"];
  295. $data["parent_id"] = $_GET["pid"];
  296. $data["department_name"] = $_GET["name"];
  297. $data["institution_id"] = $_GET["institutionid"];
  298. $data["order_num"] = $_GET["ordernum"];
  299. $data["is_report"] = $_GET["isreport"];
  300. 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"]]);
  301. echo "update_ok";
  302. SysLogs::log("constant", "U", $id . " --> " . json_encode($data));
  303. }
  304. }
  305. public function deptdel() {
  306. $id = $_GET["id"];
  307. $result = Db::table("department")->delete($id);
  308. if ($result) {
  309. echo "delete_ok";
  310. SysLogs::log("department", "D", $id . " --> delete_ok");
  311. } else {
  312. echo "delete_fail";
  313. SysLogs::log("department", "D", $id . " --> delete_fail");
  314. }
  315. }
  316. }