Order.php 12 KB

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