Order.php 13 KB

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