TemplateModel.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. ->field('id, TITLE AS title, exam_class_id, PARENT_ID AS parent_id')
  49. ->select();
  50. break;
  51. case 'private':
  52. $data = $this
  53. ->where('is_public', 2)
  54. ->where('parent_id',0)
  55. ->where('exam_class_id', $constant_value)
  56. ->where('create_user', $uid)
  57. ->field('id, TITLE AS title, exam_class_id, PARENT_ID AS parent_id')
  58. ->select();
  59. break;
  60. }
  61. return $data;
  62. } catch (DbException $exception){
  63. $this->throwError($exception->getMessage(),0001);
  64. }
  65. }
  66. public function getChildData($id)
  67. {
  68. try{
  69. // 判断获取子类还是内容
  70. $temp = $this->where('id', $id)->find();
  71. if($temp['parent_id'] == '0'){
  72. $data = $this
  73. ->where('parent_id', $id)
  74. ->field('id, title, exam_class_id, parent_id')
  75. ->select();
  76. } else {
  77. $data = $this
  78. ->where('id', $id)
  79. ->field('id, title, exam_class_id, parent_id, impression, description')
  80. ->find();
  81. }
  82. // 返回
  83. return $data;
  84. } catch (Exception $exception){
  85. $this->throwError($exception->getMessage(),0001);
  86. }
  87. }
  88. public function getTemplate($id)
  89. {
  90. $info = $this->where('id',$id)->field('title AS label,impression,description,exam_class_id,parent_id')->find();
  91. return $info;
  92. }
  93. public function getTemplateByPid($id)
  94. {
  95. $info = $this->where('id',$id)->value('title');
  96. return $info;
  97. }
  98. public function checkParentTemplate($param,$doctor)
  99. {
  100. $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();
  101. return $info;
  102. }
  103. public function checkChildTemplate($param,$doctor)
  104. {
  105. $info = $this->where('title',$param['label'])->where('is_public',2)->where('parent_id',$param['id'])->where('create_user',$doctor['id'])->find();
  106. return $info;
  107. }
  108. public function insertTemplate($data)
  109. {
  110. $info = $this->insert($data);
  111. return $info;
  112. }
  113. public function getTemplateExam($id)
  114. {
  115. $info = $this->where('id',$id)->value('exam_class_id');
  116. return $info;
  117. }
  118. public function updateTemplate($param)
  119. {
  120. $info = $this->where('id',$param['id'])->update($param);
  121. return $info;
  122. }
  123. public function getParentList($id,$params)
  124. {
  125. $where = [];
  126. if(isset($params['exam_class']) && !empty($params['exam_class'])){
  127. $where['exam_class_id'] = $params['exam_class'];
  128. }
  129. $info = $this->where('create_user',$id)->where('parent_id',0)->where($where)->where('is_public',2)->field('id,title')->select();
  130. return $info;
  131. }
  132. public function checkTemplate($id)
  133. {
  134. $info = $this->where('parent_id',$id)->find();
  135. return $info;
  136. }
  137. public function delTemplate($doctor,$id)
  138. {
  139. $info = $this->where('create_user',$doctor)->where('id',$id)->delete();
  140. return $info;
  141. }
  142. public function getHospitalTemplate($institution,$class)
  143. {
  144. if(empty($class))
  145. {
  146. $info = $this->where('institution_id',$institution)->where('is_public',3)->where('parent_id',0)->field('id,title,parent_id')->select();
  147. }else{
  148. $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();
  149. }
  150. return $info;
  151. }
  152. }