TemplateModel.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace app\api\model\template;
  3. use app\api\model\constant\ConstantModel;
  4. use app\api\model\ZskkDefaultModel;
  5. use think\facade\Log;
  6. class TemplateModel extends ZskkDefaultModel {
  7. protected $table= 'templates';
  8. protected $logName = "TemplateModel";
  9. public function getPublicInfo($constantValue)
  10. {
  11. $data =$this->where('is_public', 1)
  12. ->where('exam_class_id', $constantValue)
  13. ->field('id, title, exam_class_id, description, impression, parent_id AS pid')
  14. ->select();
  15. return $data;
  16. }
  17. public function getConstant($id, $value)
  18. {
  19. try{
  20. return ConstantModel::where('id', $id)
  21. ->value($value);
  22. } catch (Exception $exception){
  23. $this->throwError($exception->getMessage(),0001);
  24. }
  25. }
  26. public function getPrivateInfo($constantValue,$uid)
  27. {
  28. $data = $this->where('is_public', 2)
  29. ->where('exam_class_id', $constantValue)
  30. ->where('create_user', $uid)
  31. ->field('id, title, exam_class_id, description, impression, parent_id AS pid')
  32. ->select();
  33. return $data;
  34. }
  35. public function getParentTemplate($exam_class, $type, $uid = null)
  36. {
  37. try{
  38. // 获取常量
  39. $constant_value = $this->getConstant($exam_class, 'constant_value');
  40. // 查询数据
  41. $data = [];
  42. switch ($type){
  43. case 'public':
  44. $data = $this
  45. ->where('is_public', 1)
  46. ->where('parent_id',0)
  47. ->where('exam_class_id', $constant_value)
  48. ->select();
  49. break;
  50. case 'private':
  51. $data = $this
  52. ->where('is_public', 2)
  53. ->where('parent_id',0)
  54. ->where('exam_class_id', $constant_value)
  55. ->where('create_user', $uid)
  56. ->select();
  57. break;
  58. }
  59. return $data;
  60. } catch (DbException $exception){
  61. $this->throwError($exception->getMessage(),0001);
  62. }
  63. }
  64. public function getChildData($id)
  65. {
  66. try{
  67. // 判断获取子类还是内容
  68. $temp = $this->where('id', $id)->find();
  69. if($temp['parent_id'] == '0'){
  70. $data = $this
  71. ->where('parent_id', $id)
  72. ->select();
  73. } else {
  74. $data = $this
  75. ->where('id', $id)
  76. ->find();
  77. }
  78. // 返回
  79. return $data;
  80. } catch (Exception $exception){
  81. $this->throwError($exception->getMessage(),0001);
  82. }
  83. }
  84. public function getTemplate($id)
  85. {
  86. $info = $this->where('id',$id)->field('title AS label,impression,description,exam_class_id,parent_id')->find();
  87. return $info;
  88. }
  89. public function getTemplateByPid($id)
  90. {
  91. $info = $this->where('id',$id)->value('title');
  92. return $info;
  93. }
  94. public function checkParentTemplate($param,$doctor)
  95. {
  96. $info = $this->where('title',$param['label'])->where('exam_class_id',$param['exam_class_id'])->where('is_public',2)->where('create_user',$doctor['id'])->where('parent_id',0)->find();
  97. return $info;
  98. }
  99. public function checkChildTemplate($param,$doctor)
  100. {
  101. $info = $this->where('title',$param['label'])->where('is_public',2)->where('parent_id',$param['id'])->where('create_user',$doctor['id'])->find();
  102. return $info;
  103. }
  104. public function insertTemplate($data)
  105. {
  106. $info = $this->insert($data);
  107. return $info;
  108. }
  109. public function getTemplateExam($id)
  110. {
  111. $info = $this->where('id',$id)->value('exam_class_id');
  112. return $info;
  113. }
  114. public function updateTemplate($param)
  115. {
  116. $info = $this->where('id',$param['id'])->update($param);
  117. return $info;
  118. }
  119. public function getParentList($id,$params)
  120. {
  121. $where = [];
  122. if(isset($params['exam_class']) && !empty($params['exam_class'])){
  123. $where['exam_class_id'] = $params['exam_class'];
  124. }
  125. $info = $this->where('create_user',$id)->where('parent_id',0)->where($where)->where('is_public',2)->field('id,title')->select();
  126. return $info;
  127. }
  128. public function checkTemplate($id)
  129. {
  130. $info = $this->where('parent_id',$id)->find();
  131. return $info;
  132. }
  133. public function delTemplate($doctor,$id)
  134. {
  135. $info = $this->where('create_user',$doctor)->where('id',$id)->delete();
  136. return $info;
  137. }
  138. public function getHospitalTemplate($institution,$class)
  139. {
  140. if(empty($class))
  141. {
  142. $info = $this->where('institution_id',$institution)->where('is_public',3)->where('parent_id',0)->field('id,title,parent_id')->select();
  143. }else{
  144. $info = $this->where('institution_id',$institution)->where('is_public',3)->where('parent_id',0)->where('exam_class_id',$class)->field('id,title,parent_id')->select();
  145. }
  146. return $info;
  147. }
  148. }