HospitalTemplate.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <?php
  2. namespace app\admin\controller\template;
  3. use app\api\utils\UUIDUtils;
  4. use app\common\controller\Backend;
  5. use think\db;
  6. /**
  7. *
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class HospitalTemplate extends Backend
  12. {
  13. protected $noNeedRight = ['*'];
  14. /**
  15. * HospitalTemplate模型对象
  16. * @var \app\admin\model\template\HospitalTemplate
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\template\HospitalTemplate;
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. public function public_index()
  30. {
  31. //设置过滤方法
  32. $this->request->filter(['strip_tags']);
  33. if ($this->request->isAjax()) {
  34. //如果发送的来源是Selectpage,则转发到Selectpage
  35. if ($this->request->request('keyField')) {
  36. return $this->selectpage();
  37. }
  38. list($where, $sort, $order, $offset, $limit) = $this->buildparams('title');
  39. $childInsIds = $this->auth->getMyInsId();
  40. if($childInsIds == false){
  41. $more = false;
  42. } else {
  43. $more = ['institution_id' => ['in', $this->auth->getMyInsId()]];
  44. }
  45. $total = $this->model
  46. ->where($where)
  47. ->where($more)
  48. ->where('is_public',3)
  49. ->where('parent_id',0)
  50. ->order($sort, $order)
  51. ->count();
  52. $list = $this->model
  53. ->where($where)
  54. ->where($more)
  55. ->where('is_public',3)
  56. ->where('parent_id',0)
  57. ->order($sort, $order)
  58. ->limit($offset, $limit)
  59. ->select();
  60. $list = collection($list)->toArray();
  61. $result = array("total" => $total, "rows" => $list);
  62. return json($result);
  63. }
  64. return $this->view->fetch();
  65. }
  66. public function child_index()
  67. {
  68. $pid = $this->request->param('pid');
  69. //设置过滤方法
  70. $this->request->filter(['strip_tags']);
  71. if ($this->request->isAjax()) {
  72. //如果发送的来源是Selectpage,则转发到Selectpage
  73. if ($this->request->request('keyField')) {
  74. return $this->selectpage();
  75. }
  76. list($where, $sort, $order, $offset, $limit) = $this->buildparams('title');
  77. $childInsIds = $this->auth->getMyInsId();
  78. if($childInsIds == false){
  79. $more = false;
  80. } else {
  81. $more = ['institution_id' => ['in', $this->auth->getMyInsId()]];
  82. }
  83. $total = $this->model
  84. ->where($where)
  85. ->where($more)
  86. ->where('parent_id',$pid)
  87. ->where('is_public',3)
  88. ->order($sort, $order)
  89. ->count();
  90. $list = $this->model
  91. ->where($where)
  92. ->where($more)
  93. ->where('parent_id',$pid)
  94. ->where('is_public',3)
  95. ->order($sort, $order)
  96. ->limit($offset, $limit)
  97. ->select();
  98. $list = collection($list)->toArray();
  99. $result = array("total" => $total, "rows" => $list);
  100. return json($result);
  101. }
  102. return $this->view->fetch();
  103. }
  104. //医院模板父级添加
  105. public function hospitalAddParent()
  106. {
  107. if ($this->request->isPost()) {
  108. $params = $this->request->post("row/a");
  109. if ($params) {
  110. $params = $this->preExcludeFields($params);
  111. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  112. $params[$this->dataLimitField] = $this->auth->id;
  113. }
  114. $result = false;
  115. Db::startTrans();
  116. try {
  117. //是否采用模型验证
  118. if ($this->modelValidate) {
  119. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  120. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  121. $this->model->validateFailException(true)->validate($validate);
  122. }
  123. $data = $params;
  124. $data['id'] = makeNew16Uid();
  125. $data['is_public'] =3;
  126. $result = $this->model->allowField(true)->save($data);
  127. Db::commit();
  128. } catch (ValidateException $e) {
  129. Db::rollback();
  130. $this->error($e->getMessage());
  131. } catch (PDOException $e) {
  132. Db::rollback();
  133. $this->error($e->getMessage());
  134. } catch (Exception $e) {
  135. Db::rollback();
  136. $this->error($e->getMessage());
  137. }
  138. if ($result !== false) {
  139. $this->success();
  140. } else {
  141. $this->error(__('No rows were inserted'));
  142. }
  143. }
  144. $this->error(__('Parameter %s can not be empty', ''));
  145. }
  146. return $this->view->fetch();
  147. }
  148. public function hospitalAddChild($ids)
  149. {
  150. $pid = $ids;
  151. if ($this->request->isPost()) {
  152. $params = $this->request->post("row/a");
  153. if ($params) {
  154. $params = $this->preExcludeFields($params);
  155. if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  156. $params[$this->dataLimitField] = $this->auth->id;
  157. }
  158. $result = false;
  159. Db::startTrans();
  160. try {
  161. //是否采用模型验证
  162. if ($this->modelValidate) {
  163. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  164. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  165. $this->model->validateFailException(true)->validate($validate);
  166. }
  167. $data = $params;
  168. $data['id'] = makeNew16Uid();
  169. $data['is_public'] =3;
  170. $data['parent_id'] = $pid;
  171. $data['institution_id'] = $this->model->where('id',$pid)->value('institution_id');
  172. $result = $this->model->allowField(true)->save($data);
  173. Db::commit();
  174. } catch (ValidateException $e) {
  175. Db::rollback();
  176. $this->error($e->getMessage());
  177. } catch (PDOException $e) {
  178. Db::rollback();
  179. $this->error($e->getMessage());
  180. } catch (Exception $e) {
  181. Db::rollback();
  182. $this->error($e->getMessage());
  183. }
  184. if ($result !== false) {
  185. $this->success();
  186. } else {
  187. $this->error(__('No rows were inserted'));
  188. }
  189. }
  190. $this->error(__('Parameter %s can not be empty', ''));
  191. }
  192. $this->view->assign("pid", $pid);
  193. return $this->view->fetch();
  194. }
  195. /**
  196. * 编辑
  197. */
  198. public function hospitalEditParent($ids = null)
  199. {
  200. $row = $this->model->where('id',$ids)->find();
  201. if (!$row) {
  202. $this->error(__('No Results were found'));
  203. }
  204. $adminIds = $this->getDataLimitAdminIds();
  205. if (is_array($adminIds)) {
  206. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  207. $this->error(__('You have no permission'));
  208. }
  209. }
  210. if ($this->request->isPost()) {
  211. $params = $this->request->post("row/a");
  212. if ($params) {
  213. $params = $this->preExcludeFields($params);
  214. $result = false;
  215. Db::startTrans();
  216. try {
  217. //是否采用模型验证
  218. if ($this->modelValidate) {
  219. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  220. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  221. $row->validateFailException(true)->validate($validate);
  222. }
  223. $result = $row->allowField(true)->save($params);
  224. Db::commit();
  225. } catch (ValidateException $e) {
  226. Db::rollback();
  227. $this->error($e->getMessage());
  228. } catch (PDOException $e) {
  229. Db::rollback();
  230. $this->error($e->getMessage());
  231. } catch (Exception $e) {
  232. Db::rollback();
  233. $this->error($e->getMessage());
  234. }
  235. if ($result !== false) {
  236. $this->success();
  237. } else {
  238. $this->error(__('No rows were updated'));
  239. }
  240. }
  241. $this->error(__('Parameter %s can not be empty', ''));
  242. }
  243. $this->view->assign("row", $row);
  244. return $this->view->fetch();
  245. }
  246. public function hospitalEditChild($ids = null)
  247. {
  248. $row = $this->model->where('id',$ids)->find();
  249. if (!$row) {
  250. $this->error(__('No Results were found'));
  251. }
  252. $adminIds = $this->getDataLimitAdminIds();
  253. if (is_array($adminIds)) {
  254. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  255. $this->error(__('You have no permission'));
  256. }
  257. }
  258. if ($this->request->isPost()) {
  259. $params = $this->request->post("row/a");
  260. if ($params) {
  261. $params = $this->preExcludeFields($params);
  262. $result = false;
  263. Db::startTrans();
  264. try {
  265. //是否采用模型验证
  266. if ($this->modelValidate) {
  267. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  268. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  269. $row->validateFailException(true)->validate($validate);
  270. }
  271. $result = $row->allowField(true)->save($params);
  272. Db::commit();
  273. } catch (ValidateException $e) {
  274. Db::rollback();
  275. $this->error($e->getMessage());
  276. } catch (PDOException $e) {
  277. Db::rollback();
  278. $this->error($e->getMessage());
  279. } catch (Exception $e) {
  280. Db::rollback();
  281. $this->error($e->getMessage());
  282. }
  283. if ($result !== false) {
  284. $this->success();
  285. } else {
  286. $this->error(__('No rows were updated'));
  287. }
  288. }
  289. $this->error(__('Parameter %s can not be empty', ''));
  290. }
  291. $this->view->assign("row", $row);
  292. return $this->view->fetch();
  293. }
  294. public function hospitalDelParent($ids = "")
  295. {
  296. $adminIds = $this->getDataLimitAdminIds();
  297. if (is_array($adminIds)) {
  298. $this->model->where($this->dataLimitField, 'in', $adminIds);
  299. }
  300. $count = 0;
  301. Db::startTrans();
  302. try {
  303. if($ids)
  304. {
  305. $template = $this->model->where('parent_id',$ids)->find();
  306. if(empty($template))
  307. {
  308. $count = $this->model->where('id',$ids)->delete();
  309. }else{
  310. $this->error('存在下级模板,无法删除');
  311. }
  312. }else{
  313. $this->error('无效的id,请刷新页面');
  314. }
  315. Db::commit();
  316. } catch (PDOException $e) {
  317. Db::rollback();
  318. $this->error($e->getMessage());
  319. } catch (Exception $e) {
  320. Db::rollback();
  321. $this->error($e->getMessage());
  322. }
  323. if ($count) {
  324. $this->success();
  325. } else {
  326. $this->error(__('No rows were deleted'));
  327. }
  328. $this->error(__('Parameter %s can not be empty', 'ids'));
  329. }
  330. public function hospitalDelChild($ids = "")
  331. {
  332. $adminIds = $this->getDataLimitAdminIds();
  333. if (is_array($adminIds)) {
  334. $this->model->where($this->dataLimitField, 'in', $adminIds);
  335. }
  336. $count = 0;
  337. Db::startTrans();
  338. try {
  339. if($ids)
  340. {
  341. $count = $this->model->where('id',$ids)->delete();
  342. }else{
  343. $this->error('无效的id,请刷新页面');
  344. }
  345. Db::commit();
  346. } catch (PDOException $e) {
  347. Db::rollback();
  348. $this->error($e->getMessage());
  349. } catch (Exception $e) {
  350. Db::rollback();
  351. $this->error($e->getMessage());
  352. }
  353. if ($count) {
  354. $this->success();
  355. } else {
  356. $this->error(__('No rows were deleted'));
  357. }
  358. $this->error(__('Parameter %s can not be empty', 'ids'));
  359. }
  360. }