TemplateModel.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. ->field('id, title, exam_class_id, parent_id')
  73. ->select();
  74. } else {
  75. $data = $this
  76. ->where('id', $id)
  77. ->field('id, title, exam_class_id, parent_id, impression, description')
  78. ->find();
  79. }
  80. // 返回
  81. return $data;
  82. } catch (Exception $exception){
  83. $this->throwError($exception->getMessage(),0001);
  84. }
  85. }
  86. public function getTemplate($id)
  87. {
  88. $info = $this->where('id',$id)->field('title AS label,impression,description,exam_class_id,parent_id')->find();
  89. return $info;
  90. }
  91. public function getTemplateByPid($id)
  92. {
  93. $info = $this->where('id',$id)->value('title');
  94. return $info;
  95. }
  96. public function checkParentTemplate($param,$doctor)
  97. {
  98. $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();
  99. return $info;
  100. }
  101. public function checkChildTemplate($param,$doctor)
  102. {
  103. $info = $this->where('title',$param['label'])->where('is_public',2)->where('parent_id',$param['id'])->where('create_user',$doctor['id'])->find();
  104. return $info;
  105. }
  106. public function insertTemplate($data)
  107. {
  108. $info = $this->insert($data);
  109. return $info;
  110. }
  111. public function getTemplateExam($id)
  112. {
  113. $info = $this->where('id',$id)->value('exam_class_id');
  114. return $info;
  115. }
  116. public function updateTemplate($param)
  117. {
  118. $info = $this->where('id',$param['id'])->update($param);
  119. return $info;
  120. }
  121. public function getParentList($id,$params)
  122. {
  123. $where = [];
  124. if(isset($params['exam_class']) && !empty($params['exam_class'])){
  125. $where['exam_class_id'] = $params['exam_class'];
  126. }
  127. $info = $this->where('create_user',$id)->where('parent_id',0)->where($where)->where('is_public',2)->field('id,title')->select();
  128. return $info;
  129. }
  130. public function checkTemplate($id)
  131. {
  132. $info = $this->where('parent_id',$id)->find();
  133. return $info;
  134. }
  135. public function delTemplate($doctor,$id)
  136. {
  137. $info = $this->where('create_user',$doctor)->where('id',$id)->delete();
  138. return $info;
  139. }
  140. public function getHospitalTemplate($institution,$class)
  141. {
  142. if(empty($class))
  143. {
  144. $info = $this->where('institution_id',$institution)->where('is_public',3)->where('parent_id',0)->field('id,title,parent_id')->select();
  145. }else{
  146. $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();
  147. }
  148. return $info;
  149. }
  150. }