Order.php 14 KB

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