123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- namespace app\api\model\template;
- use app\api\model\constant\ConstantModel;
- use app\api\model\ZskkDefaultModel;
- use think\facade\Log;
- class TemplateModel extends ZskkDefaultModel {
- protected $table= 'templates';
- protected $logName = "TemplateModel";
- public function getPublicInfo($constantValue)
- {
- $data =$this->where('is_public', 1)
- ->where('exam_class_id', $constantValue)
- ->field('id, title, exam_class_id, description, impression, parent_id AS pid')
- ->select();
- return $data;
- }
- public function getConstant($id, $value)
- {
- try{
- return ConstantModel::where('id', $id)
- ->value($value);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function getPrivateInfo($constantValue,$uid)
- {
- $data = $this->where('is_public', 2)
- ->where('exam_class_id', $constantValue)
- ->where('create_user', $uid)
- ->field('id, title, exam_class_id, description, impression, parent_id AS pid')
- ->select();
- return $data;
- }
- public function getParentTemplate($exam_class, $type, $uid = null)
- {
- try{
- // 获取常量
- $constant_value = $this->getConstant($exam_class, 'constant_value');
- // 查询数据
- $data = [];
- switch ($type){
- case 'public':
- $data = $this
- ->where('is_public', 1)
- ->where('parent_id',0)
- ->where('exam_class_id', $constant_value)
- ->field('id, TITLE AS title, exam_class_id, PARENT_ID AS parent_id')
- ->select();
- break;
- case 'private':
- $data = $this
- ->where('is_public', 2)
- ->where('parent_id',0)
- ->where('exam_class_id', $constant_value)
- ->where('create_user', $uid)
- ->field('id, TITLE AS title, exam_class_id, PARENT_ID AS parent_id')
- ->select();
- break;
- }
- return $data;
- } catch (DbException $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function getChildData($id)
- {
- try{
- // 判断获取子类还是内容
- $temp = $this->where('id', $id)->find();
- if($temp['parent_id'] == '0'){
- $data = $this
- ->where('parent_id', $id)
- ->field('id, title, exam_class_id, parent_id')
- ->select();
- } else {
- $data = $this
- ->where('id', $id)
- ->field('id, title, exam_class_id, parent_id, impression, description')
- ->find();
- }
- // 返回
- return $data;
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function getTemplate($id)
- {
- $info = $this->where('id',$id)->field('title AS label,impression,description,exam_class_id,parent_id')->find();
- return $info;
- }
- public function getTemplateByPid($id)
- {
- $info = $this->where('id',$id)->value('title');
- return $info;
- }
- public function checkParentTemplate($param,$doctor)
- {
- $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();
- return $info;
- }
- public function checkChildTemplate($param,$doctor)
- {
- $info = $this->where('title',$param['label'])->where('is_public',2)->where('parent_id',$param['id'])->where('create_user',$doctor['id'])->find();
- return $info;
- }
- public function insertTemplate($data)
- {
- $info = $this->insert($data);
- return $info;
- }
- public function getTemplateExam($id)
- {
- $info = $this->where('id',$id)->value('exam_class_id');
- return $info;
- }
- public function updateTemplate($param)
- {
- $info = $this->where('id',$param['id'])->update($param);
- return $info;
- }
- public function getParentList($id,$params)
- {
- $where = [];
- if(isset($params['exam_class']) && !empty($params['exam_class'])){
- $where['exam_class_id'] = $params['exam_class'];
- }
- $info = $this->where('create_user',$id)->where('parent_id',0)->where($where)->where('is_public',2)->field('id,title')->select();
- return $info;
- }
- public function checkTemplate($id)
- {
- $info = $this->where('parent_id',$id)->find();
- return $info;
- }
- public function delTemplate($doctor,$id)
- {
- $info = $this->where('create_user',$doctor)->where('id',$id)->delete();
- return $info;
- }
- public function getHospitalTemplate($institution,$class)
- {
- if(empty($class))
- {
- $info = $this->where('institution_id',$institution)->where('is_public',3)->where('parent_id',0)->field('id,title,parent_id')->select();
- }else{
- $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();
- }
- return $info;
- }
- }
|